Commits

gigadot committed 253e6c8

added MolDocPersistenceManager

  • Participants
  • Parent commits 27fe2fd

Comments (0)

Files changed (16)

File model/pom.xml

         </plugins>
     </build>
     <dependencies>
-        <!--dependency>
-            <groupId>org.eclipse.persistence</groupId>
-            <artifactId>org.eclipse.persistence.moxy</artifactId>
-            <version>{version}</version>
-        </dependency-->
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
         <dependency>
             <groupId>org.eclipse.persistence</groupId>
             <artifactId>org.eclipse.persistence.moxy</artifactId>
-            <version>2.4.0</version>
         </dependency>
     </dependencies>
     <repositories>

File model/src/main/java/gigadot/chom/model/brownie/Atom.java

 import gigadot.chom.model.Brownie;
 import gigadot.chom.model.chemistry.Element;
 import gigadot.chom.model.chemistry.PeriodicTable;
+import gigadot.chom.model.internal.jaxb.BasicProperty;
+import gigadot.chom.model.internal.jaxb.PropertyAdaptors;
+import gigadot.chom.model.jaxb.XmlTransientRules;
 import gigatools.lite.constant.PhysicalConstants;
 import javax.persistence.Entity;
 import javax.persistence.Transient;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 
 /**
  *
     protected Atom() {
     }
 
-    @XmlAttribute(name="symbol")
+    @XmlAttribute(name = "symbol")
     protected String getElementSymbol() {
         return element.symbol;
     }
     }
 
     @Transient
+    @XmlAttribute
+    @XmlTransientRules(XmlTransientRules.STANDARD)
     public int getOrder() {
         return order;
     }
 
     @Transient
+    @XmlElement(name = "x")
+    @XmlJavaTypeAdapter(value = PropertyAdaptors.LengthInAngstromPropertyAdaptor.class, type = BasicProperty.class)
+    @XmlTransientRules(XmlTransientRules.STANDARD)
     public double getXInA() {
         return posXInA;
     }
 
     @Transient
+    @XmlElement(name = "y")
+    @XmlJavaTypeAdapter(value = PropertyAdaptors.LengthInAngstromPropertyAdaptor.class, type = BasicProperty.class)
+    @XmlTransientRules(XmlTransientRules.STANDARD)
     public double getYInA() {
         return posYInA;
     }
 
     @Transient
+    @XmlElement(name = "z")
+    @XmlJavaTypeAdapter(value = PropertyAdaptors.LengthInAngstromPropertyAdaptor.class, type = BasicProperty.class)
+    @XmlTransientRules(XmlTransientRules.STANDARD)
     public double getZInA() {
         return posZInA;
     }
         posZInA = z;
     }
 
+    public void setXInA(double x) {
+        posX = x * PhysicalConstants.A;
+        posXInA = x;
+    }
+
+    public void setYInA(double y) {
+        posY = y * PhysicalConstants.A;
+        posYInA = y;
+    }
+
+    public void setZInA(double z) {
+        posZ = z * PhysicalConstants.A;
+        posZInA = z;
+    }
+
     @Transient
     public double getX() {
         return posX;

File model/src/main/java/gigadot/chom/model/cookie/EnthalpyOfFormation.java

 @XmlAccessorType(XmlAccessType.NONE)
 public class EnthalpyOfFormation extends Cookie {
 
-    @XmlElement(name = "phase")
     private Phase phase = Phase.Unknown;
     /**
      * Enthalpy of formation in J/mol.
      */
-    @XmlElement(name = "value")
     private double delta_H_f = 0.0;
     /**
      * error or standard deviation of enthalpy of formation in J/mol.
     /**
      * Temperature in K.
      */
-    @XmlElement(name = "temperature")
-    @XmlJavaTypeAdapter(value = PropertyAdaptors.TemperaturePropertyAdaptor.class, type = BasicProperty.class)
     private double T = PhysicalConstants.T_25C;
     /**
      * Temperature in K.
      */
