You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ti...@apache.org on 2010/01/21 16:23:07 UTC

svn commit: r901737 - in /incubator/aries/trunk/jpa/jpa-container: ./ src/main/java/org/apache/aries/jpa/container/impl/ src/main/java/org/apache/aries/jpa/container/parsing/ src/main/java/org/apache/aries/jpa/container/unit/impl/ src/main/resources/OS...

Author: timothyjward
Date: Thu Jan 21 15:23:06 2010
New Revision: 901737

URL: http://svn.apache.org/viewvc?rev=901737&view=rev
Log:
ARIES-127 : Add logging to the JPA components

Modified:
    incubator/aries/trunk/jpa/jpa-container/pom.xml
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/EntityManagerFactoryManager.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidRangeCombination.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParser.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParserException.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/BundleDelegatingClassLoader.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoFactoryImpl.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java
    incubator/aries/trunk/jpa/jpa-container/src/main/resources/OSGI-INF/blueprint/jpa.xml

Modified: incubator/aries/trunk/jpa/jpa-container/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/pom.xml?rev=901737&r1=901736&r2=901737&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/pom.xml (original)
+++ incubator/aries/trunk/jpa/jpa-container/pom.xml Thu Jan 21 15:23:06 2010
@@ -60,6 +60,15 @@
       <artifactId>geronimo-jpa_2.0_spec</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <scope>test</scope>
+    </dependency> 
+    <dependency>
       <groupId>org.apache.aries.testsupport</groupId>
       <artifactId>org.apache.aries.testsupport.unit</artifactId>
       <scope>test</scope>
@@ -93,8 +102,8 @@
                     <instructions>
                         <Bundle-SymbolicName>${pom.groupId}.container</Bundle-SymbolicName>
                         <Import-Package>
-                            javax.persistence;version="[1.0.0,1.2.0)",
-                            javax.persistence.spi;version="[1.0.0,1.2.0)",
+                            javax.persistence;version="[1.0.0,2.1.0)",
+                            javax.persistence.spi;version="[1.0.0,2.1.0)",
                             *
                         </Import-Package>
                         <Export-Package>

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/EntityManagerFactoryManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/EntityManagerFactoryManager.java?rev=901737&r1=901736&r2=901737&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/EntityManagerFactoryManager.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/EntityManagerFactoryManager.java Thu Jan 21 15:23:06 2010
@@ -35,6 +35,8 @@
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 /**
  * This class manages the lifecycle of Persistence Units and their associated
  * {@link EntityManagerFactory} objects.
@@ -54,6 +56,9 @@
   /** The {@link ServiceRegistration} objects for the {@link EntityManagerFactory}s */
   private Collection<ServiceRegistration> registrations = null;
 
