X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=misc%2Fenv%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fmisc%2Fenv%2Fjaxb%2FJAXBData.java;h=a5f10e0ff0909d2a89fbb7c267dab0918f037405;hb=3a5ca081c75bfeaecae40684a2cf89126fb99164;hp=84502adef8e64aad98ff043508a8f4faa9f17e67;hpb=ceda6e8bc270202bcb24340b86617110289c902e;p=aaf%2Fauthz.git diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBData.java b/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBData.java index 84502ade..a5f10e0f 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBData.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBData.java @@ -55,267 +55,270 @@ import org.onap.aaf.misc.env.old.Stringifier; * @param */ public final class JAXBData implements Data{ - private Stringifier stringifier; - private Objectifier objectifier; - private String dataAsString; - private T dataAsObject; - private Class tclass; - private JAXBDF 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 df, Stringifier strfr, Objectifier objfr, String text, Class 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 df, Stringifier strfr, Objectifier objfr, T object) { - dataAsString = null; - dataAsObject = object; - stringifier = strfr; - objectifier = objfr; - tclass = (Class) object.getClass(); - creatingEnv = env; - this.df = df; - } + private Stringifier stringifier; + private Objectifier objectifier; + private String dataAsString; + private T dataAsObject; + private Class tclass; + private JAXBDF 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 df, Stringifier strfr, Objectifier objfr, String text, Class 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 df, Stringifier strfr, Objectifier objfr, T object) { + dataAsString = null; + dataAsObject = object; + stringifier = strfr; + objectifier = objfr; + tclass = (Class) object.getClass(); + creatingEnv = env; + this.df = df; + } - /** - * Respond with the String if it exists, or marshal the String and pass the result back.

- * - * 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.

+ * + * 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 { + dataAsString = stringifier.stringify(env, dataAsObject); + return dataAsString; + } + } - /** - * 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 to(OutputStream os) throws APIException, IOException { - if(dataAsString!=null) { - os.write(dataAsString.getBytes()); - } else if (stringifier instanceof IOStringifier){ - ((IOStringifier)stringifier).stringify(creatingEnv, dataAsObject, os, options); - } else { - dataAsString = stringifier.stringify(creatingEnv, dataAsObject, options); - os.write(dataAsString.getBytes()); - } - return this; - } + /** + * 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 { + dataAsString = stringifier.stringify(creatingEnv, dataAsObject,options); + return dataAsString; + } + } + + public Data to(OutputStream os) throws APIException, IOException { + if (dataAsString!=null) { + os.write(dataAsString.getBytes()); + } else if (stringifier instanceof IOStringifier){ + ((IOStringifier)stringifier).stringify(creatingEnv, dataAsObject, os, options); + } else { + dataAsString = stringifier.stringify(creatingEnv, dataAsObject, options); + os.write(dataAsString.getBytes()); + } + return this; + } - // @Override - public JAXBData to(Writer writer) throws APIException, IOException { - if(dataAsString!=null) { - writer.write(dataAsString); - } else if (stringifier instanceof IOStringifier){ - ((IOStringifier)stringifier).stringify(creatingEnv, dataAsObject, writer, options); - } else { - dataAsString = stringifier.stringify(creatingEnv, dataAsObject, options); - writer.write(dataAsString); - } - return this; - } + // @Override + public JAXBData to(Writer writer) throws APIException, IOException { + if (dataAsString!=null) { + writer.write(dataAsString); + } else if (stringifier instanceof IOStringifier){ + ((IOStringifier)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 } if it exists, or unmarshal from String - * and pass the result back.

- * - * Explicitly use a specific Env for logging purposes - * - * @param env - * @return T - * @throws APIException - */ + 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 } if it exists, or unmarshal from String + * and pass the result back.

+ * + * 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; - } - } + 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 } if it exists, or unmarshal from String - * and pass the result back.

- * - * 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; - } - } - + /** + * Respond with the Object of type {@literal } if it exists, or unmarshal from String + * and pass the result back.

+ * + * 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} - */ - // @Override - public Class getTypeClass() { - return tclass; - } - - - /** - * For Debugging Convenience, we marshal to String if possible. - * - * Behavior is essentially the same as asString(), except asString() throws - * an APIException.

- * Since toString() must not throw exceptions, the function just catches and prints an - * error, which is probably not the behavior desired.

- * - * 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(); - } - } - } + /** + * Return the Class Type supported by this DataObject + * + * @return {@literal Class} + */ + // @Override + public Class getTypeClass() { + return tclass; + } + + + /** + * For Debugging Convenience, we marshal to String if possible. + * + * Behavior is essentially the same as asString(), except asString() throws + * an APIException.

+ * Since toString() must not throw exceptions, the function just catches and prints an + * error, which is probably not the behavior desired.

+ * + * 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 { + dataAsString = stringifier.stringify(creatingEnv, dataAsObject); + return dataAsString; + } catch (APIException e) { + return "ERROR - Can't Stringify from Object " + e.getLocalizedMessage(); + } + } + } - public Data load(T t) throws APIException { - dataAsObject = t; - dataAsString = null; - return this; - } + public Data load(T t) throws APIException { + dataAsObject = t; + dataAsString = null; + return this; + } - public Data load(String str) throws APIException { - dataAsObject = null; - dataAsString = str; - return this; - } + public Data load(String str) throws APIException { + dataAsObject = null; + dataAsString = str; + return this; + } - public Data 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 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 load(Reader rdr) throws APIException { - try { - dataAsObject = df.jumar.unmarshal(creatingEnv.debug(),rdr); - dataAsString = null; - } catch (JAXBException e) { - throw new APIException(e); - } - return this; - } + public Data 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 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 out(TYPE type) { - // it's going to be XML regardless... - return this; - } + // @Override + public Data out(TYPE type) { + // it's going to be XML regardless... + return this; + } - // @Override - public Data in(TYPE type) { - // Not Supported... will still be XML - return this; - } + // @Override + public Data in(TYPE type) { + // Not Supported... will still be XML + return this; + } - // @Override - public Data option(int option) { - options[0] = (option&Data.PRETTY)==Data.PRETTY; - options[1] = (option&Data.FRAGMENT)==Data.FRAGMENT; - return this; - } - + // @Override + public Data option(int option) { + options[0] = (option&Data.PRETTY)==Data.PRETTY; + options[1] = (option&Data.FRAGMENT)==Data.FRAGMENT; + return this; + } + } \ No newline at end of file