[jbpm-commits] JBoss JBPM SVN: r1573 - in api/trunk/modules/api/src/main/java/org/jboss/bpm: util and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Jul 10 10:08:20 EDT 2008


Author: thomas.diesler at jboss.com
Date: 2008-07-10 10:08:20 -0400 (Thu, 10 Jul 2008)
New Revision: 1573

Added:
   api/trunk/modules/api/src/main/java/org/jboss/bpm/util/
   api/trunk/modules/api/src/main/java/org/jboss/bpm/util/ProcessMarshaller.java
   api/trunk/modules/api/src/main/java/org/jboss/bpm/util/ProcessUnmarshaller.java
Log:
Add ProcessMarshaller/Unmarshaller

Added: api/trunk/modules/api/src/main/java/org/jboss/bpm/util/ProcessMarshaller.java
===================================================================
--- api/trunk/modules/api/src/main/java/org/jboss/bpm/util/ProcessMarshaller.java	                        (rev 0)
+++ api/trunk/modules/api/src/main/java/org/jboss/bpm/util/ProcessMarshaller.java	2008-07-10 14:08:20 UTC (rev 1573)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.util;
+
+// $Id$
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+
+import org.jboss.bpm.model.Process;
+
+/**
+ * A JAXB marshaller for a Process
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 08-Jul-2008
+ */
+public class ProcessMarshaller
+{
+  public void marshallProcess(Process proc, Writer out) throws JAXBException, IOException
+  {
+    StringWriter strwr = new StringWriter();
+    JAXBContext jaxbContext = JAXBContext.newInstance(Process.class.getPackage().getName());
+    Marshaller marshaller = jaxbContext.createMarshaller();
+    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
+
+    marshaller.marshal(proc, strwr);
+
+    // Add xmlns:xsi to the top level element and remove it from all others
+    String str = strwr.toString();
+    String xsi = " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";
+    str = new StringBuilder(str.replace(xsi, "")).insert(str.indexOf(">"), xsi).toString();
+
+    // Write the xml string
+    out.write(str);
+  }
+}


Property changes on: api/trunk/modules/api/src/main/java/org/jboss/bpm/util/ProcessMarshaller.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: api/trunk/modules/api/src/main/java/org/jboss/bpm/util/ProcessUnmarshaller.java
===================================================================
--- api/trunk/modules/api/src/main/java/org/jboss/bpm/util/ProcessUnmarshaller.java	                        (rev 0)
+++ api/trunk/modules/api/src/main/java/org/jboss/bpm/util/ProcessUnmarshaller.java	2008-07-10 14:08:20 UTC (rev 1573)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.bpm.util;
+
+// $Id$
+
+import java.io.Reader;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+
+import org.jboss.bpm.model.FlowObject;
+import org.jboss.bpm.model.Process;
+
+/**
+ * A JAXB unmarshaller for a Process 
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 08-Jul-2008
+ */
+public class ProcessUnmarshaller 
+{
+  public Process unmarshallProcess(Reader xml) throws Exception
+  {
+    JAXBContext jaxbContext = JAXBContext.newInstance(Process.class.getPackage().getName());
+    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+    Process proc = (Process)unmarshaller.unmarshal(xml);
+    
+    // Set the process reference
+    for (FlowObject fo : proc.getFlowObjects())
+      fo.setProcess(proc);
+    
+    return proc;
+  }
+}


Property changes on: api/trunk/modules/api/src/main/java/org/jboss/bpm/util/ProcessUnmarshaller.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF




More information about the jbpm-commits mailing list