+  /** Logger */
+  private static final Logger _logger = LoggerFactory.getLogger("org.apache.aries.jpa.container");
+  
   /**
    * Create an {@link EntityManagerFactoryManager} for
    * the supplied persistence bundle.
@@ -140,7 +145,8 @@
         try {
           reg.unregister();
         } catch (Exception e) {
-          //TODO log this
+          _logger.error("There was an error unregistering the EntityManagerFactory services for bundle " 
+              + bundle.getSymbolicName() + "_" + bundle.getVersion() , e);
         }
       }
       // remember to set registrations to be null
@@ -164,29 +170,29 @@
       registrations = new ArrayList<ServiceRegistration>();
       String providerName = (String) provider.getProperty("javax.persistence.provider");
       if(providerName == null) {
-        //TODO log this
-        throw new InvalidPersistenceUnitException();
+        _logger.warn("The PersistenceProvider for bundle {} did not specify a provider name in the \"javax.persistence.provider\" service property. " +
+        		"As a result EntityManagerFactory objects will not be registered with the " 
+            + PersistenceUnitConstants.OSGI_UNIT_PROVIDER + " property. " 
+            + "The Peristence Provider service was {}",
+            new Object[] {bundle.getSymbolicName() + "_" + bundle.getVersion(), provider});
       }
       //Register each EMF
       for(Entry<String, EntityManagerFactory> entry : emfs.entrySet())
       {
         Properties props = new Properties();
         String unitName = entry.getKey();
-        
-        if(unitName == null) {
-          //TODO log
-          throw new InvalidPersistenceUnitException();
-        }
           
         props.put(PersistenceUnitConstants.OSGI_UNIT_NAME, unitName);
-        props.put(PersistenceUnitConstants.OSGI_UNIT_PROVIDER, providerName);
+        if(providerName != null)
+          props.put(PersistenceUnitConstants.OSGI_UNIT_PROVIDER, providerName);
         props.put(PersistenceUnitConstants.OSGI_UNIT_VERSION, provider.getBundle().getVersion());
         props.put(PersistenceUnitConstants.CONTAINER_MANAGED_PERSISTENCE_UNIT, Boolean.TRUE);
         props.put(PersistenceUnitConstants.EMPTY_PERSISTENCE_UNIT_NAME, "".equals(unitName));
         try {
           registrations.add(bundle.getBundleContext().registerService(EntityManagerFactory.class.getCanonicalName(), entry.getValue(), props));
         } catch (Exception e) {
-          //TODO log
+          _logger.error("There was an error registering the persistence unit " 
+              + unitName + " defined by the bundle " + bundle.getSymbolicName() + "_" + bundle.getVersion(), e);
           throw new InvalidPersistenceUnitException(e);
         }
       }
@@ -208,7 +214,12 @@
           //Get hold of the provider
           PersistenceProvider providerService = (PersistenceProvider) containerContext.getService(provider);
 
-          if(providerService == null) throw new InvalidPersistenceUnitException();
+          if(providerService == null) {
+            _logger.warn("The PersistenceProvider service hosting persistence units in bundle " 
+                + bundle.getSymbolicName() + "_" + bundle.getVersion() + " is no longer available. " +
+                		"Persistence units defined by the bundle will not be available until the bundle is refreshed");
+            throw new InvalidPersistenceUnitException();
+          }
       
           for(ManagedPersistenceUnitInfo info : persistenceUnits){
             PersistenceUnitInfo pUnitInfo = info.getPersistenceUnitInfo();
@@ -263,7 +274,8 @@
         try {
           entry.getValue().close();
         } catch (Exception e) {
-          //TODO log this error
+          _logger.error("There was an exception when closing the EntityManagerFactory for persistence unit "
+              + entry.getKey() + " in bundle " + bundle.getSymbolicName() + "_" + bundle.getVersion(), e);
         }
       }
     }

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidRangeCombination.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidRangeCombination.java?rev=901737&r1=901736&r2=901737&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidRangeCombination.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/InvalidRangeCombination.java Thu Jan 21 15:23:06 2010
@@ -32,7 +32,16 @@
 
   public InvalidRangeCombination(Version minVersion, boolean minExclusive,
       Version maxVersion, boolean maxExclusive) {
-    // TODO Auto-generated constructor stub
+    super("There was no overlap between the specified version ranges. The combined version range" +
+    		"string would have been " + getVersionRangeString(minVersion, minExclusive, maxVersion, maxExclusive));
   }
 
+  private static String getVersionRangeString(Version minVersion,
+      boolean minExclusive, Version maxVersion, boolean maxExclusive) {
+    
+    if(maxVersion == null)
+      return minVersion.toString();
+    else
+    return ((minExclusive) ? "(" : "[") + minVersion + "," + maxVersion + ((maxExclusive) ? ")" : "]");
+  }
 }

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java?rev=901737&r1=901736&r2=901737&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java Thu Jan 21 15:23:06 2010
@@ -30,12 +30,17 @@
 
 import org.apache.aries.jpa.container.parsing.PersistenceDescriptor;
 import org.osgi.framework.Bundle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * This helper can be used to locate persistence.xml files in a bundle
  */
 public class PersistenceBundleHelper
 {
+  /** Logger */
+  private static final Logger _logger = LoggerFactory.getLogger("org.apache.aries.jpa.container");
+  
   /** The persistence xml location */
   public static final String PERSISTENCE_XML = "META-INF/persistence.xml";
   /** The Meta-Persistence header */
@@ -69,24 +74,29 @@
         locations.add(s.trim());
     
       //Find the file and add it to our list
-      try {
-        for(String location : locations) {
-          InputStream file = locateFile(bundle, location);
-          if(file != null)
-            persistenceXmlFiles.add(new PersistenceDescriptorImpl(location, file));
-          }
-      } catch (Exception e) {
-          //TODO log
-        //If we get an exception, then go through closing all of our streams.
-        //It is better to fail completely than half succeed.
-        for (PersistenceDescriptor desc : persistenceXmlFiles) {
-          try {
-            desc.getInputStream().close();
-          } catch (IOException ioe) {
-            // TODO: log ioe
+      for(String location : locations) {
+        try {
+            InputStream file = locateFile(bundle, location);
+            if(file != null)
+              persistenceXmlFiles.add(new PersistenceDescriptorImpl(location, file));
+            
+        } catch (Exception e) {
+            _logger.error("There was an exception while locating the persistence descriptor at location "
+                + location + " in bundle " + bundle.getSymbolicName() + "_" + bundle.getVersion()
+            		+ ". No persistence descriptors will be processed for this bundle.", e);
+          //If we get an exception, then go through closing all of our streams.
+          //It is better to fail completely than half succeed.
+          for (PersistenceDescriptor desc : persistenceXmlFiles) {
+            try {
+              desc.getInputStream().close();
+            } catch (IOException ioe) {
+              //We don't care about this exception, so swallow it
+            }
           }
+          persistenceXmlFiles = Collections.emptySet();
+          //Exit the for loop
+          break;
         }
-        persistenceXmlFiles = Collections.emptySet();
       }
     }
    return persistenceXmlFiles;

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java?rev=901737&r1=901736&r2=901737&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java Thu Jan 21 15:23:06 2010
@@ -49,13 +49,17 @@
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.Version;
-
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * This class locates, parses and manages persistence units defined in OSGi bundles.
  */
 public class PersistenceBundleManager extends MultiBundleTracker
 {
+  /** Logger */
+  private static final Logger _logger = LoggerFactory.getLogger("org.apache.aries.jpa.container");
+  
   /** The bundle context for this bundle */
   private BundleContext ctx = null;
   /** 
@@ -87,20 +91,19 @@
     this.ctx = ctx;
   }
   
+  @SuppressWarnings("unchecked")
   @Override
   public void open() {
     //Create the pluggable ManagedPersistenceUnitInfoFactory
     String className = config.getProperty(ManagedPersistenceUnitInfoFactory.DEFAULT_PU_INFO_FACTORY_KEY);
-    Class<? extends ManagedPersistenceUnitInfoFactory> clazz = null;
     
     if(className != null) {
       try {
-        clazz = ctx.getBundle().loadClass(className);
+        Class<? extends ManagedPersistenceUnitInfoFactory> clazz = ctx.getBundle().loadClass(className);
         persistenceUnitFactory = clazz.newInstance();
       } catch (Exception e) {
-        // TODO Log the error
-        e.printStackTrace();
-        //clazz = default;
+        _logger.error("There was a problem creating the custom ManagedPersistenceUnitInfoFactory " + className 
+            + ". The default ManagedPersistenceUnitInfo factory will be used instead", e);
       }
     }
     
@@ -110,39 +113,8 @@
     super.open();
   }
   
-  
-  
-//  /**
-//   * If we have generated a resources for the supplied bundle, then
-//   * tidy them  up.
-//   * @param host
-//   */
-//  private void tidyUpPersistenceBundle(Bundle host)
-//  {
-//    
-//    Bundle fragment = hostToFragmentMap.remove(host);
-//    Set<ServiceRegistration> services = hostToPersistenceUnitMap.remove(host);
-//    
-//    if(services != null) {
-//      for(ServiceRegistration reg : services)
-//        reg.unregister();
-//    }
-//    
-//    if(fragment != null){
-//      try {
-//        fragment.uninstall();
-//      } catch (BundleException be) {
-//        //TODO log this error, then hope that we don't try to
-//        //recreate the fragment before restarting the framework!
-//      }
-//    }
-//  }
-
   public Object addingBundle(Bundle bundle, BundleEvent event) 
   {
-    if(bundle.getState() == Bundle.ACTIVE) {
-      //TODO LOG WARNING HERE
-    }
     EntityManagerFactoryManager mgr = null;
     mgr = setupManager(bundle, mgr);
     return mgr;
@@ -189,60 +161,21 @@
     URL u = ctx.getBundle().getResource(ManagedPersistenceUnitInfoFactory.ARIES_JPA_CONTAINER_PROPERTIES);
     
     if(u != null) {
+      if(_logger.isInfoEnabled())
+        _logger.info("A {} file was found. The default properties {} will be overridden.",
+            new Object[] {ManagedPersistenceUnitInfoFactory.ARIES_JPA_CONTAINER_PROPERTIES, config});
       try {
         config.load(u.openStream());
       } catch (IOException e) {
-        // TODO Log this error
-        e.printStackTrace();
+        _logger.error("There was an error reading from " 
+            + ManagedPersistenceUnitInfoFactory.ARIES_JPA_CONTAINER_PROPERTIES, e);
       }
+    } else {
+      if(_logger.isInfoEnabled())
+        _logger.info("No {} file was found. The default properties {} will be used.",
+            new Object[] {ManagedPersistenceUnitInfoFactory.ARIES_JPA_CONTAINER_PROPERTIES, config});
     }
   }
-     
-//      //If we can't find a provider then bomb out
-//      if (providerRef != null)
-//      {
-//        try 
-//          FragmentBuilder builder = new FragmentBuilder(b, ".jpa.fragment");
-//          builder.addImportsFromExports(providerRef.getBundle());
-//          fragment = builder.install(ctx);
-//        
-//          
-//          hostToFragmentMap.put(b, fragment);
-//          // If we successfully got a fragment then
-//          // set the provider reference and register the units
-//          Set<ServiceRegistration> registrations = new HashSet<ServiceRegistration>();
-//          Hashtable<String, Object> props = new Hashtable<String, Object>();
-//          
-//          props.put(PersistenceUnitInfoService.PERSISTENCE_BUNDLE_SYMBOLIC_NAME, b.getSymbolicName());
-//          props.put(PersistenceUnitInfoService.PERSISTENCE_BUNDLE_VERSION, b.getVersion());
-//          
-//          for(PersistenceUnitImpl unit : parsedPersistenceUnits){
-//            Hashtable<String, Object> serviceProps = new Hashtable<String, Object>(props);
-//            
-//            String unitName = (String) unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.UNIT_NAME);
-//            if(unitName != null)
-//              serviceProps.put(PersistenceUnitInfoService.PERSISTENCE_UNIT_NAME, unitName);
-//            
-//            unit.setProviderReference(providerRef);
-//            registrations.add(ctx.registerService(PersistenceUnitInfoService.class.getName(), unit, serviceProps));
-//          }
-//          hostToPersistenceUnitMap.put(b, registrations);
-//        }
-//        catch (IOException e)
-//        {
-//          // TODO Fragment generation failed, log the error
-//          // No clean up because we didn't register the bundle yet
-//          e.printStackTrace();
-//        }
-//        catch (BundleException be) {
-//          //TODO log the failure to install the fragment, but return null
-//          // to show we didn't get a fragment installed
-//          // No clean up because we didn't register the bundle yet
-//        }
-//      }
-//    }
-//  }
-
 
   public void modifiedBundle(Bundle bundle, BundleEvent event, Object object) {
 
@@ -257,7 +190,7 @@
       try {
         mgr.bundleStateChange();
       } catch (InvalidPersistenceUnitException e) {
-        // TODO log this
+        logInvalidPersistenceUnitException(bundle, e);
         mgr.destroy();
       }
     }
@@ -287,6 +220,12 @@
 
       //If we have no persistence units then our job is done
       if (!!!persistenceXmls.isEmpty()) {
+        
+        if(bundle.getState() == Bundle.ACTIVE) {
+          _logger.warn("The bundle {} is already active, it may not be possible to create managed persistence units for it.", 
+              new Object[] {bundle.getSymbolicName() + "_" + bundle.getVersion()});
+        }
+        
         Collection<ParsedPersistenceUnit> pUnits = new ArrayList<ParsedPersistenceUnit>();
         
         //Parse each descriptor
@@ -294,8 +233,9 @@
           try {
             pUnits.addAll(PersistenceDescriptorParser.parse(bundle, descriptor));
           } catch (PersistenceDescriptorParserException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
+            _logger.error("There was an error while parsing the persistence descriptor " 
+                + descriptor.getLocation() + " in bundle " + bundle.getSymbolicName() 
+                + "_" + bundle.getVersion() + ". No persistence units will be managed for this bundle", e);
           }
         }
         
@@ -323,7 +263,7 @@
             try {
               mgr.bundleStateChange();
             } catch (InvalidPersistenceUnitException e) {
-              // TODO Log this error
+              logInvalidPersistenceUnitException(bundle, e);
               mgr.destroy();
               persistenceUnitFactory.destroyPersistenceBundle(bundle);
             }
@@ -357,12 +297,12 @@
         
         if(props != null && props.containsKey(ParsedPersistenceUnit.JPA_PROVIDER_VERSION)) {
          
+          String versionRangeString = props.getProperty(ParsedPersistenceUnit.JPA_PROVIDER_VERSION, "0.0.0");
           try {
-            String versionRangeString = props.getProperty(ParsedPersistenceUnit.JPA_PROVIDER_VERSION, "0.0.0");
             versionRanges.add(ManifestHeaderProcessor.parseVersionRange(versionRangeString));
           } catch (IllegalArgumentException e) {
-            // TODO Log error. This is an invalid range and will be ignored.
-            e.printStackTrace();
+            _logger.warn("There was an error parsing the version range string {} for persistence unit {}. It will be ignored."
+                , new Object[] {versionRangeString, metadata.get(ParsedPersistenceUnit.UNIT_NAME)});
           }
         }
       }
@@ -374,15 +314,20 @@
       try {
         range = combineVersionRanges(versionRanges);
       } catch (InvalidRangeCombination e) {
-        // TODO Log this error
-        e.printStackTrace();
+        Bundle bundle = parsedPersistenceUnits.iterator().next().getDefiningBundle();
+        _logger.error("The bundle " + bundle.getSymbolicName() 
+            + "_" + bundle.getVersion() + " specified an invalid combination of provider version ranges",  e);
         return null;
       }
     }
     
     if(ppClassNames.size() > 1)
     {
-      //TODO log this error then(too many persistence providers specified)
+      Bundle bundle = parsedPersistenceUnits.iterator().next().getDefiningBundle();
+      _logger.error("The bundle " + bundle.getSymbolicName() 
+          + "_" + bundle.getVersion() + " specified more than one persistence provider: {}. "
+          + "This is not supported, so no persistence units will be created for this bundle.",
+          new Object[] {ppClassNames});
       return null;
     } else {
       //Get the best provider for the given filters
@@ -484,14 +429,15 @@
           //Return the "best" provider, i.e. the highest version
           return Collections.max(refs, new ProviderServiceComparator());
         } else {
-          //TODO no matching providers for matching criteria
+          _logger.warn("There are no suitable providers for the provider class name {} and version range {}.",
+              new Object[] {providerClass, matchingCriteria});
         }
       } else {
         //Return the "best" provider, i.e. the service OSGi would pick
         return (ServiceReference) Collections.max(persistenceProviders);
       }
     } else {
-      //TODO log no matching Providers for impl class
+      _logger.warn("There are no providers available.");
     }
     return null;
   }
@@ -514,4 +460,15 @@
       return res;
     }
   }
+  
+  /**
+   * Log a warning to indicate that the Persistence units state will be destroyed
+   * @param bundle
+   * @param e
+   */
+  private void logInvalidPersistenceUnitException(Bundle bundle,
+      InvalidPersistenceUnitException e) {
+    _logger.warn("The persistence units for bundle " + bundle.getSymbolicName() + "_" + bundle.getVersion()
+        + " became invalid and will be destroyed.", e);
+  }
 }

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParser.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParser.java?rev=901737&r1=901736&r2=901737&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParser.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParser.java Thu Jan 21 15:23:06 2010
@@ -70,6 +70,7 @@
     Collection<ParsedPersistenceUnit> persistenceUnits = new ArrayList<ParsedPersistenceUnit>();
     SAXParserFactory parserFactory = SAXParserFactory.newInstance();
     BufferedInputStream is = null;
+    boolean schemaFound = false;
     try {
       //Buffer the InputStream so we can mark it, though we'll be in 
       //trouble if we have to read more than 8192 characters before finding
@@ -85,6 +86,7 @@
         Schema s = epr.getSchema();
         
         if(s != null) {
+          schemaFound = true;
           parserFactory.setSchema(s);
           parserFactory.setNamespaceAware(true);
           parser = parserFactory.newSAXParser();
@@ -95,23 +97,23 @@
           JPAHandler handler = new JPAHandler(b, epr.getVersion());
           parser.parse(is, handler);
           persistenceUnits.addAll(handler.getPersistenceUnits());
-        } else {
-          //TODO Should we try without validation?
-        }
+        } 
       }
     } catch (Exception e) {
-      //TODO Log this error in parsing
-      System.out.println("Error parsing " + descriptor.getLocation() + " in bundle " + b.getSymbolicName() + "_" + b.getVersion());
-      e.printStackTrace();
-      throw new PersistenceDescriptorParserException(e);
+      throw new PersistenceDescriptorParserException("There was an error parsing " + descriptor.getLocation() 
+          + " in bundle " + b.getSymbolicName() + "_" + b.getVersion(), e);
     } finally {
       if(is != null) try {
         is.close();
       } catch (IOException e) {
-        //TODO Log this
-        e.printStackTrace();
+        //No logging necessary, just consume
       }
     }
+    if(!!!schemaFound) {
+    throw new PersistenceDescriptorParserException("No Schema could be located for the" +
+        "persistence descriptor " + descriptor.getLocation() 
+        + " in bundle " + b.getSymbolicName() + "_" + b.getVersion());
+    }
     return persistenceUnits;
   }
 

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParserException.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParserException.java?rev=901737&r1=901736&r2=901737&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParserException.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/parsing/PersistenceDescriptorParserException.java Thu Jan 21 15:23:06 2010
@@ -26,13 +26,22 @@
 
   /**
    * Construct a PersistenceDescriptorException
+   * @param string 
    * @param e the exception to wrap
    */
-  public PersistenceDescriptorParserException(Exception e) {
-    super(e);
+  public PersistenceDescriptorParserException(String string, Exception e) {
+    super(string, e);
   }
 
   /**
+   * Construct a PersistenceDescriptorException
+   * @param string 
+   */
+  public PersistenceDescriptorParserException(String string) {
+    super(string);
+  }
+  
+  /**
    * For Serialization
    */
   private static final long serialVersionUID = -8960763303021136544L;

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/BundleDelegatingClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/BundleDelegatingClassLoader.java?rev=901737&r1=901736&r2=901737&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/BundleDelegatingClassLoader.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/BundleDelegatingClassLoader.java Thu Jan 21 15:23:06 2010
@@ -45,6 +45,7 @@
     return bundle.getResource(resName);
   }
 
