db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r292681 - in /incubator/jdo/trunk: core20/src/java/org/apache/jdo/impl/model/java/reflection/ ri11/src/java/org/apache/jdo/impl/model/java/ ri11/src/java/org/apache/jdo/impl/model/java/reflection/ ri11/src/java/org/apache/jdo/impl/model/jav...
Date Fri, 30 Sep 2005 09:03:02 GMT
Author: mbo
Date: Fri Sep 30 02:02:50 2005
New Revision: 292681

URL: http://svn.apache.org/viewcvs?rev=292681&view=rev
Log:
Changed java model implementation to make sure a class object is initialized 
such that pc classes register itself at the JDOImplHelper.
Cleaned up I18N bundle in java model implementation.

Added:
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModelFactory.java
Modified:
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java
    incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModelFactory.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/Bundle.properties
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/Bundle.properties
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModelFactory.java
    incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/Bundle.properties

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java?rev=292681&r1=292680&r2=292681&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java
(original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java
Fri Sep 30 02:02:50 2005
@@ -96,8 +96,8 @@
                     // loaded, Class.forName will load the class which
                     // calls RegisterClassListener.registerClass.
                     // This will create a new JavaType entry in the cache.
-                    javaType = getJavaType(Class.forName(name, initialize, 
-                                                         classLoader));
+                    javaType = getJavaTypeInternal(
+                        Class.forName(name, initialize, classLoader));
                 }
                 catch (ClassNotFoundException ex) {
                     // cannot find class => return null
@@ -130,15 +130,21 @@
      */
     public JavaType getJavaType(Class clazz)
     {
-        String name = clazz.getName();
-        synchronized (types) {
-            JavaType javaType = (JavaType)types.get(name);
-            if (javaType == null) {
-                javaType = newJavaTypeInstance(clazz);
-                types.put(name, javaType);
+        if (clazz == null)
+            return null;
+        
+        if (initialize) {
+            try {
+                // make sure the class is initialized
+                Class.forName(clazz.getName(), initialize, 
+                    ReflectionJavaModelFactory.getClassLoaderPrivileged(clazz));
+            }
+            catch (ClassNotFoundException ex) {
+                // ignore, since class has already been loaded 
             }
-            return javaType;
         }
+
+        return getJavaTypeInternal(clazz);
     }
 
     /**
@@ -190,6 +196,28 @@
     public ClassLoader getClassLoader()
     {
         return classLoader;
+    }
+
+    /**
+     * The method returns the JavaType instance for the type name of the
+     * specified class object. It first checks the cache and if there is no
+     * entry for the type name in the cache then it creates a new JavaType
+     * instance for the specified Class object.
+     * @param clazz the Class instance representing the type
+     * @return a JavaType instance for the name of the specified class
+     * object or <code>null</code> if not present in this model instance.
+     */
+    protected JavaType getJavaTypeInternal(Class clazz)
+    {
+        String name = clazz.getName();
+        synchronized (types) {
+            JavaType javaType = (JavaType)types.get(name);
+            if (javaType == null) {
+                javaType = newJavaTypeInstance(clazz);
+                types.put(name, javaType);
+            }
+            return javaType;
+        }
     }
     
     /** */

Modified: incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModelFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModelFactory.java?rev=292681&r1=292680&r2=292681&view=diff
==============================================================================
--- incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModelFactory.java
(original)
+++ incubator/jdo/trunk/core20/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModelFactory.java
Fri Sep 30 02:02:50 2005
@@ -35,7 +35,7 @@
  * instances per ClassLoader.
  * 
  * @author Michael Bouschen
- * @since JDO 2.0
+ * @since JDO 1.1
  */
 public abstract class ReflectionJavaModelFactory
     extends AbstractJavaModelFactory
@@ -145,7 +145,7 @@
      * @exception ModelFatalException wraps the SecurityException thrown by
      * getClassLoader.
      */
-    public ClassLoader getClassLoaderPrivileged(final Class clazz)
+    public static ClassLoader getClassLoaderPrivileged(final Class clazz)
     {
         if (clazz == null)
             return null;

Modified: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/Bundle.properties
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/Bundle.properties?rev=292681&r1=292680&r2=292681&view=diff
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/Bundle.properties (original)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/Bundle.properties Fri
Sep 30 02:02:50 2005
@@ -27,7 +27,7 @@
 EXC_ClassLoadingError=Error during loading of class ''{0}'': {1}.
 
 #
-# ReflectionJavaType
+# BaseReflectionJavaType
 #
 
 # {0} - error location (class.method)
@@ -35,6 +35,16 @@
 ERR_InvalidNullClassInstance={0}: specified Class instance is null.
 
 #
+# ReflectionJavaType
+#
+
+# {0} - error location (class.method)
+# {1} - implementation method name
+# {2} - field name
+#NOI18N
+ERR_MultipleJavaField={0}: multiple JavaField ''{1}'' for class ''{2}''.
+
+#
 # BaseReflectionJavaField
 #
 # {0} - class name
@@ -53,4 +63,14 @@
 # {0} - class name
 # {1} - method name
 EXC_MethodNotSupported=Class {0} does not support method {1}.
+
+#
+# ReflectionJavaModelFactory
+#
+
+# {0} - class instance
+EXC_CannotGetClassLoader=A SecurityException was thrown when trying to get the \
+class loader of class instance ''{0}''. In order to get runtime metadata, you \
+must grant ReflectPermission("getClassLoader") to the codeBase containing the \
+JDO Reference Implementation (jdori.jar).
 

Modified: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java?rev=292681&r1=292680&r2=292681&view=diff
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java
(original)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModel.java
Fri Sep 30 02:02:50 2005
@@ -87,8 +87,8 @@
                     // loaded, Class.forName will load the class which
                     // calls RegisterClassListener.registerClass.
                     // This will create a new JavaType entry in the cache.
-                    javaType = getJavaType(Class.forName(name, initialize, 
-                                                         classLoader));
+                    javaType = getJavaTypeInternal(
+                        Class.forName(name, initialize, classLoader));
                 }
                 catch (ClassNotFoundException ex) {
                     // cannot find class => return null
@@ -121,15 +121,21 @@
      */
     public JavaType getJavaType(Class clazz)
     {
-        String name = clazz.getName();
-        synchronized (types) {
-            JavaType javaType = (JavaType)types.get(name);
-            if (javaType == null) {
-                javaType = createJavaType(clazz);
-                types.put(name, javaType);
+        if (clazz == null)
+            return null;
+        
+        if (initialize) {
+            try {
+                // make sure the class is initialized
+                Class.forName(clazz.getName(), initialize, 
+                    ReflectionJavaModelFactory.getClassLoaderPrivileged(clazz));
+            }
+            catch (ClassNotFoundException ex) {
+                // ignore, since class has already been loaded 
             }
-            return javaType;
         }
+
+        return getJavaTypeInternal(clazz);
     }
 
     /**
@@ -168,6 +174,28 @@
     public ClassLoader getClassLoader()
     {
         return classLoader;
+    }
+
+    /**
+     * The method returns the JavaType instance for the type name of the
+     * specified class object. It first checks the cache and if there is no
+     * entry for the type name in the cache then it creates a new JavaType
+     * instance for the specified Class object.
+     * @param clazz the Class instance representing the type
+     * @return a JavaType instance for the name of the specified class
+     * object or <code>null</code> if not present in this model instance.
+     */
+    protected JavaType getJavaTypeInternal(Class clazz)
+    {
+        String name = clazz.getName();
+        synchronized (types) {
+            JavaType javaType = (JavaType)types.get(name);
+            if (javaType == null) {
+                javaType = createJavaType(clazz);
+                types.put(name, javaType);
+            }
+            return javaType;
+        }
     }
 
     /** 

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModelFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModelFactory.java?rev=292681&view=auto
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModelFactory.java
(added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/reflection/ReflectionJavaModelFactory.java
Fri Sep 30 02:02:50 2005
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.jdo.impl.model.java.reflection;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.apache.jdo.model.ModelException;
+import org.apache.jdo.model.ModelFatalException;
+import org.apache.jdo.model.java.JavaModel;
+import org.apache.jdo.model.java.JavaType;
+import org.apache.jdo.impl.model.java.AbstractJavaModelFactory;
+import org.apache.jdo.impl.model.java.BaseReflectionJavaType;
+import org.apache.jdo.util.I18NHelper;
+
+/**
+ * A reflection based JavaModelFactory implementation. 
+ * 
+ * @since JDO 1.1
+ */
+public abstract class ReflectionJavaModelFactory
+    extends AbstractJavaModelFactory
+{    
+    /** I18N support */
+    private final static I18NHelper msg =  
+        I18NHelper.getInstance("org.apache.jdo.impl.model.java.Bundle"); //NOI18N
+
+    // ===== Methods not defined in JavaModelFactory =====
+
+    /**
+     * Calls getClassLoader on the specified class instance in a
+     * doPrivileged block. Any SecurityException is wrapped into a
+     * ModelFatalException. 
+     * @return the class loader that loaded the specified class instance.
+     * @exception ModelFatalException wraps the SecurityException thrown by
+     * getClassLoader.
+     */
+    public static ClassLoader getClassLoaderPrivileged(final Class clazz)
+    {
+        if (clazz == null)
+            return null;
+
+        try { 
+            return (ClassLoader) AccessController.doPrivileged(
+                new PrivilegedAction () {
+                    public Object run () {
+                        return clazz.getClassLoader();
+                    }
+                }
+                );
+        }
+        catch (SecurityException ex) {
+            throw new ModelFatalException(
+                msg.msg("EXC_CannotGetClassLoader", clazz), ex); //NOI18N
+        }
+    }
+
+}

Modified: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/Bundle.properties
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/Bundle.properties?rev=292681&r1=292680&r2=292681&view=diff
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/Bundle.properties
(original)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/Bundle.properties
Fri Sep 30 02:02:50 2005
@@ -14,19 +14,6 @@
 # limitations under the License.
 
 #
-# Generic messages
-#
-
-# {0} - location (class.method)
-#NOI18N
-ERR_InvalidNullFieldInstance={0}: specified Field instance is null.
-
-
-# {0} - class name
-# {1} - detailed message of the cause
-EXC_ClassLoadingError=Error during loading of class ''{0}'': {1}.
-
-#
 # RuntimeJavaModelFactory
 #
 
@@ -40,12 +27,6 @@
 metadata, you must grant javax.jdo.spi.JDOPermission("getMetadata") to the \
 codeBases containing the JDO Reference Implementation (jdo.jar and jdori.jar).
 
-# {0} - class instance
-EXC_CannotGetClassLoader=A SecurityException was thrown when trying to get the \
-class loader of class instance ''{0}''. In order to get runtime metadata, you \
-must grant ReflectPermission("getClassLoader") to the codeBase containing the \
-JDO Reference Implementation (jdori.jar).
-
 # {0} - key instance
 EXC_InvalidJavaModelKey=Invalid key for runtime JavaModel lookup: \
 expected ''java.lang.ClassLoader'' instance, found ''{0}'' instance.
@@ -62,12 +43,3 @@
 #NOI18N
 ERR_CannotSetJDOModel=Cannot set JDOModel for JavaModel instance.
 
-#
-# RuntimeJavaType
-#
-
-# {0} - error location (class.method)
-# {1} - implementation method name
-# {2} - field name
-#NOI18N
-ERR_MultipleJavaField={0}: multiple JavaField ''{1}'' for class '{2}''.

Modified: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModelFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModelFactory.java?rev=292681&r1=292680&r2=292681&view=diff
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModelFactory.java
(original)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/model/java/runtime/RuntimeJavaModelFactory.java
Fri Sep 30 02:02:50 2005
@@ -30,8 +30,8 @@
 import org.apache.jdo.model.java.JavaType;
 import org.apache.jdo.model.jdo.JDOModelFactory;
 import org.apache.jdo.model.jdo.JDOModel;
-import org.apache.jdo.impl.model.java.AbstractJavaModelFactory;
 import org.apache.jdo.impl.model.java.BaseReflectionJavaType;
+import org.apache.jdo.impl.model.java.reflection.ReflectionJavaModelFactory;
 import org.apache.jdo.impl.model.jdo.caching.JDOModelFactoryImplCaching;
 import org.apache.jdo.util.I18NHelper;
 
@@ -52,7 +52,7 @@
  * @since JDO 1.0.1
  */
 public class RuntimeJavaModelFactory
-    extends AbstractJavaModelFactory
+    extends ReflectionJavaModelFactory
 {    
     /** The singleton RuntimeJavaModelFactory instance. */    
     private static final RuntimeJavaModelFactory runtimeJavaModelFactory = 
@@ -219,34 +219,6 @@
     // ===== Methods not defined in JavaModelFactory =====
 
     /**
-     * Calls getClassLoader on the specified class instance in a
-     * doPrivileged block. Any SecurityException is wrapped into a
-     * ModelFatalException. 
-     * @return the class loader that loaded the specified class instance.
-     * @exception ModelFatalException wraps the SecurityException thrown by
-     * getClassLoader.
-     */
-    public ClassLoader getClassLoaderPrivileged(final Class clazz)
-    {
-        if (clazz == null)
-            return null;
-
-        try { 
-            return (ClassLoader) AccessController.doPrivileged(
-                new PrivilegedAction () {
-                    public Object run () {
-                        return clazz.getClassLoader();
-                    }
-                }
-                );
-        }
-        catch (SecurityException ex) {
-            throw new ModelFatalException(
-                msg.msg("EXC_CannotGetClassLoader", clazz), ex); //NOI18N
-        }
-    }
-
-    /**
      * Returns the <code>java.lang.Class</code> wrapped in the specified 
      * JavaType. 
      * @return the <code>java.lang.Class</code> for the specified
@@ -283,7 +255,8 @@
             javaModel.setJDOModel(jdoModel);
         }
         catch (ModelException ex) {
-            throw new ModelFatalException("ERR_CannotSetJDOModel", ex); //NOI18N
+            throw new ModelFatalException(
+                msg.msg("ERR_CannotSetJDOModel"), ex); //NOI18N
         }
     }
 }

Modified: incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/Bundle.properties
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/Bundle.properties?rev=292681&r1=292680&r2=292681&view=diff
==============================================================================
--- incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/Bundle.properties
(original)
+++ incubator/jdo/trunk/runtime20/src/java/org/apache/jdo/impl/model/java/runtime/Bundle.properties
Fri Sep 30 02:02:50 2005
@@ -35,4 +35,4 @@
 # {1} - implementation method name
 # {2} - field name
 #NOI18N
-ERR_MultipleJavaField={0}: multiple JavaField ''{1}'' for class '{2}''.
+ERR_MultipleJavaField={0}: multiple JavaField ''{1}'' for class ''{2}''.



Mime
View raw message