-    @XmlElement(name = "pressure")
     private double P = PhysicalConstants.P_1atm;
 
     protected EnthalpyOfFormation() {
         this.T = hf.T;
     }
 
+    @XmlElement
     public Phase getPhase() {
         return phase;
     }
         return new EnthalpyOfFormation(dHfInkcal_Per_mol * PhysicalConstants.Cal * 1000);
     }
 
+    @XmlElement(name = "value")
+    @XmlJavaTypeAdapter(value = PropertyAdaptors.JoulePerMolePropertyAdaptor.class, type = BasicProperty.class)
     public double getValue() {
         return delta_H_f;
     }
         }
     }
 
+    @XmlElement
+    @XmlJavaTypeAdapter(value = PropertyAdaptors.TemperaturePropertyAdaptor.class, type = BasicProperty.class)
     public double getTemperature() {
         return this.T;
     }
         this.T = T;
     }
 
+    @XmlElement
+    @XmlJavaTypeAdapter(value = PropertyAdaptors.PressurePropertyAdaptor.class, type = BasicProperty.class)
     public double getPressure() {
         return P;
     }

File model/src/main/java/gigadot/chom/model/cookie/Reaction.java

 package gigadot.chom.model.cookie;
 
 import gigadot.chom.model.Cookie;
-import gigadot.chom.model.cookie.Species;
-import gigadot.chom.model.util.MolDocNamespaceConstants;
 import java.util.ArrayList;
 import java.util.List;
 import javax.persistence.Column;

File model/src/main/java/gigadot/chom/model/internal/jaxb/PropertyAdaptors.java

 
     public static class TemperaturePropertyAdaptor extends XmlAdapter<BasicProperty, Double> {
 
-        public TemperaturePropertyAdaptor() {
-            System.out.println("Creating " + getClass());
-        }
-
         @Override
         public Double unmarshal(BasicProperty v) throws Exception {
             if ("K".equals(v.units)) {
             return new BasicProperty(v, "K");
         }
     }
+
+    public static class LengthInAngstromPropertyAdaptor extends XmlAdapter<BasicProperty, Double> {
+
+        @Override
+        public Double unmarshal(BasicProperty v) throws Exception {
+            if ("A".equals(v.units)) {
+                return v.value;
+            } else {
+                throw new UnitsConversionException();
+            }
+        }
+
+        @Override
+        public BasicProperty marshal(Double v) throws Exception {
+            return new BasicProperty(v, "A");
+        }
+    }
+
+    public static class PressurePropertyAdaptor extends XmlAdapter<BasicProperty, Double> {
+
+        @Override
+        public Double unmarshal(BasicProperty v) throws Exception {
+            if ("Pa".equals(v.units)) {
+                return v.value;
+            } else {
+                throw new UnitsConversionException();
+            }
+        }
+
+        @Override
+        public BasicProperty marshal(Double v) throws Exception {
+            return new BasicProperty(v, "Pa");
+        }
+    }
+    public static class JoulePerMolePropertyAdaptor extends XmlAdapter<BasicProperty, Double> {
+
+        @Override
+        public Double unmarshal(BasicProperty v) throws Exception {
+            if ("J/mol".equals(v.units)) {
+                return v.value;
+            } else {
+                throw new UnitsConversionException();
+            }
+        }
+
+        @Override
+        public BasicProperty marshal(Double v) throws Exception {
+            return new BasicProperty(v, "J/mol");
+        }
+    }
+
 }

File model/src/main/java/gigadot/chom/model/jaxb/MolDocBinderScanner.java

+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package gigadot.chom.model.jaxb;
+
+import gigadot.chom.model.internal.jaxb.MultiPackageMetadataSourceFactory;
+import gigadot.rebound.Rebound;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import org.eclipse.persistence.jaxb.metadata.MetadataSource;
+
+/**
+ *
+ * @author wp214
+ */
+public class MolDocBinderScanner {
+
+    private Set<String> rules = new HashSet<String>();
+    private MultiPackageMetadataSourceFactory mpmsf = null;
+    private boolean haveRulesChanged = true;
+
+    public void setRules(String... rules) {
+        //this.rules = rules;
+        this.rules.clear();
+        this.rules.addAll(Arrays.asList(rules));
+        haveRulesChanged = true;
+    }
+
+    public Map<String, MetadataSource> getXmlTransientRulesMetadataSourceMap() {
+        if (mpmsf == null || haveRulesChanged) {
+            init();
+        }
+        return mpmsf.getMetadataSources();
+    }
+
+    private void init() {
+        Rebound r = new Rebound("gigadot.chom.model", true, false);
+        Set<Class<? extends Object>> clzzes = r.getSubClassesOf(Object.class);
+        mpmsf = new MultiPackageMetadataSourceFactory();
+        for (Class<? extends Object> clz : clzzes) {
+            // find @XmlTransientRules
+            Method[] transientMethods = ReflectionUtils.getAnnotatedDeclaredMethods(clz, XmlTransientRules.class);
+            for (Method method : transientMethods) {
+                // get the method or property name
+                String propertyName = ReflectionUtils.getPropertyName(method);
+                // get rules
+                XmlTransientRules xmlTransientRules = method.getAnnotation(XmlTransientRules.class);
+                boolean shouldApplyTransient = false;
+                for (String rule : xmlTransientRules.value()) {
+                    if (rules.contains(rule)) {
+                        shouldApplyTransient = true;
+                        break;
+                    }
+                }
+                if (shouldApplyTransient) {
+                    // apply transient using my metadatasource
+                    mpmsf.setXmlTransient(clz, propertyName);
+                }
+            }
+        }
+        haveRulesChanged = false;
+    }
+}

File model/src/main/java/gigadot/chom/model/jaxb/MolDocPersistenceException.java

+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package gigadot.chom.model.jaxb;
+
+/**
+ *
+ * @author wp214
+ */
+public class MolDocPersistenceException extends Exception {
+
+    public MolDocPersistenceException() {
+        super();
+    }
+
+    public MolDocPersistenceException(String message) {
+        super(message);
+    }
+
+    public MolDocPersistenceException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public MolDocPersistenceException(Throwable cause) {
+        super(cause);
+    }
+
+    public MolDocPersistenceException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+        super(message, cause, enableSuppression, writableStackTrace);
+    }
+
+}

File model/src/main/java/gigadot/chom/model/jaxb/MolDocPersistenceManager.java

