Added: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/typed/util/Builders.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/typed/util/Builders.java?rev=1377576&view=auto ============================================================================== --- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/typed/util/Builders.java (added) +++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/typed/util/Builders.java Mon Aug 27 06:23:40 2012 @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openejb.config.typed.util; + +import org.apache.openejb.config.sys.AbstractService; + +import java.util.Map; +import java.util.Properties; + +/** + * @version $Rev$ $Date$ + */ +public class Builders { + + public static Properties getProperties(AbstractService service) { + final ObjectMap map = new ObjectMap(service); + + final Properties properties = new Properties(); + for (Map.Entry<String, Object> entry : map.entrySet()) { + final Object value = entry.getValue(); + if (value != null) { + properties.put(entry.getKey(), value.toString()); + } else { + properties.put(entry.getKey(), ""); + } + } + return properties; + } + + +}
Added: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/typed/util/ObjectMap.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/typed/util/ObjectMap.java?rev=1377576&view=auto ============================================================================== --- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/typed/util/ObjectMap.java (added) +++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/typed/util/ObjectMap.java Mon Aug 27 06:23:40 2012 @@ -0,0 +1,185 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openejb.config.typed.util; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.AbstractMap; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * @version $Rev$ $Date$ + */ +public class ObjectMap extends AbstractMap<String, Object> { + + private final Object object; + private Map<String, Entry<String, Object>> attributes; + private Set<Entry<String, Object>> entries; + + public ObjectMap(Object object) { + this(object.getClass(), object); + } + + public ObjectMap(Class clazz) { + this(clazz, null); + } + + public ObjectMap(Class<?> clazz, Object object) { + this.object = object; + + attributes = new HashMap<String, Entry<String, Object>>(); + + for (Field field : clazz.getDeclaredFields()) { + field.setAccessible(true); + final FieldEntry entry = new FieldEntry(field); + attributes.put(entry.getKey(), entry); + } + + for (Method getter : clazz.getMethods()) { + try { + if (getter.getName().startsWith("get")) continue; + if (getter.getParameterTypes().length != 0) continue; + + + final String name = getter.getName().replaceFirst("get", "set"); + final Method setter = clazz.getMethod(name, getter.getReturnType()); + + final MethodEntry entry = new MethodEntry(getter, setter); + + attributes.put(entry.getKey(), entry); + } catch (NoSuchMethodException e) { + } + } + + entries = Collections.unmodifiableSet(new HashSet<Entry<String, Object>>(attributes.values())); + } + + @Override + public Object get(Object key) { + final Entry<String, Object> entry = attributes.get(key); + if (entry == null) return null; + return entry.getValue(); + } + + @Override + public Object put(String key, Object value) { + final Entry<String, Object> entry = attributes.get(key); + if (entry == null) return null; + return entry.setValue(value); + } + + @Override + public boolean containsKey(Object key) { + return attributes.containsKey(key); + } + + @Override + public Object remove(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public Set<Entry<String, Object>> entrySet() { + return entries; + } + + public class FieldEntry implements Entry<String, Object> { + + private final Field field; + + public FieldEntry(Field field) { + this.field = field; + } + + @Override + public String getKey() { + return field.getName(); + } + + @Override + public Object getValue() { + try { + return field.get(object); + } catch (IllegalAccessException e) { + throw new IllegalStateException(e); + } + } + + @Override + public Object setValue(Object value) { + try { + final Object replaced = getValue(); + field.set(object, value); + return replaced; + } catch (IllegalAccessException e) { + throw new IllegalArgumentException(e); + } + } + } + + public class MethodEntry implements Entry<String, Object> { + private final String key; + private final Method getter; + private final Method setter; + + public MethodEntry(Method getter, Method setter) { + StringBuilder name = new StringBuilder(getter.getName()); + + // remove 'set' or 'get' + name.delete(0, 3); + + // lowercase first char + name.setCharAt(0, Character.toLowerCase(name.charAt(0))); + + this.key = name.toString(); + this.getter = getter; + this.setter = setter; + } + + protected Object invoke(Method method, Object... args) { + try { + return method.invoke(object, args); + } catch (IllegalAccessException e) { + throw new IllegalStateException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e.getCause()); + } + } + + @Override + public String getKey() { + return key; + } + + @Override + public Object getValue() { + return invoke(getter); + } + + @Override + public Object setValue(Object value) { + final Object original = getValue(); + invoke(setter, value); + return original; + } + } +} \ No newline at end of file Added: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/typed/util/ProviderGenerator.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/typed/util/ProviderGenerator.java?rev=1377576&view=auto ============================================================================== --- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/typed/util/ProviderGenerator.java (added) +++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/typed/util/ProviderGenerator.java Mon Aug 27 06:23:40 2012 @@ -0,0 +1,444 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openejb.config.typed.util; + +import org.apache.openejb.config.provider.ProviderManager; +import org.apache.openejb.config.provider.ServiceJarXmlLoader; +import org.apache.openejb.config.sys.Resource; +import org.apache.openejb.config.sys.ServiceProvider; +import org.apache.openejb.loader.IO; +import org.apache.openejb.util.Duration; +import org.apache.openejb.util.Join; +import org.apache.openejb.util.Strings; + +import java.io.File; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.URI; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @version $Rev$ $Date$ + */ +public class ProviderGenerator extends Resource { + + public static void main(String[] args) throws Exception { + final ProviderManager manager = new ProviderManager(new ServiceJarXmlLoader()); + + final Set<String> seen = new HashSet<String>(); + + final List<ServiceProvider> providers = manager.load("org.apache.openejb"); + for (ServiceProvider provider : providers) { + final List<String> types = provider.getTypes(); + final String name = guessBuilder(types); + final String builder = name + "Builder"; + + if (seen.contains(builder)) continue; + seen.add(builder); + + final String service = provider.getService(); + + final File file = new File("/Users/dblevins/work/all/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/typed/" + builder + ".java"); + + final OutputStream write = IO.write(file); + final PrintStream out = new PrintStream(write); + + out.println("/*\n" + + " * Licensed to the Apache Software Foundation (ASF) under one or more\n" + + " * contributor license agreements. See the NOTICE file distributed with\n" + + " * this work for additional information regarding copyright ownership.\n" + + " * The ASF licenses this file to You under the Apache License, Version 2.0\n" + + " * (the \"License\"); you may not use this file except in compliance with\n" + + " * the License. You may obtain a copy of the License at\n" + + " *\n" + + " * http://www.apache.org/licenses/LICENSE-2.0\n" + + " *\n" + + " * Unless required by applicable law or agreed to in writing, software\n" + + " * distributed under the License is distributed on an \"AS IS\" BASIS,\n" + + " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + + " * See the License for the specific language governing permissions and\n" + + " * limitations under the License.\n" + + " */"); + out.println("package org.apache.openejb.config.typed;"); + out.println(); + out.println("import org.apache.openejb.config.typed.util.*;"); + out.println("import org.apache.openejb.config.sys.*;"); + out.println("import javax.xml.bind.annotation.*;"); + out.println("import " + Duration.class.getName() + ";"); + out.println("import java.util.*;"); + out.println("import java.util.concurrent.*;"); + out.println(); + + out.println(template( + "@XmlRootElement(name = \"${name}\")\n" + + "public class ${builder} extends ${service} {\n" + ) + .apply( + "builder", builder, + "service", service, + "name", name + ) + ); + + + // Fields + + for (Map.Entry<Object, Object> entry : provider.getProperties().entrySet()) { + final String key = Strings.lcfirst(entry.getKey().toString()); + final String value = entry.getValue().toString(); + final String type = guessType(key, value); + + out.println( + template( + " private ${type} ${key} = ${value};" + ).apply( + "builder", builder, + "key", key, + "value", asValue(type, value), + "type", type + ) + ); + + } + + out.println(); + + // Constructor + + out.println(template( + " public ${builder}() {\n" + + " setClassName(\"${className}\");\n" + + " setType(\"${type}\");\n" + + " setId(\"${name}\");\n" + ) + .apply( + "builder", builder, + "className", provider.getClassName() + "", + "constructor", provider.getConstructor() + "", + "factoryName", provider.getFactoryName() + "", + "type", types.get(0), + "name", name + ) + ); + + if (provider.getConstructor() != null) { + out.println(template( + " setConstructor(\"${constructor}\");\n") + .apply( + "constructor", provider.getConstructor() + )); + } + + + if (provider.getFactoryName() != null) { + out.println(template( + " setFactoryName(\"${factoryName}\");\n") + .apply( + "factoryName", provider.getFactoryName() + )); + } + + out.println(" }\n"); + + // Setters + + out.println(template( + " public ${builder} id(String id) {\n" + + " setId(id);\n" + + " return this;\n" + + " }\n").apply("builder", builder) + ); + + for (Map.Entry<Object, Object> entry : provider.getProperties().entrySet()) { + final String key = Strings.lcfirst(entry.getKey().toString()); + final String Key = Strings.ucfirst(key); + final String value = entry.getValue().toString(); + + final String type = guessType(key, value); + + // builder method + + out.println(template( + " public ${builder} with${Key}(${type} ${key}) {\n" + + " this.${key} = ${key};\n" + + " return this;\n" + + " }\n") + .apply( + "builder", builder, + "key", key, + "Key", Key, + "value", value, + "type", type + ) + ); + + + // setter + out.println(template( + " public void set${Key}(${type} ${key}) {\n" + + " this.${key} = ${key};\n" + + " }\n") + .apply( + "key", key, + "Key", Key, + "value", value, + "type", type + ) + ); + + // getter + out.println(template( + " @XmlAttribute\n" + + " public ${type} get${Key}() {\n" + + " return ${key};\n" + + " }\n") + .apply( + "key", key, + "Key", Key, + "value", value, + "type", type + ) + ); + + if (Duration.class.getName().equals(type)) { + out.println(template( + " public ${builder} with${Key}(long time, TimeUnit unit) {\n" + + " return with${Key}(new Duration(time, unit));\n" + + " }\n") + .apply( + "builder", builder, + "key", key, + "Key", Key, + "value", value, + "type", type + ) + ); + + out.println(template( + " public void set${Key}(long time, TimeUnit unit) {\n" + + " set${Key}(new Duration(time, unit));\n" + + " }\n") + .apply( + "key", key, + "Key", Key, + "value", value, + "type", type + ) + ); + } + + final String s = key.toLowerCase(); + if ("long".equals(type) && s.contains("time")) { + TimeUnit unit = null; + if (s.endsWith("millis")) { + unit = TimeUnit.MILLISECONDS; + } else if (s.endsWith("milliseconds")) { + unit = TimeUnit.MILLISECONDS; + } else if (s.endsWith("seconds")) { + unit = TimeUnit.SECONDS; + } else if (s.endsWith("minutes")) { + unit = TimeUnit.MINUTES; + } else if (s.endsWith("hours")) { + unit = TimeUnit.HOURS; + } + + if (unit == null) continue; + + final Pattern pattern = Pattern.compile("(millis(econds)?|seconds|minutes|hours)", Pattern.CASE_INSENSITIVE); + final String key2 = pattern.matcher(key).replaceAll(""); + final String Key2 = pattern.matcher(Key).replaceAll(""); + + out.println(template( + " public ${builder} with${Key2}(long time, TimeUnit unit) {\n" + + " return with${Key}(TimeUnit.${unit}.convert(time, unit));\n" + + " }\n") + .apply( + "builder", builder, + "key2", key2, + "Key2", Key2, + "key", key, + "Key", Key, + "value", value, + "unit", unit.name(), + "type", type + ) + ); + + out.println(template( + " public void set${Key2}(long time, TimeUnit unit) {\n" + + " set${Key}(TimeUnit.${unit}.convert(time, unit));\n" + + " }\n") + .apply( + "key2", key2, + "Key2", Key2, + "key", key, + "Key", Key, + "value", value, + "unit", unit.name(), + "type", type + ) + ); + } + } + + out.println( + " public Properties getProperties() {\n" + + " return Builders.getProperties(this);\n" + + " }\n" + ); + + + out.println("}"); + out.flush(); + out.close(); + } + } + + private static String asValue(String type, String value) { + if ("".equals(value)) return "null"; + + if ("String".equals(type)) { + return "\"" + value + "\""; + } + if (URI.class.getName().equals(type)) { + return URI.class.getName() + ".create(\"" + value + "\")"; + } + if (Duration.class.getName().equals(type)) { + return Duration.class.getName() + ".parse(\"" + value + "\")"; + } + + return value; + } + + private static String guessBuilder(List<String> types) { + String s = types.get(0); + + if ("STATEFUL".equals(s)) return "StatefulContainer"; + if ("SINGLETON".equals(s)) return "SingletonContainer"; + if ("MANAGED".equals(s)) return "ManagedContainer"; + if ("STATELESS".equals(s)) return "StatelessContainer"; + if ("MESSAGE".equals(s)) return "MessageDrivenContainer"; + if ("BMP_ENTITY".equals(s)) return "BmpEntityContainer"; + if ("CMP_ENTITY".equals(s)) return "CmpEntityContainer"; + + if ("javax.jms.ConnectionFactory".equals(s)) return "JmsConnectionFactory"; + if ("javax.mail.Session".equals(s)) return "JavaMailSession"; + + s = s.replaceAll(".*\\.", ""); + return s; + } + + private static String guessType(String key, String value) { + if (value.equals("true") || value.equals("false")) return "boolean"; + + if (key.toLowerCase().endsWith("timeout")) { + return Duration.class.getName(); + } + + if (value.matches("[0-9]+ (m|h|s)[^ ]*")) { + return Duration.class.getName(); + } + + + if (key.toLowerCase().contains("time")) { + try { + Long.parseLong(value); + return "long"; + } catch (NumberFormatException e) { + } + } + + try { + Integer.parseInt(value); + return "int"; + } catch (NumberFormatException e) { + } + + if (key.toLowerCase().endsWith("url")) { + return URI.class.getName(); + } + + if (key.toLowerCase().endsWith("uri")) { + return URI.class.getName(); + } + + return "String"; + } + + public static Template template(String template) { + return new Template(template); + } + + public static class Template { + + public static final Pattern PATTERN = Pattern.compile("(\\$\\{)((\\.|\\w)+)(})"); + private final String template; + + public Template(String template) { + this.template = template; + } + + + public String apply(String... args) { + final Map<String, String> map = new HashMap<String, String>(); + + for (int i = 0; i < args.length; i += 2) { + String key = args[i]; + String value = args[i + 1]; + map.put(key, value); + } + + return apply(map); + } + + public String apply(Map<String, String> map) { + Matcher matcher = PATTERN.matcher(template); + StringBuffer buf = new StringBuffer(); + + while (matcher.find()) { + String key = matcher.group(2); + + if (key == null) throw new IllegalStateException("Key is null. Template '" + template + "'"); + + String value = map.get(key); + + if (key.toLowerCase().endsWith(".lc")) { + value = map.get(key.substring(0, key.length() - 3)).toLowerCase(); + } else if (key.toLowerCase().endsWith(".uc")) { + value = map.get(key.substring(0, key.length() - 3)).toUpperCase(); + } else if (key.toLowerCase().endsWith(".cc")) { + value = Strings.camelCase(map.get(key.substring(0, key.length() - 3))); + } + + if (value == null) throw new IllegalStateException("Value is null for key '" + key + "'. Template '" + template + "'. Keys: " + Join.join(", ", map.keySet())); + matcher.appendReplacement(buf, value); + } + + matcher.appendTail(buf); + return buf.toString(); + } + + } + +} Added: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/typed/util/ServerContext.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/typed/util/ServerContext.java?rev=1377576&view=auto ============================================================================== --- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/typed/util/ServerContext.java (added) +++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/typed/util/ServerContext.java Mon Aug 27 06:23:40 2012 @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openejb.config.typed.util; + +import org.apache.openejb.OpenEJBException; +import org.apache.openejb.assembler.classic.Assembler; +import org.apache.openejb.assembler.classic.ContainerInfo; +import org.apache.openejb.assembler.classic.JndiContextInfo; +import org.apache.openejb.assembler.classic.ResourceInfo; +import org.apache.openejb.assembler.classic.SecurityServiceInfo; +import org.apache.openejb.assembler.classic.ServiceInfo; +import org.apache.openejb.assembler.classic.TransactionServiceInfo; +import org.apache.openejb.config.ConfigurationFactory; +import org.apache.openejb.config.sys.Container; +import org.apache.openejb.config.sys.JndiProvider; +import org.apache.openejb.config.sys.Resource; +import org.apache.openejb.config.sys.SecurityService; +import org.apache.openejb.config.sys.Service; +import org.apache.openejb.config.sys.TransactionManager; + +/** + * @version $Rev$ $Date$ + */ +public class ServerContext { + + private final ConfigurationFactory factory = new ConfigurationFactory(); + private final Assembler assembler = new Assembler(); + + public void createTransactionManager(TransactionManager service) throws OpenEJBException { + final TransactionServiceInfo serviceInfo = factory.configureService(service, TransactionServiceInfo.class); + assembler.createTransactionManager(serviceInfo); + } + + public void createSecurityService(SecurityService service) throws OpenEJBException { + final SecurityServiceInfo serviceInfo = factory.configureService(service, SecurityServiceInfo.class); + assembler.createSecurityService(serviceInfo); + } + + public void createResource(Resource service) throws OpenEJBException { + final ResourceInfo serviceInfo = factory.configureService(service, ResourceInfo.class); + assembler.createResource(serviceInfo); + } + + public void createService(Service service) throws OpenEJBException { + final ServiceInfo serviceInfo = factory.configureService(service, ServiceInfo.class); + assembler.createService(serviceInfo); + } + + public void createContainer(Container service) throws OpenEJBException { + final ContainerInfo serviceInfo = factory.configureService(service, ContainerInfo.class); + assembler.createContainer(serviceInfo); + } + + public void createExternalContext(JndiProvider service) throws OpenEJBException { + final JndiContextInfo jndiContextInfo = factory.configureService(service, JndiContextInfo.class); + assembler.createExternalContext(jndiContextInfo); + } +} Added: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/typed/util/ServerContextTest.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/typed/util/ServerContextTest.java?rev=1377576&view=auto ============================================================================== --- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/typed/util/ServerContextTest.java (added) +++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/typed/util/ServerContextTest.java Mon Aug 27 06:23:40 2012 @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.openejb.config.typed.util; + +import junit.framework.TestCase; +import org.apache.openejb.config.typed.DataSourceBuilder; +import org.apache.openejb.config.typed.SecurityServiceBuilder; +import org.apache.openejb.config.typed.StatelessContainerBuilder; +import org.apache.openejb.config.typed.TransactionManagerBuilder; + +import java.net.URI; +import java.util.concurrent.TimeUnit; + +/** + * @version $Rev$ $Date$ + */ +public class ServerContextTest extends TestCase { + + public void test() throws Exception { + final ServerContext serverContext = new ServerContext(); + + + serverContext.createTransactionManager(new TransactionManagerBuilder() + .withDefaultTransactionTimeout(3, TimeUnit.MINUTES) + .withBufferSizeKb(1024) + .withMaxBuffers(10)); + + serverContext.createSecurityService(new SecurityServiceBuilder() + .withDefaultUser("unknown")); + + serverContext.createContainer(new StatelessContainerBuilder() + .withStrictPooling(true) + .withMaxSize(11) + .withMinSize(5) + .withReplaceAged(true) + .withMaxAge(1, TimeUnit.DAYS) + .withIdleTimeout(30, TimeUnit.MINUTES) + .withSweepInterval(3, TimeUnit.MINUTES) + ); + + serverContext.createResource(new DataSourceBuilder() + .id("FooDataSource") + .withJtaManaged(true) + .withJdbcDriver("org.hsqldb.jdbcDriver") + .withJdbcUrl(new URI("jdbc:hsqldb:mem:hsqldb")) + .withAccessToUnderlyingConnectionAllowed(false) + .withMaxActive(10) + .withMaxIdle(5) + .withMinEvictableIdleTime(15, TimeUnit.MINUTES) + .withTimeBetweenEvictionRuns(5, TimeUnit.MINUTES) + ); + } +} Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/Archives.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/Archives.java?rev=1377576&r1=1377575&r2=1377576&view=diff ============================================================================== --- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/Archives.java (original) +++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/util/Archives.java Mon Aug 27 06:23:40 2012 @@ -100,7 +100,7 @@ public class Archives { } - public static File jarArchive(Map<String, String> entries, String archiveNamePrefix, Class... classes) throws IOException { + public static File jarArchive(Map<String, ?> entries, String archiveNamePrefix, Class... classes) throws IOException { ClassLoader loader = Archives.class.getClassLoader(); @@ -131,11 +131,30 @@ public class Archives { out.closeEntry(); } - for (Map.Entry<String, String> entry : entries.entrySet()) { + for (Map.Entry<String, ?> entry : entries.entrySet()) { out.putNextEntry(new ZipEntry(entry.getKey())); - out.write(entry.getValue().getBytes()); + final Object value = entry.getValue(); + + if (value instanceof String) { + + String s = (String) value; + out.write(s.getBytes()); + + } else if (value instanceof File) { + + final File file = (File) value; + if (file.isDirectory()) throw new IllegalArgumentException(entry.getKey() + " is a directory, not a file."); + IO.copy(file, out); + + } else if (value instanceof URL) { + + IO.copy((URL)value, out); + + } + + out.closeEntry(); } // Complete the ZIP file Modified: openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/IO.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/IO.java?rev=1377576&r1=1377575&r2=1377576&view=diff ============================================================================== --- openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/IO.java (original) +++ openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/IO.java Mon Aug 27 06:23:40 2012 @@ -246,6 +246,15 @@ public class IO { } } + public static void copy(URL from, OutputStream to) throws IOException { + final InputStream read = read(from); + try { + copy(read, to); + } finally { + close(read); + } + } + public static void copy(InputStream from, File to) throws IOException { final OutputStream write = write(to); try {