+  @SuppressWarnings("unchecked")
   @Override
   protected Enumeration<URL> findResources(String resName) throws IOException {
     return bundle.getResources(resName);

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoFactoryImpl.java?rev=901737&r1=901736&r2=901737&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoFactoryImpl.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoFactoryImpl.java Thu Jan 21 15:23:06 2010
@@ -36,6 +36,8 @@
       ServiceReference providerReference,
       Collection<ParsedPersistenceUnit> persistenceMetadata) {
     
+    //TODO add support for provider bundle imports (e.g. for weaving) here
+    
     Collection<ManagedPersistenceUnitInfo> managedUnits = new ArrayList<ManagedPersistenceUnitInfo>();
     
     for(ParsedPersistenceUnit unit : persistenceMetadata)
@@ -45,7 +47,6 @@
   }
 
   public void destroyPersistenceBundle(Bundle bundle) {
-    // TODO Auto-generated method stub
 
   }
 
@@ -53,4 +54,78 @@
     return null;
   }
 
+  //Code that can be used to attach a fragment for provider wiring
+  
+////If we can't find a provider then bomb out
+//if (providerRef != null)
+//{
+//  try 
+//    FragmentBuilder builder = new FragmentBuilder(b, ".jpa.fragment");
+//    builder.addImportsFromExports(providerRef.getBundle());
+//    fragment = builder.install(ctx);
+//  
+//    
+//    hostToFragmentMap.put(b, fragment);
+//    // If we successfully got a fragment then
+//    // set the provider reference and register the units
+//    Set<ServiceRegistration> registrations = new HashSet<ServiceRegistration>();
+//    Hashtable<String, Object> props = new Hashtable<String, Object>();
+//    
+//    props.put(PersistenceUnitInfoService.PERSISTENCE_BUNDLE_SYMBOLIC_NAME, b.getSymbolicName());
+//    props.put(PersistenceUnitInfoService.PERSISTENCE_BUNDLE_VERSION, b.getVersion());
+//    
+//    for(PersistenceUnitImpl unit : parsedPersistenceUnits){
+//      Hashtable<String, Object> serviceProps = new Hashtable<String, Object>(props);
+//      
+//      String unitName = (String) unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.UNIT_NAME);
+//      if(unitName != null)
+//        serviceProps.put(PersistenceUnitInfoService.PERSISTENCE_UNIT_NAME, unitName);
+//      
+//      unit.setProviderReference(providerRef);
+//      registrations.add(ctx.registerService(PersistenceUnitInfoService.class.getName(), unit, serviceProps));
+//    }
+//    hostToPersistenceUnitMap.put(b, registrations);
+//  }
+//  catch (IOException e)
+//  {
+//    // TODO Fragment generation failed, log the error
+//    // No clean up because we didn't register the bundle yet
+//    e.printStackTrace();
+//  }
+//  catch (BundleException be) {
+//    //TODO log the failure to install the fragment, but return null
+//    // to show we didn't get a fragment installed
+//    // No clean up because we didn't register the bundle yet
+//  }
+//}
+//}
+//}
+  
+  //Code that can be used to clear up a persistence unit
+  
+///**
+// * If we have generated a resources for the supplied bundle, then
+// * tidy them  up.
+// * @param host
+// */
+//private void tidyUpPersistenceBundle(Bundle host)
+//{
+//  
+//  Bundle fragment = hostToFragmentMap.remove(host);
+//  Set<ServiceRegistration> services = hostToPersistenceUnitMap.remove(host);
+//  
+//  if(services != null) {
+//    for(ServiceRegistration reg : services)
+//      reg.unregister();
+//  }
+//  
+//  if(fragment != null){
+//    try {
+//      fragment.uninstall();
+//    } catch (BundleException be) {
+//      //TODO log this error, then hope that we don't try to
+//      //recreate the fragment before restarting the framework!
+//    }
+//  }
+//}
 }

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java?rev=901737&r1=901736&r2=901737&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/ManagedPersistenceUnitInfoImpl.java Thu Jan 21 15:23:06 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.aries.jpa.container.unit.impl;
 
