diff --git a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/build.properties b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/build.properties index 34d2e4d2da..5791d48d5f 100644 --- a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/build.properties +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/build.properties @@ -1,4 +1,5 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ - . + .,\ + res/ diff --git a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/res/spring/ebxml-jaxb-datadelivery-registry.xml b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/res/spring/ebxml-jaxb-datadelivery-registry.xml new file mode 100644 index 0000000000..b12da17cde --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/res/spring/ebxml-jaxb-datadelivery-registry.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.common.registry.ebxml/src/com/raytheon/uf/common/registry/ebxml/encoder/JaxbEncoder.java b/edexOsgi/com.raytheon.uf.common.registry.ebxml/src/com/raytheon/uf/common/registry/ebxml/encoder/JaxbEncoder.java index bf351c11f7..0b82b45136 100644 --- a/edexOsgi/com.raytheon.uf.common.registry.ebxml/src/com/raytheon/uf/common/registry/ebxml/encoder/JaxbEncoder.java +++ b/edexOsgi/com.raytheon.uf.common.registry.ebxml/src/com/raytheon/uf/common/registry/ebxml/encoder/JaxbEncoder.java @@ -39,6 +39,7 @@ import com.raytheon.uf.common.serialization.SerializationException; * Sep 07, 2012 1102 djohnson Initial creation * Jun 03, 2013 2038 djohnson Add equals/hashcode. * Oct 31, 2013 2361 njensen Use specific JAXBManager instead of SerializationUtil + * Nov 14, 2013 2552 bkowal EbxmlJaxbManager is now accessed via getInstance * * * @@ -61,7 +62,8 @@ class JaxbEncoder extends StringBasedEncoder { @Override Object decodeContent(String content) throws SerializationException { try { - return EbxmlJaxbManager.getJaxbManager().unmarshalFromXml(content); + return EbxmlJaxbManager.getInstance().getJaxbManager() + .unmarshalFromXml(content); } catch (JAXBException e) { throw new SerializationException("Unable to decode the object!", e); } @@ -73,8 +75,8 @@ class JaxbEncoder extends StringBasedEncoder { @Override String encodeContent(Object objectToEncode) throws SerializationException { try { - return new String(EbxmlJaxbManager.getJaxbManager().marshalToXml( - objectToEncode)); + return new String(EbxmlJaxbManager.getInstance().getJaxbManager() + .marshalToXml(objectToEncode)); } catch (JAXBException e) { throw new SerializationException("Unable to encode the object!", e); } diff --git a/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/META-INF/MANIFEST.MF index 399a674add..8250aa8af7 100644 --- a/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/META-INF/MANIFEST.MF @@ -13,7 +13,8 @@ Require-Bundle: javax.persistence;bundle-version="1.0.0", org.apache.commons.cxf;bundle-version="1.0.0", com.raytheon.uf.common.status;bundle-version="1.12.1174", com.raytheon.uf.common.util;bundle-version="1.12.1174", - org.reflections;bundle-version="0.9.9" + org.reflections;bundle-version="0.9.9", + org.apache.commons.logging;bundle-version="1.1.2" Export-Package: com.raytheon.uf.common.registry, com.raytheon.uf.common.registry.schemas.ebxml.util, com.raytheon.uf.common.registry.schemas.ebxml.util.annotations, diff --git a/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/build.properties b/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/build.properties index 34d2e4d2da..5791d48d5f 100644 --- a/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/build.properties +++ b/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/build.properties @@ -1,4 +1,5 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ - . + .,\ + res/ diff --git a/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/res/spring/ebxml-jaxb-datadelivery.xml b/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/res/spring/ebxml-jaxb-datadelivery.xml new file mode 100644 index 0000000000..0b7ad134cb --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/res/spring/ebxml-jaxb-datadelivery.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/src/com/raytheon/uf/common/registry/schemas/ebxml/util/EbxmlJaxbManager.java b/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/src/com/raytheon/uf/common/registry/schemas/ebxml/util/EbxmlJaxbManager.java index e11abcba09..f52e44f5eb 100644 --- a/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/src/com/raytheon/uf/common/registry/schemas/ebxml/util/EbxmlJaxbManager.java +++ b/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/src/com/raytheon/uf/common/registry/schemas/ebxml/util/EbxmlJaxbManager.java @@ -19,6 +19,7 @@ **/ package com.raytheon.uf.common.registry.schemas.ebxml.util; +import java.util.HashSet; import java.util.Set; import javax.xml.bind.JAXBException; @@ -29,6 +30,8 @@ import org.reflections.Reflections; import org.reflections.scanners.TypeAnnotationsScanner; import org.reflections.util.ClasspathHelper; import org.reflections.util.ConfigurationBuilder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import com.raytheon.uf.common.serialization.JAXBManager; @@ -42,6 +45,9 @@ import com.raytheon.uf.common.serialization.JAXBManager; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Oct 30, 2013 2361 njensen Initial creation + * Nov 14, 2013 2252 bkowal Added the ability to dynamically inject packages + * that this jaxb implementation should support. + * Eliminated use of System.out. * * * @@ -51,53 +57,70 @@ import com.raytheon.uf.common.serialization.JAXBManager; public class EbxmlJaxbManager { + /** The logger */ + private static Log theLogger = LogFactory.getLog(EbxmlJaxbManager.class); + + private static EbxmlJaxbManager instance; + private static JAXBManager jaxb; - /** - * Uses reflections to scan for ebxml datadelivery registry classes that can - * be transformed to/from xml, and then adds in the ebxml object factories. - * - * @return the classes it found without any duplicates - */ - private static Class[] getClasses() { - String[] packageNames = new String[] { - "com.raytheon.uf.common.datadelivery.registry" }; + private static Set> jaxables; + + public static synchronized EbxmlJaxbManager getInstance() { + if (instance == null) { + instance = new EbxmlJaxbManager(); + } + return instance; + } + + public String findJaxables(String packageName) { + theLogger.info("Scanning package ... " + packageName); long t0 = System.currentTimeMillis(); ConfigurationBuilder cb = new ConfigurationBuilder(); - for (String pkg : packageNames) { - cb.addUrls(ClasspathHelper.forPackage(pkg)); - } + cb.addUrls(ClasspathHelper.forPackage(packageName)); cb.setScanners(new TypeAnnotationsScanner()); // the call to build() will do the actual scanning so the separate // calls to getTypesAnnotatedWith(class, false) will not slow it down + Reflections reflecs = cb.build(); Set> set = reflecs.getTypesAnnotatedWith( XmlAccessorType.class, false); - set.addAll(reflecs.getTypesAnnotatedWith(XmlRegistry.class, false)); + synchronized (jaxables) { + // add them to set for auditing purposes initially + set.addAll(reflecs.getTypesAnnotatedWith(XmlRegistry.class, false)); + // copy set to jaxables + jaxables.addAll(set); + } long t1 = System.currentTimeMillis(); - System.out.println("Found " + set.size() + " classes for ebxml in " + theLogger.info("Found " + set.size() + " classes for ebxml in " + (t1 - t0) + " ms"); + // if jaxb has already been initialized, reset it so that it will be + // recreated with the latest set of jaxable classes. + synchronized (this) { + jaxb = null; + } - set.add(oasis.names.tc.ebxml.regrep.xsd.lcm.v4.ObjectFactory.class); - set.add(oasis.names.tc.ebxml.regrep.xsd.query.v4.ObjectFactory.class); - set.add(oasis.names.tc.ebxml.regrep.xsd.rim.v4.ObjectFactory.class); - set.add(oasis.names.tc.ebxml.regrep.xsd.rs.v4.ObjectFactory.class); - set.add(oasis.names.tc.ebxml.regrep.xsd.spi.v4.ObjectFactory.class); - - return set.toArray(new Class[0]); + return packageName; } - public static synchronized JAXBManager getJaxbManager() - throws JAXBException { + public synchronized JAXBManager getJaxbManager() throws JAXBException { if (jaxb == null) { - jaxb = new JAXBManager(getClasses()); + jaxb = new JAXBManager(jaxables.toArray(new Class[0])); } return jaxb; } private EbxmlJaxbManager() { + jaxables = new HashSet>(); + // add the default jaxables + jaxables.add(oasis.names.tc.ebxml.regrep.xsd.lcm.v4.ObjectFactory.class); + jaxables.add(oasis.names.tc.ebxml.regrep.xsd.query.v4.ObjectFactory.class); + jaxables.add(oasis.names.tc.ebxml.regrep.xsd.rim.v4.ObjectFactory.class); + jaxables.add(oasis.names.tc.ebxml.regrep.xsd.rs.v4.ObjectFactory.class); + jaxables.add(oasis.names.tc.ebxml.regrep.xsd.spi.v4.ObjectFactory.class); + + theLogger.info("Initialization Complete."); } - -} +} \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/src/com/raytheon/uf/common/registry/schemas/ebxml/util/SerializedType.java b/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/src/com/raytheon/uf/common/registry/schemas/ebxml/util/SerializedType.java index f6c7944b3c..2861a0285a 100644 --- a/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/src/com/raytheon/uf/common/registry/schemas/ebxml/util/SerializedType.java +++ b/edexOsgi/com.raytheon.uf.common.registry.schemas.ebxml/src/com/raytheon/uf/common/registry/schemas/ebxml/util/SerializedType.java @@ -42,6 +42,7 @@ import org.hibernate.usertype.UserType; * ------------ ---------- ----------- -------------------------- * --/--/---- Initial creation * Oct 31, 2013 2361 njensen Use specific JAXBManager instead of SerializationUtil + * Nov 14, 2013 2552 bkowal EbxmlJaxbManager is now accessed via getInstance * * * @@ -93,7 +94,8 @@ public class SerializedType implements UserType { if (obj != null) { try { - return EbxmlJaxbManager.getJaxbManager().unmarshalFromXml(obj); + return EbxmlJaxbManager.getInstance().getJaxbManager() + .unmarshalFromXml(obj); } catch (Exception e) { throw new HibernateException("Error retrieving AnyType data", e); } @@ -110,8 +112,8 @@ public class SerializedType implements UserType { } else { try { ; - statement.setString(index, EbxmlJaxbManager.getJaxbManager() - .marshalToXml(value)); + statement.setString(index, EbxmlJaxbManager.getInstance() + .getJaxbManager().marshalToXml(value)); } catch (Exception e) { throw new HibernateException("Error storing AnyType data", e); } diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/dao/DbInit.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/dao/DbInit.java index e0df2cef1d..ac663cba3d 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/dao/DbInit.java +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/dao/DbInit.java @@ -89,6 +89,7 @@ import com.raytheon.uf.edex.registry.ebxml.init.RegistryInitializedListener; * Jun 24, 2013 2106 djohnson Invoke registry initialized listeners in their own transaction so * they can't fail the ebxml schema creation/population. * Nov 01, 2013 2361 njensen Use EbxmlJaxbManager instead of SerializationUtil + * Nov 14, 2013 2552 bkowal EbxmlJaxbManager is now accessed via getInstance * * * @author bphillip @@ -167,8 +168,11 @@ public class DbInit extends com.raytheon.uf.edex.database.init.DbInit implements SubmitObjectsRequest obj = null; try { - obj = EbxmlJaxbManager.getJaxbManager().unmarshalFromXmlFile( - SubmitObjectsRequest.class, fileList[i]); + obj = EbxmlJaxbManager + .getInstance() + .getJaxbManager() + .unmarshalFromXmlFile(SubmitObjectsRequest.class, + fileList[i]); } catch (JAXBException e) { throw new SerializationException( "Error unmarshalling from file: " @@ -360,8 +364,7 @@ public class DbInit extends com.raytheon.uf.edex.database.init.DbInit implements listener.executeAfterRegistryInit(); } } catch (Throwable t) { - throw new RuntimeException( - "Error initializing EBXML database!", t); + throw new RuntimeException("Error initializing EBXML database!", t); } } diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/adhoc/AdhocQueryExpressionManager.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/adhoc/AdhocQueryExpressionManager.java index 7b3d0f962e..1c61b8873f 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/adhoc/AdhocQueryExpressionManager.java +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/query/adhoc/AdhocQueryExpressionManager.java @@ -41,6 +41,7 @@ import com.raytheon.uf.common.status.UFStatus; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Feb 29, 2012 bphillip Initial creation + * Nov 14, 2013 2552 bkowal EbxmlJaxbManager is now accessed via getInstance * * * @@ -82,8 +83,11 @@ public class AdhocQueryExpressionManager { AdhocQueryExpression obj = null; try { - obj = EbxmlJaxbManager.getJaxbManager().unmarshalFromXmlFile( - AdhocQueryExpression.class, fileList[i]); + obj = EbxmlJaxbManager + .getInstance() + .getJaxbManager() + .unmarshalFromXmlFile(AdhocQueryExpression.class, + fileList[i]); } catch (Exception e) { statusHandler.error("Error getting predefined adhoc queries.", e);