⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 profileimpl.java

📁 java实现的P2P多agent中间件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 * @return Properties The properties collection.
	 */
	public Properties getProperties() {
		return props;
	}      

	//#MIDP_EXCLUDE_BEGIN
	/**
	 * Retrieve the configuration properties as they were passed to this Profile object, i.e. without 
	 * internal initializations automatically performed by the Profile class. 
	 */
	public Properties getBootProperties() {
		return bootProps;
	}
	//#MIDP_EXCLUDE_END

	/**
	 * Assign the given value to the given property name.
	 *
	 * @param key is the property name
	 * @param value is the property value
	 */
	public void setParameter(String key, String value) {
		if(value==null){
			props.remove(key);
		}else{
			props.setProperty(key, value);
		}
	}
	
	/**
	 * Assign the given property value to the given property name
	 *
	 * @param key is the property name
	 * @param value is the property value
	 */
	public void setSpecifiers(String key, List value) {
		//#MIDP_EXCLUDE_BEGIN
		props.put(key, value);
		//#MIDP_EXCLUDE_END
	} 
	
	/**
	 * Retrieve a String value from the configuration properties.
	 * If no parameter corresponding to the specified key is found,
	 * <code>aDefault</code> is returned.
	 * @param key The key identifying the parameter to be retrieved
	 * among the configuration properties.
	 * @param aDefault The value that is returned if the specified 
	 * key is not found
	 */
	public String getParameter(String key, String aDefault) {
		String v = props.getProperty(key);
		if (v==null) {
			String dottedKey = key.replace('_', '.');
			v = props.getProperty( dottedKey );
		}
		if (v==null) {
			String underscoredKey = key.replace('.', '_');
			v = props.getProperty( underscoredKey );
		}
		return (v != null ? v.trim() : aDefault);
	}
	
	/**
	 * Retrieve a boolean value for a configuration property.  If no
	 * corresponding property is found or if its string value cannot
	 * be converted to a boolean one, a default value is returned.
	 * @param key The key identifying the parameter to be retrieved
	 * among the configuration properties.
	 * @param aDefault The value to return when there is no property
	 * set for the given key, or its value cannot be converted to a
	 * boolean value.
	 *
	 public boolean getParameter(String key, boolean aDefault) {
	 String v = props.getProperty(key);
	 if(v == null) {
	 return aDefault;
	 }
	 else {
	 if(CaseInsensitiveString.equalsIgnoreCase(v, "true")) {
	 return true;
	 }
	 else if(CaseInsensitiveString.equalsIgnoreCase(v, "false")) {
	 return false;
	 }
	 else {
	 return aDefault;
	 }
	 }
	 }*/
	
	/**
	 * Retrieve a list of Specifiers from the configuration properties.
	 * Agents, MTPs and other items are specified among the configuration
	 * properties in this way.
	 * If no list of Specifiers corresponding to the specified key is found,
	 * an empty list is returned.
	 * @param key The key identifying the list of Specifires to be retrieved
	 * among the configuration properties.
	 */
	public List getSpecifiers(String key) throws ProfileException {
		//#MIDP_EXCLUDE_BEGIN
		// Check if the list of specs is already in the properties as a list
		Object o = props.get(key);
		if (o instanceof List) { // null isn't an instance of anything
			return (List) o;
		}
		//#MIDP_EXCLUDE_END
		
		// The list should be present as a string --> parse it
		String    specsLine = getParameter(key, null);
		try {
			Vector v = Specifier.parseSpecifierList(specsLine);
			// convert the vector into an arraylist (notice that using the vector allows to avoid class loading of ArrayList)
			List l1 = new ArrayList(v.size());
			for (int i=0; i<v.size(); i++)
				l1.add(v.elementAt(i));
			return l1;
		}
		catch (Exception e) {
			throw new ProfileException("Error parsing specifier list "+specsLine+".", e);
		}
	}
	
	/**
	 * Retrieve a boolean value for a configuration property.  If no
	 * corresponding property is found or if its string value cannot
	 * be converted to a boolean one, a default value is returned.
	 * @param key The key identifying the parameter to be retrieved
	 * among the configuration properties.
	 * @param aDefault The value to return when there is no property
	 * set for the given key, or its value cannot be converted to a
	 * boolean value.
	 */
	public boolean getBooleanProperty(String aKey, boolean aDefault) {
		String v = props.getProperty(aKey);
		if(v == null) {
			return aDefault;
		}
		else {
			if(CaseInsensitiveString.equalsIgnoreCase(v, "true")) {
				return true;
			}
			else if(CaseInsensitiveString.equalsIgnoreCase(v, "false")) {
				return false;
			}
			else {
				return aDefault;
			}
		}
	}
	
	/**
	 Creates a string representation of this profile. The returned
	 string has the format
	 <p><code>(profile name1=value1 name2=value2 ... )</code></p>
	 
	 @return A string containing a readable representation of this
	 profile object.
	 */
	public String toString() {
		return props.toString();
	}
	
	//#APIDOC_EXCLUDE_BEGIN
	
	protected PlatformManager getPlatformManager() throws ProfileException {
		if (myPlatformManager == null) {
			createPlatformManager();
		}
		return myPlatformManager;
	}
	
	/**
	 Access the platform service manager.
	 @return The platform service manager, either the real
	 implementation or a remote proxy object.
	 @throws ProfileException If some needed information is wrong or
	 missing from the profile.
	 */
	protected ServiceManager getServiceManager() throws ProfileException {
		if(myServiceManager == null) {
			myServiceManager = new ServiceManagerImpl(this, getPlatformManager());
		}
		return myServiceManager;
	}
	
	/**
	 Access the platform service finder.
	 @return The platform service finder, either the real
	 implementation or a remote proxy object.
	 @throws ProfileException If some needed information is wrong or
	 missing from the profile.
	 */
	protected ServiceFinder getServiceFinder() throws ProfileException {
		return (ServiceFinder) getServiceManager();
	}
	
	protected CommandProcessor getCommandProcessor() throws ProfileException {
		if(myCommandProcessor == null) {
			myCommandProcessor = new CommandProcessor();
		}
		return myCommandProcessor;
	}
	
	
	//#MIDP_EXCLUDE_BEGIN
	protected MainContainerImpl getMain() throws ProfileException {
		return myMain;
	}
	//#MIDP_EXCLUDE_END
	
	
	/**
	 */
	protected IMTPManager getIMTPManager() throws ProfileException {
		if (myIMTPManager == null) {
			createIMTPManager();
		}
		return myIMTPManager;
	}
	
	/**
	 */
	public ResourceManager getResourceManager() throws ProfileException {
		if (myResourceManager == null) {
			createResourceManager();
		}
		return myResourceManager;
	}
	
	
	//#APIDOC_EXCLUDE_END
	
	
	private void createPlatformManager() throws ProfileException {
		try {
			myIMTPManager = getIMTPManager();
			
			//#MIDP_EXCLUDE_BEGIN
			if(isMain()) {
				// This is a main container: create a real PlatformManager,
				// export it and get the MainContainer. 
				PlatformManagerImpl pm = new PlatformManagerImpl(this);
				myIMTPManager.exportPlatformManager(pm);
				myMain = pm.getMain();
				myPlatformManager = pm;
				return;
			}
			//#MIDP_EXCLUDE_END
			
			// This is a peripheral container: create a proxy to the PlatformManager
			myPlatformManager = myIMTPManager.getPlatformManagerProxy();
		}
		catch(IMTPException imtpe) {
			throw new ProfileException("Can't get a proxy to the Platform Manager", imtpe);
		}
	}
	
	
	
	private void createIMTPManager() throws ProfileException {
		String className = getParameter(IMTP, DEFAULT_IMTPMANAGER_CLASS);
		try {
			myIMTPManager = (IMTPManager) Class.forName(className).newInstance();
		}
		catch (Exception e) {
			throw new ProfileException("Error loading IMTPManager class "+className);
		}
	}
	
	private void createResourceManager() throws ProfileException {
		//#J2ME_EXCLUDE_BEGIN
		String className = getParameter(RESOURCE, "jade.core.FullResourceManager");
		//#J2ME_EXCLUDE_END
		/*#J2ME_INCLUDE_BEGIN
		 String className = getParameter(RESOURCE, "jade.core.LightResourceManager");
		 #J2ME_INCLUDE_END*/
		
		try {
			myResourceManager = (ResourceManager) Class.forName(className).newInstance();
		}
		catch (Exception e) {
			throw new ProfileException("Error loading ResourceManager class "+className);
		}
	}
	
	
	private void setPropertyIfNot(String key, String value) {
		Object old = props.get(key);
		if(old == null) {
			props.put(key, value);
		}
	}
	
	private void setIntProperty(String aKey, int aValue) {
		props.setProperty(aKey, Integer.toString(aValue));
	}
	
	
	//#APIDOC_EXCLUDE_BEGIN
	protected boolean isMain() {
		return getBooleanProperty(MAIN, false);
	}
	
	// True if this is a Main Container and the LOCAL_SERVICE_MANAGER
	// option is set to false or not set
	protected boolean isFirstMain() {
		return isMain() && !getBooleanProperty(LOCAL_SERVICE_MANAGER, false);
	}	
	//#APIDOC_EXCLUDE_END
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -