Search in sources :

Example 6 with SuperProperties

use of org.apache.openejb.util.SuperProperties in project tomee by apache.

the class Info2Properties method printSystemProperties.

private static void printSystemProperties(final PrintStream out, final String cr) {
    try {
        final SuperProperties p = new SuperProperties();
        p.setSpaceBetweenProperties(false);
        p.setKeyValueSeparator(" = ");
        p.setLineSeparator(cr);
        copyOpenEjbProperties(JavaSecurityManagers.getSystemProperties(), p);
        copyOpenEjbProperties(SystemInstance.get().getProperties(), p);
        p.store(out, null);
        final Properties p2 = JavaSecurityManagers.getSystemProperties();
        final String[] misc = { "os.version", "os.name", "os.arch", "java.version", "java.vendor" };
        for (final String prop : misc) {
            comment(out, cr, prop + "=" + p2.get(prop));
        }
    } catch (final IOException e) {
        e.printStackTrace(new PrintWriter(new CommentsFilter(out)));
    }
}
Also used : IOException(java.io.IOException) Properties(java.util.Properties) SuperProperties(org.apache.openejb.util.SuperProperties) SuperProperties(org.apache.openejb.util.SuperProperties) PrintWriter(java.io.PrintWriter)

Example 7 with SuperProperties

use of org.apache.openejb.util.SuperProperties in project tomee by apache.

the class TomEEDataSourceCreator method createProperties.

private SuperProperties createProperties(final String name, final Properties properties) {
    final SuperProperties converted = new SuperProperties() {

        @Override
        public Object setProperty(final String name, final String value) {
            if (value == null) {
                return super.getProperty(name);
            }
            return super.setProperty(name, value);
        }
    }.caseInsensitive(true);
    converted.setProperty("name", name);
    // very few properties have default = connection ones, so ensure to translate them with priority to specific ones
    converted.setProperty("url", properties.getProperty("url", (String) properties.remove("JdbcUrl")));
    converted.setProperty("driverClassName", properties.getProperty("driverClassName", (String) properties.remove("JdbcDriver")));
    converted.setProperty("username", (String) properties.remove("username"));
    converted.setProperty("password", (String) properties.remove("password"));
    converted.putAll(properties);
    final String passwordCipher = (String) converted.remove("PasswordCipher");
    if (passwordCipher != null && !"PlainText".equals(passwordCipher)) {
        converted.setProperty("password", PasswordCipherFactory.getPasswordCipher(passwordCipher).decrypt(converted.getProperty("Password").toCharArray()));
    }
    return converted;
}
Also used : SuperProperties(org.apache.openejb.util.SuperProperties)

Example 8 with SuperProperties

use of org.apache.openejb.util.SuperProperties in project tomee by apache.

the class AutoConfig method copy.

private ResourceInfo copy(final ResourceInfo a) {
    final ResourceInfo b = new ResourceInfo();
    b.id = a.id;
    b.service = a.service;
    b.className = a.className;
    b.codebase = a.codebase;
    b.displayName = a.displayName;
    b.description = a.description;
    b.factoryMethod = a.factoryMethod;
    b.constructorArgs.addAll(a.constructorArgs);
    b.originAppName = a.originAppName;
    b.types.addAll(a.types);
    b.properties = new SuperProperties();
    b.properties.putAll(a.properties);
    if (a.classpath != null) {
        b.classpath = new URI[a.classpath.length];
        System.arraycopy(a.classpath, 0, b.classpath, 0, a.classpath.length);
    }
    return b;
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) SuperProperties(org.apache.openejb.util.SuperProperties)

Example 9 with SuperProperties

use of org.apache.openejb.util.SuperProperties in project tomee by apache.

the class Info2Properties method print.

