tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fra...@apache.org
Subject svn commit: r399033 - /incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java
Date Tue, 02 May 2006 20:15:39 GMT
Author: frankb
Date: Tue May  2 13:15:37 2006
New Revision: 399033

URL: http://svn.apache.org/viewcvs?rev=399033&view=rev
Log:
Fix for TUSCANY-256

Modified:
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java?rev=399033&r1=399032&r2=399033&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java
Tue May  2 13:15:37 2006
@@ -20,6 +20,8 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedExceptionAction;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
@@ -391,28 +393,29 @@
    */
   public static void registerStaticTypes(Class factoryClass)
   {
-    //TODO this implementation is a temporary kludge until the SDO generated factory pattern
is decided
+    //TODO this implementation is temporary, until the SDO generated factory pattern is decided
+    //
     String temp = factoryClass.getName().replaceFirst("Factory$", "PackageImpl");
     int lastDot = temp.lastIndexOf('.');
     String packageName = temp.substring(0, lastDot) + ".impl" + temp.substring(lastDot);
-    try
+    try // this case handles the current default generator pattern
     {
-      Class javaClass = factoryClass.getClassLoader().loadClass(packageName);
+      Class javaClass = getPackageClass(factoryClass, packageName);
       Field field = javaClass.getField("eINSTANCE");
       field.get(null); 
     }
     catch (Exception e1)
     {
       packageName = factoryClass.getName().replaceFirst("Factory$", "Package");
-      try
+      try // this case handles the -noInterfaces generator pattern
       {
-        Class javaClass = factoryClass.getClassLoader().loadClass(packageName);
+        Class javaClass = getPackageClass(factoryClass, packageName);
         Field field = javaClass.getField("eINSTANCE");
         field.get(null); 
       }
       catch (Exception e2)
       {
-        try
+        try // this case handles the -noEMF generator pattern
         {
           Field field = factoryClass.getField("INSTANCE");
           field.get(null); 
@@ -423,6 +426,17 @@
         }
       }
     }
+  }
+
+  private static Class getPackageClass(Class factoryClass, String packageName) throws Exception
+  {
+    final Class factoryClassTemp = factoryClass;
+    final String packageNameTemp = packageName;
+    return (Class)AccessController.doPrivileged(new PrivilegedExceptionAction() {
+        public Object run() throws Exception {
+          return factoryClassTemp.getClassLoader().loadClass(packageNameTemp);
+        }
+      });
   }
 
   //XSD to SDO Mappings mappings (p.95 of the SDO spec)



Mime
View raw message