📄 properties.java
字号:
}
/**
* Loads all required attributes for be able to use the application level.
* @throws InitializationException if cannot load any required attribute.
*/
public static void activateApplicationLevelAttributes() throws InitializationException
{
if (Properties.activatedApplicationLevel) return;
Properties.activatedApplicationLevel = true;
/* Factory classes: */
Properties.factoriesApplicationFactory = properties.getPropertyAsClass(FACTORIES_APPLICATIONFACTORY);
Properties.factoriesEndPointFactory = properties.getPropertyAsClass(FACTORIES_ENDPOINTFACTORY);
/* Specific classes: */
Properties.factoriesApplication = properties.getPropertyAsClass(FACTORIES_APPLICATION);
Properties.factoriesEndPoint = properties.getPropertyAsClass(FACTORIES_ENDPOINT);
//testing the correctness of the values
Interfaces.ensureImplementedInterfaceOrClass(Properties.factoriesApplicationFactory,Interfaces.FACTORIES_APPLICATIONFACTORY,FACTORIES_APPLICATIONFACTORY);
Interfaces.ensureImplementedInterfaceOrClass(Properties.factoriesEndPointFactory, Interfaces.FACTORIES_ENDPOINTFACTORY, FACTORIES_ENDPOINTFACTORY);
Interfaces.ensureImplementedInterfaceOrClass(Properties.factoriesApplication, Interfaces.FACTORIES_APPLICATION, FACTORIES_APPLICATION);
Interfaces.ensureImplementedInterfaceOrClass(Properties.factoriesEndPoint, Interfaces.FACTORIES_ENDPOINT, FACTORIES_ENDPOINT);
}
/**
* Permits the use of files with events to be loaded into the current
* simulation.
* @throws InitializationException if any error has ocurred during the
* loading process.
*/
public static void activateEventsAttributes() throws InitializationException
{
if (Properties.activatedEvents) return;
Properties.activatedEvents = true;
Properties.simulatorEventFile = properties.getProperty(SIMULATOR_EVENT_FILE);
}
/**
* Permits the loading, saving process of a serialized network. A loaded
* serialized network can be used for the current simulation without any
* other cost (without its creation and stabilization processes). You
* can save the current simulation state to use it in the future wihtout any
* other cost.
* @throws InitializationException if any error has ocurred during the
* loading process.
*/
public static void activateSerializationAttributes() throws InitializationException
{
if (Properties.activatedSerialization) return;
Properties.activatedSerialization = true;
Properties.serializedInputFile = properties.getProperty(SERIALIZATION_INPUT_FILE);
Properties.serializedOutputFile = properties.getProperty(SERIALIZATION_OUTPUT_FILE);
Properties.serializedOutputFileReplaced = properties.getPropertyAsBoolean(SERIALIZATION_REPLACE_OUTPUT_FILE);
}
/**
* Loads all results types specified in the properties file.
* @throws InitializationException if any error occurs during the
* loading process.
*/
public static void activateResultsAttributes() throws InitializationException
{
if ( Properties.activatedResults) return;
Properties.activatedResults = true;
StringTokenizer resultsFactory = new StringTokenizer(properties.getProperty(RESULTS_FACTORY), ",");
StringTokenizer resultsEdge = new StringTokenizer(properties.getProperty(RESULTS_EDGE), ",");
StringTokenizer resultsConstraint = new StringTokenizer(properties.getProperty(RESULTS_CONSTRAINT), ",");
StringTokenizer resultsGenerator = new StringTokenizer(properties.getProperty(RESULTS_GENERATOR), ",");
StringTokenizer resultsProperties = new StringTokenizer(properties.getProperty(RESULTS_PROPERTIES), ",");
StringTokenizer resultsUniqueName = new StringTokenizer(properties.getProperty(RESULTS_UNIQUE_NAME),",");
final int MAX_ELEMS = resultsUniqueName.countTokens();
Properties.resultsFactory = new Vector(MAX_ELEMS);
Properties.resultsEdge = new Vector(MAX_ELEMS);
Properties.resultsConstraint = new Vector(MAX_ELEMS);
Properties.resultsGenerator = new Vector(MAX_ELEMS);
Properties.resultsProperties = new Vector(MAX_ELEMS);
Properties.resultsPropertiesInstance = new Vector(MAX_ELEMS);
Properties.resultsUniqueName = new TreeMap();
//testing if there are the same number of items
if (resultsFactory.countTokens() != MAX_ELEMS ||
resultsEdge.countTokens() != MAX_ELEMS ||
resultsConstraint.countTokens() != MAX_ELEMS ||
resultsGenerator.countTokens() != MAX_ELEMS ||
resultsProperties.countTokens() != MAX_ELEMS)
throw new InitializationException("There are not the same number of items in the results attributes");
//loading the items
String uniqueName = null;
Class factory = null;
Class edge = null;
Class constraint = null;
Class generator = null;
Class prop = null;
for (int i =0; i < MAX_ELEMS; i++)
{
uniqueName = resultsUniqueName.nextToken().trim();
if (uniqueName.equals("")) throw new InitializationException("An empty string is not a valid results type name");
Properties.resultsUniqueName.put(uniqueName,new Integer(i));
//loading process
factory = PropertiesWrapper.getValueAsClass(resultsFactory.nextToken().trim(),RESULTS_FACTORY);
edge = PropertiesWrapper.getValueAsClass(resultsEdge.nextToken().trim(),RESULTS_EDGE);
constraint = PropertiesWrapper.getValueAsClass(resultsConstraint.nextToken().trim(),RESULTS_CONSTRAINT);
generator = PropertiesWrapper.getValueAsClass(resultsGenerator.nextToken().trim(),RESULTS_GENERATOR);
prop = PropertiesWrapper.getValueAsClass(resultsProperties.nextToken().trim(),RESULTS_PROPERTIES);
//testing the correctness of the values
Interfaces.ensureImplementedInterfaceOrClass(factory, Interfaces.RESULTS_FACTORY, RESULTS_FACTORY);
Interfaces.ensureImplementedInterfaceOrClass(edge, Interfaces.RESULTS_EDGE, RESULTS_EDGE);
Interfaces.ensureImplementedInterfaceOrClass(constraint,Interfaces.RESULTS_CONSTRAINT,RESULTS_CONSTRAINT);
Interfaces.ensureImplementedInterfaceOrClass(generator, Interfaces.RESULTS_GENERATOR, RESULTS_GENERATOR);
Interfaces.ensureImplementedInterfaceOrClass(prop, Interfaces.RESULTS_PROPERTIES,RESULTS_PROPERTIES);
//add references
Properties.resultsFactory.add(factory);
Properties.resultsEdge.add(edge);
Properties.resultsConstraint.add(constraint);
Properties.resultsGenerator.add(generator);
Properties.resultsProperties.add(prop);
Properties.resultsPropertiesInstance.add(loadPropertiesInitializer(prop));
}
}
/**
* Gets related index of the requested results type.
* @param resultsName Results name.
* @return The related index of the requested results type.
* @throws InitializationException if some error occurs during
* the process.
*/
private static int getIndexOf(String resultsName) throws InitializationException
{
//testing if the results has been activated.
if (!activatedResults)
throw new InitializationException("The optional results part is not activated.");
//testing if has a correct value
if (resultsName == null)
throw new InitializationException("The specified resultsName is null.");
//testing if the requested results type exists
Object value = Properties.resultsUniqueName.get(resultsName);
if (value == null)
throw new InitializationException("The results name '"+resultsName+"' don't appear into the loaded configuration.");
//obtaining the requested index
return ((Integer)value).intValue();
}
/**
* Gets the ResultsFactory related to the <b>resultsname</b>.
* @param resultsName Results name, appeared in the configuration file.
* @return The requrested ResultsFactory.
* @throws InitializationException if some error occurs during
* the obtaining process.
*/
public static Class getResultsFactory(String resultsName) throws InitializationException
{
//obtaining the requested factory
try {
return (Class)Properties.resultsFactory.get(getIndexOf(resultsName));
} catch (Exception e)
{
throw new InitializationException("Cannot obtain the requested ResultsFactory of '"+resultsName+"' results",e);
}
}
/**
* Gets the ResultsConstraint related to the <b>resultsname</b>.
* @param resultsName Results name, appeared in the configuration file.
* @return The requrested ResultsConstraint.
* @throws InitializationException if some error occurs during
* the obtaining process.
*/
public static Class getResultsConstraint(String resultsName) throws InitializationException
{
//obtaining the requested constraint
try {
return (Class)Properties.resultsConstraint.get(getIndexOf(resultsName));
} catch (Exception e)
{
throw new InitializationException("Cannot obtain the requested ResultsConstraint of '"+resultsName+"' results",e);
}
}
/**
* Gets the ResultsEdge related to the <b>resultsname</b>.
* @param resultsName Results name, appeared in the configuration file.
* @return The requrested ResultsEdge.
* @throws InitializationException if some error occurs during
* the obtaining process.
*/
public static Class getResultsEdge(String resultsName) throws InitializationException
{
//obtaining the requested edge
try {
return (Class)Properties.resultsEdge.get(getIndexOf(resultsName));
} catch (Exception e)
{
throw new InitializationException("Cannot obtain the requested ResultsEdge of '"+resultsName+"' results",e);
}
}
/**
* Gets the ResultsGenerator related to the <b>resultsname</b>.
* @param resultsName Results name, appeared in the configuration file.
* @return The requrested ResultsGenerator.
* @throws InitializationException if some error occurs during
* the obtaining process.
*/
public static Class getResultsGenerator(String resultsName) throws InitializationException
{
//obtaining the requested generator
try {
return (Class)Properties.resultsGenerator.get(getIndexOf(resultsName));
} catch (Exception e)
{
throw new InitializationException("Cannot obtain the requested ResultsGenerator of '"+resultsName+"' results",e);
}
}
/**
* Gets the properties class related to the <b>resultsname</b>.
* @param resultsName Results name, appeared in the configuration file.
* @return The requested properties.
* @throws InitializationException if some error occurs during
* the obtaining process.
*/
public static Class getResultsProperties(String resultsName) throws InitializationException
{
//obtaining the requested properties class
try {
return (Class)Properties.resultsProperties.get(getIndexOf(resultsName));
} catch (Exception e)
{
throw new InitializationException("Cannot obtain the requested properties class of '"+resultsName+"' results",e);
}
}
/**
* Gets the properties instance related to the <b>resultsname</b>.
* @param resultsName Results name, appeared in the configuration file.
* @return The requested properties instance.
* @throws InitializationException if some error occurs during
* the obtaining process.
*/
public static PropertiesInitializer getResultsPropertiesInstance(String resultsName) throws InitializationException
{
//obtaining the requested properties instance
try {
return (PropertiesInitializer)Properties.resultsPropertiesInstance.get(getIndexOf(resultsName));
} catch (Exception e)
{
throw new InitializationException("Cannot obtain the requested properties class of '"+resultsName+"' results",e);
}
}
/**
* Shows when the optional application level has been activated.
* @return true when it is activated. false in other case.
*/
public static boolean isApplicationLevelActivated()
{
return activatedApplicationLevel;
}
/**
* Shows when the optional events part has been activated.
* @return true when it is activated. false in other case.
*/
public static boolean isEventsActivated()
{
return activatedEvents;
}
/**
* Shows when the optional serialization has been activated.
* @return true when it is activated. false in other case.
*/
public static boolean isSerializationActivated()
{
return activatedSerialization;
}
/**
* Shows when the optional results part has been activated.
* @return true when it is activated. false in other case.
*/
public static boolean isResultsActivated()
{
return activatedResults;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -