You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/02/13 21:56:59 UTC

svn commit: r1243688 - in /openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb: assembler/classic/Info.java config/ConfigurationFactory.java

Author: rmannibucau
Date: Mon Feb 13 20:56:59 2012
New Revision: 1243688

URL: http://svn.apache.org/viewvc?rev=1243688&view=rev
Log:
OPENEJB-1772 using Info class for serialization

Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Info.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Info.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Info.java?rev=1243688&r1=1243687&r2=1243688&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Info.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Info.java Mon Feb 13 20:56:59 2012
@@ -19,7 +19,9 @@ package org.apache.openejb.assembler.cla
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.annotation.XmlRootElement;
+import java.io.InputStream;
 import java.io.OutputStream;
 
 /**
@@ -27,6 +29,16 @@ import java.io.OutputStream;
  */
 @XmlRootElement
 public class Info {
+    private static final JAXBContext JAXB_CONTEXT;
+
+    static {
+        try {
+            JAXB_CONTEXT = JAXBContext.newInstance(Info.class);
+        } catch (JAXBException e) {
+            // TODO: find a better exception?
+            throw new RuntimeException("can't create jaxbcontext for Info class");
+        }
+    }
 
     public AppInfo appInfo;
 
@@ -45,11 +57,17 @@ public class Info {
         marshaller().marshal(new Info(appInfo), out);
     }
 
+    public static AppInfo unmarshal(InputStream in) throws JAXBException {
+        return ((Info) unmarshaller().unmarshal(in)).appInfo;
+    }
+
     private static Marshaller marshaller() throws JAXBException {
-        final JAXBContext jaxbContext = JAXBContext.newInstance(Info.class);
-        final Marshaller marshaller = jaxbContext.createMarshaller();
+        final Marshaller marshaller = JAXB_CONTEXT.createMarshaller();
         marshaller.setProperty("jaxb.formatted.output", true);
         return marshaller;
     }
 
+    private static Unmarshaller unmarshaller() throws JAXBException {
+        return JAXB_CONTEXT.createUnmarshaller();
+    }
 }

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?rev=1243688&r1=1243687&r2=1243688&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java Mon Feb 13 20:56:59 2012
@@ -32,6 +32,7 @@ import org.apache.openejb.assembler.clas
 import org.apache.openejb.assembler.classic.FacilitiesInfo;
 import org.apache.openejb.assembler.classic.HandlerChainInfo;
 import org.apache.openejb.assembler.classic.HandlerInfo;
+import org.apache.openejb.assembler.classic.Info;
 import org.apache.openejb.assembler.classic.JndiContextInfo;
 import org.apache.openejb.assembler.classic.ManagedContainerInfo;
 import org.apache.openejb.assembler.classic.MdbContainerInfo;
@@ -78,16 +79,14 @@ import org.apache.openejb.util.URLs;
 import org.apache.openejb.util.UpdateChecker;
 
 import javax.ejb.embeddable.EJBContainer;
+import javax.xml.bind.JAXBException;
 import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -1296,18 +1295,20 @@ public class ConfigurationFactory implem
         }
     }
 
-    public void dump(final File output, final AppInfo info) throws IOException {
+    public void dump(final File output, final AppInfo info) throws OpenEJBException {
         final File parent = output.getParentFile();
         if (!parent.exists() && !parent.mkdirs()) {
-            throw new IOException("can't create directory " + output.getParent());
+            throw new OpenEJBException("can't create directory " + output.getParent());
         }
 
-        // TODO: something else is surely better than java serialization!
-        // loadDump method should be modified too
-        final OutputStream fos = new BufferedOutputStream(new FileOutputStream(output));
-        final ObjectOutputStream oos = new ObjectOutputStream(fos);
+        FileOutputStream fos = null;
         try {
-            oos.writeObject(info);
+            fos = new FileOutputStream(output);
+            Info.marshal(info, fos);
+        } catch (FileNotFoundException e) {
+            throw new OpenEJBException(e);
+        } catch (JAXBException e) {
+            throw new OpenEJBException(e);
         } finally {
             IO.close(fos);
         }
@@ -1320,18 +1321,9 @@ public class ConfigurationFactory implem
 
         // TODO: something else is surely better than java serialization!
         final InputStream fis = new BufferedInputStream(input);
-        final ObjectInputStream ois;
-        try {
-            ois = new ObjectInputStream(fis);
-        } catch (IOException e) {
-            throw new OpenEJBException(e);
-        }
-
         try {
-            return (AppInfo) ois.readObject();
-        } catch (ClassNotFoundException e) {
-            throw new OpenEJBException(e);
-        } catch (IOException e) {
+            return Info.unmarshal(fis);
+        } catch (JAXBException e) {
             throw new OpenEJBException(e);
         } finally {
             IO.close(fis);