tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r751333 - in /openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb: Vendor.java config/ConfigurationFactory.java util/Options.java
Date Sat, 07 Mar 2009 22:29:29 GMT
Author: dblevins
Date: Sat Mar  7 22:29:29 2009
New Revision: 751333

URL: http://svn.apache.org/viewvc?rev=751333&view=rev
Log:
OPENEJB-1006: Added 'openejb.vendor.config' property settable to any of: geronimo, glassfish,
jboss, weblogic

Added:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/Vendor.java
Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Options.java

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/Vendor.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/Vendor.java?rev=751333&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/Vendor.java
(added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/Vendor.java
Sat Mar  7 22:29:29 2009
@@ -0,0 +1,8 @@
+package org.apache.openejb;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public enum Vendor {
+    GERONIMO, GLASSFISH, JBOSS, WEBLOGIC
+}

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?rev=751333&r1=751332&r2=751333&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
Sat Mar  7 22:29:29 2009
@@ -32,8 +32,10 @@
 import java.util.Map;
 import java.util.Properties;
 import java.util.Collection;
+import java.util.Set;
 
 import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.Vendor;
 import org.apache.openejb.assembler.classic.AppInfo;
 import org.apache.openejb.assembler.classic.Assembler;
 import org.apache.openejb.assembler.classic.BmpEntityContainerInfo;
@@ -85,6 +87,7 @@
 import org.apache.openejb.util.Messages;
 import org.apache.openejb.util.SuperProperties;
 import org.apache.openejb.util.URISupport;
+import org.apache.openejb.util.Options;
 
 public class ConfigurationFactory implements OpenEjbConfigurationFactory {
 
@@ -150,9 +153,21 @@
         }
 
         chain.add(new CmpJpaConversion());
-        chain.add(new OpenEjb2Conversion());
-        chain.add(new SunConversion());
-        chain.add(new WlsConversion());
+
+        // By default all vendor support is enabled
+        Set<Vendor> support = Options.getEnums(SystemInstance.get().getProperties(),
"openejb.vendor.config", Vendor.values());
+
+        if (support.contains(Vendor.GERONIMO) || System.getProperty(DUCT_TAPE_PROPERTY) !=
null) {
+            chain.add(new OpenEjb2Conversion());
+        }
+
+        if (support.contains(Vendor.GLASSFISH)) {
+            chain.add(new SunConversion());
+        }
+
+        if (support.contains(Vendor.WEBLOGIC)) {
+            chain.add(new WlsConversion());
+        }
 
         if (System.getProperty(DUCT_TAPE_PROPERTY) != null){
             // must be after CmpJpaConversion since it adds new persistence-context-refs

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Options.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Options.java?rev=751333&r1=751332&r2=751333&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Options.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Options.java
Sat Mar  7 22:29:29 2009
@@ -16,7 +16,15 @@
  */
 package org.apache.openejb.util;
 
+import static org.apache.openejb.util.Join.join;
+
 import java.util.Properties;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.Map;
+import java.util.HashMap;
 
 /**
  * @version $Rev$ $Date$
@@ -60,21 +68,87 @@
 
     public static <T extends Enum<T>> T getEnum(Properties p, String property,
T defaultValue){
         String value = p.getProperty(property);
+        if (value == null) return defaultValue;
+
+        if (defaultValue == null) throw new IllegalArgumentException("Must supply a default
for property " + property);
+
+        Class<T> enumType = (Class<T>) defaultValue.getClass();
+
         try {
-            if (value != null) {
-                Class<T> enumType = (Class<T>) defaultValue.getClass();
-                return Enum.valueOf(enumType, value.toUpperCase());
-            } else {
-                return defaultValue;
-            }
+            return valueOf(enumType, value.toUpperCase());
         } catch (IllegalArgumentException e) {
-            warn(property, value, defaultValue, e);
+            warn(property, value, enumType, defaultValue);
             return defaultValue;
         }
     }
 
+    public static <T extends Enum<T>> Set<T> getEnums(Properties p, String
property, T... defaultValue){
+        String value = p.getProperty(property);
+
+        if (value == null) return EnumSet.copyOf(Arrays.asList(defaultValue));
+
+        Class<T> enumType;
+        try {
+            T t = defaultValue[0];
+            enumType = (Class<T>) t.getClass();
+        } catch (Exception e) {
+            throw new IllegalArgumentException("Must supply a default for property " + property);
+        }
+
+        try {
+            String[] values = value.split(",");
+            EnumSet<T> set = EnumSet.noneOf(enumType);
+
+            for (String s : values) {
+                s = s.trim();
+                set.add(valueOf(enumType, s.toUpperCase()));
+            }
+            return set;
+        } catch (IllegalArgumentException e) {
+            warn(property, value, enumType, defaultValue);
+            return EnumSet.copyOf(Arrays.asList(defaultValue));
+        }
+    }
+
+    /**
+     * Use this instead of Enum.valueOf() when you want to ensure that the
+     * the enum values are case insensitive.
+     * 
+     * @param enumType
+     * @param name
+     * @param <T>
+     * @return
+     */
+    public static <T extends Enum<T>> T valueOf(Class<T> enumType, String
name){
+        Map<String, T> map = new HashMap<String, T>();
+        for (T t : enumType.getEnumConstants()) {
+            map.put(t.name().toUpperCase(), t);
+        }
+
+        T value = map.get(name.toUpperCase());
+
+        // Call Enum.valueOf for the clean exception
+        if (value == null) Enum.valueOf(enumType, name);
+
+        return value;
+    }
+    
+    private static void warn(String property, String value, Class<? extends Enum> enumType,
Enum... defaults) {
+        String defaultValues = join(", ", lowercase(defaults));
+        String possibleValues = join(", ", lowercase(enumType.getEnumConstants()));
+        logger.warning("Cannot parse supplied value \"" + value + "\" for option \"" + property
+ "\".  Using default of \"" + defaultValues + "\".  Possible values are: " + possibleValues);
+    }
 
     private static void warn(String property, String value, Object defaultValue, Exception
e) {
         logger.warning("Cannot parse supplied value \"" + value + "\" for option \"" + property
+ "\".  Using default of \"" + defaultValue + "\"", e);
     }
+
+    private static <T extends Enum<T>>  String[] lowercase(T... items) {
+        String[] values = new String[items.length];
+        for (int i = 0; i < items.length; i++) {
+            values[i] = items[i].name().toLowerCase();
+        }
+        return values;
+    }
+
 }



Mime
View raw message