org.apache.felix.utils.properties.Properties.getProperty()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(134)

本文整理了Java中org.apache.felix.utils.properties.Properties.getProperty()方法的一些代码示例,展示了Properties.getProperty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Properties.getProperty()方法的具体详情如下:
包路径:org.apache.felix.utils.properties.Properties
类名称:Properties
方法名:getProperty

Properties.getProperty介绍

[英]Searches for the property with the specified key in this property list.
[中]在此属性列表中搜索具有指定键的属性。

代码示例

代码示例来源:origin: apache/karaf

private String getPropertyOrFail(String propertyName) {
  String value = props.getProperty(propertyName);
  if (value == null) {
    throw new IllegalArgumentException("Property " + propertyName + " must be set in the etc/" + CONFIG_PROPERTIES_FILE_NAME + " configuration file");
  }
  return value;
}

代码示例来源:origin: apache/karaf

private int getDefaultBundleStartLevel(int ibsl) {
  try {
    String str = props.getProperty("karaf.startlevel.bundle");
    if (str != null) {
      ibsl = Integer.parseInt(str);
    }
  } catch (Throwable t) {
  }
  return ibsl;
}

代码示例来源:origin: apache/karaf

private String[] getSecurityProviders() {
  String prop = props.getProperty(SECURITY_PROVIDERS);
  return (prop != null) ? prop.split(",") : new String[] {};
}

代码示例来源:origin: apache/karaf

String getLogFilePath() {
  String filename = configProps == null ? null : configProps.getProperty(KARAF_BOOTSTRAP_LOG);
  if (filename != null) {
    return filename;
  }
  Properties props = loadPaxLoggingConfig();
   // Make a best effort to log to the default file appender configured for log4j
   return props.getProperty(LOG4J_APPENDER_FILE, "${karaf.log}/karaf.log");
}

代码示例来源:origin: apache/karaf

public DefaultJDBCLock(Properties props) {
  BootstrapLogManager.configureLogger(LOG);
  this.url = props.getProperty(PROPERTY_LOCK_URL);
  this.driver = props.getProperty(PROPERTY_LOCK_JDBC_DRIVER);
  this.user = props.getProperty(PROPERTY_LOCK_JDBC_USER, DEFAULT_USER);
  this.password = props.getProperty(PROPERTY_LOCK_JDBC_PASSWORD, DEFAULT_PASSWORD);
  this.table = props.getProperty(PROPERTY_LOCK_JDBC_TABLE, DEFAULT_TABLE);
  this.clusterName = props.getProperty(PROPERTY_LOCK_JDBC_CLUSTERNAME, DEFAULT_CLUSTERNAME);
  this.timeout = Integer.parseInt(props.getProperty(PROPERTY_LOCK_JDBC_TIMEOUT, DEFAULT_TIMEOUT));
  this.statements = createStatements();
  
  init();
}

代码示例来源:origin: apache/karaf

public static Lock createLock(Properties props) {
  if (Boolean.parseBoolean(props.getProperty(PROPERTY_USE_LOCK, "true"))) {
    return new NoLock();
  }
  String clz = props.getProperty(PROPERTY_LOCK_CLASS, PROPERTY_LOCK_CLASS_DEFAULT);
  try {
    return (Lock) Class.forName(clz).getConstructor(Properties.class).newInstance(props);
  } catch (Exception e) {
    throw new RuntimeException("Exception instantiating lock class " + clz, e);
  }
}

代码示例来源:origin: apache/karaf

public GenericJDBCLock(Properties props) {
  BootstrapLogManager.configureLogger(LOG);
  this.url = props.getProperty(PROPERTY_LOCK_URL);
  this.driver = props.getProperty(PROPERTY_LOCK_JDBC_DRIVER);
  this.table = props.getProperty(PROPERTY_LOCK_JDBC_TABLE, DEFAULT_TABLE);
  this.clusterName = props.getProperty(PROPERTY_LOCK_JDBC_CLUSTERNAME, DEFAULT_CLUSTERNAME);
  this.table_id = props.getProperty(PROPERTY_LOCK_JDBC_TABLE_ID, DEFAULT_TABLE_ID);
  this.lock_delay = Integer.parseInt(props.getProperty(ConfigProperties.PROPERTY_LOCK_DELAY, ConfigProperties.DEFAULT_LOCK_DELAY));
  this.statements = createStatements();
  String url = this.url;
  if (url.toLowerCase().startsWith("jdbc:derby")) {
    url = (url.toLowerCase().contains("create=true")) ? url : url + ";create=true";
  }
  boolean cacheEnabled = Boolean.parseBoolean(props.getProperty(PROPERTY_LOCK_JDBC_CACHE, DEFAULT_CACHE));
  int validTimeout = Integer.parseInt(props.getProperty(PROPERTY_LOCK_JDBC_VALID_TIMEOUT, DEFAULT_VALID_TIMEOUT));
  String user = props.getProperty(PROPERTY_LOCK_JDBC_USER, DEFAULT_USER);
  String password = props.getProperty(PROPERTY_LOCK_JDBC_PASSWORD, DEFAULT_PASSWORD);
  this.dataSource = new GenericDataSource(driver, url, user, password, cacheEnabled, validTimeout);
  init();
}

