geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1329447 - in /geronimo/server/branches/3.0-beta: framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/ plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/
Date Mon, 23 Apr 2012 21:08:42 GMT
Author: xuhaihong
Date: Mon Apr 23 21:08:42 2012
New Revision: 1329447

URL: http://svn.apache.org/viewvc?rev=1329447&view=rev
Log:
Add a util method for accessing nested entry in the jar file from a bundle, depending on the
installation url, different url is created

Modified:
    geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/BundleUtil.java
    geronimo/server/branches/3.0-beta/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java
    geronimo/server/branches/3.0-beta/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java

Modified: geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/BundleUtil.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/BundleUtil.java?rev=1329447&r1=1329446&r2=1329447&view=diff
==============================================================================
--- geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/BundleUtil.java
(original)
+++ geronimo/server/branches/3.0-beta/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/BundleUtil.java
Mon Apr 23 21:08:42 2012
@@ -97,4 +97,20 @@ public class BundleUtil {
         }
         return bundle.getEntry(name);
     }
+
+    public static URL getNestedEntry(Bundle bundle, String jarEntryName, String subEntryName)
throws MalformedURLException {
+        File bundleFile = toFile(bundle);
+        if (bundleFile != null && bundleFile.isDirectory()) {
+            File entryFile = new File(bundleFile, jarEntryName);
+            if (entryFile.exists()) {
+                if (entryFile.isFile()) {
+                    return new URL("jar:" + entryFile.toURI().toURL() + "!/" + subEntryName);
+                } else {
+                    return new File(entryFile, subEntryName).toURI().toURL();
+                }
+            }
+            return null;
+        }
+        return new URL("jar:" + bundle.getEntry(jarEntryName).toString() + "!/" + subEntryName);
+    }
 }

Modified: geronimo/server/branches/3.0-beta/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-beta/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java?rev=1329447&r1=1329446&r2=1329447&view=diff
==============================================================================
--- geronimo/server/branches/3.0-beta/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java
(original)
+++ geronimo/server/branches/3.0-beta/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java
Mon Apr 23 21:08:42 2012
@@ -28,6 +28,7 @@ import java.util.Map;
 import java.util.Set;
 
 import javax.xml.namespace.QName;
+
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.AbstractNameQuery;
@@ -96,7 +97,7 @@ public class PersistenceRefBuilder exten
         return plan != null && plan.selectChildren(PersistenceRefBuilder.GER_PERSISTENCE_UNIT_REF_QNAME_SET).length
> 0;
     }
 
