X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=misc%2Fenv%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fmisc%2Fenv%2Fjaxb%2FJAXBumar.java;h=30345e7cdb62657b5001722275998fa9dc744ec2;hb=7e966914050e66219689001ff4ab601a49eef0ac;hp=74072aaf2c7b298a958b05bc6b3746f07a0ce062;hpb=63f9f4d81af883ec5e5fc8de8865c81a2eb6bcd3;p=aaf%2Fauthz.git diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBumar.java b/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBumar.java index 74072aaf..30345e7c 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBumar.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBumar.java @@ -67,177 +67,177 @@ import org.w3c.dom.Node; * */ public class JAXBumar { - // Need to store off possible JAXBContexts based on Class, which will be stored in Creator - private static Map[],Pool> pools = new HashMap[], Pool>(); - - private Class cls; - private Schema schema; - private Pool mpool;; - - // Handle Marshaller class setting of properties only when needed - private class SUnmarshaller { - private Unmarshaller u; - private Schema s; - - public SUnmarshaller(Unmarshaller unmarshaller) throws JAXBException { - u = unmarshaller; - s = null; - } - - public Unmarshaller get(Schema schema) throws JAXBException { - if(s != schema) { - u.setSchema(s = schema); - } - return u; - } - } - - private class Creator implements Pool.Creator { - private JAXBContext jc; - private String name; - - public Creator(Class[] classes) throws JAXBException { - jc = JAXBContext.newInstance(classes); - name = "JAXBumar: " + classes[0].getName(); - } - - // @Override - public SUnmarshaller create() throws APIException { - try { - return new SUnmarshaller(jc.createUnmarshaller()); - } catch (JAXBException e) { - throw new APIException(e); - } - } - - public String toString() { - return name; - } - - // @Override - public void destroy(SUnmarshaller sui) { - // Nothing to do - } - - // @Override - public boolean isValid(SUnmarshaller t) { - return true; - } - - // @Override - public void reuse(SUnmarshaller t) { - // Nothing to do here - } - - } - - private Pool getPool(Class ... classes) throws JAXBException { - Pool mp; - synchronized(pools) { - mp = pools.get(classes); - if(mp==null) { - pools.put(classes,mp = new Pool(new Creator(classes))); - } - } - return mp; - } - - public JAXBumar(Class ... classes) throws JAXBException { - cls = classes[0]; - mpool = getPool(classes); - schema = null; - } - - /** - * Constructs a new JAXBumar with schema validation enabled. - * - * @param schema - * @param theClass - * @throws JAXBException - */ - public JAXBumar(Schema schema, Class ... classes) throws JAXBException { - cls = classes[0]; - mpool = getPool(classes); - this.schema = schema; - } - - @SuppressWarnings("unchecked") - public O unmarshal(LogTarget env, Node node) throws JAXBException, APIException { - Pooled s = mpool.get(env); - try { - return s.content.get(schema).unmarshal(node,(Class)cls).getValue(); - } finally { - s.done(); - } - - } - - @SuppressWarnings("unchecked") - public O unmarshal(LogTarget env, String xml) throws JAXBException, APIException { - if(xml==null) throw new JAXBException("Null Input for String unmarshal"); - Pooled s = mpool.get(env); - try { - return (O)s.content.get(schema).unmarshal( - new StreamSource(new StringReader(xml)) - ,(Class)cls).getValue(); - } finally { - s.done(); - } - } - - @SuppressWarnings("unchecked") - public O unmarshal(LogTarget env, File xmlFile) throws JAXBException, APIException { - Pooled s = mpool.get(env); - try { - return (O)s.content.get(schema).unmarshal(xmlFile); - } finally { - s.done(); - } - - } - - @SuppressWarnings("unchecked") - public O unmarshal(LogTarget env,InputStream is) throws JAXBException, APIException { - Pooled s = mpool.get(env); - try { - return (O)s.content.get(schema).unmarshal(is); - } finally { - s.done(); - } - } - - @SuppressWarnings("unchecked") - public O unmarshal(LogTarget env, Reader rdr) throws JAXBException, APIException { - Pooled s = mpool.get(env); - try { - return (O)s.content.get(schema).unmarshal(rdr); - } finally { - s.done(); - } - } - - @SuppressWarnings("unchecked") - public O unmarshal(LogTarget env, XMLStreamReader xsr) throws JAXBException, APIException { - Pooled s = mpool.get(env); - try { - return (O)s.content.get(schema).unmarshal(xsr,(Class)cls).getValue(); - } finally { - s.done(); - } - } - - @SuppressWarnings("unchecked") - public O unmarshal(LogTarget env, XMLEventReader xer) throws JAXBException, APIException { - Pooled s = mpool.get(env); - try { - return (O)s.content.get(schema).unmarshal(xer,(Class)cls).getValue(); - } finally { - s.done(); - } - } - - @SuppressWarnings("unchecked") - public O newInstance() throws InstantiationException, IllegalAccessException{ - return ((Class)cls).newInstance(); - } + // Need to store off possible JAXBContexts based on Class, which will be stored in Creator + private static Map[],Pool> pools = new HashMap<>(); + + private Class cls; + private Schema schema; + private Pool mpool;; + + // Handle Marshaller class setting of properties only when needed + private class SUnmarshaller { + private Unmarshaller u; + private Schema s; + + public SUnmarshaller(Unmarshaller unmarshaller) throws JAXBException { + u = unmarshaller; + s = null; + } + + public Unmarshaller get(Schema schema) throws JAXBException { + if (s != schema) { + u.setSchema(s = schema); + } + return u; + } + } + + private class Creator implements Pool.Creator { + private JAXBContext jc; + private String name; + + public Creator(Class[] classes) throws JAXBException { + jc = JAXBContext.newInstance(classes); + name = "JAXBumar: " + classes[0].getName(); + } + + // @Override + public SUnmarshaller create() throws APIException { + try { + return new SUnmarshaller(jc.createUnmarshaller()); + } catch (JAXBException e) { + throw new APIException(e); + } + } + + public String toString() { + return name; + } + + // @Override + public void destroy(SUnmarshaller sui) { + // Nothing to do + } + + // @Override + public boolean isValid(SUnmarshaller t) { + return true; + } + + // @Override + public void reuse(SUnmarshaller t) { + // Nothing to do here + } + + } + + private Pool getPool(Class ... classes) throws JAXBException { + Pool mp; + synchronized(pools) { + mp = pools.get(classes); + if (mp==null) { + pools.put(classes,mp = new Pool(new Creator(classes))); + } + } + return mp; + } + + public JAXBumar(Class ... classes) throws JAXBException { + cls = classes[0]; + mpool = getPool(classes); + schema = null; + } + + /** + * Constructs a new JAXBumar with schema validation enabled. + * + * @param schema + * @param theClass + * @throws JAXBException + */ + public JAXBumar(Schema schema, Class ... classes) throws JAXBException { + cls = classes[0]; + mpool = getPool(classes); + this.schema = schema; + } + + @SuppressWarnings("unchecked") + public O unmarshal(LogTarget env, Node node) throws JAXBException, APIException { + Pooled s = mpool.get(env); + try { + return s.content.get(schema).unmarshal(node,(Class)cls).getValue(); + } finally { + s.done(); + } + + } + + @SuppressWarnings("unchecked") + public O unmarshal(LogTarget env, String xml) throws JAXBException, APIException { + if (xml==null) throw new JAXBException("Null Input for String unmarshal"); + Pooled s = mpool.get(env); + try { + return (O)s.content.get(schema).unmarshal( + new StreamSource(new StringReader(xml)) + ,(Class)cls).getValue(); + } finally { + s.done(); + } + } + + @SuppressWarnings("unchecked") + public O unmarshal(LogTarget env, File xmlFile) throws JAXBException, APIException { + Pooled s = mpool.get(env); + try { + return (O)s.content.get(schema).unmarshal(xmlFile); + } finally { + s.done(); + } + + } + + @SuppressWarnings("unchecked") + public O unmarshal(LogTarget env,InputStream is) throws JAXBException, APIException { + Pooled s = mpool.get(env); + try { + return (O)s.content.get(schema).unmarshal(is); + } finally { + s.done(); + } + } + + @SuppressWarnings("unchecked") + public O unmarshal(LogTarget env, Reader rdr) throws JAXBException, APIException { + Pooled s = mpool.get(env); + try { + return (O)s.content.get(schema).unmarshal(rdr); + } finally { + s.done(); + } + } + + @SuppressWarnings("unchecked") + public O unmarshal(LogTarget env, XMLStreamReader xsr) throws JAXBException, APIException { + Pooled s = mpool.get(env); + try { + return (O)s.content.get(schema).unmarshal(xsr,(Class)cls).getValue(); + } finally { + s.done(); + } + } + + @SuppressWarnings("unchecked") + public O unmarshal(LogTarget env, XMLEventReader xer) throws JAXBException, APIException { + Pooled s = mpool.get(env); + try { + return (O)s.content.get(schema).unmarshal(xer,(Class)cls).getValue(); + } finally { + s.done(); + } + } + + @SuppressWarnings("unchecked") + public O newInstance() throws InstantiationException, IllegalAccessException{ + return ((Class)cls).newInstance(); + } }