+import java.util.Collections;
 import java.util.Map;
 
 import javax.persistence.spi.PersistenceUnitInfo;
@@ -39,7 +40,7 @@
   }
 
   public Map<String, Object> getContainerProperties() {
-    return null;
+    return Collections.emptyMap();
   }
 
   public PersistenceUnitInfo getPersistenceUnitInfo() {

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java?rev=901737&r1=901736&r2=901737&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java Thu Jan 21 15:23:06 2010
@@ -35,6 +35,8 @@
 import org.apache.aries.jpa.container.parsing.ParsedPersistenceUnit;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class PersistenceUnitInfoImpl implements PersistenceUnitInfo {
   
@@ -46,6 +48,9 @@
   
   private final ServiceReference providerRef;
   
+  /** Logger */
+  private static final Logger _logger = LoggerFactory.getLogger("org.apache.aries.jpa.container");
+  
   public PersistenceUnitInfoImpl (Bundle b, ParsedPersistenceUnit parsedData, ServiceReference providerRef)
   {
     bundle = b;
@@ -55,7 +60,7 @@
   }
   
   public void addTransformer(ClassTransformer arg0) {
-    // TODO Auto-generated method stub
+    // TODO Add support for class transformation from this method
   }
 
   public boolean excludeUnlistedClasses() {
@@ -81,12 +86,14 @@
   public DataSource getJtaDataSource() {
     String jndiString = (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.NON_JTA_DATASOURCE);
     DataSource toReturn = null;
-    try {
-      InitialContext ctx = new InitialContext();
-      toReturn = (DataSource) ctx.lookup(jndiString);
-    } catch (NamingException e) {
-      // TODO Auto-generated catch block
-      e.printStackTrace();
+    if(jndiString != null) {
+      try {
+        InitialContext ctx = new InitialContext();
+        toReturn = (DataSource) ctx.lookup(jndiString);
+      } catch (NamingException e) {
+        _logger.error("No JTA datasource could be located using the JNDI name " + jndiString,
+            e);
+      }
     }
     return toReturn;
   }
@@ -109,12 +116,14 @@
     
     String jndiString = (String) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.NON_JTA_DATASOURCE);
     DataSource toReturn = null;
-    try {
-      InitialContext ctx = new InitialContext();
-      toReturn = (DataSource) ctx.lookup(jndiString);
-    } catch (NamingException e) {
-      // TODO Auto-generated catch block
-      e.printStackTrace();
+    if(jndiString != null) {
+      try {
+        InitialContext ctx = new InitialContext();
+        toReturn = (DataSource) ctx.lookup(jndiString);
+      } catch (NamingException e) {
+        _logger.error("No Non JTA datasource could be located using the JNDI name " + jndiString,
+            e);
+      }
     }
     return toReturn;
   }
@@ -140,7 +149,7 @@
   }
 
   public SharedCacheMode getSharedCacheMode() {
-    // TODO Auto-generated method stub
+    // TODO This needs to be supported once we parse JPA 2.0 xml
     return null;
   }
 
@@ -150,7 +159,7 @@
   }
 
   public ValidationMode getValidationMode() {
-    // TODO Auto-generated method stub
+    // TODO This needs to be supported once we parse JPA 2.0 xml
     return null;
   }
   

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java?rev=901737&r1=901736&r2=901737&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java Thu Jan 21 15:23:06 2010
@@ -72,6 +72,7 @@
     return bundle.getResource(resName);
   }
 
+  @SuppressWarnings("unchecked")
   @Override
   protected Enumeration<URL> findResources(String resName) throws IOException {
     return bundle.getResources(resName);

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/resources/OSGI-INF/blueprint/jpa.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/resources/OSGI-INF/blueprint/jpa.xml?rev=901737&r1=901736&r2=901737&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/resources/OSGI-INF/blueprint/jpa.xml (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/resources/OSGI-INF/blueprint/jpa.xml Thu Jan 21 15:23:06 2010
@@ -22,7 +22,7 @@
       <property name="config"><props/></property>
     </bean>
 
-	<reference-list interface="javax.persistence.spi.PersistenceProvider">
+	<reference-list interface="javax.persistence.spi.PersistenceProvider" availability="optional">
 	  <reference-listener ref="container" bind-method="addingProvider" unbind-method="removingProvider"/>
 	</reference-list>