cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r572053 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/enhancer: DoubleEnhanceException.java Enhancer.java PersistentInterfaceVisitor.java
Date Sun, 02 Sep 2007 17:52:33 GMT
Author: aadamchik
Date: Sun Sep  2 10:52:33 2007
New Revision: 572053

URL: http://svn.apache.org/viewvc?rev=572053&view=rev
Log:
CAY-757 JPA enhancer should enhance undeclared classes
(added a check for double enhancement...)

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/enhancer/DoubleEnhanceException.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/enhancer/Enhancer.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/enhancer/PersistentInterfaceVisitor.java

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/enhancer/DoubleEnhanceException.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/enhancer/DoubleEnhanceException.java?rev=572053&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/enhancer/DoubleEnhanceException.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/enhancer/DoubleEnhanceException.java
Sun Sep  2 10:52:33 2007
@@ -0,0 +1,47 @@
+/*****************************************************************
+ *   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.cayenne.enhancer;
+
+import org.apache.cayenne.CayenneRuntimeException;
+
+/**
+ * An exception thrown from within enhancer visitors to indicate that the class is already
+ * enhanced and enhancement run should be stopped.
+ * 
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+public class DoubleEnhanceException extends CayenneRuntimeException {
+
+    public DoubleEnhanceException() {
+    }
+
+    public DoubleEnhanceException(String message) {
+        super(message);
+    }
+
+    public DoubleEnhanceException(Throwable cause) {
+        super(cause);
+    }
+
+    public DoubleEnhanceException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/enhancer/Enhancer.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/enhancer/Enhancer.java?rev=572053&r1=572052&r2=572053&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/enhancer/Enhancer.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/enhancer/Enhancer.java
Sun Sep  2 10:52:33 2007
@@ -55,7 +55,8 @@
         ClassReader reader = new ClassReader(classfileBuffer);
 
         // optimization note: per ASM docs COMPUTE_FRAMES makes code generation 2x slower,
-        // so we may investigate manual computation options, although that's likely a pain.
+        // so we may investigate manual computation options, although that's likely a
+        // pain.
         ClassWriter writer = new ClassWriter(reader, ClassWriter.COMPUTE_FRAMES);
 
         ClassVisitor visitor = visitorFactory.createVisitor(className, writer);
@@ -65,7 +66,15 @@
         }
 
         logger.info("enhancing class " + className);
-        reader.accept(visitor, 0);
+
+        try {
+            reader.accept(visitor, 0);
+        }
+        catch (DoubleEnhanceException e) {
+            logger.info("class already enhanced, skipping: " + className);
+            return null;
+        }
+        
         return writer.toByteArray();
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/enhancer/PersistentInterfaceVisitor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/enhancer/PersistentInterfaceVisitor.java?rev=572053&r1=572052&r2=572053&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/enhancer/PersistentInterfaceVisitor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/enhancer/PersistentInterfaceVisitor.java
Sun Sep  2 10:52:33 2007
@@ -23,6 +23,7 @@
 import org.apache.cayenne.Persistent;
 import org.objectweb.asm.ClassAdapter;
 import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.Type;
 
 /**
  * Enhances classes passed through the visitor to add {@link Persistent} interface to
@@ -33,6 +34,8 @@
  */
 public class PersistentInterfaceVisitor extends ClassAdapter {
 
+    static String ENHANCED_INTERFACE_SIG = Type.getInternalName(Persistent.class);
+
     protected EnhancementHelper helper;
 
     public PersistentInterfaceVisitor(ClassVisitor visitor) {
@@ -52,12 +55,20 @@
             String superName,
             String[] interfaces) {
 
+        for (int i = 0; i < interfaces.length; i++) {
+            if (ENHANCED_INTERFACE_SIG.equals(interfaces[i])) {
+                throw new DoubleEnhanceException(name
+                        + " already implements "
+                        + ENHANCED_INTERFACE_SIG);
+            }
+        }
+
         helper.reset(name);
         interfaces = helper.addInterface(interfaces, Persistent.class);
 
         super.visit(version, access, name, signature, superName, interfaces);
     }
-    
+
     @Override
     public void visitEnd() {
         // per ASM docs, 'visitEnd' is the only correct place to add class members



Mime
View raw message