代码示例来源:origin: org.sonatype.nexus.assemblies/nexus-branding

public NexusFileLock(final Properties properties) {
 if (properties == null) {
  throw new NullPointerException();
 }
 // verify minimum java version
 requireMinimumJavaVersion();
 this.dataDir = properties.getProperty(ConfigProperties.PROP_KARAF_DATA);
 this.file = new File(dataDir, "lock");
}

代码示例来源:origin: org.apache.karaf/org.apache.karaf.client

private static TypedProperties loadProps(File file, Properties context) {
  TypedProperties props = new TypedProperties((name, key, value) -> context.getProperty(value));
  try {
    props.load(file);
  } catch (Exception e) {
    System.err.println("Warning: could not load properties from: " + file + ": " + e);
  }
  return props;
}

代码示例来源:origin: apache/karaf

private static TypedProperties loadProps(File file, Properties context) {
  TypedProperties props = new TypedProperties((name, key, value) -> context.getProperty(value));
  try {
    props.load(file);
  } catch (Exception e) {
    System.err.println("Warning: could not load properties from: " + file + ": " + e);
  }
  return props;
}

代码示例来源:origin: apache/karaf

public SimpleFileLock(Properties props) {
  BootstrapLogManager.configureLogger(LOG);
  try {
    String lock = props.getProperty(PROPERTY_LOCK_DIR);
    if (lock != null) {
      File karafLock = getKarafLock(new File(lock), props);
      props.setProperty(PROPERTY_LOCK_DIR, karafLock.getPath());
    } else {
      props.setProperty(PROPERTY_LOCK_DIR, System.getProperty(PROP_KARAF_BASE));
    }
    File base = new File(props.getProperty(PROPERTY_LOCK_DIR));
    lockPath = new File(base, "lock"); 
    lockFile = new RandomAccessFile(lockPath, "rw");
  } catch (IOException ioe){
    throw new RuntimeException("Karaf can't startup, make sure the log file can be accessed and written by the user starting Karaf : " + ioe.getMessage(), ioe);
  } catch (Exception e){
    throw new RuntimeException("Could not create file lock: " + e.getMessage(), e);
  }
}

代码示例来源:origin: apache/karaf

public List<BundleInfo> readBundlesFromStartupProperties(File startupPropsFile) {
  Properties startupProps = PropertiesLoader.loadPropertiesOrFail(startupPropsFile);
  List<BundleInfo> bundeList = new ArrayList<>();
  for (String key : startupProps.keySet()) {
    try {
      BundleInfo bi = new BundleInfo();
      bi.uri = new URI(key);
      String startlevelSt = startupProps.getProperty(key).trim();
      bi.startLevel = new Integer(startlevelSt);
      bundeList.add(bi);
    } catch (Exception e) {
      throw new RuntimeException("Error loading startup bundle list from " + startupPropsFile + " at " + key, e);
    }
  }
  return bundeList; 
}

代码示例来源:origin: apache/karaf

private static File getKarafLock(File lock,Properties props) {
  File rc = null;
  String path = lock.getPath();
  if (path != null) {
    rc = validateDirectoryExists(path, "Invalid " + PROPERTY_LOCK_DIR + " system property");
  }
  if (rc == null) {
    path = props.getProperty(PROP_KARAF_BASE);
    if (path != null) {
      rc = validateDirectoryExists(path, "Invalid " + PROP_KARAF_BASE + " property");
    }
  }
  if (rc == null) {
    rc = lock;
  }
  return rc;
}

代码示例来源:origin: apache/karaf

props.put("karaf.log", new File(new File(new File(instance.loc), "data"), "log").getCanonicalPath());
InterpolationHelper.performSubstitution(props, null, true, false, true);
int port = Integer.parseInt(props.getProperty(KARAF_SHUTDOWN_PORT, "0"));
String host = props.getProperty(KARAF_SHUTDOWN_HOST, "localhost");
String portFile = props.getProperty(KARAF_SHUTDOWN_PORT_FILE);
String shutdown = props.getProperty(KARAF_SHUTDOWN_COMMAND, DEFAULT_SHUTDOWN_COMMAND);
if (port == 0 && portFile != null) {
  BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(portFile)));
  s.getOutputStream().write(shutdown.getBytes());
  s.close();
  long stopTimeout = Long.parseLong(props.getProperty(KARAF_SHUTDOWN_TIMEOUT,
                            Long.toString(getStopTimeout())));
  long t = System.currentTimeMillis() + stopTimeout;

代码示例来源:origin: org.apache.aries.blueprint/org.apache.aries.blueprint.core

