You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by ma...@apache.org on 2008/11/24 17:45:48 UTC

svn commit: r720223 - in /openejb/trunk/openejb3: container/openejb-core/src/main/java/org/apache/openejb/core/ itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/annotations/ itests/openejb-itests-beans/src/main/java/org/apache/openejb/...

Author: manugeorge
Date: Mon Nov 24 08:45:47 2008
New Revision: 720223

URL: http://svn.apache.org/viewvc?rev=720223&view=rev
Log:
OPENEJB-951 : There are problems to deploy ejb with custom annotation where values are enums. The fix for this is to load enums with the normal classloader just like annotations.

Added:
    openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/annotations/
    openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/annotations/MeasureSensible.java
    openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/annotations/MeasureSensivity.java
Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/TempClassLoader.java
    openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/BasicStatelessBean.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/TempClassLoader.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/TempClassLoader.java?rev=720223&r1=720222&r2=720223&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/TempClassLoader.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/TempClassLoader.java Mon Nov 24 08:45:47 2008
@@ -97,7 +97,8 @@
         }
 
         // Annotation classes must be loaded by the normal classloader
-        if (isAnnotationClass(bytes)) {
+        // So must Enum classes to prevent problems with the sun jdk.
+        if (isAnnotationClass(bytes) || isEnum(bytes)) {
             return Class.forName(name, resolve, getClass().getClassLoader());
         }
 
@@ -118,6 +119,17 @@
             return super.loadClass(name, resolve);
         }
     }
+    
+    /**
+     * Fast-parse the given class bytecode to determine if it is an
+     * enum class.
+     */
+    private static boolean isEnum(byte[] bytes) {
+        IsEnumVisitor isEnumVisitor = new IsEnumVisitor();
+        ClassReader classReader = new ClassReader(bytes);
+        classReader.accept(isEnumVisitor, ClassReader.SKIP_DEBUG);
+        return isEnumVisitor.isEnum;
+    }
 
     /**
      * Fast-parse the given class bytecode to determine if it is an
@@ -138,4 +150,14 @@
         }
 
     }
+    
+    public static class IsEnumVisitor extends EmptyVisitor {
+        public boolean isEnum = false;
+
+        public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
+            isEnum = (access & Opcodes.ACC_ENUM) != 0;
+        }
+
+    }
+
 }

Added: openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/annotations/MeasureSensible.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/annotations/MeasureSensible.java?rev=720223&view=auto
==============================================================================
--- openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/annotations/MeasureSensible.java (added)
+++ openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/annotations/MeasureSensible.java Mon Nov 24 08:45:47 2008
@@ -0,0 +1,32 @@
+/**
+ * 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.test.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.PARAMETER, ElementType.METHOD})
+public @interface MeasureSensible {
+
+    MeasureSensivity[] value() default {};
+
+}
\ No newline at end of file

Added: openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/annotations/MeasureSensivity.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/annotations/MeasureSensivity.java?rev=720223&view=auto
==============================================================================
--- openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/annotations/MeasureSensivity.java (added)
+++ openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/annotations/MeasureSensivity.java Mon Nov 24 08:45:47 2008
@@ -0,0 +1,22 @@
+/**
+ * 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.test.annotations;
+
+public enum MeasureSensivity {
+    PARAM,
+    RESULT
+}

Modified: openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/BasicStatelessBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/BasicStatelessBean.java?rev=720223&r1=720222&r2=720223&view=diff
==============================================================================
--- openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/BasicStatelessBean.java (original)
+++ openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/stateless/BasicStatelessBean.java Mon Nov 24 08:45:47 2008
@@ -28,6 +28,8 @@
 import javax.naming.NamingException;
 
 import org.apache.openejb.test.ApplicationException;
+import org.apache.openejb.test.annotations.MeasureSensible;
+import org.apache.openejb.test.annotations.MeasureSensivity;
 import org.apache.openejb.test.beans.TimerSync;
 import org.apache.openejb.test.object.OperationsPolicy;
 
@@ -138,6 +140,7 @@
     /**
      * @throws javax.ejb.CreateException
      */
+    @MeasureSensible(MeasureSensivity.RESULT)  
     public void ejbCreateObject() throws javax.ejb.CreateException {
         testAllowedOperations("ejbCreate");
         this.name = "nameless automaton";