You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2008/01/05 11:06:23 UTC

svn commit: r609117 - in /openejb/trunk/openejb3/container/openejb-core/src: main/java/org/apache/openejb/config/sys/ main/java/org/apache/openejb/util/ test/java/org/apache/openejb/util/

Author: dblevins
Date: Sat Jan  5 02:06:01 2008
New Revision: 609117

URL: http://svn.apache.org/viewvc?rev=609117&view=rev
Log:
Fully case insensitive properties implemenation

Added:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/CaseInsensitiveProperties.java
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/util/CaseInsensitivePropertiesTest.java
Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/sys/PropertiesAdapter.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/sys/PropertiesAdapter.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/sys/PropertiesAdapter.java?rev=609117&r1=609116&r2=609117&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/sys/PropertiesAdapter.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/sys/PropertiesAdapter.java Sat Jan  5 02:06:01 2008
@@ -17,6 +17,8 @@
  */
 package org.apache.openejb.config.sys;
 
+import org.apache.openejb.util.CaseInsensitiveProperties;
+
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -27,7 +29,7 @@
  */
 public class PropertiesAdapter extends XmlAdapter<String, Properties> {
     public Properties unmarshal(String s) throws Exception {
-        Properties properties = new Properties();
+        Properties properties = new CaseInsensitiveProperties();
         ByteArrayInputStream in = new ByteArrayInputStream(s.getBytes());
         properties.load(in);
         return properties;

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/CaseInsensitiveProperties.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/CaseInsensitiveProperties.java?rev=609117&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/CaseInsensitiveProperties.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/CaseInsensitiveProperties.java Sat Jan  5 02:06:01 2008
@@ -0,0 +1,82 @@
+/**
+ * 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.util;
+
+import java.util.Properties;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CaseInsensitiveProperties extends Properties {
+    public CaseInsensitiveProperties() {
+    }
+
+    public CaseInsensitiveProperties(Properties defaults) {
+        if (!(defaults instanceof CaseInsensitiveProperties)) {
+            super.defaults = new CaseInsensitiveProperties();
+            super.defaults.putAll(defaults);
+        }
+    }
+
+    public boolean containsKey(Object key) {
+        return getKey((String) key) != null;
+    }
+
+    public Object get(Object key) {
+        return super.get(normalize(key));
+    }
+
+    public Object put(Object key, Object value) {
+        return super.put(normalize(key), value);
+    }
+
+    public String getProperty(String key) {
+        Object property = get(key);
+        if (property != null && property instanceof String){
+            return (String) property;
+        }
+        if (defaults != null) {
+            return defaults.getProperty(key);
+        }
+        return null;
+    }
+
+    private Object normalize(Object key){
+        if (key instanceof String) {
+            String normalized = getKey((String)key);
+            key = (normalized != null) ? normalized : key;
+        }
+        return key;
+    }
+
+    private String getKey(String property){
+        if (super.containsKey(property)){
+            return property;
+        }
+
+        for (Object o : keySet()) {
+            String key = (String) o;
+            if (key.equalsIgnoreCase(property)) return key;
+        }
+
+        if (defaults != null) {
+            CaseInsensitiveProperties defaults = (CaseInsensitiveProperties) this.defaults;
+            return defaults.getKey(property);
+        }
+        return null;
+    }
+}

Added: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/util/CaseInsensitivePropertiesTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/util/CaseInsensitivePropertiesTest.java?rev=609117&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/util/CaseInsensitivePropertiesTest.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/util/CaseInsensitivePropertiesTest.java Sat Jan  5 02:06:01 2008
@@ -0,0 +1,48 @@
+/**
+ * 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.util;
+
+import junit.framework.TestCase;
+
+import java.util.Properties;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CaseInsensitivePropertiesTest extends TestCase {
+
+    public void test() throws Exception {
+        Properties p = new CaseInsensitiveProperties();
+
+        assertEquals(0, p.size());
+
+        p.setProperty("FoO", "true");
+
+        assertEquals(1, p.size());
+
+        p.setProperty("Foo", "false");
+
+        // should still be size 1
+        assertEquals(1, p.size());
+
+        assertEquals("false", p.getProperty("FoO"));
+        assertEquals("false", p.getProperty("Foo"));
+
+        assertTrue(p.containsKey("Foo"));
+
+    }
+}