From 4b5a7d721d994a49057e9bfb403c7bff1b376660 Mon Sep 17 00:00:00 2001 From: Instrumental Date: Fri, 7 Sep 2018 12:21:34 -0500 Subject: Mass removal of all Tabs (Style Warnings) Issue-ID: AAF-473 Change-Id: Iaf0ef8120882937959bb0065f2f6ba74a021940f Signed-off-by: Instrumental --- .../java/org/onap/aaf/misc/env/APIException.java | 94 +-- .../org/onap/aaf/misc/env/BaseDataFactory.java | 806 ++++++++++----------- .../main/java/org/onap/aaf/misc/env/Creatable.java | 30 +- .../src/main/java/org/onap/aaf/misc/env/Data.java | 108 +-- .../java/org/onap/aaf/misc/env/DataFactory.java | 6 +- .../main/java/org/onap/aaf/misc/env/Decryptor.java | 16 +- .../main/java/org/onap/aaf/misc/env/Encryptor.java | 14 +- .../src/main/java/org/onap/aaf/misc/env/Env.java | 156 ++-- .../main/java/org/onap/aaf/misc/env/EnvJAXB.java | 42 +- .../main/java/org/onap/aaf/misc/env/EnvProps.java | 96 +-- .../java/org/onap/aaf/misc/env/IOObjectifier.java | 50 +- .../java/org/onap/aaf/misc/env/IOStringifier.java | 78 +- .../main/java/org/onap/aaf/misc/env/LifeCycle.java | 146 ++-- .../main/java/org/onap/aaf/misc/env/LogTarget.java | 196 ++--- .../java/org/onap/aaf/misc/env/Objectifier.java | 40 +- .../src/main/java/org/onap/aaf/misc/env/Slot.java | 114 +-- .../java/org/onap/aaf/misc/env/StaticSlot.java | 78 +- .../src/main/java/org/onap/aaf/misc/env/Store.java | 148 ++-- .../main/java/org/onap/aaf/misc/env/StoreImpl.java | 400 +++++----- .../java/org/onap/aaf/misc/env/Stringifier.java | 28 +- .../main/java/org/onap/aaf/misc/env/TimeTaken.java | 154 ++-- .../src/main/java/org/onap/aaf/misc/env/Trans.java | 56 +- .../java/org/onap/aaf/misc/env/TransCreate.java | 2 +- .../java/org/onap/aaf/misc/env/TransStore.java | 60 +- .../java/org/onap/aaf/misc/env/impl/AbsTrans.java | 350 ++++----- .../org/onap/aaf/misc/env/impl/AbsTransJAXB.java | 46 +- .../java/org/onap/aaf/misc/env/impl/BasicEnv.java | 580 +++++++-------- .../org/onap/aaf/misc/env/impl/BasicTrans.java | 78 +- .../org/onap/aaf/misc/env/impl/EnvFactory.java | 58 +- .../onap/aaf/misc/env/impl/JavaUtilLogTarget.java | 94 +-- .../org/onap/aaf/misc/env/impl/Log4JLogTarget.java | 126 ++-- .../org/onap/aaf/misc/env/impl/NullLifeCycle.java | 10 +- .../java/org/onap/aaf/misc/env/jaxb/JAXBDF.java | 526 +++++++------- .../java/org/onap/aaf/misc/env/jaxb/JAXBData.java | 478 ++++++------ .../onap/aaf/misc/env/jaxb/JAXBObjectifier.java | 186 ++--- .../onap/aaf/misc/env/jaxb/JAXBStringifier.java | 198 ++--- .../java/org/onap/aaf/misc/env/jaxb/JAXBmar.java | 374 +++++----- .../java/org/onap/aaf/misc/env/jaxb/JAXBumar.java | 346 ++++----- .../org/onap/aaf/misc/env/old/IOObjectifier.java | 50 +- .../org/onap/aaf/misc/env/old/IOStringifier.java | 78 +- .../org/onap/aaf/misc/env/old/Objectifier.java | 40 +- .../org/onap/aaf/misc/env/old/OldDataFactory.java | 22 +- .../org/onap/aaf/misc/env/old/Stringifier.java | 28 +- .../java/org/onap/aaf/misc/env/util/Chrono.java | 524 +++++++------- .../onap/aaf/misc/env/util/DoubleOutputStream.java | 70 +- .../org/onap/aaf/misc/env/util/IPValidator.java | 54 +- .../main/java/org/onap/aaf/misc/env/util/Pool.java | 618 ++++++++-------- .../aaf/misc/env/util/RefreshableThreadObject.java | 134 ++-- .../java/org/onap/aaf/misc/env/util/Split.java | 128 ++-- .../misc/env/util/StringBuilderOutputStream.java | 70 +- .../aaf/misc/env/util/StringBuilderWriter.java | 62 +- .../org/onap/aaf/misc/env/JU_APIExceptionTest.java | 60 +- .../org/onap/aaf/misc/env/JU_BasicTransTest.java | 146 ++-- .../org/onap/aaf/misc/env/JU_LogTargetTest.java | 70 +- .../onap/aaf/misc/env/impl/JU_BasicEnvTest.java | 202 +++--- .../onap/aaf/misc/env/impl/JU_EnvFactoryTest.java | 64 +- .../aaf/misc/env/impl/JU_Log4JLogTargetTest.java | 30 +- .../onap/aaf/misc/env/jaxb/JU_JAXBDataTest.java | 192 ++--- .../org/onap/aaf/misc/env/util/JU_ChronoTest.java | 302 ++++---- .../misc/env/util/JU_DoubleOutputStreamTest.java | 94 +-- .../misc/env/util/JU_IndentPrintWriterTest.java | 108 +-- .../org/onap/aaf/misc/env/util/JU_SplitTest.java | 52 +- .../env/util/JU_StringBuilderOutputStreamTest.java | 202 +++--- .../misc/env/util/JU_StringBuilderWriterTest.java | 202 +++--- .../aaf/misc/env/util/test/JU_IPValidator.java | 64 +- .../onap/aaf/misc/env/util/test/JU_PoolTest.java | 90 +-- 66 files changed, 5062 insertions(+), 5062 deletions(-) (limited to 'misc/env') diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/APIException.java b/misc/env/src/main/java/org/onap/aaf/misc/env/APIException.java index bf1d357f..4aa1451e 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/APIException.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/APIException.java @@ -35,55 +35,55 @@ package org.onap.aaf.misc.env; * */ public class APIException extends Exception { - - private Object payload = null; - - /** - * @param t - */ - public APIException(Throwable t) { - super(t); - } - - /** - * @param string - */ - public APIException(String string) { - super(string); - } + + private Object payload = null; + + /** + * @param t + */ + public APIException(Throwable t) { + super(t); + } + + /** + * @param string + */ + public APIException(String string) { + super(string); + } - /** - * @param errorMessage - * @param t - */ - public APIException(String errorMessage, Throwable t) { - super(errorMessage,t); - } + /** + * @param errorMessage + * @param t + */ + public APIException(String errorMessage, Throwable t) { + super(errorMessage,t); + } - /** - * Return payload, or null if none was set. Type is up to the calling - * System. - * - * @return Object - */ - public Object getPayload() { - return payload; - } + /** + * Return payload, or null if none was set. Type is up to the calling + * System. + * + * @return Object + */ + public Object getPayload() { + return payload; + } - /** - * Set a specific payload into this Exception, which doesn't necessarily - * inherit from Throwable. - * - * @param payload - * @return APIException - */ - public APIException setPayload(Object payload) { - this.payload = payload; - return this; - } + /** + * Set a specific payload into this Exception, which doesn't necessarily + * inherit from Throwable. + * + * @param payload + * @return APIException + */ + public APIException setPayload(Object payload) { + this.payload = payload; + return this; + } - /** - * Java expected serial ID - */ - private static final long serialVersionUID = 3505343458251445169L; + /** + * Java expected serial ID + */ + private static final long serialVersionUID = 3505343458251445169L; } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/BaseDataFactory.java b/misc/env/src/main/java/org/onap/aaf/misc/env/BaseDataFactory.java index 78615018..d72222e8 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/BaseDataFactory.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/BaseDataFactory.java @@ -54,425 +54,425 @@ import org.xml.sax.SAXException; * @param */ public class BaseDataFactory { - private static final Object LOCK = new Object(); - /** - * Generate a Schema Object for use in validation based on FileNames. - * - * WARNING: The java.xml.binding code requires YOU to figure out what order the - * files go in. If there is an import from A in B, then you must list A first. - * - * @param err - * @param filenames - * @return - * @throws APIException - */ - public static Schema genSchema(Store env, String ... filenames) throws APIException { - String schemaDir = env.get( - env.staticSlot(EnvFactory.SCHEMA_DIR), - EnvFactory.DEFAULT_SCHEMA_DIR); - File dir = new File(schemaDir); - if(!dir.exists())throw new APIException("Schema Directory " + schemaDir + " does not exist. You can set this with " + EnvFactory.SCHEMA_DIR + " property"); - FileInputStream[] fis = new FileInputStream[filenames.length]; - Source[] sources = new Source[filenames.length]; - File f; - for(int i=0; i clss) throws APIException { - // Obtain the Necessary info for QName from Requirement - XmlRootElement xre = clss.getAnnotation(XmlRootElement.class); - if(xre==null)throw new APIException(clss.getName() + " does not have an XmlRootElement annotation"); - Package pkg = clss.getPackage(); - XmlSchema xs = pkg.getAnnotation(XmlSchema.class); - if(xs==null) throw new APIException(clss.getName() + " package-info does not have an XmlSchema annotation"); - return new QName(xs.namespace(),xre.name()); - } + public static QName getQName(Class clss) throws APIException { + // Obtain the Necessary info for QName from Requirement + XmlRootElement xre = clss.getAnnotation(XmlRootElement.class); + if(xre==null)throw new APIException(clss.getName() + " does not have an XmlRootElement annotation"); + Package pkg = clss.getPackage(); + XmlSchema xs = pkg.getAnnotation(XmlSchema.class); + if(xs==null) throw new APIException(clss.getName() + " package-info does not have an XmlSchema annotation"); + return new QName(xs.namespace(),xre.name()); + } - ///////////////////////////////////////////// - // Native Type Converters - ///////////////////////////////////////////// -// /** -// * StringStringifier -// * -// * Support the Native Type String.. just return it back -// * -// * @author Jonathan -// * -// */ -// public static class StringStringifier extends NullLifeCycle implements Stringifier { -// /* (non-Javadoc) -// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) -// */ -// public String stringify(Env env, String input) throws APIException { -// return input; -// } -// }; + ///////////////////////////////////////////// + // Native Type Converters + ///////////////////////////////////////////// +// /** +// * StringStringifier +// * +// * Support the Native Type String.. just return it back +// * +// * @author Jonathan +// * +// */ +// public static class StringStringifier extends NullLifeCycle implements Stringifier { +// /* (non-Javadoc) +// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) +// */ +// public String stringify(Env env, String input) throws APIException { +// return input; +// } +// }; // -// /** -// * StringObjectifier -// * -// * Support the Native Type String.. just return it back -// * -// * @author Jonathan -// * -// */ -// public static class StringObjectifier extends NullLifeCycle implements Objectifier { -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) -// */ -// public String objectify(Env env, String input) throws APIException { -// return input; -// } +// /** +// * StringObjectifier +// * +// * Support the Native Type String.. just return it back +// * +// * @author Jonathan +// * +// */ +// public static class StringObjectifier extends NullLifeCycle implements Objectifier { +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) +// */ +// public String objectify(Env env, String input) throws APIException { +// return input; +// } // -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#newObject() -// */ -// public String newInstance() throws APIException { -// return ""; -// } -// }; -// -// /** -// * LongStringifier -// * -// * Support the Native Type Long.. use Long parse functions -// * -// * @author Jonathan -// * -// */ -// public static class LongStringifier extends NullLifeCycle implements Stringifier { -// public String stringify(Env env, Long input) throws APIException { -// return input.toString(); -// } -// } -// -// /** -// * LongObjectifier -// * -// * Support the Native Type Long.. use Long parse functions -// * -// * @author Jonathan -// * -// */ -// public static class LongObjectifier extends NullLifeCycle implements Objectifier { -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) -// */ -// public Long objectify(Env env, String input) throws APIException { -// try { -// return new Long(input); -// } catch (Exception e) { -// APIException ae = new APIException("Cannot create a \"Long\" from [" + input + ']'); -// ae.initCause(e); -// throw ae; -// } -// } +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#newObject() +// */ +// public String newInstance() throws APIException { +// return ""; +// } +// }; +// +// /** +// * LongStringifier +// * +// * Support the Native Type Long.. use Long parse functions +// * +// * @author Jonathan +// * +// */ +// public static class LongStringifier extends NullLifeCycle implements Stringifier { +// public String stringify(Env env, Long input) throws APIException { +// return input.toString(); +// } +// } +// +// /** +// * LongObjectifier +// * +// * Support the Native Type Long.. use Long parse functions +// * +// * @author Jonathan +// * +// */ +// public static class LongObjectifier extends NullLifeCycle implements Objectifier { +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) +// */ +// public Long objectify(Env env, String input) throws APIException { +// try { +// return new Long(input); +// } catch (Exception e) { +// APIException ae = new APIException("Cannot create a \"Long\" from [" + input + ']'); +// ae.initCause(e); +// throw ae; +// } +// } // -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#newObject() -// */ -// public Long newInstance() throws APIException { -// return 0L; -// } -// } +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#newObject() +// */ +// public Long newInstance() throws APIException { +// return 0L; +// } +// } // -// /** -// * IntegerStringifier -// * -// * Support the Native Integer.. use Integer parse functions -// * -// * @author Jonathan -// * -// */ -// public static class IntegerStringifier extends NullLifeCycle implements Stringifier { -// /* (non-Javadoc) -// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) -// */ -// public String stringify(Env env, Integer input) throws APIException { -// return input.toString(); -// } -// } -// -// /** -// * IntegerObjectifier -// * -// * Support the Native Integer.. use Integer parse functions -// * -// * @author Jonathan -// * -// */ -// public static class IntegerObjectifier extends NullLifeCycle implements Objectifier { -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) -// */ -// public Integer objectify(Env env, String input) throws APIException { -// try { -// return new Integer(input); -// } catch (Exception e) { -// APIException ae = new APIException("Cannot create a \"Integer\" from [" + input + ']'); -// ae.initCause(e); -// throw ae; -// } -// } +// /** +// * IntegerStringifier +// * +// * Support the Native Integer.. use Integer parse functions +// * +// * @author Jonathan +// * +// */ +// public static class IntegerStringifier extends NullLifeCycle implements Stringifier { +// /* (non-Javadoc) +// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) +// */ +// public String stringify(Env env, Integer input) throws APIException { +// return input.toString(); +// } +// } +// +// /** +// * IntegerObjectifier +// * +// * Support the Native Integer.. use Integer parse functions +// * +// * @author Jonathan +// * +// */ +// public static class IntegerObjectifier extends NullLifeCycle implements Objectifier { +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) +// */ +// public Integer objectify(Env env, String input) throws APIException { +// try { +// return new Integer(input); +// } catch (Exception e) { +// APIException ae = new APIException("Cannot create a \"Integer\" from [" + input + ']'); +// ae.initCause(e); +// throw ae; +// } +// } // -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#newObject() -// */ -// public Integer newInstance() throws APIException { -// return 0; -// } -// } +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#newObject() +// */ +// public Integer newInstance() throws APIException { +// return 0; +// } +// } // -// /** -// * ShortStringifier -// * -// * Support the Native Short.. use Short parse functions -// * -// * @author Jonathan -// * -// */ -// public static class ShortStringifier extends NullLifeCycle implements Stringifier { -// public String stringify(Env env, Short input) throws APIException { -// return input.toString(); -// } -// } -// -// /** -// * ShortObjectifier -// * -// * Support the Native Short.. use Short parse functions -// * -// * @author Jonathan -// * -// */ -// public static class ShortObjectifier extends NullLifeCycle implements Objectifier { -// public Short objectify(Env env, String input) throws APIException { -// try { -// return new Short(input); -// } catch (Exception e) { -// APIException ae = new APIException("Cannot create a \"Short\" from [" + input + ']'); -// ae.initCause(e); -// throw ae; -// } -// } +// /** +// * ShortStringifier +// * +// * Support the Native Short.. use Short parse functions +// * +// * @author Jonathan +// * +// */ +// public static class ShortStringifier extends NullLifeCycle implements Stringifier { +// public String stringify(Env env, Short input) throws APIException { +// return input.toString(); +// } +// } +// +// /** +// * ShortObjectifier +// * +// * Support the Native Short.. use Short parse functions +// * +// * @author Jonathan +// * +// */ +// public static class ShortObjectifier extends NullLifeCycle implements Objectifier { +// public Short objectify(Env env, String input) throws APIException { +// try { +// return new Short(input); +// } catch (Exception e) { +// APIException ae = new APIException("Cannot create a \"Short\" from [" + input + ']'); +// ae.initCause(e); +// throw ae; +// } +// } // -// public Short newInstance() throws APIException { -// return 0; -// } -// } -// -// /** -// * ByteStringifier -// * -// * Support the Native Byte.. use Byte parse functions -// * -// * @author Jonathan -// * -// */ -// public static class ByteStringifier extends NullLifeCycle implements Stringifier { -// /* (non-Javadoc) -// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) -// */ -// public String stringify(Env env, Byte input) throws APIException { -// return input.toString(); -// } -// } -// -// /** -// * ByteObjectifier -// * -// * Support the Native Byte.. use Byte parse functions -// * -// * @author Jonathan -// * -// */ -// public static class ByteObjectifier extends NullLifeCycle implements Objectifier { -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) -// */ -// public Byte objectify(Env env, String input) throws APIException { -// try { -// return new Byte(input); -// } catch (Exception e) { -// APIException ae = new APIException("Cannot create a \"Byte\" from [" + input + ']'); -// ae.initCause(e); -// throw ae; -// } -// } +// public Short newInstance() throws APIException { +// return 0; +// } +// } +// +// /** +// * ByteStringifier +// * +// * Support the Native Byte.. use Byte parse functions +// * +// * @author Jonathan +// * +// */ +// public static class ByteStringifier extends NullLifeCycle implements Stringifier { +// /* (non-Javadoc) +// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) +// */ +// public String stringify(Env env, Byte input) throws APIException { +// return input.toString(); +// } +// } +// +// /** +// * ByteObjectifier +// * +// * Support the Native Byte.. use Byte parse functions +// * +// * @author Jonathan +// * +// */ +// public static class ByteObjectifier extends NullLifeCycle implements Objectifier { +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) +// */ +// public Byte objectify(Env env, String input) throws APIException { +// try { +// return new Byte(input); +// } catch (Exception e) { +// APIException ae = new APIException("Cannot create a \"Byte\" from [" + input + ']'); +// ae.initCause(e); +// throw ae; +// } +// } // -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#newObject() -// */ -// public Byte newInstance() throws APIException { -// return 0; -// } -// } +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#newObject() +// */ +// public Byte newInstance() throws APIException { +// return 0; +// } +// } // -// /** -// * CharacterStringifier -// * -// * Support the Native Character.. use Character parse functions -// * -// * @author Jonathan -// * -// */ -// public static class CharacterStringifier extends NullLifeCycle implements Stringifier { -// /* (non-Javadoc) -// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) -// */ -// public String stringify(Env env, Character input) throws APIException { -// return input.toString(); -// } -// } -// -// /** -// * CharacterObjectifier -// * -// * Support the Native Character.. use Character parse functions -// * -// * @author Jonathan -// * -// */ -// public static class CharacterObjectifier extends NullLifeCycle implements Objectifier { -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) -// */ -// public Character objectify(Env env, String input) throws APIException { -// int length = input.length(); -// if(length<1 || length>1) { -// throw new APIException("String [" + input + "] does not represent a single Character"); -// } -// return input.charAt(0); -// } +// /** +// * CharacterStringifier +// * +// * Support the Native Character.. use Character parse functions +// * +// * @author Jonathan +// * +// */ +// public static class CharacterStringifier extends NullLifeCycle implements Stringifier { +// /* (non-Javadoc) +// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) +// */ +// public String stringify(Env env, Character input) throws APIException { +// return input.toString(); +// } +// } +// +// /** +// * CharacterObjectifier +// * +// * Support the Native Character.. use Character parse functions +// * +// * @author Jonathan +// * +// */ +// public static class CharacterObjectifier extends NullLifeCycle implements Objectifier { +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) +// */ +// public Character objectify(Env env, String input) throws APIException { +// int length = input.length(); +// if(length<1 || length>1) { +// throw new APIException("String [" + input + "] does not represent a single Character"); +// } +// return input.charAt(0); +// } // -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#newObject() -// */ -// public Character newInstance() throws APIException { -// return 0; -// } -// } +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#newObject() +// */ +// public Character newInstance() throws APIException { +// return 0; +// } +// } // -// /** -// * FloatStringifier -// * -// * Support the Native Float.. use Float parse functions -// * -// * @author Jonathan -// * -// */ -// public static class FloatStringifier extends NullLifeCycle implements Stringifier { -// /* (non-Javadoc) -// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) -// */ -// public String stringify(Env env, Float input) throws APIException { -// return input.toString(); -// } -// } -// -// /** -// * FloatObjectifier -// * -// * Support the Native Float.. use Float parse functions -// * -// * @author Jonathan -// * -// */ -// public static class FloatObjectifier extends NullLifeCycle implements Objectifier { -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) -// */ -// public Float objectify(Env env, String input) throws APIException { -// try { -// return new Float(input); -// } catch (Exception e) { -// APIException ae = new APIException("Cannot create a \"Float\" from [" + input + ']'); -// ae.initCause(e); -// throw ae; -// } -// } +// /** +// * FloatStringifier +// * +// * Support the Native Float.. use Float parse functions +// * +// * @author Jonathan +// * +// */ +// public static class FloatStringifier extends NullLifeCycle implements Stringifier { +// /* (non-Javadoc) +// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) +// */ +// public String stringify(Env env, Float input) throws APIException { +// return input.toString(); +// } +// } +// +// /** +// * FloatObjectifier +// * +// * Support the Native Float.. use Float parse functions +// * +// * @author Jonathan +// * +// */ +// public static class FloatObjectifier extends NullLifeCycle implements Objectifier { +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) +// */ +// public Float objectify(Env env, String input) throws APIException { +// try { +// return new Float(input); +// } catch (Exception e) { +// APIException ae = new APIException("Cannot create a \"Float\" from [" + input + ']'); +// ae.initCause(e); +// throw ae; +// } +// } // -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#newObject() -// */ -// public Float newInstance() throws APIException { -// return 0.0f; -// } -// } +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#newObject() +// */ +// public Float newInstance() throws APIException { +// return 0.0f; +// } +// } // -// /** -// * DoubleStringifier -// * -// * Support the Native Double.. use Double parse functions -// * -// * @author Jonathan -// * -// */ -// public static class DoubleStringifier extends NullLifeCycle implements Stringifier { -// /* (non-Javadoc) -// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) -// */ -// public String stringify(Env env, Double input) throws APIException { -// return input.toString(); -// } -// } -// -// /** -// * DoubleObjectifier -// * -// * Support the Native Double.. use Double parse functions -// * -// * @author Jonathan -// * -// */ -// public static class DoubleObjectifier extends NullLifeCycle implements Objectifier { -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) -// */ -// public Double objectify(Env env, String input) throws APIException { -// try { -// return new Double(input); -// } catch (Exception e) { -// APIException ae = new APIException("Cannot create a \"Double\" from [" + input + ']'); -// ae.initCause(e); -// throw ae; -// } -// } +// /** +// * DoubleStringifier +// * +// * Support the Native Double.. use Double parse functions +// * +// * @author Jonathan +// * +// */ +// public static class DoubleStringifier extends NullLifeCycle implements Stringifier { +// /* (non-Javadoc) +// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) +// */ +// public String stringify(Env env, Double input) throws APIException { +// return input.toString(); +// } +// } +// +// /** +// * DoubleObjectifier +// * +// * Support the Native Double.. use Double parse functions +// * +// * @author Jonathan +// * +// */ +// public static class DoubleObjectifier extends NullLifeCycle implements Objectifier { +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) +// */ +// public Double objectify(Env env, String input) throws APIException { +// try { +// return new Double(input); +// } catch (Exception e) { +// APIException ae = new APIException("Cannot create a \"Double\" from [" + input + ']'); +// ae.initCause(e); +// throw ae; +// } +// } // -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#newObject() -// */ -// public Double newInstance() throws APIException { -// return 0.0; -// } -// } +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#newObject() +// */ +// public Double newInstance() throws APIException { +// return 0.0; +// } +// } } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/Creatable.java b/misc/env/src/main/java/org/onap/aaf/misc/env/Creatable.java index 2423ed62..c64cfff2 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/Creatable.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/Creatable.java @@ -34,19 +34,19 @@ package org.onap.aaf.misc.env; * @param */ public interface Creatable { - /** - * Return the timestamp (Unix long) when this object was created.

- * This can be used to see if the object is out of date in certain - * circumstances, or perhaps has already been notified in others. - * - * @return long - */ - public abstract long created(); - - /** - * Allow LifeCycle aware process to signal this element as destroyed. - * - * @param env - */ - public abstract void destroy(Env env); + /** + * Return the timestamp (Unix long) when this object was created.

+ * This can be used to see if the object is out of date in certain + * circumstances, or perhaps has already been notified in others. + * + * @return long + */ + public abstract long created(); + + /** + * Allow LifeCycle aware process to signal this element as destroyed. + * + * @param env + */ + public abstract void destroy(Env env); } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/Data.java b/misc/env/src/main/java/org/onap/aaf/misc/env/Data.java index 155dfc71..4c64e5de 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/Data.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/Data.java @@ -42,7 +42,7 @@ import java.io.Writer; * the "options" available on several functions control the output of this particular call. When * blank, they will default to the DataFactory defaults. When present, they override this * particular call. - * The available options are "pretty" (for XML and JSON) and "fragment" (XML only concept), which drops + * The available options are "pretty" (for XML and JSON) and "fragment" (XML only concept), which drops * the "" header so you can create larger XML documents from the output. * * @author Jonathan @@ -50,64 +50,64 @@ import java.io.Writer; * @param */ public interface Data { - static enum TYPE {XML,JSON,JAXB,RAW,DEFAULT}; - // can & with 0xFFFF; -// public static final int XML = 0x1; -// public static final int JSON = 0x2; -// public static final int JAXB = 0x4; -// public static final int RAW = 0x1000; - - // can & with 0xF00000; - public static final int PRETTY = 0x100000; - public static final int FRAGMENT = 0x200000; + static enum TYPE {XML,JSON,JAXB,RAW,DEFAULT}; + // can & with 0xFFFF; +// public static final int XML = 0x1; +// public static final int JSON = 0x2; +// public static final int JAXB = 0x4; +// public static final int RAW = 0x1000; + + // can & with 0xF00000; + public static final int PRETTY = 0x100000; + public static final int FRAGMENT = 0x200000; - /** - * 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 - */ - public String asString() throws APIException; + /** + * 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 + */ + public String asString() throws APIException; - /** - * 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 - */ - public T asObject() throws APIException; + /** + * 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 + */ + public T asObject() throws APIException; - /** - * Set a particular option on an existing Out - * - * if int is negative, it should remove the option - * @param option - */ - public Data option(int option); + /** + * Set a particular option on an existing Out + * + * if int is negative, it should remove the option + * @param option + */ + public Data option(int option); - public Data to(OutputStream os) throws APIException, IOException; - public Data to(Writer writer) throws APIException, IOException; - - public Data load(T t) throws APIException; - public Data load(String str) throws APIException; - public Data load(InputStream is) throws APIException; - public Data load(Reader rdr) throws APIException; - - public Data in(TYPE type); - public Data out(TYPE type); - /** - * Return the Class Type supported by this DataObject - * - * @return {@literal Class} - */ - public Class getTypeClass(); + public Data to(OutputStream os) throws APIException, IOException; + public Data to(Writer writer) throws APIException, IOException; + + public Data load(T t) throws APIException; + public Data load(String str) throws APIException; + public Data load(InputStream is) throws APIException; + public Data load(Reader rdr) throws APIException; + + public Data in(TYPE type); + public Data out(TYPE type); + /** + * Return the Class Type supported by this DataObject + * + * @return {@literal Class} + */ + public Class getTypeClass(); - public void direct(InputStream input, OutputStream output) throws APIException, IOException; + public void direct(InputStream input, OutputStream output) throws APIException, IOException; } \ No newline at end of file diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/DataFactory.java b/misc/env/src/main/java/org/onap/aaf/misc/env/DataFactory.java index a9595a55..6735e9a6 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/DataFactory.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/DataFactory.java @@ -23,8 +23,8 @@ package org.onap.aaf.misc.env; public interface DataFactory { - public abstract Data newData(); - public abstract Data newData(Env trans); // and Env or Trans object - public abstract Class getTypeClass(); + public abstract Data newData(); + public abstract Data newData(Env trans); // and Env or Trans object + public abstract Class getTypeClass(); } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/Decryptor.java b/misc/env/src/main/java/org/onap/aaf/misc/env/Decryptor.java index bc29c318..48d55e0a 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/Decryptor.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/Decryptor.java @@ -23,12 +23,12 @@ package org.onap.aaf.misc.env; public interface Decryptor { - public String decrypt(String tag); - - public static final Decryptor NULL = new Decryptor() { - @Override - public String decrypt(String tag) { - return tag; - } - }; + public String decrypt(String tag); + + public static final Decryptor NULL = new Decryptor() { + @Override + public String decrypt(String tag) { + return tag; + } + }; } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/Encryptor.java b/misc/env/src/main/java/org/onap/aaf/misc/env/Encryptor.java index ad7409d0..1925f65e 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/Encryptor.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/Encryptor.java @@ -23,12 +23,12 @@ package org.onap.aaf.misc.env; public interface Encryptor { - public String encrypt(String data); + public String encrypt(String data); - public static final Encryptor NULL = new Encryptor() { - @Override - public String encrypt(String data) { - return data; - } - }; + public static final Encryptor NULL = new Encryptor() { + @Override + public String encrypt(String data) { + return data; + } + }; } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/Env.java b/misc/env/src/main/java/org/onap/aaf/misc/env/Env.java index e4b6aaa2..f709a434 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/Env.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/Env.java @@ -46,91 +46,91 @@ package org.onap.aaf.misc.env; * */ public interface Env { - /** - * Very Severe Error may cause program to abort - */ - public LogTarget fatal(); - - /** - * Severe Error, but program might continue running - */ - public LogTarget error(); + /** + * Very Severe Error may cause program to abort + */ + public LogTarget fatal(); + + /** + * Severe Error, but program might continue running + */ + public LogTarget error(); - /** - * Required Audit statements - * @return - */ - public LogTarget audit(); + /** + * Required Audit statements + * @return + */ + public LogTarget audit(); - /** - * Initialization steps... Allows a Logger to separate startup info - * @return - */ - public LogTarget init(); + /** + * Initialization steps... Allows a Logger to separate startup info + * @return + */ + public LogTarget init(); - /** - * Potentially harmful situations - * @return - */ - public LogTarget warn(); - - /** - * Course Grained highlights of program progress - * @return - */ - public LogTarget info(); - - /** - * Fine-grained informational events useful for debugging - * @return - */ - public LogTarget debug(); - - /** - * Finest grained Informational events... more detailed than Debug - * @return - */ - public LogTarget trace(); + /** + * Potentially harmful situations + * @return + */ + public LogTarget warn(); + + /** + * Course Grained highlights of program progress + * @return + */ + public LogTarget info(); + + /** + * Fine-grained informational events useful for debugging + * @return + */ + public LogTarget debug(); + + /** + * Finest grained Informational events... more detailed than Debug + * @return + */ + public LogTarget trace(); - /** - * Basic and Common Audit info... - * - * Note Apps can define, but should use Integers after 0x1F. They can combine with "&" - */ - public static final int REMOTE = 0x01; - public static final int XML = 0x02; - public static final int JSON = 0x04; - public static final int SUB = 0x08; - public static final int CHECKPOINT = 0x10; - public static final int ALWAYS = 0x20; // Mark as a line to print, even in WARN+ mode + /** + * Basic and Common Audit info... + * + * Note Apps can define, but should use Integers after 0x1F. They can combine with "&" + */ + public static final int REMOTE = 0x01; + public static final int XML = 0x02; + public static final int JSON = 0x04; + public static final int SUB = 0x08; + public static final int CHECKPOINT = 0x10; + public static final int ALWAYS = 0x20; // Mark as a line to print, even in WARN+ mode - - /** - * Start a Time Trail with differentiation by flag. This can be Defined By above flags or combined with - * app flag definitions - * - * @param string - * @param flag - * @return - */ - public TimeTaken start(String name, int flag); - - public String setProperty(String tag, String value); - public String getProperty(String tag); - public String getProperty(String tag, String deflt); - - /** - * Passwords should be encrypted on the disk. Use this method to apply decryption before - * using. The Implementation should give ways to decrypt - * - * @param tag - * @return - */ - public Decryptor decryptor(); - - public Encryptor encryptor(); + + /** + * Start a Time Trail with differentiation by flag. This can be Defined By above flags or combined with + * app flag definitions + * + * @param string + * @param flag + * @return + */ + public TimeTaken start(String name, int flag); + + public String setProperty(String tag, String value); + public String getProperty(String tag); + public String getProperty(String tag, String deflt); + + /** + * Passwords should be encrypted on the disk. Use this method to apply decryption before + * using. The Implementation should give ways to decrypt + * + * @param tag + * @return + */ + public Decryptor decryptor(); + + public Encryptor encryptor(); } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/EnvJAXB.java b/misc/env/src/main/java/org/onap/aaf/misc/env/EnvJAXB.java index a530073e..09db36f4 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/EnvJAXB.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/EnvJAXB.java @@ -25,28 +25,28 @@ import javax.xml.namespace.QName; import javax.xml.validation.Schema; public interface EnvJAXB extends EnvStore { - /** - * Obtain a DataInterface from this Environment - * - * @param - * @param classes - * @return - * @throws APIException - */ - public DataFactory newDataFactory(Class... classes) throws APIException; + /** + * Obtain a DataInterface from this Environment + * + * @param + * @param classes + * @return + * @throws APIException + */ + public DataFactory newDataFactory(Class... classes) throws APIException; - /** - * Obtain a DataInterface from this Environment, with Validating Schema - * - * @param - * @param classes - * @return - * @throws APIException - */ - public DataFactory newDataFactory(Schema schema, Class... classes) throws APIException; + /** + * Obtain a DataInterface from this Environment, with Validating Schema + * + * @param + * @param classes + * @return + * @throws APIException + */ + public DataFactory newDataFactory(Schema schema, Class... classes) throws APIException; - public DataFactory newDataFactory(QName qName, Class ... classes) throws APIException; + public DataFactory newDataFactory(QName qName, Class ... classes) throws APIException; - public DataFactory newDataFactory(Schema schema, QName qName, Class ... classes) throws APIException; - + public DataFactory newDataFactory(Schema schema, QName qName, Class ... classes) throws APIException; + } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/EnvProps.java b/misc/env/src/main/java/org/onap/aaf/misc/env/EnvProps.java index 0e645da2..b2cebb55 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/EnvProps.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/EnvProps.java @@ -24,57 +24,57 @@ package org.onap.aaf.misc.env; import java.util.Map; public interface EnvProps extends Env { - public interface EnvProperty { - public String getProperty(String input); - }; + public interface EnvProperty { + public String getProperty(String input); + }; - /** - * Obtain a Property (String) based on a Key. Implementor decides how - * that works, i.e. from a complex set of Configurations, or just - * "System" (Java standard) - * - * @param key - * @return APIException - */ - public String getProperty(String key); + /** + * Obtain a Property (String) based on a Key. Implementor decides how + * that works, i.e. from a complex set of Configurations, or just + * "System" (Java standard) + * + * @param key + * @return APIException + */ + public String getProperty(String key); - /** - * Obtain a Property (String) based on a Key. Implementor decides how - * that works, i.e. from a complex set of Configurations, or just - * "System" (Java standard) - * - * If Property Value is null, then default will be used. - * @param key - * @return APIException - */ - public String getProperty(String tag, String defaultValue); + /** + * Obtain a Property (String) based on a Key. Implementor decides how + * that works, i.e. from a complex set of Configurations, or just + * "System" (Java standard) + * + * If Property Value is null, then default will be used. + * @param key + * @return APIException + */ + public String getProperty(String tag, String defaultValue); - /** - * Set a Property (String) based on a Key accessible to all in Env. Implementor decides how - * that works, i.e. from a complex set of Configurations, or just - * "System" (Java standard) - * - * @param key - * @return APIException - */ - public String setProperty(String key, String value); - - /** - * Get the SubProperties based on key. - * - * use "false" to remove prefix, "true" to leave prefix in. - * - * @param key - * @return APIException - * Given a known property set (or in this case, properties starting with key), - * return map of all properties with appropriate key names - */ - public Map getSubProperties(String key, boolean includePrefix); + /** + * Set a Property (String) based on a Key accessible to all in Env. Implementor decides how + * that works, i.e. from a complex set of Configurations, or just + * "System" (Java standard) + * + * @param key + * @return APIException + */ + public String setProperty(String key, String value); + + /** + * Get the SubProperties based on key. + * + * use "false" to remove prefix, "true" to leave prefix in. + * + * @param key + * @return APIException + * Given a known property set (or in this case, properties starting with key), + * return map of all properties with appropriate key names + */ + public Map getSubProperties(String key, boolean includePrefix); - /** - * Get all of the properties in the Environment - * @return - */ - public Map getProperties(); + /** + * Get all of the properties in the Environment + * @return + */ + public Map getProperties(); } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/IOObjectifier.java b/misc/env/src/main/java/org/onap/aaf/misc/env/IOObjectifier.java index e3e74305..70b4adde 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/IOObjectifier.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/IOObjectifier.java @@ -25,30 +25,30 @@ import java.io.InputStream; import java.io.Reader; public interface IOObjectifier extends Objectifier { - /** - * Marshal to Object T from a Reader, using contents from Env as necessary.

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return T - * @throws APIException - */ - public abstract T objectify(Env env, Reader rdr) throws APIException; - - /** - * Marshal to Object T from an InputStream, using contents from Env as necessary.

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return T - * @throws APIException - */ - public abstract T objectify(Env env, InputStream is) throws APIException; + /** + * Marshal to Object T from a Reader, using contents from Env as necessary.

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return T + * @throws APIException + */ + public abstract T objectify(Env env, Reader rdr) throws APIException; + + /** + * Marshal to Object T from an InputStream, using contents from Env as necessary.

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return T + * @throws APIException + */ + public abstract T objectify(Env env, InputStream is) throws APIException; } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/IOStringifier.java b/misc/env/src/main/java/org/onap/aaf/misc/env/IOStringifier.java index 57d85472..4329fcbc 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/IOStringifier.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/IOStringifier.java @@ -28,47 +28,47 @@ import java.io.Writer; * Allow Extended IO interface usage without muddying up the Stringifier Interface */ public interface IOStringifier extends Stringifier { - /** - * Marshal from an Object T onto a Writer, using contents from Env as necessary.

- * - * Implementations should use the {@link Env} to call "env.startTime(, Env.XML)" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return String - * @throws APIException - */ - public abstract void stringify(Env env, T input, Writer writer, boolean ... options) throws APIException; - - /** - * Marshal from a String to an Object T, using contents from Env as necessary.

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return String - * @throws APIException - */ - public abstract void stringify(Env env, T input, OutputStream os, boolean ... options) throws APIException; + /** + * Marshal from an Object T onto a Writer, using contents from Env as necessary.

+ * + * Implementations should use the {@link Env} to call "env.startTime(, Env.XML)" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return String + * @throws APIException + */ + public abstract void stringify(Env env, T input, Writer writer, boolean ... options) throws APIException; + + /** + * Marshal from a String to an Object T, using contents from Env as necessary.

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return String + * @throws APIException + */ + public abstract void stringify(Env env, T input, OutputStream os, boolean ... options) throws APIException; - /** - * Set Pretty XML, where possible - * - * @param pretty - * @throws APIException - */ - public abstract IOStringifier pretty(boolean pretty); + /** + * Set Pretty XML, where possible + * + * @param pretty + * @throws APIException + */ + public abstract IOStringifier pretty(boolean pretty); - /** - * Set Generate Fragment - * - * @param fragment - * @throws APIException - */ - public abstract IOStringifier asFragment(boolean fragment); + /** + * Set Generate Fragment + * + * @param fragment + * @throws APIException + */ + public abstract IOStringifier asFragment(boolean fragment); } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/LifeCycle.java b/misc/env/src/main/java/org/onap/aaf/misc/env/LifeCycle.java index 5124f6b5..75f3b701 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/LifeCycle.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/LifeCycle.java @@ -43,81 +43,81 @@ import org.onap.aaf.misc.env.util.RefreshableThreadObject; * */ public interface LifeCycle { - /** - * The Service using LifeCycle Elements is required to call this method at - * the appropriate startup time. This is better for services than a simple - * static call, because the exact moment of starting can be determined - * programatically. - *

- * - * An excellent use is to establish security credentials with a backend - * after appropriate configurations have been read and available as part of - * the {@link Env} Object. - * - * @param env - * @throws APIException - */ - public abstract void servicePrestart(Env env) throws APIException; + /** + * The Service using LifeCycle Elements is required to call this method at + * the appropriate startup time. This is better for services than a simple + * static call, because the exact moment of starting can be determined + * programatically. + *

+ * + * An excellent use is to establish security credentials with a backend + * after appropriate configurations have been read and available as part of + * the {@link Env} Object. + * + * @param env + * @throws APIException + */ + public abstract void servicePrestart(Env env) throws APIException; - /** - * Many cases of implementations are not thread safe, and mechanisms must be - * derived to accomodate them by holding per Thread. - *

- * - * {@link ThreadLocal} is a valuable resource, but start up times within the - * thread, depending on what it is, can be substantial. - *

- * - * Use ThreadPrestart to do all that is possible before actually performing - * work, i.e. inside of a client transaction. - * - * @param env - * @throws APIException - */ - public abstract void threadPrestart(Env env) throws APIException; + /** + * Many cases of implementations are not thread safe, and mechanisms must be + * derived to accomodate them by holding per Thread. + *

+ * + * {@link ThreadLocal} is a valuable resource, but start up times within the + * thread, depending on what it is, can be substantial. + *

+ * + * Use ThreadPrestart to do all that is possible before actually performing + * work, i.e. inside of a client transaction. + * + * @param env + * @throws APIException + */ + public abstract void threadPrestart(Env env) throws APIException; - /** - * The Service will call this when (service-defined) configurations change. - *

- * - * This mechanism allows the Service to recognize events, such as file - * changes, and pass on the event to all LifeCycle implementors. - *

- * - * The code should take the opportunity to evaluate configuration and change - * as necessary. - *

- * - *

IMPORTANT:

- * The LifeCycle implementor cannot guarantee it will not be in the middle - * of a transaction, so it would behoove the implementor to construct - * content that does not affect anything until finished, then apply to an - * appropriate atomic action (i.e. setting an Object to a field), or even - * synchronizing. - * - * If you are using Java's "ThreadLocal", consider - * {@link RefreshableThreadObject}, because it implements LifeCycle, and - * responds to the refresh command. - * - * @param env - * @throws APIException - */ - public abstract void refresh(Env env) throws APIException; + /** + * The Service will call this when (service-defined) configurations change. + *

+ * + * This mechanism allows the Service to recognize events, such as file + * changes, and pass on the event to all LifeCycle implementors. + *

+ * + * The code should take the opportunity to evaluate configuration and change + * as necessary. + *

+ * + *

IMPORTANT:

+ * The LifeCycle implementor cannot guarantee it will not be in the middle + * of a transaction, so it would behoove the implementor to construct + * content that does not affect anything until finished, then apply to an + * appropriate atomic action (i.e. setting an Object to a field), or even + * synchronizing. + * + * If you are using Java's "ThreadLocal", consider + * {@link RefreshableThreadObject}, because it implements LifeCycle, and + * responds to the refresh command. + * + * @param env + * @throws APIException + */ + public abstract void refresh(Env env) throws APIException; - /** - * Parallel to threadPrestart, threadDestroy tells the implementor that the - * service is ending this particular thread, and to take this opportunity to - * close out any content specific to this thread that can be closed. - * - * @param env - * @throws APIException - */ - public abstract void threadDestroy(Env env) throws APIException; + /** + * Parallel to threadPrestart, threadDestroy tells the implementor that the + * service is ending this particular thread, and to take this opportunity to + * close out any content specific to this thread that can be closed. + * + * @param env + * @throws APIException + */ + public abstract void threadDestroy(Env env) throws APIException; - /** - * Parallel to servicePrestart, serviceDestroy tells the implementor that - * the service is ending, and to take this opportunity to close out any - * content under it's control that can or should be closed explicitly. - */ - public abstract void serviceDestroy(Env env) throws APIException; + /** + * Parallel to servicePrestart, serviceDestroy tells the implementor that + * the service is ending, and to take this opportunity to close out any + * content under it's control that can or should be closed explicitly. + */ + public abstract void serviceDestroy(Env env) throws APIException; } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/LogTarget.java b/misc/env/src/main/java/org/onap/aaf/misc/env/LogTarget.java index 8915becf..aa74edc9 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/LogTarget.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/LogTarget.java @@ -32,7 +32,7 @@ import org.onap.aaf.misc.env.util.Chrono; * Implement for any Logging Library of your choice, and for any logging string Format desired. * * Included are several Static Implementations for various uses: - * NULL: Does nothing with Logging Messages + * NULL: Does nothing with Logging Messages * SYSOUT: Writes messages in general form to System Out * SYSERR: Writes messages in general form to System Err * @@ -40,103 +40,103 @@ import org.onap.aaf.misc.env.util.Chrono; * */ public interface LogTarget { - public abstract void log(Object... msgs); - public abstract void log(Throwable e, Object ... msgs); - public abstract boolean isLoggable(); - public abstract void printf(String fmt, Object ... vars); - - // A Convenient LogTarget to insert when a NO-OP is desired. - public static final LogTarget NULL = new LogTarget() { - public void log(Object ... msgs) { - } - - public void log(Throwable t, Object ... msgs) { - } - - public boolean isLoggable() { - return false; - } - - @Override - public void printf(String fmt, Object ... vars) { - } - }; - - // A Convenient LogTarget to write to the Console - public static final LogTarget SYSOUT = new LogTarget() { - public void log(Object ... msgs) { - PrintStream out = System.out; - out.print(org.onap.aaf.misc.env.util.Chrono.dateFmt.format(new Date())); - out.print(": "); - for(Object str : msgs) { - if(str!=null) { - out.print(str.toString()); - out.print(' '); - } else { - out.print("null "); - } - } - out.println(); - } - - public void log(Throwable t, Object ... msgs) { - PrintStream out = System.out; - out.print(Chrono.dateFmt.format(new Date())); - out.print(": "); - for(Object str : msgs) { - out.print(str.toString()); - out.print(' '); - } - out.println(); - t.printStackTrace(out); - out.println(); - } - - public boolean isLoggable() { - return true; - } - - @Override - public void printf(String fmt, Object ... vars) { - log(String.format(fmt,vars)); - } - }; - - // A Convenient LogTarget to write to the Console - public static final LogTarget SYSERR = new LogTarget() { - public void log(Object ... msgs) { - PrintStream out = System.err; - out.print(Chrono.dateFmt.format(new Date())); - out.print(": "); - for(Object str : msgs) { - out.print(str.toString()); - out.print(' '); - } - out.println(); - out.flush(); - } - - public void log(Throwable t, Object ... msgs) { - PrintStream out = System.err; - out.print(Chrono.dateFmt.format(new Date())); - out.print(": "); - for(Object str : msgs) { - out.print(str.toString()); - out.print(' '); - } - out.println(); - t.printStackTrace(out); - } - - public boolean isLoggable() { - return true; - } - @Override - public void printf(String fmt, Object ... vars) { - log(String.format(fmt,vars)); - } - - }; + public abstract void log(Object... msgs); + public abstract void log(Throwable e, Object ... msgs); + public abstract boolean isLoggable(); + public abstract void printf(String fmt, Object ... vars); + + // A Convenient LogTarget to insert when a NO-OP is desired. + public static final LogTarget NULL = new LogTarget() { + public void log(Object ... msgs) { + } + + public void log(Throwable t, Object ... msgs) { + } + + public boolean isLoggable() { + return false; + } + + @Override + public void printf(String fmt, Object ... vars) { + } + }; + + // A Convenient LogTarget to write to the Console + public static final LogTarget SYSOUT = new LogTarget() { + public void log(Object ... msgs) { + PrintStream out = System.out; + out.print(org.onap.aaf.misc.env.util.Chrono.dateFmt.format(new Date())); + out.print(": "); + for(Object str : msgs) { + if(str!=null) { + out.print(str.toString()); + out.print(' '); + } else { + out.print("null "); + } + } + out.println(); + } + + public void log(Throwable t, Object ... msgs) { + PrintStream out = System.out; + out.print(Chrono.dateFmt.format(new Date())); + out.print(": "); + for(Object str : msgs) { + out.print(str.toString()); + out.print(' '); + } + out.println(); + t.printStackTrace(out); + out.println(); + } + + public boolean isLoggable() { + return true; + } + + @Override + public void printf(String fmt, Object ... vars) { + log(String.format(fmt,vars)); + } + }; + + // A Convenient LogTarget to write to the Console + public static final LogTarget SYSERR = new LogTarget() { + public void log(Object ... msgs) { + PrintStream out = System.err; + out.print(Chrono.dateFmt.format(new Date())); + out.print(": "); + for(Object str : msgs) { + out.print(str.toString()); + out.print(' '); + } + out.println(); + out.flush(); + } + + public void log(Throwable t, Object ... msgs) { + PrintStream out = System.err; + out.print(Chrono.dateFmt.format(new Date())); + out.print(": "); + for(Object str : msgs) { + out.print(str.toString()); + out.print(' '); + } + out.println(); + t.printStackTrace(out); + } + + public boolean isLoggable() { + return true; + } + @Override + public void printf(String fmt, Object ... vars) { + log(String.format(fmt,vars)); + } + + }; }; \ No newline at end of file diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/Objectifier.java b/misc/env/src/main/java/org/onap/aaf/misc/env/Objectifier.java index 039855e1..30c9c1da 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/Objectifier.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/Objectifier.java @@ -32,26 +32,26 @@ package org.onap.aaf.misc.env; * the creation of an uninitialized object. */ public interface Objectifier extends LifeCycle { - /** - * Marshal to Object T from a String, using contents from Env as necessary.

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return T - * @throws APIException - */ - public abstract T objectify(Env env, String input) throws APIException; + /** + * Marshal to Object T from a String, using contents from Env as necessary.

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return T + * @throws APIException + */ + public abstract T objectify(Env env, String input) throws APIException; - /** - * Create a new object of type T. This is often more efficiently done with - * the underlying XML (or other) Library. - * @return T - * @throws APIException - */ - public abstract T newInstance() throws APIException; + /** + * Create a new object of type T. This is often more efficiently done with + * the underlying XML (or other) Library. + * @return T + * @throws APIException + */ + public abstract T newInstance() throws APIException; - + } \ No newline at end of file diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/Slot.java b/misc/env/src/main/java/org/onap/aaf/misc/env/Slot.java index f79d12d4..33a65752 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/Slot.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/Slot.java @@ -40,63 +40,63 @@ package org.onap.aaf.misc.env; * Slot's are used to store and retrieve data in the transaction's State object. */ public final class Slot { - - /* - * The name of the Slot. - */ - private final String key; - - /* - * The index of the State's local map associated with this Slot. - */ - final int slot; - - /** - * Constructs a new Slot. - * - * @param index - * The index of State's local map this Slot is associated with. - * @param name - * The name of the Slot's key. - */ - Slot(int index, String name) { - slot = index; - key = name; - } - - /** - * Debug method only to print key=slot pairs. - */ - public String toString() { - return key + '=' + slot; - } - - /** - * Returns the name of this Slot's key. - * - * @return - * The name of this Slot's key. - */ - public String getKey() { - return key; - } - - /** - * Put an Object into the slot on the State - * @param state - * @param obj - */ - public void put(Object[] state, Object obj) { - state[slot]=obj; - } + + /* + * The name of the Slot. + */ + private final String key; + + /* + * The index of the State's local map associated with this Slot. + */ + final int slot; + + /** + * Constructs a new Slot. + * + * @param index + * The index of State's local map this Slot is associated with. + * @param name + * The name of the Slot's key. + */ + Slot(int index, String name) { + slot = index; + key = name; + } + + /** + * Debug method only to print key=slot pairs. + */ + public String toString() { + return key + '=' + slot; + } + + /** + * Returns the name of this Slot's key. + * + * @return + * The name of this Slot's key. + */ + public String getKey() { + return key; + } + + /** + * Put an Object into the slot on the State + * @param state + * @param obj + */ + public void put(Object[] state, Object obj) { + state[slot]=obj; + } - /** - * Get an Object from the slot on the State - * @param state - * @param obj - */ - public Object get(Object[] state) { - return state[slot]; - } + /** + * Get an Object from the slot on the State + * @param state + * @param obj + */ + public Object get(Object[] state) { + return state[slot]; + } } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/StaticSlot.java b/misc/env/src/main/java/org/onap/aaf/misc/env/StaticSlot.java index 35bad1ba..0bff6a06 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/StaticSlot.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/StaticSlot.java @@ -41,45 +41,45 @@ package org.onap.aaf.misc.env; */ public final class StaticSlot { - /* - * The name of the StaticSlot. - */ - private final String key; - - /* - * The index of the Organizer's static map associated with this StaticSlot. - */ - final int slot; - - /** - * Constructs a new StaticSlot. - * - * @param index - * The index of Organizer's static map this StaticSlot is associated with. - * @param name - * The name of the StaticSlot's key. - */ - StaticSlot(int index, String name) { - slot = index; - key = name; - } - - /** - * Debug method only to print key=slot pairs. - */ - public String toString() { - return key + '=' + slot; - } - - /** - * Returns the name of this StaticSlot's key. - * - * @return - * The name of this StaticSlot's key. - */ - public String getKey() { - return key; - } + /* + * The name of the StaticSlot. + */ + private final String key; + + /* + * The index of the Organizer's static map associated with this StaticSlot. + */ + final int slot; + + /** + * Constructs a new StaticSlot. + * + * @param index + * The index of Organizer's static map this StaticSlot is associated with. + * @param name + * The name of the StaticSlot's key. + */ + StaticSlot(int index, String name) { + slot = index; + key = name; + } + + /** + * Debug method only to print key=slot pairs. + */ + public String toString() { + return key + '=' + slot; + } + + /** + * Returns the name of this StaticSlot's key. + * + * @return + * The name of this StaticSlot's key. + */ + public String getKey() { + return key; + } } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/Store.java b/misc/env/src/main/java/org/onap/aaf/misc/env/Store.java index 43f5f521..8c810783 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/Store.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/Store.java @@ -24,85 +24,85 @@ package org.onap.aaf.misc.env; import java.util.List; public interface Store { - /** - * Returns the Slot assigned to the supplied name. - * - * @param name - * The name of the Slot to acquire. - * @return - * The Slot associated with the supplied name. - */ - public abstract Slot slot(String name); + /** + * Returns the Slot assigned to the supplied name. + * + * @param name + * The name of the Slot to acquire. + * @return + * The Slot associated with the supplied name. + */ + public abstract Slot slot(String name); - /** - * Returns the existing Slot associated with the supplied name, or null if it doesn't exist. - * - * @param name - * The name of the Slot to get. - * @return - * The Slot assigned to the supplied name, or null if it doesn't exist. - * - */ - public abstract Slot existingSlot(String name); + /** + * Returns the existing Slot associated with the supplied name, or null if it doesn't exist. + * + * @param name + * The name of the Slot to get. + * @return + * The Slot assigned to the supplied name, or null if it doesn't exist. + * + */ + public abstract Slot existingSlot(String name); - /** - * Returns the names used while creating Slots in a List - * - * @return - */ - public abstract List existingSlotNames(); + /** + * Returns the names used while creating Slots in a List + * + * @return + */ + public abstract List existingSlotNames(); - /** - * Returns the StaticSlot assigned to the supplied name. - * - * @param name - * The name of the StaticSlot to acquire. - * @return - * The StaticSlot associated with the supplied name. - */ - public abstract StaticSlot staticSlot(String name); + /** + * Returns the StaticSlot assigned to the supplied name. + * + * @param name + * The name of the StaticSlot to acquire. + * @return + * The StaticSlot associated with the supplied name. + */ + public abstract StaticSlot staticSlot(String name); - /** - * Returns the names used while creating Static Slots in a List - * - * @return - */ - public abstract List existingStaticSlotNames(); - - /** - * Store the supplied value in the StaticSlot of the Organizer's static state. - * - * @param slot - * The StaticSlot used to store the object. - * @param value - * The object to store. - */ - public abstract void put(StaticSlot slot, Object value); + /** + * Returns the names used while creating Static Slots in a List + * + * @return + */ + public abstract List existingStaticSlotNames(); + + /** + * Store the supplied value in the StaticSlot of the Organizer's static state. + * + * @param slot + * The StaticSlot used to store the object. + * @param value + * The object to store. + */ + public abstract void put(StaticSlot slot, Object value); - /** - * Returns an Object from the Organizer's static state, or the Default if null - * - * @param slot - * The StaticSlot to retrieve the data from. - * @return - * The Object located in the supplied StaticSlot of the Organizer's static state. - */ - public abstract T get(StaticSlot slot, T dflt); + /** + * Returns an Object from the Organizer's static state, or the Default if null + * + * @param slot + * The StaticSlot to retrieve the data from. + * @return + * The Object located in the supplied StaticSlot of the Organizer's static state. + */ + public abstract T get(StaticSlot slot, T dflt); - /** - * Returns an Object from the Organizer's static state - * - * @param slot - * The StaticSlot to retrieve the data from. - * @return - * The Object located in the supplied StaticSlot of the Organizer's static state. - */ - public abstract T get(StaticSlot slot); + /** + * Returns an Object from the Organizer's static state + * + * @param slot + * The StaticSlot to retrieve the data from. + * @return + * The Object located in the supplied StaticSlot of the Organizer's static state. + */ + public abstract T get(StaticSlot slot); -// /** -// * Transfer (targeted) Args to Slots -// * -// * Transfer Strings with format "tag=value" into Static Slots -// */ -// public abstract void transfer(String args[], String ... tagss); +// /** +// * Transfer (targeted) Args to Slots +// * +// * Transfer Strings with format "tag=value" into Static Slots +// */ +// public abstract void transfer(String args[], String ... tagss); } \ No newline at end of file diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/StoreImpl.java b/misc/env/src/main/java/org/onap/aaf/misc/env/StoreImpl.java index 685bfb6e..b8a8e03a 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/StoreImpl.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/StoreImpl.java @@ -36,205 +36,205 @@ import java.util.Properties; public class StoreImpl implements Store { - /* - * The re-adjustment factor for growing the Static State array. - */ - private static final int growSize = 10; - - /* - * The index reference for Slot assignment. - */ - private int local; - - /* - * The index reference for StaticSlot assignment. - */ - private int stat; - - /* - * The name/slot map for local (transaction specific) State. - */ - private HashMap localMap; - - /* - * The name/slot map for Static State. - */ - private HashMap staticMap; - - private Object[] staticState; - - public StoreImpl() { - staticState = new Object[growSize]; - staticMap = new HashMap<>(); - localMap = new HashMap<>(); - } - - public StoreImpl(String tag) { - staticState = new Object[growSize]; - staticMap = new HashMap<>(); - localMap = new HashMap<>(); - } - - - public StoreImpl(String tag, String[] args) { - staticState = new Object[growSize]; - staticMap = new HashMap<>(); - localMap = new HashMap<>(); - - if(tag!=null) { - String tequals = tag + '='; - for(String arg : args) { - if(arg.startsWith(tequals) && !arg.equals(tequals)) { // needs to have something after = - Properties props = new Properties(); - for(String f : Split.split(File.pathSeparatorChar,arg.substring(tequals.length()))) { - moreProps(new File(f),props); - } - for(Entry es : props.entrySet()) { - put(staticSlot(es.getKey().toString()),es.getValue()); - } - } - } - } - - // Make sure properties on command line override those in Props - propsFromArgs(tag,args); - } - - public StoreImpl(String tag, Properties props) { - staticState = new Object[growSize]; - staticMap = new HashMap<>(); - localMap = new HashMap<>(); - - if(tag!=null) { - String fname = props.getProperty(tag); - if(fname!=null) { - for(String f : Split.split(File.pathSeparatorChar,fname)) { - if(!moreProps(new File(f),props)) { - System.err.println("Unable to load Properties from " + f); - } - } - } - } - - for(Entry es : props.entrySet()) { - put(staticSlot(es.getKey().toString()),es.getValue()); - } - } - - public void propsFromArgs(String tag, String[] args) { - if(tag!=null) { - for(String arg : args) { - String sarg[] = Split.split('=',arg); - if(sarg.length==2) { - if(tag.equals(sarg[0])) { - for(String fname : Split.split(File.pathSeparatorChar,sarg[1])) { - moreProps(new File(fname),null /* no target */); - } - } - put(staticSlot(sarg[0]),sarg[1]); - } - } - } - } - - private boolean moreProps(File f, Properties target) { - if(f.exists()) { - Properties props = new Properties(); - try { - FileInputStream fis = new FileInputStream(f); - try { - props.load(fis); - if(target!=null) { - target.load(fis); - } - } finally { - fis.close(); - } - } catch(IOException e) { - System.err.println(e); - } - for(Entry es : props.entrySet()) { - put(staticSlot(es.getKey().toString()),es.getValue()); - } - return true; - } else { - return false; - } - } - - public Object[] newTransState() { - return new Object[local]; - } - - /* (non-Javadoc) - * @see com.att.env.Store#slot(java.lang.String) - */ - public synchronized Slot slot(String name) { - name = name == null ? "" : name.trim(); - Slot slot = localMap.get(name); - if (slot == null) { - slot = new Slot(local++, name); - localMap.put(name, slot); - } - return slot; - } - - - /* (non-Javadoc) - * @see com.att.env.Store#existingSlot(java.lang.String) - */ - public Slot existingSlot(String name) { - return localMap.get(name); - } - - /* (non-Javadoc) - * @see com.att.env.Store#existingSlotNames() - */ - public List existingSlotNames() { - return new ArrayList<>(localMap.keySet()); - } - - /* (non-Javadoc) - * @see com.att.env.Store#staticSlot(java.lang.String) - */ - public synchronized StaticSlot staticSlot(String name) { - name = name == null ? "" : name.trim(); - StaticSlot slot = staticMap.get(name); - if (slot == null) { - if (stat%growSize == 0) { - Object[] temp = staticState; - staticState = new Object[temp.length+growSize]; - System.arraycopy(temp, 0, staticState, 0, temp.length); - } - slot = new StaticSlot(stat++, name); - staticMap.put(name, slot); - } - return slot; - } - - /* (non-Javadoc) - * @see com.att.env.Store#put(com.att.env.StaticSlot, java.lang.Object) - */ - public void put(StaticSlot slot, Object value) { - staticState[slot.slot] = value; - } - - /* (non-Javadoc) - * @see com.att.env.Store#get(com.att.env.StaticSlot T defaultObject) - */ - @SuppressWarnings("unchecked") - public T get(StaticSlot sslot,T dflt) { - T t = (T)staticState[sslot.slot]; - return t==null?dflt:t; - } - - @SuppressWarnings("unchecked") - public T get(StaticSlot sslot) { - return (T)staticState[sslot.slot]; - } - - public List existingStaticSlotNames() { - return new ArrayList<>(staticMap.keySet()); - } + /* + * The re-adjustment factor for growing the Static State array. + */ + private static final int growSize = 10; + + /* + * The index reference for Slot assignment. + */ + private int local; + + /* + * The index reference for StaticSlot assignment. + */ + private int stat; + + /* + * The name/slot map for local (transaction specific) State. + */ + private HashMap localMap; + + /* + * The name/slot map for Static State. + */ + private HashMap staticMap; + + private Object[] staticState; + + public StoreImpl() { + staticState = new Object[growSize]; + staticMap = new HashMap<>(); + localMap = new HashMap<>(); + } + + public StoreImpl(String tag) { + staticState = new Object[growSize]; + staticMap = new HashMap<>(); + localMap = new HashMap<>(); + } + + + public StoreImpl(String tag, String[] args) { + staticState = new Object[growSize]; + staticMap = new HashMap<>(); + localMap = new HashMap<>(); + + if(tag!=null) { + String tequals = tag + '='; + for(String arg : args) { + if(arg.startsWith(tequals) && !arg.equals(tequals)) { // needs to have something after = + Properties props = new Properties(); + for(String f : Split.split(File.pathSeparatorChar,arg.substring(tequals.length()))) { + moreProps(new File(f),props); + } + for(Entry es : props.entrySet()) { + put(staticSlot(es.getKey().toString()),es.getValue()); + } + } + } + } + + // Make sure properties on command line override those in Props + propsFromArgs(tag,args); + } + + public StoreImpl(String tag, Properties props) { + staticState = new Object[growSize]; + staticMap = new HashMap<>(); + localMap = new HashMap<>(); + + if(tag!=null) { + String fname = props.getProperty(tag); + if(fname!=null) { + for(String f : Split.split(File.pathSeparatorChar,fname)) { + if(!moreProps(new File(f),props)) { + System.err.println("Unable to load Properties from " + f); + } + } + } + } + + for(Entry es : props.entrySet()) { + put(staticSlot(es.getKey().toString()),es.getValue()); + } + } + + public void propsFromArgs(String tag, String[] args) { + if(tag!=null) { + for(String arg : args) { + String sarg[] = Split.split('=',arg); + if(sarg.length==2) { + if(tag.equals(sarg[0])) { + for(String fname : Split.split(File.pathSeparatorChar,sarg[1])) { + moreProps(new File(fname),null /* no target */); + } + } + put(staticSlot(sarg[0]),sarg[1]); + } + } + } + } + + private boolean moreProps(File f, Properties target) { + if(f.exists()) { + Properties props = new Properties(); + try { + FileInputStream fis = new FileInputStream(f); + try { + props.load(fis); + if(target!=null) { + target.load(fis); + } + } finally { + fis.close(); + } + } catch(IOException e) { + System.err.println(e); + } + for(Entry es : props.entrySet()) { + put(staticSlot(es.getKey().toString()),es.getValue()); + } + return true; + } else { + return false; + } + } + + public Object[] newTransState() { + return new Object[local]; + } + + /* (non-Javadoc) + * @see com.att.env.Store#slot(java.lang.String) + */ + public synchronized Slot slot(String name) { + name = name == null ? "" : name.trim(); + Slot slot = localMap.get(name); + if (slot == null) { + slot = new Slot(local++, name); + localMap.put(name, slot); + } + return slot; + } + + + /* (non-Javadoc) + * @see com.att.env.Store#existingSlot(java.lang.String) + */ + public Slot existingSlot(String name) { + return localMap.get(name); + } + + /* (non-Javadoc) + * @see com.att.env.Store#existingSlotNames() + */ + public List existingSlotNames() { + return new ArrayList<>(localMap.keySet()); + } + + /* (non-Javadoc) + * @see com.att.env.Store#staticSlot(java.lang.String) + */ + public synchronized StaticSlot staticSlot(String name) { + name = name == null ? "" : name.trim(); + StaticSlot slot = staticMap.get(name); + if (slot == null) { + if (stat%growSize == 0) { + Object[] temp = staticState; + staticState = new Object[temp.length+growSize]; + System.arraycopy(temp, 0, staticState, 0, temp.length); + } + slot = new StaticSlot(stat++, name); + staticMap.put(name, slot); + } + return slot; + } + + /* (non-Javadoc) + * @see com.att.env.Store#put(com.att.env.StaticSlot, java.lang.Object) + */ + public void put(StaticSlot slot, Object value) { + staticState[slot.slot] = value; + } + + /* (non-Javadoc) + * @see com.att.env.Store#get(com.att.env.StaticSlot T defaultObject) + */ + @SuppressWarnings("unchecked") + public T get(StaticSlot sslot,T dflt) { + T t = (T)staticState[sslot.slot]; + return t==null?dflt:t; + } + + @SuppressWarnings("unchecked") + public T get(StaticSlot sslot) { + return (T)staticState[sslot.slot]; + } + + public List existingStaticSlotNames() { + return new ArrayList<>(staticMap.keySet()); + } } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/Stringifier.java b/misc/env/src/main/java/org/onap/aaf/misc/env/Stringifier.java index c6e0dbd1..293d7c15 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/Stringifier.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/Stringifier.java @@ -28,18 +28,18 @@ package org.onap.aaf.misc.env; * Stringifier abstracts the marshaling of a String to an Object */ public interface Stringifier extends LifeCycle { - - /** - * Marshal from a String to an Object T, using contents from Env as necessary.

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return String - * @throws APIException - */ - public abstract String stringify(Env env, T input, boolean ... options) throws APIException; - + + /** + * Marshal from a String to an Object T, using contents from Env as necessary.

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return String + * @throws APIException + */ + public abstract String stringify(Env env, T input, boolean ... options) throws APIException; + } \ No newline at end of file diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/TimeTaken.java b/misc/env/src/main/java/org/onap/aaf/misc/env/TimeTaken.java index 78f4a617..02018707 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/TimeTaken.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/TimeTaken.java @@ -35,82 +35,82 @@ package org.onap.aaf.misc.env; * */ public abstract class TimeTaken { - public final long start; - protected long end, size; - public final int flag; - public final String name; - - /** - * The name is as it will appear when written to output (abstract method) - * - * The flag is an integer which can be System type (XML, REMOTE, etc), or End User defined for reporting purposes - * - * @param name - * @param flag - */ - public TimeTaken(String name, int flag) { - start = System.nanoTime(); - this.flag = flag; - this.name = name; - size = -1; - } + public final long start; + protected long end, size; + public final int flag; + public final String name; + + /** + * The name is as it will appear when written to output (abstract method) + * + * The flag is an integer which can be System type (XML, REMOTE, etc), or End User defined for reporting purposes + * + * @param name + * @param flag + */ + public TimeTaken(String name, int flag) { + start = System.nanoTime(); + this.flag = flag; + this.name = name; + size = -1; + } - /** - * Call this when process is done to state ending time.

- * - * It is exceedingly prudent to wrap the process called with a try-finally:

- * - *

-	 *   TimeTaken tt = env.startSubTime();
-	 *   try {
-	 *       process.me(); // code to be timed.
-	 *   } finally {
-	 *   	 tt.done();
-	 *   }
-	 * 
- */ - public void done() { - end = System.nanoTime(); - } - - - /** - * For sizable contents, set the size. Implementations can simply write a no-op if they don't wish to - * store the size. - * - * @param size - */ - public void size(long theSize) { - size = theSize; - } - - /** - * Give readonly access to End, which isn't final - * @return - */ - public long end() { - return end; - } - - /** - * Time is taken in NanoSeconds. This method converts to decimals of Milliseconds - * @return - */ - public float millis() { - return (end-start)/1000000f; - } - /** - * Write self to a String Builder (for making Audits) - * @param sb - */ - public abstract void output(StringBuilder sb); - - /** - * For Debugging - */ - public String toString() { - return name + ' ' + millis() + "ms " + (size>0?Long.toString(size):""); - } - -} + /** + * Call this when process is done to state ending time.

+ * + * It is exceedingly prudent to wrap the process called with a try-finally:

+ * + *

+     *   TimeTaken tt = env.startSubTime();
+     *   try {
+     *       process.me(); // code to be timed.
+     *   } finally {
+     *        tt.done();
+     *   }
+     * 
+ */ + public void done() { + end = System.nanoTime(); + } + + + /** + * For sizable contents, set the size. Implementations can simply write a no-op if they don't wish to + * store the size. + * + * @param size + */ + public void size(long theSize) { + size = theSize; + } + + /** + * Give readonly access to End, which isn't final + * @return + */ + public long end() { + return end; + } + + /** + * Time is taken in NanoSeconds. This method converts to decimals of Milliseconds + * @return + */ + public float millis() { + return (end-start)/1000000f; + } + /** + * Write self to a String Builder (for making Audits) + * @param sb + */ + public abstract void output(StringBuilder sb); + + /** + * For Debugging + */ + public String toString() { + return name + ' ' + millis() + "ms " + (size>0?Long.toString(size):""); + } + +} diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/Trans.java b/misc/env/src/main/java/org/onap/aaf/misc/env/Trans.java index 24473751..bb66c0f6 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/Trans.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/Trans.java @@ -39,36 +39,36 @@ package org.onap.aaf.misc.env; * */ public interface Trans extends Env { - /** - * Add a completed entry in the Audit Trail for tracking purposes. - * - * @param text - */ - public void checkpoint(String text); + /** + * Add a completed entry in the Audit Trail for tracking purposes. + * + * @param text + */ + public void checkpoint(String text); - /** - * Add a completed entry in the Audit Trail for tracking purposes, and combine flag with "CHECKPOINT" - * - * @param text - */ - public void checkpoint(String text, int additionalFlag); + /** + * Add a completed entry in the Audit Trail for tracking purposes, and combine flag with "CHECKPOINT" + * + * @param text + */ + public void checkpoint(String text, int additionalFlag); - /** - * Output an Audit Trail onto the StringBuilder - * - * Load metrics into an array of floats from passed in Flags - * - * @param flag - * @param sb - * @return - */ - public Metric auditTrail(LogTarget lt, int indent, StringBuilder sb, int ... flag); + /** + * Output an Audit Trail onto the StringBuilder + * + * Load metrics into an array of floats from passed in Flags + * + * @param flag + * @param sb + * @return + */ + public Metric auditTrail(LogTarget lt, int indent, StringBuilder sb, int ... flag); - public Metric auditTrail(int indent, StringBuilder sb, int ... flag); + public Metric auditTrail(int indent, StringBuilder sb, int ... flag); - public class Metric { - public float[] buckets; - public float total; - public int entries; - } + public class Metric { + public float[] buckets; + public float total; + public int entries; + } } \ No newline at end of file diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/TransCreate.java b/misc/env/src/main/java/org/onap/aaf/misc/env/TransCreate.java index 1ed4dcd2..d311c3ed 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/TransCreate.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/TransCreate.java @@ -22,5 +22,5 @@ package org.onap.aaf.misc.env; public interface TransCreate { - public TRANS newTrans(); + public TRANS newTrans(); } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/TransStore.java b/misc/env/src/main/java/org/onap/aaf/misc/env/TransStore.java index e9c1b390..5a8f7620 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/TransStore.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/TransStore.java @@ -22,36 +22,36 @@ package org.onap.aaf.misc.env; public interface TransStore extends Trans { - /** - * Returns the Slot assigned to the supplied name. - * - * @param name - * The name of the Slot to acquire. - * @return - * The Slot associated with the supplied name. - */ - public abstract Slot slot(String name); - - /** - * Put data into the right slot - */ - public void put(Slot slot, Object value); + /** + * Returns the Slot assigned to the supplied name. + * + * @param name + * The name of the Slot to acquire. + * @return + * The Slot associated with the supplied name. + */ + public abstract Slot slot(String name); + + /** + * Put data into the right slot + */ + public void put(Slot slot, Object value); - /** - * Get data from the right slot - * - * This will do a cast to the expected type derived from Default - */ - public T get(Slot slot, T deflt); + /** + * Get data from the right slot + * + * This will do a cast to the expected type derived from Default + */ + public T get(Slot slot, T deflt); - /** - * Returns an Object from the Organizer's static state, or the Default if null - * - * @param slot - * The StaticSlot to retrieve the data from. - * @return - * The Object located in the supplied StaticSlot of the Organizer's static state. - */ - public abstract T get(StaticSlot slot, T dflt); - + /** + * Returns an Object from the Organizer's static state, or the Default if null + * + * @param slot + * The StaticSlot to retrieve the data from. + * @return + * The Object located in the supplied StaticSlot of the Organizer's static state. + */ + public abstract T get(StaticSlot slot, T dflt); + } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/AbsTrans.java b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/AbsTrans.java index e378e2c3..b86b4fbb 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/AbsTrans.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/AbsTrans.java @@ -33,182 +33,182 @@ import org.onap.aaf.misc.env.TimeTaken; import org.onap.aaf.misc.env.TransStore; public abstract class AbsTrans implements TransStore { - private static final float[] EMPTYF = new float[0]; - private static final Object[] EMPTYO = new Object[0]; - - protected ENV delegate; - protected List trail = new ArrayList<>(30); - private Object[] state; - - + private static final float[] EMPTYF = new float[0]; + private static final Object[] EMPTYO = new Object[0]; + + protected ENV delegate; + protected List trail = new ArrayList<>(30); + private Object[] state; + + public AbsTrans(ENV delegate) { - this.delegate = delegate; - state = delegate instanceof StoreImpl?((StoreImpl) delegate).newTransState():EMPTYO; - } - - // @Override - public LogTarget fatal() { - return delegate.fatal(); - } - -// @Override - public LogTarget error() { - return delegate.error(); - } - -// @Override - public LogTarget audit() { - return delegate.audit(); - } - -// @Override - public LogTarget init() { - return delegate.init(); - } - -// @Override - public LogTarget warn() { - return delegate.warn(); - } - -// @Override - public LogTarget info() { - return delegate.info(); - } - -// @Override - public LogTarget debug() { - return delegate.debug(); - } - -// @Override - public LogTarget trace() { - return delegate.trace(); - } - - /** - * Let the final Trans Implementation choose the exact kind of TimeTaken to use - * @param name - * @param flag - * @return - */ - protected abstract TimeTaken newTimeTaken(String name, int flag); - -// @Override - public final TimeTaken start(String name, int flag) { - TimeTaken tt = newTimeTaken(name,flag); - trail.add(tt); - return tt; - } - -// @Override - public final void checkpoint(String name) { - TimeTaken tt = newTimeTaken(name,CHECKPOINT); - tt.done(); - trail.add(tt); - } - - public final void checkpoint(String name, int additionalFlag) { - TimeTaken tt = newTimeTaken(name,CHECKPOINT|additionalFlag); - trail.add(tt); - tt.done(); - } - - @Override - public Metric auditTrail(int indent, StringBuilder sb, int ... flags) { - return auditTrail(info(),indent,sb,flags); - } - - @Override - public Metric auditTrail(LogTarget lt, int indent, StringBuilder sb, int ... flags) { - Metric metric = new Metric(); - int last = (metric.entries = trail.size()) -1; - metric.buckets = flags.length==0?EMPTYF:new float[flags.length]; - if(last>=0) { - TimeTaken first = trail.get(0); - // If first entry is sub, then it's actually the last "end" as well - // otherwise, check end - //long end = (first.flag&SUB)==SUB?first.end():trail.get(last).end(); - long end = trail.get(last).end(); - metric.total = (end - first.start) / 1000000f; - } - - if(sb==null) { - for(TimeTaken tt : trail) { - float ms = tt.millis(); - for(int i=0;i stack = new Stack(); - for(TimeTaken tt : trail) { - // Create Indentation based on SUB - while(!stack.isEmpty() && tt.end()>stack.peek()) { - --indent; - stack.pop(); - } - for(int i=0;i T get(Slot slot, T deflt) { - Object o; - try { - o = slot.get(state); - } catch(ArrayIndexOutOfBoundsException e) { - // Env State Size has changed because of dynamic Object creation... Rare event, but needs to be covered - Object[] temp = ((StoreImpl) delegate).newTransState(); - System.arraycopy(state, 0, temp, 0, state.length); - state = temp; - o=null; - } - return o==null?deflt:(T)o; - } + this.delegate = delegate; + state = delegate instanceof StoreImpl?((StoreImpl) delegate).newTransState():EMPTYO; + } + + // @Override + public LogTarget fatal() { + return delegate.fatal(); + } + +// @Override + public LogTarget error() { + return delegate.error(); + } + +// @Override + public LogTarget audit() { + return delegate.audit(); + } + +// @Override + public LogTarget init() { + return delegate.init(); + } + +// @Override + public LogTarget warn() { + return delegate.warn(); + } + +// @Override + public LogTarget info() { + return delegate.info(); + } + +// @Override + public LogTarget debug() { + return delegate.debug(); + } + +// @Override + public LogTarget trace() { + return delegate.trace(); + } + + /** + * Let the final Trans Implementation choose the exact kind of TimeTaken to use + * @param name + * @param flag + * @return + */ + protected abstract TimeTaken newTimeTaken(String name, int flag); + +// @Override + public final TimeTaken start(String name, int flag) { + TimeTaken tt = newTimeTaken(name,flag); + trail.add(tt); + return tt; + } + +// @Override + public final void checkpoint(String name) { + TimeTaken tt = newTimeTaken(name,CHECKPOINT); + tt.done(); + trail.add(tt); + } + + public final void checkpoint(String name, int additionalFlag) { + TimeTaken tt = newTimeTaken(name,CHECKPOINT|additionalFlag); + trail.add(tt); + tt.done(); + } + + @Override + public Metric auditTrail(int indent, StringBuilder sb, int ... flags) { + return auditTrail(info(),indent,sb,flags); + } + + @Override + public Metric auditTrail(LogTarget lt, int indent, StringBuilder sb, int ... flags) { + Metric metric = new Metric(); + int last = (metric.entries = trail.size()) -1; + metric.buckets = flags.length==0?EMPTYF:new float[flags.length]; + if(last>=0) { + TimeTaken first = trail.get(0); + // If first entry is sub, then it's actually the last "end" as well + // otherwise, check end + //long end = (first.flag&SUB)==SUB?first.end():trail.get(last).end(); + long end = trail.get(last).end(); + metric.total = (end - first.start) / 1000000f; + } + + if(sb==null) { + for(TimeTaken tt : trail) { + float ms = tt.millis(); + for(int i=0;i stack = new Stack(); + for(TimeTaken tt : trail) { + // Create Indentation based on SUB + while(!stack.isEmpty() && tt.end()>stack.peek()) { + --indent; + stack.pop(); + } + for(int i=0;i T get(Slot slot, T deflt) { + Object o; + try { + o = slot.get(state); + } catch(ArrayIndexOutOfBoundsException e) { + // Env State Size has changed because of dynamic Object creation... Rare event, but needs to be covered + Object[] temp = ((StoreImpl) delegate).newTransState(); + System.arraycopy(state, 0, temp, 0, state.length); + state = temp; + o=null; + } + return o==null?deflt:(T)o; + } } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/AbsTransJAXB.java b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/AbsTransJAXB.java index c20589a3..5576a1a0 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/AbsTransJAXB.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/AbsTransJAXB.java @@ -30,28 +30,28 @@ import org.onap.aaf.misc.env.EnvJAXB; import org.onap.aaf.misc.env.TransJAXB; public abstract class AbsTransJAXB extends AbsTrans implements TransJAXB { - public AbsTransJAXB(EnvJAXB env) { - super(env); - } - -// @Override - public DataFactory newDataFactory(Class... classes) throws APIException { - return delegate.newDataFactory(classes); - } - -// @Override - public DataFactory newDataFactory(Schema schema, Class... classes) throws APIException { - return delegate.newDataFactory(schema, classes); - } - -// @Override - public DataFactory newDataFactory(QName qName, Class... classes) throws APIException { - return delegate.newDataFactory(qName, classes); - } - -// @Override - public DataFactory newDataFactory(Schema schema, QName qName, Class... classes) throws APIException { - return delegate.newDataFactory(schema, qName, classes); - } + public AbsTransJAXB(EnvJAXB env) { + super(env); + } + +// @Override + public DataFactory newDataFactory(Class... classes) throws APIException { + return delegate.newDataFactory(classes); + } + +// @Override + public DataFactory newDataFactory(Schema schema, Class... classes) throws APIException { + return delegate.newDataFactory(schema, classes); + } + +// @Override + public DataFactory newDataFactory(QName qName, Class... classes) throws APIException { + return delegate.newDataFactory(qName, classes); + } + +// @Override + public DataFactory newDataFactory(Schema schema, QName qName, Class... classes) throws APIException { + return delegate.newDataFactory(schema, qName, classes); + } } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/BasicEnv.java b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/BasicEnv.java index cd62a7e5..94f7d47b 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/BasicEnv.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/BasicEnv.java @@ -57,296 +57,296 @@ import org.onap.aaf.misc.env.util.Split; * */ public class BasicEnv extends StoreImpl implements EnvJAXB, TransCreate{ - protected LogTarget fatal=LogTarget.SYSERR; - protected LogTarget error=LogTarget.SYSERR; - protected LogTarget audit=LogTarget.SYSOUT; - protected LogTarget init=LogTarget.SYSOUT; - protected LogTarget warn=LogTarget.SYSERR; - protected LogTarget info=LogTarget.SYSOUT; - protected LogTarget debug=LogTarget.NULL; - protected LogTarget trace=LogTarget.NULL; -// protected Map props; - -// private boolean sysprops; - - public BasicEnv(String ... args) { - super(null,args); - } - - public BasicEnv(String tag, String[] args) { - super(tag, args); - } - - - /** - * Suitable for use in Applets... obtain all the values - * listed for the variable String arg "tags" - */ - public BasicEnv(Applet applet, String ... tags) { - super(null, tags); -// props = new HashMap<>(); -// String value; -// for(int i=0;i=0) { - sb.append(" size: "); - sb.append(Long.toString(size)); - } - } - } - }; - } - - // @Override - public String getProperty(String key) { - return get(staticSlot(key),null); - } - - public Properties getProperties(String ... filter) { - Properties props = new Properties(); - boolean yes; - for(String key : existingStaticSlotNames()) { - if(filter.length>0) { - yes = false; - for(String f : filter) { - if(key.startsWith(f)) { - yes = true; - break; - } - } - } else { - yes = true; - } - if(yes) { - String value = getProperty(key); - if(value!=null) { - props.put(key, value); - } - } - } - return props; - } - - // @Override - public String getProperty(String key, String defaultValue) { - return get(staticSlot(key),defaultValue); - } - - // @Override - public String setProperty(String key, String value) { - put(staticSlot(key),value==null?null:value.trim()); - return value; - } - - protected Decryptor decryptor = Decryptor.NULL; - protected Encryptor encryptor = Encryptor.NULL; - - - public Decryptor decryptor() { - return decryptor; - } - - public void set(Decryptor newDecryptor) { - decryptor = newDecryptor; - } - - public Encryptor encryptor() { - return encryptor; - } - - public void set(Encryptor newEncryptor) { - encryptor = newEncryptor; - } - - -// @SuppressWarnings("unchecked") - // @Override - public DataFactory newDataFactory(Class... classes) throws APIException { -// if(String.class.isAssignableFrom(classes[0])) -// return (DataFactory) new StringDF(this); - return new JAXBDF(this,classes); - } - -// @SuppressWarnings("unchecked") - // @Override - public DataFactory newDataFactory(Schema schema, Class... classes) throws APIException { -// if(String.class.isAssignableFrom(classes[0])) -// return (DataFactory) new StringDF(this); - return new JAXBDF(this, schema, classes); - } - -// @SuppressWarnings("unchecked") - // @Override - public DataFactory newDataFactory(QName qName, Class ... classes) throws APIException { -// if(String.class.isAssignableFrom(classes[0])) -// return (DataFactory) new StringDF(this); - return new JAXBDF(this, qName, classes); - } - - // @Override - public DataFactory newDataFactory(Schema schema, QName qName, Class ... classes) throws APIException { - return new JAXBDF(this, schema, qName, classes); - } - - // @Override - public BasicTrans newTrans() { - return new BasicTrans(this); - } - - public void loadFromSystemPropsStartsWith(String ... str) { - for(String name : System.getProperties().stringPropertyNames()) { - for(String s : str) { - if(name.startsWith(s)) { - setProperty(name, System.getProperty(name)); - } - } - } - } - - /** - * - * - */ - public void loadToSystemPropsStartsWith(String ... str) { - String value; - for(String name : existingStaticSlotNames()) { - for(String s : str) { - if(name.startsWith(s)) { - if((value = getProperty(name))!=null) - System.setProperty(name,value); - } - } - } - } - - public void loadPropFiles(String tag, ClassLoader classloader) throws IOException { - String propfiles = getProperty(tag); - if(propfiles!=null) { - for(String pf : Split.splitTrim(File.pathSeparatorChar, propfiles)) { - InputStream is = classloader==null?null:classloader.getResourceAsStream(pf); - if(is==null) { - File f = new File(pf); - if(f.exists()) { - is = new FileInputStream(f); - } - } - if(is!=null) { - BufferedReader br = new BufferedReader(new InputStreamReader(is)); - try { - String line; - while((line=br.readLine())!=null) { - line = line.trim(); - if(!line.startsWith("#")) { - String[] tv = Split.splitTrim('=', line); - if(tv.length==2) { - setProperty(tv[0],tv[1]); - } - } - } - } finally { - try { - br.close(); - } catch (IOException e) { - error().log(e); - } - } - } - } - } - } - - /** - * Create a StaticSlot, and load it from existing Properties - * - * @param name - * @param propName - * @return - */ - public synchronized StaticSlot staticSlot(String name, final String propName) { - StaticSlot ss = staticSlot(name); - put(ss,getProperty(propName)); - return ss; - } + protected LogTarget fatal=LogTarget.SYSERR; + protected LogTarget error=LogTarget.SYSERR; + protected LogTarget audit=LogTarget.SYSOUT; + protected LogTarget init=LogTarget.SYSOUT; + protected LogTarget warn=LogTarget.SYSERR; + protected LogTarget info=LogTarget.SYSOUT; + protected LogTarget debug=LogTarget.NULL; + protected LogTarget trace=LogTarget.NULL; +// protected Map props; + +// private boolean sysprops; + + public BasicEnv(String ... args) { + super(null,args); + } + + public BasicEnv(String tag, String[] args) { + super(tag, args); + } + + + /** + * Suitable for use in Applets... obtain all the values + * listed for the variable String arg "tags" + */ + public BasicEnv(Applet applet, String ... tags) { + super(null, tags); +// props = new HashMap<>(); +// String value; +// for(int i=0;i=0) { + sb.append(" size: "); + sb.append(Long.toString(size)); + } + } + } + }; + } + + // @Override + public String getProperty(String key) { + return get(staticSlot(key),null); + } + + public Properties getProperties(String ... filter) { + Properties props = new Properties(); + boolean yes; + for(String key : existingStaticSlotNames()) { + if(filter.length>0) { + yes = false; + for(String f : filter) { + if(key.startsWith(f)) { + yes = true; + break; + } + } + } else { + yes = true; + } + if(yes) { + String value = getProperty(key); + if(value!=null) { + props.put(key, value); + } + } + } + return props; + } + + // @Override + public String getProperty(String key, String defaultValue) { + return get(staticSlot(key),defaultValue); + } + + // @Override + public String setProperty(String key, String value) { + put(staticSlot(key),value==null?null:value.trim()); + return value; + } + + protected Decryptor decryptor = Decryptor.NULL; + protected Encryptor encryptor = Encryptor.NULL; + + + public Decryptor decryptor() { + return decryptor; + } + + public void set(Decryptor newDecryptor) { + decryptor = newDecryptor; + } + + public Encryptor encryptor() { + return encryptor; + } + + public void set(Encryptor newEncryptor) { + encryptor = newEncryptor; + } + + +// @SuppressWarnings("unchecked") + // @Override + public DataFactory newDataFactory(Class... classes) throws APIException { +// if(String.class.isAssignableFrom(classes[0])) +// return (DataFactory) new StringDF(this); + return new JAXBDF(this,classes); + } + +// @SuppressWarnings("unchecked") + // @Override + public DataFactory newDataFactory(Schema schema, Class... classes) throws APIException { +// if(String.class.isAssignableFrom(classes[0])) +// return (DataFactory) new StringDF(this); + return new JAXBDF(this, schema, classes); + } + +// @SuppressWarnings("unchecked") + // @Override + public DataFactory newDataFactory(QName qName, Class ... classes) throws APIException { +// if(String.class.isAssignableFrom(classes[0])) +// return (DataFactory) new StringDF(this); + return new JAXBDF(this, qName, classes); + } + + // @Override + public DataFactory newDataFactory(Schema schema, QName qName, Class ... classes) throws APIException { + return new JAXBDF(this, schema, qName, classes); + } + + // @Override + public BasicTrans newTrans() { + return new BasicTrans(this); + } + + public void loadFromSystemPropsStartsWith(String ... str) { + for(String name : System.getProperties().stringPropertyNames()) { + for(String s : str) { + if(name.startsWith(s)) { + setProperty(name, System.getProperty(name)); + } + } + } + } + + /** + * + * + */ + public void loadToSystemPropsStartsWith(String ... str) { + String value; + for(String name : existingStaticSlotNames()) { + for(String s : str) { + if(name.startsWith(s)) { + if((value = getProperty(name))!=null) + System.setProperty(name,value); + } + } + } + } + + public void loadPropFiles(String tag, ClassLoader classloader) throws IOException { + String propfiles = getProperty(tag); + if(propfiles!=null) { + for(String pf : Split.splitTrim(File.pathSeparatorChar, propfiles)) { + InputStream is = classloader==null?null:classloader.getResourceAsStream(pf); + if(is==null) { + File f = new File(pf); + if(f.exists()) { + is = new FileInputStream(f); + } + } + if(is!=null) { + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + try { + String line; + while((line=br.readLine())!=null) { + line = line.trim(); + if(!line.startsWith("#")) { + String[] tv = Split.splitTrim('=', line); + if(tv.length==2) { + setProperty(tv[0],tv[1]); + } + } + } + } finally { + try { + br.close(); + } catch (IOException e) { + error().log(e); + } + } + } + } + } + } + + /** + * Create a StaticSlot, and load it from existing Properties + * + * @param name + * @param propName + * @return + */ + public synchronized StaticSlot staticSlot(String name, final String propName) { + StaticSlot ss = staticSlot(name); + put(ss,getProperty(propName)); + return ss; + } } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/BasicTrans.java b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/BasicTrans.java index 05e62024..dbda57b5 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/BasicTrans.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/BasicTrans.java @@ -30,52 +30,52 @@ import org.onap.aaf.misc.env.TimeTaken; public class BasicTrans extends AbsTransJAXB { - - public BasicTrans(EnvJAXB env) { - super(env); - } + + public BasicTrans(EnvJAXB env) { + super(env); + } - @Override - protected TimeTaken newTimeTaken(String name, int flag) { - /** - * Note: could have created a different format for Time Taken, but using BasicEnv's instead - */ - return delegate.start(name, flag); - } - - public Slot slot(String name) { - return delegate.slot(name); - } + @Override + protected TimeTaken newTimeTaken(String name, int flag) { + /** + * Note: could have created a different format for Time Taken, but using BasicEnv's instead + */ + return delegate.start(name, flag); + } + + public Slot slot(String name) { + return delegate.slot(name); + } - public T get(StaticSlot slot) { - return delegate.get(slot); - } + public T get(StaticSlot slot) { + return delegate.get(slot); + } - public T get(StaticSlot slot, T dflt) { - return delegate.get(slot,dflt); - } + public T get(StaticSlot slot, T dflt) { + return delegate.get(slot,dflt); + } - public String setProperty(String tag, String value) { - delegate.setProperty(tag, value); - return value; - } + public String setProperty(String tag, String value) { + delegate.setProperty(tag, value); + return value; + } - public String getProperty(String tag) { - return delegate.getProperty(tag); - } + public String getProperty(String tag) { + return delegate.getProperty(tag); + } - public String getProperty(String tag, String deflt) { - return delegate.getProperty(tag, deflt); - } + public String getProperty(String tag, String deflt) { + return delegate.getProperty(tag, deflt); + } - @Override - public Decryptor decryptor() { - return delegate.decryptor(); - } + @Override + public Decryptor decryptor() { + return delegate.decryptor(); + } - @Override - public Encryptor encryptor() { - return delegate.encryptor(); - } + @Override + public Encryptor encryptor() { + return delegate.encryptor(); + } } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/EnvFactory.java b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/EnvFactory.java index 9bf4fdc5..aa0b947a 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/EnvFactory.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/EnvFactory.java @@ -33,36 +33,36 @@ import org.onap.aaf.misc.env.TransJAXB; */ public class EnvFactory { - public static final String SCHEMA_DIR = "env-schema_dir"; - public static final String DEFAULT_SCHEMA_DIR = "src/main/xsd"; - static BasicEnv singleton; + public static final String SCHEMA_DIR = "env-schema_dir"; + public static final String DEFAULT_SCHEMA_DIR = "src/main/xsd"; + static BasicEnv singleton; - static { - singleton = new BasicEnv(); - } - public static BasicEnv singleton() { - return singleton; - } - - public static void setSingleton(BasicEnv be) { - singleton = be; - } - - public static TransJAXB newTrans() { - return new BasicTrans(singleton); - } + static { + singleton = new BasicEnv(); + } + public static BasicEnv singleton() { + return singleton; + } + + public static void setSingleton(BasicEnv be) { + singleton = be; + } + + public static TransJAXB newTrans() { + return new BasicTrans(singleton); + } - public static TransJAXB newTrans(EnvJAXB env) { - return new BasicTrans(env); - } - - public static TransCreate transCreator() { - return new TransCreate() { - // @Override - public BasicTrans newTrans() { - return singleton.newTrans(); - } - }; - } + public static TransJAXB newTrans(EnvJAXB env) { + return new BasicTrans(env); + } + + public static TransCreate transCreator() { + return new TransCreate() { + // @Override + public BasicTrans newTrans() { + return singleton.newTrans(); + } + }; + } } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/JavaUtilLogTarget.java b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/JavaUtilLogTarget.java index ac3e8b45..c8adfc78 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/JavaUtilLogTarget.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/JavaUtilLogTarget.java @@ -36,55 +36,55 @@ import org.onap.aaf.misc.env.LogTarget; * */ public class JavaUtilLogTarget implements LogTarget { - private Level level; - private Logger log; + private Level level; + private Logger log; - public JavaUtilLogTarget(Logger logger, Level theLevel) { - log = logger; - level = theLevel; - } + public JavaUtilLogTarget(Logger logger, Level theLevel) { + log = logger; + level = theLevel; + } - public boolean isLoggable() { - return log.isLoggable(level); - } + public boolean isLoggable() { + return log.isLoggable(level); + } - public void log(Object ... msgs) { - if(log.isLoggable(level)) { - StringBuilder sb = new StringBuilder(); - String msg; - for(int i=0;i0) { - int sbl = sb.length(); - if(sbl>0) { - char last = sb.charAt(sbl-1); - if(" (.".indexOf(last)<0 && "().".indexOf(msg.charAt(0))<0)sb.append(' '); - } - sb.append(msg); - } - } - log.log(level, sb.toString()); - } - } + public void log(Object ... msgs) { + if(log.isLoggable(level)) { + StringBuilder sb = new StringBuilder(); + String msg; + for(int i=0;i0) { + int sbl = sb.length(); + if(sbl>0) { + char last = sb.charAt(sbl-1); + if(" (.".indexOf(last)<0 && "().".indexOf(msg.charAt(0))<0)sb.append(' '); + } + sb.append(msg); + } + } + log.log(level, sb.toString()); + } + } - public void log(Throwable e, Object ... msgs) { - String str = e.getLocalizedMessage(); - if(str==null) { - str = e.getMessage(); - } - if(str==null) { - str = e.getClass().getName(); - } - log.log(level,str,msgs); - } + public void log(Throwable e, Object ... msgs) { + String str = e.getLocalizedMessage(); + if(str==null) { + str = e.getMessage(); + } + if(str==null) { + str = e.getClass().getName(); + } + log.log(level,str,msgs); + } - /* (non-Javadoc) - * @see com.att.inno.env.LogTarget#printf(java.lang.String, java.lang.String[]) - */ - @Override - public void printf(String fmt, Object ... vars) { - if(log.isLoggable(level)) { - log.log(level,String.format(fmt,vars)); - } - } -} + /* (non-Javadoc) + * @see com.att.inno.env.LogTarget#printf(java.lang.String, java.lang.String[]) + */ + @Override + public void printf(String fmt, Object ... vars) { + if(log.isLoggable(level)) { + log.log(level,String.format(fmt,vars)); + } + } +} diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/Log4JLogTarget.java b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/Log4JLogTarget.java index a5f118c9..81d9c1b2 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/Log4JLogTarget.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/Log4JLogTarget.java @@ -37,73 +37,73 @@ import org.onap.aaf.misc.env.util.StringBuilderWriter; * */ public class Log4JLogTarget implements LogTarget { - private Level level; - private Logger log; + private Level level; + private Logger log; - public Log4JLogTarget(String loggerName, Level level) throws APIException { - this.level = level; - if (loggerName != null && loggerName.length() > 0) { - log = Logger.getLogger(loggerName); - } else { - log = Logger.getRootLogger(); - } - } + public Log4JLogTarget(String loggerName, Level level) throws APIException { + this.level = level; + if (loggerName != null && loggerName.length() > 0) { + log = Logger.getLogger(loggerName); + } else { + log = Logger.getRootLogger(); + } + } - // @Override - public boolean isLoggable() { - return log.isEnabledFor(level); - } + // @Override + public boolean isLoggable() { + return log.isEnabledFor(level); + } - // @Override - public void log(Object... msgs) { - log(null, msgs); - } + // @Override + public void log(Object... msgs) { + log(null, msgs); + } - // @Override - public void log(Throwable e, Object... msgs) { - if (log.isEnabledFor(level)) { - StringBuilder sb = new StringBuilder(); - - String msg; - if (e != null) { - e.printStackTrace(new PrintWriter(new StringBuilderWriter(sb))); - } - for (int i = 0; i < msgs.length; ++i) { - if(msgs[i]!=null) { - msg = msgs[i].toString(); - if (msg != null && msg.length() > 0) { - int sbl = sb.length(); - if (sbl > 0) { - char last = sb.charAt(sbl - 1); - if (" (.".indexOf(last) < 0 - && "().".indexOf(msg.charAt(0)) < 0) - sb.append(' '); - } - sb.append(msg); - } - } - } - log.log(level, sb.toString()); - } - } + // @Override + public void log(Throwable e, Object... msgs) { + if (log.isEnabledFor(level)) { + StringBuilder sb = new StringBuilder(); + + String msg; + if (e != null) { + e.printStackTrace(new PrintWriter(new StringBuilderWriter(sb))); + } + for (int i = 0; i < msgs.length; ++i) { + if(msgs[i]!=null) { + msg = msgs[i].toString(); + if (msg != null && msg.length() > 0) { + int sbl = sb.length(); + if (sbl > 0) { + char last = sb.charAt(sbl - 1); + if (" (.".indexOf(last) < 0 + && "().".indexOf(msg.charAt(0)) < 0) + sb.append(' '); + } + sb.append(msg); + } + } + } + log.log(level, sb.toString()); + } + } - /* (non-Javadoc) - * @see com.att.inno.env.LogTarget#printf(java.lang.String, java.lang.String[]) - */ - @Override - public void printf(String fmt, Object ... vars) { - if(log.isEnabledFor(level)) { - log.log(level,String.format(fmt,vars)); - } - } + /* (non-Javadoc) + * @see com.att.inno.env.LogTarget#printf(java.lang.String, java.lang.String[]) + */ + @Override + public void printf(String fmt, Object ... vars) { + if(log.isEnabledFor(level)) { + log.log(level,String.format(fmt,vars)); + } + } - public static void setLog4JEnv(String loggerName, BasicEnv env) throws APIException { - env.fatal = new Log4JLogTarget(loggerName,Level.FATAL); - env.error = new Log4JLogTarget(loggerName,Level.ERROR); - env.warn = env.audit = env.init = new Log4JLogTarget(loggerName,Level.WARN); - env.info = new Log4JLogTarget(loggerName,Level.INFO); - env.debug = new Log4JLogTarget(loggerName,Level.DEBUG); - env.trace = new Log4JLogTarget(loggerName,Level.TRACE); - } - + public static void setLog4JEnv(String loggerName, BasicEnv env) throws APIException { + env.fatal = new Log4JLogTarget(loggerName,Level.FATAL); + env.error = new Log4JLogTarget(loggerName,Level.ERROR); + env.warn = env.audit = env.init = new Log4JLogTarget(loggerName,Level.WARN); + env.info = new Log4JLogTarget(loggerName,Level.INFO); + env.debug = new Log4JLogTarget(loggerName,Level.DEBUG); + env.trace = new Log4JLogTarget(loggerName,Level.TRACE); + } + } \ No newline at end of file diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/NullLifeCycle.java b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/NullLifeCycle.java index 7e41f5df..3184f8c0 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/impl/NullLifeCycle.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/impl/NullLifeCycle.java @@ -51,9 +51,9 @@ import org.onap.aaf.misc.env.LifeCycle; * */ public class NullLifeCycle implements LifeCycle { - public void servicePrestart(Env env) throws APIException {} - public void threadPrestart(Env env) throws APIException {} - public void refresh(Env env) throws APIException {} - public void threadDestroy(Env env) throws APIException {} - public void serviceDestroy(Env env) throws APIException {} + public void servicePrestart(Env env) throws APIException {} + public void threadPrestart(Env env) throws APIException {} + public void refresh(Env env) throws APIException {} + public void threadDestroy(Env env) throws APIException {} + public void serviceDestroy(Env env) throws APIException {} } \ No newline at end of file diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBDF.java b/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBDF.java index e32532bc..dc7ee192 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBDF.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBDF.java @@ -42,268 +42,268 @@ import org.onap.aaf.misc.env.old.IOStringifier; import org.onap.aaf.misc.env.old.OldDataFactory; public class JAXBDF extends BaseDataFactory implements OldDataFactory,IOObjectifier, IOStringifier { - // 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 pretty(boolean pretty) { - jmar.pretty(pretty); - return this; - } - - // @Override - public IOStringifier 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 newData() { - return new JAXBData(primaryEnv, this, new JAXBStringifier(jmar), new JAXBObjectifier(jumar),"",(Class)jmar.getMarshalClass()); - } - - @SuppressWarnings("unchecked") - // @Override - public Data newData(Env env) { - return new JAXBData(env, this,new JAXBStringifier(jmar), new JAXBObjectifier(jumar),"",(Class)jmar.getMarshalClass()); - } - - // @Override - public Data newData(T type) { - return new JAXBData(primaryEnv, this, new JAXBStringifier(jmar), new JAXBObjectifier(jumar), type); - } - - // @Override - public Data 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(primaryEnv, this, new JAXBStringifier(jmar), new JAXBObjectifier(jumar),t); - } catch(JAXBException e) { - throw new APIException(e); - } - } - - @SuppressWarnings("unchecked") - // @Override - public Data newDataFromString(String string) { - return new JAXBData(primaryEnv, this,new JAXBStringifier(jmar), new JAXBObjectifier(jumar), string,(Class)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 getTypeClass() { - return (Class)jmar.getMarshalClass(); - } + // 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 pretty(boolean pretty) { + jmar.pretty(pretty); + return this; + } + + // @Override + public IOStringifier 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 newData() { + return new JAXBData(primaryEnv, this, new JAXBStringifier(jmar), new JAXBObjectifier(jumar),"",(Class)jmar.getMarshalClass()); + } + + @SuppressWarnings("unchecked") + // @Override + public Data newData(Env env) { + return new JAXBData(env, this,new JAXBStringifier(jmar), new JAXBObjectifier(jumar),"",(Class)jmar.getMarshalClass()); + } + + // @Override + public Data newData(T type) { + return new JAXBData(primaryEnv, this, new JAXBStringifier(jmar), new JAXBObjectifier(jumar), type); + } + + // @Override + public Data 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(primaryEnv, this, new JAXBStringifier(jmar), new JAXBObjectifier(jumar),t); + } catch(JAXBException e) { + throw new APIException(e); + } + } + + @SuppressWarnings("unchecked") + // @Override + public Data newDataFromString(String string) { + return new JAXBData(primaryEnv, this,new JAXBStringifier(jmar), new JAXBObjectifier(jumar), string,(Class)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 getTypeClass() { + return (Class)jmar.getMarshalClass(); + } } 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..38977a35 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,267 @@ 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 { + 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 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 { + 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; + } - // @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 { + return dataAsString = stringifier.stringify(creatingEnv, dataAsObject); + } 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 diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBObjectifier.java b/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBObjectifier.java index 432a449a..7075c7ef 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBObjectifier.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBObjectifier.java @@ -36,100 +36,100 @@ import org.onap.aaf.misc.env.old.IOObjectifier; * Allow Extended IO interface usage without muddying up the Stringifier Interface */ public class JAXBObjectifier implements IOObjectifier { - 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); - } - } - + 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); - } - } + 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/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBStringifier.java b/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBStringifier.java index d1b0cdad..8600efa2 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBStringifier.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBStringifier.java @@ -34,104 +34,104 @@ import org.onap.aaf.misc.env.TimeTaken; import org.onap.aaf.misc.env.old.IOStringifier; public class JAXBStringifier implements IOStringifier { - 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 pretty(boolean pretty) { - jmar.pretty(pretty); - return this; - } - - // @Override - public JAXBStringifier asFragment(boolean fragment) { - jmar.asFragment(fragment); - return this; - } + 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 pretty(boolean pretty) { + jmar.pretty(pretty); + return this; + } + + // @Override + public JAXBStringifier asFragment(boolean fragment) { + jmar.asFragment(fragment); + return this; + } } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBmar.java b/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBmar.java index 4a01d8b1..46c40ebb 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBmar.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBmar.java @@ -63,191 +63,191 @@ import org.onap.aaf.misc.env.util.Pool.Pooled; * */ public class JAXBmar { - // Need to store off possible JAXBContexts based on Class, which will be stored in Creator - private static Map[],Pool> pools = new HashMap<>(); - - // 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 { - 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 mpool; // specific Pool associated with constructed Classes - private Class cls; - - 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 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 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 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(qname, (Class)cls, o ), - writer); - } - return o; - } finally { - m.done(); - } - } - - @SuppressWarnings("unchecked") - public 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 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(qname, (Class)cls, o ),os); - } - return o; - } finally { - m.done(); - } - } - - public O marshal(LogTarget lt, O o, Writer writer, Class clss) throws JAXBException, APIException { - Pooled 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(qname, clss, o),writer); - } - return o; - } finally { - m.done(); - } - - } - - public O marshal(LogTarget lt, O o, OutputStream os, Class clss) throws JAXBException, APIException { - Pooled 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(qname, clss, o ),os); - } - return o; - } finally { - m.done(); - } - } - - /** - * @return - */ - public Class getMarshalClass() { - return cls; - } - - public 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; - } + // Need to store off possible JAXBContexts based on Class, which will be stored in Creator + private static Map[],Pool> pools = new HashMap<>(); + + // 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 { + 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 mpool; // specific Pool associated with constructed Classes + private Class cls; + + 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 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 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 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(qname, (Class)cls, o ), + writer); + } + return o; + } finally { + m.done(); + } + } + + @SuppressWarnings("unchecked") + public 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 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(qname, (Class)cls, o ),os); + } + return o; + } finally { + m.done(); + } + } + + public O marshal(LogTarget lt, O o, Writer writer, Class clss) throws JAXBException, APIException { + Pooled 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(qname, clss, o),writer); + } + return o; + } finally { + m.done(); + } + + } + + public O marshal(LogTarget lt, O o, OutputStream os, Class clss) throws JAXBException, APIException { + Pooled 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(qname, clss, o ),os); + } + return o; + } finally { + m.done(); + } + } + + /** + * @return + */ + public Class getMarshalClass() { + return cls; + } + + public 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/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 0c078a98..fe3f0145 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<>(); - - 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(); + } } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/old/IOObjectifier.java b/misc/env/src/main/java/org/onap/aaf/misc/env/old/IOObjectifier.java index ba1b981a..03e47911 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/old/IOObjectifier.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/old/IOObjectifier.java @@ -28,30 +28,30 @@ import org.onap.aaf.misc.env.APIException; import org.onap.aaf.misc.env.Env; public interface IOObjectifier extends Objectifier { - /** - * Marshal to Object T from a Reader, using contents from Env as necessary.

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return T - * @throws APIException - */ - public abstract T objectify(Env env, Reader rdr) throws APIException; - - /** - * Marshal to Object T from an InputStream, using contents from Env as necessary.

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return T - * @throws APIException - */ - public abstract T objectify(Env env, InputStream is) throws APIException; + /** + * Marshal to Object T from a Reader, using contents from Env as necessary.

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return T + * @throws APIException + */ + public abstract T objectify(Env env, Reader rdr) throws APIException; + + /** + * Marshal to Object T from an InputStream, using contents from Env as necessary.

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return T + * @throws APIException + */ + public abstract T objectify(Env env, InputStream is) throws APIException; } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/old/IOStringifier.java b/misc/env/src/main/java/org/onap/aaf/misc/env/old/IOStringifier.java index 137e401f..ca03a1b8 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/old/IOStringifier.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/old/IOStringifier.java @@ -31,47 +31,47 @@ import org.onap.aaf.misc.env.Env; * Allow Extended IO interface usage without muddying up the Stringifier Interface */ public interface IOStringifier extends Stringifier { - /** - * Marshal from an Object T onto a Writer, using contents from Env as necessary.

- * - * Implementations should use the {@link Env} to call "env.startTime(, Env.XML)" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return String - * @throws APIException - */ - public abstract void stringify(Env env, T input, Writer writer, boolean ... options) throws APIException; - - /** - * Marshal from a String to an Object T, using contents from Env as necessary.

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return String - * @throws APIException - */ - public abstract void stringify(Env env, T input, OutputStream os, boolean ... options) throws APIException; + /** + * Marshal from an Object T onto a Writer, using contents from Env as necessary.

+ * + * Implementations should use the {@link Env} to call "env.startTime(, Env.XML)" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return String + * @throws APIException + */ + public abstract void stringify(Env env, T input, Writer writer, boolean ... options) throws APIException; + + /** + * Marshal from a String to an Object T, using contents from Env as necessary.

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return String + * @throws APIException + */ + public abstract void stringify(Env env, T input, OutputStream os, boolean ... options) throws APIException; - /** - * Set Pretty XML, where possible - * - * @param pretty - * @throws APIException - */ - public abstract IOStringifier pretty(boolean pretty); + /** + * Set Pretty XML, where possible + * + * @param pretty + * @throws APIException + */ + public abstract IOStringifier pretty(boolean pretty); - /** - * Set Generate Fragment - * - * @param fragment - * @throws APIException - */ - public abstract IOStringifier asFragment(boolean fragment); + /** + * Set Generate Fragment + * + * @param fragment + * @throws APIException + */ + public abstract IOStringifier asFragment(boolean fragment); } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/old/Objectifier.java b/misc/env/src/main/java/org/onap/aaf/misc/env/old/Objectifier.java index 1fd3cdaf..1f58077e 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/old/Objectifier.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/old/Objectifier.java @@ -35,26 +35,26 @@ import org.onap.aaf.misc.env.LifeCycle; * the creation of an uninitialized object. */ public interface Objectifier extends LifeCycle { - /** - * Marshal to Object T from a String, using contents from Env as necessary.

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return T - * @throws APIException - */ - public abstract T objectify(Env env, String input) throws APIException; + /** + * Marshal to Object T from a String, using contents from Env as necessary.

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return T + * @throws APIException + */ + public abstract T objectify(Env env, String input) throws APIException; - /** - * Create a new object of type T. This is often more efficiently done with - * the underlying XML (or other) Library. - * @return T - * @throws APIException - */ - public abstract T newInstance() throws APIException; + /** + * Create a new object of type T. This is often more efficiently done with + * the underlying XML (or other) Library. + * @return T + * @throws APIException + */ + public abstract T newInstance() throws APIException; - + } \ No newline at end of file diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/old/OldDataFactory.java b/misc/env/src/main/java/org/onap/aaf/misc/env/old/OldDataFactory.java index 724e9f48..463bc15a 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/old/OldDataFactory.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/old/OldDataFactory.java @@ -32,16 +32,16 @@ import org.onap.aaf.misc.env.DataFactory; import org.onap.aaf.misc.env.Env; public interface OldDataFactory extends DataFactory { - public abstract String stringify(T type) throws APIException; - public abstract void stringify(T type, OutputStream os) throws APIException; - public abstract void stringify(T type, Writer writer) throws APIException; - public abstract T objectify(InputStream is) throws APIException; - public abstract T objectify(Reader rdr) throws APIException; - public abstract T objectify(String text) throws APIException; - public abstract T newInstance() throws APIException; - public abstract Data newData(T type); - public abstract Data newDataFromStream(Env env, InputStream input) throws APIException; - public abstract Data newDataFromString(String string); - + public abstract String stringify(T type) throws APIException; + public abstract void stringify(T type, OutputStream os) throws APIException; + public abstract void stringify(T type, Writer writer) throws APIException; + public abstract T objectify(InputStream is) throws APIException; + public abstract T objectify(Reader rdr) throws APIException; + public abstract T objectify(String text) throws APIException; + public abstract T newInstance() throws APIException; + public abstract Data newData(T type); + public abstract Data newDataFromStream(Env env, InputStream input) throws APIException; + public abstract Data newDataFromString(String string); + } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/old/Stringifier.java b/misc/env/src/main/java/org/onap/aaf/misc/env/old/Stringifier.java index eaea7f6a..01689f38 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/old/Stringifier.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/old/Stringifier.java @@ -31,18 +31,18 @@ import org.onap.aaf.misc.env.LifeCycle; * Stringifier abstracts the marshaling of a String to an Object */ public interface Stringifier extends LifeCycle { - - /** - * Marshal from a String to an Object T, using contents from Env as necessary.

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return String - * @throws APIException - */ - public abstract String stringify(Env env, T input, boolean ... options) throws APIException; - + + /** + * Marshal from a String to an Object T, using contents from Env as necessary.

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return String + * @throws APIException + */ + public abstract String stringify(Env env, T input, boolean ... options) throws APIException; + } \ No newline at end of file diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/util/Chrono.java b/misc/env/src/main/java/org/onap/aaf/misc/env/util/Chrono.java index ebae19b4..ae78918c 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/util/Chrono.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/util/Chrono.java @@ -38,273 +38,273 @@ import javax.xml.datatype.XMLGregorianCalendar; public class Chrono { private static final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L; - public final static DateFormat dateFmt, dateOnlyFmt, niceDateFmt, utcFmt,iso8601Fmt; - // Give general access to XML DataType Factory, since it's pretty common - public static final DatatypeFactory xmlDatatypeFactory; - - static { - try { - xmlDatatypeFactory = DatatypeFactory.newInstance(); - } catch (DatatypeConfigurationException e) { - throw new RuntimeException(e); - } - dateOnlyFmt = new SimpleDateFormat("yyyy-MM-dd"); - niceDateFmt = new SimpleDateFormat("yyyy/MM/dd HH:mm zzz"); - dateFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); - utcFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); - iso8601Fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"); - utcFmt.setTimeZone(TimeZone.getTimeZone("UTC")); - } - - - public static class Formatter8601 extends Formatter { - - @Override - public String format(LogRecord r) { - StringBuilder sb = new StringBuilder(); - sb.append(dateFmt.format(new Date(r.getMillis()))); - sb.append(' '); - sb.append(r.getThreadID()); - sb.append(' '); - sb.append(r.getLevel()); - sb.append(": "); - sb.append(r.getMessage()); - sb.append('\n'); - return sb.toString(); - } - - } - - /** - * timeStamp - * - * Convenience method to setup an XML dateTime (XMLGregorianCalendar) with "now" - * @return - */ - public static XMLGregorianCalendar timeStamp() { - return xmlDatatypeFactory.newXMLGregorianCalendar(new GregorianCalendar()); - } - - /** - * timestamp - * - * Convenience method to setup an XML dateTime (XMLGregorianCalendar) with passed in Date - * @param date - * @return - */ - public static XMLGregorianCalendar timeStamp(Date date) { - GregorianCalendar gc = new GregorianCalendar(); - gc.setTime(date); - return xmlDatatypeFactory.newXMLGregorianCalendar(gc); - } - - public static XMLGregorianCalendar timeStamp(GregorianCalendar gc) { - return xmlDatatypeFactory.newXMLGregorianCalendar(gc); - } - - public static String utcStamp() { - return utcFmt.format(new Date()); - } - - public static String utcStamp(Date date) { - if(date==null)return ""; - return utcFmt.format(date); - } - - public static String utcStamp(GregorianCalendar gc) { - if(gc==null)return ""; - return utcFmt.format(gc.getTime()); - } - - public static String utcStamp(XMLGregorianCalendar xgc) { - if(xgc==null)return ""; - return utcFmt.format(xgc.toGregorianCalendar().getTime()); - } - - public static String dateStamp() { - return dateFmt.format(new Date()); - } - - public static String dateStamp(GregorianCalendar gc) { - if(gc == null)return ""; - return dateFmt.format(gc.getTime()); - } - - public static String dateStamp(Date date) { - if(date == null)return ""; - return dateFmt.format(date); - } - - public static String dateStamp(XMLGregorianCalendar xgc) { - if(xgc==null)return ""; - return dateFmt.format(xgc.toGregorianCalendar().getTime()); - } - - /** - * JAXB compatible dataTime Stamp - * - * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it. - * - * @return - */ - public static String dateTime() { - return dateTime(new GregorianCalendar()); - } - - /** - * JAXB compatible dataTime Stamp - * - * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it. - * - * @return - */ - public static String dateTime(Date date) { - GregorianCalendar gc = new GregorianCalendar(); - gc.setTime(date); - return dateTime(gc); - } - - /** - * JAXB compatible dataTime Stamp - * - * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it. - * - * @return - */ - public static String dateTime(GregorianCalendar gc) { - if(gc == null)return ""; - TimeZone tz = gc.getTimeZone(); - int tz1 = (tz.getRawOffset()+tz.getDSTSavings())/0x8CA0; - int tz1abs = Math.abs(tz1); - return String.format("%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d:%02d", - gc.get(GregorianCalendar.YEAR), - gc.get(GregorianCalendar.MONTH)+1, - gc.get(GregorianCalendar.DAY_OF_MONTH), - gc.get(GregorianCalendar.HOUR), - gc.get(GregorianCalendar.MINUTE), - gc.get(GregorianCalendar.SECOND), - gc.get(GregorianCalendar.MILLISECOND), - tz1==tz1abs?'+':'-', - tz1abs/100, - ((tz1abs-(tz1abs/100)*100)*6)/10 // Get the "10s", then convert to mins (without losing int place) - ); - } - - /** - * JAXB compatible dataTime Stamp - * - * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it. - * - * @return - */ - public static String dateTime(XMLGregorianCalendar xgc) { - return xgc==null?"":dateTime(xgc.toGregorianCalendar()); - } - - public static String dateOnlyStamp() { - return dateOnlyFmt.format(new Date()); - } - - public static String dateOnlyStamp(GregorianCalendar gc) { - return gc == null?"":dateOnlyFmt.format(gc.getTime()); - } - - public static String dateOnlyStamp(Date date) { - return date == null?"":dateOnlyFmt.format(date); - } - - public static String dateOnlyStamp(XMLGregorianCalendar xgc) { - return xgc==null?"":dateOnlyFmt.format(xgc.toGregorianCalendar().getTime()); - } - - public static String niceDateStamp() { - return niceDateFmt.format(new Date()); - } - - public static String niceDateStamp(Date date) { - return date==null?"":niceDateFmt.format(date); - } - - public static String niceDateStamp(GregorianCalendar gc) { - return gc==null?"":niceDateFmt.format(gc.getTime()); - } - - public static String niceDateStamp(XMLGregorianCalendar xgc) { - return xgc==null?"":niceDateFmt.format(xgc.toGregorianCalendar().getTime()); - } - - - ////////////////////// HELPFUL Strings - public static final String BAD_DIR_CHARS_REGEX = "[/:\\;.]"; - public static final String SPLIT_DIR_REGEX = "/"; - - public static long firstMomentOfDay(long utc) { - GregorianCalendar begin = new GregorianCalendar(); - begin.setTimeInMillis(utc); - return firstMomentOfDay(begin).getTimeInMillis(); - } - - public static long lastMomentOfDay(long utc) { - GregorianCalendar end = new GregorianCalendar(); - end.setTimeInMillis(utc); - return lastMomentOfDay(end).getTimeInMillis(); - } - - public static GregorianCalendar firstMomentOfDay(GregorianCalendar begin) { - if(begin==null)begin = new GregorianCalendar(); - begin.set(GregorianCalendar.HOUR, 0); - begin.set(GregorianCalendar.AM_PM, GregorianCalendar.AM); - begin.set(GregorianCalendar.MINUTE, 0); - begin.set(GregorianCalendar.SECOND, 0); - begin.set(GregorianCalendar.MILLISECOND, 0); - return begin; - } - - public static GregorianCalendar lastMomentOfDay(GregorianCalendar end) { - if(end==null)end = new GregorianCalendar(); - end.set(GregorianCalendar.HOUR, 11); - end.set(GregorianCalendar.MINUTE, 59); - end.set(GregorianCalendar.SECOND, 59); - end.set(GregorianCalendar.MILLISECOND, 999); - end.set(GregorianCalendar.AM_PM, GregorianCalendar.PM); - return end; - } - - // UUID needs to be converted from UUID Epoch - public static final Date uuidToDate(UUID id) { - return new Date((id.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH)/10000); - } - - public static final long uuidToUnix(UUID id) { - return (id.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH)/10000; - } - - public static float millisFromNanos(long start, long end) { - return (end - start) / 1000000f; - } - - - private static long sequence = new SecureRandom().nextInt(); - private static synchronized long sequence() { - return ++sequence; - } - - public static final UUID dateToUUID(Date origTime) { - return dateToUUID(origTime.getTime()); - } - - public static final UUID dateToUUID(long origTime) { - /* - * From Cassandra : http://wiki.apache.org/cassandra/FAQ - Magic number obtained from #cassandra's thobbs, who - claims to have stolen it from a Python library. - */ + public final static DateFormat dateFmt, dateOnlyFmt, niceDateFmt, utcFmt,iso8601Fmt; + // Give general access to XML DataType Factory, since it's pretty common + public static final DatatypeFactory xmlDatatypeFactory; + + static { + try { + xmlDatatypeFactory = DatatypeFactory.newInstance(); + } catch (DatatypeConfigurationException e) { + throw new RuntimeException(e); + } + dateOnlyFmt = new SimpleDateFormat("yyyy-MM-dd"); + niceDateFmt = new SimpleDateFormat("yyyy/MM/dd HH:mm zzz"); + dateFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); + utcFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); + iso8601Fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"); + utcFmt.setTimeZone(TimeZone.getTimeZone("UTC")); + } + + + public static class Formatter8601 extends Formatter { + + @Override + public String format(LogRecord r) { + StringBuilder sb = new StringBuilder(); + sb.append(dateFmt.format(new Date(r.getMillis()))); + sb.append(' '); + sb.append(r.getThreadID()); + sb.append(' '); + sb.append(r.getLevel()); + sb.append(": "); + sb.append(r.getMessage()); + sb.append('\n'); + return sb.toString(); + } + + } + + /** + * timeStamp + * + * Convenience method to setup an XML dateTime (XMLGregorianCalendar) with "now" + * @return + */ + public static XMLGregorianCalendar timeStamp() { + return xmlDatatypeFactory.newXMLGregorianCalendar(new GregorianCalendar()); + } + + /** + * timestamp + * + * Convenience method to setup an XML dateTime (XMLGregorianCalendar) with passed in Date + * @param date + * @return + */ + public static XMLGregorianCalendar timeStamp(Date date) { + GregorianCalendar gc = new GregorianCalendar(); + gc.setTime(date); + return xmlDatatypeFactory.newXMLGregorianCalendar(gc); + } + + public static XMLGregorianCalendar timeStamp(GregorianCalendar gc) { + return xmlDatatypeFactory.newXMLGregorianCalendar(gc); + } + + public static String utcStamp() { + return utcFmt.format(new Date()); + } + + public static String utcStamp(Date date) { + if(date==null)return ""; + return utcFmt.format(date); + } + + public static String utcStamp(GregorianCalendar gc) { + if(gc==null)return ""; + return utcFmt.format(gc.getTime()); + } + + public static String utcStamp(XMLGregorianCalendar xgc) { + if(xgc==null)return ""; + return utcFmt.format(xgc.toGregorianCalendar().getTime()); + } + + public static String dateStamp() { + return dateFmt.format(new Date()); + } + + public static String dateStamp(GregorianCalendar gc) { + if(gc == null)return ""; + return dateFmt.format(gc.getTime()); + } + + public static String dateStamp(Date date) { + if(date == null)return ""; + return dateFmt.format(date); + } + + public static String dateStamp(XMLGregorianCalendar xgc) { + if(xgc==null)return ""; + return dateFmt.format(xgc.toGregorianCalendar().getTime()); + } + + /** + * JAXB compatible dataTime Stamp + * + * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it. + * + * @return + */ + public static String dateTime() { + return dateTime(new GregorianCalendar()); + } + + /** + * JAXB compatible dataTime Stamp + * + * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it. + * + * @return + */ + public static String dateTime(Date date) { + GregorianCalendar gc = new GregorianCalendar(); + gc.setTime(date); + return dateTime(gc); + } + + /** + * JAXB compatible dataTime Stamp + * + * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it. + * + * @return + */ + public static String dateTime(GregorianCalendar gc) { + if(gc == null)return ""; + TimeZone tz = gc.getTimeZone(); + int tz1 = (tz.getRawOffset()+tz.getDSTSavings())/0x8CA0; + int tz1abs = Math.abs(tz1); + return String.format("%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d:%02d", + gc.get(GregorianCalendar.YEAR), + gc.get(GregorianCalendar.MONTH)+1, + gc.get(GregorianCalendar.DAY_OF_MONTH), + gc.get(GregorianCalendar.HOUR), + gc.get(GregorianCalendar.MINUTE), + gc.get(GregorianCalendar.SECOND), + gc.get(GregorianCalendar.MILLISECOND), + tz1==tz1abs?'+':'-', + tz1abs/100, + ((tz1abs-(tz1abs/100)*100)*6)/10 // Get the "10s", then convert to mins (without losing int place) + ); + } + + /** + * JAXB compatible dataTime Stamp + * + * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it. + * + * @return + */ + public static String dateTime(XMLGregorianCalendar xgc) { + return xgc==null?"":dateTime(xgc.toGregorianCalendar()); + } + + public static String dateOnlyStamp() { + return dateOnlyFmt.format(new Date()); + } + + public static String dateOnlyStamp(GregorianCalendar gc) { + return gc == null?"":dateOnlyFmt.format(gc.getTime()); + } + + public static String dateOnlyStamp(Date date) { + return date == null?"":dateOnlyFmt.format(date); + } + + public static String dateOnlyStamp(XMLGregorianCalendar xgc) { + return xgc==null?"":dateOnlyFmt.format(xgc.toGregorianCalendar().getTime()); + } + + public static String niceDateStamp() { + return niceDateFmt.format(new Date()); + } + + public static String niceDateStamp(Date date) { + return date==null?"":niceDateFmt.format(date); + } + + public static String niceDateStamp(GregorianCalendar gc) { + return gc==null?"":niceDateFmt.format(gc.getTime()); + } + + public static String niceDateStamp(XMLGregorianCalendar xgc) { + return xgc==null?"":niceDateFmt.format(xgc.toGregorianCalendar().getTime()); + } + + + ////////////////////// HELPFUL Strings + public static final String BAD_DIR_CHARS_REGEX = "[/:\\;.]"; + public static final String SPLIT_DIR_REGEX = "/"; + + public static long firstMomentOfDay(long utc) { + GregorianCalendar begin = new GregorianCalendar(); + begin.setTimeInMillis(utc); + return firstMomentOfDay(begin).getTimeInMillis(); + } + + public static long lastMomentOfDay(long utc) { + GregorianCalendar end = new GregorianCalendar(); + end.setTimeInMillis(utc); + return lastMomentOfDay(end).getTimeInMillis(); + } + + public static GregorianCalendar firstMomentOfDay(GregorianCalendar begin) { + if(begin==null)begin = new GregorianCalendar(); + begin.set(GregorianCalendar.HOUR, 0); + begin.set(GregorianCalendar.AM_PM, GregorianCalendar.AM); + begin.set(GregorianCalendar.MINUTE, 0); + begin.set(GregorianCalendar.SECOND, 0); + begin.set(GregorianCalendar.MILLISECOND, 0); + return begin; + } + + public static GregorianCalendar lastMomentOfDay(GregorianCalendar end) { + if(end==null)end = new GregorianCalendar(); + end.set(GregorianCalendar.HOUR, 11); + end.set(GregorianCalendar.MINUTE, 59); + end.set(GregorianCalendar.SECOND, 59); + end.set(GregorianCalendar.MILLISECOND, 999); + end.set(GregorianCalendar.AM_PM, GregorianCalendar.PM); + return end; + } + + // UUID needs to be converted from UUID Epoch + public static final Date uuidToDate(UUID id) { + return new Date((id.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH)/10000); + } + + public static final long uuidToUnix(UUID id) { + return (id.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH)/10000; + } + + public static float millisFromNanos(long start, long end) { + return (end - start) / 1000000f; + } + + + private static long sequence = new SecureRandom().nextInt(); + private static synchronized long sequence() { + return ++sequence; + } + + public static final UUID dateToUUID(Date origTime) { + return dateToUUID(origTime.getTime()); + } + + public static final UUID dateToUUID(long origTime) { + /* + * From Cassandra : http://wiki.apache.org/cassandra/FAQ + Magic number obtained from #cassandra's thobbs, who + claims to have stolen it from a Python library. + */ long time = origTime * 10000 + NUM_100NS_INTERVALS_SINCE_UUID_EPOCH; long timeLow = time & 0xffffffffL; long timeMid = time & 0xffff00000000L; long timeHi = time & 0xfff000000000000L; long upperLong = (timeLow << 32) | (timeMid >> 16) | (1 << 12) | (timeHi >> 48) ; return new java.util.UUID(upperLong, (0xC000000000000000L | sequence())); - } + } } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/util/DoubleOutputStream.java b/misc/env/src/main/java/org/onap/aaf/misc/env/util/DoubleOutputStream.java index 9c4c4316..97d9de99 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/util/DoubleOutputStream.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/util/DoubleOutputStream.java @@ -26,15 +26,15 @@ import java.io.OutputStream; public class DoubleOutputStream extends OutputStream { private OutputStream[] oss; - private boolean[] close; + private boolean[] close; - /** + /** * Create a Double Stream Writer * Some Streams should not be closed by this object (i.e. System.out), therefore, mark them with booleans */ public DoubleOutputStream(OutputStream a, boolean closeA, OutputStream b, boolean closeB) { - oss = new OutputStream[] {a,b}; - close = new boolean[] {closeA,closeB}; + oss = new OutputStream[] {a,b}; + close = new boolean[] {closeA,closeB}; } /** @@ -43,9 +43,9 @@ public class DoubleOutputStream extends OutputStream { */ @Override public void write(int c) throws IOException { - for(OutputStream os : oss) { - os.write(c); - } + for(OutputStream os : oss) { + os.write(c); + } } /** @@ -58,39 +58,39 @@ public class DoubleOutputStream extends OutputStream { */ @Override public void write(byte bbuf[], int off, int len) throws IOException { - for(OutputStream os : oss) { - os.write(bbuf,off,len); - } + for(OutputStream os : oss) { + os.write(bbuf,off,len); + } } @Override - public void write(byte[] b) throws IOException { - for(OutputStream os : oss) { - os.write(b); - } - } + public void write(byte[] b) throws IOException { + for(OutputStream os : oss) { + os.write(b); + } + } - /* (non-Javadoc) - * @see java.io.OutputStream#close() - */ - @Override - public void close() throws IOException { - for(int i=0;i */ public class Pool { - /** - * This is a constant which specified the default maximum number of unused - * objects to be held at any given time. - */ - private static final int MAX_RANGE = 6; // safety + /** + * This is a constant which specified the default maximum number of unused + * objects to be held at any given time. + */ + private static final int MAX_RANGE = 6; // safety - /** - * only Simple List needed. - * - * NOTE TO MAINTAINERS: THIS OBJECT DOES IT'S OWN SYNCHRONIZATION. All - * changes that touch list must account for correctly synchronizing list. - */ - private LinkedList> list; + /** + * only Simple List needed. + * + * NOTE TO MAINTAINERS: THIS OBJECT DOES IT'S OWN SYNCHRONIZATION. All + * changes that touch list must account for correctly synchronizing list. + */ + private LinkedList> list; - /** - * keep track of how many elements exist, to avoid asking list. - */ - private int count; + /** + * keep track of how many elements exist, to avoid asking list. + */ + private int count; - /** - * Spares are those Object that are primed and ready to go. - */ - private int spares; + /** + * Spares are those Object that are primed and ready to go. + */ + private int spares; - /** - * Actual MAX number of spares allowed to hang around. Can be set to - * something besides the default MAX_RANGE. - */ - private int max_range = MAX_RANGE; + /** + * Actual MAX number of spares allowed to hang around. Can be set to + * something besides the default MAX_RANGE. + */ + private int max_range = MAX_RANGE; - /** - * The Creator for this particular pool. It must work for type T. - */ - private Creator creator; + /** + * The Creator for this particular pool. It must work for type T. + */ + private Creator creator; - /** - * Create a new Pool, given the implementation of Creator, which must be - * able to create/destroy T objects at will. - * - * @param creator - */ - public Pool(Creator creator) { - count = spares = 0; - this.creator = creator; - list = new LinkedList<>(); - } + /** + * Create a new Pool, given the implementation of Creator, which must be + * able to create/destroy T objects at will. + * + * @param creator + */ + public Pool(Creator creator) { + count = spares = 0; + this.creator = creator; + list = new LinkedList<>(); + } - /** - * Preallocate a certain number of T Objects. Useful for services so that - * the first transactions don't get hit with all the Object creation costs - * - * @param lt - * @param prime - * @throws APIException - */ - public void prime(LogTarget lt, int prime) throws APIException { - for (int i = 0; i < prime; ++i) { - Pooled pt = new Pooled(creator.create(), this, lt); - synchronized (list) { - list.addFirst(pt); - ++count; - } - } + /** + * Preallocate a certain number of T Objects. Useful for services so that + * the first transactions don't get hit with all the Object creation costs + * + * @param lt + * @param prime + * @throws APIException + */ + public void prime(LogTarget lt, int prime) throws APIException { + for (int i = 0; i < prime; ++i) { + Pooled pt = new Pooled(creator.create(), this, lt); + synchronized (list) { + list.addFirst(pt); + ++count; + } + } - } + } - /** - * Destroy and remove all remaining objects. This is valuable for closing - * down all Allocated objects cleanly for exiting. It is also a good method - * for removing objects when, for instance, all Objects are invalid because - * of broken connections, etc. - */ - public void drain() { - synchronized (list) { - for (int i = 0; i < list.size(); ++i) { - Pooled pt = list.remove(); - creator.destroy(pt.content); - pt.logTarget.log("Pool drained ", creator.toString()); - } - count = spares = 0; - } + /** + * Destroy and remove all remaining objects. This is valuable for closing + * down all Allocated objects cleanly for exiting. It is also a good method + * for removing objects when, for instance, all Objects are invalid because + * of broken connections, etc. + */ + public void drain() { + synchronized (list) { + for (int i = 0; i < list.size(); ++i) { + Pooled pt = list.remove(); + creator.destroy(pt.content); + pt.logTarget.log("Pool drained ", creator.toString()); + } + count = spares = 0; + } - } + } - /** - * This is the essential function for Pool. Get an Object "T" inside a - * "Pooled" object. If there is a spare Object, then use it. If not, then - * create and pass back. - * - * This one uses a Null LogTarget - * - * IMPORTANT: When the use of this object is done (and the object is still - * in a valid state), then "done()" should be called immediately to allow - * the object to be reused. That is the point of the Pool... - * - * If the Object is in an invalid state, then "toss()" should be used so the - * Pool doesn't pass on invalid objects to others. - * - * @param lt - * @return - * @throws APIException - */ - public Pooled get() throws APIException { - Pooled pt; - synchronized (list) { - if (list.isEmpty()) { - pt = null; - } else { - pt = list.removeLast(); - --count; - creator.reuse(pt.content); - } - } - if (pt == null) { - if (spares < max_range) - ++spares; - pt = new Pooled(creator.create(), this, LogTarget.NULL); - } else { - if (spares > 1) - --spares; - } - return pt; - } + /** + * This is the essential function for Pool. Get an Object "T" inside a + * "Pooled" object. If there is a spare Object, then use it. If not, then + * create and pass back. + * + * This one uses a Null LogTarget + * + * IMPORTANT: When the use of this object is done (and the object is still + * in a valid state), then "done()" should be called immediately to allow + * the object to be reused. That is the point of the Pool... + * + * If the Object is in an invalid state, then "toss()" should be used so the + * Pool doesn't pass on invalid objects to others. + * + * @param lt + * @return + * @throws APIException + */ + public Pooled get() throws APIException { + Pooled pt; + synchronized (list) { + if (list.isEmpty()) { + pt = null; + } else { + pt = list.removeLast(); + --count; + creator.reuse(pt.content); + } + } + if (pt == null) { + if (spares < max_range) + ++spares; + pt = new Pooled(creator.create(), this, LogTarget.NULL); + } else { + if (spares > 1) + --spares; + } + return pt; + } - /** - * This is the essential function for Pool. Get an Object "T" inside a - * "Pooled" object. If there is a spare Object, then use it. If not, then - * create and pass back. - * - * If you don't have access to a LogTarget from Env, use LogTarget.NULL - * - * IMPORTANT: When the use of this object is done (and the object is still - * in a valid state), then "done()" should be called immediately to allow - * the object to be reused. That is the point of the Pool... - * - * If the Object is in an invalid state, then "toss()" should be used so the - * Pool doesn't pass on invalid objects to others. - * - * @param lt - * @return - * @throws APIException - */ - public Pooled get(LogTarget lt) throws APIException { - Pooled pt; - synchronized (list) { - if (list.isEmpty()) { - pt = null; - } else { - pt = list.remove(); - --count; - creator.reuse(pt.content); - } - } - if (pt == null) { - if (spares < max_range) - ++spares; - pt = new Pooled(creator.create(), this, lt); - lt.log("Pool created ", creator.toString()); - } else { - if (spares > 1) - --spares; - } - return pt; - } + /** + * This is the essential function for Pool. Get an Object "T" inside a + * "Pooled" object. If there is a spare Object, then use it. If not, then + * create and pass back. + * + * If you don't have access to a LogTarget from Env, use LogTarget.NULL + * + * IMPORTANT: When the use of this object is done (and the object is still + * in a valid state), then "done()" should be called immediately to allow + * the object to be reused. That is the point of the Pool... + * + * If the Object is in an invalid state, then "toss()" should be used so the + * Pool doesn't pass on invalid objects to others. + * + * @param lt + * @return + * @throws APIException + */ + public Pooled get(LogTarget lt) throws APIException { + Pooled pt; + synchronized (list) { + if (list.isEmpty()) { + pt = null; + } else { + pt = list.remove(); + --count; + creator.reuse(pt.content); + } + } + if (pt == null) { + if (spares < max_range) + ++spares; + pt = new Pooled(creator.create(), this, lt); + lt.log("Pool created ", creator.toString()); + } else { + if (spares > 1) + --spares; + } + return pt; + } - /** - * This function will validate whether the Objects are still in a usable - * state. If not, they are tossed from the Pool. This is valuable to have - * when Remote Connections go down, and there is a question on whether the - * Pooled Objects are still functional. - * - * @return - */ - public boolean validate() { - boolean rv = true; - synchronized (list) { - for (Pooled t : list) { - if (!creator.isValid(t.content)) { - rv = false; - t.toss(); - list.remove(t); - } - } - } - return rv; - } + /** + * This function will validate whether the Objects are still in a usable + * state. If not, they are tossed from the Pool. This is valuable to have + * when Remote Connections go down, and there is a question on whether the + * Pooled Objects are still functional. + * + * @return + */ + public boolean validate() { + boolean rv = true; + synchronized (list) { + for (Pooled t : list) { + if (!creator.isValid(t.content)) { + rv = false; + t.toss(); + list.remove(t); + } + } + } + return rv; + } - /** - * This is an internal method, used only by the Internal Pooled class. - * - * The Pooled class "offers" it's Object back after use. It is an - * "offer", because Pool will simply destroy and remove the object if it has - * more than enough spares. - * - * @param lt - * @param used - * @return - */ - // Used only by Pooled - private boolean offer(LogTarget lt, Pooled used) { - if (count < spares) { - synchronized (list) { - list.addFirst(used); - ++count; - } - lt.log("Pool recovered ", creator.toString()); - } else { - lt.log("Pool destroyed ", creator.toString()); - creator.destroy(used.content); - } - return false; - } + /** + * This is an internal method, used only by the Internal Pooled class. + * + * The Pooled class "offers" it's Object back after use. It is an + * "offer", because Pool will simply destroy and remove the object if it has + * more than enough spares. + * + * @param lt + * @param used + * @return + */ + // Used only by Pooled + private boolean offer(LogTarget lt, Pooled used) { + if (count < spares) { + synchronized (list) { + list.addFirst(used); + ++count; + } + lt.log("Pool recovered ", creator.toString()); + } else { + lt.log("Pool destroyed ", creator.toString()); + creator.destroy(used.content); + } + return false; + } - /** - * The Creator Interface give the Pool the ability to Create, Destroy and - * Validate the Objects it is maintaining. Thus, it is a specially written - * Implementation for each type. - * - * @author Jonathan - * - * @param - */ - public interface Creator { - public T create() throws APIException; + /** + * The Creator Interface give the Pool the ability to Create, Destroy and + * Validate the Objects it is maintaining. Thus, it is a specially written + * Implementation for each type. + * + * @author Jonathan + * + * @param + */ + public interface Creator { + public T create() throws APIException; - public void destroy(T t); + public void destroy(T t); - public boolean isValid(T t); + public boolean isValid(T t); - public void reuse(T t); - } + public void reuse(T t); + } - /** - * The "Pooled" class is the transient class that wraps the actual Object - * T for API use/ It gives the ability to return ("done()", or "toss()") the - * Object to the Pool when processing is finished. - * - * For Safety, i.e. to avoid memory leaks and invalid Object States, there - * is a "finalize" method. It is strictly for when coder forgets to return - * the object, or perhaps hasn't covered the case during Exceptions or - * Runtime Exceptions with finally (preferred). This should not be - * considered normal procedure, as finalize() is called at an undetermined - * time during garbage collection, and is thus rather useless for a Pool. - * However, we don't want Coding Mistakes to put the whole program in an - * invalid state, so if something happened such that "done()" or "toss()" - * were not called, the resource is still cleaned up as well as possible. - * - * @author Jonathan - * - * @param - */ - public static class Pooled { - public final T content; - private Pool pool; - protected LogTarget logTarget; + /** + * The "Pooled" class is the transient class that wraps the actual Object + * T for API use/ It gives the ability to return ("done()", or "toss()") the + * Object to the Pool when processing is finished. + * + * For Safety, i.e. to avoid memory leaks and invalid Object States, there + * is a "finalize" method. It is strictly for when coder forgets to return + * the object, or perhaps hasn't covered the case during Exceptions or + * Runtime Exceptions with finally (preferred). This should not be + * considered normal procedure, as finalize() is called at an undetermined + * time during garbage collection, and is thus rather useless for a Pool. + * However, we don't want Coding Mistakes to put the whole program in an + * invalid state, so if something happened such that "done()" or "toss()" + * were not called, the resource is still cleaned up as well as possible. + * + * @author Jonathan + * + * @param + */ + public static class Pooled { + public final T content; + private Pool pool; + protected LogTarget logTarget; - /** - * Create the Wrapping Object Pooled. - * - * @param t - * @param pool - * @param logTarget - */ - public Pooled(T t, Pool pool, LogTarget logTarget) { - content = t; - this.pool = pool; - this.logTarget = logTarget; - } + /** + * Create the Wrapping Object Pooled. + * + * @param t + * @param pool + * @param logTarget + */ + public Pooled(T t, Pool pool, LogTarget logTarget) { + content = t; + this.pool = pool; + this.logTarget = logTarget; + } - /** - * This is the key API for the Pool, as calling "done()" offers this - * object back to the Pool for reuse. - * - * Do not use the Pooled object again after calling "done()". - */ - public void done() { - if (pool != null) { - pool.offer(logTarget, this); - } - } + /** + * This is the key API for the Pool, as calling "done()" offers this + * object back to the Pool for reuse. + * + * Do not use the Pooled object again after calling "done()". + */ + public void done() { + if (pool != null) { + pool.offer(logTarget, this); + } + } - /** - * The user of the Object may discover that the Object t is no longer in - * a valid state. Don't put Garbage back in the Refrigerator... Toss it, - * if it's no longer valid. - * - * toss() is also used for draining the Pool, etc. - * - * toss() will attempt to destroy the Object by using the Creator - * Interface. - * - */ - public void toss() { - if (pool != null) { - pool.creator.destroy(content); - } - // Don't allow finalize to put it back in. - pool = null; - } + /** + * The user of the Object may discover that the Object t is no longer in + * a valid state. Don't put Garbage back in the Refrigerator... Toss it, + * if it's no longer valid. + * + * toss() is also used for draining the Pool, etc. + * + * toss() will attempt to destroy the Object by using the Creator + * Interface. + * + */ + public void toss() { + if (pool != null) { + pool.creator.destroy(content); + } + // Don't allow finalize to put it back in. + pool = null; + } - /** - * Just in case someone neglected to offer back object... Do not rely on - * this, as there is no specific time when finalize is called, which - * rather defeats the purpose of a Pool. - */ - @Override - protected void finalize() throws Throwable { - if (pool != null) { - done(); - pool = null; - } - } - } + /** + * Just in case someone neglected to offer back object... Do not rely on + * this, as there is no specific time when finalize is called, which + * rather defeats the purpose of a Pool. + */ + @Override + protected void finalize() throws Throwable { + if (pool != null) { + done(); + pool = null; + } + } + } - /** - * Get the maximum number of spare objects allowed at any moment - * - * @return - */ - public int getMaxRange() { - return max_range; - } + /** + * Get the maximum number of spare objects allowed at any moment + * + * @return + */ + public int getMaxRange() { + return max_range; + } - /** - * Set a Max Range for numbers of spare objects waiting to be used. - * - * No negative numbers are allowed - * - * @return - */ - public void setMaxRange(int max_range) { - // Do not allow negative numbers - this.max_range = Math.max(0, max_range); - } + /** + * Set a Max Range for numbers of spare objects waiting to be used. + * + * No negative numbers are allowed + * + * @return + */ + public void setMaxRange(int max_range) { + // Do not allow negative numbers + this.max_range = Math.max(0, max_range); + } } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/util/RefreshableThreadObject.java b/misc/env/src/main/java/org/onap/aaf/misc/env/util/RefreshableThreadObject.java index 6892a4b5..759a8c8b 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/util/RefreshableThreadObject.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/util/RefreshableThreadObject.java @@ -54,71 +54,71 @@ import org.onap.aaf.misc.env.LifeCycle; * @param */ public class RefreshableThreadObject> { - private Map objs; - private long refreshed; - private Constructor cnst; - - /** - * The passed in class must implement the constructor - *

-	 *   public MyClass(Env env) {
-	 *     ...
-	 *   }
-	 * 
- * @param clss - * @throws APIException - */ - public RefreshableThreadObject(Class clss) throws APIException { - objs = new ConcurrentHashMap<>(); - try { - cnst = clss.getConstructor(new Class[]{Env.class} ); - } catch (Exception e) { - throw new APIException(e); - } - } - - /** - * Get the "T" class from the current thread - * - * @param env - * @return T - * @throws APIException - */ - public T get(Env env) throws APIException { - Thread t = Thread.currentThread(); - T obj = objs.get(t); - if(obj==null || refreshed>obj.created()) { - try { - obj = cnst.newInstance(new Object[]{env}); - } catch (InvocationTargetException e) { - throw new APIException(e.getTargetException()); - } catch (Exception e) { - throw new APIException(e); - } - T destroyMe = objs.put(t,obj); - if(destroyMe!=null) { - destroyMe.destroy(env); - } - } - return obj; - } - - /** - * Mark the timestamp of refreshed. - * - * @param env - */ - public void refresh(Env env) { - refreshed = System.currentTimeMillis(); - } - - /** - * Remove the object from the Thread instances - * @param env - */ - public void remove(Env env) { - T obj = objs.remove(Thread.currentThread()); - if(obj!=null) - obj.destroy(env); - } + private Map objs; + private long refreshed; + private Constructor cnst; + + /** + * The passed in class must implement the constructor + *
+     *   public MyClass(Env env) {
+     *     ...
+     *   }
+     * 
+ * @param clss + * @throws APIException + */ + public RefreshableThreadObject(Class clss) throws APIException { + objs = new ConcurrentHashMap<>(); + try { + cnst = clss.getConstructor(new Class[]{Env.class} ); + } catch (Exception e) { + throw new APIException(e); + } + } + + /** + * Get the "T" class from the current thread + * + * @param env + * @return T + * @throws APIException + */ + public T get(Env env) throws APIException { + Thread t = Thread.currentThread(); + T obj = objs.get(t); + if(obj==null || refreshed>obj.created()) { + try { + obj = cnst.newInstance(new Object[]{env}); + } catch (InvocationTargetException e) { + throw new APIException(e.getTargetException()); + } catch (Exception e) { + throw new APIException(e); + } + T destroyMe = objs.put(t,obj); + if(destroyMe!=null) { + destroyMe.destroy(env); + } + } + return obj; + } + + /** + * Mark the timestamp of refreshed. + * + * @param env + */ + public void refresh(Env env) { + refreshed = System.currentTimeMillis(); + } + + /** + * Remove the object from the Thread instances + * @param env + */ + public void remove(Env env) { + T obj = objs.remove(Thread.currentThread()); + if(obj!=null) + obj.destroy(env); + } } diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/util/Split.java b/misc/env/src/main/java/org/onap/aaf/misc/env/util/Split.java index efb68120..4069c329 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/util/Split.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/util/Split.java @@ -30,73 +30,73 @@ package org.onap.aaf.misc.env.util; */ public class Split { - private static final String[] BLANK = new String[0]; - - public static String[] split(char c, String value) { - if(value==null) { - return BLANK; - } + private static final String[] BLANK = new String[0]; + + public static String[] split(char c, String value) { + if(value==null) { + return BLANK; + } - // Count items to preallocate Array (memory alloc is more expensive than counting twice) - int count,idx; - for(count=1,idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,++idx),++count); - String[] rv = new String[count]; - if(count==1) { - rv[0]=value; - } else { - int last=0; - count=-1; - for(idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,idx)) { - rv[++count]=value.substring(last,idx); - last = ++idx; - } - rv[++count]=value.substring(last); - } - return rv; - } + // Count items to preallocate Array (memory alloc is more expensive than counting twice) + int count,idx; + for(count=1,idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,++idx),++count); + String[] rv = new String[count]; + if(count==1) { + rv[0]=value; + } else { + int last=0; + count=-1; + for(idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,idx)) { + rv[++count]=value.substring(last,idx); + last = ++idx; + } + rv[++count]=value.substring(last); + } + return rv; + } - public static String[] splitTrim(char c, String value) { - if(value==null) { - return BLANK; - } - // Count items to preallocate Array (memory alloc is more expensive than counting twice) - int count,idx; - for(count=1,idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,++idx),++count); - String[] rv = new String[count]; - if(count==1) { - rv[0]=value.trim(); - } else { - int last=0; - count=-1; - for(idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,idx)) { - rv[++count]=value.substring(last,idx).trim(); - last = ++idx; - } - rv[++count]=value.substring(last).trim(); - } - return rv; - } + public static String[] splitTrim(char c, String value) { + if(value==null) { + return BLANK; + } + // Count items to preallocate Array (memory alloc is more expensive than counting twice) + int count,idx; + for(count=1,idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,++idx),++count); + String[] rv = new String[count]; + if(count==1) { + rv[0]=value.trim(); + } else { + int last=0; + count=-1; + for(idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,idx)) { + rv[++count]=value.substring(last,idx).trim(); + last = ++idx; + } + rv[++count]=value.substring(last).trim(); + } + return rv; + } - public static String[] splitTrim(char c, String value, int size) { - if(value==null) { - return BLANK; - } + public static String[] splitTrim(char c, String value, int size) { + if(value==null) { + return BLANK; + } - int idx; - String[] rv = new String[size]; - if(size==1) { - rv[0]=value.trim(); - } else { - int last=0; - int count=-1; - size-=2; - for(idx=value.indexOf(c);idx>=0 && count=0 && countinitialSize is negative */ public StringBuilderOutputStream(int initialSize) { - if (initialSize < 0) { - throw new IllegalArgumentException("Negative buffer size"); - } - buf = new StringBuilder(initialSize); + if (initialSize < 0) { + throw new IllegalArgumentException("Negative buffer size"); + } + buf = new StringBuilder(initialSize); } /** * Write a single character. */ public void write(int c) { - buf.append((byte) c); + buf.append((byte) c); } /** @@ -88,15 +88,15 @@ public class StringBuilderOutputStream extends OutputStream { } @Override - public void write(byte[] b) throws IOException { - buf.append(new String(b)); - } + public void write(byte[] b) throws IOException { + buf.append(new String(b)); + } - /** + /** * Write a string. */ public void write(String str) { - buf.append(str); + buf.append(str); } /** @@ -107,23 +107,23 @@ public class StringBuilderOutputStream extends OutputStream { * @param len Number of characters to write */ public void write(String str, int off, int len) { - buf.append(str,off,len); + buf.append(str,off,len); } public StringBuilderOutputStream append(CharSequence csq) { - if (csq == null) { - write("null"); - } else { - for(int i = 0;iinitialSize is negative */ public StringBuilderWriter(int initialSize) { - if (initialSize < 0) { - throw new IllegalArgumentException("Negative buffer size"); - } - buf = new StringBuilder(initialSize); + if (initialSize < 0) { + throw new IllegalArgumentException("Negative buffer size"); + } + buf = new StringBuilder(initialSize); } /** * Write a single character. */ public void write(int c) { - buf.append((char) c); + buf.append((char) c); } /** @@ -90,7 +90,7 @@ public class StringBuilderWriter extends Writer { * Write a string. */ public void write(String str) { - buf.append(str); + buf.append(str); } /** @@ -101,23 +101,23 @@ public class StringBuilderWriter extends Writer { * @param len Number of characters to write */ public void write(String str, int off, int len) { - char[] chars = new char[len]; - str.getChars(off, off+len, chars, 0); - buf.append(chars); + char[] chars = new char[len]; + str.getChars(off, off+len, chars, 0); + buf.append(chars); } public StringBuilderWriter append(CharSequence csq) { - if (csq == null) { - write("null"); - } else { - buf.append(csq); - } - return this; + if (csq == null) { + write("null"); + } else { + buf.append(csq); + } + return this; } public StringBuilderWriter append(CharSequence csq, int start, int end) { - CharSequence cs = (csq == null ? "null" : csq); - return append(cs.subSequence(start, end)); + CharSequence cs = (csq == null ? "null" : csq); + return append(cs.subSequence(start, end)); } /** @@ -137,15 +137,15 @@ public class StringBuilderWriter extends Writer { * @since 1.5 */ public StringBuilderWriter append(char c) { - buf.append(c); - return this; + buf.append(c); + return this; } /** * Return the buffer's current value as a string. */ public String toString() { - return buf.toString(); + return buf.toString(); } /** @@ -154,19 +154,19 @@ public class StringBuilderWriter extends Writer { * @return StringBuffer holding the current buffer value. */ public StringBuilder getBuffer() { - return buf; + return buf; } public void reset() { - buf.setLength(0); + buf.setLength(0); } - @Override - public void flush() throws IOException { - } + @Override + public void flush() throws IOException { + } - @Override - public void close() throws IOException { - } + @Override + public void close() throws IOException { + } } diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/JU_APIExceptionTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/JU_APIExceptionTest.java index b0c60878..c1d7f6b1 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/JU_APIExceptionTest.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/JU_APIExceptionTest.java @@ -27,45 +27,45 @@ import org.junit.Test; public class JU_APIExceptionTest { - private static final String EXCEPTION_MESSAGE = "New API Exception for test"; + private static final String EXCEPTION_MESSAGE = "New API Exception for test"; - @Before - public void setUp() throws Exception { - } + @Before + public void setUp() throws Exception { + } - @Test - public void testNewAPIExceptionWithMessage() { - APIException exception = new APIException(EXCEPTION_MESSAGE); + @Test + public void testNewAPIExceptionWithMessage() { + APIException exception = new APIException(EXCEPTION_MESSAGE); - assertEquals(exception.getMessage(), EXCEPTION_MESSAGE); - } + assertEquals(exception.getMessage(), EXCEPTION_MESSAGE); + } - @Test - public void testNewAPIExceptionCreatedWithMessageAndThrowable() { - Throwable throwable = new Throwable(); - APIException exception = new APIException(EXCEPTION_MESSAGE, throwable); + @Test + public void testNewAPIExceptionCreatedWithMessageAndThrowable() { + Throwable throwable = new Throwable(); + APIException exception = new APIException(EXCEPTION_MESSAGE, throwable); - assertEquals(exception.getMessage(), EXCEPTION_MESSAGE); - assertEquals(exception.getCause(), throwable); - } + assertEquals(exception.getMessage(), EXCEPTION_MESSAGE); + assertEquals(exception.getCause(), throwable); + } - @Test - public void testNewAPIExceptionCreatedWithThrowable() { - Throwable throwable = new Throwable(); - APIException exception = new APIException(throwable); + @Test + public void testNewAPIExceptionCreatedWithThrowable() { + Throwable throwable = new Throwable(); + APIException exception = new APIException(throwable); - assertEquals(exception.getCause(), throwable); - } + assertEquals(exception.getCause(), throwable); + } - @Test - public void testPayloadSetter() { - Throwable throwable = new Throwable(); - Object payload = new Object(); + @Test + public void testPayloadSetter() { + Throwable throwable = new Throwable(); + Object payload = new Object(); - APIException exception = new APIException(throwable); + APIException exception = new APIException(throwable); - exception.setPayload(payload); + exception.setPayload(payload); - assertEquals(exception.getPayload(), payload); - } + assertEquals(exception.getPayload(), payload); + } } diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/JU_BasicTransTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/JU_BasicTransTest.java index 6a090167..0525bd66 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/JU_BasicTransTest.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/JU_BasicTransTest.java @@ -33,77 +33,77 @@ import org.onap.aaf.misc.env.impl.BasicTrans; @RunWith(MockitoJUnitRunner.class) public class JU_BasicTransTest { - BasicTrans trans = null; - - @Mock - private EnvJAXB env; - - @Mock - private TimeTaken timeTaken; - - @Before - public void setUp() throws Exception { - trans = new BasicTrans(env); - } - - @Test - public void testSlot() { - Slot slot = new Slot(1, "XML"); - when(env.slot("XML")).thenReturn(slot); - - Slot outputSlot = trans.slot("XML"); - Object[] state = new Object[2]; - - slot.put(state, "JSON"); - - assertEquals(slot.get(state), "JSON"); - assertEquals(slot.getKey(), outputSlot.getKey()); - assertEquals(slot.toString(), outputSlot.toString()); - } - - @Test - public void testGetStaticSlot() { - StaticSlot staticSlot = new StaticSlot(1, "XML"); - when(env.get(staticSlot)).thenReturn(staticSlot.toString()); - - assertEquals(staticSlot.toString(), trans.get(staticSlot)); - } - - @Test - public void testGetStaticSlotWithT() { - StaticSlot staticSlot = new StaticSlot(1, "XML"); - when(env.get(staticSlot, "XML")).thenReturn(staticSlot.getKey()); - - assertEquals(staticSlot.getKey(), trans.get(staticSlot, "XML")); - } - - @Test - public void testSetProperty() { - String tag = "tag"; - String value = "value"; - String defltValue = "diffValue"; - when(env.setProperty(tag, value)).thenReturn(value); - when(env.getProperty(tag)).thenReturn(value); - when(env.getProperty(tag, defltValue)).thenReturn(defltValue); - - assertEquals(value, trans.setProperty(tag, value)); - assertEquals(value, trans.getProperty(tag)); - assertEquals(defltValue, trans.getProperty(tag, defltValue)); - } - - @Test - public void testDecryptor() { - when(env.decryptor()).thenReturn(Decryptor.NULL); - - assertEquals(Decryptor.NULL, trans.decryptor()); - assertEquals("tag", trans.decryptor().decrypt("tag")); - } - - @Test - public void testEncryptor() { - when(env.encryptor()).thenReturn(Encryptor.NULL); - - assertEquals(Encryptor.NULL, trans.encryptor()); - assertEquals("tag", trans.encryptor().encrypt("tag")); - } + BasicTrans trans = null; + + @Mock + private EnvJAXB env; + + @Mock + private TimeTaken timeTaken; + + @Before + public void setUp() throws Exception { + trans = new BasicTrans(env); + } + + @Test + public void testSlot() { + Slot slot = new Slot(1, "XML"); + when(env.slot("XML")).thenReturn(slot); + + Slot outputSlot = trans.slot("XML"); + Object[] state = new Object[2]; + + slot.put(state, "JSON"); + + assertEquals(slot.get(state), "JSON"); + assertEquals(slot.getKey(), outputSlot.getKey()); + assertEquals(slot.toString(), outputSlot.toString()); + } + + @Test + public void testGetStaticSlot() { + StaticSlot staticSlot = new StaticSlot(1, "XML"); + when(env.get(staticSlot)).thenReturn(staticSlot.toString()); + + assertEquals(staticSlot.toString(), trans.get(staticSlot)); + } + + @Test + public void testGetStaticSlotWithT() { + StaticSlot staticSlot = new StaticSlot(1, "XML"); + when(env.get(staticSlot, "XML")).thenReturn(staticSlot.getKey()); + + assertEquals(staticSlot.getKey(), trans.get(staticSlot, "XML")); + } + + @Test + public void testSetProperty() { + String tag = "tag"; + String value = "value"; + String defltValue = "diffValue"; + when(env.setProperty(tag, value)).thenReturn(value); + when(env.getProperty(tag)).thenReturn(value); + when(env.getProperty(tag, defltValue)).thenReturn(defltValue); + + assertEquals(value, trans.setProperty(tag, value)); + assertEquals(value, trans.getProperty(tag)); + assertEquals(defltValue, trans.getProperty(tag, defltValue)); + } + + @Test + public void testDecryptor() { + when(env.decryptor()).thenReturn(Decryptor.NULL); + + assertEquals(Decryptor.NULL, trans.decryptor()); + assertEquals("tag", trans.decryptor().decrypt("tag")); + } + + @Test + public void testEncryptor() { + when(env.encryptor()).thenReturn(Encryptor.NULL); + + assertEquals(Encryptor.NULL, trans.encryptor()); + assertEquals("tag", trans.encryptor().encrypt("tag")); + } } diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/JU_LogTargetTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/JU_LogTargetTest.java index 474f646c..caaca1d1 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/JU_LogTargetTest.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/JU_LogTargetTest.java @@ -34,54 +34,54 @@ import org.mockito.Mock; public class JU_LogTargetTest { - @Mock - Throwable t; + @Mock + Throwable t; - @Before - public void setup() { - t = mock(Throwable.class); - } + @Before + public void setup() { + t = mock(Throwable.class); + } - @Test - public void testLogTargetNull() { - LogTarget nullTarget = LogTarget.NULL; + @Test + public void testLogTargetNull() { + LogTarget nullTarget = LogTarget.NULL; - // Expect methods doing nothing as no implemenation provided. - nullTarget.log(new Throwable(), null, null); - nullTarget.log("String", null); - nullTarget.printf(null, null, null); + // Expect methods doing nothing as no implemenation provided. + nullTarget.log(new Throwable(), null, null); + nullTarget.log("String", null); + nullTarget.printf(null, null, null); - assertFalse(nullTarget.isLoggable()); - } + assertFalse(nullTarget.isLoggable()); + } - @Test - public void testLogTargetSysOut() { - LogTarget outTarget = LogTarget.SYSOUT; + @Test + public void testLogTargetSysOut() { + LogTarget outTarget = LogTarget.SYSOUT; - outTarget.printf("format", new Date()); - outTarget.log("null", null, null); + outTarget.printf("format", new Date()); + outTarget.log("null", null, null); - outTarget.log(t); - outTarget.log(t, "First String Object"); + outTarget.log(t); + outTarget.log(t, "First String Object"); - assertTrue(outTarget.isLoggable()); + assertTrue(outTarget.isLoggable()); - verify(t, times(2)).printStackTrace(System.out); - } + verify(t, times(2)).printStackTrace(System.out); + } - @Test - public void testLogTargetSysErr() { - LogTarget errTarget = LogTarget.SYSERR; + @Test + public void testLogTargetSysErr() { + LogTarget errTarget = LogTarget.SYSERR; - errTarget.printf("format", new Date()); - errTarget.log("null", "null"); + errTarget.printf("format", new Date()); + errTarget.log("null", "null"); - errTarget.log(t); - errTarget.log(t, "First String Object"); + errTarget.log(t); + errTarget.log(t, "First String Object"); - assertTrue(errTarget.isLoggable()); + assertTrue(errTarget.isLoggable()); - verify(t, times(2)).printStackTrace(System.err); - } + verify(t, times(2)).printStackTrace(System.err); + } } diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_BasicEnvTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_BasicEnvTest.java index 65dc7c50..b15972ef 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_BasicEnvTest.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_BasicEnvTest.java @@ -40,141 +40,141 @@ import org.onap.aaf.misc.env.TimeTaken; public class JU_BasicEnvTest { - @Mock - Decryptor decrypt; + @Mock + Decryptor decrypt; - @Mock - Encryptor encrypt; + @Mock + Encryptor encrypt; - @Before - public void setup() { - decrypt = mock(Decryptor.class); - encrypt = mock(Encryptor.class); - } + @Before + public void setup() { + decrypt = mock(Decryptor.class); + encrypt = mock(Encryptor.class); + } - @Test - public void testLogTarget() { - Properties prop = new Properties(); - BasicEnv env = new BasicEnv(prop); + @Test + public void testLogTarget() { + Properties prop = new Properties(); + BasicEnv env = new BasicEnv(prop); - assertEquals(env.fatal(), LogTarget.SYSERR); - assertEquals(env.error(), LogTarget.SYSERR); - assertEquals(env.audit(), LogTarget.SYSOUT); - assertEquals(env.warn(), LogTarget.SYSERR); - assertEquals(env.init(), LogTarget.SYSOUT); - assertEquals(env.info(), LogTarget.SYSOUT); - assertEquals(env.debug(), LogTarget.NULL); - assertEquals(env.trace(), LogTarget.NULL); + assertEquals(env.fatal(), LogTarget.SYSERR); + assertEquals(env.error(), LogTarget.SYSERR); + assertEquals(env.audit(), LogTarget.SYSOUT); + assertEquals(env.warn(), LogTarget.SYSERR); + assertEquals(env.init(), LogTarget.SYSOUT); + assertEquals(env.info(), LogTarget.SYSOUT); + assertEquals(env.debug(), LogTarget.NULL); + assertEquals(env.trace(), LogTarget.NULL); - env.debug(LogTarget.SYSOUT); - assertEquals(env.debug(), LogTarget.SYSOUT); + env.debug(LogTarget.SYSOUT); + assertEquals(env.debug(), LogTarget.SYSOUT); - assertNull(env.getProperty("key")); - assertEquals("default", env.getProperty("key", "default")); + assertNull(env.getProperty("key")); + assertEquals("default", env.getProperty("key", "default")); - env.setProperty("key", "value"); - assertEquals("value", env.getProperty("key", "default")); + env.setProperty("key", "value"); + assertEquals("value", env.getProperty("key", "default")); - Properties filteredProperties = env.getProperties("key"); - assertEquals(filteredProperties.size(), 1); + Properties filteredProperties = env.getProperties("key"); + assertEquals(filteredProperties.size(), 1); - env.setProperty("key", null); - assertEquals("default", env.getProperty("key", "default")); + env.setProperty("key", null); + assertEquals("default", env.getProperty("key", "default")); - filteredProperties = env.getProperties("key1"); - assertEquals(filteredProperties.size(), 0); + filteredProperties = env.getProperties("key1"); + assertEquals(filteredProperties.size(), 0); - filteredProperties = env.getProperties(); - assertEquals(filteredProperties.size(), 0); + filteredProperties = env.getProperties(); + assertEquals(filteredProperties.size(), 0); - } + } - @Test - public void testBasicEnv() { - Applet applet = null; + @Test + public void testBasicEnv() { + Applet applet = null; - BasicEnv env = new BasicEnv(applet, "tag1", "tag2"); + BasicEnv env = new BasicEnv(applet, "tag1", "tag2"); - TimeTaken tt = env.start("Name", 2); + TimeTaken tt = env.start("Name", 2); - long end = tt.end(); - StringBuilder sb = new StringBuilder(); + long end = tt.end(); + StringBuilder sb = new StringBuilder(); - assertEquals(tt.toString(), "Name " + (end - tt.start) / 1000000f + "ms "); - tt.output(sb); - assertEquals(sb.toString(), "XML Name " + (end - tt.start) / 1000000f + "ms"); + assertEquals(tt.toString(), "Name " + (end - tt.start) / 1000000f + "ms "); + tt.output(sb); + assertEquals(sb.toString(), "XML Name " + (end - tt.start) / 1000000f + "ms"); - env.set(decrypt); - assertEquals(env.decryptor(), decrypt); - env.set(encrypt); - assertEquals(env.encryptor(), encrypt); - } + env.set(decrypt); + assertEquals(env.decryptor(), decrypt); + env.set(encrypt); + assertEquals(env.encryptor(), encrypt); + } - @Test - public void testBasicEnvDiffFlag() { - Properties prop = new Properties(); + @Test + public void testBasicEnvDiffFlag() { + Properties prop = new Properties(); - BasicEnv env = new BasicEnv("tag1", prop); + BasicEnv env = new BasicEnv("tag1", prop); - TimeTaken tt = env.start("Name", 1); + TimeTaken tt = env.start("Name", 1); - long end = tt.end(); - StringBuilder sb = new StringBuilder(); + long end = tt.end(); + StringBuilder sb = new StringBuilder(); - assertEquals(tt.toString(), "Name " + (end - tt.start) / 1000000f + "ms "); - tt.output(sb); - assertEquals(sb.toString(), "REMOTE Name " + (end - tt.start) / 1000000f + "ms"); + assertEquals(tt.toString(), "Name " + (end - tt.start) / 1000000f + "ms "); + tt.output(sb); + assertEquals(sb.toString(), "REMOTE Name " + (end - tt.start) / 1000000f + "ms"); - tt = env.start("New Name", 4); - tt.size(10); - sb = new StringBuilder(); - tt.output(sb); - assertEquals(tt.toString(), "New Name " + (end - tt.start) / 1000000f + "ms 10"); - assertEquals(sb.toString(), "JSON New Name " + (end - tt.start) / 1000000f + "ms size: 10"); + tt = env.start("New Name", 4); + tt.size(10); + sb = new StringBuilder(); + tt.output(sb); + assertEquals(tt.toString(), "New Name " + (end - tt.start) / 1000000f + "ms 10"); + assertEquals(sb.toString(), "JSON New Name " + (end - tt.start) / 1000000f + "ms size: 10"); - env.staticSlot("tag", "prop"); + env.staticSlot("tag", "prop"); - if (System.getProperties().keySet().iterator().hasNext()) { - String key = (String) System.getProperties().keySet().iterator().next(); + if (System.getProperties().keySet().iterator().hasNext()) { + String key = (String) System.getProperties().keySet().iterator().next(); - env.loadFromSystemPropsStartsWith(key); - assertEquals(env.getProperty(key), System.getProperties().get(key)); - } + env.loadFromSystemPropsStartsWith(key); + assertEquals(env.getProperty(key), System.getProperties().get(key)); + } - BasicTrans trans = env.newTrans(); - assertEquals(trans.delegate, env); + BasicTrans trans = env.newTrans(); + assertEquals(trans.delegate, env); - } + } - @Test - public void testLoadProperties() throws IOException { - Properties prop = new Properties(); + @Test + public void testLoadProperties() throws IOException { + Properties prop = new Properties(); - BasicEnv env = new BasicEnv("tag1", prop); + BasicEnv env = new BasicEnv("tag1", prop); - env.loadPropFiles("tag1", null); - env.setProperty("tag1", "propfile.properties"); - env.loadPropFiles("tag1", null); + env.loadPropFiles("tag1", null); + env.setProperty("tag1", "propfile.properties"); + env.loadPropFiles("tag1", null); - assertEquals(env.getProperty("prop1"), "New Property"); + assertEquals(env.getProperty("prop1"), "New Property"); - env.loadToSystemPropsStartsWith("prop1"); + env.loadToSystemPropsStartsWith("prop1"); - assertTrue(System.getProperties().keySet().contains("prop1")); - assertEquals(System.getProperties().get("prop1"), "New Property"); - } + assertTrue(System.getProperties().keySet().contains("prop1")); + assertEquals(System.getProperties().get("prop1"), "New Property"); + } - @After - public void tearDown() throws IOException { - /* - * File file = new File("./log-Append" + ending + "_0.log"); if (file.exists()) - * { Files.delete(Paths.get(file.getAbsolutePath())); } file = new - * File("./log-Append" + ending + "_1.log"); if (file.exists()) { - * Files.delete(Paths.get(file.getAbsolutePath())); } file = new File("./Append" - * + ending + "_0.log"); if (file.exists()) { - * Files.delete(Paths.get(file.getAbsolutePath())); } file = new File("./Append" - * + ending + "_1.log"); if (file.exists()) { - * Files.delete(Paths.get(file.getAbsolutePath())); } - */ - } + @After + public void tearDown() throws IOException { + /* + * File file = new File("./log-Append" + ending + "_0.log"); if (file.exists()) + * { Files.delete(Paths.get(file.getAbsolutePath())); } file = new + * File("./log-Append" + ending + "_1.log"); if (file.exists()) { + * Files.delete(Paths.get(file.getAbsolutePath())); } file = new File("./Append" + * + ending + "_0.log"); if (file.exists()) { + * Files.delete(Paths.get(file.getAbsolutePath())); } file = new File("./Append" + * + ending + "_1.log"); if (file.exists()) { + * Files.delete(Paths.get(file.getAbsolutePath())); } + */ + } } diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_EnvFactoryTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_EnvFactoryTest.java index f6c6912d..e5d0ed52 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_EnvFactoryTest.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_EnvFactoryTest.java @@ -31,49 +31,49 @@ import org.onap.aaf.misc.env.TransJAXB; public class JU_EnvFactoryTest { - @Before - public void setUp() throws Exception { - } + @Before + public void setUp() throws Exception { + } - @Test - public void testSingleton() { - BasicEnv singleton = EnvFactory.singleton(); + @Test + public void testSingleton() { + BasicEnv singleton = EnvFactory.singleton(); - assertEquals(EnvFactory.singleton, singleton); - } + assertEquals(EnvFactory.singleton, singleton); + } - @Test - public void testSetSingleton() { - String[] str = { "argument1" }; - BasicEnv env = new BasicEnv("tag", str); - EnvFactory.setSingleton(env); + @Test + public void testSetSingleton() { + String[] str = { "argument1" }; + BasicEnv env = new BasicEnv("tag", str); + EnvFactory.setSingleton(env); - assertEquals(EnvFactory.singleton(), env); - } + assertEquals(EnvFactory.singleton(), env); + } - @Test - public void testNewTrans() { - TransJAXB newTrans = EnvFactory.newTrans(); + @Test + public void testNewTrans() { + TransJAXB newTrans = EnvFactory.newTrans(); - assertTrue(newTrans instanceof BasicTrans); - } + assertTrue(newTrans instanceof BasicTrans); + } - @Test - public void testNewTransEnvJAXB() { - EnvJAXB env = new BasicEnv(""); + @Test + public void testNewTransEnvJAXB() { + EnvJAXB env = new BasicEnv(""); - TransJAXB trans = EnvFactory.newTrans(env); + TransJAXB trans = EnvFactory.newTrans(env); - assertTrue(trans instanceof BasicTrans); - } + assertTrue(trans instanceof BasicTrans); + } - @Test - public void testTransCreator() { - TransCreate transCreator = EnvFactory.transCreator(); + @Test + public void testTransCreator() { + TransCreate transCreator = EnvFactory.transCreator(); - TransJAXB newTrans = transCreator.newTrans(); + TransJAXB newTrans = transCreator.newTrans(); - assertTrue(newTrans instanceof BasicTrans); - } + assertTrue(newTrans instanceof BasicTrans); + } } diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_Log4JLogTargetTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_Log4JLogTargetTest.java index e3f54929..914a01b0 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_Log4JLogTargetTest.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_Log4JLogTargetTest.java @@ -40,23 +40,23 @@ import org.powermock.modules.junit4.PowerMockRunner; @PrepareForTest({ Log4JLogTarget.class, Logger.class }) public class JU_Log4JLogTargetTest { - @Mock - Logger log; + @Mock + Logger log; - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - PowerMockito.mockStatic(Logger.class); - when(Logger.getLogger("Info")).thenReturn(log); - when(log.isEnabledFor(Level.DEBUG)).thenReturn(false); - } + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + PowerMockito.mockStatic(Logger.class); + when(Logger.getLogger("Info")).thenReturn(log); + when(log.isEnabledFor(Level.DEBUG)).thenReturn(false); + } - @Test - public void test() throws APIException { - Log4JLogTarget target = new Log4JLogTarget(null, Level.INFO); - Log4JLogTarget target1 = new Log4JLogTarget("Info", Level.DEBUG); + @Test + public void test() throws APIException { + Log4JLogTarget target = new Log4JLogTarget(null, Level.INFO); + Log4JLogTarget target1 = new Log4JLogTarget("Info", Level.DEBUG); - assertFalse(target1.isLoggable()); + assertFalse(target1.isLoggable()); - } + } } \ No newline at end of file diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/jaxb/JU_JAXBDataTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/jaxb/JU_JAXBDataTest.java index 80de9b7b..6780a6a8 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/jaxb/JU_JAXBDataTest.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/jaxb/JU_JAXBDataTest.java @@ -43,138 +43,138 @@ import org.onap.aaf.misc.env.old.Stringifier; public class JU_JAXBDataTest { - @Mock - private Objectifier objfr; + @Mock + private Objectifier objfr; - private String object = "Text"; + private String object = "Text"; - @Mock - private Stringifier strfr; + @Mock + private Stringifier strfr; - @Mock - private IOStringifier ioStrfr; + @Mock + private IOStringifier ioStrfr; - @Mock - private JAXBDF df; + @Mock + private JAXBDF df; - @Mock - private Env env; + @Mock + private Env env; - @Mock - private Class typeClass; + @Mock + private Class typeClass; - @Mock - private OutputStream os; + @Mock + private OutputStream os; - @Mock - private Writer writer; + @Mock + private Writer writer; - @Mock - private EnvJAXB env1; + @Mock + private EnvJAXB env1; - @Before - public void setUp() throws Exception { - writer = mock(Writer.class); - os = mock(OutputStream.class); - strfr = mock(Stringifier.class); - ioStrfr = mock(IOStringifier.class); - objfr = mock(Objectifier.class); - env1 = mock(EnvJAXB.class); - } + @Before + public void setUp() throws Exception { + writer = mock(Writer.class); + os = mock(OutputStream.class); + strfr = mock(Stringifier.class); + ioStrfr = mock(IOStringifier.class); + objfr = mock(Objectifier.class); + env1 = mock(EnvJAXB.class); + } - @Test - public void testJAXBDataEnv() throws APIException, IOException { - JAXBData jaxb = new JAXBData(env, df, strfr, objfr, object, typeClass); + @Test + public void testJAXBDataEnv() throws APIException, IOException { + JAXBData jaxb = new JAXBData(env, df, strfr, objfr, object, typeClass); - when(objfr.objectify(env, object)).thenReturn("String1"); + when(objfr.objectify(env, object)).thenReturn("String1"); - jaxb.to(os); - jaxb.to(writer); + jaxb.to(os); + jaxb.to(writer); - verify(writer).write(object); - verify(os).write(object.getBytes()); + verify(writer).write(object); + verify(os).write(object.getBytes()); - assertEquals(jaxb.asString(), object); - assertEquals(jaxb.asString(null), object); - assertEquals(jaxb.toString(), object); - assertEquals(jaxb.getTypeClass(), typeClass); - assertEquals(jaxb.out(null), jaxb); - assertEquals(jaxb.in(null), jaxb); - assertTrue(jaxb.getInputStream() instanceof ByteArrayInputStream); - assertEquals(jaxb.asObject(), "String1"); - assertEquals(jaxb.asObject(env1), "String1"); - assertEquals(jaxb.toString(), object); - } + assertEquals(jaxb.asString(), object); + assertEquals(jaxb.asString(null), object); + assertEquals(jaxb.toString(), object); + assertEquals(jaxb.getTypeClass(), typeClass); + assertEquals(jaxb.out(null), jaxb); + assertEquals(jaxb.in(null), jaxb); + assertTrue(jaxb.getInputStream() instanceof ByteArrayInputStream); + assertEquals(jaxb.asObject(), "String1"); + assertEquals(jaxb.asObject(env1), "String1"); + assertEquals(jaxb.toString(), object); + } - @Test - public void testJAXBDataEnvForObjectifier() throws APIException, IOException { - JAXBData jaxb = new JAXBData(env, df, strfr, objfr, object, typeClass); + @Test + public void testJAXBDataEnvForObjectifier() throws APIException, IOException { + JAXBData jaxb = new JAXBData(env, df, strfr, objfr, object, typeClass); - when(objfr.objectify(env1, object)).thenReturn("String1"); + when(objfr.objectify(env1, object)).thenReturn("String1"); - assertEquals(jaxb.asObject(env1), "String1"); - } + assertEquals(jaxb.asObject(env1), "String1"); + } - @Test - public void testJAXBDataEnvWithObject() throws APIException, IOException { - JAXBData jaxb = new JAXBData(env, df, strfr, objfr, object); + @Test + public void testJAXBDataEnvWithObject() throws APIException, IOException { + JAXBData jaxb = new JAXBData(env, df, strfr, objfr, object); - when(strfr.stringify(env, object, new boolean[] { false, false })).thenReturn(object); + when(strfr.stringify(env, object, new boolean[] { false, false })).thenReturn(object); - jaxb.to(os); + jaxb.to(os); - verify(os).write(object.getBytes()); + verify(os).write(object.getBytes()); - assertEquals(jaxb.asString(), object); - assertEquals(jaxb.asString(null), object); - assertEquals(jaxb.toString(), object); - } + assertEquals(jaxb.asString(), object); + assertEquals(jaxb.asString(null), object); + assertEquals(jaxb.toString(), object); + } - @Test - public void testJAXBDataEnvForWriter() throws APIException, IOException { - JAXBData jaxb = new JAXBData(env, df, strfr, objfr, object); + @Test + public void testJAXBDataEnvForWriter() throws APIException, IOException { + JAXBData jaxb = new JAXBData(env, df, strfr, objfr, object); - when(strfr.stringify(env, object, new boolean[] { false, false })).thenReturn(object); + when(strfr.stringify(env, object, new boolean[] { false, false })).thenReturn(object); - jaxb.to(writer); + jaxb.to(writer); - verify(writer).write(object); + verify(writer).write(object); - assertEquals(jaxb.asString(), object); - assertEquals(jaxb.asString(null), object); - assertEquals(jaxb.toString(), object); - assertEquals(jaxb.asObject(), object); - assertEquals(jaxb.asObject(null), object); - } + assertEquals(jaxb.asString(), object); + assertEquals(jaxb.asString(null), object); + assertEquals(jaxb.toString(), object); + assertEquals(jaxb.asObject(), object); + assertEquals(jaxb.asObject(null), object); + } - @Test - public void testAsStringWithNullString() throws APIException, IOException { - JAXBData jaxb = new JAXBData(env, df, strfr, objfr, object); + @Test + public void testAsStringWithNullString() throws APIException, IOException { + JAXBData jaxb = new JAXBData(env, df, strfr, objfr, object); - when(strfr.stringify(env, object, new boolean[] { false, false })).thenReturn(object); + when(strfr.stringify(env, object, new boolean[] { false, false })).thenReturn(object); - assertEquals(jaxb.asString(), object); - } + assertEquals(jaxb.asString(), object); + } - @Test - public void testAsStringWithNullStringWithEnv() throws APIException, IOException { - JAXBData jaxb = new JAXBData(env, df, strfr, objfr, object); + @Test + public void testAsStringWithNullStringWithEnv() throws APIException, IOException { + JAXBData jaxb = new JAXBData(env, df, strfr, objfr, object); - when(strfr.stringify(env1, object)).thenReturn(object); + when(strfr.stringify(env1, object)).thenReturn(object); - assertEquals(jaxb.asString(env1), object); - } + assertEquals(jaxb.asString(env1), object); + } - @Test - public void testToWithIOStrifier() throws APIException, IOException { - JAXBData jaxb = new JAXBData(env, df, strfr, objfr, object); + @Test + public void testToWithIOStrifier() throws APIException, IOException { + JAXBData jaxb = new JAXBData(env, df, strfr, objfr, object); - jaxb.option(0); + jaxb.option(0); - when(strfr.stringify(env1, object)).thenReturn(object); - when(strfr.stringify(env, object, new boolean[] { false, false })).thenReturn(object); + when(strfr.stringify(env1, object)).thenReturn(object); + when(strfr.stringify(env, object, new boolean[] { false, false })).thenReturn(object); - assertTrue(jaxb.getInputStream() instanceof ByteArrayInputStream); - assertEquals(jaxb.asString(env1), object); - } + assertTrue(jaxb.getInputStream() instanceof ByteArrayInputStream); + assertEquals(jaxb.asString(env1), object); + } } diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_ChronoTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_ChronoTest.java index 05fd6fbf..c113c86e 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_ChronoTest.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_ChronoTest.java @@ -36,204 +36,204 @@ import org.junit.Test; public class JU_ChronoTest { - @Before - public void setUp() throws Exception { - } - - @Test - public void testFormatter8601() { - Chrono.Formatter8601 formatter = new Chrono.Formatter8601(); + @Before + public void setUp() throws Exception { + } + + @Test + public void testFormatter8601() { + Chrono.Formatter8601 formatter = new Chrono.Formatter8601(); - LogRecord record = new LogRecord(Level.WARNING, "Log Record to test log formating"); + LogRecord record = new LogRecord(Level.WARNING, "Log Record to test log formating"); - Date date = new Date(118, 02, 02); - long time = date.getTime(); + Date date = new Date(118, 02, 02); + long time = date.getTime(); - record.setMillis(time); + record.setMillis(time); - String expectedString = Chrono.dateFmt.format(date) + " " + record.getThreadID() + " " + record.getLevel() - + ": " + record.getMessage() + "\n"; - assertEquals(expectedString, formatter.format(record)); - } + String expectedString = Chrono.dateFmt.format(date) + " " + record.getThreadID() + " " + record.getLevel() + + ": " + record.getMessage() + "\n"; + assertEquals(expectedString, formatter.format(record)); + } - @Test - public void testTimeStampWithDate() { - Date date = Calendar.getInstance().getTime(); - XMLGregorianCalendar timeStamp = Chrono.timeStamp(date); + @Test + public void testTimeStampWithDate() { + Date date = Calendar.getInstance().getTime(); + XMLGregorianCalendar timeStamp = Chrono.timeStamp(date); - GregorianCalendar gc = new GregorianCalendar(); - gc.setTime(date); - XMLGregorianCalendar expectedCalendar = Chrono.xmlDatatypeFactory.newXMLGregorianCalendar(gc); + GregorianCalendar gc = new GregorianCalendar(); + gc.setTime(date); + XMLGregorianCalendar expectedCalendar = Chrono.xmlDatatypeFactory.newXMLGregorianCalendar(gc); - assertEquals(expectedCalendar, timeStamp); - } + assertEquals(expectedCalendar, timeStamp); + } - @Test - public void testUTCStamp() { - final Date date = Calendar.getInstance().getTime(); - String expectedUTCTime = Chrono.utcFmt.format(date); + @Test + public void testUTCStamp() { + final Date date = Calendar.getInstance().getTime(); + String expectedUTCTime = Chrono.utcFmt.format(date); - String stamp = Chrono.utcStamp(date); + String stamp = Chrono.utcStamp(date); - assertEquals(stamp, expectedUTCTime); + assertEquals(stamp, expectedUTCTime); - Date date1 = null; - assertEquals("", Chrono.utcStamp(date1)); + Date date1 = null; + assertEquals("", Chrono.utcStamp(date1)); - GregorianCalendar gc = null; - assertEquals(Chrono.utcStamp(gc), ""); - gc = new GregorianCalendar(); - gc.setTime(date); - assertEquals(Chrono.utcStamp(gc), expectedUTCTime); + GregorianCalendar gc = null; + assertEquals(Chrono.utcStamp(gc), ""); + gc = new GregorianCalendar(); + gc.setTime(date); + assertEquals(Chrono.utcStamp(gc), expectedUTCTime); - XMLGregorianCalendar xgc = null; - assertEquals(Chrono.utcStamp(xgc), ""); - xgc = Chrono.timeStamp(gc); - assertEquals(Chrono.utcStamp(xgc), expectedUTCTime); + XMLGregorianCalendar xgc = null; + assertEquals(Chrono.utcStamp(xgc), ""); + xgc = Chrono.timeStamp(gc); + assertEquals(Chrono.utcStamp(xgc), expectedUTCTime); - } + } - @Test - public void testDateStamp() { - final Date date = Calendar.getInstance().getTime(); - String expectedUTCTime = Chrono.dateFmt.format(date); + @Test + public void testDateStamp() { + final Date date = Calendar.getInstance().getTime(); + String expectedUTCTime = Chrono.dateFmt.format(date); - String stamp = Chrono.dateStamp(date); + String stamp = Chrono.dateStamp(date); - assertEquals(stamp, expectedUTCTime); + assertEquals(stamp, expectedUTCTime); - Date date1 = null; - assertEquals("", Chrono.dateStamp(date1)); + Date date1 = null; + assertEquals("", Chrono.dateStamp(date1)); - GregorianCalendar gc = null; - assertEquals(Chrono.dateStamp(gc), ""); - gc = new GregorianCalendar(); - gc.setTime(date); - assertEquals(Chrono.dateStamp(gc), expectedUTCTime); + GregorianCalendar gc = null; + assertEquals(Chrono.dateStamp(gc), ""); + gc = new GregorianCalendar(); + gc.setTime(date); + assertEquals(Chrono.dateStamp(gc), expectedUTCTime); - XMLGregorianCalendar xgc = null; - assertEquals(Chrono.dateStamp(xgc), ""); - xgc = Chrono.timeStamp(gc); - assertEquals(Chrono.dateStamp(xgc), expectedUTCTime); - } + XMLGregorianCalendar xgc = null; + assertEquals(Chrono.dateStamp(xgc), ""); + xgc = Chrono.timeStamp(gc); + assertEquals(Chrono.dateStamp(xgc), expectedUTCTime); + } - @Test - public void testDateTime() { - final Date date = Calendar.getInstance().getTime(); - date.setTime(1525023883297L); + @Test + public void testDateTime() { + final Date date = Calendar.getInstance().getTime(); + date.setTime(1525023883297L); - GregorianCalendar gc = null; - assertEquals(Chrono.dateTime(gc), ""); - gc = new GregorianCalendar(); - gc.setTime(date); + GregorianCalendar gc = null; + assertEquals(Chrono.dateTime(gc), ""); + gc = new GregorianCalendar(); + gc.setTime(date); - // String expectedDateTime = "2018-04-29T11:14:43.297" + sign + hourOffSet + ":" - // + minOffSet; + // String expectedDateTime = "2018-04-29T11:14:43.297" + sign + hourOffSet + ":" + // + minOffSet; - TimeZone tz = gc.getTimeZone(); - int tz1 = (tz.getRawOffset() + tz.getDSTSavings()) / 0x8CA0; - int tz1abs = Math.abs(tz1); - String expectedDateTime = String.format("%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d:%02d", - gc.get(GregorianCalendar.YEAR), gc.get(GregorianCalendar.MONTH) + 1, - gc.get(GregorianCalendar.DAY_OF_MONTH), gc.get(GregorianCalendar.HOUR), - gc.get(GregorianCalendar.MINUTE), gc.get(GregorianCalendar.SECOND), - gc.get(GregorianCalendar.MILLISECOND), tz1 == tz1abs ? '+' : '-', tz1abs / 100, - ((tz1abs - (tz1abs / 100) * 100) * 6) / 10 // Get the "10s", then convert to mins (without losing int - // place) - ); + TimeZone tz = gc.getTimeZone(); + int tz1 = (tz.getRawOffset() + tz.getDSTSavings()) / 0x8CA0; + int tz1abs = Math.abs(tz1); + String expectedDateTime = String.format("%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d:%02d", + gc.get(GregorianCalendar.YEAR), gc.get(GregorianCalendar.MONTH) + 1, + gc.get(GregorianCalendar.DAY_OF_MONTH), gc.get(GregorianCalendar.HOUR), + gc.get(GregorianCalendar.MINUTE), gc.get(GregorianCalendar.SECOND), + gc.get(GregorianCalendar.MILLISECOND), tz1 == tz1abs ? '+' : '-', tz1abs / 100, + ((tz1abs - (tz1abs / 100) * 100) * 6) / 10 // Get the "10s", then convert to mins (without losing int + // place) + ); - String stamp = Chrono.dateTime(date); + String stamp = Chrono.dateTime(date); - assertEquals(stamp, expectedDateTime); + assertEquals(stamp, expectedDateTime); - assertEquals(Chrono.dateTime(gc), expectedDateTime); + assertEquals(Chrono.dateTime(gc), expectedDateTime); - XMLGregorianCalendar xgc = null; - assertEquals(Chrono.dateTime(xgc), ""); - xgc = Chrono.timeStamp(gc); - assertEquals(Chrono.dateTime(xgc), expectedDateTime); - } + XMLGregorianCalendar xgc = null; + assertEquals(Chrono.dateTime(xgc), ""); + xgc = Chrono.timeStamp(gc); + assertEquals(Chrono.dateTime(xgc), expectedDateTime); + } - @Test - public void testDateOnlyStamp() { - final Date date = Calendar.getInstance().getTime(); - date.setTime(1525023883297L); + @Test + public void testDateOnlyStamp() { + final Date date = Calendar.getInstance().getTime(); + date.setTime(1525023883297L); - String expectedDateTime = Chrono.dateOnlyFmt.format(date); + String expectedDateTime = Chrono.dateOnlyFmt.format(date); - String stamp = Chrono.dateOnlyStamp(date); + String stamp = Chrono.dateOnlyStamp(date); - assertEquals(stamp, expectedDateTime); + assertEquals(stamp, expectedDateTime); - Date date1 = null; - assertEquals("", Chrono.dateOnlyStamp(date1)); + Date date1 = null; + assertEquals("", Chrono.dateOnlyStamp(date1)); - GregorianCalendar gc = null; - assertEquals(Chrono.dateOnlyStamp(gc), ""); - gc = new GregorianCalendar(); - gc.setTime(date); - assertEquals(Chrono.dateOnlyStamp(gc), expectedDateTime); + GregorianCalendar gc = null; + assertEquals(Chrono.dateOnlyStamp(gc), ""); + gc = new GregorianCalendar(); + gc.setTime(date); + assertEquals(Chrono.dateOnlyStamp(gc), expectedDateTime); - XMLGregorianCalendar xgc = null; - assertEquals(Chrono.dateOnlyStamp(xgc), ""); - xgc = Chrono.timeStamp(gc); - assertEquals(Chrono.dateOnlyStamp(xgc), expectedDateTime); - } + XMLGregorianCalendar xgc = null; + assertEquals(Chrono.dateOnlyStamp(xgc), ""); + xgc = Chrono.timeStamp(gc); + assertEquals(Chrono.dateOnlyStamp(xgc), expectedDateTime); + } - @Test - public void testNiceDateStamp() { - final Date date = Calendar.getInstance().getTime(); - date.setTime(1525023883297L); + @Test + public void testNiceDateStamp() { + final Date date = Calendar.getInstance().getTime(); + date.setTime(1525023883297L); - String expectedDateTime = Chrono.niceDateFmt.format(date); + String expectedDateTime = Chrono.niceDateFmt.format(date); - String stamp = Chrono.niceDateStamp(date); + String stamp = Chrono.niceDateStamp(date); - assertEquals(stamp, expectedDateTime); + assertEquals(stamp, expectedDateTime); - Date date1 = null; - assertEquals("", Chrono.niceDateStamp(date1)); + Date date1 = null; + assertEquals("", Chrono.niceDateStamp(date1)); - GregorianCalendar gc = null; - assertEquals(Chrono.niceDateStamp(gc), ""); - gc = new GregorianCalendar(); - gc.setTime(date); - assertEquals(Chrono.niceDateStamp(gc), expectedDateTime); + GregorianCalendar gc = null; + assertEquals(Chrono.niceDateStamp(gc), ""); + gc = new GregorianCalendar(); + gc.setTime(date); + assertEquals(Chrono.niceDateStamp(gc), expectedDateTime); - XMLGregorianCalendar xgc = null; - assertEquals(Chrono.niceDateStamp(xgc), ""); - xgc = Chrono.timeStamp(gc); - assertEquals(Chrono.niceDateStamp(xgc), expectedDateTime); - } - - @Test - public void testMoment() { - final Date date = Calendar.getInstance().getTime(); - date.setTime(1525023883297L); + XMLGregorianCalendar xgc = null; + assertEquals(Chrono.niceDateStamp(xgc), ""); + xgc = Chrono.timeStamp(gc); + assertEquals(Chrono.niceDateStamp(xgc), expectedDateTime); + } + + @Test + public void testMoment() { + final Date date = Calendar.getInstance().getTime(); + date.setTime(1525023883297L); - GregorianCalendar begin = new GregorianCalendar(); - begin.setTimeInMillis(date.getTime()); - begin.set(GregorianCalendar.HOUR, 0); - begin.set(GregorianCalendar.AM_PM, GregorianCalendar.AM); - begin.set(GregorianCalendar.MINUTE, 0); - begin.set(GregorianCalendar.SECOND, 0); - begin.set(GregorianCalendar.MILLISECOND, 0); + GregorianCalendar begin = new GregorianCalendar(); + begin.setTimeInMillis(date.getTime()); + begin.set(GregorianCalendar.HOUR, 0); + begin.set(GregorianCalendar.AM_PM, GregorianCalendar.AM); + begin.set(GregorianCalendar.MINUTE, 0); + begin.set(GregorianCalendar.SECOND, 0); + begin.set(GregorianCalendar.MILLISECOND, 0); - long firstMoment = begin.getTimeInMillis(); + long firstMoment = begin.getTimeInMillis(); - begin.set(GregorianCalendar.HOUR, 11); - begin.set(GregorianCalendar.MINUTE, 59); - begin.set(GregorianCalendar.SECOND, 59); - begin.set(GregorianCalendar.MILLISECOND, 999); - begin.set(GregorianCalendar.AM_PM, GregorianCalendar.PM); + begin.set(GregorianCalendar.HOUR, 11); + begin.set(GregorianCalendar.MINUTE, 59); + begin.set(GregorianCalendar.SECOND, 59); + begin.set(GregorianCalendar.MILLISECOND, 999); + begin.set(GregorianCalendar.AM_PM, GregorianCalendar.PM); - long lastMoment = begin.getTimeInMillis(); + long lastMoment = begin.getTimeInMillis(); - assertEquals(firstMoment, Chrono.firstMomentOfDay(date.getTime())); - assertEquals(lastMoment, Chrono.lastMomentOfDay(date.getTime())); + assertEquals(firstMoment, Chrono.firstMomentOfDay(date.getTime())); + assertEquals(lastMoment, Chrono.lastMomentOfDay(date.getTime())); - float timeInMillis = (lastMoment - firstMoment) / 1000000f; - assertEquals(timeInMillis, Chrono.millisFromNanos(firstMoment, lastMoment), 0); + float timeInMillis = (lastMoment - firstMoment) / 1000000f; + assertEquals(timeInMillis, Chrono.millisFromNanos(firstMoment, lastMoment), 0); - } + } } diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_DoubleOutputStreamTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_DoubleOutputStreamTest.java index 4b8c9dce..3e6f5355 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_DoubleOutputStreamTest.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_DoubleOutputStreamTest.java @@ -34,71 +34,71 @@ import org.mockito.Mock; public class JU_DoubleOutputStreamTest { - @Mock - private OutputStream stream1; + @Mock + private OutputStream stream1; - @Mock - private OutputStream stream2; + @Mock + private OutputStream stream2; - private DoubleOutputStream doubleOutputStream; + private DoubleOutputStream doubleOutputStream; - @Before - public void setup() { - stream1 = mock(OutputStream.class); - stream2 = mock(OutputStream.class); - } + @Before + public void setup() { + stream1 = mock(OutputStream.class); + stream2 = mock(OutputStream.class); + } - @Test - public void testWriteInt() throws IOException { - doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true); + @Test + public void testWriteInt() throws IOException { + doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true); - doubleOutputStream.write(123); + doubleOutputStream.write(123); - verify(stream1, only()).write(123); - verify(stream2, only()).write(123); - } + verify(stream1, only()).write(123); + verify(stream2, only()).write(123); + } - @Test - public void testWriteByteArray() throws IOException { - doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true); + @Test + public void testWriteByteArray() throws IOException { + doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true); - byte[] bytes = { 1, 2, 3, 4 }; + byte[] bytes = { 1, 2, 3, 4 }; - doubleOutputStream.write(bytes); + doubleOutputStream.write(bytes); - verify(stream1, only()).write(bytes); - verify(stream2, only()).write(bytes); + verify(stream1, only()).write(bytes); + verify(stream2, only()).write(bytes); - } + } - @Test - public void testWriteByteArrayWithOffset() throws IOException { - doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true); + @Test + public void testWriteByteArrayWithOffset() throws IOException { + doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true); - byte[] bytes = { 1, 2, 3, 4 }; + byte[] bytes = { 1, 2, 3, 4 }; - doubleOutputStream.write(bytes, 1, 3); - verify(stream1, only()).write(bytes, 1, 3); - verify(stream2, only()).write(bytes, 1, 3); - } + doubleOutputStream.write(bytes, 1, 3); + verify(stream1, only()).write(bytes, 1, 3); + verify(stream2, only()).write(bytes, 1, 3); + } - @Test - public void testFlush() throws IOException { - doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true); + @Test + public void testFlush() throws IOException { + doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true); - doubleOutputStream.flush(); + doubleOutputStream.flush(); - verify(stream1, only()).flush(); - verify(stream2, only()).flush(); - } + verify(stream1, only()).flush(); + verify(stream2, only()).flush(); + } - @Test - public void testClose() throws IOException { - doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, false); + @Test + public void testClose() throws IOException { + doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, false); - doubleOutputStream.close(); + doubleOutputStream.close(); - verify(stream1, only()).close(); - verify(stream2, never()).close(); - } + verify(stream1, only()).close(); + verify(stream2, never()).close(); + } } diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_IndentPrintWriterTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_IndentPrintWriterTest.java index b54026f1..a307b3f8 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_IndentPrintWriterTest.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_IndentPrintWriterTest.java @@ -35,79 +35,79 @@ import org.mockito.Mock; public class JU_IndentPrintWriterTest { - @Mock - private OutputStream stream; + @Mock + private OutputStream stream; - @Mock - private Writer writer; + @Mock + private Writer writer; - @Before - public void setUp() throws Exception { - stream = mock(OutputStream.class); - writer = mock(Writer.class); - } + @Before + public void setUp() throws Exception { + stream = mock(OutputStream.class); + writer = mock(Writer.class); + } - @Test - public void testWriteInt() throws IOException { - IndentPrintWriter indentWriter = new IndentPrintWriter(writer); + @Test + public void testWriteInt() throws IOException { + IndentPrintWriter indentWriter = new IndentPrintWriter(writer); - indentWriter.write(123); + indentWriter.write(123); - verify(writer).write(123); + verify(writer).write(123); - assertEquals(indentWriter.getIndent(), 0); - } + assertEquals(indentWriter.getIndent(), 0); + } - @Test - public void testWriteIntWithNewLineCharacter() throws IOException { - IndentPrintWriter indentWriter = new IndentPrintWriter(writer); + @Test + public void testWriteIntWithNewLineCharacter() throws IOException { + IndentPrintWriter indentWriter = new IndentPrintWriter(writer); - indentWriter.setIndent(12); + indentWriter.setIndent(12); - indentWriter.println(); + indentWriter.println(); - indentWriter.write("123", 1, 2); + indentWriter.write("123", 1, 2); - verify(writer).write('\n'); - verify(writer).write('2'); - verify(writer).write('3'); - assertEquals(indentWriter.getIndent(), 12); - } + verify(writer).write('\n'); + verify(writer).write('2'); + verify(writer).write('3'); + assertEquals(indentWriter.getIndent(), 12); + } - @Test - public void testWriteString() throws IOException { - IndentPrintWriter indentWriter = new IndentPrintWriter(writer); + @Test + public void testWriteString() throws IOException { + IndentPrintWriter indentWriter = new IndentPrintWriter(writer); - indentWriter.inc(); + indentWriter.inc(); - indentWriter.write("123"); + indentWriter.write("123"); - verify(writer).write('1'); - verify(writer).write('2'); - verify(writer).write('3'); - assertEquals(indentWriter.getIndent(), 1); - } + verify(writer).write('1'); + verify(writer).write('2'); + verify(writer).write('3'); + assertEquals(indentWriter.getIndent(), 1); + } - @Test - public void testSetIndent() throws IOException { - IndentPrintWriter indentWriter = new IndentPrintWriter(stream); + @Test + public void testSetIndent() throws IOException { + IndentPrintWriter indentWriter = new IndentPrintWriter(stream); - indentWriter.setIndent(12); - indentWriter.dec(); + indentWriter.setIndent(12); + indentWriter.dec(); - assertEquals(indentWriter.getIndent(), 11); - } + assertEquals(indentWriter.getIndent(), 11); + } - @Test - public void testToCol() throws IOException { - IndentPrintWriter indentWriter = new IndentPrintWriter(writer); + @Test + public void testToCol() throws IOException { + IndentPrintWriter indentWriter = new IndentPrintWriter(writer); - indentWriter.toCol(5); - char[] chars = { 'a', 'b', 'c' }; - indentWriter.write(chars, 1, 2); + indentWriter.toCol(5); + char[] chars = { 'a', 'b', 'c' }; + indentWriter.write(chars, 1, 2); - verify(writer, times(5)).write(' '); - verify(writer).write('c'); - verify(writer).write('b'); - } + verify(writer, times(5)).write(' '); + verify(writer).write('c'); + verify(writer).write('b'); + } } \ No newline at end of file diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_SplitTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_SplitTest.java index ce2245bf..f5b4aaa4 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_SplitTest.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_SplitTest.java @@ -27,30 +27,30 @@ import org.junit.Test; public class JU_SplitTest { - @Test - public void testSplit() { - String[] splits = Split.split('c', "character c to break string"); - - assertEquals(splits.length, 4); - assertEquals(splits[0], ""); - assertEquals(splits[1], "hara"); - assertEquals(splits[2], "ter "); - assertEquals(splits[3], " to break string"); - } - - @Test - public void testSplitTrim() { - String[] splits = Split.splitTrim('c', "character c to break string", 5); - - assertEquals(splits.length, 5); - assertEquals(splits[0], ""); - assertEquals(splits[1], "hara"); - assertEquals(splits[2], "ter"); - assertEquals(splits[3], "to break string"); - assertEquals(splits[4], null); - - splits = Split.splitTrim('c', " character ", 1); - assertEquals(splits.length, 1); - assertEquals(splits[0], "character"); - } + @Test + public void testSplit() { + String[] splits = Split.split('c', "character c to break string"); + + assertEquals(splits.length, 4); + assertEquals(splits[0], ""); + assertEquals(splits[1], "hara"); + assertEquals(splits[2], "ter "); + assertEquals(splits[3], " to break string"); + } + + @Test + public void testSplitTrim() { + String[] splits = Split.splitTrim('c', "character c to break string", 5); + + assertEquals(splits.length, 5); + assertEquals(splits[0], ""); + assertEquals(splits[1], "hara"); + assertEquals(splits[2], "ter"); + assertEquals(splits[3], "to break string"); + assertEquals(splits[4], null); + + splits = Split.splitTrim('c', " character ", 1); + assertEquals(splits.length, 1); + assertEquals(splits[0], "character"); + } } diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_StringBuilderOutputStreamTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_StringBuilderOutputStreamTest.java index 377a2891..b55e2545 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_StringBuilderOutputStreamTest.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_StringBuilderOutputStreamTest.java @@ -31,105 +31,105 @@ import org.junit.Test; public class JU_StringBuilderOutputStreamTest { - StringBuilderOutputStream streamBuilder; - - StringBuilder builder = new StringBuilder(); - - @Before - public void setUp() throws Exception { - streamBuilder = new StringBuilderOutputStream(builder); - } - - @Test - public void testWriteIntAndReset() { - streamBuilder.write(123); - - assertEquals("123", streamBuilder.toString()); - streamBuilder.reset(); - assertEquals("", streamBuilder.toString()); - } - - @Test - public void testWriteByteArrayWithoutException() throws IOException { - byte[] bytes = { 1, 2, 3, 4 }; - streamBuilder.write(bytes); - assertEquals(4, streamBuilder.getBuffer().length()); - - streamBuilder.write(bytes, 1, 2); - assertEquals(6, streamBuilder.getBuffer().length()); - - streamBuilder.write(bytes, 1, 0); - assertEquals(6, streamBuilder.getBuffer().length()); - - streamBuilder.append(bytes[0]); - assertEquals(7, streamBuilder.getBuffer().length()); - } - - @Test - public void testWriteByteArrayWithIndexOutOfBoundException() { - byte[] bytes = { 1, 2, 3, 4 }; - - try { - streamBuilder.write(bytes, -1, 2); - fail("This is supposed to throw IndexOutOfBounds Excetpion"); - } catch (IndexOutOfBoundsException e) { - } catch (Exception e) { - fail("This should throw only IndexOutOfBounds Exception"); - } - assertEquals(0, streamBuilder.getBuffer().length()); - - } - - @Test - public void testDefaultConstructor() throws IOException { - StringBuilderOutputStream stream = new StringBuilderOutputStream(); - - assertNotNull(stream.getBuffer()); - stream.close(); - } - - @Test - public void testConstructorWithPositiveDefaultCapacity() throws IOException { - StringBuilderOutputStream stream = new StringBuilderOutputStream(10); - - assertNotNull(stream.getBuffer()); - assertEquals(10, stream.getBuffer().capacity()); - stream.close(); - } - - @Test - public void testConstructorWithNegativeCapacityException() { - try { - StringBuilderOutputStream stream = new StringBuilderOutputStream(-1); - fail("This should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } catch (Exception e) { - fail("This should throw only IllegalArgumentException"); - } - } - - @Test - public void testWriteString() { - streamBuilder.write("1234"); - - assertEquals("1234", streamBuilder.toString()); - - streamBuilder.write("1234", 1, 2); - assertEquals("12342", streamBuilder.toString()); - } - - @Test - public void testAppendCharSequence() { - streamBuilder.append("1234"); - assertEquals("1234", streamBuilder.toString()); - - streamBuilder.append(null); - assertEquals("1234null", streamBuilder.toString()); - - streamBuilder.append("1234", 1, 2); - assertEquals("1234null2", streamBuilder.toString()); - - streamBuilder.append(null, 1, 2); - assertEquals("1234null2u", streamBuilder.toString()); - } + StringBuilderOutputStream streamBuilder; + + StringBuilder builder = new StringBuilder(); + + @Before + public void setUp() throws Exception { + streamBuilder = new StringBuilderOutputStream(builder); + } + + @Test + public void testWriteIntAndReset() { + streamBuilder.write(123); + + assertEquals("123", streamBuilder.toString()); + streamBuilder.reset(); + assertEquals("", streamBuilder.toString()); + } + + @Test + public void testWriteByteArrayWithoutException() throws IOException { + byte[] bytes = { 1, 2, 3, 4 }; + streamBuilder.write(bytes); + assertEquals(4, streamBuilder.getBuffer().length()); + + streamBuilder.write(bytes, 1, 2); + assertEquals(6, streamBuilder.getBuffer().length()); + + streamBuilder.write(bytes, 1, 0); + assertEquals(6, streamBuilder.getBuffer().length()); + + streamBuilder.append(bytes[0]); + assertEquals(7, streamBuilder.getBuffer().length()); + } + + @Test + public void testWriteByteArrayWithIndexOutOfBoundException() { + byte[] bytes = { 1, 2, 3, 4 }; + + try { + streamBuilder.write(bytes, -1, 2); + fail("This is supposed to throw IndexOutOfBounds Excetpion"); + } catch (IndexOutOfBoundsException e) { + } catch (Exception e) { + fail("This should throw only IndexOutOfBounds Exception"); + } + assertEquals(0, streamBuilder.getBuffer().length()); + + } + + @Test + public void testDefaultConstructor() throws IOException { + StringBuilderOutputStream stream = new StringBuilderOutputStream(); + + assertNotNull(stream.getBuffer()); + stream.close(); + } + + @Test + public void testConstructorWithPositiveDefaultCapacity() throws IOException { + StringBuilderOutputStream stream = new StringBuilderOutputStream(10); + + assertNotNull(stream.getBuffer()); + assertEquals(10, stream.getBuffer().capacity()); + stream.close(); + } + + @Test + public void testConstructorWithNegativeCapacityException() { + try { + StringBuilderOutputStream stream = new StringBuilderOutputStream(-1); + fail("This should throw IllegalArgumentException"); + } catch (IllegalArgumentException e) { + } catch (Exception e) { + fail("This should throw only IllegalArgumentException"); + } + } + + @Test + public void testWriteString() { + streamBuilder.write("1234"); + + assertEquals("1234", streamBuilder.toString()); + + streamBuilder.write("1234", 1, 2); + assertEquals("12342", streamBuilder.toString()); + } + + @Test + public void testAppendCharSequence() { + streamBuilder.append("1234"); + assertEquals("1234", streamBuilder.toString()); + + streamBuilder.append(null); + assertEquals("1234null", streamBuilder.toString()); + + streamBuilder.append("1234", 1, 2); + assertEquals("1234null2", streamBuilder.toString()); + + streamBuilder.append(null, 1, 2); + assertEquals("1234null2u", streamBuilder.toString()); + } } diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_StringBuilderWriterTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_StringBuilderWriterTest.java index 6a06e866..9247d0c9 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_StringBuilderWriterTest.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_StringBuilderWriterTest.java @@ -31,105 +31,105 @@ import org.junit.Test; public class JU_StringBuilderWriterTest { - StringBuilderWriter streamWriter; - - StringBuilder builder = new StringBuilder(); - - @Before - public void setUp() throws Exception { - streamWriter = new StringBuilderWriter(builder); - } - - @Test - public void testWriteIntAndReset() { - streamWriter.write(1); - - assertEquals(1, streamWriter.getBuffer().length()); - streamWriter.reset(); - assertEquals("", streamWriter.toString()); - } - - @Test - public void testWriteByteArrayWithoutException() throws IOException { - char[] bytes = { 1, 2, 3, 4 }; - streamWriter.write(bytes); - assertEquals(4, streamWriter.getBuffer().length()); - - streamWriter.write(bytes, 1, 2); - assertEquals(6, streamWriter.getBuffer().length()); - - streamWriter.write(bytes, 1, 0); - assertEquals(6, streamWriter.getBuffer().length()); - - streamWriter.append(bytes[0]); - assertEquals(7, streamWriter.getBuffer().length()); - } - - @Test - public void testWriteByteArrayWithIndexOutOfBoundException() { - char[] bytes = { 1, 2, 3, 4 }; - - try { - streamWriter.write(bytes, -1, 2); - fail("This is supposed to throw IndexOutOfBounds Excetpion"); - } catch (IndexOutOfBoundsException e) { - } catch (Exception e) { - fail("This should throw only IndexOutOfBounds Exception"); - } - assertEquals(0, streamWriter.getBuffer().length()); - - } - - @Test - public void testDefaultConstructor() throws IOException { - StringBuilderWriter stream = new StringBuilderWriter(); - - assertNotNull(stream.getBuffer()); - stream.close(); - } - - @Test - public void testConstructorWithPositiveDefaultCapacity() throws IOException { - StringBuilderWriter stream = new StringBuilderWriter(10); - - assertNotNull(stream.getBuffer()); - assertEquals(10, stream.getBuffer().capacity()); - stream.close(); - } - - @Test - public void testConstructorWithNegativeCapacityException() { - try { - StringBuilderWriter stream = new StringBuilderWriter(-1); - fail("This should throw IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } catch (Exception e) { - fail("This should throw only IllegalArgumentException"); - } - } - - @Test - public void testWriteString() { - streamWriter.write("1234"); - - assertEquals("1234", streamWriter.toString()); - - streamWriter.write("1234", 1, 2); - assertEquals("123423", streamWriter.toString()); - } - - @Test - public void testAppendCharSequence() { - streamWriter.append("1234"); - assertEquals("1234", streamWriter.toString()); - - streamWriter.append(null); - assertEquals("1234null", streamWriter.toString()); - - streamWriter.append("1234", 1, 2); - assertEquals("1234null2", streamWriter.toString()); - - streamWriter.append(null, 1, 2); - assertEquals("1234null2u", streamWriter.toString()); - } + StringBuilderWriter streamWriter; + + StringBuilder builder = new StringBuilder(); + + @Before + public void setUp() throws Exception { + streamWriter = new StringBuilderWriter(builder); + } + + @Test + public void testWriteIntAndReset() { + streamWriter.write(1); + + assertEquals(1, streamWriter.getBuffer().length()); + streamWriter.reset(); + assertEquals("", streamWriter.toString()); + } + + @Test + public void testWriteByteArrayWithoutException() throws IOException { + char[] bytes = { 1, 2, 3, 4 }; + streamWriter.write(bytes); + assertEquals(4, streamWriter.getBuffer().length()); + + streamWriter.write(bytes, 1, 2); + assertEquals(6, streamWriter.getBuffer().length()); + + streamWriter.write(bytes, 1, 0); + assertEquals(6, streamWriter.getBuffer().length()); + + streamWriter.append(bytes[0]); + assertEquals(7, streamWriter.getBuffer().length()); + } + + @Test + public void testWriteByteArrayWithIndexOutOfBoundException() { + char[] bytes = { 1, 2, 3, 4 }; + + try { + streamWriter.write(bytes, -1, 2); + fail("This is supposed to throw IndexOutOfBounds Excetpion"); + } catch (IndexOutOfBoundsException e) { + } catch (Exception e) { + fail("This should throw only IndexOutOfBounds Exception"); + } + assertEquals(0, streamWriter.getBuffer().length()); + + } + + @Test + public void testDefaultConstructor() throws IOException { + StringBuilderWriter stream = new StringBuilderWriter(); + + assertNotNull(stream.getBuffer()); + stream.close(); + } + + @Test + public void testConstructorWithPositiveDefaultCapacity() throws IOException { + StringBuilderWriter stream = new StringBuilderWriter(10); + + assertNotNull(stream.getBuffer()); + assertEquals(10, stream.getBuffer().capacity()); + stream.close(); + } + + @Test + public void testConstructorWithNegativeCapacityException() { + try { + StringBuilderWriter stream = new StringBuilderWriter(-1); + fail("This should throw IllegalArgumentException"); + } catch (IllegalArgumentException e) { + } catch (Exception e) { + fail("This should throw only IllegalArgumentException"); + } + } + + @Test + public void testWriteString() { + streamWriter.write("1234"); + + assertEquals("1234", streamWriter.toString()); + + streamWriter.write("1234", 1, 2); + assertEquals("123423", streamWriter.toString()); + } + + @Test + public void testAppendCharSequence() { + streamWriter.append("1234"); + assertEquals("1234", streamWriter.toString()); + + streamWriter.append(null); + assertEquals("1234null", streamWriter.toString()); + + streamWriter.append("1234", 1, 2); + assertEquals("1234null2", streamWriter.toString()); + + streamWriter.append(null, 1, 2); + assertEquals("1234null2u", streamWriter.toString()); + } } diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/util/test/JU_IPValidator.java b/misc/env/src/test/java/org/onap/aaf/misc/env/util/test/JU_IPValidator.java index 3976718f..0ce3a84e 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/util/test/JU_IPValidator.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/util/test/JU_IPValidator.java @@ -29,39 +29,39 @@ import org.onap.aaf.misc.env.util.IPValidator; public class JU_IPValidator { - @Test - public void test() { - assertTrue(IPValidator.ipv4("10.10.10.10")); - assertTrue(IPValidator.ipv4("127.0.0.0")); - assertFalse(IPValidator.ipv4("10")); - assertFalse(IPValidator.ipv4("10.10.10")); - assertFalse(IPValidator.ipv4("10.10.10.")); - assertFalse(IPValidator.ipv4("10.10.10.10.")); - assertFalse(IPValidator.ipv4("10.10.10.10.10")); - assertFalse(IPValidator.ipv4("something10.10.10.10")); - assertTrue(IPValidator.ipv4("0.10.10.10")); - assertTrue(IPValidator.ipv4("0.0.0.0")); - assertTrue(IPValidator.ipv4("0.10.10.10")); - assertFalse(IPValidator.ipv4("011.255.255.255")); - assertFalse(IPValidator.ipv4("255.01.255.255")); - assertFalse(IPValidator.ipv4("255.255.255.256")); - assertFalse(IPValidator.ipv4("255.299.255.255")); + @Test + public void test() { + assertTrue(IPValidator.ipv4("10.10.10.10")); + assertTrue(IPValidator.ipv4("127.0.0.0")); + assertFalse(IPValidator.ipv4("10")); + assertFalse(IPValidator.ipv4("10.10.10")); + assertFalse(IPValidator.ipv4("10.10.10.")); + assertFalse(IPValidator.ipv4("10.10.10.10.")); + assertFalse(IPValidator.ipv4("10.10.10.10.10")); + assertFalse(IPValidator.ipv4("something10.10.10.10")); + assertTrue(IPValidator.ipv4("0.10.10.10")); + assertTrue(IPValidator.ipv4("0.0.0.0")); + assertTrue(IPValidator.ipv4("0.10.10.10")); + assertFalse(IPValidator.ipv4("011.255.255.255")); + assertFalse(IPValidator.ipv4("255.01.255.255")); + assertFalse(IPValidator.ipv4("255.255.255.256")); + assertFalse(IPValidator.ipv4("255.299.255.255")); - assertTrue(IPValidator.ipv6("0000:0000:0000:0000:0000:0000:0000:0000")); - assertTrue(IPValidator.ipv6("0:0:0:0:0:0:0:0")); - assertTrue(IPValidator.ipv6("2001:08DB:0000:0000:0023:F422:FE3B:AC10")); - assertTrue(IPValidator.ipv6("2001:8DB:0:0:23:F422:FE3B:AC10")); - assertTrue(IPValidator.ipv6("2001:8DB::23:F422:FE3B:AC10")); - assertTrue(IPValidator.ipv6("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")); - assertTrue(IPValidator.ipv6("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF")); - assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10")); - assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10")); - // more than one Double Colons - assertFalse(IPValidator.ipv6("0000:0000:0000::0000::0000")); - assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10:FFFF")); + assertTrue(IPValidator.ipv6("0000:0000:0000:0000:0000:0000:0000:0000")); + assertTrue(IPValidator.ipv6("0:0:0:0:0:0:0:0")); + assertTrue(IPValidator.ipv6("2001:08DB:0000:0000:0023:F422:FE3B:AC10")); + assertTrue(IPValidator.ipv6("2001:8DB:0:0:23:F422:FE3B:AC10")); + assertTrue(IPValidator.ipv6("2001:8DB::23:F422:FE3B:AC10")); + assertTrue(IPValidator.ipv6("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")); + assertTrue(IPValidator.ipv6("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF")); + assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10")); + assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10")); + // more than one Double Colons + assertFalse(IPValidator.ipv6("0000:0000:0000::0000::0000")); + assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10:FFFF")); - assertTrue(IPValidator.ip("2001:08DB:0000:0000:0023:F422:FE3B:AC10")); - assertTrue(IPValidator.ip("192.168.7.2")); - } + assertTrue(IPValidator.ip("2001:08DB:0000:0000:0023:F422:FE3B:AC10")); + assertTrue(IPValidator.ip("192.168.7.2")); + } } diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/util/test/JU_PoolTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/util/test/JU_PoolTest.java index 11f03d52..32e4080b 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/util/test/JU_PoolTest.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/util/test/JU_PoolTest.java @@ -30,57 +30,57 @@ import org.onap.aaf.misc.env.util.Pool; public class JU_PoolTest { - @Before - public void setUp() throws Exception { - } + @Before + public void setUp() throws Exception { + } - @Test - public void test() { - Pool pool = new Pool(new Pool.Creator() { + @Test + public void test() { + Pool pool = new Pool(new Pool.Creator() { - Integer content = 0; + Integer content = 0; - @Override - public Integer create() throws APIException { - return content++; - } + @Override + public Integer create() throws APIException { + return content++; + } - @Override - public void destroy(Integer t) { + @Override + public void destroy(Integer t) { - } + } - @Override - public boolean isValid(Integer t) { - return t == content; - } + @Override + public boolean isValid(Integer t) { + return t == content; + } - @Override - public void reuse(Integer t) { - content = t; - } - }); - Pool.Pooled pooled = new Pool.Pooled(new Integer(123), pool, LogTarget.SYSOUT); - Pool.Pooled pooled1 = new Pool.Pooled(new Integer(123), null, LogTarget.SYSOUT); - try { - // pool.drain(); - assertEquals("Should return intial value", 0, pool.get().content); - // pooled.toss(); - pool.prime(LogTarget.SYSOUT, 23); - assertEquals("Should Return 23 as added at last prime", 23, pool.get(LogTarget.SYSOUT).content); - pool.prime(LogTarget.SYSERR, 13); - assertEquals("Should add another 13 from SysErr and remove 1", 35, pool.get(LogTarget.SYSERR).content); - assertEquals("Create a new creator with create method", 1, pool.get().content); - assertEquals("Create a new creator with create method", 2, pool.get().content); - assertEquals("Should remove last from pool", 34, pool.get(LogTarget.SYSOUT).content); + @Override + public void reuse(Integer t) { + content = t; + } + }); + Pool.Pooled pooled = new Pool.Pooled(new Integer(123), pool, LogTarget.SYSOUT); + Pool.Pooled pooled1 = new Pool.Pooled(new Integer(123), null, LogTarget.SYSOUT); + try { + // pool.drain(); + assertEquals("Should return intial value", 0, pool.get().content); + // pooled.toss(); + pool.prime(LogTarget.SYSOUT, 23); + assertEquals("Should Return 23 as added at last prime", 23, pool.get(LogTarget.SYSOUT).content); + pool.prime(LogTarget.SYSERR, 13); + assertEquals("Should add another 13 from SysErr and remove 1", 35, pool.get(LogTarget.SYSERR).content); + assertEquals("Create a new creator with create method", 1, pool.get().content); + assertEquals("Create a new creator with create method", 2, pool.get().content); + assertEquals("Should remove last from pool", 34, pool.get(LogTarget.SYSOUT).content); - pool.drain(); - assertEquals("Should remove last from pool", 17, pool.get(LogTarget.SYSOUT).content); - pool.setMaxRange(10); - assertEquals(10, pool.getMaxRange()); - pooled.toss(); - pooled1.toss(); - } catch (APIException e) { - } - } + pool.drain(); + assertEquals("Should remove last from pool", 17, pool.get(LogTarget.SYSOUT).content); + pool.setMaxRange(10); + assertEquals(10, pool.getMaxRange()); + pooled.toss(); + pooled1.toss(); + } catch (APIException e) { + } + } } -- cgit 1.2.3-korg