private static void print(final PrintStream out, final String cr, final ServiceInfo info) {
    try {
        println(out, cr, "");
        comment(out, cr, info.service + "(id=" + info.id + ")");
        comment(out, cr, "className: " + info.className);
        // TODO: the codebase value usually isn't filled in, we should do that.
        // comment("codebase: " + info.codebase);
        comment(out, cr, "");
        final SuperProperties p = new SuperProperties();
        p.setSpaceBetweenProperties(false);
        p.setKeyValueSeparator(" = ");
        p.setLineSeparator(cr);
        String uri = "new://" + info.service;
        if (info.service.matches("Container|Resource|Connector")) {
            try {
                final Map query = new HashMap();
                query.put("type", info.types.get(0));
                uri += "?" + URISupport.createQueryString(query);
            } catch (final Exception e) {
            // no-op
            }
        }
        p.put(info.id, uri);
        for (final Map.Entry<Object, Object> entry : info.properties.entrySet()) {
            if (!(entry.getKey() instanceof String)) {
                continue;
            }
            if (!(entry.getValue() instanceof String)) {
                continue;
            }
            // If property name is 'password' replace value with 'xxxx' to protect it
            if ("password".equalsIgnoreCase((String) entry.getKey())) {
                p.put(info.id + "." + entry.getKey(), "xxxx");
            } else {
                p.put(info.id + "." + entry.getKey(), entry.getValue());
            }
        }
        p.store(out, null);
    } catch (final IOException e) {
        out.println("# Printing service(id=" + info.id + ") failed.");
        e.printStackTrace(new PrintWriter(new CommentsFilter(out)));
    }
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) SuperProperties(org.apache.openejb.util.SuperProperties) NamingException(javax.naming.NamingException) IOException(java.io.IOException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) ParseException(org.apache.commons.cli.ParseException) PrintWriter(java.io.PrintWriter)

Example 10 with SuperProperties

use of org.apache.openejb.util.SuperProperties in project tomee by apache.

the class WikiGenerator method generateService.

private void generateService(final ServiceProvider provider, final String serviceType) {
    final String type = provider.getTypes().get(0);
    out.println("# " + type + " <small>" + serviceType + " </small>");
    out.println();
    out.println("Declarable in openejb.xml via");
    out.println();
    out.println("    <" + provider.getService() + " id=\"Foo\" type=\"" + type + "\">");
    out.println("    </" + provider.getService() + ">");
    out.println();
    out.println("Declarable in properties via");
    out.println();
    out.println("    Foo = new://" + provider.getService() + "?type=" + type);
    out.println();
    final SuperProperties properties = (SuperProperties) provider.getProperties();
    final Map<String, String> defaults = new LinkedHashMap<String, String>();
    if (properties.size() > 0) {
        out.println("## Properties");
        out.println();
        for (final Object key : properties.keySet()) {
            if (key instanceof String) {
                final String name = (String) key;
                final Map<String, String> attributes = properties.getAttributes(name);
                if (attributes.containsKey("hidden")) {
                    continue;
                }
                out.println("### " + key);
                out.println();
                final String value = properties.getProperty(name);
                String comment = properties.getComment(name);
                comment = scrubText(comment);
                defaults.put(name, String.valueOf(value));
                if (comment.length() == 0) {
                    comment = "No description.";
                }
                out.println(comment);
                out.println();
            }
        }
        out.println("## Default declaration");
        out.println("    <" + provider.getService() + " id=\"" + provider.getId() + "\" type=\"" + type + "\">");
        for (final Map.Entry<String, String> entry : defaults.entrySet()) {
            out.print("        ");
            out.print(entry.getKey());
            out.print(" = ");
            out.println(entry.getValue());
        }
        out.println("    </" + provider.getService() + ">");
    } else {
        out.println("No properties.");
    }
    out.println();
}
Also used : LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SuperProperties(org.apache.openejb.util.SuperProperties) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

SuperProperties (org.apache.openejb.util.SuperProperties)11 Map (java.util.Map)5 Properties (java.util.Properties)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 PrintWriter (java.io.PrintWriter)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 NamingException (javax.naming.NamingException)2 OpenEJBException (org.apache.openejb.OpenEJBException)2 ObjectRecipe (org.apache.xbean.recipe.ObjectRecipe)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 InvalidObjectException (java.io.InvalidObjectException)1 ObjectStreamException (java.io.ObjectStreamException)1 Serializable (java.io.Serializable)1 Type (java.lang.reflect.Type)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1