v = properties.getProperty(val);
if (v != null) {
  LOGGER.debug("Found property {} from locations with value {}", val, v);

代码示例来源:origin: apache/karaf

private void reformatClauses(Properties config, String key) {
  String val = config.getProperty(key);
  if (val != null && !val.isEmpty()) {
    List<String> comments = config.getComments(key);
    Clause[] clauses = org.apache.felix.utils.manifest.Parser.parseHeader(val);
    Set<String> strings = new LinkedHashSet<>();
    for (Clause clause : clauses) {
      strings.add(clause.toString());
    }
    List<String> lines = new ArrayList<>();
    lines.add("");
    int index = 0;
    for (String string : strings) {
      String s = "    " + string;
      if (index++ < strings.size() - 1) {
        s += ", ";
      }
      lines.add(s);
    }
    config.put(key, comments, lines);
  }
}

代码示例来源:origin: apache/karaf

attributes.putValue(Constants.BUNDLE_VERSION, "0.0.0");
String exportPackages = configProps.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES, "");
if ("".equals(exportPackages.trim())) {
  throw new IllegalArgumentException("\"org.osgi.framework.system.packages\" property should specify system bundle" +
  exportPackages += "," + configProps.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA);
String systemCaps = configProps.getProperty(Constants.FRAMEWORK_SYSTEMCAPABILITIES, "");
attributes.putValue(Constants.PROVIDE_CAPABILITY, systemCaps);

代码示例来源:origin: org.apache.karaf.profile/org.apache.karaf.profile.core

attributes.putValue(Constants.BUNDLE_VERSION, "0.0.0");
String exportPackages = configProps.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES, "");
if ("".equals(exportPackages.trim())) {
  throw new IllegalArgumentException("\"org.osgi.framework.system.packages\" property should specify system bundle" +
  exportPackages += "," + configProps.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA);
String systemCaps = configProps.getProperty(Constants.FRAMEWORK_SYSTEMCAPABILITIES, "");
attributes.putValue(Constants.PROVIDE_CAPABILITY, systemCaps);

代码示例来源:origin: org.apache.karaf.profile/org.apache.karaf.profile.core

private void reformatClauses(Properties config, String key) {
  String val = config.getProperty(key);
  if (val != null && !val.isEmpty()) {
    List<String> comments = config.getComments(key);
    Clause[] clauses = org.apache.felix.utils.manifest.Parser.parseHeader(val);
    Set<String> strings = new LinkedHashSet<>();
    for (Clause clause : clauses) {
      strings.add(clause.toString());
    }
    List<String> lines = new ArrayList<>();
    lines.add("");
    int index = 0;
    for (String string : strings) {
      String s = "    " + string;
      if (index++ < strings.size() - 1) {
        s += ", ";
      }
      lines.add(s);
    }
    config.put(key, comments, lines);
  }
}

代码示例来源:origin: io.fabric8/fabric-zookeeper

void configureInternal(Map<String, ?> conf) throws Exception {
  configuration = configurer.configure(conf, this);
  if (Strings.isNullOrBlank(runtimeId)) {
    throw new IllegalArgumentException("Runtime id must not be null or empty.");
  }
  if (Strings.isNullOrBlank(localResolver)) {
    localResolver = globalResolver;
  }
  String decodedZookeeperPassword = null;
  Properties userProps = new Properties();
  try {
    userProps.load(new File(confDir , "users.properties"));
  } catch (IOException e) {
    LOGGER.warn("Failed to load users from etc/users.properties. No users will be imported.", e);
  }
  if (Strings.isNotBlank(zookeeperPassword)) {
    decodedZookeeperPassword = PasswordEncoder.decode(zookeeperPassword);
  } else if (userProps.containsKey(DEFAULT_ADMIN_USER)) {
    String passwordAndRole = userProps.getProperty(DEFAULT_ADMIN_USER).trim();
    decodedZookeeperPassword = passwordAndRole.substring(0, passwordAndRole.indexOf(ROLE_DELIMITER));
  } else {
    decodedZookeeperPassword = PasswordEncoder.encode(CreateEnsembleOptions.generatePassword());
  }
  if (userProps.isEmpty()) {
    userProps.put(DEFAULT_ADMIN_USER, decodedZookeeperPassword+ ROLE_DELIMITER + DEFAULT_ADMIN_ROLE);
  }
  options = CreateEnsembleOptions.builder().bindAddress(bindAddress).agentEnabled(agentAutoStart).ensembleStart(ensembleAutoStart).zookeeperPassword(decodedZookeeperPassword)
      .zooKeeperServerPort(zookeeperServerPort).zooKeeperServerConnectionPort(zookeeperServerConnectionPort).autoImportEnabled(profilesAutoImport)
      .importPath(profilesAutoImportPath).resolver(localResolver).globalResolver(globalResolver).users(userProps).profiles(profiles).version(version).build();
}

相关文章