+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package gigadot.chom.model.jaxb;
+
+import gigadot.chom.model.brownie.Atom;
+import gigadot.chom.model.cookie.EnthalpyOfFormation;
+import gigadot.chom.model.cookie.Species;
+import gigadot.chom.model.enumeration.IdentifierType;
+import gigadot.chom.model.internal.jaxb.MolDocSchemaOutputResolver;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.stream.XMLStreamException;
+import org.eclipse.persistence.jaxb.JAXBContextProperties;
+
+/**
+ *
+ * @author wp214
+ */
+public class MolDocPersistenceManager {
+
+    private static final Class[] knownJAXBClasses = {Atom.class, Species.class, EnthalpyOfFormation.class, IdentifierType.class};
+    private MolDocBinderScanner binderScanner = new MolDocBinderScanner();
+    // these are not to be accessed internally directly. use jaxbContext(), marshaller() and unmarshaller() instead.
+    private JAXBContext jaxbContext = null;
+    private Marshaller marshaller = null;
+    private Unmarshaller unmarshaller = null;
+
+    private JAXBContext jaxbContext() throws MolDocPersistenceException {
+        if (jaxbContext == null) {
+            try {
+                Map<String, Object> properties = new HashMap<String, Object>();
+                properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, binderScanner.getXmlTransientRulesMetadataSourceMap());
+                jaxbContext = JAXBContext.newInstance(knownJAXBClasses, properties);
+            } catch (JAXBException ex) {
+                throw new MolDocPersistenceException("Unable to create an instance of " + JAXBContext.class, ex);
+            }
+        }
+        return jaxbContext;
+    }
+
+    private Marshaller marshaller() throws MolDocPersistenceException {
+        if (marshaller == null) {
+            try {
+                marshaller = jaxbContext().createMarshaller();
+                marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+            } catch (JAXBException ex) {
+                throw new MolDocPersistenceException("Unable to create an instance of " + Marshaller.class + " in the " + getClass().getSimpleName(), ex);
+            }
+        }
+        return marshaller;
+    }
+
+    private Unmarshaller unmarshaller() throws MolDocPersistenceException {
+        if (unmarshaller == null) {
+            try {
+                unmarshaller = jaxbContext().createUnmarshaller();
+            } catch (JAXBException ex) {
+                throw new MolDocPersistenceException("Unable to create an instance of " + Marshaller.class + " in the " + getClass().getSimpleName(), ex);
+            }
+        }
+        return unmarshaller;
+    }
+
+    public void setRules(String... rules) {
+        binderScanner.setRules(rules);
+    }
+
+    public void marshal(Object jaxbElement, OutputStream os) throws MolDocPersistenceException {
+        try {
+            marshaller().marshal(jaxbElement, os);
+        } catch (JAXBException ex) {
+            throw new MolDocPersistenceException("Unable to marshal jaxbElement [" + jaxbElement + "] to the OutputStream [" + os + "]", ex);
+        }
+    }
+
+    public void marshal(Object jaxbElement, File output) throws MolDocPersistenceException {
+        try {
+            marshaller().marshal(jaxbElement, output);
+        } catch (JAXBException ex) {
+            throw new MolDocPersistenceException("Unable to marshal jaxbElement [" + jaxbElement + "] to the File [" + output + "]", ex);
+        }
+    }
+
+    public Object unmarshal(InputStream is) throws MolDocPersistenceException {
+        try {
+            return unmarshaller().unmarshal(is);
+        } catch (JAXBException ex) {
+            throw new MolDocPersistenceException("Unable to unmarshal the InputStream [" + is + "]", ex);
+        }
+    }
+
+    public Object unmarshal(File input) throws MolDocPersistenceException {
+        try {
+            return unmarshaller().unmarshal(input);
+        } catch (JAXBException ex) {
+            throw new MolDocPersistenceException("Unable to unmarshal the File [" + input + "]", ex);
+        }
+    }
+
+    public <T> T unmarshal(File input, Class<T> clz) throws MolDocPersistenceException {
+        return (T) unmarshal(input);
+    }
+
+    public <T> T unmarshal(InputStream is, Class<T> clz) throws MolDocPersistenceException {
+        return (T) unmarshal(is);
+    }
+
+    public void generateSchema(File directory) throws MolDocPersistenceException, IOException {
+        MolDocSchemaOutputResolver sor = new MolDocSchemaOutputResolver();
+        sor.setRootDirectory(directory);
+        jaxbContext().generateSchema(sor);
+    }
+}

File model/src/main/java/gigadot/chom/model/jaxb/ReflectionUtils.java

         Set<Method> mt = new HashSet<Method>();
         // add declared methods first
         mt.addAll(Arrays.asList(clz.getDeclaredMethods()));
