public static String getNSSLibDir() throws Exception { Properties props = System.getProperties(); String osName = props.getProperty("os.name"); if (osName.startsWith("Win")) { osName = "Windows"; NSPR_PREFIX = "lib"; } String osid = osName + "-" + props.getProperty("os.arch") + "-" + props.getProperty("sun.arch.data.model"); String ostype = osMap.get(osid); if (ostype == null) { System.out.println("Unsupported OS, skipping: " + osid); return null; // throw new Exception("Unsupported OS " + osid); } if (ostype.length() == 0) { System.out.println("NSS not supported on this platform, skipping test"); return null; } String libdir = NSS_BASE + SEP + "lib" + SEP + ostype + SEP; System.setProperty("pkcs11test.nss.libdir", libdir); return libdir; }
public static void testEnum() throws Exception { Builder b = new Builder(); b.addClasspath(new File("bin")); b.setProperty("Export-Package", "test.metatype"); b.setProperty("-metatype", "*"); b.build(); assertEquals(0, b.getErrors().size()); assertEquals(0, b.getWarnings().size()); Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.MetatypeTest$Enums.xml"); IO.copy(r.openInputStream(), System.err); Document d = db.parse(r.openInputStream()); assertEquals( "http://www.osgi.org/xmlns/metatype/v1.1.0", d.getDocumentElement().getNamespaceURI()); Properties p = new Properties(); p.setProperty("r", "requireConfiguration"); p.setProperty("i", "ignoreConfiguration"); p.setProperty("o", "optionalConfiguration"); Enums enums = Configurable.createConfigurable(Enums.class, (Map<Object, Object>) p); assertEquals(Enums.X.requireConfiguration, enums.r()); assertEquals(Enums.X.ignoreConfiguration, enums.i()); assertEquals(Enums.X.optionalConfiguration, enums.o()); }
static <T> T set(Class<T> interf, Object value) { Properties p = new Properties(); Method ms[] = interf.getMethods(); for (Method m : ms) { p.put(m.getName(), value); } return Configurable.createConfigurable(interf, (Map<Object, Object>) p); }
// Expand grid search related argument sets @Override protected NanoHTTPD.Response serveGrid(NanoHTTPD server, Properties parms, RequestType type) { String[][] values = new String[_arguments.size()][]; boolean gridSearch = false; for (int i = 0; i < _arguments.size(); i++) { Argument arg = _arguments.get(i); if (arg._gridable) { String value = _parms.getProperty(arg._name); if (value != null) { // Skips grid if argument is an array, except if imbricated expression // Little hackish, waiting for real language boolean imbricated = value.contains("("); if (!arg._field.getType().isArray() || imbricated) { values[i] = split(value); if (values[i] != null && values[i].length > 1) gridSearch = true; } else if (arg._field.getType().isArray() && !imbricated) { // Copy values which are arrays values[i] = new String[] {value}; } } } } if (!gridSearch) return superServeGrid(server, parms, type); // Ignore destination key so that each job gets its own _parms.remove("destination_key"); for (int i = 0; i < _arguments.size(); i++) if (_arguments.get(i)._name.equals("destination_key")) values[i] = null; // Iterate over all argument combinations int[] counters = new int[values.length]; ArrayList<Job> jobs = new ArrayList<Job>(); for (; ; ) { Job job = (Job) create(_parms); Properties combination = new Properties(); for (int i = 0; i < values.length; i++) { if (values[i] != null) { String value = values[i][counters[i]]; value = value.trim(); combination.setProperty(_arguments.get(i)._name, value); _arguments.get(i).reset(); _arguments.get(i).check(job, value); } } job._parms = combination; jobs.add(job); if (!increment(counters, values)) break; } GridSearch grid = new GridSearch(); grid.jobs = jobs.toArray(new Job[jobs.size()]); return grid.superServeGrid(server, parms, type); }
public static void testSpecialConversions() throws URISyntaxException { Properties p = new Properties(); p.put("enumv", "A"); p.put("pattern", ".*"); p.put("clazz", "java.lang.Object"); p.put("constructor", "http://www.aQute.biz"); SpecialConversions trt = Configurable.createConfigurable(SpecialConversions.class, (Map<Object, Object>) p); assertEquals(SpecialConversions.X.A, trt.enumv()); assertEquals(".*", trt.pattern().pattern()); assertEquals(Object.class, trt.clazz()); assertEquals(new URI("http://www.aQute.biz"), trt.constructor()); }
/** * Returns the return type of the property (see the TYPE_... values) Returns -1 if the index is * out of the range [0 ... numProperties() - 1 ] */ public Class getType(int index) { if (auxillary != null) return auxillary.getType(index); if (index < 0 || index >= numProperties()) return null; Class returnType = ((Method) (getMethods.get(index))).getReturnType(); return getTypeConversion(returnType); }
public void load(ActionEvent e) { int returnVal = fc.showOpenDialog(this); if (returnVal != JFileChooser.APPROVE_OPTION) { return; } file = fc.getSelectedFile(); try { InputStream in = new BufferedInputStream(new FileInputStream(file)); Properties newWl = new Properties(); newWl.load(in); in.close(); setWordList(newWl); } catch (IOException ex) { handleException(ex); } }
public Bean(String classPackage, String clazz, ClassLoaderStrategy cls, Bean topLevelBean) throws Exception { // Get the no-arg constructor and create the bean try { Class classOfBean = ObjectXml.getClassOfBean((ClassLoader) cls, classPackage + "." + clazz); Constructor ct = null; // check whether this class is an inner class if (classOfBean.getEnclosingClass() != null) { ct = classOfBean.getConstructor(new Class[] {classOfBean.getEnclosingClass()}); beanObject = ct.newInstance(new Object[] {topLevelBean.getBeanObject()}); } else { ct = classOfBean.getConstructor((Class[]) null); beanObject = ct.newInstance((Object[]) null); } // Get an array of property descriptors beanInfo = Introspector.getBeanInfo(classOfBean); PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors(); // load property descriptors into hashtable propDesc = new Properties(); for (int i = 0; i < pds.length; i++) { propDesc.put(pds[i].getName(), pds[i]); } } catch (Exception e) { System.err.println("Exception creating bean: " + e.getMessage()); e.printStackTrace(); throw e; } }
@Mock(reentrant = true) public boolean shouldRun(Filter filter, Object m) { testMethod = null; if (!coverageMap.isEmpty()) { if (m instanceof JUnit38ClassRunner) { boolean noTestsToRun = verifyTestMethodsInJUnit38TestClassThatShouldRun((JUnit38ClassRunner) m); if (noTestsToRun) { return false; } } else if (m instanceof FrameworkMethod) { testMethod = ((FrameworkMethod) m).getMethod(); Boolean shouldRun = shouldRunTestInCurrentTestRun(Test.class, testMethod); if (shouldRun != null) { return shouldRun; } } } Boolean shouldRun = MethodReflection.invoke(it, shouldRunMethod, filter, m); if (testMethod != null) { testMethods.put(testMethod, shouldRun); } return shouldRun; }
public String[] getCleanSql() { if (cleanSql == null) { // loop over all foreign key constraints List dropForeignKeysSql = new ArrayList(); List createForeignKeysSql = new ArrayList(); Iterator iter = configuration.getTableMappings(); while (iter.hasNext()) { Table table = (Table) iter.next(); if (table.isPhysicalTable()) { Iterator subIter = table.getForeignKeyIterator(); while (subIter.hasNext()) { ForeignKey fk = (ForeignKey) subIter.next(); if (fk.isPhysicalConstraint()) { // collect the drop key constraint dropForeignKeysSql.add( fk.sqlDropString( dialect, properties.getProperty(Environment.DEFAULT_CATALOG), properties.getProperty(Environment.DEFAULT_SCHEMA))); createForeignKeysSql.add( fk.sqlCreateString( dialect, mapping, properties.getProperty(Environment.DEFAULT_CATALOG), properties.getProperty(Environment.DEFAULT_SCHEMA))); } } } } List deleteSql = new ArrayList(); iter = configuration.getTableMappings(); while (iter.hasNext()) { Table table = (Table) iter.next(); deleteSql.add("delete from " + table.getName()); } List cleanSqlList = new ArrayList(); cleanSqlList.addAll(dropForeignKeysSql); cleanSqlList.addAll(deleteSql); cleanSqlList.addAll(createForeignKeysSql); cleanSql = (String[]) cleanSqlList.toArray(new String[cleanSqlList.size()]); } return cleanSql; }
/** * Gets a security property value. * * <p>First, if there is a security manager, its <code>checkPermission</code> method is called * with a <code>java.security.SecurityPermission("getProperty."+key)</code> permission to see if * it's ok to retrieve the specified security property value.. * * @param key the key of the property being retrieved. * @return the value of the security property corresponding to key. * @throws SecurityException if a security manager exists and its <code>{@link * java.lang.SecurityManager#checkPermission}</code> method denies access to retrieve the * specified security property value * @throws NullPointerException is key is null * @see #setProperty * @see java.security.SecurityPermission */ public static String getProperty(String key) { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new SecurityPermission("getProperty." + key)); } String name = props.getProperty(key); if (name != null) name = name.trim(); // could be a class name with trailing ws return name; }
/** * Returns the current value of the property. Simple values (byte, int, etc.) are boxed (into * Byte, Integer, etc.). Returns null if an error occurs or if the index is out of the range [0 * ... numProperties() - 1 ] */ public Object getValue(int index) { if (auxillary != null) return auxillary.getValue(index); if (index < 0 || index >= numProperties()) return null; try { return ((Method) (getMethods.get(index))).invoke(object, new Object[0]); } catch (Exception e) { e.printStackTrace(); return null; } }
protected Object _setValue(int index, Object value) { if (auxillary != null) return auxillary.setValue(index, value); // I think this is right try { if (setMethods.get(index) == null) return null; ((Method) (setMethods.get(index))).invoke(object, new Object[] {value}); return getValue(index); } catch (Exception e) { e.printStackTrace(); return null; } }
public String getDescription(int index) { if (auxillary != null) return auxillary.getDescription(index); if (index < 0 || index >= numProperties()) return null; try { if (desMethods.get(index) == null) return null; return (String) (((Method) (desMethods.get(index))).invoke(object, new Object[0])); } catch (Exception e) { e.printStackTrace(); return null; } }
public boolean isHidden(int index) { if (auxillary != null) return auxillary.isHidden(index); if (index < 0 || index >= numProperties()) return false; try { if (hideMethods.get(index) == null) return false; return ((Boolean) ((Method) (hideMethods.get(index))).invoke(object, new Object[0])) .booleanValue(); } catch (Exception e) { e.printStackTrace(); return false; } }
public void save(ActionEvent e) { if (file == null) { saveAs(e); } try { OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); wordList.store(out, "Generated by JWordPlay"); out.flush(); out.close(); } catch (IOException ex) { handleException(ex); } }
/* * Initialize to default values, if <java.home>/lib/java.security * is not found. */ private static void initializeStatic() { props.put("security.provider.1", "sun.security.provider.Sun"); props.put("security.provider.2", "sun.security.rsa.SunRsaSign"); props.put("security.provider.3", "com.sun.net.ssl.internal.ssl.Provider"); props.put("security.provider.4", "com.sun.crypto.provider.SunJCE"); props.put("security.provider.5", "sun.security.jgss.SunProvider"); props.put("security.provider.6", "com.sun.security.sasl.Provider"); }
public static Properties getEnvironmentVariables() { synchronized (cygstartPath) { if (envVars != null) return envVars; envVars = new Properties(); try (BufferedReader br = new BufferedReader( new InputStreamReader(RUNTIME.exec(comSpec + "env").getInputStream()))) { for (String line = null; (line = br.readLine()) != null; ) { // if (debug) System.out.println("getEnvironmentVariables(): line=" + line); int idx = line.indexOf('='); if (idx > 0) envVars.put(line.substring(0, idx), line.substring(idx + 1)); } } catch (IOException e) { e.printStackTrace(); } return envVars; } }
/** * Take all the properties and translate them to actual values. This method takes the set * properties and traverse them over all entries, including the default properties for that * properties. The values no longer contain macros. * * @return A new Properties with the flattened values */ public Properties getFlattenedProperties() { // Some macros only work in a lower processor, so we // do not report unknown macros while flattening flattening = true; try { Properties flattened = new Properties(); Properties source = domain.getProperties(); for (Enumeration<?> e = source.propertyNames(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); if (!key.startsWith("_")) if (key.startsWith("-")) flattened.put(key, source.getProperty(key)); else flattened.put(key, process(source.getProperty(key))); } return flattened; } finally { flattening = false; } }
public void execute(String[] sqls) { String sql = null; String showSqlText = properties.getProperty("hibernate.show_sql"); boolean showSql = ("true".equalsIgnoreCase(showSqlText)); try { createConnection(); statement = connection.createStatement(); for (int i = 0; i < sqls.length; i++) { sql = sqls[i]; String delimitedSql = sql + getSqlDelimiter(); if (showSql) log.debug(delimitedSql); statement.executeUpdate(delimitedSql); } } catch (SQLException e) { e.printStackTrace(); throw new RuntimeException("couldn't execute sql '" + sql + "'", e); } finally { closeConnection(); } }
/** * Returns the name of the given property. Returns null if the index is out of the range [0 ... * numProperties() - 1 ] */ public String getName(int index) { if (auxillary != null) return auxillary.getName(index); if (index < 0 || index >= numProperties()) return null; try { if (nameMethods.get(index) != null) return (String) (((Method) (nameMethods.get(index))).invoke(object, new Object[0])); } catch (Exception e) { e.printStackTrace(); return null; } String name = ((Method) (getMethods.get(index))).getName(); if (name.startsWith("is")) return name.substring(2); else if (name.equals("longValue")) // Integers of various kinds return "Value"; else if (name.equals("doubleValue")) // Other Numbers return "Value"; else if (name.equals("booleanValue")) // Booleans return "Value"; else if (name.equals("toString")) // Strings, StringBuffers return "Value"; else return name.substring(3); // "get", "set" }
/** * 初始化连接池 * * @param props * @param show_sql */ private static final void initDataSource(Properties dbProperties) { try { if (dbProperties == null) { dbProperties = new Properties(); dbProperties.load(DBManager.class.getResourceAsStream(CONFIG_PATH)); } // Class.forName(dbProperties.getProperty("jdbc.driverClass")); for (Object key : dbProperties.keySet()) { String skey = (String) key; if (skey.startsWith("jdbc.")) { String name = skey.substring(5); cp_props.put(name, dbProperties.getProperty(skey)); if ("show_sql".equalsIgnoreCase(name)) { show_sql = "true".equalsIgnoreCase(dbProperties.getProperty(skey)); } } } dataSource = (DataSource) Class.forName(cp_props.getProperty("datasource")).newInstance(); if (dataSource.getClass().getName().indexOf("c3p0") > 0) { // Disable JMX in C3P0 System.setProperty( "com.mchange.v2.c3p0.management.ManagementCoordinator", "com.mchange.v2.c3p0.management.NullManagementCoordinator"); } log.info("Using DataSource : " + dataSource.getClass().getName()); BeanUtils.populate(dataSource, cp_props); Connection conn = getConnection(); DatabaseMetaData mdm = conn.getMetaData(); log.info( "Connected to " + mdm.getDatabaseProductName() + " " + mdm.getDatabaseProductVersion()); closeConnection(); } catch (Exception e) { e.printStackTrace(); throw new DBException(e); } }
public PropertyDescriptor getPropertyDescriptor(String name) { return (PropertyDescriptor) propDesc.get(getPropertyName(name)); }
private static void initialize() { props = new Properties(); boolean loadedProps = false; boolean overrideAll = false; // first load the system properties file // to determine the value of security.overridePropertiesFile File propFile = securityPropFile("java.security"); if (propFile.exists()) { try { FileInputStream fis = new FileInputStream(propFile); InputStream is = new BufferedInputStream(fis); props.load(is); is.close(); loadedProps = true; if (sdebug != null) { sdebug.println("reading security properties file: " + propFile); } } catch (IOException e) { if (sdebug != null) { sdebug.println("unable to load security properties from " + propFile); e.printStackTrace(); } } } if ("true".equalsIgnoreCase(props.getProperty("security.overridePropertiesFile"))) { String extraPropFile = System.getProperty("java.security.properties"); if (extraPropFile != null && extraPropFile.startsWith("=")) { overrideAll = true; extraPropFile = extraPropFile.substring(1); } if (overrideAll) { props = new Properties(); if (sdebug != null) { sdebug.println("overriding other security properties files!"); } } // now load the user-specified file so its values // will win if they conflict with the earlier values if (extraPropFile != null) { try { URL propURL; extraPropFile = PropertyExpander.expand(extraPropFile); propFile = new File(extraPropFile); if (propFile.exists()) { propURL = new URL("file:" + propFile.getCanonicalPath()); } else { propURL = new URL(extraPropFile); } BufferedInputStream bis = new BufferedInputStream(propURL.openStream()); props.load(bis); bis.close(); loadedProps = true; if (sdebug != null) { sdebug.println("reading security properties file: " + propURL); if (overrideAll) { sdebug.println("overriding other security properties files!"); } } } catch (Exception e) { if (sdebug != null) { sdebug.println("unable to load security properties from " + extraPropFile); e.printStackTrace(); } } } } if (!loadedProps) { initializeStatic(); if (sdebug != null) { sdebug.println("unable to load security properties " + "-- using defaults"); } } }
/** Returns the setting of an environment variable set inside the JVM. */ public static String getEnvironmentVariable(String envVarName) { if (envVars == null) envVars = getEnvironmentVariables(); return (String) envVars.get(envVarName); }
/** * Sets a security property value. * * <p>First, if there is a security manager, its <code>checkPermission</code> method is called * with a <code>java.security.SecurityPermission("setProperty."+key)</code> permission to see if * it's ok to set the specified security property value. * * @param key the name of the property to be set. * @param datum the value of the property to be set. * @throws SecurityException if a security manager exists and its <code>{@link * java.lang.SecurityManager#checkPermission}</code> method denies access to set the * specified security property value * @throws NullPointerException if key or datum is null * @see #getProperty * @see java.security.SecurityPermission */ public static void setProperty(String key, String datum) { check("setProperty." + key); props.put(key, datum); invalidateSMCache(key); /* See below. */ }
public boolean isVolatile() { if (auxillary != null) return auxillary.isVolatile(); return false; }
/** Returns the number of properties discovered */ public int numProperties() { if (auxillary != null) return auxillary.numProperties(); return getMethods.size(); }
/** * Returns whether or not the property can be written as well as read Returns false if the index * is out of the range [0 ... numProperties() - 1 ] */ public boolean isReadWrite(int index) { if (auxillary != null) return auxillary.isReadWrite(index); if (index < 0 || index >= numProperties()) return false; if (isComposite(index)) return false; return (setMethods.get(index) != null); }
private synchronized String getSqlDelimiter() { if (sqlDelimiter == null) { sqlDelimiter = properties.getProperty("jbpm.sql.delimiter", ";"); } return sqlDelimiter; }