openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgras...@apache.org
Subject svn commit: r1497841 - /openjpa/branches/2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
Date Fri, 28 Jun 2013 16:55:28 GMT
Author: jgrassel
Date: Fri Jun 28 16:55:28 2013
New Revision: 1497841

URL: http://svn.apache.org/r1497841
Log:
OPENJPA-2025: Add Compatibility option to AnnotationProcessor6 tool so that the default generated
class can be processed cleanly by the default runtime processor

Modified:
    openjpa/branches/2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java

Modified: openjpa/branches/2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java?rev=1497841&r1=1497840&r2=1497841&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
(original)
+++ openjpa/branches/2.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
Fri Jun 28 16:55:28 2013
@@ -25,6 +25,7 @@ import java.io.PrintWriter;
 import java.net.URL;
 import java.util.Arrays;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -45,6 +46,7 @@ import javax.persistence.metamodel.Stati
 import javax.tools.Diagnostic;
 import javax.tools.JavaFileObject;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.MetaDataFactory;
 import org.apache.openjpa.persistence.PersistenceMetaDataFactory;
@@ -98,7 +100,8 @@ import org.apache.openjpa.persistence.ut
                     "openjpa.source",
                     "openjpa.naming",
                     "openjpa.header",
-                    "openjpa.metamodel"
+                    "openjpa.metamodel",
+                    "openjpa.Compatibility"
                   })
 @SupportedSourceVersion(RELEASE_6)
 
@@ -109,8 +112,11 @@ public class AnnotationProcessor6 extend
     private CompileTimeLogger logger;
     private String header;
     private boolean active;
+    private Map<String, String> compatibilityMap = new HashMap<String, String>();
     private static Localizer _loc =  Localizer.forPackage(AnnotationProcessor6.class);
 
+    private boolean compat_useListAttributeForArrays = true;
+    
     /**
      * Category of members as per JPA 2.0 type system.
      * 
@@ -191,11 +197,17 @@ public class AnnotationProcessor6 extend
         if (!active)
             return;
         processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, _loc.get("mmg-tool-banner").toString());
-        logger = new CompileTimeLogger(processingEnv, getOptionValue("openjpa.log"));
+        logger = new CompileTimeLogger(processingEnv, getOptionValue("openjpa.log"));   
  
         setSourceVersion();
         setNamingPolicy();
         setHeader();
         handler = new SourceAnnotationHandler(processingEnv, logger);
+        
+        // Process Compatibility Options
+        compatibilityMap = processCompatibilityOptions(getOptionValue("openjpa.Compatibility"));
+        if (compatibilityMap.keySet().contains("UseListAttributeForArrays")) {
+            compat_useListAttributeForArrays = Boolean.parseBoolean(compatibilityMap.get("UseListAttributeForArrays"));
+        }
     }
     
     /**
@@ -243,7 +255,10 @@ public class AnnotationProcessor6 extend
             Set<? extends Element> members = handler.getPersistentMembers(e);
             
             for (Element m : members) {
-                boolean isPersistentCollection = m.getAnnotation(PersistentCollection.class)
!= null; 
+                boolean isPersistentCollection = 
+                        (compat_useListAttributeForArrays == true) 
+                            ? true 
+                            : m.getAnnotation(PersistentCollection.class) != null; 
                 
                 TypeMirror decl  = handler.getDeclaredType(m);
                 String fieldName = handler.getPersistentMemberName(m);
@@ -382,4 +397,87 @@ public class AnnotationProcessor6 extend
         }
         return null;
     }
+    
+    private static Map<String, String> processCompatibilityOptions(String compatArgs)
{
+        HashMap<String, String> compatOptionsMap = new HashMap<String, String>();
+        
+        if (StringUtils.isEmpty(compatArgs)) {
+            return compatOptionsMap;
+        }
+        
+        int start = 0, pos = 0, limit = compatArgs.length();
+        Integer subConfigBoundaryDepth = null;
+        char[] optionsCharArr = compatArgs.toCharArray();
+        
+        for (pos = 0; pos < limit; pos++) {
+            // Special processing needed for augmented parameters bounded in () markers
+            if (optionsCharArr[pos] == '(') {
+                if (subConfigBoundaryDepth == null) {
+                    subConfigBoundaryDepth = new Integer(1);
+                } else {
+                    subConfigBoundaryDepth = new Integer(subConfigBoundaryDepth.intValue()
+ 1);
+                    continue;
+                }
+            }
+            
+            if (optionsCharArr[pos] == ')') {
+                if (subConfigBoundaryDepth != null) {
+                    int level = subConfigBoundaryDepth.intValue() - 1;
+                    
+                    if (level == 0) {
+                        subConfigBoundaryDepth = null;
+                    } else {
+                        subConfigBoundaryDepth = new Integer(level);
+                    }
+                }             
+
+                continue;
+            }
+            
+            // ',' symbols not in augmented parameter boundaries are compatiblity option
terminator tokens.
+            if (optionsCharArr[pos] == ',' && subConfigBoundaryDepth == null) {
+                if (pos == start) {
+                    // Ignore empty option entries
+                    start = pos + 1;
+                    continue;
+                }
+                
+                String compatOptionEntry = compatArgs.substring(start, pos);
+                start = pos + 1;
+                
+                int nameValueMarkerIndex = compatOptionEntry.indexOf('=');
+                if (nameValueMarkerIndex == -1 || (nameValueMarkerIndex+1) == limit) {
+                    String name = (compatOptionEntry.endsWith("=") 
+                            ? compatOptionEntry.substring(0,  compatOptionEntry.length()
- 1)
+                            : compatOptionEntry);
+                    compatOptionsMap.put(name, "true");
+                } else {
+                    String name = compatOptionEntry.substring(0, nameValueMarkerIndex);
+                    String value = compatOptionEntry.substring(nameValueMarkerIndex + 1);
+                    compatOptionsMap.put(name, value);
+                }
+            }
+        }
+        
+        // Ran to the end of the string, process the remainder of the text
+        if (start < limit) {
+            String compatOptionEntry = compatArgs.substring(start, pos);
+            start = pos + 1;
+            
+            int nameValueMarkerIndex = subConfigBoundaryDepth == null ? compatOptionEntry.indexOf('=')
: -1;
+            if (nameValueMarkerIndex == -1 || (nameValueMarkerIndex+1) == limit) {
+                String name = (compatOptionEntry.endsWith("=") 
+                        ? compatOptionEntry.substring(0,  compatOptionEntry.length() - 1)
+                        : compatOptionEntry);
+                compatOptionsMap.put(name.trim(), "true");
+            } else {
+                String name = compatOptionEntry.substring(0, nameValueMarkerIndex);
+                String value = compatOptionEntry.substring(nameValueMarkerIndex + 1);
+                compatOptionsMap.put(name.trim(), (value == null) ? "" : value.trim());
+            }
+        }
+        
+        
+        return compatOptionsMap;
+    }
 }



Mime
View raw message