-    public void buildNaming(JndiConsumer specDD, XmlObject plan, Module module, Map<EARContext.Key,
Object> sharedContext) throws DeploymentException {
+    public void buildNaming(JndiConsumer specDD, XmlObject plan, Module<?, ?> module,
Map<EARContext.Key, Object> sharedContext) throws DeploymentException {
         Configuration localConfiguration = module.getEarContext().getConfiguration();
         List<DeploymentException> problems = new ArrayList<DeploymentException>();
 
@@ -207,19 +208,19 @@ public class PersistenceRefBuilder exten
                 AbstractName childName = module.getEarContext().getNaming().createChildName(module.getModuleName(),
"", NameFactory.PERSISTENCE_UNIT);
                 Map<String, String> name = new HashMap<String, String>(childName.getName());
                 name.remove(NameFactory.J2EE_NAME);
-                
+
                 persistenceUnitNameQuery = new AbstractNameQuery(null, name, PERSISTENCE_UNIT_INTERFACE_TYPES);
                 Set<AbstractNameQuery> patterns = Collections.singleton(persistenceUnitNameQuery);
                 gbeans = localConfiguration.findGBeanDatas(module.getEarContext().getConfiguration(),
patterns);
-                
+
                 if (!gbeans.isEmpty()) {
                     persistenceUnitNameQuery = checkForDefaultPersistenceUnit(gbeans);
                     break;
                 }
-                                
+
                 module = module.getParentModule();
             } while(module!=null);
-            
+
             if (gbeans.isEmpty()) {
                 if (defaultPersistenceUnitAbstractNameQuery == null) {
                     throw new DeploymentException("No default PersistenceUnit specified,
and none located");

Modified: geronimo/server/branches/3.0-beta/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-beta/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java?rev=1329447&r1=1329446&r2=1329447&view=diff
==============================================================================
--- geronimo/server/branches/3.0-beta/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java
(original)
+++ geronimo/server/branches/3.0-beta/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java
Mon Apr 23 21:08:42 2012
@@ -57,6 +57,8 @@ import org.apache.geronimo.kernel.Naming
 import org.apache.geronimo.kernel.config.ConfigurationModuleType;
 import org.apache.geronimo.kernel.config.ConfigurationStore;
 import org.apache.geronimo.kernel.repository.Environment;
+import org.apache.geronimo.kernel.util.BundleUtil;
+import org.apache.geronimo.kernel.util.IOUtils;
 import org.apache.geronimo.naming.ResourceSource;
 import org.apache.geronimo.persistence.PersistenceUnitGBean;
 import org.apache.openejb.jee.JAXBContextFactory;
@@ -128,7 +130,7 @@ public class PersistenceUnitBuilder impl
         Map<String, Persistence.PersistenceUnit> overrides = new HashMap<String,
Persistence.PersistenceUnit>();
         try {
             for (XmlObject raw : raws) {
-             
+
                 Persistence persistence = fromXmlObject(raw);
                 for (Persistence.PersistenceUnit unit : persistence.getPersistenceUnit())
{
                     overrides.put(unit.getName().trim(), unit);
@@ -141,27 +143,27 @@ public class PersistenceUnitBuilder impl
 
             final Collection<String> manifestcpCopy = new LinkedHashSet<String>
();
             boolean resolveWARcp = false;
-            
-            // resolve the classpath for non-standalone war file since module.getClassPath

+
+            // resolve the classpath for non-standalone war file since module.getClassPath
             // returns the classpath relative to the war file
             if (!module.isStandAlone() && module.getType() == ConfigurationModuleType.WAR)
{
                 resolveWARcp = true;
-            } 
-            
+            }
+
             final Collection<String> manifestcp = module.getClassPath();
             for (String classpath : manifestcp) {
                 if (resolveWARcp) {
-                    manifestcpCopy.add(module.resolve(classpath).toString());           
        
+                    manifestcpCopy.add(module.resolve(classpath).toString());
                 } else {
                     manifestcpCopy.add(classpath);
                 }
             }
-            
+
             // add "" into manifestcpCopy to make META-INF/persistence.xml in standalone
ejb be processed
             if (module.isStandAlone() && module.getType() == ConfigurationModuleType.EJB)
{
                 manifestcpCopy.add("");
             }
-            
+
             BundleResourceFinder finder = new BundleResourceFinder(packageAdmin, bundle,
"", "META-INF/persistence.xml", new ResourceDiscoveryFilter() {
 
                 @Override
@@ -176,14 +178,14 @@ public class PersistenceUnitBuilder impl
 
                 @Override
                 public boolean directoryDiscoveryRequired(String s) {
-                    
+
                     boolean found = false;
                     if (manifestcpCopy.contains(s)){
                         found=true;
                     } else if(s.endsWith("/") && manifestcpCopy.contains(s.substring(0,s.length()-1))){
                         found=true;
                     }
-                    
+
                     return found;
                 }
             });
@@ -196,8 +198,7 @@ public class PersistenceUnitBuilder impl
                 }
 
                 public boolean foundInJar(Bundle bundle, String jarName, ZipEntry entry,
InputStream inputStream) throws Exception {
-                    URL jarURL = bundle.getEntry(jarName);
-                    URL url = new URL("jar:" + jarURL.toString() + "!/" + entry.getName());
+                    URL url = BundleUtil.getNestedEntry(bundle, jarName, entry.getName());
                     persistenceURLs.put(url, jarName);
                     return true;
                 }
@@ -215,7 +216,7 @@ public class PersistenceUnitBuilder impl
                 } catch (JAXBException e) {
                     throw new DeploymentException("Could not parse persistence.xml file:
" + persistenceUrl, e);
                 } finally {
-                    in.close();
+                    IOUtils.close(in);
                 }
                 buildPersistenceUnits(persistence, overrides, module, persistenceLocation);
             }
@@ -265,7 +266,7 @@ public class PersistenceUnitBuilder impl
         }
         gbeanData.setAttribute("persistenceUnitName", persistenceUnitName);
         gbeanData.setAttribute("persistenceUnitRoot", persistenceModulePath);
-        
+
         //try to start PU GBean firstly to init the transformer before the entity classes
get loaded.
         gbeanData.setPriority(GBeanInfo.PRIORITY_CLASSLOADER);
 
@@ -374,28 +375,28 @@ public class PersistenceUnitBuilder impl
     }
 
     private Persistence fromXmlObject(XmlObject xmlObject) throws JAXBException {
-        
-        /* 
-         * To avoid illegal exception in JAXB. Convert 
-         * 
-         * <xml-fragment> ... </xml-fragment> 
+
+        /*
+         * To avoid illegal exception in JAXB. Convert
+         *
+         * <xml-fragment> ... </xml-fragment>
          * to
          * <persistence xmlns="http://java.sun.com/xml/ns/persistence"> ... </persistence>
-         * 
-         * before unmarshalling it 
+         *
+         * before unmarshalling it
          */
         XmlObject newXmlObject=XmlObject.Factory.newInstance();
         XmlCursor newXmlCursor=newXmlObject.newCursor();
         newXmlCursor.toNextToken();
         newXmlCursor.beginElement(PERSISTENCE_QNAME);
-        
+
         XmlCursor oldXmlCursor=xmlObject.newCursor();
         oldXmlCursor.copyXmlContents(newXmlCursor);
-        
+
         oldXmlCursor.dispose();
         newXmlCursor.dispose();
-        
-        
+
+
         XMLStreamReader reader = newXmlObject.newXMLStreamReader();
         JAXBContext context = JAXBContextFactory.newInstance(Persistence.class);
         Unmarshaller unmarshaller = context.createUnmarshaller();



Mime
View raw message