openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r713493 - in /openjpa/trunk: openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/
Date Wed, 12 Nov 2008 20:19:41 GMT
Author: mikedd
Date: Wed Nov 12 12:19:40 2008
New Revision: 713493

URL: http://svn.apache.org/viewvc?rev=713493&view=rev
Log:
unify doPrivHelpers

Removed:
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPriv5Helper.java
Modified:
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
    openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceXMLMetaDataParser.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java?rev=713493&r1=713492&r2=713493&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
(original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
Wed Nov 12 12:19:40 2008
@@ -24,7 +24,9 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.annotation.Annotation;
 import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.net.InetAddress;
@@ -98,6 +100,9 @@
  * <li>serp.bytecode.BCClass.getFields
  * <li>serp.bytecode.FieldInstruction.getField
  * <li>serp.bytecode.Project.loadClass
+ * <li>AnnotatedElement.getAnnotations
+ * <li>AnnotatedElement.getDeclaredAnnotations
+ * <li>AnnotatedElement.isAnnotationPresent
  * </ul>
  * 
  * If these methods are used, the following sample usage patterns should be
@@ -1047,4 +1052,60 @@
             }
         };
     }
+    
+    /**
+     * Return a PrivilegeAction object for AnnotatedElement.getAnnotations().
+     *
+     * Requires security policy:
+     *   'permission java.lang.RuntimePermission "accessDeclaredMembers";'
+     *
+     * @return Annotation[]
+     */
+    public static final PrivilegedAction<Annotation []> getAnnotationsAction(
+        final AnnotatedElement element) {
+        return new PrivilegedAction<Annotation []>() {
+            public Annotation [] run() {
+                return element.getAnnotations();
+            }
+        };
+    }
+
+    /**
+     * Return a PrivilegeAction object for
+     *   AnnotatedElement.getDeclaredAnnotations().
+     *
+     * Requires security policy:
+     *   'permission java.lang.RuntimePermission "accessDeclaredMembers";'
+     *
+     * @return Annotation[]
+     */
+    public static final PrivilegedAction<Annotation []> 
+        getDeclaredAnnotationsAction(
+        final AnnotatedElement element) {
+        return new PrivilegedAction<Annotation[]>() {
+            public Annotation [] run() {
+                return element.getDeclaredAnnotations();
+            }
+        };
+    }
+
+    /**
+     * Return a PrivilegeAction object for
+     *   AnnotatedElement.isAnnotationPresent().
+     *
+     * Requires security policy:
+     *   'permission java.lang.RuntimePermission "accessDeclaredMembers";'
+     *
+     * @return Boolean
+     */
+    public static final PrivilegedAction<Boolean> isAnnotationPresentAction(
+        final AnnotatedElement element,
+        final Class<? extends Annotation> annotationClazz) {
+        return new PrivilegedAction<Boolean>() {
+            public Boolean run() {
+                return element.isAnnotationPresent(annotationClazz)
+                    ? Boolean.TRUE : Boolean.FALSE;
+            }
+        };
+    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java?rev=713493&r1=713492&r2=713493&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
Wed Nov 12 12:19:40 2008
@@ -77,7 +77,7 @@
 import org.apache.openjpa.jdbc.schema.Unique;
 import org.apache.openjpa.jdbc.sql.DBDictionary;
 import org.apache.openjpa.lib.log.Log;
-import org.apache.openjpa.lib.util.J2DoPriv5Helper;
+import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.FieldMetaData;
@@ -1308,7 +1308,7 @@
             
             if (xmlTypeClass != null
                 && StringUtils.isEmpty(pcols[i].columnDefinition())
-                && (AccessController.doPrivileged(J2DoPriv5Helper
+                && (AccessController.doPrivileged(J2DoPrivHelper
                     .isAnnotationPresentAction(fm.getDeclaredType(),
                         xmlTypeClass))).booleanValue()) {
                 DBDictionary dict = ((MappingRepository) getRepository())

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java?rev=713493&r1=713492&r2=713493&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
Wed Nov 12 12:19:40 2008
@@ -87,7 +87,7 @@
 import org.apache.openjpa.kernel.jpql.JPQLParser;
 import org.apache.openjpa.lib.conf.Configurations;
 import org.apache.openjpa.lib.log.Log;
-import org.apache.openjpa.lib.util.J2DoPriv5Helper;
+import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.DelegatingMetaDataFactory;
@@ -467,12 +467,12 @@
         // check immediately whether the user is using any annotations,
         // regardless of mode.  this prevents adding non-entity classes to
         // repository if we're ignoring these annotations in mapping mode
-        if (!(AccessController.doPrivileged(J2DoPriv5Helper
+        if (!(AccessController.doPrivileged(J2DoPrivHelper
             .isAnnotationPresentAction(_cls, Entity.class))).booleanValue()
-            && !(AccessController.doPrivileged(J2DoPriv5Helper
+            && !(AccessController.doPrivileged(J2DoPrivHelper
                 .isAnnotationPresentAction(_cls, Embeddable.class)))
                 .booleanValue()
-            && !(AccessController.doPrivileged(J2DoPriv5Helper
+            && !(AccessController.doPrivileged(J2DoPrivHelper
                 .isAnnotationPresentAction(_cls, MappedSuperclass.class)))
                 .booleanValue())
             return null;
@@ -679,17 +679,17 @@
 
         String rsrc = StringUtils.replace(cls.getName(), ".", "/");
         ClassLoader loader = AccessController.doPrivileged(
-            J2DoPriv5Helper.getClassLoaderAction(cls)); 
+            J2DoPrivHelper.getClassLoaderAction(cls)); 
         if (loader == null)
             loader = AccessController.doPrivileged(
-                J2DoPriv5Helper.getSystemClassLoaderAction()); 
+                J2DoPrivHelper.getSystemClassLoaderAction()); 
         if (loader == null)
             return null;
         URL url = AccessController.doPrivileged(
-            J2DoPriv5Helper.getResourceAction(loader, rsrc + ".java")); 
+            J2DoPrivHelper.getResourceAction(loader, rsrc + ".java")); 
         if (url == null) {
             url = AccessController.doPrivileged(
-                J2DoPriv5Helper.getResourceAction(loader, rsrc + ".class")); 
+                J2DoPrivHelper.getResourceAction(loader, rsrc + ".class")); 
             if (url == null)
                 return null;
         }
@@ -779,10 +779,10 @@
                 meta.setDetachedState(detached.fieldName());
         } else {
             Field[] fields = (Field[]) AccessController.doPrivileged(
-                J2DoPriv5Helper.getDeclaredFieldsAction(
+                J2DoPrivHelper.getDeclaredFieldsAction(
                     meta.getDescribedType())); 
             for (int i = 0; i < fields.length; i++)
-                if ((AccessController.doPrivileged(J2DoPriv5Helper
+                if ((AccessController.doPrivileged(J2DoPrivHelper
                     .isAnnotationPresentAction(fields[i], DetachedState.class)))
                     .booleanValue())
                     meta.setDetachedState(fields[i].getName());
@@ -827,7 +827,7 @@
         Set<MethodKey> seen = new HashSet<MethodKey>();
         do {
             for (Method m : (Method[]) AccessController.doPrivileged(
-                J2DoPriv5Helper.getDeclaredMethodsAction(sup))) {
+                J2DoPrivHelper.getDeclaredMethodsAction(sup))) {
                 mods = m.getModifiers();
                 if (Modifier.isStatic(mods) || Modifier.isFinal(mods) ||
                     Object.class.equals(m.getDeclaringClass()))
@@ -845,7 +845,7 @@
         MetaDataDefaults def = repos.getMetaDataFactory().getDefaults();
         for (Method m : methods) {
             for (Annotation anno : (Annotation[]) AccessController
-                .doPrivileged(J2DoPriv5Helper
+                .doPrivileged(J2DoPrivHelper
                     .getDeclaredAnnotationsAction(m))) {
                 MetaDataTag tag = _tags.get(anno.annotationType());
                 if (tag == null)
@@ -984,7 +984,7 @@
         fmd.setExplicit(true);
 
         AnnotatedElement el = (AnnotatedElement) member;
-        boolean lob = (AccessController.doPrivileged(J2DoPriv5Helper
+        boolean lob = (AccessController.doPrivileged(J2DoPrivHelper
             .isAnnotationPresentAction(el, Lob.class))).booleanValue();
         if (isMetaDataMode()) {
             switch (pstrat) {

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceXMLMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceXMLMetaDataParser.java?rev=713493&r1=713492&r2=713493&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceXMLMetaDataParser.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceXMLMetaDataParser.java
Wed Nov 12 12:19:40 2008
@@ -27,7 +27,7 @@
 import org.apache.commons.lang.StringUtils;
 import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.lib.log.Log;
-import org.apache.openjpa.lib.util.J2DoPriv5Helper;
+import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.DelegatingMetaDataFactory;
 import org.apache.openjpa.meta.FieldMetaData;
@@ -173,10 +173,10 @@
     private XMLMetaData parseXMLClassAnnotations() {
         // check immediately whether the class has JAXB XML annotations
         if (_cls == null || xmlTypeClass == null
-            || !((AccessController.doPrivileged(J2DoPriv5Helper
+            || !((AccessController.doPrivileged(J2DoPrivHelper
                 .isAnnotationPresentAction(_cls, xmlTypeClass))).booleanValue()
                 && (AccessController
-                .doPrivileged(J2DoPriv5Helper.isAnnotationPresentAction(_cls,
+                .doPrivileged(J2DoPrivHelper.isAnnotationPresentAction(_cls,
                     xmlRootElementClass))).booleanValue()))
             return null;
 
@@ -225,7 +225,7 @@
         Class superclass = cls.getSuperclass();
 
         // handle inheritance at sub-element level
-        if ((AccessController.doPrivileged(J2DoPriv5Helper
+        if ((AccessController.doPrivileged(J2DoPrivHelper
             .isAnnotationPresentAction(superclass, xmlTypeClass)))
             .booleanValue())
             populateFromReflection(superclass, meta);
@@ -247,7 +247,7 @@
                     // avoid JAXB XML bind default name
                     if (StringUtils.equals(XMLMetaData.defaultName, xmlname))
                         xmlname = member.getName();
-                    if ((AccessController.doPrivileged(J2DoPriv5Helper
+                    if ((AccessController.doPrivileged(J2DoPrivHelper
                         .isAnnotationPresentAction(((Field) member).getType(),
                             xmlTypeClass))).booleanValue()) {
                         field = _repos.addXMLMetaData(((Field) member).getType()

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java?rev=713493&r1=713492&r2=713493&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
Wed Nov 12 12:19:40 2008
@@ -50,7 +50,7 @@
 import javax.persistence.Transient;
 
 import org.apache.commons.lang.StringUtils;
-import org.apache.openjpa.lib.util.J2DoPriv5Helper;
+import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.meta.AbstractMetaDataDefaults;
@@ -118,7 +118,7 @@
         if (member == null)
             return null;
         AnnotatedElement el = (AnnotatedElement) member;
-        if ((AccessController.doPrivileged(J2DoPriv5Helper
+        if ((AccessController.doPrivileged(J2DoPrivHelper
             .isAnnotationPresentAction(el, Transient.class))).booleanValue())
             return TRANSIENT;
         if (fmd != null
@@ -185,7 +185,7 @@
         }
 
         //### EJB3: what if defined in XML?
-        if ((AccessController.doPrivileged(J2DoPriv5Helper
+        if ((AccessController.doPrivileged(J2DoPrivHelper
             .isAnnotationPresentAction(type, Embeddable.class))).booleanValue())
             return EMBEDDED;
         if (Serializable.class.isAssignableFrom(type))
@@ -260,10 +260,10 @@
 
         int access = 0;
         if (annotated((Field[]) AccessController.doPrivileged(
-            J2DoPriv5Helper.getDeclaredFieldsAction(cls))).size() > 0)
+            J2DoPrivHelper.getDeclaredFieldsAction(cls))).size() > 0)
             access |= ClassMetaData.ACCESS_FIELD;
         if (annotated((Method[]) AccessController.doPrivileged(
-            J2DoPriv5Helper.getDeclaredMethodsAction(cls))).size() > 0
+            J2DoPrivHelper.getDeclaredMethodsAction(cls))).size() > 0
             || cls.isInterface()) // OpenJPA managed ifaces must use prop access
             access |= ClassMetaData.ACCESS_PROPERTY;
         return getAccessType(cls.getSuperclass()) | access;
@@ -272,13 +272,13 @@
     @Override
     protected List getFieldAccessNames(ClassMetaData meta) {
         return annotated((Field[]) AccessController.doPrivileged(
-            J2DoPriv5Helper.getDeclaredFieldsAction(meta.getDescribedType())));
+            J2DoPrivHelper.getDeclaredFieldsAction(meta.getDescribedType())));
     }
 
     @Override
     protected List getPropertyAccessNames(ClassMetaData meta) {
         return annotated((Method[]) AccessController.doPrivileged(
-            J2DoPriv5Helper.getDeclaredMethodsAction(meta.getDescribedType())));
+            J2DoPrivHelper.getDeclaredMethodsAction(meta.getDescribedType())));
     }
 
     /**
@@ -290,7 +290,7 @@
         String name;
         List annotated = new ArrayList(members.length);
         for (int i = 0; i < members.length; i++) {
-            annos = (Annotation[]) AccessController.doPrivileged(J2DoPriv5Helper
+            annos = (Annotation[]) AccessController.doPrivileged(J2DoPrivHelper
                 .getAnnotationsAction(members[i]));
             for (int j = 0; j < annos.length; j++) {
                 name = annos[j].annotationType().getName();
@@ -313,7 +313,7 @@
             try {
                 // check for setters for methods
                 Method setter = AccessController.doPrivileged(
-                    J2DoPriv5Helper.getDeclaredMethodAction(
+                    J2DoPrivHelper.getDeclaredMethodAction(
                         meta.getDescribedType(), "set" +
                         StringUtils.capitalize(name), new Class[] { 
                             ((Method) member).getReturnType() }));
@@ -337,7 +337,7 @@
 
     private boolean isAnnotatedTransient(Member member) {
         return member instanceof AnnotatedElement
-            && (AccessController.doPrivileged(J2DoPriv5Helper
+            && (AccessController.doPrivileged(J2DoPrivHelper
                 .isAnnotationPresentAction(((AnnotatedElement) member),
                     Transient.class))).booleanValue();
     }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java?rev=713493&r1=713492&r2=713493&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java
Wed Nov 12 12:19:40 2008
@@ -46,7 +46,7 @@
 import org.apache.openjpa.lib.meta.ClassArgParser;
 import org.apache.openjpa.lib.meta.MetaDataFilter;
 import org.apache.openjpa.lib.meta.MetaDataParser;
-import org.apache.openjpa.lib.util.J2DoPriv5Helper;
+import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.Options;
 import org.apache.openjpa.meta.AbstractCFMetaDataFactory;
@@ -293,24 +293,24 @@
             return null;
         Collection classes = repos.loadPersistentTypes(false, loader);
         for (Class cls : (Collection<Class>) classes) {
-            if ((AccessController.doPrivileged(J2DoPriv5Helper
+            if ((AccessController.doPrivileged(J2DoPrivHelper
                 .isAnnotationPresentAction(cls, NamedQuery.class)))
                 .booleanValue() && hasNamedQuery
                 (queryName, (NamedQuery) cls.getAnnotation(NamedQuery.class)))
                 return cls;
-            if ((AccessController.doPrivileged(J2DoPriv5Helper
+            if ((AccessController.doPrivileged(J2DoPrivHelper
                 .isAnnotationPresentAction(cls, NamedQueries.class)))
                 .booleanValue() &&
                 hasNamedQuery(queryName, ((NamedQueries) cls.
                     getAnnotation(NamedQueries.class)).value()))
                 return cls;
-            if ((AccessController.doPrivileged(J2DoPriv5Helper
+            if ((AccessController.doPrivileged(J2DoPrivHelper
                 .isAnnotationPresentAction(cls, NamedNativeQuery.class)))
                 .booleanValue() &&
                 hasNamedNativeQuery(queryName, (NamedNativeQuery) cls.
                     getAnnotation(NamedNativeQuery.class)))
                 return cls;
-            if ((AccessController.doPrivileged(J2DoPriv5Helper
+            if ((AccessController.doPrivileged(J2DoPrivHelper
                 .isAnnotationPresentAction(cls, NamedNativeQueries.class)))
                 .booleanValue() &&
                 hasNamedNativeQuery(queryName, ((NamedNativeQueries) cls.
@@ -329,14 +329,14 @@
         Collection classes = repos.loadPersistentTypes(false, loader);
         for (Class cls : (Collection<Class>) classes) {
 
-            if ((AccessController.doPrivileged(J2DoPriv5Helper
+            if ((AccessController.doPrivileged(J2DoPrivHelper
                 .isAnnotationPresentAction(cls, SqlResultSetMapping.class)))
                 .booleanValue() &&
                 hasRSMapping(rsMappingName, (SqlResultSetMapping) cls.
                 getAnnotation(SqlResultSetMapping.class)))
                 return cls;
 
-            if ((AccessController.doPrivileged(J2DoPriv5Helper
+            if ((AccessController.doPrivileged(J2DoPrivHelper
                 .isAnnotationPresentAction(cls, SqlResultSetMappings.class)))
                 .booleanValue() &&
                 hasRSMapping(rsMappingName, ((SqlResultSetMappings) cls.
@@ -458,11 +458,11 @@
         ClassLoader loader = repos.getConfiguration().
             getClassResolverInstance().getClassLoader(getClass(), null);
         URL rsrc = AccessController.doPrivileged(
-            J2DoPriv5Helper.getResourceAction(loader, "META-INF/orm.xml"));
+            J2DoPrivHelper.getResourceAction(loader, "META-INF/orm.xml"));
         if (rsrc != null) {
             File file = new File(rsrc.getFile());
             if ((AccessController.doPrivileged(
-                J2DoPriv5Helper.existsAction(file))).booleanValue())
+                J2DoPrivHelper.existsAction(file))).booleanValue())
                 return file;
         }
         return new File("orm.xml");



Mime
View raw message