本文整理了Java中org.apache.avalon.framework.configuration.Configuration
类的一些代码示例,展示了Configuration
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration
类的具体详情如下:
包路径:org.apache.avalon.framework.configuration.Configuration
类名称:Configuration
[英]Configuration
is a interface encapsulating a configuration node used to retrieve configuration values.
This is a "read only" interface preventing applications from modifying their own configurations. Once it is created, the information never changes.
The data model is a subset of XML's; a single-rooted hierarchical tree where each node can contain multiple attributes, and leaf nodes can also contain a value. Reflecting this, Configuration
s are usually built from an XML file by the DefaultConfigurationBuilder class, or directly by a SAX parser using a SAXConfigurationHandler or NamespacedSAXConfigurationHandler event handler.
Since version 4.1, each Configuration
node has a namespace associated with it, in the form of a string, accessible through #getNamespace. If no namespace is present, getNamespace
will return blank (""). See DefaultConfigurationBuilder for details on how XML namespaces are mapped to Configuration
namespaces.
As an example, consider two Configuration
s (with and without namespaces) built from this XML:
<my-system version="1.3" xmlns:doc="http://myco.com/documentation">
<doc:desc>This is a highly fictitious config file</doc:desc>
<widget name="fooWidget" initOrder="1" threadsafe="true"/>
</my-system>
If namespace support is enabled (eg through DefaultConfigurationBuilder#DefaultConfigurationBuilder(boolean) new DefaultConfigurationBuilder(true)), then the xmlns:doc
element will not translate into a Configuration attribute, and the doc:desc
element will become a Configuration
node with name "desc" and namespace "http://myco.com/documentation". The widget
element will have namespace "".
If namespace support is disabled (the default for DefaultConfigurationBuilder), the above XML will translate directly to Configuration
nodes. The my-system
node will have an attribute named "xmlns:doc", and a child called "doc:desc".
Assuming the Configuration
object is named conf
, here is how the data could be retrieved:
CodeNo namespacesWith namespacesconf. #getName()
my-systemconf. #getAttributeNames().length
21conf. #getChildren()().length
2conf. #getAttributeAsFloat(String)("version")
1.3conf. #getChild(String)("widget"). #getAttribute(String)("name")
fooWidgetconf. #getChild(String)("widget") . #getAttributeAsBoolean(String)("threadsafe")``true``conf. #getChild(String)("widget"). #getLocation()
file:///home/jeff/tmp/java/avalon/src/java/new.xconf:4:60conf. #getChild(String)("desc"). #getName()
desc (see #getChild(String))descconf. #getChild(String)("doc:desc"). #getName()
doc:descdoc:desc (see #getChild(String))conf. #getChild(String)("desc"). #getValue()()
ConfigurationExceptionThis is a highly fictitious config fileconf. #getChild(String)("doc:desc"). #getValue()()
This is a highly fictitious config fileConfigurationExceptionconf. #getChild(String)("desc"). #getNamespace()
http://myco.com/documentation"
Type-safe utility methods are provided for retrieving attribute and element values as String
, int
, long
, float
and boolean
.
Currently, the configuration tree can only be traversed one node at a time, eg., through #getChild(String) or #getChildren(). In a future release, it may be possible to access child nodes with an XPath-like syntax.
Checking for the existence of an attribute can be done as follows:
String value = conf.getAttribute( "myAttribute", null );
if ( null == value )
{
// Do the processing applicable if the attribute isn't present.
}
[中]Configuration
是封装用于检索配置值的配置节点的接口。
这是一个“只读”接口,防止应用程序修改自己的配置。一旦创建,信息就永远不会更改。
####数据模型
数据模型是XML的子集;单根层次树,其中每个节点可以包含多个属性,叶节点也可以包含一个值。考虑到这一点,Configuration
通常由DefaultConfigurationBuilder类从XML文件构建,或直接由SAX解析器使用SAXConfigurationHandler或NamespacedSAXConfigurationHandler事件处理程序构建。
#####命名空间支持
从版本4.1开始,每个Configuration
节点都有一个与之关联的名称空间,以字符串的形式,可通过#getNamespace访问。如果不存在名称空间,getNamespace
将返回空白(“”)。有关如何将XML命名空间映射到Configuration
命名空间的详细信息,请参阅DefaultConfigurationBuilder。
####范例
作为一个例子,考虑两个[$$ 5 ] s(有和没有命名空间)从这个XML构建的:
<my-system version="1.3" xmlns:doc="http://myco.com/documentation">
<doc:desc>This is a highly fictitious config file</doc:desc>
<widget name="fooWidget" initOrder="1" threadsafe="true"/>
</my-system>
如果启用了名称空间支持(例如通过DefaultConfigurationBuilder#DefaultConfigurationBuilder(布尔值)new DefaultConfigurationBuilder(true)),则xmlns:doc
元素将不会转换为配置属性,doc:desc
元素将成为名为“desc”和名称空间的Configuration
节点http://myco.com/documentation“。widget
元素将具有命名空间“”。
如果禁用了命名空间支持(DefaultConfigurationBuilder的默认设置),则上述XML将直接转换为Configuration
节点。my-system
节点将有一个名为“xmlns:doc”的属性和一个名为“doc:desc”的子节点。
假设Configuration
对象名为conf
,以下是如何检索数据:
CodeNo名称空间具有名称空间conf. #getName()
我的系统conf. #getAttributeNames().length
21conf. #getChildren()().length
2conf. #getAttributeAsFloat(String)("version")
1.3conf. #getChild(String)("widget"). #getAttribute(String)("name")
fooWidget[$19$]true``conf. #getChild(String)("widget"). #getLocation()
file:///home/jeff/tmp/java/avalon/src/java/new.xconf:4:60这是一个高度虚构的配置文件配置异常conf. #getChild(String)("desc"). #getNamespace()
http://myco.com/documentation"
类型安全实用程序方法用于检索属性和元素值,如String
、int
、long
、float
和boolean
。
####杂集
目前,配置树一次只能遍历一个节点,例如通过#getChild(String)或#getchilds()。在未来的版本中,可以使用类似XPath的语法访问子节点。
检查属性是否存在可按如下方式进行:
String value = conf.getAttribute( "myAttribute", null );
if ( null == value )
{
// Do the processing applicable if the attribute isn't present.
}
代码示例来源:origin: plutext/docx4j
if (cfg.getChild("use-cache", false) != null) {
try {
fontManager.setUseCache(
cfg.getChild("use-cache").getValueAsBoolean());
} catch (ConfigurationException mfue) {
LogUtil.handleException(log, mfue, true);
if (cfg.getChild("font-base", false) != null) {
try {
fontManager.setFontBaseURL(
cfg.getChild("font-base").getValue(null));
} catch (MalformedURLException mfue) {
LogUtil.handleException(log, mfue, true);
Configuration fontsCfg = cfg.getChild("fonts", false);
if (fontsCfg != null) {
Configuration substitutionsCfg = fontsCfg.getChild("substitutions", false);
if (substitutionsCfg != null) {
FontSubstitutionsConfigurator fontSubstitutionsConfigurator
Configuration referencedFontsCfg = fontsCfg.getChild("referenced-fonts", false);
if (referencedFontsCfg != null) {
createReferencedFontsMatcher(referencedFontsCfg, strict, fontManager);
代码示例来源:origin: plutext/docx4j
private static void createReferencedFontsMatcher(Configuration referencedFontsCfg,
boolean strict, FontManager fontManager) throws FOPException {
List matcherList = new java.util.ArrayList();
Configuration[] matches = referencedFontsCfg.getChildren("match");
for (int i = 0; i < matches.length; i++) {
try {
matcherList.add(new FontFamilyRegExFontTripletMatcher(
matches[i].getAttribute("font-family")));
} catch (ConfigurationException ce) {
LogUtil.handleException(log, ce, strict);
continue;
}
}
FontTriplet.Matcher orMatcher = new OrFontTripletMatcher(
(FontTriplet.Matcher[])matcherList.toArray(
new FontTriplet.Matcher[matcherList.size()]));
fontManager.setReferencedFontsMatcher(orMatcher);
}
代码示例来源:origin: plutext/docx4j
/**
* Configures a font substitution catalog
*
* @param substitutions font substitutions
* @throws FOPException if something's wrong with the config data
*/
public void configure(FontSubstitutions substitutions) throws FOPException {
Configuration[] substitutionCfgs = cfg.getChildren("substitution");
for (int i = 0; i < substitutionCfgs.length; i++) {
Configuration fromCfg = substitutionCfgs[i].getChild("from", false);
if (fromCfg == null) {
throw new FOPException("'substitution' element without child 'from' element");
}
Configuration toCfg = substitutionCfgs[i].getChild("to", false);
if (fromCfg == null) {
throw new FOPException("'substitution' element without child 'to' element");
}
FontQualifier fromQualifier = getQualfierFromConfiguration(fromCfg);
FontQualifier toQualifier = getQualfierFromConfiguration(toCfg);
FontSubstitution substitution = new FontSubstitution(fromQualifier, toQualifier);
substitutions.add(substitution);
}
}
}
代码示例来源:origin: org.apache.fulcrum/fulcrum-factory
@Override
public void configure(Configuration conf) throws ConfigurationException
{
final Configuration[] loaders = conf.getChildren(CLASS_LOADER);
if (loaders != null)
{
loaderNames = new String[loaders.length];
for (int i = 0; i < loaders.length; i++)
{
loaderNames[i] = loaders[i].getValue();
}
}
final Configuration factories = conf.getChild(OBJECT_FACTORY, false);
if (factories != null)
{
// Store the factory to the table as a string and
// instantiate it by using the service when needed.
Configuration[] nameVal = factories.getChildren();
for (Configuration entry : nameVal)
objectFactoryClasses.put(entry.getName(), entry.getValue());
}
}
代码示例来源:origin: org.apache.fulcrum/fulcrum-yaafi
/**
* @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
*/
public void configure(Configuration configuration) throws ConfigurationException {
super.configure(configuration);
this.maxArgLength = configuration.getChild("maxArgLength").getValueAsInteger(MAX_ARG_LENGTH);
this.toStringBuilderClassName = configuration.getChild("toStringBuilderClass")
.getValue(ArgumentToStringBuilderImpl.class.getName());
this.monitorAllExceptions = configuration.getChild("monitorAllExceptions").getValueAsBoolean(true);
}
代码示例来源:origin: org.apache.cocoon/cocoon-sitemap-impl
public ProcessingNode buildNode(Configuration config) throws Exception {
String actionSetName = config.getAttribute("name");
Configuration[] childrenConfig = config.getChildren();
for (int i = 0; i < childrenConfig.length; i++) {
Configuration childConfig = childrenConfig[i];
String name = childConfig.getName();
actions[i] = childConfig.getAttribute("action", null);
} else {
String msg = "Unknown element " + name + " in action-set at " + childConfig.getLocation();
throw new ConfigurationException(msg);
代码示例来源:origin: org.codehaus.plexus/plexus-ftpd
/**
* Configure user manager - third step.
*/
public void configure(Configuration config) throws ConfigurationException {
mConfig = config;
Configuration adminConf = mConfig.getChild("ftp-admin-name", false);
mstAdminName = "admin";
if(adminConf != null) {
mstAdminName = adminConf.getValue(mstAdminName);
}
mBaseDirectory = config.getChild("base-directory").getValue(null);
if(mBaseDirectory == null)
throw new ConfigurationException("Missing configuration element 'base-directory'");
}
代码示例来源:origin: org.apache.fulcrum/fulcrum-yaafi
/**
* @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
*/
public void configure(Configuration configuration) throws ConfigurationException {
super.configure(configuration);
this.reportTimeout = configuration.getChild("reportTimeout").getValueAsLong(0);
// parse the performance monitor class name
this.performanceMonitorClassName = configuration.getChild("performanceMonitorClassName")
.getValue(DEFAULT_PERFORMANCEMONITOR_CLASSNAME);
// parse the report file name
String reportFileName = configuration.getChild("reportFile").getValue("./javasimon.html");
this.reportFile = this.makeAbsoluteFile(reportFileName);
// determine when to create the next report
this.nextReportTimestamp = System.currentTimeMillis() + this.reportTimeout;
// do we create a report on disposal
this.reportOnExit = configuration.getChild("reportOnExit").getValueAsBoolean(false);
}
代码示例来源:origin: org.apache.fulcrum/fulcrum-security-api
/**
* Avalon component lifecycle method
*/
@Override
public void configure(Configuration conf) throws ConfigurationException
{
algorithm = conf.getChild("algorithm").getValue();
cipher = conf.getChild("cipher").getValue();
}
代码示例来源:origin: org.apache.fulcrum/fulcrum-yaafi
this.reconfigurationDelay = configuration.getChild(RECONFIGURATION_DELAY_KEY)
.getValueAsInteger(RECONFIGURATION_DELAY_DEFAULT);
this.disposalDelay = configuration.getChild(DISPOSAL_DELAY_KEY).getValueAsInteger(DISPOSAL_DELAY_DEFAULT);
this.hasDynamicProxies = configuration.getChild(DYNAMICPROXY_ENABLED_KEY).getValueAsBoolean(false);
configuration.getChild(CONTAINERFLAVOUR_CONFIG_KEY).getValue(COMPONENT_CONTAINERFLAVOUR_VALUE));
Configuration currComponentRoles = configuration.getChild(COMPONENT_ROLE_KEYS);
currComponentRoles.getChild(COMPONENT_LOCATION_KEY).getValue(COMPONENT_ROLE_VALUE));
currComponentRoles.getChild(CONTAINERFLAVOUR_CONFIG_KEY).getValue(COMPONENT_ROLECONFIGFLAVOUR_VALUE));
this.setComponentRolesEncrypted(currComponentRoles.getChild(COMPONENT_ISENCRYPTED_KEY).getValue("false"));
Configuration currComponentConfiguration = configuration.getChild(COMPONENT_CONFIG_KEY);
currComponentConfiguration.getChild(COMPONENT_LOCATION_KEY).getValue(COMPONENT_CONFIG_VALUE));
currComponentConfiguration.getChild(COMPONENT_ISENCRYPTED_KEY).getValue("false"));
this.componentConfigurationPropertiesResolverConfig = configuration.getChild(COMPONENT_CONFIG_PROPERTIES_KEY);
Configuration currParameters = configuration.getChild(COMPONENT_PARAMETERS_KEY);
currParameters.getChild(COMPONENT_LOCATION_KEY).getValue(COMPONENT_PARAMETERS_VALUE));
代码示例来源:origin: org.codehaus.plexus/plexus-ftpd
/**
* Configure user manager - third step.
*/
public void configure(Configuration config) throws ConfigurationException {
mConfig = config;
// get server address
Configuration tmpConf = mConfig.getChild("allow-ip", false);
mbAllowIp = false;
if(tmpConf != null) {
mbAllowIp = tmpConf.getValueAsBoolean(mbAllowIp);
}
mBaseDirectory = config.getChild("base-directory").getValue(null);
if(mBaseDirectory == null)
throw new ConfigurationException("Missing configuration element 'base-directory'");
}
代码示例来源:origin: org.apache.cocoon/cocoon-sitemap-impl
/**
* Configures the database access helper.
*
* Takes all elements nested in component declaration and stores
* them as key-value pairs in <code>settings</code>. Nested
* configuration option are not catered for. This way global
* configuration options can be used.
*
* For nested configurations override this function.
* */
public void configure(Configuration conf) throws ConfigurationException {
Configuration[] parameters = conf.getChildren();
this.settings = new HashMap(parameters.length);
for (int i = 0; i < parameters.length; i++) {
String key = parameters[i].getName();
String val = parameters[i].getValue("");
this.settings.put (key, val);
}
}
代码示例来源:origin: org.apache.fulcrum/fulcrum-yaafi
/**
* @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
*/
public void configure(Configuration configuration) throws ConfigurationException {
Configuration[] interceptorConfigList = configuration.getChild("interceptors").getChildren("interceptor");
this.defaultInterceptorList = new String[interceptorConfigList.length];
for (int i = 0; i < interceptorConfigList.length; i++) {
this.defaultInterceptorList[i] = interceptorConfigList[i].getValue();
}
}
代码示例来源:origin: org.apache.fulcrum/fulcrum-yaafi
/**
* @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
*/
public void configure(Configuration configuration) throws ConfigurationException {
// limit to minimum interval of 1 second
this.interval = Math.max(configuration.getAttributeAsInteger("interval", 5000), 1000);
this.getLogger().debug("Monitoring the resources every " + this.interval + " ms");
if (configuration.getChild("entry", false) != null) {
Configuration shutdownConfig = configuration.getChild("entry");
String shutdownEntryLocation = shutdownConfig.getChild("location").getValue();
this.shutdownEntry = new ShutdownEntry(this.getLogger(), this.applicationDir, shutdownEntryLocation,
shutdownConfig.getChild("useSystemExit").getValueAsBoolean(false));
this.getLogger().debug("Using a shutdown entry : " + shutdownEntryLocation);
} else {
this.shutdownEntry = null;
this.getLogger().debug("No shutdown entry defined");
}
}
代码示例来源:origin: com.cloudhopper.proxool/proxool
/**
* Check that all top level elements are named proxool and hand them to
* {@link XMLConfigurator}.
* @param configuration the configuration handed over by the Avalon Framework.
* @throws ConfigurationException if the configuration fails.
*/
public void configure(Configuration configuration) throws ConfigurationException {
final XMLConfigurator xmlConfigurator = new XMLConfigurator();
this.closeOnDispose = configuration.getAttributeAsBoolean(CLOSE_ON_DISPOSE_ATTRIBUTE, true);
final Configuration[] children = configuration.getChildren();
for (int i = 0; i < children.length; ++i) {
if (!children[i].getName().equals(ProxoolConstants.PROXOOL)) {
throw new ConfigurationException("Found element named " + children[i].getName() + ". Only "
+ ProxoolConstants.PROXOOL + " top level elements are alowed.");
}
}
try {
xmlConfigurator.startDocument();
reportProperties(xmlConfigurator, configuration.getChildren());
xmlConfigurator.endDocument();
} catch (SAXException e) {
throw new ConfigurationException("", e);
}
}
代码示例来源:origin: org.apache.avalon.cornerstone.scheduler/cornerstone-scheduler-api
throws ConfigurationException
final String type = conf.getAttribute( "type" );
conf.getChild( "offset", true ).getValueAsInteger( 0 );
final int period =
conf.getChild( "period", true ).getValueAsInteger( -1 );
conf.getChild( "minute" ).getValueAsInteger( -1 );
final int hour =
conf.getChild( "hour" ).getValueAsInteger( -1 );
final int day =
conf.getChild( "day" ).getValueAsInteger( -1 );
final int month =
conf.getChild( "month" ).getValueAsInteger( -1 );
final int year =
conf.getChild( "year" ).getValueAsInteger( -1 );
final boolean dayOfWeek =
conf.getChild( "day" ).getAttributeAsBoolean( "week", false );
throw new ConfigurationException( "Unknown trigger type" );
代码示例来源:origin: org.apache.cocoon/cocoon-sitemap-impl
/**
* Configure the tree processor:
* <processor file="{Location of the sitemap}"
* check-reload="{true|false}"
* config="{Location of sitemap tree processor config}>
* <reload delay="10"/>
* </processor>
*
* Only the file attribute is required; everything else is optional.
*
* @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
*/
public void configure(Configuration config)
throws ConfigurationException {
this.checkReload = config.getAttributeAsBoolean("check-reload",
this.settings.isReloadingEnabled("sitemap"));
// Reload check delay. Default is 1 second.
this.lastModifiedDelay = config.getChild("reload").getAttributeAsLong("delay", this.settings.getReloadDelay("sitemap"));
String fileName = config.getAttribute("file", "sitemap.xmap");
try {
this.source = new DelayedRefreshSourceWrapper(this.resolver.resolveURI(fileName), lastModifiedDelay);
} catch (Exception e) {
throw new ConfigurationException("Cannot resolve " + fileName, e);
}
}
代码示例来源:origin: org.apache.excalibur.containerkit/excalibur-logger
final Configuration configChild = conf.getChild( "address", false );
if( null == configChild )
throw new ConfigurationException( "target address not specified in the config" );
address = InetAddress.getByName( configChild.getAttribute( "hostname" ) );
throw new ConfigurationException( "Host specified in datagram target adress is unknown!", uhex );
int port = configChild.getAttributeAsInteger( "port" );
final Formatter formatter = getFormatter( conf.getChild( "format", false ) );
throw new ConfigurationException( "Failed to create target!", ioex );
代码示例来源:origin: org.apache.cocoon/cocoon-core
/**
* Configure the component.
*
* @param configuration the configuration
*/
public void configure(Configuration configuration) throws ConfigurationException {
this.directory = configuration.getChild(ConfigurationKeys.ROOT_DIRECTORY).getValue("");
String cacheRole = configuration.getChild(ConfigurationKeys.STORE_ROLE).getValue(Store.TRANSIENT_STORE);
try {
this.cache = (Store) this.manager.lookup(cacheRole);
} catch (ServiceException e) {
throw new ConfigurationException("Unable to lookup store '" + cacheRole + "'");
}
this.interval = configuration.getChild(ConfigurationKeys.RELOAD_INTERVAL).getValueAsLong(60000L);
if (getLogger().isDebugEnabled()) {
getLogger().debug("Bundle directory '" + this.directory + "'");
getLogger().debug("Store role '" + cacheRole + "'");
}
}
代码示例来源:origin: org.apache.cocoon/cocoon-sitemap-impl
/**
* The category name is the value of the "category-name" child, or if not
* present, the name of the configuration element.
*/
public void configure(Configuration config) throws ConfigurationException {
super.configure(config);
this.name = config.getChild("category-name").getValue(config.getAttribute("name"));
}
内容来源于网络,如有侵权,请联系作者删除!