summaryrefslogtreecommitdiffstats
path: root/env/src/main/java/org/onap/aaf/inno/env/jaxb
diff options
context:
space:
mode:
Diffstat (limited to 'env/src/main/java/org/onap/aaf/inno/env/jaxb')
-rw-r--r--env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBDF.java310
-rw-r--r--env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBData.java321
-rw-r--r--env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBObjectifier.java136
-rw-r--r--env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBStringifier.java138
-rw-r--r--env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBmar.java253
-rw-r--r--env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBumar.java242
6 files changed, 0 insertions, 1400 deletions
diff --git a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBDF.java b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBDF.java
deleted file mode 100644
index dec3efa..0000000
--- a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBDF.java
+++ /dev/null
@@ -1,310 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.inno.env.jaxb;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.StringWriter;
-import java.io.Writer;
-
-import javax.xml.bind.JAXBException;
-import javax.xml.namespace.QName;
-import javax.xml.validation.Schema;
-
-import org.onap.aaf.inno.env.APIException;
-import org.onap.aaf.inno.env.BaseDataFactory;
-import org.onap.aaf.inno.env.Data;
-import org.onap.aaf.inno.env.Env;
-import org.onap.aaf.inno.env.EnvJAXB;
-import org.onap.aaf.inno.env.TimeTaken;
-import org.onap.aaf.inno.env.old.IOObjectifier;
-import org.onap.aaf.inno.env.old.IOStringifier;
-import org.onap.aaf.inno.env.old.OldDataFactory;
-
-public class JAXBDF<T> extends BaseDataFactory implements OldDataFactory<T>,IOObjectifier<T>, IOStringifier<T> {
- // Package on purpose
- EnvJAXB primaryEnv;
- JAXBumar jumar;
- JAXBmar jmar;
-
- public JAXBDF(EnvJAXB env, Class<?> ... classes) throws APIException {
- try {
- primaryEnv = env;
- jumar = new JAXBumar(classes);
- jmar = new JAXBmar(classes) ;
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- }
-
- public JAXBDF(EnvJAXB env, Schema schema, Class<?> ... classes) throws APIException {
- try {
- primaryEnv = env;
- jumar = new JAXBumar(schema, classes);
- jmar = new JAXBmar(classes);
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- }
-
- public JAXBDF(EnvJAXB env, QName qname, Class<?> ... classes) throws APIException {
- try {
- primaryEnv = env;
- jumar = new JAXBumar(classes);
- jmar = new JAXBmar(qname, classes);
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- }
-
- public JAXBDF(EnvJAXB env, Schema schema, QName qname, Class<?> ... classes) throws APIException {
- try {
- primaryEnv = env;
- jumar = new JAXBumar(schema, classes);
- jmar = new JAXBmar(qname, classes);
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- }
-
- // @Override
- public T newInstance() throws APIException {
- try {
- return jumar.newInstance();
- } catch (Exception e) {
- throw new APIException(e);
- }
- }
-
- // @Override
- public IOStringifier<T> pretty(boolean pretty) {
- jmar.pretty(pretty);
- return this;
- }
-
- // @Override
- public IOStringifier<T> asFragment(boolean fragment) {
- jmar.asFragment(fragment);
- return this;
- }
-
- // @Override
- public void servicePrestart(Env env) throws APIException {
- }
-
- // @Override
- public void threadPrestart(Env env) throws APIException {
- }
-
- // @Override
- public void refresh(Env env) throws APIException {
- }
-
- // @Override
- public void threadDestroy(Env env) throws APIException {
- }
-
- // @Override
- public void serviceDestroy(Env env) throws APIException {
- }
-
- @SuppressWarnings("unchecked")
- // @Override
- public Data<T> newData() {
- return new JAXBData<T>(primaryEnv, this, new JAXBStringifier<T>(jmar), new JAXBObjectifier<T>(jumar),"",(Class<T>)jmar.getMarshalClass());
- }
-
- @SuppressWarnings("unchecked")
- // @Override
- public Data<T> newData(Env env) {
- return new JAXBData<T>(env, this,new JAXBStringifier<T>(jmar), new JAXBObjectifier<T>(jumar),"",(Class<T>)jmar.getMarshalClass());
- }
-
- // @Override
- public Data<T> newData(T type) {
- return new JAXBData<T>(primaryEnv, this, new JAXBStringifier<T>(jmar), new JAXBObjectifier<T>(jumar), type);
- }
-
- // @Override
- public Data<T> newDataFromStream(Env env, InputStream input) throws APIException {
- //TODO Write an unvalidated String using STAX checking for end of Doc?
- // perhaps key evaluation as well.
- try {
- T t = jumar.unmarshal(env.debug(), input);
- return new JAXBData<T>(primaryEnv, this, new JAXBStringifier<T>(jmar), new JAXBObjectifier<T>(jumar),t);
- } catch(JAXBException e) {
- throw new APIException(e);
- }
- }
-
- @SuppressWarnings("unchecked")
- // @Override
- public Data<T> newDataFromString(String string) {
- return new JAXBData<T>(primaryEnv, this,new JAXBStringifier<T>(jmar), new JAXBObjectifier<T>(jumar), string,(Class<T>)jmar.getMarshalClass());
- }
-
- /////////// Old DataFactory Interface
- // @Override
- public String stringify(T type) throws APIException {
- try {
- StringWriter sw = new StringWriter();
- jmar.marshal(primaryEnv.debug(), type, sw);
- return sw.toString();
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- }
-
- // @Override
- public void stringify(T type, Writer writer) throws APIException {
- try {
- jmar.marshal(primaryEnv.debug(), type, writer);
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- }
-
- // @Override
- public void stringify(T type, OutputStream os) throws APIException {
- try {
- jmar.marshal(primaryEnv.debug(), type, os);
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- }
-
- /////////// New DataFactory Interface
- // @Override
- public String stringify(Env env, T input, boolean ... options) throws APIException {
- try {
- StringWriter sw = new StringWriter();
- TimeTaken tt = env.start("JAXB Stringify", Env.XML);
- try {
- jmar.marshal(env.debug(), input, sw, options);
- } finally {
- tt.done();
- }
- String str = sw.toString();
- tt.size(str.getBytes().length);
- return str;
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- }
-
- // @Override
- public void stringify(Env env, T input, Writer writer, boolean ... options) throws APIException {
- TimeTaken tt = env.start("JAXB Stringify", Env.XML);
- try {
- jmar.marshal(env.debug(), input, writer, options);
- } catch (JAXBException e) {
- throw new APIException(e);
- } finally {
- tt.done();
- }
- }
-
- // @Override
- public void stringify(Env env, T input, OutputStream os, boolean ... options) throws APIException {
- TimeTaken tt = env.start("JAXB Stringify", Env.XML);
- try {
- jmar.marshal(env.debug(), input, os, options);
- } catch (JAXBException e) {
- throw new APIException(e);
- } finally {
- tt.done();
- }
- }
-
- // @Override
- public T objectify(Env env, Reader rdr) throws APIException {
- TimeTaken tt = env.start("JAXB Objectify", Env.XML);
- try {
- return jumar.unmarshal(env.debug(), rdr);
- } catch (JAXBException e) {
- throw new APIException(e);
- } finally {
- tt.done();
- }
- }
-
- // @Override
- public T objectify(Reader rdr) throws APIException {
- try {
- return jumar.unmarshal(primaryEnv.debug(), rdr);
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- }
-
- // @Override
- public T objectify(Env env, InputStream is) throws APIException {
- TimeTaken tt = env.start("JAXB Objectify", Env.XML);
- try {
- return jumar.unmarshal(env.debug(), is);
- } catch (JAXBException e) {
- throw new APIException(e);
- } finally {
- tt.done();
- }
- }
-
- // @Override
- public T objectify(InputStream is) throws APIException {
- try {
- return jumar.unmarshal(primaryEnv.debug(), is);
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- }
-
- // @Override
- public T objectify(Env env, String input) throws APIException {
- TimeTaken tt = env.start("JAXB Objectify", Env.XML);
- tt.size(input.getBytes().length);
- try {
- return jumar.unmarshal(env.debug(), input);
- } catch (JAXBException e) {
- throw new APIException(e);
- } finally {
- tt.done();
- }
- }
-
- // @Override
- public T objectify(String text) throws APIException {
- try {
- return jumar.unmarshal(primaryEnv.debug(), text);
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- }
-
- @SuppressWarnings("unchecked")
- // @Override
- public Class<T> getTypeClass() {
- return (Class<T>)jmar.getMarshalClass();
- }
-
-}
diff --git a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBData.java b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBData.java
deleted file mode 100644
index 3b51256..0000000
--- a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBData.java
+++ /dev/null
@@ -1,321 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.inno.env.jaxb;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-
-import javax.xml.bind.JAXBException;
-
-import org.onap.aaf.inno.env.APIException;
-import org.onap.aaf.inno.env.Data;
-import org.onap.aaf.inno.env.Env;
-import org.onap.aaf.inno.env.EnvJAXB;
-import org.onap.aaf.inno.env.old.IOStringifier;
-import org.onap.aaf.inno.env.old.Objectifier;
-import org.onap.aaf.inno.env.old.Stringifier;
-/**
- * <H1>Data</H1>
- * <i>Data</i> facilitates lazy marshaling of data with a pre-determined
- * marshaling mechanism.<p>
- *
- * It stores either Object (defined by Generic {@literal <T>}) or String.<p>
- *
- * On asking for Object of type {@literal <T>}, it will respond with the object
- * if it exists, or unmarshal the string and pass the result back.<p>
- *
- * On asking for String, it will respond with the String
- * if it exists, or marshal the String and pass the result back.<p>
- *
- *
- * @param <T>
- */
-public final class JAXBData<T> implements Data<T>{
- private Stringifier<T> stringifier;
- private Objectifier<T> objectifier;
- private String dataAsString;
- private T dataAsObject;
- private Class<T> tclass;
- private JAXBDF<T> df;
- private Env creatingEnv;
- private boolean options[] = new boolean[] {false, false};
-
- /**
- * Construct a Data Object with an appropriate Stringifier, Objectifier and Class to support
- *
- * @param env
- * @param strfr
- * @param objfr
- * @param text
- * @param typeClass
- */
- JAXBData(Env env, JAXBDF<T> df, Stringifier<T> strfr, Objectifier<T> objfr, String text, Class<T> typeClass) {
- dataAsString = text;
- dataAsObject = null;
- stringifier = strfr;
- objectifier = objfr;
- tclass = typeClass;
- creatingEnv = env;
- this.df = df;
- }
-
-
- /**
- * Construct a Data Object with an appropriate Stringifier, Objectifier and Object (which will
- * yield it's class)
- *
- * @param env
- * @param strfr
- * @param objfr
- * @param object
- */
- @SuppressWarnings("unchecked")
- JAXBData(Env env, JAXBDF<T> df, Stringifier<T> strfr, Objectifier<T> objfr, T object) {
- dataAsString = null;
- dataAsObject = object;
- stringifier = strfr;
- objectifier = objfr;
- tclass = (Class<T>) object.getClass();
- creatingEnv = env;
- this.df = df;
- }
-
- /**
- * Respond with the String if it exists, or marshal the String and pass the result back.<p>
- *
- * Explicitly use a specific Env for logging purposes
- *
- * @param env
- * @return String
- * @throws APIException
- */
- public String asString(EnvJAXB env) throws APIException {
- if(dataAsString!=null) {
- return dataAsString;
- } else {
- return dataAsString = stringifier.stringify(env, dataAsObject);
- }
- }
-
- /**
- * Respond with the String if it exists, or marshal the String and pass the result back.
- *
- * However, use the Env the Data Object was created with.
- *
- * @return String
- * @throws APIException
- */
- // @Override
- public String asString() throws APIException {
- if(dataAsString!=null) {
- return dataAsString;
- } else {
- return dataAsString = stringifier.stringify(creatingEnv, dataAsObject,options);
- }
- }
-
- public Data<T> to(OutputStream os) throws APIException, IOException {
- if(dataAsString!=null) {
- os.write(dataAsString.getBytes());
- } else if (stringifier instanceof IOStringifier){
- ((IOStringifier<T>)stringifier).stringify(creatingEnv, dataAsObject, os, options);
- } else {
- dataAsString = stringifier.stringify(creatingEnv, dataAsObject, options);
- os.write(dataAsString.getBytes());
- }
- return this;
- }
-
-
- // @Override
- public JAXBData<T> to(Writer writer) throws APIException, IOException {
- if(dataAsString!=null) {
- writer.write(dataAsString);
- } else if (stringifier instanceof IOStringifier){
- ((IOStringifier<T>)stringifier).stringify(creatingEnv, dataAsObject, writer, options);
- } else {
- dataAsString = stringifier.stringify(creatingEnv, dataAsObject, options);
- writer.write(dataAsString);
- }
- return this;
- }
-
-
- public InputStream getInputStream() throws APIException {
- if(dataAsString==null) {
- dataAsString = stringifier.stringify(creatingEnv,dataAsObject,options);
- }
- return new ByteArrayInputStream(dataAsString.getBytes());
- }
-
- /**
- * Respond with the Object of type {@literal <T>} if it exists, or unmarshal from String
- * and pass the result back.<p>
- *
- * Explicitly use a specific Env for logging purposes
- *
- * @param env
- * @return T
- * @throws APIException
- */
-
- public T asObject(EnvJAXB env) throws APIException {
- if(dataAsObject !=null) {
- return dataAsObject;
- } else {
- // Some Java compilers need two statements here
- dataAsObject = objectifier.objectify(env, dataAsString);
- return dataAsObject;
- }
- }
-
- /**
- * Respond with the Object of type {@literal <T>} if it exists, or unmarshal from String
- * and pass the result back.<p>
- *
- * However, use the Env the Data Object was created with.
- *
- * @return T
- * @throws APIException
- */
- // @Override
- public T asObject() throws APIException {
- if(dataAsObject !=null) {
- return dataAsObject;
- } else {
- // Some Java compilers need two statements here
- dataAsObject = objectifier.objectify(creatingEnv, dataAsString);
- return dataAsObject;
- }
- }
-
-
- /**
- * Return the Class Type supported by this DataObject
- *
- * @return {@literal Class<T>}
- */
- // @Override
- public Class<T> getTypeClass() {
- return tclass;
- }
-
-
- /**
- * For Debugging Convenience, we marshal to String if possible.
- *
- * Behavior is essentially the same as asString(), except asString() throws
- * an APIException. <p>
- * Since toString() must not throw exceptions, the function just catches and prints an
- * error, which is probably not the behavior desired.<p>
- *
- * Therefore, use "asString()" where possible in actual Transactional code.
- *
- * @see java.lang.Object#toString()
- */
- // @Override
- public String toString() {
- if(dataAsString!=null) {
- return dataAsString;
- } else {
- try {
- return dataAsString = stringifier.stringify(creatingEnv, dataAsObject);
- } catch (APIException e) {
- return "ERROR - Can't Stringify from Object " + e.getLocalizedMessage();
- }
- }
- }
-
- public Data<T> load(T t) throws APIException {
- dataAsObject = t;
- dataAsString = null;
- return this;
- }
-
-
- public Data<T> load(String str) throws APIException {
- dataAsObject = null;
- dataAsString = str;
- return this;
- }
-
-
- public Data<T> load(InputStream is) throws APIException {
- try {
- dataAsObject = df.jumar.unmarshal(creatingEnv.debug(),is);
- dataAsString = null;
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- return this;
- }
-
-
- public Data<T> load(Reader rdr) throws APIException {
- try {
- dataAsObject = df.jumar.unmarshal(creatingEnv.debug(),rdr);
- dataAsString = null;
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- return this;
- }
-
-
- // @Override
- public void direct(InputStream input, OutputStream output) throws APIException, IOException {
- byte b[] = new byte[128];
- int count;
- do {
- count = input.read(b);
- if(count>0)output.write(b, 0, count);
- } while(count>=0);
- }
-
-
- // @Override
- public Data<T> out(TYPE type) {
- // it's going to be XML regardless...
- return this;
- }
-
-
- // @Override
- public Data<T> in(TYPE type) {
- // Not Supported... will still be XML
- return this;
- }
-
-
- // @Override
- public Data<T> option(int option) {
- options[0] = (option&Data.PRETTY)==Data.PRETTY;
- options[1] = (option&Data.FRAGMENT)==Data.FRAGMENT;
- return this;
- }
-
-}
diff --git a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBObjectifier.java b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBObjectifier.java
deleted file mode 100644
index 880aa21..0000000
--- a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBObjectifier.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.inno.env.jaxb;
-
-import java.io.InputStream;
-import java.io.Reader;
-
-import javax.xml.bind.JAXBException;
-import javax.xml.validation.Schema;
-
-import org.onap.aaf.inno.env.APIException;
-import org.onap.aaf.inno.env.Env;
-import org.onap.aaf.inno.env.TimeTaken;
-import org.onap.aaf.inno.env.old.IOObjectifier;
-
-/**
- * Allow Extended IO interface usage without muddying up the Stringifier Interface
- */
-public class JAXBObjectifier<T> implements IOObjectifier<T> {
- private JAXBumar jumar;
-
- public JAXBObjectifier(Schema schema, Class<?>... classes) throws APIException {
- try {
- jumar = new JAXBumar(schema, classes);
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- }
-
- public JAXBObjectifier(Class<?>... classes) throws APIException {
- try {
- jumar = new JAXBumar(classes);
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- }
-
- // package on purpose
- JAXBObjectifier(JAXBumar jumar) {
- this.jumar = jumar;
- }
-
- @SuppressWarnings("unchecked")
- // @Override
- public T objectify(Env env, String input) throws APIException {
- TimeTaken tt = env.start("JAXB Unmarshal", Env.XML);
- try {
- tt.size(input.length());
- return (T)jumar.unmarshal(env.debug(), input);
- } catch (JAXBException e) {
- throw new APIException(e);
- } finally {
- tt.done();
- }
- }
-
- @SuppressWarnings("unchecked")
- // @Override
- public T objectify(Env env, Reader rdr) throws APIException {
- //TODO create a Reader that Counts?
- TimeTaken tt = env.start("JAXB Unmarshal", Env.XML);
- try {
- return (T)jumar.unmarshal(env.debug(), rdr);
- } catch (JAXBException e) {
- throw new APIException(e);
- } finally {
- tt.done();
- }
- }
-
-
- @SuppressWarnings("unchecked")
- // @Override
- public T objectify(Env env, InputStream is) throws APIException {
- //TODO create a Reader that Counts?
- TimeTaken tt = env.start("JAXB Unmarshal", Env.XML);
- try {
- return (T)jumar.unmarshal(env.debug(), is);
- } catch (JAXBException e) {
- throw new APIException(e);
- } finally {
- tt.done();
- }
- }
-
-
- public void servicePrestart(Env env) throws APIException {
- }
-
- public void threadPrestart(Env env) throws APIException {
- }
-
- // // @Override
- public void refresh(Env env) throws APIException {
- }
-
- // // @Override
- public void threadDestroy(Env env) throws APIException {
- }
-
- // // @Override
- public void serviceDestroy(Env env) throws APIException {
- }
-
-
- @SuppressWarnings("unchecked")
- public T newInstance() throws APIException {
- try {
- return (T)jumar.newInstance();
- } catch (Exception e) {
- throw new APIException(e);
- }
- }
-
-}
-
diff --git a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBStringifier.java b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBStringifier.java
deleted file mode 100644
index 3fcfaa8..0000000
--- a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBStringifier.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.aaf.inno.env.jaxb;
-
-import java.io.OutputStream;
-import java.io.StringWriter;
-import java.io.Writer;
-
-import javax.xml.bind.JAXBException;
-import javax.xml.namespace.QName;
-
-import org.onap.aaf.inno.env.APIException;
-import org.onap.aaf.inno.env.Env;
-import org.onap.aaf.inno.env.TimeTaken;
-import org.onap.aaf.inno.env.old.IOStringifier;
-
-public class JAXBStringifier<T> implements IOStringifier<T> {
- private JAXBmar jmar;
-
- public JAXBStringifier(Class<?>... classes) throws APIException {
- try {
- jmar = new JAXBmar(classes);
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- }
-
- public JAXBStringifier(QName qname, Class<?>... classes)
- throws APIException {
- try {
- jmar = new JAXBmar(qname, classes);
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- }
-
- // package on purpose
- JAXBStringifier(JAXBmar jmar) {
- this.jmar = jmar;
- }
-
- // // @Override
- public void stringify(Env env, T input, Writer writer, boolean ... options)
- throws APIException {
- TimeTaken tt = env.start("JAXB Marshal", Env.XML);
- try {
- jmar.marshal(env.debug(), input, writer, options);
- } catch (JAXBException e) {
- throw new APIException(e);
- } finally {
- tt.done();
- }
- }
-
- // @Override
- public void stringify(Env env, T input, OutputStream os, boolean ... options)
- throws APIException {
- // TODO create an OutputStream that Counts?
- TimeTaken tt = env.start("JAXB Marshal", Env.XML);
- try {
- jmar.marshal(env.debug(), input, os, options);
- } catch (JAXBException e) {
- throw new APIException(e);
- } finally {
- tt.done();
- }
- }
-
- // @Override
- public String stringify(Env env, T input, boolean ... options) throws APIException {
- TimeTaken tt = env.start("JAXB Marshal", Env.XML);
- StringWriter sw = new StringWriter();
- try {
- jmar.marshal(env.debug(), input, sw, options);
- String rv = sw.toString();
- tt.size(rv.length());
- return rv;
- } catch (JAXBException e) {
- tt.size(0);
- throw new APIException(e);
- } finally {
- tt.done();
- }
- }
-
- // // @Override
- public void servicePrestart(Env env) throws APIException {
- }
-
- // // @Override
- public void threadPrestart(Env env) throws APIException {
- }
-
- // // @Override
- public void refresh(Env env) throws APIException {
- }
-
- // // @Override
- public void threadDestroy(Env env) throws APIException {
- }
-
- // // @Override
- public void serviceDestroy(Env env) throws APIException {
- }
-
- // @Override
- public JAXBStringifier<T> pretty(boolean pretty) {
- jmar.pretty(pretty);
- return this;
- }
-
- // @Override
- public JAXBStringifier<T> asFragment(boolean fragment) {
- jmar.asFragment(fragment);
- return this;
- }
-
-}
diff --git a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBmar.java b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBmar.java
deleted file mode 100644
index d07c246..0000000
--- a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBmar.java
+++ /dev/null
@@ -1,253 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-/**
- * JAXBumar.java
- *
- * Created on: Apr 10, 2009
- * Created by:
- *
- * Revamped to do away with ThreadLocal 5/27/2011,
- *
- * (c) 2009 SBC Knowledge Ventures, L.P. All rights reserved.
- *******************************************************************
- * RESTRICTED - PROPRIETARY INFORMATION The Information contained
- * herein is for use only by authorized employees of AT&T Services,
- * Inc., and authorized Affiliates of AT&T Services, Inc., and is
- * not for general distribution within or outside the respective
- * companies.
- *******************************************************************
- */
-package org.onap.aaf.inno.env.jaxb;
-
-import java.io.OutputStream;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.namespace.QName;
-
-import org.onap.aaf.inno.env.APIException;
-import org.onap.aaf.inno.env.LogTarget;
-import org.onap.aaf.inno.env.util.Pool;
-import org.onap.aaf.inno.env.util.Pool.Pooled;
-
-/**
- * JAXBmar classes are inexpensive for going in and out of scope
- * and have been made thread safe via Pooling
-
- *
- */
-public class JAXBmar {
- // Need to store off possible JAXBContexts based on Class, which will be stored in Creator
- private static Map<Class<?>[],Pool<PMarshaller>> pools = new HashMap<Class<?>[], Pool<PMarshaller>>();
-
- // Handle Marshaller class setting of properties only when needed
- private class PMarshaller {
- private Marshaller m;
- private boolean p;
- private boolean f;
-
- public PMarshaller(Marshaller marshaller) throws JAXBException {
- m = marshaller;
- m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
- m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, p = false);
- m.setProperty(Marshaller.JAXB_FRAGMENT, f = false);
- }
-
- public Marshaller get(boolean pretty, boolean fragment) throws JAXBException {
- if(pretty != p) {
- m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, p = pretty);
- }
- if(fragment != f) {
- m.setProperty(Marshaller.JAXB_FRAGMENT, f = fragment);
- }
- return m;
- }
- }
-
- private class Creator implements Pool.Creator<PMarshaller> {
- private JAXBContext jc;
- private String name;
- public Creator(Class<?>[] classes) throws JAXBException {
- jc = JAXBContext.newInstance(classes);
- name = "JAXBmar: " + classes[0].getName();
- }
-
- // @Override
- public PMarshaller create() throws APIException {
- try {
- return new PMarshaller(jc.createMarshaller());
- } catch (JAXBException e) {
- throw new APIException(e);
- }
- }
-
- public String toString() {
- return name;
- }
-
- // @Override
- public void reuse(PMarshaller pm) {
- // Nothing to do
- }
-
- // @Override
- public void destroy(PMarshaller pm) {
- // Nothing to do
- }
-
- // @Override
- public boolean isValid(PMarshaller t) {
- return true;
- }
- }
-
- //TODO isn't UTF-8 a standard string somewhere for encoding?
- private boolean fragment= false;
- private boolean pretty=false;
- private QName qname;
-
- private Pool<PMarshaller> mpool; // specific Pool associated with constructed Classes
- private Class<?> cls;
-
- private Pool<PMarshaller> getPool(Class<?> ... classes) throws JAXBException {
- Pool<PMarshaller> mp;
- synchronized(pools) {
- mp = pools.get(classes);
- if(mp==null) {
- pools.put(classes,mp = new Pool<PMarshaller>(new Creator(classes)));
- }
- }
- return mp;
- }
-
- public JAXBmar(Class<?>... classes) throws JAXBException {
- cls = classes[0];
- mpool = getPool(classes);
- qname = null;
- }
-
- public JAXBmar(QName theQname, Class<?>... classes) throws JAXBException {
- cls = classes[0];
- mpool = getPool(classes);
- qname = theQname;
- }
-
- @SuppressWarnings("unchecked")
- public<O> O marshal(LogTarget lt,O o, Writer writer, boolean ... options) throws JAXBException, APIException {
- boolean pretty, fragment;
- pretty = options.length>0?options[0]:this.pretty;
- fragment = options.length>1?options[1]:this.fragment;
- Pooled<PMarshaller> m = mpool.get(lt);
- try {
- if(qname==null) {
- m.content.get(pretty,fragment).marshal(o, writer);
- } else {
- m.content.get(pretty,fragment).marshal(
- new JAXBElement<O>(qname, (Class<O>)cls, o ),
- writer);
- }
- return o;
- } finally {
- m.done();
- }
- }
-
- @SuppressWarnings("unchecked")
- public<O> O marshal(LogTarget lt, O o, OutputStream os, boolean ... options) throws JAXBException, APIException {
- boolean pretty, fragment;
- pretty = options.length>0?options[0]:this.pretty;
- fragment = options.length>1?options[1]:this.fragment;
- Pooled<PMarshaller> m = mpool.get(lt);
- try {
- if(qname==null) {
- m.content.get(pretty,fragment).marshal(o, os);
- } else {
- m.content.get(pretty,fragment).marshal(
- new JAXBElement<O>(qname, (Class<O>)cls, o ),os);
- }
- return o;
- } finally {
- m.done();
- }
- }
-
- public<O> O marshal(LogTarget lt, O o, Writer writer, Class<O> clss) throws JAXBException, APIException {
- Pooled<PMarshaller> m = mpool.get(lt);
- try {
- if(qname==null) {
- m.content.get(pretty,fragment).marshal(o, writer);
- } else {
- m.content.get(pretty,fragment).marshal(
- new JAXBElement<O>(qname, clss, o),writer);
- }
- return o;
- } finally {
- m.done();
- }
-
- }
-
- public<O> O marshal(LogTarget lt, O o, OutputStream os, Class<O> clss) throws JAXBException, APIException {
- Pooled<PMarshaller> m = mpool.get(lt);
- try {
- if(qname==null) {
- m.content.get(pretty,fragment).marshal(o, os);
- } else {
- m.content.get(pretty,fragment).marshal(
- new JAXBElement<O>(qname, clss, o ),os);
- }
- return o;
- } finally {
- m.done();
- }
- }
-
- /**
- * @return
- */
- public Class<?> getMarshalClass() {
- return cls;
- }
-
- public<O> String stringify(LogTarget lt, O o) throws JAXBException, APIException {
- StringWriter sw = new StringWriter();
- marshal(lt,o,sw);
- return sw.toString();
- }
-
- public JAXBmar pretty(boolean pretty) {
- this.pretty = pretty;
- return this;
- }
-
- public JAXBmar asFragment(boolean fragment) {
- this.fragment = fragment;
- return this;
- }
-}
diff --git a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBumar.java b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBumar.java
deleted file mode 100644
index cd31301..0000000
--- a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBumar.java
+++ /dev/null
@@ -1,242 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START====================================================
- * * org.onap.aaf
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-/**
- * JAXBumar.java
- *
- * Created on: Apr 10, 2009
- * Created by:
- *
- * Revamped to do away with ThreadLocal 5/27/2011,
- *
- * (c) 2009 SBC Knowledge Ventures, L.P. All rights reserved.
- *******************************************************************
- * RESTRICTED - PROPRIETARY INFORMATION The Information contained
- * herein is for use only by authorized employees of AT&T Services,
- * Inc., and authorized Affiliates of AT&T Services, Inc., and is
- * not for general distribution within or outside the respective
- * companies.
- *******************************************************************
- */
-package org.onap.aaf.inno.env.jaxb;
-
-import java.io.File;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.stream.XMLEventReader;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-
-import org.onap.aaf.inno.env.APIException;
-import org.onap.aaf.inno.env.LogTarget;
-import org.onap.aaf.inno.env.util.Pool;
-import org.onap.aaf.inno.env.util.Pool.Pooled;
-import org.w3c.dom.Node;
-
-/**
- * JAXBumar classes are inexpensive for going in and out of scope
- * and have been made thread safe via Pooling
- *
- */
-public class JAXBumar {
- // Need to store off possible JAXBContexts based on Class, which will be stored in Creator
- private static Map<Class<?>[],Pool<SUnmarshaller>> pools = new HashMap<Class<?>[], Pool<SUnmarshaller>>();
-
- private Class<?> cls;
- private Schema schema;
- private Pool<SUnmarshaller> 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<SUnmarshaller> {
- 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<SUnmarshaller> getPool(Class<?> ... classes) throws JAXBException {
- Pool<SUnmarshaller> mp;
- synchronized(pools) {
- mp = pools.get(classes);
- if(mp==null) {
- pools.put(classes,mp = new Pool<SUnmarshaller>(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> O unmarshal(LogTarget env, Node node) throws JAXBException, APIException {
- Pooled<SUnmarshaller> s = mpool.get(env);
- try {
- return s.content.get(schema).unmarshal(node,(Class<O>)cls).getValue();
- } finally {
- s.done();
- }
-
- }
-
- @SuppressWarnings("unchecked")
- public<O> O unmarshal(LogTarget env, String xml) throws JAXBException, APIException {
- if(xml==null) throw new JAXBException("Null Input for String unmarshal");
- Pooled<SUnmarshaller> s = mpool.get(env);
- try {
- return (O)s.content.get(schema).unmarshal(
- new StreamSource(new StringReader(xml))
- ,(Class<O>)cls).getValue();
- } finally {
- s.done();
- }
- }
-
- @SuppressWarnings("unchecked")
- public<O> O unmarshal(LogTarget env, File xmlFile) throws JAXBException, APIException {
- Pooled<SUnmarshaller> s = mpool.get(env);
- try {
- return (O)s.content.get(schema).unmarshal(xmlFile);
- } finally {
- s.done();
- }
-
- }
-
- @SuppressWarnings("unchecked")
- public<O> O unmarshal(LogTarget env,InputStream is) throws JAXBException, APIException {
- Pooled<SUnmarshaller> s = mpool.get(env);
- try {
- return (O)s.content.get(schema).unmarshal(is);
- } finally {
- s.done();
- }
- }
-
- @SuppressWarnings("unchecked")
- public<O> O unmarshal(LogTarget env, Reader rdr) throws JAXBException, APIException {
- Pooled<SUnmarshaller> s = mpool.get(env);
- try {
- return (O)s.content.get(schema).unmarshal(rdr);
- } finally {
- s.done();
- }
- }
-
- @SuppressWarnings("unchecked")
- public<O> O unmarshal(LogTarget env, XMLStreamReader xsr) throws JAXBException, APIException {
- Pooled<SUnmarshaller> s = mpool.get(env);
- try {
- return (O)s.content.get(schema).unmarshal(xsr,(Class<O>)cls).getValue();
- } finally {
- s.done();
- }
- }
-
- @SuppressWarnings("unchecked")
- public<O> O unmarshal(LogTarget env, XMLEventReader xer) throws JAXBException, APIException {
- Pooled<SUnmarshaller> s = mpool.get(env);
- try {
- return (O)s.content.get(schema).unmarshal(xer,(Class<O>)cls).getValue();
- } finally {
- s.done();
- }
- }
-
- @SuppressWarnings("unchecked")
- public<O> O newInstance() throws InstantiationException, IllegalAccessException{
- return ((Class<O>)cls).newInstance();
- }
-}