-        mt.removeAll(Arrays.asList(Object.class.getMethods()));
+        mt.removeAll(Arrays.asList(Object.class.getDeclaredMethods()));
         return mt.toArray(new Method[mt.size()]);
     }
 
     }
 
     private static String lowerCaseFirstChar(String name) {
-        return Character.toLowerCase(name.charAt(0)) + name.substring(1);
+        if (name.length() > 1) {
+            if (Character.isUpperCase(name.charAt(0)) && Character.isUpperCase(name.charAt(1))) {
+                return name;
+            } else if (Character.isUpperCase(name.charAt(0)) && Character.isLowerCase(name.charAt(1))) {
+                return Character.toLowerCase(name.charAt(0)) + name.substring(1);
+            } else {
+                return name;
+            }
+        } else if (name.length() == 1){
+            return Character.toLowerCase(name.charAt(0)) + "";
+        } else {
+            return "";
+        }
     }
 
     public static String getPropertyName(Method method) {
     public static Method getGetter(Method method) {
         try {
             String getterName = getGetterName(method);
-            return method.getDeclaringClass().getMethod(getterName);
+            return method.getDeclaringClass().getDeclaredMethod(getterName);
         } catch (Exception ex) {
             return null;
         }
         try {
             String setterName = getSetterName(method);
             Method getter = getGetter(method);
-            return method.getDeclaringClass().getMethod(setterName, getter.getReturnType());
+            return method.getDeclaringClass().getDeclaredMethod(setterName, getter.getReturnType());
         } catch (Exception ex) {
             return null;
         }

File model/src/main/java/gigadot/chom/model/jaxb/XmlBinderScanner.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package gigadot.chom.model.jaxb;
-
-import gigadot.chom.model.internal.jaxb.MultiPackageMetadataSourceFactory;
-import gigadot.chom.model.jaxb.XmlTransientRules;
-import gigadot.rebound.Rebound;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import org.eclipse.persistence.jaxb.metadata.MetadataSource;
-
-/**
- *
- * @author wp214
- */
-public class XmlBinderScanner {
-
-    private Set<String> rules = new HashSet<String>();
-    private MultiPackageMetadataSourceFactory mpmsf = null;
-
-    public void setRules(String... rules) {
-        //this.rules = rules;
-        this.rules.clear();
-        this.rules.addAll(Arrays.asList(rules));
-    }
-
-    public Map<String, MetadataSource> getXmlTransientRulesMetadataSourceMap() {
-        if (mpmsf == null) {
-            init();
-        }
-        return mpmsf.getMetadataSources();
-    }
-
-    private void init() {
-        Rebound r = new Rebound("gigadot.chom.model", true, false);
-        Set<Class<? extends Object>> clzzes = r.getSubClassesOf(Object.class);
-        mpmsf = new MultiPackageMetadataSourceFactory();
-        for (Class<? extends Object> clz : clzzes) {
-            // find @XmlTransientRules
-            Method[] transientMethods = ReflectionUtils.getAnnotatedDeclaredMethods(clz, XmlTransientRules.class);
-            for (Method method : transientMethods) {
-                // get the method or property name
-                String propertyName = ReflectionUtils.getPropertyName(method);
-                // get rules
-                XmlTransientRules xmlTransientRules = method.getAnnotation(XmlTransientRules.class);
-                boolean shouldApplyTransient = false;
-                for (String rule : xmlTransientRules.value()) {
-                    if (rules.contains(rule)) {
-                        shouldApplyTransient = true;
-                        break;
-                    }
-                }
-                if (shouldApplyTransient) {
-                    // apply transient using my metadatasource
-                    mpmsf.setXmlTransient(clz, propertyName);
-                }
-            }
-
-        }
-    }
-}

File model/src/main/java/gigadot/chom/model/jaxb/XmlTransientRules.java

 import java.lang.annotation.Target;
 
 /**
- * override jaxb annotation. if getter is annotated and rule is enforced, the getter will be set to transient. if the getter is
- * annotated with @XmlTransient, @XmlTransient is prioritised.
+ * override jaxb annotation. if getter is annotated and rule is enforced, the getter will be set to transient. if the
+ * getter is annotated with
+ *
+ * @XmlTransient,
+ * @XmlTransient is prioritised.
  * @author wp214
  */
 @Target({ElementType.METHOD})
 @Retention(RetentionPolicy.RUNTIME)
 public @interface XmlTransientRules {
 
+    public static final String STANDARD = "standard";
+    public static final String EXTENDED = "extended";
+
     public String[] value() default {};
 }

File model/src/test/java/gigadot/chom/model/brownie/Address.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package gigadot.chom.model.brownie;
-
-/**
- *
- * @author wp214
- */
-public class Address {
-
-    private String street;
-
-    public String getStreet() {
-        return street;
-    }
-
-    public void setStreet(String street) {
-        this.street = street;
-    }
-}

File model/src/test/java/gigadot/chom/model/brownie/AtomTest.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package gigadot.chom.model.brownie;
-
-import gigadot.chom.model.cookie.EnthalpyOfFormation;
-import gigadot.chom.model.cookie.Species;
-import gigadot.chom.model.enumeration.IdentifierType;
-import gigadot.chom.model.internal.jaxb.BasicProperty;
-import gigadot.chom.model.internal.jaxb.MolDocSchemaOutputResolver;
-import gigatools.lite.constant.PhysicalConstants;
-import java.io.File;
-import java.io.IOException;
-import java.io.StringWriter;
-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;
-import javax.xml.bind.util.JAXBSource;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import org.junit.Ignore;
-import org.junit.Test;
-import static org.junit.Assert.*;
-
-/**
- *
- * @author wp214
- */
-public class AtomTest {
-
-    /**
-     * Test of getElementSymbol method, of class Atom.
-     */
-    @Test
-    @Ignore
-    public void testGetElementSymbol() throws JAXBException {
-        Atom carbon = new Atom("C");
-
-        JAXBContext contextA = JAXBContext.newInstance(Atom.class);
-        JAXBElement<Atom> jaxbElementA = new JAXBElement(new QName("student"), Atom.class, carbon);
-        JAXBSource sourceA = new JAXBSource(contextA, jaxbElementA);
-
-        JAXBContext contextB = JAXBContext.newInstance(Atom.class);
-        Unmarshaller unmarshallerB = contextB.createUnmarshaller();
-        JAXBElement<Atom> jaxbElementB = unmarshallerB.unmarshal(sourceA, Atom.class);
-
-        Atom studentB = jaxbElementB.getValue();
-        System.out.println(studentB.getElementSymbol());
-    }
-
-    @Test
-    public void method() throws JAXBException {
-        Atom carbon = new Atom("C");
-        StringWriter writer = new StringWriter();
-        JAXBContext context = JAXBContext.newInstance(Atom.class);
-        // this project requires MOXy. if it is not found, check whether jaxb.properties is in the same packages as one of the classes in the JAXBContext.newInstance
-        assertEquals(context.getClass(), org.eclipse.persistence.jaxb.JAXBContext.class);
-        Marshaller m = context.createMarshaller();
-        m.marshal(carbon, writer);
-        System.out.println(writer.toString());
-    }
-
-    @Test
-    public void method1() throws JAXBException {
-        Identifier identifier = new Identifier("CH4", IdentifierType.formula);
-        StringWriter writer = new StringWriter();
-        JAXBContext context = JAXBContext.newInstance(Identifier.class, BasicProperty.class);
-        // this project requires MOXy. if it is not found, check whether jaxb.properties is in the same packages as one of the classes in the JAXBContext.newInstance
-        assertEquals(context.getClass(), org.eclipse.persistence.jaxb.JAXBContext.class);
-        Marshaller m = context.createMarshaller();
-        m.marshal(identifier, writer);
-        System.out.println(writer.toString());
-    }
-
-    @Test
-    public void method2() throws JAXBException {
-        Identifier id1 = new Identifier("CH4", IdentifierType.formula);
-        Identifier id2 = new Identifier("Metane", IdentifierType.name);
-        Species sp = new Species();
-        sp.getIdentifiers().add(id1);
-        sp.getIdentifiers().add(id2);
-        StringWriter writer = new StringWriter();
-        JAXBContext context = JAXBContext.newInstance(Species.class, BasicProperty.class);
-        // this project requires MOXy. if it is not found, check whether jaxb.properties is in the same packages as one of the classes in the JAXBContext.newInstance
-        assertEquals(context.getClass(), org.eclipse.persistence.jaxb.JAXBContext.class);
-        Marshaller m = context.createMarshaller();
-        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
-        m.marshal(sp, writer);
-        System.out.println(writer.toString());
-    }
-
-    @Test
-    public void method3() throws JAXBException, IOException, XMLStreamException {
-        JAXBContext context = JAXBContext.newInstance(EnthalpyOfFormation.class, Species.class, IdentifierType.class);
-        // this project requires MOXy. if it is not found, check whether jaxb.properties is in the same packages as one of the classes in the JAXBContext.newInstance
-        assertEquals(context.getClass(), org.eclipse.persistence.jaxb.JAXBContext.class);
-
-        MolDocSchemaOutputResolver sor = new MolDocSchemaOutputResolver();
-        sor.setRootDirectory(new File("target"));
-        context.generateSchema(sor);
-    }
-
-    @Test
-    public void method4() throws JAXBException {
-        EnthalpyOfFormation dhf = EnthalpyOfFormation.from_kcal_Per_mol(PhysicalConstants.T_25C, 102d, 2d);
-        StringWriter writer = new StringWriter();
-        JAXBContext context = JAXBContext.newInstance(EnthalpyOfFormation.class, BasicProperty.class);
-        // this project requires MOXy. if it is not found, check whether jaxb.properties is in the same packages as one of the classes in the JAXBContext.newInstance
-        assertEquals(context.getClass(), org.eclipse.persistence.jaxb.JAXBContext.class);
-        Marshaller m = context.createMarshaller();
-        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
-        m.marshal(dhf, writer);
-        System.out.println(writer.toString());
-    }
-
-}

File model/src/test/java/gigadot/chom/model/brownie/Customer.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package gigadot.chom.model.brownie;
-
-import gigadot.chom.model.jaxb.XmlTransientRules;
-import java.util.HashMap;
-import java.util.Map;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
-import org.eclipse.persistence.oxm.annotations.XmlVirtualAccessMethods;
-
-/**
- *
- * @author wp214
- */
-@XmlRootElement
-@XmlType(propOrder = {"firstName", "lastName", "address"})
-@XmlVirtualAccessMethods
-public class Customer {
-
-    private String firstNameX;
-    private String lastName;
-    private Address billingAddress;
-
-    @XmlTransientRules({"normal"})
-    public String getFirstName() {
-        return firstNameX;
-    }
-
-    public void setFirstName(String firstName) {
-        this.firstNameX = firstName;
-    }
-
-    public String getLastName() {
-        return lastName;
-    }
-
-    public void setLastName(String lastName) {
-        this.lastName = lastName;
-    }
-
-    public Address getBillingAddress() {
-        return billingAddress;
-    }
-
-    public void setBillingAddress(Address billingAddress) {
-        this.billingAddress = billingAddress;
-    }
-
-}

File model/src/test/java/gigadot/chom/model/brownie/SomeTest.java

-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package gigadot.chom.model.brownie;
-
-import gigadot.chom.model.jaxb.XmlBinderScanner;
-import java.util.HashMap;
-import java.util.Map;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import org.eclipse.persistence.jaxb.JAXBContextProperties;
-import org.eclipse.persistence.jaxb.JAXBHelper;
-import org.junit.Test;
-
-/**
- *
- * @author wp214
- */
-public class SomeTest {
-
-    @Test
-    public void xmlTransientRulesExtension() throws JAXBException {
-        XmlBinderScanner xmlBinderScanner = new XmlBinderScanner();
-        xmlBinderScanner.setRules("normal");
-        Map<String, Object> properties = new HashMap<String, Object>();
-        properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, xmlBinderScanner.getXmlTransientRulesMetadataSourceMap());
-
-        JAXBContext jc = JAXBContext.newInstance(new Class[]{Customer.class}, properties);
-        Marshaller marshaller = jc.createMarshaller();
-        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
-
-        Customer customer = new Customer();
-        customer.setFirstName("Jane");
-        customer.setLastName("Doe");
-
-        Address billingAddress = new Address();
-        billingAddress.setStreet("123 Billing Address");
-        customer.setBillingAddress(billingAddress);
-
-        Address shippingAddress = new Address();
-        shippingAddress.setStreet("456 Shipping Address");
-
-        marshaller.marshal(customer, System.out);
-
-        JAXBHelper.getJAXBContext(jc).refreshMetadata();
-
-        marshaller.marshal(customer, System.out);
-    }
-}

File model/src/test/java/gigadot/chom/model/jaxb/MolDocPersistenceManagerTest.java

+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package gigadot.chom.model.jaxb;
+
+import gigadot.chom.model.brownie.Atom;
+import gigadot.chom.model.brownie.Identifier;
+import gigadot.chom.model.cookie.EnthalpyOfFormation;
+import gigadot.chom.model.cookie.Species;
+import gigadot.chom.model.enumeration.IdentifierType;
+import gigatools.lite.constant.PhysicalConstants;
+import java.io.File;
+import java.io.IOException;
+import javax.xml.bind.JAXBException;
+import org.apache.commons.io.IOUtils;
+import static org.junit.Assert.*;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ *
+ * @author wp214
+ */
+public class MolDocPersistenceManagerTest {
+
+    /**
+     * Test of generateSchema method, of class MolDocPersistenceManager.
+     */
+    @Test
+    public void testGenerateSchema() {
+        File directory = new File("target");
+        MolDocPersistenceManager molDocPersistenceManager = new MolDocPersistenceManager();
+        try {
+            molDocPersistenceManager.generateSchema(directory);
+        } catch (MolDocPersistenceException ex) {
+            fail();
+        } catch (IOException ex) {
+            fail();
+        }
+    }
+
+    @Test
+    public void marshalAtom() {
+        Atom carbon = new Atom("C");
+        MolDocPersistenceManager molDocPersistenceManager = new MolDocPersistenceManager();
+        molDocPersistenceManager.setRules(XmlTransientRules.STANDARD);
+        try {
+            molDocPersistenceManager.marshal(carbon, System.out);
+            Atom atom = molDocPersistenceManager.unmarshal(IOUtils.toInputStream("<atom xmlns=\"http://www.molhub.org/moldoc/schema\" xmlns:moldoc=\"http://www.molhub.org/moldoc/schema\" count=\"1\" symbol=\"C\"/>"), Atom.class);
+            assertEquals("C", atom.getElement().symbol);
+        } catch (MolDocPersistenceException ex) {
+            fail();
+        }
+    }
+
+    @Test
+    @Ignore
+    public void method1() throws JAXBException {
+        Identifier identifier = new Identifier("CH4", IdentifierType.formula);
+    }
+
+    @Test
+    @Ignore
+    public void method2() throws JAXBException {
+        Identifier id1 = new Identifier("CH4", IdentifierType.formula);
+        Identifier id2 = new Identifier("Metane", IdentifierType.name);
+        Species sp = new Species();
+        sp.getIdentifiers().add(id1);
+        sp.getIdentifiers().add(id2);
+    }
+
+    @Test
+    @Ignore
+    public void method4() throws JAXBException {
+        EnthalpyOfFormation dhf = EnthalpyOfFormation.from_kcal_Per_mol(PhysicalConstants.T_25C, 102d, 2d);
+    }
+}