本文整理匯總了Java中org.apache.commons.configuration.HierarchicalConfiguration類的典型用法代碼示例。如果您正苦於以下問題:Java HierarchicalConfiguration類的具體用法?Java HierarchicalConfiguration怎麽用?Java HierarchicalConfiguration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HierarchicalConfiguration類屬於org.apache.commons.configuration包,在下文中一共展示了HierarchicalConfiguration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLocalList
import org.apache.commons.configuration.HierarchicalConfiguration; //導入依賴的package包/類
/**
*
* @param config Preferred configuration
* @param altConfig Alternative configuration
* @param inPath XML path
* @param defaultList List of default values to return if none found in config
* @return
*/
private static List<String> getLocalList(HierarchicalConfiguration config, HierarchicalConfiguration altConfig, String inPath,
List<String> defaultList) {
if (config == null) {
throw new IllegalArgumentException("config may not be null");
}
List<Object> objects = config.getList(inPath, altConfig == null ? null : altConfig.getList(inPath, defaultList));
if (objects != null && !objects.isEmpty()) {
List<String> ret = new ArrayList<>(objects.size());
for (Object obj : objects) {
ret.add((String) obj);
}
return ret;
}
return new ArrayList<>(0);
}
示例2: getEseTypes
import org.apache.commons.configuration.HierarchicalConfiguration; //導入依賴的package包/類
/**
* Returns mappings for the ESE "type" element.
*
* @return
* @should return all values
*/
@SuppressWarnings("rawtypes")
public Map<String, String> getEseTypes() {
Map<String, String> ret = new HashMap<>();
List<HierarchicalConfiguration> types = getLocalConfigurationsAt("ese.types.docstruct");
if (types != null) {
for (Iterator it = types.iterator(); it.hasNext();) {
HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next();
ret.put(sub.getString("[@name]"), sub.getString("[@type]"));
// logger.debug("loaded type: " + sub.getString("[@name]") + ": " + sub.getString("[@type]"));
}
}
return ret;
}
示例3: getAdditionalDocstructTypes
import org.apache.commons.configuration.HierarchicalConfiguration; //導入依賴的package包/類
/**
* Returns a list of additional docstruct types "type" element.
*
* @return
* @should return all values
*/
@SuppressWarnings("rawtypes")
public List<String> getAdditionalDocstructTypes() {
List<String> ret = new ArrayList<>();
List<HierarchicalConfiguration> docstructs = getLocalConfigurationsAt("epicur.additionalDocstructTypes.docstruct");
if (docstructs != null) {
for (Iterator it = docstructs.iterator(); it.hasNext();) {
HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next();
ret.add(sub.getString("."));
logger.trace("loaded additional docstruct type: {}", sub.getString("."));
}
}
return ret;
}
示例4: getAllValuesSets
import org.apache.commons.configuration.HierarchicalConfiguration; //導入依賴的package包/類
/**
*
* @return
* @should return all values
*/
public List<Set> getAllValuesSets() {
List<HierarchicalConfiguration> types = getLocalConfigurationsAt("sets.allValuesSet");
if (types != null) {
List<Set> ret = new ArrayList<>(types.size());
for (Iterator<HierarchicalConfiguration> it = types.iterator(); it.hasNext();) {
HierarchicalConfiguration sub = it.next();
Set set = new Set(sub.getString("."), null, null);
set.setTranslate(sub.getBoolean("[@translate]", false));
ret.add(set);
// logger.debug("loaded type: " + sub.getString("[@name]") + ": " + sub.getString("[@type]"));
}
return ret;
}
return new ArrayList<>(0);
}
示例5: getCollectionBlacklist
import org.apache.commons.configuration.HierarchicalConfiguration; //導入依賴的package包/類
/**
* Returns collection names to be omitted from search results, listings etc. from config_viewer.xml
*
* @return
* @should return all key-value pairs
*/
public List<String> getCollectionBlacklist() {
List<String> ret = new ArrayList<>();
if (viewerConfig == null) {
logger.error("Viewer config not loaded, cannot read collection blacklist.");
return ret;
}
List<HierarchicalConfiguration> templates = viewerConfig.configurationsAt("collections.collection");
if (templates != null && !templates.isEmpty()) {
for (Iterator<HierarchicalConfiguration> it = templates.iterator(); it.hasNext();) {
HierarchicalConfiguration sub = it.next();
String field = sub.getString("[@field]");
List<Object> collections = sub.getList("blacklist.collection");
for (Object o : collections) {
ret.add(field + ":" + (String) o);
}
}
}
return ret;
}
示例6: getRestrictedAccessConditions
import org.apache.commons.configuration.HierarchicalConfiguration; //導入依賴的package包/類
/**
* @return
* @should return all values
*/
public List<LicenseType> getRestrictedAccessConditions() {
List<HierarchicalConfiguration> elements = getLocalConfigurationsAt("solr.restrictions.restriction");
if (elements != null) {
List<LicenseType> ret = new ArrayList<>(elements.size());
for (Iterator<HierarchicalConfiguration> it = elements.iterator(); it.hasNext();) {
HierarchicalConfiguration sub = it.next();
Map<String, String> fieldConfig = new HashMap<>();
String value = sub.getString(".");
String field = sub.getString("[@field]", null);
String condition = sub.getString("[@conditions]", null);
ret.add(new LicenseType(field, value, condition));
}
return ret;
}
return new ArrayList<>(0);
}
示例7: parseWaveServerCienaOchPorts
import org.apache.commons.configuration.HierarchicalConfiguration; //導入依賴的package包/類
public static PortDescription parseWaveServerCienaOchPorts(long portNumber, long oduPortSpeed,
HierarchicalConfiguration config,
SparseAnnotations annotations) {
final List<String> tunableType = Lists.newArrayList("Performance-Optimized", "Accelerated");
final String transmitterPath = "ptp-config.transmitter-state";
final String tunablePath = "ptp-config.adv-config.tx-tuning-mode";
final String gridTypePath = "ptp-config.adv-config.wl-spacing";
final String frequencyPath = "ptp-config.adv-config.frequency";
boolean isEnabled = config.getString(transmitterPath).equals("enabled");
boolean isTunable = tunableType.contains(config.getString(tunablePath));
//FIXME change when all optical types have two way information methods, see jira tickets
final int speed100GbpsinMbps = 100000;
OduSignalType oduSignalType = oduPortSpeed == speed100GbpsinMbps ? OduSignalType.ODU4 : null;
GridType gridType = config.getString(gridTypePath).equals("FlexGrid") ? GridType.FLEX : null;
ChannelSpacing chSpacing = gridType == GridType.FLEX ? ChannelSpacing.CHL_6P25GHZ : null;
//Working in Ghz //(Nominal central frequency - 193.1)/channelSpacing = spacingMultiplier
final int baseFrequency = 193100;
int spacingMult = (int) (toGbps((Integer.parseInt(config.getString(frequencyPath)) -
baseFrequency)) / toGbpsFromHz(chSpacing.frequency().asHz())); //FIXME is there a better way ?
return ochPortDescription(PortNumber.portNumber(portNumber), isEnabled, oduSignalType, isTunable,
new OchSignal(gridType, chSpacing, spacingMult, 1), annotations);
}
示例8: parseFujitsuT100Ports
import org.apache.commons.configuration.HierarchicalConfiguration; //導入依賴的package包/類
/**
* Parses a configuration and returns a set of ports for the fujitsu T100.
* @param cfg a hierarchical configuration
* @return a list of port descriptions
*/
private static List<PortDescription> parseFujitsuT100Ports(HierarchicalConfiguration cfg) {
AtomicInteger counter = new AtomicInteger(1);
List<PortDescription> portDescriptions = Lists.newArrayList();
List<HierarchicalConfiguration> subtrees =
cfg.configurationsAt("data.interfaces.interface");
for (HierarchicalConfiguration portConfig : subtrees) {
if (!portConfig.getString("name").contains("LCN") &&
!portConfig.getString("name").contains("LMP") &&
portConfig.getString("type").equals("ianaift:ethernetCsmacd")) {
portDescriptions.add(parseT100OduPort(portConfig, counter.getAndIncrement()));
} else if (portConfig.getString("type").equals("ianaift:otnOtu")) {
portDescriptions.add(parseT100OchPort(portConfig, counter.getAndIncrement()));
}
}
return portDescriptions;
}
示例9: getInterfacesFromConfig
import org.apache.commons.configuration.HierarchicalConfiguration; //導入依賴的package包/類
/**
* Parses device configuration and returns the descriptions of the device
* interfaces.
*
* @param cfg an hierarchical configuration
* @return list of interface descriptions for the device
*/
public static List<DeviceInterfaceDescription> getInterfacesFromConfig(
HierarchicalConfiguration cfg) {
List<DeviceInterfaceDescription> intfs = Lists.newArrayList();
List<HierarchicalConfiguration> subtrees =
cfg.configurationsAt("data.xml-config-data.Device-Configuration.interface");
for (HierarchicalConfiguration intfConfig :subtrees) {
String intfName = getInterfaceName(intfConfig);
DeviceInterfaceDescription.Mode intfMode = getInterfaceMode(intfConfig);
List<VlanId> intfVlans = getInterfaceVlans(intfConfig, intfMode);
short intfLimit = getInterfaceLimit(intfConfig);
boolean intfLimited = (intfLimit == NO_LIMIT ? false : true);
DeviceInterfaceDescription intf =
new DefaultDeviceInterfaceDescription(intfName,
intfMode,
intfVlans,
intfLimited,
intfLimit);
intfs.add(intf);
}
return intfs;
}
示例10: findPath
import org.apache.commons.configuration.HierarchicalConfiguration; //導入依賴的package包/類
private String findPath(HierarchicalConfiguration cfg, String element) {
Iterator<String> it = cfg.getKeys();
while (it.hasNext()) {
String key = it.next();
String[] arr = key.split("\\.");
for (int i = 0; i < arr.length; i++) {
if (element.equals(arr[i])) {
String completeKey = "";
for (int j = 0; j <= i; j++) {
completeKey = completeKey + "." + arr[j];
}
return completeKey.substring(1);
}
}
}
return null;
}
示例11: loadDriver
import org.apache.commons.configuration.HierarchicalConfiguration; //導入依賴的package包/類
/**
* Loads a driver from the supplied hierarchical configuration.
*
* @param driverCfg hierarchical configuration containing the driver definition
* @param resolver driver resolver
* @return driver
*/
public DefaultDriver loadDriver(HierarchicalConfiguration driverCfg,
DriverResolver resolver) {
String name = driverCfg.getString(NAME);
String parentsString = driverCfg.getString(EXTENDS, "");
List<Driver> parents = Lists.newArrayList();
if (!parentsString.equals("")) {
List<String> parentsNames;
if (parentsString.contains(",")) {
parentsNames = Arrays.asList(parentsString.replace(" ", "").split(","));
} else {
parentsNames = Lists.newArrayList(parentsString);
}
parents = parentsNames.stream().map(parent -> (parent != null) ?
resolve(parent, resolver) : null).collect(Collectors.toList());
}
String manufacturer = driverCfg.getString(MFG, "");
String hwVersion = driverCfg.getString(HW, "");
String swVersion = driverCfg.getString(SW, "");
return new DefaultDriver(name, parents, manufacturer, hwVersion, swVersion,
parseBehaviours(driverCfg),
parseProperties(driverCfg));
}
示例12: build
import org.apache.commons.configuration.HierarchicalConfiguration; //導入依賴的package包/類
public RemoteConfig build() {
int port = config.getInt("port", 7210);
String className = config.getString("className");
int maxQueue = config.getInt("maxQueue", Runtime.getRuntime().availableProcessors() * 100);
int maxThread = config.getInt("maxThread", Runtime.getRuntime().availableProcessors());
int replicaPort = config.getInt("replicaPort", 7310);
freq = config.getInt("freq", 10);
boolean useNio = config.getBoolean("useNio", true);
List<HierarchicalConfiguration> list = (List<HierarchicalConfiguration>) config.configurationsAt(STORE);
if (list == null || list.size() == 0 ) throw new RuntimeException("list is null or freq ==0 for node "+STORE);
List<StoreConfig> toReturn = new CopyOnWriteArrayList<StoreConfig>();
for( HierarchicalConfiguration each : list) {
toReturn.add( buildStoreConfig( each));
}
RemoteConfig remoteConfig = new RemoteConfig(maxQueue, maxThread, port, className, toReturn, replicaPort, freq);
remoteConfig.setUseNio( useNio);
return remoteConfig;
}
示例13: build
import org.apache.commons.configuration.HierarchicalConfiguration; //導入依賴的package包/類
public List<ClusterNodes> build() {
List<HierarchicalConfiguration> list = (List<HierarchicalConfiguration>) config.configurationsAt(CLUSTERS);
if (list == null || list.size() == 0 ) throw new RuntimeException("list is null or freq ==0 for node "+CLUSTERS);
List<ClusterNodes> toReturn = new CopyOnWriteArrayList<ClusterNodes>();
StringBuilder stringBuilder = new StringBuilder();
HashSet<Short> sets = new HashSet<Short>();
int error = 0;
for (HierarchicalConfiguration each : list) {
ClusterNodes clusterNode = buildClusterNodes(each);
if (sets.contains( clusterNode.getId())) {
error++;
stringBuilder.append(" cluster no "+ clusterNode.getId());
}
else
sets.add( clusterNode.getId() );
toReturn.add( clusterNode);
}
if ( error > 0 ) {
throw new RuntimeException(error+" duplicate clusters , "+stringBuilder.toString()+" in clusters.xml" );
}
else
return toReturn;
}
示例14: loadConfiguration
import org.apache.commons.configuration.HierarchicalConfiguration; //導入依賴的package包/類
private void loadConfiguration() {
Properties sysProps = System.getProperties();
String configFileName = sysProps.getProperty("test.config.filename");
if (StringUtils.isEmpty(configFileName)) {
configFileName = defaultConfigurationFileName;
}
try {
AllConfiguration = new DefaultConfigurationBuilder(configFileName).getConfiguration();
((HierarchicalConfiguration) AllConfiguration).setExpressionEngine(new XPathExpressionEngine());
} catch (Exception e) {
Fail.fail("failed to read config file", e);
log.error("Failed to read config file", e);
}
}
示例15: load
import org.apache.commons.configuration.HierarchicalConfiguration; //導入依賴的package包/類
/**
* Loads and parse CME MDP Configuration.
*
* @param uri URI to CME MDP Configuration (config.xml, usually available on CME FTP)
* @throws ConfigurationException if failed to parse configuration file
* @throws MalformedURLException if URI to Configuration is malformed
*/
private void load(final URI uri) throws ConfigurationException, MalformedURLException {
// todo: if to implement the same via standard JAXB then dep to apache commons configuration will be not required
final XMLConfiguration configuration = new XMLConfiguration();
configuration.setDelimiterParsingDisabled(true);
configuration.load(uri.toURL());
for (final HierarchicalConfiguration channelCfg : configuration.configurationsAt("channel")) {
final ChannelCfg channel = new ChannelCfg(channelCfg.getString("[@id]"), channelCfg.getString("[@label]"));
for (final HierarchicalConfiguration connCfg : channelCfg.configurationsAt("connections.connection")) {
final String id = connCfg.getString("[@id]");
final FeedType type = FeedType.valueOf(connCfg.getString("type[@feed-type]"));
final TransportProtocol protocol = TransportProtocol.valueOf(connCfg.getString("protocol").substring(0, 3));
final Feed feed = Feed.valueOf(connCfg.getString("feed"));
final String ip = connCfg.getString("ip");
final int port = connCfg.getInt("port");
final List<String> hostIPs = Arrays.asList(connCfg.getStringArray("host-ip"));
final ConnectionCfg connection = new ConnectionCfg(feed, id, type, protocol, ip, hostIPs, port);
channel.addConnection(connection);
connCfgs.put(connection.getId(), connection);
}
channelCfgs.put(channel.getId(), channel);
}
}