You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2011/11/22 14:11:35 UTC

svn commit: r1204969 - in /karaf/trunk: features/core/src/main/java/org/apache/karaf/features/internal/model/ tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/...

Author: gnodet
Date: Tue Nov 22 13:11:34 2011
New Revision: 1204969

URL: http://svn.apache.org/viewvc?rev=1204969&view=rev
Log:
[KARAF-1031] Performance issue in the features jaxb support

Modified:
    karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/model/JaxbUtil.java
    karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
    karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/GenerateDescriptorMojoTest.java

Modified: karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/model/JaxbUtil.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/model/JaxbUtil.java?rev=1204969&r1=1204968&r2=1204969&view=diff
==============================================================================
--- karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/model/JaxbUtil.java (original)
+++ karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/model/JaxbUtil.java Tue Nov 22 13:11:34 2011
@@ -25,9 +25,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Writer;
-
 import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
@@ -37,9 +35,8 @@ import javax.xml.parsers.ParserConfigura
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.sax.SAXSource;
+
 import org.xml.sax.Attributes;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
@@ -62,33 +59,29 @@ public class JaxbUtil {
         }
     }
 
-    public static <T> void marshal(Class<T> type, Object object, OutputStream out) throws JAXBException {
-        JAXBContext ctx2 = JAXBContext.newInstance(type);
-        Marshaller marshaller = ctx2.createMarshaller();
+    public static void marshal(Features features, OutputStream out) throws JAXBException {
+        Marshaller marshaller = FEATURES_CONTEXT.createMarshaller();
 
         marshaller.setProperty("jaxb.formatted.output", true);
 
-        marshaller.marshal(object, out);
+        marshaller.marshal(features, out);
     }
 
-    public static <T> void marshal(Class<T> type, Object object, Writer out) throws JAXBException {
-        JAXBContext ctx2 = JAXBContext.newInstance(type);
-        Marshaller marshaller = ctx2.createMarshaller();
+    public static void marshal(Features features, Writer out) throws JAXBException {
+        Marshaller marshaller = FEATURES_CONTEXT.createMarshaller();
 
         marshaller.setProperty("jaxb.formatted.output", true);
 
-        marshaller.marshal(object, out);
+        marshaller.marshal(features, out);
     }
 
 
     /**
-     * Read in a T from the input stream.
+     * Read in a Features from the input stream.
      *
-     * @param type     Class of object to be read in
      * @param in       input stream to read
      * @param validate whether to validate the input.
-     * @param <T>      class of object to be returned
-     * @return a T read from the input stream
+     * @return a Features read from the input stream
      * @throws ParserConfigurationException is the SAX parser can not be configured
      * @throws SAXException                 if there is an xml problem
      * @throws JAXBException                if the xml cannot be marshalled into a T.
@@ -104,8 +97,7 @@ public class JaxbUtil {
             parser = factory.newSAXParser();
         
 
-        JAXBContext ctx = JAXBContext.newInstance(Features.class);
-        Unmarshaller unmarshaller = ctx.createUnmarshaller();
+        Unmarshaller unmarshaller = FEATURES_CONTEXT.createUnmarshaller();
         unmarshaller.setEventHandler(new ValidationEventHandler() {
             public boolean handleEvent(ValidationEvent validationEvent) {
                 System.out.println(validationEvent);

Modified: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java?rev=1204969&r1=1204968&r2=1204969&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java Tue Nov 22 13:11:34 2011
@@ -299,7 +299,7 @@ public class GenerateDescriptorMojo exte
             features.getFeature().add(feature);
         }
 
-        JaxbUtil.marshal(Features.class, features, out);
+        JaxbUtil.marshal(features, out);
         try {
             checkChanges(features, objectFactory);
         } catch (Exception e) {
@@ -583,13 +583,13 @@ public class GenerateDescriptorMojo exte
         if (!addedBundles.isEmpty() || ! addedDependencys.isEmpty()) {
             out.write("\tAdded dependencies are saved here: " + addedFile.getAbsolutePath() + "\n");
             if (logDependencyChanges) {
-                JaxbUtil.marshal(Features.class, added, out);
+                JaxbUtil.marshal(added, out);
             }
         }
         if (!removedBundles.isEmpty() || !removedDependencys.isEmpty()) {
             out.write("\tRemoved dependencies are saved here: " + removedFile.getAbsolutePath() + "\n");
             if (logDependencyChanges) {
-                JaxbUtil.marshal(Features.class, removed, out);
+                JaxbUtil.marshal(removed, out);
             }
         }
         out.write("Delete " + dependencyFile.getAbsolutePath()
@@ -619,7 +619,7 @@ public class GenerateDescriptorMojo exte
         }
         FileOutputStream out = new FileOutputStream(file);
         try {
-            JaxbUtil.marshal(Features.class, features, out);
+            JaxbUtil.marshal(features, out);
         } finally {
             out.close();
         }

Modified: karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/GenerateDescriptorMojoTest.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/GenerateDescriptorMojoTest.java?rev=1204969&r1=1204968&r2=1204969&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/GenerateDescriptorMojoTest.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/GenerateDescriptorMojoTest.java Tue Nov 22 13:11:34 2011
@@ -43,7 +43,7 @@ public class GenerateDescriptorMojoTest 
         assert featuresRoot.getRepository().size() == 1;
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        JaxbUtil.marshal(Features.class, featuresRoot, baos);
+        JaxbUtil.marshal(featuresRoot, baos);
         String s = new String(baos.toByteArray());
         assert s.indexOf("repository") > -1;
         assert s.indexOf("http://karaf.apache.org/xmlns/features/v1.0.0") > -1;