📄 configurationstore.java
字号:
} catch (InstantiationException ie) {
throw new ParsingException("couldn't instantiate " + className,
ie);
} catch (IllegalAccessException iae) {
throw new ParsingException("couldn't get access to instance " +
"of " + className, iae);
} catch (InvocationTargetException ite) {
throw new ParsingException("couldn't create " + className,
ite);
}
}
return instance;
}
/**
* Private helper that gets the constructor arguments for a given class.
* Right now this just supports String and List, but it's trivial to
* add support for other types should that be needed. Right now, it's not
* clear that there's any need for other types.
*/
private List getArgs(Node root) {
List args = new ArrayList();
NodeList children = root.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
String name = child.getNodeName();
if (child.getNodeType() == Node.ELEMENT_NODE) {
if (name.equals("string")) {
args.add(child.getFirstChild().getNodeValue());
} else if (name.equals("list")) {
args.add(getArgs(child));
} else {
throw new IllegalArgumentException("unkown arg type: " +
name);
}
}
}
return args;
}
/**
* Private helper used by the three factory routines to see if the
* given factory should be based on the standard setup
*/
private boolean useStandard(Node node, String attributeName) {
NamedNodeMap map = node.getAttributes();
if (map == null)
return true;
Node attrNode = map.getNamedItem(attributeName);
if (attrNode == null)
return true;
return attrNode.getNodeValue().equals("true");
}
/**
* Returns the default PDP configuration. If no default was specified
* then this throws an exception.
*
* @return the default PDP configuration
*
* @throws UnknownIdentifierException if there is no default config
*/
public PDPConfig getDefaultPDPConfig() throws UnknownIdentifierException {
if (defaultPDPConfig == null)
throw new UnknownIdentifierException("no default available");
return defaultPDPConfig;
}
/**
* Returns the PDP configuration with the given name. If no such
* configuration exists then an exception is thrown.
*
* @return the matching PDP configuation
*
* @throws UnknownIdentifierException if the name is unknown
*/
public PDPConfig getPDPConfig(String name)
throws UnknownIdentifierException
{
Object object = pdpConfigMap.get(name);
if (object == null)
throw new UnknownIdentifierException("unknown pdp: " + name);
return (PDPConfig)object;
}
/**
* Returns a set of identifiers representing each PDP configuration
* available.
*
* @return a <code>Set</code> of <code>String</code>s
*/
public Set getSupportedPDPConfigurations() {
return Collections.unmodifiableSet(pdpConfigMap.keySet());
}
/**
* Returns the default attribute factory.
*
* @return the default attribute factory
*/
public AttributeFactory getDefaultAttributeFactory() {
return defaultAttributeFactory;
}
/**
* Returns the attribute factory with the given name. If no such
* factory exists then an exception is thrown.
*
* @return the matching attribute factory
*
* @throws UnknownIdentifierException if the name is unknown
*/
public AttributeFactory getAttributeFactory(String name)
throws UnknownIdentifierException
{
Object object = attributeMap.get(name);
if (object == null)
throw new UnknownIdentifierException("unknown factory: " + name);
return (AttributeFactory)object;
}
/**
* Returns a set of identifiers representing each attribute factory
* available.
*
* @return a <code>Set</code> of <code>String</code>s
*/
public Set getSupportedAttributeFactories() {
return Collections.unmodifiableSet(attributeMap.keySet());
}
/**
* Registers all the supported factories with the given identifiers. If
* a given identifier is already in use, then that factory is not
* registered. This method is provided only as a convenience, and
* any registration that may involve identifier clashes should be done
* by registering each factory individually.
*/
public void registerAttributeFactories() {
Iterator it = attributeMap.keySet().iterator();
while (it.hasNext()) {
String id = (String)(it.next());
AttributeFactory af = (AttributeFactory)(attributeMap.get(id));
try {
AttributeFactory.registerFactory(id, new AFProxy(af));
} catch (IllegalArgumentException iae) {
logger.log(Level.WARNING, "Couldn't register AttributeFactory:"
+ id + " (already in use)", iae);
}
}
}
/**
* Returns the default combiningAlg factory.
*
* @return the default combiningAlg factory
*/
public CombiningAlgFactory getDefaultCombiningAlgFactory() {
return defaultCombiningFactory;
}
/**
* Returns the combiningAlg factory with the given name. If no such
* factory exists then an exception is thrown.
*
* @return the matching combiningAlg factory
*
* @throws UnknownIdentifierException if the name is unknown
*/
public CombiningAlgFactory getCombiningAlgFactory(String name)
throws UnknownIdentifierException
{
Object object = combiningMap.get(name);
if (object == null)
throw new UnknownIdentifierException("unknown factory: " + name);
return (CombiningAlgFactory)object;
}
/**
* Returns a set of identifiers representing each combiningAlg factory
* available.
*
* @return a <code>Set</code> of <code>String</code>s
*/
public Set getSupportedCombiningAlgFactories() {
return Collections.unmodifiableSet(combiningMap.keySet());
}
/**
* Registers all the supported factories with the given identifiers. If
* a given identifier is already in use, then that factory is not
* registered. This method is provided only as a convenience, and
* any registration that may involve identifier clashes should be done
* by registering each factory individually.
*/
public void registerCombiningAlgFactories() {
Iterator it = combiningMap.keySet().iterator();
while (it.hasNext()) {
String id = (String)(it.next());
CombiningAlgFactory cf =
(CombiningAlgFactory)(combiningMap.get(id));
try {
CombiningAlgFactory.registerFactory(id, new CAFProxy(cf));
} catch (IllegalArgumentException iae) {
logger.log(Level.WARNING, "Couldn't register " +
"CombiningAlgFactory: " + id + " (already in use)",
iae);
}
}
}
/**
* Returns the default function factory proxy.
*
* @return the default function factory proxy
*/
public FunctionFactoryProxy getDefaultFunctionFactoryProxy() {
return defaultFunctionFactoryProxy;
}
/**
* Returns the function factory proxy with the given name. If no such
* proxy exists then an exception is thrown.
*
* @return the matching function factory proxy
*
* @throws UnknownIdentifierException if the name is unknown
*/
public FunctionFactoryProxy getFunctionFactoryProxy(String name)
throws UnknownIdentifierException
{
Object object = functionMap.get(name);
if (object == null)
throw new UnknownIdentifierException("unknown factory: " + name);
return (FunctionFactoryProxy)object;
}
/**
* Returns a set of identifiers representing each function factory proxy
* available.
*
* @return a <code>Set</code> of <code>String</code>s
*/
public Set getSupportedFunctionFactories() {
return Collections.unmodifiableSet(functionMap.keySet());
}
/**
* Registers all the supported factories with the given identifiers. If
* a given identifier is already in use, then that factory is not
* registered. This method is provided only as a convenience, and
* any registration that may involve identifier clashes should be done
* by registering each factory individually.
*/
public void registerFunctionFactories() {
Iterator it = functionMap.keySet().iterator();
while (it.hasNext()) {
String id = (String)(it.next());
FunctionFactoryProxy ffp =
(FunctionFactoryProxy)(functionMap.get(id));
try {
FunctionFactory.registerFactory(id, ffp);
} catch (IllegalArgumentException iae) {
logger.log(Level.WARNING, "Couldn't register FunctionFactory: "
+ id + " (already in use)", iae);
}
}
}
/**
* Uses the default configuration to re-set the default factories used
* by the system (attribute, combining algorithm, and function). If
* a default is not provided for a given factory, then that factory
* will not be set as the system's default.
*/
public void useDefaultFactories() {
logger.fine("Switching to default factories from configuration");
// set the default attribute factory, if it exists here
if (defaultAttributeFactory != null) {
AttributeFactory.
setDefaultFactory(new AFProxy(defaultAttributeFactory));
}
// set the default combining algorithm factory, if it exists here
if (defaultCombiningFactory != null) {
CombiningAlgFactory.
setDefaultFactory(new CAFProxy(defaultCombiningFactory));
}
// set the default function factories, if they exists here
if (defaultFunctionFactoryProxy != null)
FunctionFactory.setDefaultFactory(defaultFunctionFactoryProxy);
}
/**
*
*/
class AFProxy implements AttributeFactoryProxy {
private AttributeFactory factory;
public AFProxy(AttributeFactory factory) {
this.factory = factory;
}
public AttributeFactory getFactory() {
return factory;
}
}
/**
*
*/
class CAFProxy implements CombiningAlgFactoryProxy {
private CombiningAlgFactory factory;
public CAFProxy(CombiningAlgFactory factory) {
this.factory = factory;
}
public CombiningAlgFactory getFactory() {
return factory;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -