Increase coverage for Env module 27/44927/1
authorSai Gandham <sg481n@att.com>
Thu, 26 Apr 2018 16:19:49 +0000 (16:19 +0000)
committerSai Gandham <sg481n@att.com>
Thu, 26 Apr 2018 16:20:00 +0000 (16:20 +0000)
Issue-ID: AAF-219
Change-Id: Ic41009cdefa30d2b43ec95f0fc21e3f9e8fb472e
Signed-off-by: Sai Gandham <sg481n@att.com>
58 files changed:
misc/env/src/main/java/org/onap/aaf/misc/env/APIException.java
misc/env/src/main/java/org/onap/aaf/misc/env/BaseDataFactory.java
misc/env/src/main/java/org/onap/aaf/misc/env/Creatable.java
misc/env/src/main/java/org/onap/aaf/misc/env/Data.java
misc/env/src/main/java/org/onap/aaf/misc/env/DataFactory.java
misc/env/src/main/java/org/onap/aaf/misc/env/Decryptor.java
misc/env/src/main/java/org/onap/aaf/misc/env/Encryptor.java
misc/env/src/main/java/org/onap/aaf/misc/env/Env.java
misc/env/src/main/java/org/onap/aaf/misc/env/EnvJAXB.java
misc/env/src/main/java/org/onap/aaf/misc/env/EnvJAXBProps.java
misc/env/src/main/java/org/onap/aaf/misc/env/EnvProps.java
misc/env/src/main/java/org/onap/aaf/misc/env/EnvStore.java
misc/env/src/main/java/org/onap/aaf/misc/env/IOObjectifier.java
misc/env/src/main/java/org/onap/aaf/misc/env/IOStringifier.java
misc/env/src/main/java/org/onap/aaf/misc/env/LifeCycle.java
misc/env/src/main/java/org/onap/aaf/misc/env/LogTarget.java
misc/env/src/main/java/org/onap/aaf/misc/env/Objectifier.java
misc/env/src/main/java/org/onap/aaf/misc/env/Slot.java
misc/env/src/main/java/org/onap/aaf/misc/env/StaticSlot.java
misc/env/src/main/java/org/onap/aaf/misc/env/Store.java
misc/env/src/main/java/org/onap/aaf/misc/env/StoreImpl.java
misc/env/src/main/java/org/onap/aaf/misc/env/Stringifier.java
misc/env/src/main/java/org/onap/aaf/misc/env/TimeTaken.java
misc/env/src/main/java/org/onap/aaf/misc/env/Trans.java
misc/env/src/main/java/org/onap/aaf/misc/env/TransCreate.java
misc/env/src/main/java/org/onap/aaf/misc/env/TransJAXB.java
misc/env/src/main/java/org/onap/aaf/misc/env/TransStore.java
misc/env/src/main/java/org/onap/aaf/misc/env/impl/AbsTrans.java
misc/env/src/main/java/org/onap/aaf/misc/env/impl/AbsTransJAXB.java
misc/env/src/main/java/org/onap/aaf/misc/env/impl/BasicEnv.java
misc/env/src/main/java/org/onap/aaf/misc/env/impl/BasicTrans.java
misc/env/src/main/java/org/onap/aaf/misc/env/impl/EnvFactory.java
misc/env/src/main/java/org/onap/aaf/misc/env/impl/JavaUtilLogTarget.java
misc/env/src/main/java/org/onap/aaf/misc/env/impl/Log4JLogTarget.java
misc/env/src/main/java/org/onap/aaf/misc/env/impl/NullLifeCycle.java
misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBDF.java
misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBData.java
misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBObjectifier.java
misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBStringifier.java
misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBmar.java
misc/env/src/main/java/org/onap/aaf/misc/env/jaxb/JAXBumar.java
misc/env/src/main/java/org/onap/aaf/misc/env/old/IOObjectifier.java
misc/env/src/main/java/org/onap/aaf/misc/env/old/IOStringifier.java
misc/env/src/main/java/org/onap/aaf/misc/env/old/Objectifier.java
misc/env/src/main/java/org/onap/aaf/misc/env/old/OldDataFactory.java
misc/env/src/main/java/org/onap/aaf/misc/env/old/Stringifier.java
misc/env/src/main/java/org/onap/aaf/misc/env/util/Chrono.java
misc/env/src/main/java/org/onap/aaf/misc/env/util/DoubleOutputStream.java
misc/env/src/main/java/org/onap/aaf/misc/env/util/IPValidator.java
misc/env/src/main/java/org/onap/aaf/misc/env/util/IndentPrintWriter.java
misc/env/src/main/java/org/onap/aaf/misc/env/util/Pool.java
misc/env/src/main/java/org/onap/aaf/misc/env/util/RefreshableThreadObject.java
misc/env/src/main/java/org/onap/aaf/misc/env/util/Split.java
misc/env/src/main/java/org/onap/aaf/misc/env/util/StringBuilderOutputStream.java
misc/env/src/main/java/org/onap/aaf/misc/env/util/StringBuilderWriter.java
misc/env/src/test/java/org/onap/aaf/misc/env/JU_LogTargetTest.java [new file with mode: 0644]
misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_BasicEnvTest.java [new file with mode: 0644]
misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_ChronoTest.java [new file with mode: 0644]

index 2b66345..bf1d357 100644 (file)
@@ -1,89 +1,89 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-
-/**
- * An Exception with the ability to hold a payload.<p>
- * 
- * This is important, because sometimes, the output of a Framework
- * may be a descriptive object which doesn't inherit from Throwable
- * and thus cannot be attached in "initCause".<p>
- * 
- * Examples may be a SOAP Fault.
- * 
- * @author Jonathan
- *
- */
-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);
-       }
-
-       /**
-        * @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;
-       }
-
-       /**
-        * 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;
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+\r
+/**\r
+ * An Exception with the ability to hold a payload.<p>\r
+ * \r
+ * This is important, because sometimes, the output of a Framework\r
+ * may be a descriptive object which doesn't inherit from Throwable\r
+ * and thus cannot be attached in "initCause".<p>\r
+ * \r
+ * Examples may be a SOAP Fault.\r
+ * \r
+ * @author Jonathan\r
+ *\r
+ */\r
+public class APIException extends Exception {\r
+       \r
+       private Object payload = null;\r
+       \r
+       /**\r
+        * @param t\r
+        */\r
+       public APIException(Throwable t) {\r
+               super(t);\r
+       }\r
+       \r
+       /**\r
+        * @param string\r
+        */\r
+       public APIException(String string) {\r
+               super(string);\r
+       }\r
+\r
+       /**\r
+        * @param errorMessage\r
+        * @param t\r
+        */\r
+       public APIException(String errorMessage, Throwable t) {\r
+               super(errorMessage,t);\r
+       }\r
+\r
+       /**\r
+        * Return payload, or null if none was set.  Type is up to the calling\r
+        * System.\r
+        * \r
+        * @return Object\r
+        */\r
+       public Object getPayload() {\r
+               return payload;\r
+       }\r
+\r
+       /**\r
+        * Set a specific payload into this Exception, which doesn't necessarily\r
+        * inherit from Throwable.\r
+        * \r
+        * @param payload\r
+        * @return APIException\r
+        */\r
+       public APIException setPayload(Object payload) {\r
+               this.payload = payload;\r
+               return this;\r
+       }\r
+\r
+       /**\r
+        * Java expected serial ID\r
+        */\r
+       private static final long serialVersionUID = 3505343458251445169L;\r
+}\r
index 4dfa26b..7861501 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-
-import javax.xml.XMLConstants;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlSchema;
-import javax.xml.namespace.QName;
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-
-import org.onap.aaf.misc.env.impl.EnvFactory;
-import org.xml.sax.SAXException;
-
-
-
-/**
- * DataFactory Constructor will create the Stringifiers and Objectifiers necessary 
- * by Type and store the Class of the Type for quick creation of Data Objects
- * with reused (and thread safe) components
- * s
- * Native Types are included.
- * Those types covered by Env Implementation are covered dynamically.
- * Types outside of Env mechanism can be added with "add" function
- * 
- * @author Jonathan
- *
- * @param <T>
- */
-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<filenames.length; ++i) {
-                       if(!(f=new File(schemaDir + File.separatorChar + filenames[i])).exists()) {
-                               if(!f.exists()) throw new APIException("Cannot find " + f.getName() + " for schema validation");
-                       }
-                       try {
-                               fis[i]=new FileInputStream(f);
-                       } catch (FileNotFoundException e) {
-                               throw new APIException(e);
-                       }
-                       sources[i]= new StreamSource(fis[i]);
-               }
-               try {
-                       //Note: SchemaFactory is not reentrant or very thread safe either... see docs
-                       synchronized(LOCK) { // SchemaFactory is not reentrant
-                               return SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
-                                       .newSchema(sources);
-                       }
-               } catch (SAXException e) {
-                       throw new APIException(e);
-               } finally {
-                       for(FileInputStream d : fis) {
-                               try {
-                                       d.close();
-                               } catch (IOException e) {
-                                // Never mind... we did our best
-                               }
-                       }
-               }
-
-       }
-
-       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<String> {
-//             /* (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<String> {
-//             /* (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<Long> {
-//             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<Long> {
-//             /* (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;
-//             }
-//     }
-//
-//     /**
-//      * IntegerStringifier
-//      * 
-//      * Support the Native Integer.. use Integer parse functions
-//      * 
-//      * @author Jonathan
-//      *
-//      */
-//     public static class IntegerStringifier extends NullLifeCycle implements Stringifier<Integer> {
-//             /* (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<Integer> {
-//             /* (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;
-//             }
-//     }
-//
-//     /**
-//      * ShortStringifier
-//      * 
-//      * Support the Native Short.. use Short parse functions
-//      * 
-//      * @author Jonathan
-//      *
-//      */
-//     public static class ShortStringifier extends NullLifeCycle implements Stringifier<Short> {
-//             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<Short> {
-//             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<Byte> {
-//             /* (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<Byte> {
-//             /* (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;
-//             }
-//     }
-//
-//     /**
-//      * CharacterStringifier
-//      * 
-//      * Support the Native Character.. use Character parse functions
-//      * 
-//      * @author Jonathan
-//      *
-//      */
-//     public static class CharacterStringifier extends NullLifeCycle implements Stringifier<Character> {
-//             /* (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<Character> {
-//             /* (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;
-//             }
-//     }
-//
-//     /**
-//      * FloatStringifier
-//      * 
-//      * Support the Native Float.. use Float parse functions
-//      * 
-//      * @author Jonathan
-//      *
-//      */
-//     public static class FloatStringifier extends NullLifeCycle implements Stringifier<Float> {
-//             /* (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<Float> {
-//             /* (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;
-//             }
-//     }
-//
-//     /**
-//      * DoubleStringifier
-//      * 
-//      * Support the Native Double.. use Double parse functions
-//      * 
-//      * @author Jonathan
-//      *
-//      */
-//     public static class DoubleStringifier extends NullLifeCycle implements Stringifier<Double> {
-//             /* (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<Double> {
-//             /* (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;
-//             }
-//     }
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.FileNotFoundException;\r
+import java.io.IOException;\r
+\r
+import javax.xml.XMLConstants;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+import javax.xml.bind.annotation.XmlSchema;\r
+import javax.xml.namespace.QName;\r
+import javax.xml.transform.Source;\r
+import javax.xml.transform.stream.StreamSource;\r
+import javax.xml.validation.Schema;\r
+import javax.xml.validation.SchemaFactory;\r
+\r
+import org.onap.aaf.misc.env.impl.EnvFactory;\r
+import org.xml.sax.SAXException;\r
+\r
+\r
+\r
+/**\r
+ * DataFactory Constructor will create the Stringifiers and Objectifiers necessary \r
+ * by Type and store the Class of the Type for quick creation of Data Objects\r
+ * with reused (and thread safe) components\r
+ * s\r
+ * Native Types are included.\r
+ * Those types covered by Env Implementation are covered dynamically.\r
+ * Types outside of Env mechanism can be added with "add" function\r
+ * \r
+ * @author Jonathan\r
+ *\r
+ * @param <T>\r
+ */\r
+public class BaseDataFactory {\r
+       private static final Object LOCK = new Object();\r
+       /**\r
+        * Generate a Schema Object for use in validation based on FileNames.\r
+        * \r
+        * WARNING: The java.xml.binding code requires YOU to figure out what order the\r
+        * files go in.  If there is an import from A in B, then you must list A first.\r
+        * \r
+        * @param err\r
+        * @param filenames\r
+        * @return\r
+        * @throws APIException\r
+        */\r
+       public static Schema genSchema(Store env, String ... filenames) throws APIException {\r
+               String schemaDir = env.get(\r
+                               env.staticSlot(EnvFactory.SCHEMA_DIR),\r
+                               EnvFactory.DEFAULT_SCHEMA_DIR);\r
+               File dir = new File(schemaDir);\r
+               if(!dir.exists())throw new APIException("Schema Directory " + schemaDir + " does not exist.  You can set this with " + EnvFactory.SCHEMA_DIR + " property");\r
+               FileInputStream[] fis = new FileInputStream[filenames.length];\r
+               Source[] sources = new Source[filenames.length];\r
+               File f; \r
+               for(int i=0; i<filenames.length; ++i) {\r
+                       if(!(f=new File(schemaDir + File.separatorChar + filenames[i])).exists()) {\r
+                               if(!f.exists()) throw new APIException("Cannot find " + f.getName() + " for schema validation");\r
+                       }\r
+                       try {\r
+                               fis[i]=new FileInputStream(f);\r
+                       } catch (FileNotFoundException e) {\r
+                               throw new APIException(e);\r
+                       }\r
+                       sources[i]= new StreamSource(fis[i]);\r
+               }\r
+               try {\r
+                       //Note: SchemaFactory is not reentrant or very thread safe either... see docs\r
+                       synchronized(LOCK) { // SchemaFactory is not reentrant\r
+                               return SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)\r
+                                       .newSchema(sources);\r
+                       }\r
+               } catch (SAXException e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       for(FileInputStream d : fis) {\r
+                               try {\r
+                                       d.close();\r
+                               } catch (IOException e) {\r
+                                // Never mind... we did our best\r
+                               }\r
+                       }\r
+               }\r
+\r
+       }\r
+\r
+       public static QName getQName(Class<?> clss) throws APIException {\r
+               // Obtain the Necessary info for QName from Requirement\r
+               XmlRootElement xre = clss.getAnnotation(XmlRootElement.class);\r
+               if(xre==null)throw new APIException(clss.getName() + " does not have an XmlRootElement annotation");\r
+               Package pkg = clss.getPackage();\r
+               XmlSchema xs = pkg.getAnnotation(XmlSchema.class);\r
+               if(xs==null) throw new APIException(clss.getName() + " package-info does not have an XmlSchema annotation");\r
+               return new QName(xs.namespace(),xre.name());\r
+       }\r
+\r
+       /////////////////////////////////////////////\r
+       // Native Type Converters\r
+       /////////////////////////////////////////////\r
+//     /**\r
+//      * StringStringifier\r
+//      * \r
+//      * Support the Native Type String.. just return it back\r
+//      * \r
+//      * @author Jonathan\r
+//      *\r
+//      */\r
+//     public static class StringStringifier extends NullLifeCycle implements Stringifier<String> {\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object)\r
+//              */\r
+//             public String stringify(Env env, String input) throws APIException {\r
+//                     return input;\r
+//             }\r
+//     };              \r
+//\r
+//     /**\r
+//      * StringObjectifier\r
+//      * \r
+//      * Support the Native Type String.. just return it back\r
+//      * \r
+//      * @author Jonathan\r
+//      *\r
+//      */\r
+//     public static class StringObjectifier extends NullLifeCycle implements Objectifier<String> {\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String)\r
+//              */\r
+//             public String objectify(Env env, String input) throws APIException {\r
+//                     return input;\r
+//             }\r
+//\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Objectifier#newObject()\r
+//              */\r
+//             public String newInstance() throws APIException {\r
+//                     return "";\r
+//             }\r
+//     };\r
+//     \r
+//     /**\r
+//      * LongStringifier\r
+//      * \r
+//      * Support the Native Type Long.. use Long parse functions\r
+//      * \r
+//      * @author Jonathan\r
+//      *\r
+//      */\r
+//     public static class LongStringifier extends NullLifeCycle implements Stringifier<Long> {\r
+//             public String stringify(Env env, Long input) throws APIException {\r
+//                     return input.toString();\r
+//             }\r
+//     }\r
+//     \r
+//     /**\r
+//      * LongObjectifier\r
+//      * \r
+//      * Support the Native Type Long.. use Long parse functions\r
+//      * \r
+//      * @author Jonathan\r
+//      *\r
+//      */\r
+//     public static class LongObjectifier extends NullLifeCycle implements Objectifier<Long> {\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String)\r
+//              */\r
+//             public Long objectify(Env env, String input) throws APIException {\r
+//                     try {\r
+//                             return new Long(input);\r
+//                     } catch (Exception e) {\r
+//                             APIException ae = new APIException("Cannot create a \"Long\" from [" + input + ']');\r
+//                             ae.initCause(e);\r
+//                             throw ae;\r
+//                     }\r
+//             }\r
+//\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Objectifier#newObject()\r
+//              */\r
+//             public Long newInstance() throws APIException {\r
+//                     return 0L;\r
+//             }\r
+//     }\r
+//\r
+//     /**\r
+//      * IntegerStringifier\r
+//      * \r
+//      * Support the Native Integer.. use Integer parse functions\r
+//      * \r
+//      * @author Jonathan\r
+//      *\r
+//      */\r
+//     public static class IntegerStringifier extends NullLifeCycle implements Stringifier<Integer> {\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object)\r
+//              */\r
+//             public String stringify(Env env, Integer input) throws APIException {\r
+//                     return input.toString();\r
+//             }\r
+//     }\r
+//     \r
+//     /**\r
+//      * IntegerObjectifier\r
+//      * \r
+//      * Support the Native Integer.. use Integer parse functions\r
+//      * \r
+//      * @author Jonathan\r
+//      *\r
+//      */\r
+//     public static class IntegerObjectifier extends NullLifeCycle implements Objectifier<Integer> {\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String)\r
+//              */\r
+//             public Integer objectify(Env env, String input) throws APIException {\r
+//                     try {\r
+//                             return new Integer(input);\r
+//                     } catch (Exception e) {\r
+//                             APIException ae = new APIException("Cannot create a \"Integer\" from [" + input + ']');\r
+//                             ae.initCause(e);\r
+//                             throw ae;\r
+//                     }\r
+//             }\r
+//\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Objectifier#newObject()\r
+//              */\r
+//             public Integer newInstance() throws APIException {\r
+//                     return 0;\r
+//             }\r
+//     }\r
+//\r
+//     /**\r
+//      * ShortStringifier\r
+//      * \r
+//      * Support the Native Short.. use Short parse functions\r
+//      * \r
+//      * @author Jonathan\r
+//      *\r
+//      */\r
+//     public static class ShortStringifier extends NullLifeCycle implements Stringifier<Short> {\r
+//             public String stringify(Env env, Short input) throws APIException {\r
+//                     return input.toString();\r
+//             }\r
+//     }\r
+//     \r
+//     /**\r
+//      * ShortObjectifier\r
+//      * \r
+//      * Support the Native Short.. use Short parse functions\r
+//      * \r
+//      * @author Jonathan\r
+//      *\r
+//      */\r
+//     public static class ShortObjectifier extends NullLifeCycle implements Objectifier<Short> {\r
+//             public Short objectify(Env env, String input) throws APIException {\r
+//                     try {\r
+//                             return new Short(input);\r
+//                     } catch (Exception e) {\r
+//                             APIException ae = new APIException("Cannot create a \"Short\" from [" + input + ']');\r
+//                             ae.initCause(e);\r
+//                             throw ae;\r
+//                     }\r
+//             }\r
+//\r
+//             public Short newInstance() throws APIException {\r
+//                     return 0;\r
+//             }\r
+//     }\r
+//     \r
+//     /**\r
+//      * ByteStringifier\r
+//      * \r
+//      * Support the Native Byte.. use Byte parse functions\r
+//      * \r
+//      * @author Jonathan\r
+//      *\r
+//      */\r
+//     public static class ByteStringifier extends NullLifeCycle implements Stringifier<Byte> {\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object)\r
+//              */\r
+//             public String stringify(Env env, Byte input) throws APIException {\r
+//                     return input.toString();\r
+//             }\r
+//     }\r
+//     \r
+//     /**\r
+//      * ByteObjectifier\r
+//      * \r
+//      * Support the Native Byte.. use Byte parse functions\r
+//      * \r
+//      * @author Jonathan\r
+//      *\r
+//      */\r
+//     public static class ByteObjectifier extends NullLifeCycle implements Objectifier<Byte> {\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String)\r
+//              */\r
+//             public Byte objectify(Env env, String input) throws APIException {\r
+//                     try {\r
+//                             return new Byte(input);\r
+//                     } catch (Exception e) {\r
+//                             APIException ae = new APIException("Cannot create a \"Byte\" from [" + input + ']');\r
+//                             ae.initCause(e);\r
+//                             throw ae;\r
+//                     }\r
+//             }\r
+//\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Objectifier#newObject()\r
+//              */\r
+//             public Byte newInstance() throws APIException {\r
+//                     return 0;\r
+//             }\r
+//     }\r
+//\r
+//     /**\r
+//      * CharacterStringifier\r
+//      * \r
+//      * Support the Native Character.. use Character parse functions\r
+//      * \r
+//      * @author Jonathan\r
+//      *\r
+//      */\r
+//     public static class CharacterStringifier extends NullLifeCycle implements Stringifier<Character> {\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object)\r
+//              */\r
+//             public String stringify(Env env, Character input) throws APIException {\r
+//                     return input.toString();\r
+//             }\r
+//     }\r
+//     \r
+//     /**\r
+//      * CharacterObjectifier\r
+//      * \r
+//      * Support the Native Character.. use Character parse functions\r
+//      * \r
+//      * @author Jonathan\r
+//      *\r
+//      */\r
+//     public static class CharacterObjectifier extends NullLifeCycle implements Objectifier<Character> {\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String)\r
+//              */\r
+//             public Character objectify(Env env, String input) throws APIException {\r
+//                     int length = input.length();\r
+//                     if(length<1 || length>1) {\r
+//                             throw new APIException("String [" + input + "] does not represent a single Character");\r
+//                     }\r
+//                     return input.charAt(0);\r
+//             }\r
+//\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Objectifier#newObject()\r
+//              */\r
+//             public Character newInstance() throws APIException {\r
+//                     return 0;\r
+//             }\r
+//     }\r
+//\r
+//     /**\r
+//      * FloatStringifier\r
+//      * \r
+//      * Support the Native Float.. use Float parse functions\r
+//      * \r
+//      * @author Jonathan\r
+//      *\r
+//      */\r
+//     public static class FloatStringifier extends NullLifeCycle implements Stringifier<Float> {\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object)\r
+//              */\r
+//             public String stringify(Env env, Float input) throws APIException {\r
+//                     return input.toString();\r
+//             }\r
+//     }\r
+//     \r
+//     /**\r
+//      * FloatObjectifier\r
+//      * \r
+//      * Support the Native Float.. use Float parse functions\r
+//      * \r
+//      * @author Jonathan\r
+//      *\r
+//      */\r
+//     public static class FloatObjectifier extends NullLifeCycle implements Objectifier<Float> {\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String)\r
+//              */\r
+//             public Float objectify(Env env, String input) throws APIException {\r
+//                     try {\r
+//                             return new Float(input);\r
+//                     } catch (Exception e) {\r
+//                             APIException ae = new APIException("Cannot create a \"Float\" from [" + input + ']');\r
+//                             ae.initCause(e);\r
+//                             throw ae;\r
+//                     }\r
+//             }\r
+//\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Objectifier#newObject()\r
+//              */\r
+//             public Float newInstance() throws APIException {\r
+//                     return 0.0f;\r
+//             }\r
+//     }\r
+//\r
+//     /**\r
+//      * DoubleStringifier\r
+//      * \r
+//      * Support the Native Double.. use Double parse functions\r
+//      * \r
+//      * @author Jonathan\r
+//      *\r
+//      */\r
+//     public static class DoubleStringifier extends NullLifeCycle implements Stringifier<Double> {\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object)\r
+//              */\r
+//             public String stringify(Env env, Double input) throws APIException {\r
+//                     return input.toString();\r
+//             }\r
+//     }\r
+//     \r
+//     /**\r
+//      * DoubleObjectifier\r
+//      * \r
+//      * Support the Native Double.. use Double parse functions\r
+//      * \r
+//      * @author Jonathan\r
+//      *\r
+//      */\r
+//     public static class DoubleObjectifier extends NullLifeCycle implements Objectifier<Double> {\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String)\r
+//              */\r
+//             public Double objectify(Env env, String input) throws APIException {\r
+//                     try {\r
+//                             return new Double(input);\r
+//                     } catch (Exception e) {\r
+//                             APIException ae = new APIException("Cannot create a \"Double\" from [" + input + ']');\r
+//                             ae.initCause(e);\r
+//                             throw ae;\r
+//                     }\r
+//             }\r
+//\r
+//             /* (non-Javadoc)\r
+//              * @see com.att.env.Objectifier#newObject()\r
+//              */\r
+//             public Double newInstance() throws APIException {\r
+//                     return 0.0;\r
+//             }\r
+//     }\r
+\r
+}\r
index 995819e..2423ed6 100644 (file)
@@ -1,52 +1,52 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-
-/**
- * <h1>Creatable</h1>
- * <b>**Must implement constructor T(ENV env, long currentTimeMillis);**</b><p>
- *
- * This interface exists to cover basic LifeCycle semantics so that Objects
- * can be created dynamically and managed at a basic level (destroy(env)).
- * 
- * @author Jonathan
- *
- * @param <T>
- */
-public interface Creatable<T> {
-       /**
-        * Return the timestamp (Unix long) when this object was created.<p>
-        * 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);
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+\r
+/**\r
+ * <h1>Creatable</h1>\r
+ * <b>**Must implement constructor T(ENV env, long currentTimeMillis);**</b><p>\r
+ *\r
+ * This interface exists to cover basic LifeCycle semantics so that Objects\r
+ * can be created dynamically and managed at a basic level (destroy(env)).\r
+ * \r
+ * @author Jonathan\r
+ *\r
+ * @param <T>\r
+ */\r
+public interface Creatable<T> {\r
+       /**\r
+        * Return the timestamp (Unix long) when this object was created.<p>\r
+        * This can be used to see if the object is out of date in certain\r
+        * circumstances, or perhaps has already been notified in others.\r
+        * \r
+        * @return long\r
+        */\r
+       public abstract long created();\r
+       \r
+       /**\r
+        * Allow LifeCycle aware process to signal this element as destroyed.\r
+        *  \r
+        * @param env\r
+        */\r
+       public abstract void destroy(Env env);\r
+}\r
index 2c24cb1..155dfc7 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-/**
- * <H1>Data</H1>
- * <i>Data</i> facilitates lazy marshaling of data with a pre-determined
- * marshaling mechanism.<p>
- * 
- * It stores either Object (defined by Generic {@literal <T>}) or String.<p>  
- * 
- * On asking for Object of type {@literal <T>}, it will respond with the object
- * if it exists, or unmarshal the string and pass the result back.<p>
- * 
- * On asking for String, it will respond with the String
- * if it exists, or marshal the String and pass the result back.<p>
- *
- * 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 "<?xml ...?>" header so you can create larger XML documents from the output. 
- * 
- * @author Jonathan
- *
- * @param <T>
- */
-public interface Data<T> {
-       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 Object of type {@literal <T>} if it exists, or unmarshal from String 
-        * and pass the result back.<p>
-        *
-        * However, use the Env the Data Object was created with.
-        * 
-        * @return T
-        * @throws APIException
-        */
-       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<T> option(int option);
-
-       public Data<T> to(OutputStream os) throws APIException, IOException;
-       public Data<T> to(Writer writer) throws APIException, IOException;
-       
-       public Data<T> load(T t) throws APIException;
-       public Data<T> load(String str) throws APIException;
-       public Data<T> load(InputStream is) throws APIException;
-       public Data<T> load(Reader rdr) throws APIException;
-       
-       public Data<T> in(TYPE type);
-       public Data<T> out(TYPE type);
-       /**
-        * Return the Class Type supported by this DataObject
-        * 
-        * @return {@literal Class<T>}
-        */
-       public Class<T> getTypeClass();
-
-       public void direct(InputStream input, OutputStream output) throws APIException, IOException;
-
-
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
+import java.io.Reader;\r
+import java.io.Writer;\r
+/**\r
+ * <H1>Data</H1>\r
+ * <i>Data</i> facilitates lazy marshaling of data with a pre-determined\r
+ * marshaling mechanism.<p>\r
+ * \r
+ * It stores either Object (defined by Generic {@literal <T>}) or String.<p>  \r
+ * \r
+ * On asking for Object of type {@literal <T>}, it will respond with the object\r
+ * if it exists, or unmarshal the string and pass the result back.<p>\r
+ * \r
+ * On asking for String, it will respond with the String\r
+ * if it exists, or marshal the String and pass the result back.<p>\r
+ *\r
+ * the "options" available on several functions control the output of this particular call.  When \r
+ * blank, they will default to the DataFactory defaults.  When present, they override this\r
+ * particular call.\r
+ *     The available options are "pretty" (for XML and JSON) and "fragment" (XML only concept), which drops\r
+ * the "<?xml ...?>" header so you can create larger XML documents from the output. \r
+ * \r
+ * @author Jonathan\r
+ *\r
+ * @param <T>\r
+ */\r
+public interface Data<T> {\r
+       static enum TYPE {XML,JSON,JAXB,RAW,DEFAULT};\r
+       // can & with 0xFFFF;\r
+//     public static final int XML = 0x1;\r
+//     public static final int JSON = 0x2;\r
+//     public static final int JAXB = 0x4;\r
+//     public static final int RAW = 0x1000;\r
+       \r
+       // can & with 0xF00000;\r
+       public static final int PRETTY = 0x100000;\r
+       public static final int FRAGMENT = 0x200000;\r
+\r
+       /**\r
+        * Respond with the String if it exists, or marshal the String and pass the result back.\r
+        * \r
+        * However, use the Env the Data Object was created with.\r
+        * \r
+        * @return String\r
+        * @throws APIException\r
+        */\r
+       public String asString() throws APIException;\r
+\r
+       /**\r
+        * Respond with the Object of type {@literal <T>} if it exists, or unmarshal from String \r
+        * and pass the result back.<p>\r
+        *\r
+        * However, use the Env the Data Object was created with.\r
+        * \r
+        * @return T\r
+        * @throws APIException\r
+        */\r
+       public T asObject() throws APIException;\r
+\r
+       /**\r
+        * Set a particular option on an existing Out \r
+        * \r
+        * if int is negative, it should remove the option\r
+        * @param option\r
+        */\r
+       public Data<T> option(int option);\r
+\r
+       public Data<T> to(OutputStream os) throws APIException, IOException;\r
+       public Data<T> to(Writer writer) throws APIException, IOException;\r
+       \r
+       public Data<T> load(T t) throws APIException;\r
+       public Data<T> load(String str) throws APIException;\r
+       public Data<T> load(InputStream is) throws APIException;\r
+       public Data<T> load(Reader rdr) throws APIException;\r
+       \r
+       public Data<T> in(TYPE type);\r
+       public Data<T> out(TYPE type);\r
+       /**\r
+        * Return the Class Type supported by this DataObject\r
+        * \r
+        * @return {@literal Class<T>}\r
+        */\r
+       public Class<T> getTypeClass();\r
+\r
+       public void direct(InputStream input, OutputStream output) throws APIException, IOException;\r
+\r
+\r
 }
\ No newline at end of file
index 4ce7eaf..a9595a5 100644 (file)
@@ -1,30 +1,30 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-
-public interface DataFactory<T> {
-       public abstract Data<T> newData();
-       public abstract Data<T> newData(Env trans); // and Env or Trans object
-       public abstract Class<T> getTypeClass();
-}
-
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+\r
+public interface DataFactory<T> {\r
+       public abstract Data<T> newData();\r
+       public abstract Data<T> newData(Env trans); // and Env or Trans object\r
+       public abstract Class<T> getTypeClass();\r
+}\r
+\r
index 039cb2f..bc29c31 100644 (file)
@@ -1,34 +1,34 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-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;
-               }
-       };
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+\r
+public interface Decryptor {\r
+       public String decrypt(String tag);\r
+       \r
+       public static final Decryptor NULL = new Decryptor() {\r
+               @Override\r
+               public String decrypt(String tag) {\r
+                       return tag;\r
+               }\r
+       };\r
+}\r
index 9e62113..ad7409d 100644 (file)
@@ -1,34 +1,34 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-
-public interface Encryptor {
-       public String encrypt(String data);
-
-       public static final Encryptor NULL = new Encryptor() {
-               @Override
-               public String encrypt(String data) {
-                       return data;
-               }
-       };
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+\r
+public interface Encryptor {\r
+       public String encrypt(String data);\r
+\r
+       public static final Encryptor NULL = new Encryptor() {\r
+               @Override\r
+               public String encrypt(String data) {\r
+                       return data;\r
+               }\r
+       };\r
+}\r
index 71f7922..e4b6aaa 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-
-/**
- * <H1>Env</H1>
- * <i>Env</i> is the basic representation of what can be obtained from the
- * Environment.  Environments also need the ability to Log and Track Time, so
- * to keep the interfaces clean, Env Interface inherits from Trans.  This does NOT
- * mean that all Environments are Transactions... It only means Environments need 
- * to Log and Track Times. 
- * .<p>
- * 
- * Using this abstraction, Components can be built on a modular basis,
- * and still have the essentials of functioning within the service mechanism.<p>
- * 
- * Thus, for instance, an Module could be made to work in two separate
- * service types, with substantial differences in choices of logging, or auditing,
- * and still have reasonably deep insight, such as the exact time a
- * remote service was invoked.<p>
- * 
- * There is a bit of an assumption corresponding to the reality of the 2000s that
- * XML plays a part in most service work.
- *  
- * @author Jonathan
- *
- */
-public interface Env {
-       /**
-        * 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();
-
-       /**
-        * 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();
-
-
-       /**
-        * 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();
-
-}
-
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+\r
+/**\r
+ * <H1>Env</H1>\r
+ * <i>Env</i> is the basic representation of what can be obtained from the\r
+ * Environment.  Environments also need the ability to Log and Track Time, so\r
+ * to keep the interfaces clean, Env Interface inherits from Trans.  This does NOT\r
+ * mean that all Environments are Transactions... It only means Environments need \r
+ * to Log and Track Times. \r
+ * .<p>\r
+ * \r
+ * Using this abstraction, Components can be built on a modular basis,\r
+ * and still have the essentials of functioning within the service mechanism.<p>\r
+ * \r
+ * Thus, for instance, an Module could be made to work in two separate\r
+ * service types, with substantial differences in choices of logging, or auditing,\r
+ * and still have reasonably deep insight, such as the exact time a\r
+ * remote service was invoked.<p>\r
+ * \r
+ * There is a bit of an assumption corresponding to the reality of the 2000s that\r
+ * XML plays a part in most service work.\r
+ *  \r
+ * @author Jonathan\r
+ *\r
+ */\r
+public interface Env {\r
+       /**\r
+        * Very Severe Error may cause program to abort\r
+        */\r
+       public LogTarget fatal();\r
+       \r
+       /**\r
+        * Severe Error, but program might continue running\r
+        */\r
+       public LogTarget error();\r
+\r
+       /**\r
+        * Required Audit statements\r
+        * @return\r
+        */\r
+       public LogTarget audit();\r
+\r
+       /**\r
+        * Initialization steps... Allows a Logger to separate startup info\r
+        * @return\r
+        */\r
+       public LogTarget init();\r
+\r
+       /**\r
+        * Potentially harmful situations\r
+        * @return\r
+        */\r
+       public LogTarget warn();\r
+       \r
+       /**\r
+        * Course Grained highlights of program progress\r
+        * @return\r
+        */\r
+       public LogTarget info();\r
+       \r
+       /**\r
+        * Fine-grained informational events useful for debugging\r
+        * @return\r
+        */\r
+       public LogTarget debug();\r
+       \r
+       /**\r
+        * Finest grained Informational events... more detailed than Debug\r
+        * @return\r
+        */\r
+       public LogTarget trace();\r
+\r
+\r
+       /**\r
+        * Basic and Common Audit info... \r
+        *  \r
+        * Note Apps can define, but should use Integers after 0x1F.  They can combine with "&"\r
+        */\r
+       public static final int REMOTE = 0x01;\r
+       public static final int XML = 0x02;\r
+       public static final int JSON = 0x04;\r
+       public static final int SUB = 0x08;\r
+       public static final int CHECKPOINT = 0x10;\r
+       public static final int ALWAYS = 0x20; // Mark as a line to print, even in WARN+ mode\r
+\r
+\r
+       \r
+       /**\r
+        * Start a Time Trail with differentiation by flag.  This can be Defined By above flags or combined with\r
+        * app flag definitions\r
+        * \r
+        * @param string\r
+        * @param flag\r
+        * @return\r
+        */\r
+       public TimeTaken start(String name, int flag);\r
+       \r
+       public String setProperty(String tag, String value);\r
+       public String getProperty(String tag);\r
+       public String getProperty(String tag, String deflt);\r
+       \r
+       /**\r
+        * Passwords should be encrypted on the disk.  Use this method to apply decryption before\r
+        * using.  The Implementation should give ways to decrypt\r
+        * \r
+        * @param tag\r
+        * @return\r
+        */\r
+       public Decryptor decryptor();\r
+       \r
+       public Encryptor encryptor();\r
+\r
+}\r
+\r
index 27f423b..a530073 100644 (file)
@@ -1,52 +1,52 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-import javax.xml.namespace.QName;
-import javax.xml.validation.Schema;
-
-public interface EnvJAXB extends EnvStore<TransJAXB> {
-       /**
-        * Obtain a DataInterface from this Environment
-        * 
-        * @param <T>
-        * @param classes
-        * @return
-        * @throws APIException
-        */
-       public <T> DataFactory<T> newDataFactory(Class<?>... classes) throws APIException;
-
-       /**
-        * Obtain a DataInterface from this Environment, with Validating Schema
-        * 
-        * @param <T>
-        * @param classes
-        * @return
-        * @throws APIException
-        */
-       public <T> DataFactory<T> newDataFactory(Schema schema, Class<?>... classes) throws APIException;
-
-       public<T> DataFactory<T> newDataFactory(QName qName, Class<?> ... classes)      throws APIException;
-
-       public<T> DataFactory<T> newDataFactory(Schema schema, QName qName, Class<?> ... classes) throws APIException;
-       
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+import javax.xml.namespace.QName;\r
+import javax.xml.validation.Schema;\r
+\r
+public interface EnvJAXB extends EnvStore<TransJAXB> {\r
+       /**\r
+        * Obtain a DataInterface from this Environment\r
+        * \r
+        * @param <T>\r
+        * @param classes\r
+        * @return\r
+        * @throws APIException\r
+        */\r
+       public <T> DataFactory<T> newDataFactory(Class<?>... classes) throws APIException;\r
+\r
+       /**\r
+        * Obtain a DataInterface from this Environment, with Validating Schema\r
+        * \r
+        * @param <T>\r
+        * @param classes\r
+        * @return\r
+        * @throws APIException\r
+        */\r
+       public <T> DataFactory<T> newDataFactory(Schema schema, Class<?>... classes) throws APIException;\r
+\r
+       public<T> DataFactory<T> newDataFactory(QName qName, Class<?> ... classes)      throws APIException;\r
+\r
+       public<T> DataFactory<T> newDataFactory(Schema schema, QName qName, Class<?> ... classes) throws APIException;\r
+       \r
+}\r
index 1aba746..f0f75aa 100644 (file)
@@ -1,31 +1,31 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-/**
- * An interface to express both JAXB and Property elements of Env
- * @author Jonathan
- *
- */
-public interface EnvJAXBProps extends EnvJAXB, EnvProps {
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+/**\r
+ * An interface to express both JAXB and Property elements of Env\r
+ * @author Jonathan\r
+ *\r
+ */\r
+public interface EnvJAXBProps extends EnvJAXB, EnvProps {\r
+\r
+}\r
index 2bfc027..0e645da 100644 (file)
@@ -1,80 +1,80 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-import java.util.Map;
-
-public interface EnvProps extends Env {
-       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)
-        * 
-        * 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<String, String> getSubProperties(String key, boolean includePrefix);
-
-       /**
-        * Get all of the properties in the Environment
-        * @return
-        */
-       public Map<String, String> getProperties();
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+import java.util.Map;\r
+\r
+public interface EnvProps extends Env {\r
+       public interface EnvProperty {\r
+               public String getProperty(String input);\r
+       };\r
+\r
+       /**\r
+        * Obtain a Property (String) based on a Key.  Implementor decides how\r
+        * that works, i.e. from a complex set of Configurations, or just \r
+        * "System" (Java standard)\r
+        * \r
+        * @param key\r
+        * @return APIException\r
+        */\r
+       public String getProperty(String key);\r
+\r
+       /**\r
+        * Obtain a Property (String) based on a Key.  Implementor decides how\r
+        * that works, i.e. from a complex set of Configurations, or just \r
+        * "System" (Java standard)\r
+        * \r
+        * If Property Value is null, then default will be used.\r
+        * @param key\r
+        * @return APIException\r
+        */\r
+       public String getProperty(String tag, String defaultValue);\r
+\r
+       /**\r
+        * Set a Property (String) based on a Key accessible to all in Env.  Implementor decides how\r
+        * that works, i.e. from a complex set of Configurations, or just \r
+        * "System" (Java standard)\r
+        * \r
+        * @param key\r
+        * @return APIException\r
+        */\r
+       public String setProperty(String key, String value);\r
+       \r
+       /**\r
+        * Get the SubProperties based on key.\r
+        * \r
+        * use "false" to remove prefix, "true" to leave prefix in.\r
+        * \r
+        * @param key\r
+        * @return APIException\r
+        * Given a known property set (or in this case, properties starting with key), \r
+        * return map of all properties with appropriate key names\r
+        */\r
+       public Map<String, String> getSubProperties(String key, boolean includePrefix);\r
+\r
+       /**\r
+        * Get all of the properties in the Environment\r
+        * @return\r
+        */\r
+       public Map<String, String> getProperties();\r
+\r
+}\r
index 32dda01..bad31de 100644 (file)
@@ -1,27 +1,27 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-
-public interface EnvStore<TRANS extends Trans> extends Env, Store, TransCreate<TRANS>{
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+\r
+public interface EnvStore<TRANS extends Trans> extends Env, Store, TransCreate<TRANS>{\r
+\r
+}\r
index d4e2868..e3e7430 100644 (file)
@@ -1,54 +1,54 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-import java.io.InputStream;
-import java.io.Reader;
-
-public interface IOObjectifier<T> extends Objectifier<T> {
-       /**
-        * Marshal to Object T from a Reader, using contents from Env as necessary.<p>
-        * 
-        * 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.<p>
-        * 
-        * 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;
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+import java.io.InputStream;\r
+import java.io.Reader;\r
+\r
+public interface IOObjectifier<T> extends Objectifier<T> {\r
+       /**\r
+        * Marshal to Object T from a Reader, using contents from Env as necessary.<p>\r
+        * \r
+        * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark\r
+        * XML time, since this is often a costly process.\r
+        *\r
+        * @param env\r
+        * @param input\r
+        * @return T\r
+        * @throws APIException\r
+        */\r
+       public abstract T objectify(Env env, Reader rdr) throws APIException;\r
+       \r
+       /**\r
+        * Marshal to Object T from an InputStream, using contents from Env as necessary.<p>\r
+        * \r
+        * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark\r
+        * XML time, since this is often a costly process.\r
+        *\r
+        * @param env\r
+        * @param input\r
+        * @return T\r
+        * @throws APIException\r
+        */\r
+       public abstract T objectify(Env env, InputStream is) throws APIException;\r
+\r
+}\r
index 1eab8db..57d8547 100644 (file)
@@ -1,74 +1,74 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-import java.io.OutputStream;
-import java.io.Writer;
-
-/**
- * Allow Extended IO interface usage without muddying up the Stringifier Interface
- */
-public interface IOStringifier<T> extends Stringifier<T> {
-       /**
-        * Marshal from an Object T onto a Writer, using contents from Env as necessary.<p>
-        * 
-        * Implementations should use the {@link Env} to call "env.startTime(<string>, 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.<p>
-        * 
-        * 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<T> pretty(boolean pretty);
-
-       /**
-        * Set Generate Fragment
-        * 
-        * @param fragment
-        * @throws APIException
-        */
-       public abstract IOStringifier<T> asFragment(boolean fragment);
-
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+import java.io.OutputStream;\r
+import java.io.Writer;\r
+\r
+/**\r
+ * Allow Extended IO interface usage without muddying up the Stringifier Interface\r
+ */\r
+public interface IOStringifier<T> extends Stringifier<T> {\r
+       /**\r
+        * Marshal from an Object T onto a Writer, using contents from Env as necessary.<p>\r
+        * \r
+        * Implementations should use the {@link Env} to call "env.startTime(<string>, Env.XML)" to mark\r
+        * XML time, since this is often a costly process.\r
+        *\r
+        * @param env\r
+        * @param input\r
+        * @return String\r
+        * @throws APIException\r
+        */\r
+       public abstract void stringify(Env env, T input, Writer writer, boolean ... options) throws APIException;\r
+       \r
+       /**\r
+        * Marshal from a String to an Object T, using contents from Env as necessary.<p>\r
+        * \r
+        * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark\r
+        * XML time, since this is often a costly process.\r
+        *\r
+        * @param env\r
+        * @param input\r
+        * @return String\r
+        * @throws APIException\r
+        */\r
+       public abstract void stringify(Env env, T input, OutputStream os, boolean ... options) throws APIException;\r
+\r
+       /**\r
+        * Set Pretty XML, where possible\r
+        * \r
+        * @param pretty\r
+        * @throws APIException\r
+        */\r
+       public abstract IOStringifier<T> pretty(boolean pretty);\r
+\r
+       /**\r
+        * Set Generate Fragment\r
+        * \r
+        * @param fragment\r
+        * @throws APIException\r
+        */\r
+       public abstract IOStringifier<T> asFragment(boolean fragment);\r
+\r
+\r
+}\r
index 3e14511..5124f6b 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-/**
- *
- * Created on: Aug 19, 2009
- * Created by: Jonathan
- *
- * (c) 2009 SBC Knowledge Ventures, L.P. All rights reserved.
- ******************************************************************* 
- * RESTRICTED - PROPRIETARY INFORMATION The Information contained 
- * herein is for use only by authorized employees of AT&T Services, 
- * Inc., and authorized Affiliates of AT&T Services, Inc., and is 
- * not for general distribution within or outside the respective 
- * companies. 
- *******************************************************************
- */
-package org.onap.aaf.misc.env;
-
-import org.onap.aaf.misc.env.util.RefreshableThreadObject;
-
-
-/**
- * @author Jonathan
- * 
- */
-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.
-        * <p>
-        * 
-        * 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.
-        * <p>
-        * 
-        * {@link ThreadLocal} is a valuable resource, but start up times within the
-        * thread, depending on what it is, can be substantial.
-        * <p>
-        * 
-        * 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.
-        * <p>
-        * 
-        * This mechanism allows the Service to recognize events, such as file
-        * changes, and pass on the event to all LifeCycle implementors.
-        * <p>
-        * 
-        * The code should take the opportunity to evaluate configuration and change
-        * as necessary.
-        * <p>
-        * 
-        * <h2>IMPORTANT:</h2>
-        * 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 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;
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+/**\r
+ *\r
+ * Created on: Aug 19, 2009\r
+ * Created by: Jonathan\r
+ *\r
+ * (c) 2009 SBC Knowledge Ventures, L.P. All rights reserved.\r
+ ******************************************************************* \r
+ * RESTRICTED - PROPRIETARY INFORMATION The Information contained \r
+ * herein is for use only by authorized employees of AT&T Services, \r
+ * Inc., and authorized Affiliates of AT&T Services, Inc., and is \r
+ * not for general distribution within or outside the respective \r
+ * companies. \r
+ *******************************************************************\r
+ */\r
+package org.onap.aaf.misc.env;\r
+\r
+import org.onap.aaf.misc.env.util.RefreshableThreadObject;\r
+\r
+\r
+/**\r
+ * @author Jonathan\r
+ * \r
+ */\r
+public interface LifeCycle {\r
+       /**\r
+        * The Service using LifeCycle Elements is required to call this method at\r
+        * the appropriate startup time. This is better for services than a simple\r
+        * static call, because the exact moment of starting can be determined\r
+        * programatically.\r
+        * <p>\r
+        * \r
+        * An excellent use is to establish security credentials with a backend\r
+        * after appropriate configurations have been read and available as part of\r
+        * the {@link Env} Object.\r
+        * \r
+        * @param env\r
+        * @throws APIException\r
+        */\r
+       public abstract void servicePrestart(Env env) throws APIException;\r
+\r
+       /**\r
+        * Many cases of implementations are not thread safe, and mechanisms must be\r
+        * derived to accomodate them by holding per Thread.\r
+        * <p>\r
+        * \r
+        * {@link ThreadLocal} is a valuable resource, but start up times within the\r
+        * thread, depending on what it is, can be substantial.\r
+        * <p>\r
+        * \r
+        * Use ThreadPrestart to do all that is possible before actually performing\r
+        * work, i.e. inside of a client transaction.\r
+        * \r
+        * @param env\r
+        * @throws APIException\r
+        */\r
+       public abstract void threadPrestart(Env env) throws APIException;\r
+\r
+       /**\r
+        * The Service will call this when (service-defined) configurations change.\r
+        * <p>\r
+        * \r
+        * This mechanism allows the Service to recognize events, such as file\r
+        * changes, and pass on the event to all LifeCycle implementors.\r
+        * <p>\r
+        * \r
+        * The code should take the opportunity to evaluate configuration and change\r
+        * as necessary.\r
+        * <p>\r
+        * \r
+        * <h2>IMPORTANT:</h2>\r
+        * The LifeCycle implementor cannot guarantee it will not be in the middle\r
+        * of a transaction, so it would behoove the implementor to construct\r
+        * content that does not affect anything until finished, then apply to an\r
+        * appropriate atomic action (i.e. setting an Object to a field), or even\r
+        * synchronizing.\r
+        * \r
+        * If you are using Java's "ThreadLocal", consider\r
+        * {@link RefreshableThreadObject}, because it implements LifeCycle, and\r
+        * responds to the refresh command.\r
+        * \r
+        * @param env\r
+        * @throws APIException\r
+        */\r
+       public abstract void refresh(Env env) throws APIException;\r
+\r
+       /**\r
+        * Parallel to threadPrestart, threadDestroy tells the implementor that the\r
+        * service is ending this particular thread, and to take this opportunity to\r
+        * close out any content specific to this thread that can be closed.\r
+        * \r
+        * @param env\r
+        * @throws APIException\r
+        */\r
+       public abstract void threadDestroy(Env env) throws APIException;\r
+\r
+       /**\r
+        * Parallel to servicePrestart, serviceDestroy tells the implementor that\r
+        * the service is ending, and to take this opportunity to close out any\r
+        * content under it's control that can or should be closed explicitly.\r
+        */\r
+       public abstract void serviceDestroy(Env env) throws APIException;\r
+}\r
index 7ceaf95..8915bec 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-import java.io.PrintStream;
-import java.util.Date;
-
-import org.onap.aaf.misc.env.util.Chrono;
-
-/**
- * LogTarget is the interface with which to assign any kind of Logging Implementations.
- * 
- * 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
- *   SYSOUT: Writes messages in general form to System Out
- *   SYSERR: Writes messages in general form to System Err
- *   
- * @author Jonathan
- *
- */
-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));
-               }
-
-       };
-
-
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+import java.io.PrintStream;\r
+import java.util.Date;\r
+\r
+import org.onap.aaf.misc.env.util.Chrono;\r
+\r
+/**\r
+ * LogTarget is the interface with which to assign any kind of Logging Implementations.\r
+ * \r
+ * Implement for any Logging Library of your choice, and for any logging string Format desired.\r
+ * \r
+ * Included are several Static Implementations for various uses:\r
+ *      NULL: Does nothing with Logging Messages\r
+ *   SYSOUT: Writes messages in general form to System Out\r
+ *   SYSERR: Writes messages in general form to System Err\r
+ *   \r
+ * @author Jonathan\r
+ *\r
+ */\r
+public interface LogTarget {\r
+       public abstract void log(Object... msgs);\r
+       public abstract void log(Throwable e, Object ... msgs);\r
+       public abstract boolean isLoggable();\r
+       public abstract void printf(String fmt, Object ... vars);\r
+\r
+       // A Convenient LogTarget to insert when a NO-OP is desired.\r
+       public static final LogTarget NULL = new LogTarget() {\r
+               public void log(Object ... msgs) {\r
+               }\r
+\r
+               public void log(Throwable t, Object ... msgs) {\r
+               }\r
+\r
+               public boolean isLoggable() {\r
+                       return false;\r
+               }\r
+\r
+               @Override\r
+               public void printf(String fmt, Object ... vars) {\r
+               }\r
+       };\r
+\r
+       // A Convenient LogTarget to write to the Console\r
+       public static final LogTarget SYSOUT = new LogTarget() {\r
+               public void log(Object ... msgs) {\r
+                       PrintStream out = System.out;\r
+                       out.print(org.onap.aaf.misc.env.util.Chrono.dateFmt.format(new Date()));\r
+                       out.print(": ");\r
+                       for(Object str : msgs) {\r
+                               if(str!=null) {\r
+                                       out.print(str.toString());\r
+                                       out.print(' ');\r
+                               } else {\r
+                                       out.print("null ");\r
+                               }\r
+                       }\r
+                       out.println();\r
+               }\r
+\r
+               public void log(Throwable t, Object ... msgs) {\r
+                       PrintStream out = System.out;\r
+                       out.print(Chrono.dateFmt.format(new Date()));\r
+                       out.print(": ");\r
+                       for(Object str : msgs) {\r
+                               out.print(str.toString());\r
+                               out.print(' ');\r
+                       }\r
+                       out.println();\r
+                       t.printStackTrace(out);\r
+                       out.println();\r
+               }\r
+\r
+               public boolean isLoggable() {\r
+                       return true;\r
+               }\r
+\r
+               @Override\r
+               public void printf(String fmt, Object ... vars) {\r
+                       log(String.format(fmt,vars));\r
+               }\r
+       };\r
+       \r
+       // A Convenient LogTarget to write to the Console\r
+       public static final LogTarget SYSERR = new LogTarget() {\r
+               public void log(Object ... msgs) {\r
+                       PrintStream out = System.err;\r
+                       out.print(Chrono.dateFmt.format(new Date()));\r
+                       out.print(": ");\r
+                       for(Object str : msgs) {\r
+                               out.print(str.toString());\r
+                               out.print(' ');\r
+                       }\r
+                       out.println();\r
+                       out.flush();\r
+               }\r
+\r
+               public void log(Throwable t, Object ... msgs) {\r
+                       PrintStream out = System.err;\r
+                       out.print(Chrono.dateFmt.format(new Date()));\r
+                       out.print(": ");\r
+                       for(Object str : msgs) {\r
+                               out.print(str.toString());\r
+                               out.print(' ');\r
+                       }\r
+                       out.println();\r
+                       t.printStackTrace(out);\r
+               }\r
+\r
+               public boolean isLoggable() {\r
+                       return true;\r
+               }\r
+               @Override\r
+               public void printf(String fmt, Object ... vars) {\r
+                       log(String.format(fmt,vars));\r
+               }\r
+\r
+       };\r
+\r
+\r
 };
\ No newline at end of file
index 09397de..039855e 100644 (file)
@@ -1,57 +1,57 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-/**
- * 
- */
-package org.onap.aaf.misc.env;
-
-
-
-/**
- * <h1>Objectifier</h1>
- * <i>Objectifier</i> abstracts the unmarshaling of an Object from a String, and 
- * the creation of an uninitialized object. 
- */
-public interface Objectifier<T> extends LifeCycle {
-       /**
-        * Marshal to Object T from a String, using contents from Env as necessary.<p>
-        * 
-        * 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;
-
-       
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+/**\r
+ * \r
+ */\r
+package org.onap.aaf.misc.env;\r
+\r
+\r
+\r
+/**\r
+ * <h1>Objectifier</h1>\r
+ * <i>Objectifier</i> abstracts the unmarshaling of an Object from a String, and \r
+ * the creation of an uninitialized object. \r
+ */\r
+public interface Objectifier<T> extends LifeCycle {\r
+       /**\r
+        * Marshal to Object T from a String, using contents from Env as necessary.<p>\r
+        * \r
+        * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark\r
+        * XML time, since this is often a costly process.\r
+        *\r
+        * @param env\r
+        * @param input\r
+        * @return T\r
+        * @throws APIException\r
+        */\r
+       public abstract T objectify(Env env, String input) throws APIException;\r
+\r
+       /**\r
+        * Create a new object of type T.  This is often more efficiently done with\r
+        * the underlying XML (or other) Library.\r
+        * @return T\r
+        * @throws APIException\r
+        */\r
+       public abstract T newInstance() throws APIException;\r
+\r
+       \r
 }
\ No newline at end of file
index e202472..f79d12d 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-/**
- * Slot.java
- *
- * Created on: Dec 5, 2008
- * Created by: Jonathan
- *
- * (c) 2008 SBC Knowledge Ventures, L.P. All rights reserved.
- ******************************************************************* 
- * RESTRICTED - PROPRIETARY INFORMATION The Information contained 
- * herein is for use only by authorized employees of AT&T Services, 
- * Inc., and authorized Affiliates of AT&T Services, Inc., and is 
- * not for general distribution within or outside the respective 
- * companies. 
- *******************************************************************
- */
-package org.onap.aaf.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;
-       }
-
-       /**
-        * Get an Object from the slot on the State
-        * @param state
-        * @param obj
-        */
-       public Object get(Object[] state) {
-               return state[slot];
-       }
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+/**\r
+ * Slot.java\r
+ *\r
+ * Created on: Dec 5, 2008\r
+ * Created by: Jonathan\r
+ *\r
+ * (c) 2008 SBC Knowledge Ventures, L.P. All rights reserved.\r
+ ******************************************************************* \r
+ * RESTRICTED - PROPRIETARY INFORMATION The Information contained \r
+ * herein is for use only by authorized employees of AT&T Services, \r
+ * Inc., and authorized Affiliates of AT&T Services, Inc., and is \r
+ * not for general distribution within or outside the respective \r
+ * companies. \r
+ *******************************************************************\r
+ */\r
+package org.onap.aaf.misc.env;\r
+\r
+/**\r
+ * Slot's are used to store and retrieve data in the transaction's State object.\r
+ */\r
+public final class Slot {\r
+       \r
+       /*\r
+        * The name of the Slot.\r
+        */\r
+       private final String key;\r
+       \r
+       /*\r
+        * The index of the State's local map associated with this Slot.\r
+        */\r
+       final int slot; \r
+       \r
+       /**\r
+        * Constructs a new Slot.\r
+        * \r
+        * @param index\r
+        *                      The index of State's local map this Slot is associated with.\r
+        * @param name\r
+        *                      The name of the Slot's key.\r
+        */\r
+       Slot(int index, String name) {\r
+               slot = index;\r
+               key = name;\r
+       }\r
+       \r
+       /**\r
+        * Debug method only to print key=slot pairs.\r
+        */\r
+       public String toString() {\r
+               return key + '=' + slot;\r
+       }\r
+       \r
+       /**\r
+        * Returns the name of this Slot's key.\r
+        * \r
+        * @return\r
+        *                      The name of this Slot's key.\r
+        */\r
+       public String getKey() {\r
+               return key;\r
+       }\r
+       \r
+       /**\r
+        * Put an Object into the slot on the State\r
+        * @param state\r
+        * @param obj\r
+        */\r
+       public void put(Object[] state, Object obj) {\r
+               state[slot]=obj;\r
+       }\r
+\r
+       /**\r
+        * Get an Object from the slot on the State\r
+        * @param state\r
+        * @param obj\r
+        */\r
+       public Object get(Object[] state) {\r
+               return state[slot];\r
+       }\r
+\r
+}\r
index 4a1033f..35bad1b 100644 (file)
@@ -1,85 +1,85 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-/**
- * Slot.java
- *
- * Created on: Dec 5, 2008
- * Created by: Jonathan
- *
- * (c)2008 SBC Knowledge Ventures, L.P. All rights reserved.
- ******************************************************************* 
- * RESTRICTED - PROPRIETARY INFORMATION The Information contained 
- * herein is for use only by authorized employees of AT&T Services, 
- * Inc., and authorized Affiliates of AT&T Services, Inc., and is 
- * not for general distribution within or outside the respective 
- * companies. 
- *******************************************************************
- */
-package org.onap.aaf.misc.env;
-
-/**
- * StaticSlot's are used to store and retrieve data from the Organizer that does not change.
- */
-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;
-       }
-
-}
-
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+/**\r
+ * Slot.java\r
+ *\r
+ * Created on: Dec 5, 2008\r
+ * Created by: Jonathan\r
+ *\r
+ * (c)2008 SBC Knowledge Ventures, L.P. All rights reserved.\r
+ ******************************************************************* \r
+ * RESTRICTED - PROPRIETARY INFORMATION The Information contained \r
+ * herein is for use only by authorized employees of AT&T Services, \r
+ * Inc., and authorized Affiliates of AT&T Services, Inc., and is \r
+ * not for general distribution within or outside the respective \r
+ * companies. \r
+ *******************************************************************\r
+ */\r
+package org.onap.aaf.misc.env;\r
+\r
+/**\r
+ * StaticSlot's are used to store and retrieve data from the Organizer that does not change.\r
+ */\r
+public final class StaticSlot {\r
+\r
+       /*\r
+        * The name of the StaticSlot.\r
+        */\r
+       private final String key;\r
+       \r
+       /*\r
+        * The index of the Organizer's static map associated with this StaticSlot.\r
+        */\r
+       final int slot; \r
+       \r
+       /**\r
+        * Constructs a new StaticSlot.\r
+        * \r
+        * @param index\r
+        *                      The index of Organizer's static map this StaticSlot is associated with.\r
+        * @param name\r
+        *                      The name of the StaticSlot's key.\r
+        */\r
+       StaticSlot(int index, String name) {\r
+               slot = index;\r
+               key = name;\r
+       }\r
+       \r
+       /**\r
+        * Debug method only to print key=slot pairs.\r
+        */\r
+       public String toString() {\r
+               return key + '=' + slot;\r
+       }\r
+       \r
+       /**\r
+        * Returns the name of this StaticSlot's key.\r
+        * \r
+        * @return\r
+        *                      The name of this StaticSlot's key.\r
+        */\r
+       public String getKey() {\r
+               return key;\r
+       }\r
+\r
+}\r
+\r
index 4e34dcd..43f5f52 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-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 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<String> 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 names used while creating Static Slots in a List
-        * 
-        * @return
-        */
-       public abstract List<String> 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> 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> 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);
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+import java.util.List;\r
+\r
+public interface Store {\r
+       /**\r
+        * Returns the Slot assigned to the supplied name.\r
+        * \r
+        * @param name\r
+        *                      The name of the Slot to acquire.\r
+        * @return\r
+        *                      The Slot associated with the supplied name.\r
+        */\r
+       public abstract Slot slot(String name);\r
+\r
+       /**\r
+        * Returns the existing Slot associated with the supplied name, or null if it doesn't exist.\r
+        * \r
+        * @param name\r
+        *                      The name of the Slot to get.\r
+        * @return\r
+        *                      The Slot assigned to the supplied name, or null if it doesn't exist.\r
+        *                      \r
+        */\r
+       public abstract Slot existingSlot(String name);\r
+\r
+       /**\r
+        * Returns the names used while creating Slots in a List\r
+        * \r
+        * @return\r
+        */\r
+       public abstract List<String> existingSlotNames();\r
+\r
+       /**\r
+        * Returns the StaticSlot assigned to the supplied name.\r
+        * \r
+        * @param name\r
+        *                      The name of the StaticSlot to acquire.\r
+        * @return\r
+        *                      The StaticSlot associated with the supplied name.\r
+        */\r
+       public abstract StaticSlot staticSlot(String name);\r
+\r
+       /**\r
+        * Returns the names used while creating Static Slots in a List\r
+        * \r
+        * @return\r
+        */\r
+       public abstract List<String> existingStaticSlotNames();\r
+       \r
+       /**\r
+        * Store the supplied value in the StaticSlot of the Organizer's static state.\r
+        * \r
+        * @param slot\r
+        *                      The StaticSlot used to store the object.\r
+        * @param value\r
+        *                      The object to store.\r
+        */\r
+       public abstract void put(StaticSlot slot, Object value);\r
+\r
+       /**\r
+        * Returns an Object from the Organizer's static state, or the Default if null\r
+        * \r
+        * @param slot\r
+        *                      The StaticSlot to retrieve the data from.\r
+        * @return\r
+        *                      The Object located in the supplied StaticSlot of the Organizer's static state.\r
+        */\r
+       public abstract<T> T get(StaticSlot slot, T dflt);\r
+\r
+       /**\r
+        * Returns an Object from the Organizer's static state \r
+        * \r
+        * @param slot\r
+        *                      The StaticSlot to retrieve the data from.\r
+        * @return\r
+        *                      The Object located in the supplied StaticSlot of the Organizer's static state.\r
+        */\r
+       public abstract<T> T get(StaticSlot slot);\r
+\r
+//     /** \r
+//      * Transfer (targeted) Args to Slots\r
+//      * \r
+//      * Transfer Strings with format "tag=value" into Static Slots\r
+//      */\r
+//     public abstract void transfer(String args[], String ... tagss);\r
 }
\ No newline at end of file
index 90fb1f2..54b0ce8 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.lang.reflect.GenericArrayType;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map.Entry;
-
-import org.onap.aaf.misc.env.util.Split;
-
-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<String, Slot> localMap;
-       
-       /*
-        * The name/slot map for Static State.
-        */
-       private HashMap<String, StaticSlot> staticMap;
-
-       private Object[] staticState;
-       
-       public StoreImpl() {
-                staticState = new Object[growSize];
-                staticMap = new HashMap<String,StaticSlot>();
-                localMap = new HashMap<String,Slot>();
-       }
-       
-       public StoreImpl(String tag) {
-                staticState = new Object[growSize];
-                staticMap = new HashMap<String,StaticSlot>();
-                localMap = new HashMap<String,Slot>();
-       }
-
-       
-       public StoreImpl(String tag, String[] args) {
-                staticState = new Object[growSize];
-                staticMap = new HashMap<String,StaticSlot>();
-                localMap = new HashMap<String,Slot>();
-
-                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<Object, Object> 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<String,StaticSlot>();
-                localMap = new HashMap<String,Slot>();
-                
-                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<Object, Object> 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<Object, Object> 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<String> existingSlotNames() {
-               return new ArrayList<String>(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> T get(StaticSlot sslot,T dflt) {
-               T t = (T)staticState[sslot.slot];
-               return t==null?dflt:t;
-       }
-
-       @SuppressWarnings("unchecked")
-       public <T> T get(StaticSlot sslot) {
-               return (T)staticState[sslot.slot];
-       }
-
-       public List<String> existingStaticSlotNames() {
-               return new ArrayList<String>(staticMap.keySet());
-       }
-}
-
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.IOException;\r
+import java.lang.reflect.GenericArrayType;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map.Entry;\r
+\r
+import org.onap.aaf.misc.env.util.Split;\r
+\r
+import java.util.Properties;\r
+\r
+\r
+public class StoreImpl implements Store {\r
+       /*\r
+        * The re-adjustment factor for growing the Static State array. \r
+        */\r
+       private static final int growSize = 10;\r
+       \r
+       /*\r
+        * The index reference for Slot assignment.\r
+        */\r
+       private int local;\r
+       \r
+       /*\r
+        * The index reference for StaticSlot assignment. \r
+        */\r
+       private int stat;\r
+       \r
+       /*\r
+        * The name/slot map for local (transaction specific) State.\r
+        */\r
+       private HashMap<String, Slot> localMap;\r
+       \r
+       /*\r
+        * The name/slot map for Static State.\r
+        */\r
+       private HashMap<String, StaticSlot> staticMap;\r
+\r
+       private Object[] staticState;\r
+       \r
+       public StoreImpl() {\r
+                staticState = new Object[growSize];\r
+                staticMap = new HashMap<String,StaticSlot>();\r
+                localMap = new HashMap<String,Slot>();\r
+       }\r
+       \r
+       public StoreImpl(String tag) {\r
+                staticState = new Object[growSize];\r
+                staticMap = new HashMap<String,StaticSlot>();\r
+                localMap = new HashMap<String,Slot>();\r
+       }\r
+\r
+       \r
+       public StoreImpl(String tag, String[] args) {\r
+                staticState = new Object[growSize];\r
+                staticMap = new HashMap<String,StaticSlot>();\r
+                localMap = new HashMap<String,Slot>();\r
+\r
+                if(tag!=null) {\r
+                       String tequals = tag + '=';\r
+                       for(String arg : args) {\r
+                               if(arg.startsWith(tequals) && !arg.equals(tequals)) { // needs to have something after =\r
+                                       Properties props = new Properties();\r
+                                       for(String f : Split.split(File.pathSeparatorChar,arg.substring(tequals.length()))) {\r
+                                               moreProps(new File(f),props);\r
+                                       }\r
+                                       for(Entry<Object, Object> es : props.entrySet()) {\r
+                                               put(staticSlot(es.getKey().toString()),es.getValue());\r
+                                       }\r
+                               }\r
+                       }\r
+                }\r
+\r
+               // Make sure properties on command line override those in Props\r
+               propsFromArgs(tag,args);\r
+       }\r
+       \r
+       public StoreImpl(String tag, Properties props) {\r
+                staticState = new Object[growSize];\r
+                staticMap = new HashMap<String,StaticSlot>();\r
+                localMap = new HashMap<String,Slot>();\r
+                \r
+                if(tag!=null) {\r
+                        String fname = props.getProperty(tag);\r
+                        if(fname!=null) {\r
+                                for(String f : Split.split(File.pathSeparatorChar,fname)) {\r
+                                        if(!moreProps(new File(f),props)) {\r
+                                               System.err.println("Unable to load Properties from " + f); \r
+                                        }\r
+                                }\r
+                        }\r
+                }\r
+\r
+                for(Entry<Object, Object> es : props.entrySet()) {\r
+                        put(staticSlot(es.getKey().toString()),es.getValue());\r
+                }\r
+       }\r
+\r
+       public void propsFromArgs(String tag, String[] args) {\r
+               if(tag!=null) {\r
+                       for(String arg : args) {\r
+                               String sarg[] = Split.split('=',arg);\r
+                               if(sarg.length==2) {\r
+                                       if(tag.equals(sarg[0])) {\r
+                                               for(String fname : Split.split(File.pathSeparatorChar,sarg[1])) {\r
+                                                       moreProps(new File(fname),null /* no target */);\r
+                                               }\r
+                                       }\r
+                                       put(staticSlot(sarg[0]),sarg[1]);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       private boolean moreProps(File f, Properties target) {\r
+                if(f.exists()) {\r
+                        Properties props = new Properties();\r
+                        try {\r
+                                FileInputStream fis = new FileInputStream(f);\r
+                                try {\r
+                                        props.load(fis);\r
+                                        if(target!=null) {\r
+                                                target.load(fis);\r
+                                        }\r
+                                } finally {\r
+                                        fis.close();\r
+                                }\r
+                        } catch(IOException e) {\r
+                                System.err.println(e);\r
+                        }\r
+                        for(Entry<Object, Object> es : props.entrySet()) {\r
+                                put(staticSlot(es.getKey().toString()),es.getValue());\r
+                        }\r
+                        return true;\r
+                } else {\r
+                        return false;\r
+                }\r
+       }\r
+\r
+       public Object[] newTransState() {\r
+               return new Object[local];\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see com.att.env.Store#slot(java.lang.String)\r
+        */\r
+       public synchronized Slot slot(String name) {\r
+               name = name == null ? "" : name.trim();\r
+               Slot slot = localMap.get(name);\r
+               if (slot == null)  {\r
+                       slot = new Slot(local++, name);\r
+                       localMap.put(name, slot);\r
+               }\r
+               return slot;\r
+       }\r
+       \r
+       \r
+       /* (non-Javadoc)\r
+        * @see com.att.env.Store#existingSlot(java.lang.String)\r
+        */\r
+       public Slot existingSlot(String name) {\r
+               return localMap.get(name);\r
+       }\r
+       \r
+       /* (non-Javadoc)\r
+        * @see com.att.env.Store#existingSlotNames()\r
+        */\r
+       public List<String> existingSlotNames() {\r
+               return new ArrayList<String>(localMap.keySet());\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see com.att.env.Store#staticSlot(java.lang.String)\r
+        */\r
+       public synchronized StaticSlot staticSlot(String name) {\r
+               name = name == null ? "" : name.trim();\r
+               StaticSlot slot = staticMap.get(name);\r
+               if (slot == null)  {\r
+                       if (stat%growSize == 0) {\r
+                               Object[] temp = staticState;\r
+                               staticState = new Object[temp.length+growSize];\r
+                               System.arraycopy(temp, 0, staticState, 0, temp.length);\r
+                       }\r
+                       slot = new StaticSlot(stat++, name);\r
+                       staticMap.put(name, slot);\r
+               }\r
+               return slot;\r
+       }\r
+       \r
+       /* (non-Javadoc)\r
+        * @see com.att.env.Store#put(com.att.env.StaticSlot, java.lang.Object)\r
+        */\r
+       public void put(StaticSlot slot, Object value) {\r
+               staticState[slot.slot] = value;\r
+       }\r
+       \r
+       /* (non-Javadoc)\r
+        * @see com.att.env.Store#get(com.att.env.StaticSlot T defaultObject)\r
+        */\r
+       @SuppressWarnings("unchecked")\r
+       public<T> T get(StaticSlot sslot,T dflt) {\r
+               T t = (T)staticState[sslot.slot];\r
+               return t==null?dflt:t;\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public <T> T get(StaticSlot sslot) {\r
+               return (T)staticState[sslot.slot];\r
+       }\r
+\r
+       public List<String> existingStaticSlotNames() {\r
+               return new ArrayList<String>(staticMap.keySet());\r
+       }\r
+}\r
+\r
index 3d29366..c6e0dbd 100644 (file)
@@ -1,45 +1,45 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-
-
-/**
- * <h1>Stringifier</h1>
- * <i>Stringifier</i> abstracts the marshaling of a String to an Object
- */
-public interface Stringifier<T> extends LifeCycle {
-       
-       /**
-        * Marshal from a String to an Object T, using contents from Env as necessary.<p>
-        * 
-        * 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;
-       
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+\r
+\r
+/**\r
+ * <h1>Stringifier</h1>\r
+ * <i>Stringifier</i> abstracts the marshaling of a String to an Object\r
+ */\r
+public interface Stringifier<T> extends LifeCycle {\r
+       \r
+       /**\r
+        * Marshal from a String to an Object T, using contents from Env as necessary.<p>\r
+        * \r
+        * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark\r
+        * XML time, since this is often a costly process.\r
+        *\r
+        * @param env\r
+        * @param input\r
+        * @return String\r
+        * @throws APIException\r
+        */\r
+       public abstract String stringify(Env env, T input, boolean ... options) throws APIException;\r
+       \r
 }
\ No newline at end of file
index 053d4d6..78f4a61 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-/**
- * <h1>TimeTaken</h1>
- * This simple interface allows for many different kinds of 
- * Audit Logs to be accomplished, by assuming that the creation
- * of this object indicates "start", and the calling of "done" 
- * ends.
- * 
- * The implementor of this class can easily be stored in efficient
- * mechanisms to minimize impact of Auditing on performance.
- * 
- * @author Jonathan
- *
- */
-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;
-       }
-
-
-       /**
-        * Call this when process is done to state ending time.<p>
-        * 
-        * It is <i>exceedingly prudent</i> to wrap the process called with a try-finally:<p>
-        * 
-        * <pre>
-        *   TimeTaken tt = env.startSubTime();
-        *   try {
-        *       process.me(); // code to be timed.
-        *   } finally {
-        *       tt.done();
-        *   }
-        * </pre>
-        */
-       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):"");
-       }
-       
-}              
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+/**\r
+ * <h1>TimeTaken</h1>\r
+ * This simple interface allows for many different kinds of \r
+ * Audit Logs to be accomplished, by assuming that the creation\r
+ * of this object indicates "start", and the calling of "done" \r
+ * ends.\r
+ * \r
+ * The implementor of this class can easily be stored in efficient\r
+ * mechanisms to minimize impact of Auditing on performance.\r
+ * \r
+ * @author Jonathan\r
+ *\r
+ */\r
+public abstract class TimeTaken {\r
+       public final long start;\r
+       protected long end, size;\r
+       public final int flag;\r
+       public final String name;\r
+       \r
+       /**\r
+        * The name is as it will appear when written to output (abstract method)\r
+        * \r
+        * The flag is an integer which can be System type (XML, REMOTE, etc), or End User defined for reporting purposes \r
+        * \r
+        * @param name\r
+        * @param flag\r
+        */\r
+       public TimeTaken(String name, int flag) {\r
+               start = System.nanoTime();\r
+               this.flag = flag;\r
+               this.name = name;\r
+               size = -1;\r
+       }\r
+\r
+\r
+       /**\r
+        * Call this when process is done to state ending time.<p>\r
+        * \r
+        * It is <i>exceedingly prudent</i> to wrap the process called with a try-finally:<p>\r
+        * \r
+        * <pre>\r
+        *   TimeTaken tt = env.startSubTime();\r
+        *   try {\r
+        *       process.me(); // code to be timed.\r
+        *   } finally {\r
+        *       tt.done();\r
+        *   }\r
+        * </pre>\r
+        */\r
+       public void done() {\r
+               end = System.nanoTime();\r
+       }\r
+       \r
+       \r
+       /**\r
+        * For sizable contents, set the size.  Implementations can simply write a no-op if they don't wish to \r
+        * store the size. \r
+        * \r
+        * @param size\r
+        */\r
+       public void size(long theSize) {\r
+               size = theSize;\r
+       }\r
+       \r
+       /**\r
+        * Give readonly access to End, which isn't final\r
+        * @return\r
+        */\r
+       public long end() {\r
+               return end;\r
+       }\r
+       \r
+       /**\r
+        * Time is taken in NanoSeconds.  This method converts to decimals of Milliseconds\r
+        * @return\r
+        */\r
+       public float millis() {\r
+               return (end-start)/1000000f;\r
+       }\r
+       /**\r
+        * Write self to a String Builder (for making Audits)\r
+        * @param sb\r
+        */\r
+       public abstract void output(StringBuilder sb);\r
+       \r
+       /**\r
+        * For Debugging\r
+        */\r
+       public String toString() {\r
+               return name + ' ' + millis() + "ms " + (size>0?Long.toString(size):"");\r
+       }\r
+       \r
+}              \r
index ced64e8..2447375 100644 (file)
@@ -1,74 +1,74 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-
-
-
-/**
- * A Trans is like an Env, however, it's purpose it to track the Transient 
- * Data associated with Transactions, or other short term elements.
- * 
- * Any Object implementing Trans should expect to go in an out of scope quickly
- * 
- * Implementations should also overload the concepts of "Start", etc and build up
- * and Audit Log, so it can implement "metric" below
- * 
- * All Transactions (i.e. a call to a service) will need these items.
- * 
- * @author Jonathan
- *
- */
-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, 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);
-
-       public Metric auditTrail(int indent, StringBuilder sb, int ... flag);
-
-       public class Metric {
-               public float[] buckets;
-               public float   total;
-               public int     entries;
-       }
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+\r
+\r
+\r
+/**\r
+ * A Trans is like an Env, however, it's purpose it to track the Transient \r
+ * Data associated with Transactions, or other short term elements.\r
+ * \r
+ * Any Object implementing Trans should expect to go in an out of scope quickly\r
+ * \r
+ * Implementations should also overload the concepts of "Start", etc and build up\r
+ * and Audit Log, so it can implement "metric" below\r
+ * \r
+ * All Transactions (i.e. a call to a service) will need these items.\r
+ * \r
+ * @author Jonathan\r
+ *\r
+ */\r
+public interface Trans extends Env {\r
+       /**\r
+        * Add a completed entry in the Audit Trail for tracking purposes.\r
+        * \r
+        * @param text\r
+        */\r
+       public void checkpoint(String text);\r
+\r
+       /**\r
+        * Add a completed entry in the Audit Trail for tracking purposes, and combine flag with "CHECKPOINT" \r
+        * \r
+        * @param text\r
+        */\r
+       public void checkpoint(String text, int additionalFlag);\r
+\r
+       /**\r
+        * Output an Audit Trail onto the StringBuilder\r
+        *\r
+        * Load metrics into an array of floats from passed in Flags\r
+        * \r
+        * @param flag\r
+        * @param sb\r
+        * @return       \r
+        */\r
+       public Metric auditTrail(LogTarget lt, int indent, StringBuilder sb, int ... flag);\r
+\r
+       public Metric auditTrail(int indent, StringBuilder sb, int ... flag);\r
+\r
+       public class Metric {\r
+               public float[] buckets;\r
+               public float   total;\r
+               public int     entries;\r
+       }\r
 }
\ No newline at end of file
index 7c16613..1ed4dcd 100644 (file)
@@ -1,26 +1,26 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-public interface TransCreate<TRANS> {
-       public TRANS newTrans();
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+public interface TransCreate<TRANS> {\r
+       public TRANS newTrans();\r
+}\r
index dfc12b6..2fa6493 100644 (file)
@@ -1,26 +1,26 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env;
-
-public interface TransJAXB extends Trans, TransStore {
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+public interface TransJAXB extends Trans, TransStore {\r
+\r
+}\r
index 6b50313..e9c1b39 100644 (file)
@@ -1,57 +1,57 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-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);
-
-       /**
-        *  Get data from the right slot
-        *  
-        *  This will do a cast to the expected type derived from Default
-        */
-       public<T> 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> T get(StaticSlot slot, T dflt);
-       
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env;\r
+\r
+public interface TransStore extends Trans {\r
+       /**\r
+        * Returns the Slot assigned to the supplied name.\r
+        * \r
+        * @param name\r
+        *                      The name of the Slot to acquire.\r
+        * @return\r
+        *                      The Slot associated with the supplied name.\r
+        */\r
+       public abstract Slot slot(String name);\r
+       \r
+       /**\r
+        * Put data into the right slot \r
+        */\r
+       public void put(Slot slot, Object value);\r
+\r
+       /**\r
+        *  Get data from the right slot\r
+        *  \r
+        *  This will do a cast to the expected type derived from Default\r
+        */\r
+       public<T> T get(Slot slot, T deflt);\r
+\r
+       /**\r
+        * Returns an Object from the Organizer's static state, or the Default if null\r
+        * \r
+        * @param slot\r
+        *                      The StaticSlot to retrieve the data from.\r
+        * @return\r
+        *                      The Object located in the supplied StaticSlot of the Organizer's static state.\r
+        */\r
+       public abstract<T> T get(StaticSlot slot, T dflt);\r
+       \r
+}\r
index a04b63e..f10de38 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Stack;
-
-import org.onap.aaf.misc.env.Env;
-import org.onap.aaf.misc.env.LogTarget;
-import org.onap.aaf.misc.env.Slot;
-import org.onap.aaf.misc.env.StoreImpl;
-import org.onap.aaf.misc.env.TimeTaken;
-import org.onap.aaf.misc.env.TransStore;
-
-public abstract class AbsTrans<ENV extends Env> implements TransStore {
-       private static final float[] EMPTYF = new float[0];
-       private static final Object[] EMPTYO = new Object[0];
-       
-       protected ENV delegate;
-       protected List<TimeTaken> trail = new ArrayList<TimeTaken>(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<flags.length;++i) {
-                                       if(tt.flag == flags[i]) metric.buckets[i]+=ms;
-                               }
-                       }
-               } else if(!lt.isLoggable()) {
-                       boolean first = true;
-                       for(TimeTaken tt : trail) {
-                               float ms = tt.millis();
-                               for(int i=0;i<flags.length;++i) {
-                                       if(tt.flag == flags[i]) metric.buckets[i]+=ms;
-                               }
-                               if((tt.flag&ALWAYS)==ALWAYS) {
-                                       if(first) first = false;
-                                       else sb.append('/');
-                                       sb.append(tt.name);
-                               }
-                       }                       
-               } else {
-                       Stack<Long> stack = new Stack<Long>();
-                       for(TimeTaken tt : trail) {
-                               // Create Indentation based on SUB
-                               while(!stack.isEmpty() && tt.end()>stack.peek()) {
-                                       --indent;
-                                       stack.pop();
-                               }
-                               for(int i=0;i<indent;++i) {
-                                       sb.append("  ");
-                               }
-                               tt.output(sb);
-                               sb.append('\n');
-                               if((tt.flag&SUB)==SUB) {
-                                       stack.push(tt.end());
-                                       ++indent;
-                               }
-                               
-                               // Add time values to Metric
-                               float ms = tt.millis();
-                               for(int i=0;i<flags.length;++i) {
-                                       if(tt.flag == flags[i]) metric.buckets[i]+=ms;
-                               }
-                       }
-               }
-               return metric;
-       }
-
-       /**
-        * Put data into the Trans State at the right slot 
-        */
-//     @Override
-       public void put(Slot slot, Object value) {
-               slot.put(state, value);
-       }
-
-       /**
-        *  Get data from the Trans State from the right slot
-        *  
-        *  This will do a cast to the expected type derived from Default
-        */
-//     @Override
-       @SuppressWarnings("unchecked")
-       public<T> 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;
-       }
-
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.impl;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Stack;\r
+\r
+import org.onap.aaf.misc.env.Env;\r
+import org.onap.aaf.misc.env.LogTarget;\r
+import org.onap.aaf.misc.env.Slot;\r
+import org.onap.aaf.misc.env.StoreImpl;\r
+import org.onap.aaf.misc.env.TimeTaken;\r
+import org.onap.aaf.misc.env.TransStore;\r
+\r
+public abstract class AbsTrans<ENV extends Env> implements TransStore {\r
+       private static final float[] EMPTYF = new float[0];\r
+       private static final Object[] EMPTYO = new Object[0];\r
+       \r
+       protected ENV delegate;\r
+       protected List<TimeTaken> trail = new ArrayList<TimeTaken>(30);\r
+       private Object[] state;\r
+       \r
+       \r
+    public AbsTrans(ENV delegate) {\r
+               this.delegate = delegate;\r
+               state = delegate instanceof StoreImpl?((StoreImpl) delegate).newTransState():EMPTYO;\r
+       }\r
+\r
+       //      @Override\r
+       public LogTarget fatal() {\r
+               return delegate.fatal();\r
+       }\r
+\r
+//     @Override\r
+       public LogTarget error() {\r
+               return delegate.error();\r
+       }\r
+\r
+//     @Override\r
+       public LogTarget audit() {\r
+               return delegate.audit();\r
+       }\r
+\r
+//     @Override\r
+       public LogTarget init() {\r
+               return delegate.init();\r
+       }\r
+\r
+//     @Override\r
+       public LogTarget warn() {\r
+               return delegate.warn();\r
+       }\r
+\r
+//     @Override\r
+       public LogTarget info() {\r
+               return delegate.info();\r
+       }\r
+\r
+//     @Override\r
+       public LogTarget debug() {\r
+               return delegate.debug();\r
+       }\r
+\r
+//     @Override\r
+       public LogTarget trace() {\r
+               return delegate.trace();\r
+       }\r
+\r
+       /**\r
+        * Let the final Trans Implementation choose the exact kind of TimeTaken to use\r
+        * @param name\r
+        * @param flag\r
+        * @return\r
+        */\r
+       protected abstract TimeTaken newTimeTaken(String name, int flag);\r
+       \r
+//     @Override\r
+       public final TimeTaken start(String name, int flag) {\r
+               TimeTaken tt = newTimeTaken(name,flag);\r
+               trail.add(tt);\r
+               return tt;\r
+       }\r
+       \r
+//     @Override\r
+       public final void checkpoint(String name) {\r
+               TimeTaken tt = newTimeTaken(name,CHECKPOINT);\r
+               tt.done();\r
+               trail.add(tt);\r
+       }\r
+\r
+       public final void checkpoint(String name, int additionalFlag) {\r
+               TimeTaken tt = newTimeTaken(name,CHECKPOINT|additionalFlag);\r
+               trail.add(tt);\r
+               tt.done();\r
+       }\r
+\r
+       @Override\r
+       public Metric auditTrail(int indent, StringBuilder sb, int ... flags) {\r
+               return auditTrail(info(),indent,sb,flags);\r
+       }\r
+       \r
+       @Override\r
+       public Metric auditTrail(LogTarget lt, int indent, StringBuilder sb, int ... flags) {\r
+               Metric metric = new Metric();\r
+               int last = (metric.entries = trail.size()) -1;\r
+               metric.buckets = flags.length==0?EMPTYF:new float[flags.length];\r
+               if(last>=0) {\r
+                       TimeTaken first = trail.get(0);\r
+                       // If first entry is sub, then it's actually the last "end" as well\r
+                       // otherwise, check end\r
+                       //long end = (first.flag&SUB)==SUB?first.end():trail.get(last).end();\r
+                       long end = trail.get(last).end();\r
+                       metric.total = (end - first.start) / 1000000f;\r
+               }\r
+               \r
+               if(sb==null) {\r
+                       for(TimeTaken tt : trail) {\r
+                               float ms = tt.millis();\r
+                               for(int i=0;i<flags.length;++i) {\r
+                                       if(tt.flag == flags[i]) metric.buckets[i]+=ms;\r
+                               }\r
+                       }\r
+               } else if(!lt.isLoggable()) {\r
+                       boolean first = true;\r
+                       for(TimeTaken tt : trail) {\r
+                               float ms = tt.millis();\r
+                               for(int i=0;i<flags.length;++i) {\r
+                                       if(tt.flag == flags[i]) metric.buckets[i]+=ms;\r
+                               }\r
+                               if((tt.flag&ALWAYS)==ALWAYS) {\r
+                                       if(first) first = false;\r
+                                       else sb.append('/');\r
+                                       sb.append(tt.name);\r
+                               }\r
+                       }                       \r
+               } else {\r
+                       Stack<Long> stack = new Stack<Long>();\r
+                       for(TimeTaken tt : trail) {\r
+                               // Create Indentation based on SUB\r
+                               while(!stack.isEmpty() && tt.end()>stack.peek()) {\r
+                                       --indent;\r
+                                       stack.pop();\r
+                               }\r
+                               for(int i=0;i<indent;++i) {\r
+                                       sb.append("  ");\r
+                               }\r
+                               tt.output(sb);\r
+                               sb.append('\n');\r
+                               if((tt.flag&SUB)==SUB) {\r
+                                       stack.push(tt.end());\r
+                                       ++indent;\r
+                               }\r
+                               \r
+                               // Add time values to Metric\r
+                               float ms = tt.millis();\r
+                               for(int i=0;i<flags.length;++i) {\r
+                                       if(tt.flag == flags[i]) metric.buckets[i]+=ms;\r
+                               }\r
+                       }\r
+               }\r
+               return metric;\r
+       }\r
+\r
+       /**\r
+        * Put data into the Trans State at the right slot \r
+        */\r
+//     @Override\r
+       public void put(Slot slot, Object value) {\r
+               slot.put(state, value);\r
+       }\r
+\r
+       /**\r
+        *  Get data from the Trans State from the right slot\r
+        *  \r
+        *  This will do a cast to the expected type derived from Default\r
+        */\r
+//     @Override\r
+       @SuppressWarnings("unchecked")\r
+       public<T> T get(Slot slot, T deflt) {\r
+               Object o;\r
+               try {\r
+                       o = slot.get(state);\r
+               } catch(ArrayIndexOutOfBoundsException e) {\r
+                       // Env State Size has changed because of dynamic Object creation... Rare event, but needs to be covered\r
+                       Object[] temp = ((StoreImpl) delegate).newTransState();\r
+                       System.arraycopy(state, 0, temp, 0, state.length);\r
+                       state = temp;\r
+                       o=null;\r
+               }\r
+               return o==null?deflt:(T)o;\r
+       }\r
+\r
+\r
+}\r
index 5c4a80b..c20589a 100644 (file)
@@ -1,57 +1,57 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.impl;
-
-import javax.xml.namespace.QName;
-import javax.xml.validation.Schema;
-
-import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.misc.env.DataFactory;
-import org.onap.aaf.misc.env.EnvJAXB;
-import org.onap.aaf.misc.env.TransJAXB;
-
-public abstract class AbsTransJAXB extends AbsTrans<EnvJAXB> implements TransJAXB {
-       public AbsTransJAXB(EnvJAXB env) {
-               super(env);
-       }
-       
-//     @Override
-       public <T> DataFactory<T> newDataFactory(Class<?>... classes) throws APIException {
-               return delegate.newDataFactory(classes);
-       }
-
-//     @Override
-       public <T> DataFactory<T> newDataFactory(Schema schema, Class<?>... classes) throws APIException {
-               return delegate.newDataFactory(schema, classes);
-       }
-
-//     @Override
-       public <T> DataFactory<T> newDataFactory(QName qName, Class<?>... classes) throws APIException {
-               return delegate.newDataFactory(qName, classes);
-       }
-
-//     @Override
-       public <T> DataFactory<T> newDataFactory(Schema schema, QName qName, Class<?>... classes) throws APIException {
-               return delegate.newDataFactory(schema, qName, classes);
-       }
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.impl;\r
+\r
+import javax.xml.namespace.QName;\r
+import javax.xml.validation.Schema;\r
+\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.DataFactory;\r
+import org.onap.aaf.misc.env.EnvJAXB;\r
+import org.onap.aaf.misc.env.TransJAXB;\r
+\r
+public abstract class AbsTransJAXB extends AbsTrans<EnvJAXB> implements TransJAXB {\r
+       public AbsTransJAXB(EnvJAXB env) {\r
+               super(env);\r
+       }\r
+       \r
+//     @Override\r
+       public <T> DataFactory<T> newDataFactory(Class<?>... classes) throws APIException {\r
+               return delegate.newDataFactory(classes);\r
+       }\r
+\r
+//     @Override\r
+       public <T> DataFactory<T> newDataFactory(Schema schema, Class<?>... classes) throws APIException {\r
+               return delegate.newDataFactory(schema, classes);\r
+       }\r
+\r
+//     @Override\r
+       public <T> DataFactory<T> newDataFactory(QName qName, Class<?>... classes) throws APIException {\r
+               return delegate.newDataFactory(qName, classes);\r
+       }\r
+\r
+//     @Override\r
+       public <T> DataFactory<T> newDataFactory(Schema schema, QName qName, Class<?>... classes) throws APIException {\r
+               return delegate.newDataFactory(schema, qName, classes);\r
+       }\r
+\r
+}\r
index 65fe9d8..2a3628d 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.impl;
-
-import java.applet.Applet;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.Properties;
-
-import javax.xml.namespace.QName;
-import javax.xml.validation.Schema;
-
-import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.misc.env.DataFactory;
-import org.onap.aaf.misc.env.Decryptor;
-import org.onap.aaf.misc.env.Encryptor;
-import org.onap.aaf.misc.env.Env;
-import org.onap.aaf.misc.env.EnvJAXB;
-import org.onap.aaf.misc.env.LogTarget;
-import org.onap.aaf.misc.env.StaticSlot;
-import org.onap.aaf.misc.env.StoreImpl;
-import org.onap.aaf.misc.env.TimeTaken;
-import org.onap.aaf.misc.env.TransCreate;
-import org.onap.aaf.misc.env.TransJAXB;
-import org.onap.aaf.misc.env.jaxb.JAXBDF;
-import org.onap.aaf.misc.env.util.Split;
-
-/**
- * An essential Implementation of Env, which will fully function, without any sort
- * of configuration.
- * 
- * Use as a basis for Group level Env, just overriding where needed.
- * @author Jonathan
- *
- */
-public class BasicEnv extends StoreImpl implements EnvJAXB, TransCreate<TransJAXB>{
-       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<String, String> 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, String>();
-//             String value;
-//             for(int i=0;i<tags.length;++i) {
-//                     value = applet.getParameter(tags[i]);
-//                     if(value!=null) {
-//                             props.put(tags[i], value);
-//                     }
-//             }
-       }
-
-       public BasicEnv(Properties props) {
-               super(null, props);
-       }
-
-       public BasicEnv(String tag, Properties props) {
-               super(tag, props);
-       }
-
-
-
-       // @Override
-       public LogTarget fatal() {
-               return fatal;
-       }
-
-       // @Override
-       public LogTarget error() {
-               return error;
-       }
-
-       
-       // @Override
-       public LogTarget audit() {
-               return audit;
-       }
-
-       // @Override
-       public LogTarget init() {
-               return init;
-       }
-
-       // @Override
-       public LogTarget warn() {
-               return warn;
-       }
-
-       // @Override
-       public LogTarget info() {
-               return info;
-       }
-
-       // @Override
-       public LogTarget debug() {
-               return debug;
-       }
-
-       public void debug(LogTarget lt) {
-               debug = lt;
-       }
-
-       // @Override
-       public LogTarget trace() {
-               return trace;
-       }
-
-       // @Override
-       public TimeTaken start(String name, int flag) {
-               return new TimeTaken(name, flag) {
-                       /**
-                        * Format to be printed when called upon
-                        */
-                       // @Override
-                       public void output(StringBuilder sb) {
-       
-                               switch(flag) {
-                                       case Env.XML: sb.append("XML "); break;
-                                       case Env.JSON: sb.append("JSON "); break;
-                                       case Env.REMOTE: sb.append("REMOTE "); break;
-                               }
-                               sb.append(name);
-                               if(flag != Env.CHECKPOINT) {
-                                       sb.append(' ');
-                                       sb.append((end-start)/1000000f);
-                                       sb.append("ms");
-                                       if(size>=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 <T> DataFactory<T> newDataFactory(Class<?>... classes) throws APIException {
-//             if(String.class.isAssignableFrom(classes[0])) 
-//                     return (DataFactory<T>) new StringDF(this);
-               return new JAXBDF<T>(this,classes);
-       }
-
-//     @SuppressWarnings("unchecked")
-       // @Override
-       public <T> DataFactory<T> newDataFactory(Schema schema, Class<?>... classes) throws APIException {
-//             if(String.class.isAssignableFrom(classes[0])) 
-//                     return (DataFactory<T>) new StringDF(this);
-               return new JAXBDF<T>(this, schema, classes);
-       }
-
-//     @SuppressWarnings("unchecked")
-       // @Override
-       public<T> DataFactory<T> newDataFactory(QName qName, Class<?> ... classes) throws APIException {
-//             if(String.class.isAssignableFrom(classes[0])) 
-//                     return (DataFactory<T>) new StringDF(this);
-               return new JAXBDF<T>(this, qName, classes);
-       }
-
-       // @Override
-       public<T> DataFactory<T> newDataFactory(Schema schema, QName qName, Class<?> ... classes) throws APIException {
-               return new JAXBDF<T>(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;
-       }
-
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.impl;\r
+\r
+import java.applet.Applet;\r
+import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.InputStreamReader;\r
+import java.util.Properties;\r
+\r
+import javax.xml.namespace.QName;\r
+import javax.xml.validation.Schema;\r
+\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.DataFactory;\r
+import org.onap.aaf.misc.env.Decryptor;\r
+import org.onap.aaf.misc.env.Encryptor;\r
+import org.onap.aaf.misc.env.Env;\r
+import org.onap.aaf.misc.env.EnvJAXB;\r
+import org.onap.aaf.misc.env.LogTarget;\r
+import org.onap.aaf.misc.env.StaticSlot;\r
+import org.onap.aaf.misc.env.StoreImpl;\r
+import org.onap.aaf.misc.env.TimeTaken;\r
+import org.onap.aaf.misc.env.TransCreate;\r
+import org.onap.aaf.misc.env.TransJAXB;\r
+import org.onap.aaf.misc.env.jaxb.JAXBDF;\r
+import org.onap.aaf.misc.env.util.Split;\r
+\r
+/**\r
+ * An essential Implementation of Env, which will fully function, without any sort\r
+ * of configuration.\r
+ * \r
+ * Use as a basis for Group level Env, just overriding where needed.\r
+ * @author Jonathan\r
+ *\r
+ */\r
+public class BasicEnv extends StoreImpl implements EnvJAXB, TransCreate<TransJAXB>{\r
+       protected LogTarget fatal=LogTarget.SYSERR;\r
+       protected LogTarget error=LogTarget.SYSERR;\r
+       protected LogTarget audit=LogTarget.SYSOUT;\r
+       protected LogTarget init=LogTarget.SYSOUT;\r
+       protected LogTarget warn=LogTarget.SYSERR;\r
+       protected LogTarget info=LogTarget.SYSOUT;\r
+       protected LogTarget debug=LogTarget.NULL;\r
+       protected LogTarget trace=LogTarget.NULL;\r
+//     protected Map<String, String> props;\r
+       \r
+//     private boolean sysprops;\r
+\r
+       public BasicEnv(String ... args) {\r
+               super(null,args);\r
+       }\r
+\r
+       public BasicEnv(String tag, String[] args) {\r
+               super(tag, args);\r
+       }\r
+       \r
+\r
+       /**\r
+        * Suitable for use in Applets... obtain all the values \r
+        * listed for the variable String arg "tags"\r
+        */\r
+       public BasicEnv(Applet applet, String ... tags) {\r
+               super(null, tags);\r
+//             props = new HashMap<String, String>();\r
+//             String value;\r
+//             for(int i=0;i<tags.length;++i) {\r
+//                     value = applet.getParameter(tags[i]);\r
+//                     if(value!=null) {\r
+//                             props.put(tags[i], value);\r
+//                     }\r
+//             }\r
+       }\r
+\r
+       public BasicEnv(Properties props) {\r
+               super(null, props);\r
+       }\r
+\r
+       public BasicEnv(String tag, Properties props) {\r
+               super(tag, props);\r
+       }\r
+\r
+\r
+\r
+       // @Override\r
+       public LogTarget fatal() {\r
+               return fatal;\r
+       }\r
+\r
+       // @Override\r
+       public LogTarget error() {\r
+               return error;\r
+       }\r
+\r
+       \r
+       // @Override\r
+       public LogTarget audit() {\r
+               return audit;\r
+       }\r
+\r
+       // @Override\r
+       public LogTarget init() {\r
+               return init;\r
+       }\r
+\r
+       // @Override\r
+       public LogTarget warn() {\r
+               return warn;\r
+       }\r
+\r
+       // @Override\r
+       public LogTarget info() {\r
+               return info;\r
+       }\r
+\r
+       // @Override\r
+       public LogTarget debug() {\r
+               return debug;\r
+       }\r
+\r
+       public void debug(LogTarget lt) {\r
+               debug = lt;\r
+       }\r
+\r
+       // @Override\r
+       public LogTarget trace() {\r
+               return trace;\r
+       }\r
+\r
+       // @Override\r
+       public TimeTaken start(String name, int flag) {\r
+               return new TimeTaken(name, flag) {\r
+                       /**\r
+                        * Format to be printed when called upon\r
+                        */\r
+                       // @Override\r
+                       public void output(StringBuilder sb) {\r
+       \r
+                               switch(flag) {\r
+                                       case Env.XML: sb.append("XML "); break;\r
+                                       case Env.JSON: sb.append("JSON "); break;\r
+                                       case Env.REMOTE: sb.append("REMOTE "); break;\r
+                               }\r
+                               sb.append(name);\r
+                               if(flag != Env.CHECKPOINT) {\r
+                                       sb.append(' ');\r
+                                       sb.append((end-start)/1000000f);\r
+                                       sb.append("ms");\r
+                                       if(size>=0) {\r
+                                               sb.append(" size: ");\r
+                                               sb.append(Long.toString(size));\r
+                                       }\r
+                               }\r
+                       }\r
+               };\r
+       }\r
+\r
+       // @Override\r
+       public String getProperty(String key) {\r
+               return get(staticSlot(key),null);\r
+       }\r
+       \r
+       public Properties getProperties(String ... filter) {\r
+               Properties props = new Properties();\r
+               boolean yes;\r
+               for(String key : existingStaticSlotNames()) {\r
+                       if(filter.length>0) {\r
+                               yes = false;\r
+                               for(String f : filter) {\r
+                                       if(key.startsWith(f)) {\r
+                                               yes = true;\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       } else {\r
+                               yes = true;\r
+                       }\r
+                       if(yes) {\r
+                               String value = getProperty(key);\r
+                               if(value!=null) {\r
+                                       props.put(key, value);\r
+                               }\r
+                       }\r
+               }\r
+               return props;\r
+       }\r
+       \r
+       // @Override\r
+       public String getProperty(String key, String defaultValue) {\r
+               return get(staticSlot(key),defaultValue);\r
+       }\r
+\r
+       // @Override\r
+       public String setProperty(String key, String value) {\r
+               put(staticSlot(key),value==null?null:value.trim());\r
+               return value;\r
+       }\r
+       \r
+       protected Decryptor decryptor = Decryptor.NULL;\r
+       protected Encryptor encryptor = Encryptor.NULL;\r
+\r
+       \r
+       public Decryptor decryptor() {\r
+               return decryptor; \r
+       }\r
+       \r
+       public void set(Decryptor newDecryptor) {\r
+               decryptor = newDecryptor;\r
+       }\r
+       \r
+       public Encryptor encryptor() {\r
+               return encryptor; \r
+       }\r
+       \r
+       public void set(Encryptor newEncryptor) {\r
+               encryptor = newEncryptor;\r
+       }\r
+\r
+       \r
+//     @SuppressWarnings("unchecked")\r
+       // @Override\r
+       public <T> DataFactory<T> newDataFactory(Class<?>... classes) throws APIException {\r
+//             if(String.class.isAssignableFrom(classes[0])) \r
+//                     return (DataFactory<T>) new StringDF(this);\r
+               return new JAXBDF<T>(this,classes);\r
+       }\r
+\r
+//     @SuppressWarnings("unchecked")\r
+       // @Override\r
+       public <T> DataFactory<T> newDataFactory(Schema schema, Class<?>... classes) throws APIException {\r
+//             if(String.class.isAssignableFrom(classes[0])) \r
+//                     return (DataFactory<T>) new StringDF(this);\r
+               return new JAXBDF<T>(this, schema, classes);\r
+       }\r
+\r
+//     @SuppressWarnings("unchecked")\r
+       // @Override\r
+       public<T> DataFactory<T> newDataFactory(QName qName, Class<?> ... classes) throws APIException {\r
+//             if(String.class.isAssignableFrom(classes[0])) \r
+//                     return (DataFactory<T>) new StringDF(this);\r
+               return new JAXBDF<T>(this, qName, classes);\r
+       }\r
+\r
+       // @Override\r
+       public<T> DataFactory<T> newDataFactory(Schema schema, QName qName, Class<?> ... classes) throws APIException {\r
+               return new JAXBDF<T>(this, schema, qName, classes);\r
+       }\r
+\r
+       // @Override\r
+       public BasicTrans newTrans() {\r
+               return new BasicTrans(this);\r
+       }\r
+\r
+       public void loadFromSystemPropsStartsWith(String ... str) {\r
+                for(String name : System.getProperties().stringPropertyNames()) {\r
+                       for(String s : str) {\r
+                               if(name.startsWith(s)) {\r
+                                       setProperty(name, System.getProperty(name));\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       /**\r
+        * \r
+        * \r
+        */\r
+       public void loadToSystemPropsStartsWith(String ... str) {\r
+               String value;\r
+               for(String name : existingStaticSlotNames()) {\r
+                       for(String s : str) {\r
+                               if(name.startsWith(s)) {\r
+                                       if((value = getProperty(name))!=null)\r
+                                               System.setProperty(name,value);\r
+                               }\r
+                       }\r
+                }\r
+       }\r
+       \r
+       public void loadPropFiles(String tag, ClassLoader classloader) throws IOException {\r
+               String propfiles = getProperty(tag);\r
+               if(propfiles!=null) {\r
+                       for(String pf : Split.splitTrim(File.pathSeparatorChar, propfiles)) {\r
+                               InputStream is = classloader==null?null:classloader.getResourceAsStream(pf);\r
+                               if(is==null) {\r
+                                       File f = new File(pf);\r
+                                       if(f.exists()) {\r
+                                               is = new FileInputStream(f);\r
+                                       }\r
+                               }\r
+                               if(is!=null) {\r
+                                       BufferedReader br = new BufferedReader(new InputStreamReader(is));\r
+                                       try {\r
+                                               String line;\r
+                                               while((line=br.readLine())!=null) {\r
+                                                       line = line.trim();\r
+                                                       if(!line.startsWith("#")) {\r
+                                                               String[] tv = Split.splitTrim('=', line);\r
+                                                               if(tv.length==2) {\r
+                                                                       setProperty(tv[0],tv[1]);\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       } finally {\r
+                                               try {\r
+                                                       br.close();\r
+                                               } catch (IOException e) {\r
+                                                       error().log(e);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Create a StaticSlot, and load it from existing Properties\r
+        * \r
+        * @param name\r
+        * @param propName\r
+        * @return\r
+        */\r
+       public synchronized StaticSlot staticSlot(String name, final String propName) {\r
+               StaticSlot ss = staticSlot(name);\r
+               put(ss,getProperty(propName));\r
+               return ss;\r
+       }\r
+\r
+\r
+}\r
index eb33ff5..05e6202 100644 (file)
@@ -1,81 +1,81 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.impl;
-
-import org.onap.aaf.misc.env.Decryptor;
-import org.onap.aaf.misc.env.Encryptor;
-import org.onap.aaf.misc.env.EnvJAXB;
-import org.onap.aaf.misc.env.Slot;
-import org.onap.aaf.misc.env.StaticSlot;
-import org.onap.aaf.misc.env.TimeTaken;
-
-
-public class BasicTrans extends AbsTransJAXB {
-       
-       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);
-       }
-
-       public <T> T get(StaticSlot slot) {
-               return delegate.get(slot);
-       }
-
-       public <T> 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 getProperty(String tag) {
-               return delegate.getProperty(tag);
-       }
-
-       public String getProperty(String tag, String deflt) {
-               return delegate.getProperty(tag, deflt);
-       }
-
-       @Override
-       public Decryptor decryptor() {
-               return delegate.decryptor();
-       }
-
-       @Override
-       public Encryptor encryptor() {
-               return delegate.encryptor();
-       }
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.impl;\r
+\r
+import org.onap.aaf.misc.env.Decryptor;\r
+import org.onap.aaf.misc.env.Encryptor;\r
+import org.onap.aaf.misc.env.EnvJAXB;\r
+import org.onap.aaf.misc.env.Slot;\r
+import org.onap.aaf.misc.env.StaticSlot;\r
+import org.onap.aaf.misc.env.TimeTaken;\r
+\r
+\r
+public class BasicTrans extends AbsTransJAXB {\r
+       \r
+       public BasicTrans(EnvJAXB env) {\r
+               super(env);\r
+       }\r
+\r
+       @Override\r
+       protected TimeTaken newTimeTaken(String name, int flag) {\r
+               /**\r
+                * Note: could have created a different format for Time Taken, but using BasicEnv's instead\r
+                */\r
+               return delegate.start(name, flag);\r
+       }\r
+       \r
+       public Slot slot(String name) {\r
+               return delegate.slot(name);\r
+       }\r
+\r
+       public <T> T get(StaticSlot slot) {\r
+               return delegate.get(slot);\r
+       }\r
+\r
+       public <T> T get(StaticSlot slot, T dflt) {\r
+               return delegate.get(slot,dflt);\r
+       }\r
+\r
+       public String setProperty(String tag, String value) {\r
+               delegate.setProperty(tag, value);\r
+               return value;\r
+       }\r
+\r
+       public String getProperty(String tag) {\r
+               return delegate.getProperty(tag);\r
+       }\r
+\r
+       public String getProperty(String tag, String deflt) {\r
+               return delegate.getProperty(tag, deflt);\r
+       }\r
+\r
+       @Override\r
+       public Decryptor decryptor() {\r
+               return delegate.decryptor();\r
+       }\r
+\r
+       @Override\r
+       public Encryptor encryptor() {\r
+               return delegate.encryptor();\r
+       }\r
+\r
+}\r
index a882c74..9bf4fdc 100644 (file)
@@ -1,68 +1,68 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.impl;
-
-import org.onap.aaf.misc.env.EnvJAXB;
-import org.onap.aaf.misc.env.TransCreate;
-import org.onap.aaf.misc.env.TransJAXB;
-
-/**
- * EnvFactory
- * 
- * @author Jonathan
- * 
- */
-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;
-
-       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<TransJAXB> transCreator() {
-               return new TransCreate<TransJAXB>() {
-                       // @Override
-                       public BasicTrans newTrans() {
-                               return singleton.newTrans();
-                       }
-               };
-       }
-}
-
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.impl;\r
+\r
+import org.onap.aaf.misc.env.EnvJAXB;\r
+import org.onap.aaf.misc.env.TransCreate;\r
+import org.onap.aaf.misc.env.TransJAXB;\r
+\r
+/**\r
+ * EnvFactory\r
+ * \r
+ * @author Jonathan\r
+ * \r
+ */\r
+public class EnvFactory {\r
+\r
+       public static final String SCHEMA_DIR = "env-schema_dir";\r
+       public static final String DEFAULT_SCHEMA_DIR = "src/main/xsd";\r
+       static BasicEnv singleton;\r
+\r
+       static {\r
+               singleton = new BasicEnv();\r
+       }\r
+       public static BasicEnv singleton() {\r
+               return singleton;\r
+       }\r
+       \r
+       public static void setSingleton(BasicEnv be) {\r
+               singleton = be;\r
+       }\r
+       \r
+       public static TransJAXB newTrans() {\r
+               return new BasicTrans(singleton);\r
+       }\r
+\r
+       public static TransJAXB newTrans(EnvJAXB env) {\r
+               return new BasicTrans(env);\r
+       }\r
+       \r
+       public static TransCreate<TransJAXB> transCreator() {\r
+               return new TransCreate<TransJAXB>() {\r
+                       // @Override\r
+                       public BasicTrans newTrans() {\r
+                               return singleton.newTrans();\r
+                       }\r
+               };\r
+       }\r
+}\r
+\r
index 84a78bf..ac3e8b4 100644 (file)
@@ -1,90 +1,90 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.impl;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.onap.aaf.misc.env.LogTarget;
-
-/**
- * This LogTarget Implementation is included mostly because the JavaUtil based logging is included in the
- * JDK.  This makes the default implementation independent of any external Jars.
- * 
- *  Log4j is often considered more Enterprise capable.  See Log4JLogTarget for that implementation
- * 
- * @author Jonathan
- *
- */
-public class JavaUtilLogTarget implements LogTarget {
-       private Level level;
-       private Logger log;
-
-       public JavaUtilLogTarget(Logger logger, Level theLevel) {
-               log = logger;
-               level = theLevel;
-       }
-
-       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;i<msgs.length;++i) {
-                               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());
-               }
-       }
-
-       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));
-               }
-       }
-}      
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.impl;\r
+\r
+import java.util.logging.Level;\r
+import java.util.logging.Logger;\r
+\r
+import org.onap.aaf.misc.env.LogTarget;\r
+\r
+/**\r
+ * This LogTarget Implementation is included mostly because the JavaUtil based logging is included in the\r
+ * JDK.  This makes the default implementation independent of any external Jars.\r
+ * \r
+ *  Log4j is often considered more Enterprise capable.  See Log4JLogTarget for that implementation\r
+ * \r
+ * @author Jonathan\r
+ *\r
+ */\r
+public class JavaUtilLogTarget implements LogTarget {\r
+       private Level level;\r
+       private Logger log;\r
+\r
+       public JavaUtilLogTarget(Logger logger, Level theLevel) {\r
+               log = logger;\r
+               level = theLevel;\r
+       }\r
+\r
+       public boolean isLoggable() {\r
+               return log.isLoggable(level);\r
+       }\r
+\r
+       public void log(Object ... msgs) {\r
+               if(log.isLoggable(level)) {\r
+                       StringBuilder sb = new StringBuilder();\r
+                       String msg;\r
+                       for(int i=0;i<msgs.length;++i) {\r
+                               msg = msgs[i].toString();\r
+                               if(msg!=null && msg.length()>0) {\r
+                                       int sbl = sb.length();\r
+                                       if(sbl>0) {\r
+                                               char last = sb.charAt(sbl-1);\r
+                                               if(" (.".indexOf(last)<0 && "().".indexOf(msg.charAt(0))<0)sb.append(' ');\r
+                                       }\r
+                                       sb.append(msg);\r
+                               }\r
+                       }\r
+                       log.log(level, sb.toString());\r
+               }\r
+       }\r
+\r
+       public void log(Throwable e, Object ... msgs) {\r
+               String str = e.getLocalizedMessage();\r
+               if(str==null) {\r
+                       str = e.getMessage();\r
+               }\r
+               if(str==null) {\r
+                       str = e.getClass().getName();\r
+               }\r
+               log.log(level,str,msgs);\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see com.att.inno.env.LogTarget#printf(java.lang.String, java.lang.String[])\r
+        */\r
+       @Override\r
+       public void printf(String fmt, Object ... vars) {\r
+               if(log.isLoggable(level)) {\r
+                       log.log(level,String.format(fmt,vars));\r
+               }\r
+       }\r
+}      \r
index 44da65e..a5f118c 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.impl;
-
-import java.io.PrintWriter;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.misc.env.LogTarget;
-import org.onap.aaf.misc.env.util.StringBuilderWriter;
-
-/**
- * Many services have chosen to use Log4J for their lower level Logging Implementation.  This LogTarget will allow
- * any of the messages sent to be set to the appropriate Log4J level.
- * 
- * @author Jonathan 
- *
- */
-public class Log4JLogTarget implements LogTarget {
-       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();
-               }
-       }
-
-       // @Override
-       public boolean isLoggable() {
-               return log.isEnabledFor(level);
-       }
-
-       // @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());
-               }
-       }
-
-       /* (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);
-       }
-       
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.impl;\r
+\r
+import java.io.PrintWriter;\r
+\r
+import org.apache.log4j.Level;\r
+import org.apache.log4j.Logger;\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.LogTarget;\r
+import org.onap.aaf.misc.env.util.StringBuilderWriter;\r
+\r
+/**\r
+ * Many services have chosen to use Log4J for their lower level Logging Implementation.  This LogTarget will allow\r
+ * any of the messages sent to be set to the appropriate Log4J level.\r
+ * \r
+ * @author Jonathan \r
+ *\r
+ */\r
+public class Log4JLogTarget implements LogTarget {\r
+       private Level level;\r
+       private Logger log;\r
+\r
+       public Log4JLogTarget(String loggerName, Level level) throws APIException {\r
+               this.level = level;\r
+               if (loggerName != null && loggerName.length() > 0) {\r
+                       log = Logger.getLogger(loggerName);\r
+               } else {\r
+                       log = Logger.getRootLogger();\r
+               }\r
+       }\r
+\r
+       // @Override\r
+       public boolean isLoggable() {\r
+               return log.isEnabledFor(level);\r
+       }\r
+\r
+       // @Override\r
+       public void log(Object... msgs) {\r
+               log(null, msgs);\r
+       }\r
+\r
+       // @Override\r
+       public void log(Throwable e, Object... msgs) {\r
+               if (log.isEnabledFor(level)) {\r
+                       StringBuilder sb = new StringBuilder();\r
+                       \r
+                       String msg;\r
+                       if (e != null) {\r
+                               e.printStackTrace(new PrintWriter(new StringBuilderWriter(sb)));\r
+                       }\r
+                       for (int i = 0; i < msgs.length; ++i) {\r
+                               if(msgs[i]!=null) {\r
+                                       msg = msgs[i].toString();\r
+                                       if (msg != null && msg.length() > 0) {\r
+                                               int sbl = sb.length();\r
+                                               if (sbl > 0) {\r
+                                                       char last = sb.charAt(sbl - 1);\r
+                                                       if (" (.".indexOf(last) < 0\r
+                                                                       && "().".indexOf(msg.charAt(0)) < 0)\r
+                                                               sb.append(' ');\r
+                                               }\r
+                                               sb.append(msg);\r
+                                       }\r
+                               }\r
+                       }\r
+                       log.log(level, sb.toString());\r
+               }\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see com.att.inno.env.LogTarget#printf(java.lang.String, java.lang.String[])\r
+        */\r
+       @Override\r
+       public void printf(String fmt, Object ... vars) {\r
+               if(log.isEnabledFor(level)) {\r
+                       log.log(level,String.format(fmt,vars));\r
+               }\r
+       }\r
+\r
+       public static void setLog4JEnv(String loggerName, BasicEnv env) throws APIException {\r
+                       env.fatal = new Log4JLogTarget(loggerName,Level.FATAL);\r
+                       env.error = new Log4JLogTarget(loggerName,Level.ERROR);\r
+                       env.warn = env.audit = env.init = new Log4JLogTarget(loggerName,Level.WARN);\r
+                       env.info = new Log4JLogTarget(loggerName,Level.INFO);\r
+                       env.debug = new Log4JLogTarget(loggerName,Level.DEBUG);\r
+                       env.trace = new Log4JLogTarget(loggerName,Level.TRACE);\r
+       }\r
+       \r
 }
\ No newline at end of file
index 5cda17f..7e41f5d 100644 (file)
@@ -1,59 +1,59 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-/**
- * 
- */
-package org.onap.aaf.misc.env.impl;
-
-import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.misc.env.Env;
-import org.onap.aaf.misc.env.LifeCycle;
-
-
-
-/**
- * <h1>NullLifeCycle</h1>
- * 
- * This is a convenience class for those Objects which should
- * implement LifeCycle, but don't have anything to do in any of the 
- * LifeCycle methods defined. Extending
- * NullLifeCycle reduces the required methods for the class by 5.  
- * Any one or two of them can be overloaded.<p>
- * 
- * If more are overloaded, it is
- * recommended just to implement LifeCycle.
- * <p>
- * 
- * This only works, though, if the Object doesn't need to extend something
- * else, due to Java's Single Extension policy.  In other cases, just
- * implement LifeCycle, and leave them empty.
- * 
- * @author Jonathan
- *
- */
-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 {}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+/**\r
+ * \r
+ */\r
+package org.onap.aaf.misc.env.impl;\r
+\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.Env;\r
+import org.onap.aaf.misc.env.LifeCycle;\r
+\r
+\r
+\r
+/**\r
+ * <h1>NullLifeCycle</h1>\r
+ * \r
+ * This is a convenience class for those Objects which should\r
+ * implement LifeCycle, but don't have anything to do in any of the \r
+ * LifeCycle methods defined. Extending\r
+ * NullLifeCycle reduces the required methods for the class by 5.  \r
+ * Any one or two of them can be overloaded.<p>\r
+ * \r
+ * If more are overloaded, it is\r
+ * recommended just to implement LifeCycle.\r
+ * <p>\r
+ * \r
+ * This only works, though, if the Object doesn't need to extend something\r
+ * else, due to Java's Single Extension policy.  In other cases, just\r
+ * implement LifeCycle, and leave them empty.\r
+ * \r
+ * @author Jonathan\r
+ *\r
+ */\r
+public class NullLifeCycle implements LifeCycle {\r
+       public void servicePrestart(Env env) throws APIException {}\r
+       public void threadPrestart(Env env) throws APIException {}\r
+       public void refresh(Env env) throws APIException {}\r
+       public void threadDestroy(Env env) throws APIException {}\r
+       public void serviceDestroy(Env env) throws APIException {}\r
 }
\ No newline at end of file
index 74fcc83..e32532b 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.jaxb;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.StringWriter;
-import java.io.Writer;
-
-import javax.xml.bind.JAXBException;
-import javax.xml.namespace.QName;
-import javax.xml.validation.Schema;
-
-import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.misc.env.BaseDataFactory;
-import org.onap.aaf.misc.env.Data;
-import org.onap.aaf.misc.env.Env;
-import org.onap.aaf.misc.env.EnvJAXB;
-import org.onap.aaf.misc.env.TimeTaken;
-import org.onap.aaf.misc.env.old.IOObjectifier;
-import org.onap.aaf.misc.env.old.IOStringifier;
-import org.onap.aaf.misc.env.old.OldDataFactory;
-
-public class JAXBDF<T> extends BaseDataFactory implements OldDataFactory<T>,IOObjectifier<T>, IOStringifier<T> {
-       // Package on purpose
-       EnvJAXB primaryEnv;
-       JAXBumar jumar;
-       JAXBmar jmar;
-
-       public JAXBDF(EnvJAXB env, Class<?> ... classes) throws APIException {
-               try {
-                       primaryEnv = env;
-                       jumar = new JAXBumar(classes);
-                       jmar = new JAXBmar(classes) ;
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               }
-       }
-       
-       public JAXBDF(EnvJAXB env, Schema schema, Class<?> ... classes) throws APIException {
-               try {
-                       primaryEnv = env;
-                       jumar = new JAXBumar(schema, classes);
-                       jmar = new JAXBmar(classes);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               }
-       }
-       
-       public JAXBDF(EnvJAXB env, QName qname, Class<?> ... classes) throws APIException {
-               try {
-                       primaryEnv = env;
-                       jumar = new JAXBumar(classes);
-                       jmar = new JAXBmar(qname, classes);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               }
-       }
-
-       public JAXBDF(EnvJAXB env, Schema schema, QName qname, Class<?> ... classes) throws APIException {
-               try {
-                       primaryEnv = env;
-                       jumar = new JAXBumar(schema, classes);
-                       jmar = new JAXBmar(qname, classes);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               }
-       }
-       
-       // @Override
-       public T newInstance() throws APIException {
-               try {
-                       return jumar.newInstance();
-               } catch (Exception e) {
-                       throw new APIException(e);
-               }
-       }
-
-       // @Override
-       public IOStringifier<T> pretty(boolean pretty) {
-               jmar.pretty(pretty);
-               return this;
-       }
-
-       // @Override
-       public IOStringifier<T> asFragment(boolean fragment) {
-               jmar.asFragment(fragment);
-               return this;
-       }
-
-       // @Override
-       public void servicePrestart(Env env) throws APIException {
-       }
-
-       // @Override
-       public void threadPrestart(Env env) throws APIException {
-       }
-
-       // @Override
-       public void refresh(Env env) throws APIException {
-       }
-
-       // @Override
-       public void threadDestroy(Env env) throws APIException {
-       }
-
-       // @Override
-       public void serviceDestroy(Env env) throws APIException {
-       }
-
-       @SuppressWarnings("unchecked")
-       // @Override
-       public Data<T> newData() {
-               return new JAXBData<T>(primaryEnv, this, new JAXBStringifier<T>(jmar), new JAXBObjectifier<T>(jumar),"",(Class<T>)jmar.getMarshalClass());
-       }
-
-       @SuppressWarnings("unchecked")
-       // @Override
-       public Data<T> newData(Env env) {
-               return new JAXBData<T>(env, this,new JAXBStringifier<T>(jmar), new JAXBObjectifier<T>(jumar),"",(Class<T>)jmar.getMarshalClass());
-       }
-
-       // @Override
-       public Data<T> newData(T type) {
-               return new JAXBData<T>(primaryEnv, this, new JAXBStringifier<T>(jmar), new JAXBObjectifier<T>(jumar), type);
-       }
-
-       // @Override
-       public Data<T> newDataFromStream(Env env, InputStream input) throws APIException {
-               //TODO Write an unvalidated String using STAX checking for end of Doc?
-               // perhaps key evaluation as well.
-               try {
-                       T t = jumar.unmarshal(env.debug(), input);
-                       return new JAXBData<T>(primaryEnv, this, new JAXBStringifier<T>(jmar), new JAXBObjectifier<T>(jumar),t);
-               } catch(JAXBException e) {
-                       throw new APIException(e);
-               }
-       }
-
-       @SuppressWarnings("unchecked")
-       // @Override
-       public Data<T> newDataFromString(String string) {
-               return new JAXBData<T>(primaryEnv, this,new JAXBStringifier<T>(jmar), new JAXBObjectifier<T>(jumar), string,(Class<T>)jmar.getMarshalClass());
-       }
-
-       /////////// Old DataFactory Interface 
-       // @Override
-       public String stringify(T type) throws APIException {
-               try {
-                       StringWriter sw = new StringWriter();
-                       jmar.marshal(primaryEnv.debug(), type, sw);
-                       return sw.toString();
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               }       
-       }
-
-       // @Override
-       public void stringify(T type, Writer writer) throws APIException {
-               try {
-                       jmar.marshal(primaryEnv.debug(), type, writer);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               }       
-       }
-
-       // @Override
-       public void stringify(T type, OutputStream os) throws APIException {
-               try {
-                       jmar.marshal(primaryEnv.debug(), type, os);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               }       
-       }
-
-       /////////// New DataFactory Interface 
-       // @Override
-       public String stringify(Env env, T input, boolean ... options) throws APIException {
-               try {
-                       StringWriter sw = new StringWriter();
-                       TimeTaken tt = env.start("JAXB Stringify", Env.XML);
-                       try {
-                               jmar.marshal(env.debug(), input, sw, options);
-                       } finally {
-                               tt.done();
-                       }
-                       String str = sw.toString();
-                       tt.size(str.getBytes().length);
-                       return str;
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               }
-       }
-
-       // @Override
-       public void stringify(Env env, T input, Writer writer, boolean ... options) throws APIException {
-               TimeTaken tt = env.start("JAXB Stringify", Env.XML);
-               try {
-                       jmar.marshal(env.debug(), input, writer, options);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               } finally {
-                       tt.done();
-               }
-       }
-
-       // @Override
-       public void stringify(Env env, T input, OutputStream os, boolean ... options) throws APIException {
-               TimeTaken tt = env.start("JAXB Stringify", Env.XML);
-               try {
-                       jmar.marshal(env.debug(), input, os, options);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               } finally {
-                       tt.done();
-               }
-       }
-
-       // @Override
-       public T objectify(Env env, Reader rdr) throws APIException {
-               TimeTaken tt = env.start("JAXB Objectify", Env.XML);
-               try {
-                       return jumar.unmarshal(env.debug(), rdr);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               } finally {
-                       tt.done();
-               }
-       }
-
-       // @Override
-       public T objectify(Reader rdr) throws APIException {
-               try {
-                       return jumar.unmarshal(primaryEnv.debug(), rdr);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               }       
-       }
-
-       // @Override
-       public T objectify(Env env, InputStream is) throws APIException {
-               TimeTaken tt = env.start("JAXB Objectify", Env.XML);
-               try {
-                       return jumar.unmarshal(env.debug(), is);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               } finally {
-                       tt.done();
-               }
-       }
-
-       // @Override
-       public T objectify(InputStream is) throws APIException {
-               try {
-                       return jumar.unmarshal(primaryEnv.debug(), is);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               }       
-       }
-
-       // @Override
-       public T objectify(Env env, String input) throws APIException {
-               TimeTaken tt = env.start("JAXB Objectify", Env.XML);
-               tt.size(input.getBytes().length);
-               try {
-                       return jumar.unmarshal(env.debug(), input);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               } finally {
-                       tt.done();
-               }
-       }
-
-       // @Override
-       public T objectify(String text) throws APIException {
-               try {
-                       return jumar.unmarshal(primaryEnv.debug(), text);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               }       
-       }
-
-       @SuppressWarnings("unchecked")
-       // @Override
-       public Class<T> getTypeClass() {
-               return (Class<T>)jmar.getMarshalClass();
-       }
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.jaxb;\r
+\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
+import java.io.Reader;\r
+import java.io.StringWriter;\r
+import java.io.Writer;\r
+\r
+import javax.xml.bind.JAXBException;\r
+import javax.xml.namespace.QName;\r
+import javax.xml.validation.Schema;\r
+\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.BaseDataFactory;\r
+import org.onap.aaf.misc.env.Data;\r
+import org.onap.aaf.misc.env.Env;\r
+import org.onap.aaf.misc.env.EnvJAXB;\r
+import org.onap.aaf.misc.env.TimeTaken;\r
+import org.onap.aaf.misc.env.old.IOObjectifier;\r
+import org.onap.aaf.misc.env.old.IOStringifier;\r
+import org.onap.aaf.misc.env.old.OldDataFactory;\r
+\r
+public class JAXBDF<T> extends BaseDataFactory implements OldDataFactory<T>,IOObjectifier<T>, IOStringifier<T> {\r
+       // Package on purpose\r
+       EnvJAXB primaryEnv;\r
+       JAXBumar jumar;\r
+       JAXBmar jmar;\r
+\r
+       public JAXBDF(EnvJAXB env, Class<?> ... classes) throws APIException {\r
+               try {\r
+                       primaryEnv = env;\r
+                       jumar = new JAXBumar(classes);\r
+                       jmar = new JAXBmar(classes) ;\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               }\r
+       }\r
+       \r
+       public JAXBDF(EnvJAXB env, Schema schema, Class<?> ... classes) throws APIException {\r
+               try {\r
+                       primaryEnv = env;\r
+                       jumar = new JAXBumar(schema, classes);\r
+                       jmar = new JAXBmar(classes);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               }\r
+       }\r
+       \r
+       public JAXBDF(EnvJAXB env, QName qname, Class<?> ... classes) throws APIException {\r
+               try {\r
+                       primaryEnv = env;\r
+                       jumar = new JAXBumar(classes);\r
+                       jmar = new JAXBmar(qname, classes);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               }\r
+       }\r
+\r
+       public JAXBDF(EnvJAXB env, Schema schema, QName qname, Class<?> ... classes) throws APIException {\r
+               try {\r
+                       primaryEnv = env;\r
+                       jumar = new JAXBumar(schema, classes);\r
+                       jmar = new JAXBmar(qname, classes);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               }\r
+       }\r
+       \r
+       // @Override\r
+       public T newInstance() throws APIException {\r
+               try {\r
+                       return jumar.newInstance();\r
+               } catch (Exception e) {\r
+                       throw new APIException(e);\r
+               }\r
+       }\r
+\r
+       // @Override\r
+       public IOStringifier<T> pretty(boolean pretty) {\r
+               jmar.pretty(pretty);\r
+               return this;\r
+       }\r
+\r
+       // @Override\r
+       public IOStringifier<T> asFragment(boolean fragment) {\r
+               jmar.asFragment(fragment);\r
+               return this;\r
+       }\r
+\r
+       // @Override\r
+       public void servicePrestart(Env env) throws APIException {\r
+       }\r
+\r
+       // @Override\r
+       public void threadPrestart(Env env) throws APIException {\r
+       }\r
+\r
+       // @Override\r
+       public void refresh(Env env) throws APIException {\r
+       }\r
+\r
+       // @Override\r
+       public void threadDestroy(Env env) throws APIException {\r
+       }\r
+\r
+       // @Override\r
+       public void serviceDestroy(Env env) throws APIException {\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       // @Override\r
+       public Data<T> newData() {\r
+               return new JAXBData<T>(primaryEnv, this, new JAXBStringifier<T>(jmar), new JAXBObjectifier<T>(jumar),"",(Class<T>)jmar.getMarshalClass());\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       // @Override\r
+       public Data<T> newData(Env env) {\r
+               return new JAXBData<T>(env, this,new JAXBStringifier<T>(jmar), new JAXBObjectifier<T>(jumar),"",(Class<T>)jmar.getMarshalClass());\r
+       }\r
+\r
+       // @Override\r
+       public Data<T> newData(T type) {\r
+               return new JAXBData<T>(primaryEnv, this, new JAXBStringifier<T>(jmar), new JAXBObjectifier<T>(jumar), type);\r
+       }\r
+\r
+       // @Override\r
+       public Data<T> newDataFromStream(Env env, InputStream input) throws APIException {\r
+               //TODO Write an unvalidated String using STAX checking for end of Doc?\r
+               // perhaps key evaluation as well.\r
+               try {\r
+                       T t = jumar.unmarshal(env.debug(), input);\r
+                       return new JAXBData<T>(primaryEnv, this, new JAXBStringifier<T>(jmar), new JAXBObjectifier<T>(jumar),t);\r
+               } catch(JAXBException e) {\r
+                       throw new APIException(e);\r
+               }\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       // @Override\r
+       public Data<T> newDataFromString(String string) {\r
+               return new JAXBData<T>(primaryEnv, this,new JAXBStringifier<T>(jmar), new JAXBObjectifier<T>(jumar), string,(Class<T>)jmar.getMarshalClass());\r
+       }\r
+\r
+       /////////// Old DataFactory Interface \r
+       // @Override\r
+       public String stringify(T type) throws APIException {\r
+               try {\r
+                       StringWriter sw = new StringWriter();\r
+                       jmar.marshal(primaryEnv.debug(), type, sw);\r
+                       return sw.toString();\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               }       \r
+       }\r
+\r
+       // @Override\r
+       public void stringify(T type, Writer writer) throws APIException {\r
+               try {\r
+                       jmar.marshal(primaryEnv.debug(), type, writer);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               }       \r
+       }\r
+\r
+       // @Override\r
+       public void stringify(T type, OutputStream os) throws APIException {\r
+               try {\r
+                       jmar.marshal(primaryEnv.debug(), type, os);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               }       \r
+       }\r
+\r
+       /////////// New DataFactory Interface \r
+       // @Override\r
+       public String stringify(Env env, T input, boolean ... options) throws APIException {\r
+               try {\r
+                       StringWriter sw = new StringWriter();\r
+                       TimeTaken tt = env.start("JAXB Stringify", Env.XML);\r
+                       try {\r
+                               jmar.marshal(env.debug(), input, sw, options);\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+                       String str = sw.toString();\r
+                       tt.size(str.getBytes().length);\r
+                       return str;\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               }\r
+       }\r
+\r
+       // @Override\r
+       public void stringify(Env env, T input, Writer writer, boolean ... options) throws APIException {\r
+               TimeTaken tt = env.start("JAXB Stringify", Env.XML);\r
+               try {\r
+                       jmar.marshal(env.debug(), input, writer, options);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+       // @Override\r
+       public void stringify(Env env, T input, OutputStream os, boolean ... options) throws APIException {\r
+               TimeTaken tt = env.start("JAXB Stringify", Env.XML);\r
+               try {\r
+                       jmar.marshal(env.debug(), input, os, options);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+       // @Override\r
+       public T objectify(Env env, Reader rdr) throws APIException {\r
+               TimeTaken tt = env.start("JAXB Objectify", Env.XML);\r
+               try {\r
+                       return jumar.unmarshal(env.debug(), rdr);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+       // @Override\r
+       public T objectify(Reader rdr) throws APIException {\r
+               try {\r
+                       return jumar.unmarshal(primaryEnv.debug(), rdr);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               }       \r
+       }\r
+\r
+       // @Override\r
+       public T objectify(Env env, InputStream is) throws APIException {\r
+               TimeTaken tt = env.start("JAXB Objectify", Env.XML);\r
+               try {\r
+                       return jumar.unmarshal(env.debug(), is);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+       // @Override\r
+       public T objectify(InputStream is) throws APIException {\r
+               try {\r
+                       return jumar.unmarshal(primaryEnv.debug(), is);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               }       \r
+       }\r
+\r
+       // @Override\r
+       public T objectify(Env env, String input) throws APIException {\r
+               TimeTaken tt = env.start("JAXB Objectify", Env.XML);\r
+               tt.size(input.getBytes().length);\r
+               try {\r
+                       return jumar.unmarshal(env.debug(), input);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+       // @Override\r
+       public T objectify(String text) throws APIException {\r
+               try {\r
+                       return jumar.unmarshal(primaryEnv.debug(), text);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               }       \r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       // @Override\r
+       public Class<T> getTypeClass() {\r
+               return (Class<T>)jmar.getMarshalClass();\r
+       }\r
+\r
+}\r
index e1c54c6..84502ad 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.jaxb;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-
-import javax.xml.bind.JAXBException;
-
-import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.misc.env.Data;
-import org.onap.aaf.misc.env.Env;
-import org.onap.aaf.misc.env.EnvJAXB;
-import org.onap.aaf.misc.env.old.IOStringifier;
-import org.onap.aaf.misc.env.old.Objectifier;
-import org.onap.aaf.misc.env.old.Stringifier;
-/**
- * <H1>Data</H1>
- * <i>Data</i> facilitates lazy marshaling of data with a pre-determined
- * marshaling mechanism.<p>
- * 
- * It stores either Object (defined by Generic {@literal <T>}) or String.<p>  
- * 
- * On asking for Object of type {@literal <T>}, it will respond with the object
- * if it exists, or unmarshal the string and pass the result back.<p>
- * 
- * On asking for String, it will respond with the String
- * if it exists, or marshal the String and pass the result back.<p>
- * 
- * @author Jonathan
- *
- * @param <T>
- */
-public final class JAXBData<T> implements Data<T>{
-       private Stringifier<T> stringifier;
-       private Objectifier<T> objectifier;
-       private String dataAsString;
-       private T dataAsObject;
-       private Class<T> tclass;
-       private JAXBDF<T> df;
-       private Env creatingEnv;
-       private boolean options[] = new boolean[] {false, false};
-       
-       /**
-        * Construct a Data Object with an appropriate Stringifier, Objectifier and Class to support
-        * 
-        * @param env
-        * @param strfr
-        * @param objfr
-        * @param text
-        * @param typeClass
-        */
-       JAXBData(Env env, JAXBDF<T> df, Stringifier<T> strfr, Objectifier<T> objfr, String text, Class<T> typeClass) {
-               dataAsString = text;
-               dataAsObject = null;
-               stringifier = strfr;
-               objectifier = objfr;
-               tclass = typeClass;
-               creatingEnv = env;
-               this.df = df;
-       }
-       
-       
-       /**
-        * Construct a Data Object with an appropriate Stringifier, Objectifier and Object (which will
-        * yield it's class)
-        * 
-        * @param env
-        * @param strfr
-        * @param objfr
-        * @param object
-        */
-       @SuppressWarnings("unchecked")
-       JAXBData(Env env, JAXBDF<T> df, Stringifier<T> strfr, Objectifier<T> objfr, T object) {
-               dataAsString = null;
-               dataAsObject = object;
-               stringifier = strfr;
-               objectifier = objfr;
-               tclass = (Class<T>) object.getClass();
-               creatingEnv = env;
-               this.df = df;
-       }
-
-       /**
-        * Respond with the String if it exists, or marshal the String and pass the result back.<p>
-        * 
-        * Explicitly use a specific Env for logging purposes
-        * 
-        * @param env
-        * @return String
-        * @throws APIException
-        */
-       public String asString(EnvJAXB env) throws APIException {
-               if(dataAsString!=null) {
-                       return dataAsString;
-               } else {
-                       return dataAsString = stringifier.stringify(env, dataAsObject);
-               }
-       }
-
-       /**
-        * Respond with the String if it exists, or marshal the String and pass the result back.
-        * 
-        * However, use the Env the Data Object was created with.
-        * 
-        * @return String
-        * @throws APIException
-        */
-       // @Override
-       public String asString() throws APIException {
-               if(dataAsString!=null) {
-                       return dataAsString;
-               } else {
-                       return dataAsString = stringifier.stringify(creatingEnv, dataAsObject,options);
-               }
-       }
-       
-       public Data<T> to(OutputStream os) throws APIException, IOException {
-               if(dataAsString!=null) {
-                       os.write(dataAsString.getBytes());
-               } else if (stringifier instanceof IOStringifier){
-                       ((IOStringifier<T>)stringifier).stringify(creatingEnv, dataAsObject, os, options);
-               } else {
-                       dataAsString = stringifier.stringify(creatingEnv, dataAsObject, options);
-                       os.write(dataAsString.getBytes());
-               }
-               return this;
-       }
-
-
-       // @Override
-       public JAXBData<T> to(Writer writer) throws APIException, IOException {
-               if(dataAsString!=null) {
-                       writer.write(dataAsString);
-               } else if (stringifier instanceof IOStringifier){
-                       ((IOStringifier<T>)stringifier).stringify(creatingEnv, dataAsObject, writer, options);
-               } else {
-                       dataAsString = stringifier.stringify(creatingEnv, dataAsObject, options);
-                       writer.write(dataAsString);
-               }
-               return this;
-       }
-
-
-       public InputStream getInputStream() throws APIException {
-               if(dataAsString==null) {
-                       dataAsString = stringifier.stringify(creatingEnv,dataAsObject,options);
-               }
-               return new ByteArrayInputStream(dataAsString.getBytes());
-       }
-       
-       /**
-        * Respond with the Object of type {@literal <T>} if it exists, or unmarshal from String 
-        * and pass the result back.<p>
-        * 
-        * Explicitly use a specific Env for logging purposes
-        * 
-        * @param env
-        * @return T
-        * @throws APIException
-        */
-
-       public T asObject(EnvJAXB env) throws APIException {
-               if(dataAsObject !=null) {
-                       return dataAsObject;
-               } else {
-                       // Some Java compilers need two statements here
-                       dataAsObject = objectifier.objectify(env, dataAsString);
-                       return dataAsObject;
-               }
-       }
-
-       /**
-        * Respond with the Object of type {@literal <T>} if it exists, or unmarshal from String 
-        * and pass the result back.<p>
-        *
-        * However, use the Env the Data Object was created with.
-        * 
-        * @return T
-        * @throws APIException
-        */
-       // @Override
-       public T asObject() throws APIException {
-               if(dataAsObject !=null) {
-                       return dataAsObject;
-               } else {
-                       // Some Java compilers need two statements here
-                       dataAsObject = objectifier.objectify(creatingEnv, dataAsString);
-                       return dataAsObject;
-               }
-       }
-       
-
-       /**
-        * Return the Class Type supported by this DataObject
-        * 
-        * @return {@literal Class<T>}
-        */
-       // @Override
-       public Class<T> getTypeClass() {
-               return tclass;
-       }
-       
-       
-       /**
-        * For Debugging Convenience, we marshal to String if possible.
-        * 
-        * Behavior is essentially the same as asString(), except asString() throws
-        * an APIException.  <p>
-        * Since toString() must not throw exceptions, the function just catches and prints an
-        * error, which is probably not the behavior desired.<p>
-        *  
-        * Therefore, use "asString()" where possible in actual Transactional code. 
-        * 
-        * @see java.lang.Object#toString()
-        */
-       // @Override
-       public String toString() {
-               if(dataAsString!=null) {
-                       return dataAsString;
-               } else {
-                       try {
-                               return dataAsString = stringifier.stringify(creatingEnv, dataAsObject);
-                       } catch (APIException e) {
-                               return "ERROR - Can't Stringify from Object " + e.getLocalizedMessage();
-                       }
-               }
-       }
-
-       public Data<T> load(T t) throws APIException {
-               dataAsObject = t;
-               dataAsString = null;
-               return this;
-       }
-
-
-       public Data<T> load(String str) throws APIException {
-               dataAsObject = null;
-               dataAsString = str;
-               return this;
-       }
-
-
-       public Data<T> load(InputStream is) throws APIException {
-               try {
-                       dataAsObject = df.jumar.unmarshal(creatingEnv.debug(),is);
-                       dataAsString = null;
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               }
-               return this;
-       }
-
-
-       public Data<T> load(Reader rdr) throws APIException {
-               try {
-                       dataAsObject = df.jumar.unmarshal(creatingEnv.debug(),rdr);
-                       dataAsString = null;
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               }
-               return this;
-       }
-
-
-       // @Override
-       public void direct(InputStream input, OutputStream output) throws APIException, IOException {
-               byte b[] = new byte[128];
-               int count;
-               do {
-                       count = input.read(b);
-                       if(count>0)output.write(b, 0, count);
-               } while(count>=0);
-       }
-
-
-       // @Override
-       public Data<T> out(TYPE type) {
-               // it's going to be XML regardless...
-               return this;
-       }
-
-
-       // @Override
-       public Data<T> in(TYPE type) {
-               // Not Supported... will still be XML
-               return this;
-       }
-
-
-       // @Override
-       public Data<T> option(int option) {
-               options[0] = (option&Data.PRETTY)==Data.PRETTY;
-               options[1] = (option&Data.FRAGMENT)==Data.FRAGMENT;
-               return this;
-       }
-       
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.jaxb;\r
+\r
+import java.io.ByteArrayInputStream;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
+import java.io.Reader;\r
+import java.io.Writer;\r
+\r
+import javax.xml.bind.JAXBException;\r
+\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.Data;\r
+import org.onap.aaf.misc.env.Env;\r
+import org.onap.aaf.misc.env.EnvJAXB;\r
+import org.onap.aaf.misc.env.old.IOStringifier;\r
+import org.onap.aaf.misc.env.old.Objectifier;\r
+import org.onap.aaf.misc.env.old.Stringifier;\r
+/**\r
+ * <H1>Data</H1>\r
+ * <i>Data</i> facilitates lazy marshaling of data with a pre-determined\r
+ * marshaling mechanism.<p>\r
+ * \r
+ * It stores either Object (defined by Generic {@literal <T>}) or String.<p>  \r
+ * \r
+ * On asking for Object of type {@literal <T>}, it will respond with the object\r
+ * if it exists, or unmarshal the string and pass the result back.<p>\r
+ * \r
+ * On asking for String, it will respond with the String\r
+ * if it exists, or marshal the String and pass the result back.<p>\r
+ * \r
+ * @author Jonathan\r
+ *\r
+ * @param <T>\r
+ */\r
+public final class JAXBData<T> implements Data<T>{\r
+       private Stringifier<T> stringifier;\r
+       private Objectifier<T> objectifier;\r
+       private String dataAsString;\r
+       private T dataAsObject;\r
+       private Class<T> tclass;\r
+       private JAXBDF<T> df;\r
+       private Env creatingEnv;\r
+       private boolean options[] = new boolean[] {false, false};\r
+       \r
+       /**\r
+        * Construct a Data Object with an appropriate Stringifier, Objectifier and Class to support\r
+        * \r
+        * @param env\r
+        * @param strfr\r
+        * @param objfr\r
+        * @param text\r
+        * @param typeClass\r
+        */\r
+       JAXBData(Env env, JAXBDF<T> df, Stringifier<T> strfr, Objectifier<T> objfr, String text, Class<T> typeClass) {\r
+               dataAsString = text;\r
+               dataAsObject = null;\r
+               stringifier = strfr;\r
+               objectifier = objfr;\r
+               tclass = typeClass;\r
+               creatingEnv = env;\r
+               this.df = df;\r
+       }\r
+       \r
+       \r
+       /**\r
+        * Construct a Data Object with an appropriate Stringifier, Objectifier and Object (which will\r
+        * yield it's class)\r
+        * \r
+        * @param env\r
+        * @param strfr\r
+        * @param objfr\r
+        * @param object\r
+        */\r
+       @SuppressWarnings("unchecked")\r
+       JAXBData(Env env, JAXBDF<T> df, Stringifier<T> strfr, Objectifier<T> objfr, T object) {\r
+               dataAsString = null;\r
+               dataAsObject = object;\r
+               stringifier = strfr;\r
+               objectifier = objfr;\r
+               tclass = (Class<T>) object.getClass();\r
+               creatingEnv = env;\r
+               this.df = df;\r
+       }\r
+\r
+       /**\r
+        * Respond with the String if it exists, or marshal the String and pass the result back.<p>\r
+        * \r
+        * Explicitly use a specific Env for logging purposes\r
+        * \r
+        * @param env\r
+        * @return String\r
+        * @throws APIException\r
+        */\r
+       public String asString(EnvJAXB env) throws APIException {\r
+               if(dataAsString!=null) {\r
+                       return dataAsString;\r
+               } else {\r
+                       return dataAsString = stringifier.stringify(env, dataAsObject);\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Respond with the String if it exists, or marshal the String and pass the result back.\r
+        * \r
+        * However, use the Env the Data Object was created with.\r
+        * \r
+        * @return String\r
+        * @throws APIException\r
+        */\r
+       // @Override\r
+       public String asString() throws APIException {\r
+               if(dataAsString!=null) {\r
+                       return dataAsString;\r
+               } else {\r
+                       return dataAsString = stringifier.stringify(creatingEnv, dataAsObject,options);\r
+               }\r
+       }\r
+       \r
+       public Data<T> to(OutputStream os) throws APIException, IOException {\r
+               if(dataAsString!=null) {\r
+                       os.write(dataAsString.getBytes());\r
+               } else if (stringifier instanceof IOStringifier){\r
+                       ((IOStringifier<T>)stringifier).stringify(creatingEnv, dataAsObject, os, options);\r
+               } else {\r
+                       dataAsString = stringifier.stringify(creatingEnv, dataAsObject, options);\r
+                       os.write(dataAsString.getBytes());\r
+               }\r
+               return this;\r
+       }\r
+\r
+\r
+       // @Override\r
+       public JAXBData<T> to(Writer writer) throws APIException, IOException {\r
+               if(dataAsString!=null) {\r
+                       writer.write(dataAsString);\r
+               } else if (stringifier instanceof IOStringifier){\r
+                       ((IOStringifier<T>)stringifier).stringify(creatingEnv, dataAsObject, writer, options);\r
+               } else {\r
+                       dataAsString = stringifier.stringify(creatingEnv, dataAsObject, options);\r
+                       writer.write(dataAsString);\r
+               }\r
+               return this;\r
+       }\r
+\r
+\r
+       public InputStream getInputStream() throws APIException {\r
+               if(dataAsString==null) {\r
+                       dataAsString = stringifier.stringify(creatingEnv,dataAsObject,options);\r
+               }\r
+               return new ByteArrayInputStream(dataAsString.getBytes());\r
+       }\r
+       \r
+       /**\r
+        * Respond with the Object of type {@literal <T>} if it exists, or unmarshal from String \r
+        * and pass the result back.<p>\r
+        * \r
+        * Explicitly use a specific Env for logging purposes\r
+        * \r
+        * @param env\r
+        * @return T\r
+        * @throws APIException\r
+        */\r
+\r
+       public T asObject(EnvJAXB env) throws APIException {\r
+               if(dataAsObject !=null) {\r
+                       return dataAsObject;\r
+               } else {\r
+                       // Some Java compilers need two statements here\r
+                       dataAsObject = objectifier.objectify(env, dataAsString);\r
+                       return dataAsObject;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Respond with the Object of type {@literal <T>} if it exists, or unmarshal from String \r
+        * and pass the result back.<p>\r
+        *\r
+        * However, use the Env the Data Object was created with.\r
+        * \r
+        * @return T\r
+        * @throws APIException\r
+        */\r
+       // @Override\r
+       public T asObject() throws APIException {\r
+               if(dataAsObject !=null) {\r
+                       return dataAsObject;\r
+               } else {\r
+                       // Some Java compilers need two statements here\r
+                       dataAsObject = objectifier.objectify(creatingEnv, dataAsString);\r
+                       return dataAsObject;\r
+               }\r
+       }\r
+       \r
+\r
+       /**\r
+        * Return the Class Type supported by this DataObject\r
+        * \r
+        * @return {@literal Class<T>}\r
+        */\r
+       // @Override\r
+       public Class<T> getTypeClass() {\r
+               return tclass;\r
+       }\r
+       \r
+       \r
+       /**\r
+        * For Debugging Convenience, we marshal to String if possible.\r
+        * \r
+        * Behavior is essentially the same as asString(), except asString() throws\r
+        * an APIException.  <p>\r
+        * Since toString() must not throw exceptions, the function just catches and prints an\r
+        * error, which is probably not the behavior desired.<p>\r
+        *  \r
+        * Therefore, use "asString()" where possible in actual Transactional code. \r
+        * \r
+        * @see java.lang.Object#toString()\r
+        */\r
+       // @Override\r
+       public String toString() {\r
+               if(dataAsString!=null) {\r
+                       return dataAsString;\r
+               } else {\r
+                       try {\r
+                               return dataAsString = stringifier.stringify(creatingEnv, dataAsObject);\r
+                       } catch (APIException e) {\r
+                               return "ERROR - Can't Stringify from Object " + e.getLocalizedMessage();\r
+                       }\r
+               }\r
+       }\r
+\r
+       public Data<T> load(T t) throws APIException {\r
+               dataAsObject = t;\r
+               dataAsString = null;\r
+               return this;\r
+       }\r
+\r
+\r
+       public Data<T> load(String str) throws APIException {\r
+               dataAsObject = null;\r
+               dataAsString = str;\r
+               return this;\r
+       }\r
+\r
+\r
+       public Data<T> load(InputStream is) throws APIException {\r
+               try {\r
+                       dataAsObject = df.jumar.unmarshal(creatingEnv.debug(),is);\r
+                       dataAsString = null;\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               }\r
+               return this;\r
+       }\r
+\r
+\r
+       public Data<T> load(Reader rdr) throws APIException {\r
+               try {\r
+                       dataAsObject = df.jumar.unmarshal(creatingEnv.debug(),rdr);\r
+                       dataAsString = null;\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               }\r
+               return this;\r
+       }\r
+\r
+\r
+       // @Override\r
+       public void direct(InputStream input, OutputStream output) throws APIException, IOException {\r
+               byte b[] = new byte[128];\r
+               int count;\r
+               do {\r
+                       count = input.read(b);\r
+                       if(count>0)output.write(b, 0, count);\r
+               } while(count>=0);\r
+       }\r
+\r
+\r
+       // @Override\r
+       public Data<T> out(TYPE type) {\r
+               // it's going to be XML regardless...\r
+               return this;\r
+       }\r
+\r
+\r
+       // @Override\r
+       public Data<T> in(TYPE type) {\r
+               // Not Supported... will still be XML\r
+               return this;\r
+       }\r
+\r
+\r
+       // @Override\r
+       public Data<T> option(int option) {\r
+               options[0] = (option&Data.PRETTY)==Data.PRETTY;\r
+               options[1] = (option&Data.FRAGMENT)==Data.FRAGMENT;\r
+               return this;\r
+       }\r
+       \r
 }
\ No newline at end of file
index 9679d84..432a449 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.jaxb;
-
-import java.io.InputStream;
-import java.io.Reader;
-
-import javax.xml.bind.JAXBException;
-import javax.xml.validation.Schema;
-
-import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.misc.env.Env;
-import org.onap.aaf.misc.env.TimeTaken;
-import org.onap.aaf.misc.env.old.IOObjectifier;
-
-/**
- * Allow Extended IO interface usage without muddying up the Stringifier Interface
- */
-public class JAXBObjectifier<T> implements IOObjectifier<T> {
-       private JAXBumar jumar;
-
-       public JAXBObjectifier(Schema schema, Class<?>... classes) throws APIException {
-               try {
-                       jumar = new JAXBumar(schema, classes);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               }
-       }
-
-       public JAXBObjectifier(Class<?>... classes) throws APIException {
-               try {
-                       jumar = new JAXBumar(classes);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               }
-       }
-       
-    // package on purpose
-       JAXBObjectifier(JAXBumar jumar) {
-               this.jumar = jumar;
-       }
-
-       @SuppressWarnings("unchecked")
-       // @Override
-       public T objectify(Env env, String input) throws APIException {
-               TimeTaken tt = env.start("JAXB Unmarshal", Env.XML);
-               try {
-                       tt.size(input.length());
-                       return (T)jumar.unmarshal(env.debug(), input);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               } finally {
-                       tt.done();
-               }
-       }
-
-       @SuppressWarnings("unchecked")
-       // @Override
-       public T objectify(Env env, Reader rdr) throws APIException {
-               //TODO create a Reader that Counts?
-               TimeTaken tt = env.start("JAXB Unmarshal", Env.XML);
-               try {
-                       return (T)jumar.unmarshal(env.debug(), rdr);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               } finally {
-                       tt.done();
-               }
-       }
-
-
-       @SuppressWarnings("unchecked")
-       // @Override
-       public T objectify(Env env, InputStream is) throws APIException {
-               //TODO create a Reader that Counts?
-               TimeTaken tt = env.start("JAXB Unmarshal", Env.XML);
-               try {
-                       return (T)jumar.unmarshal(env.debug(), is);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               } finally {
-                       tt.done();
-               }
-       }
-
-
-       public void servicePrestart(Env env) throws APIException {
-       }
-
-       public void threadPrestart(Env env) throws APIException {
-       }
-
-       // // @Override
-       public void refresh(Env env) throws APIException {
-       }
-
-       // // @Override
-       public void threadDestroy(Env env) throws APIException {
-       }
-
-       // // @Override
-       public void serviceDestroy(Env env) throws APIException {
-       }
-
-
-       @SuppressWarnings("unchecked")
-       public T newInstance() throws APIException {
-               try {
-                       return (T)jumar.newInstance();
-               } catch (Exception e) {
-                       throw new APIException(e);
-               }
-       }
-
-}
-
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.jaxb;\r
+\r
+import java.io.InputStream;\r
+import java.io.Reader;\r
+\r
+import javax.xml.bind.JAXBException;\r
+import javax.xml.validation.Schema;\r
+\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.Env;\r
+import org.onap.aaf.misc.env.TimeTaken;\r
+import org.onap.aaf.misc.env.old.IOObjectifier;\r
+\r
+/**\r
+ * Allow Extended IO interface usage without muddying up the Stringifier Interface\r
+ */\r
+public class JAXBObjectifier<T> implements IOObjectifier<T> {\r
+       private JAXBumar jumar;\r
+\r
+       public JAXBObjectifier(Schema schema, Class<?>... classes) throws APIException {\r
+               try {\r
+                       jumar = new JAXBumar(schema, classes);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               }\r
+       }\r
+\r
+       public JAXBObjectifier(Class<?>... classes) throws APIException {\r
+               try {\r
+                       jumar = new JAXBumar(classes);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               }\r
+       }\r
+       \r
+    // package on purpose\r
+       JAXBObjectifier(JAXBumar jumar) {\r
+               this.jumar = jumar;\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       // @Override\r
+       public T objectify(Env env, String input) throws APIException {\r
+               TimeTaken tt = env.start("JAXB Unmarshal", Env.XML);\r
+               try {\r
+                       tt.size(input.length());\r
+                       return (T)jumar.unmarshal(env.debug(), input);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       // @Override\r
+       public T objectify(Env env, Reader rdr) throws APIException {\r
+               //TODO create a Reader that Counts?\r
+               TimeTaken tt = env.start("JAXB Unmarshal", Env.XML);\r
+               try {\r
+                       return (T)jumar.unmarshal(env.debug(), rdr);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+\r
+       @SuppressWarnings("unchecked")\r
+       // @Override\r
+       public T objectify(Env env, InputStream is) throws APIException {\r
+               //TODO create a Reader that Counts?\r
+               TimeTaken tt = env.start("JAXB Unmarshal", Env.XML);\r
+               try {\r
+                       return (T)jumar.unmarshal(env.debug(), is);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+\r
+       public void servicePrestart(Env env) throws APIException {\r
+       }\r
+\r
+       public void threadPrestart(Env env) throws APIException {\r
+       }\r
+\r
+       // // @Override\r
+       public void refresh(Env env) throws APIException {\r
+       }\r
+\r
+       // // @Override\r
+       public void threadDestroy(Env env) throws APIException {\r
+       }\r
+\r
+       // // @Override\r
+       public void serviceDestroy(Env env) throws APIException {\r
+       }\r
+\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public T newInstance() throws APIException {\r
+               try {\r
+                       return (T)jumar.newInstance();\r
+               } catch (Exception e) {\r
+                       throw new APIException(e);\r
+               }\r
+       }\r
+\r
+}\r
+\r
index 5bed4fd..d1b0cda 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.jaxb;
-
-import java.io.OutputStream;
-import java.io.StringWriter;
-import java.io.Writer;
-
-import javax.xml.bind.JAXBException;
-import javax.xml.namespace.QName;
-
-import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.misc.env.Env;
-import org.onap.aaf.misc.env.TimeTaken;
-import org.onap.aaf.misc.env.old.IOStringifier;
-
-public class JAXBStringifier<T> implements IOStringifier<T> {
-       private JAXBmar jmar;
-
-       public JAXBStringifier(Class<?>... classes) throws APIException {
-               try {
-                       jmar = new JAXBmar(classes);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               }
-       }
-
-       public JAXBStringifier(QName qname, Class<?>... classes)
-                       throws APIException {
-               try {
-                       jmar = new JAXBmar(qname, classes);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               }
-       }
-       
-       // package on purpose
-       JAXBStringifier(JAXBmar jmar) {
-               this.jmar = jmar;
-       }
-
-       // // @Override
-       public void stringify(Env env, T input, Writer writer, boolean ... options)
-                       throws APIException {
-               TimeTaken tt = env.start("JAXB Marshal", Env.XML);
-               try {
-                       jmar.marshal(env.debug(), input, writer, options);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               } finally {
-                       tt.done();
-               }
-       }
-
-       // @Override
-       public void stringify(Env env, T input, OutputStream os, boolean ... options)
-                       throws APIException {
-               // TODO create an OutputStream that Counts?
-               TimeTaken tt = env.start("JAXB Marshal", Env.XML);
-               try {
-                       jmar.marshal(env.debug(), input, os, options);
-               } catch (JAXBException e) {
-                       throw new APIException(e);
-               } finally {
-                       tt.done();
-               }
-       }
-
-       // @Override
-       public String stringify(Env env, T input, boolean ... options) throws APIException {
-               TimeTaken tt = env.start("JAXB Marshal", Env.XML);
-               StringWriter sw = new StringWriter();
-               try {
-                       jmar.marshal(env.debug(), input, sw, options);
-                       String rv = sw.toString();
-                       tt.size(rv.length());
-                       return rv;
-               } catch (JAXBException e) {
-                       tt.size(0);
-                       throw new APIException(e);
-               } finally {
-                       tt.done();
-               }
-       }
-
-       // // @Override
-       public void servicePrestart(Env env) throws APIException {
-       }
-
-       // // @Override
-       public void threadPrestart(Env env) throws APIException {
-       }
-
-       // // @Override
-       public void refresh(Env env) throws APIException {
-       }
-
-       // // @Override
-       public void threadDestroy(Env env) throws APIException {
-       }
-
-       // // @Override
-       public void serviceDestroy(Env env) throws APIException {
-       }
-
-       // @Override
-       public JAXBStringifier<T> pretty(boolean pretty) {
-               jmar.pretty(pretty);
-               return this;
-       }
-
-       // @Override
-       public JAXBStringifier<T> asFragment(boolean fragment) {
-               jmar.asFragment(fragment);
-               return this;
-       }
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.jaxb;\r
+\r
+import java.io.OutputStream;\r
+import java.io.StringWriter;\r
+import java.io.Writer;\r
+\r
+import javax.xml.bind.JAXBException;\r
+import javax.xml.namespace.QName;\r
+\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.Env;\r
+import org.onap.aaf.misc.env.TimeTaken;\r
+import org.onap.aaf.misc.env.old.IOStringifier;\r
+\r
+public class JAXBStringifier<T> implements IOStringifier<T> {\r
+       private JAXBmar jmar;\r
+\r
+       public JAXBStringifier(Class<?>... classes) throws APIException {\r
+               try {\r
+                       jmar = new JAXBmar(classes);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               }\r
+       }\r
+\r
+       public JAXBStringifier(QName qname, Class<?>... classes)\r
+                       throws APIException {\r
+               try {\r
+                       jmar = new JAXBmar(qname, classes);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               }\r
+       }\r
+       \r
+       // package on purpose\r
+       JAXBStringifier(JAXBmar jmar) {\r
+               this.jmar = jmar;\r
+       }\r
+\r
+       // // @Override\r
+       public void stringify(Env env, T input, Writer writer, boolean ... options)\r
+                       throws APIException {\r
+               TimeTaken tt = env.start("JAXB Marshal", Env.XML);\r
+               try {\r
+                       jmar.marshal(env.debug(), input, writer, options);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+       // @Override\r
+       public void stringify(Env env, T input, OutputStream os, boolean ... options)\r
+                       throws APIException {\r
+               // TODO create an OutputStream that Counts?\r
+               TimeTaken tt = env.start("JAXB Marshal", Env.XML);\r
+               try {\r
+                       jmar.marshal(env.debug(), input, os, options);\r
+               } catch (JAXBException e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+       // @Override\r
+       public String stringify(Env env, T input, boolean ... options) throws APIException {\r
+               TimeTaken tt = env.start("JAXB Marshal", Env.XML);\r
+               StringWriter sw = new StringWriter();\r
+               try {\r
+                       jmar.marshal(env.debug(), input, sw, options);\r
+                       String rv = sw.toString();\r
+                       tt.size(rv.length());\r
+                       return rv;\r
+               } catch (JAXBException e) {\r
+                       tt.size(0);\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+       // // @Override\r
+       public void servicePrestart(Env env) throws APIException {\r
+       }\r
+\r
+       // // @Override\r
+       public void threadPrestart(Env env) throws APIException {\r
+       }\r
+\r
+       // // @Override\r
+       public void refresh(Env env) throws APIException {\r
+       }\r
+\r
+       // // @Override\r
+       public void threadDestroy(Env env) throws APIException {\r
+       }\r
+\r
+       // // @Override\r
+       public void serviceDestroy(Env env) throws APIException {\r
+       }\r
+\r
+       // @Override\r
+       public JAXBStringifier<T> pretty(boolean pretty) {\r
+               jmar.pretty(pretty);\r
+               return this;\r
+       }\r
+\r
+       // @Override\r
+       public JAXBStringifier<T> asFragment(boolean fragment) {\r
+               jmar.asFragment(fragment);\r
+               return this;\r
+       }\r
+\r
+}\r
index f35ffb7..cca3e68 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-/**
- * JAXBumar.java
- *
- * Created on: Apr 10, 2009
- * Created by: Jonathan
- *
- * Revamped to do away with ThreadLocal 5/27/2011, JG1555
- *
- * (c) 2009 SBC Knowledge Ventures, L.P. All rights reserved.
- ******************************************************************* 
- * RESTRICTED - PROPRIETARY INFORMATION The Information contained 
- * herein is for use only by authorized employees of AT&T Services, 
- * Inc., and authorized Affiliates of AT&T Services, Inc., and is 
- * not for general distribution within or outside the respective 
- * companies. 
- *******************************************************************
- */
-package org.onap.aaf.misc.env.jaxb;
-
-import java.io.OutputStream;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.namespace.QName;
-
-import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.misc.env.LogTarget;
-import org.onap.aaf.misc.env.util.Pool;
-import org.onap.aaf.misc.env.util.Pool.Pooled;
-
-/**
- * JAXBmar classes are inexpensive for going in and out of scope
- * and have been made thread safe via Pooling
-
- * @author Jonathan
- *
- */
-public class JAXBmar {
-       // Need to store off possible JAXBContexts based on Class, which will be stored in Creator
-       private static Map<Class<?>[],Pool<PMarshaller>> pools = new HashMap<Class<?>[], Pool<PMarshaller>>();
-
-       // Handle Marshaller class setting of properties only when needed
-       private class PMarshaller {
-               private Marshaller m;
-               private boolean p;
-               private boolean f;
-               
-               public PMarshaller(Marshaller marshaller) throws JAXBException {
-                       m = marshaller;
-               m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
-               m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, p = false);
-               m.setProperty(Marshaller.JAXB_FRAGMENT, f = false);
-               }
-               
-               public Marshaller get(boolean pretty, boolean fragment) throws JAXBException {
-                       if(pretty != p) {
-                       m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, p = pretty);
-                       }
-                       if(fragment != f) {
-                       m.setProperty(Marshaller.JAXB_FRAGMENT, f = fragment);
-                       }
-                       return m;
-               }
-       }
-       
-       private class Creator implements Pool.Creator<PMarshaller> {
-               private JAXBContext jc;
-               private String name;
-               public Creator(Class<?>[] classes) throws JAXBException {
-                       jc = JAXBContext.newInstance(classes);
-                       name = "JAXBmar: " + classes[0].getName();
-               }
-               
-               // @Override
-               public PMarshaller create() throws APIException {
-                       try {
-                               return new PMarshaller(jc.createMarshaller());
-                       } catch (JAXBException e) {
-                               throw new APIException(e);
-                       }
-               }
-
-               public String toString() {
-                       return name;
-               }
-
-               // @Override
-               public void reuse(PMarshaller pm) {
-                       // Nothing to do
-               }
-               
-               // @Override
-               public void destroy(PMarshaller pm) {
-                       // Nothing to do
-               }
-
-               // @Override
-               public boolean isValid(PMarshaller t) {
-                       return true; 
-               }
-       }
-
-       //TODO isn't UTF-8 a standard string somewhere for encoding?
-       private boolean fragment= false;
-       private boolean pretty=false;
-       private QName qname;
-       
-       private Pool<PMarshaller> mpool; // specific Pool associated with constructed Classes
-       private Class<?> cls;
-       
-       private Pool<PMarshaller> getPool(Class<?> ... classes) throws JAXBException {
-               Pool<PMarshaller> mp;
-               synchronized(pools) {
-                       mp = pools.get(classes);
-                       if(mp==null) {
-                               pools.put(classes,mp = new Pool<PMarshaller>(new Creator(classes)));
-                       }
-               }               
-               return mp;
-       }
-       
-       public JAXBmar(Class<?>... classes) throws JAXBException {
-               cls = classes[0];
-               mpool = getPool(classes);
-               qname = null;
-       }
-
-       public JAXBmar(QName theQname, Class<?>... classes) throws JAXBException {
-               cls = classes[0];
-               mpool = getPool(classes);
-               qname = theQname;
-       }
-
-       @SuppressWarnings("unchecked")
-       public<O> O marshal(LogTarget lt,O o, Writer writer, boolean ... options) throws JAXBException, APIException {
-               boolean pretty, fragment;
-               pretty = options.length>0?options[0]:this.pretty;
-               fragment = options.length>1?options[1]:this.fragment;
-               Pooled<PMarshaller> m = mpool.get(lt);
-               try {
-                       if(qname==null) {
-                               m.content.get(pretty,fragment).marshal(o, writer);
-                       } else {
-                               m.content.get(pretty,fragment).marshal(
-                                       new JAXBElement<O>(qname, (Class<O>)cls, o ),
-                                       writer);
-                       }
-                       return o;
-               } finally {
-                       m.done();
-               }
-       }
-
-       @SuppressWarnings("unchecked")
-       public<O> O marshal(LogTarget lt, O o, OutputStream os, boolean ... options) throws JAXBException, APIException {
-               boolean pretty, fragment;
-               pretty = options.length>0?options[0]:this.pretty;
-               fragment = options.length>1?options[1]:this.fragment;
-               Pooled<PMarshaller> m = mpool.get(lt);
-               try {
-                       if(qname==null) {
-                               m.content.get(pretty,fragment).marshal(o, os);
-                       } else {
-                               m.content.get(pretty,fragment).marshal(
-                                       new JAXBElement<O>(qname, (Class<O>)cls, o ),os);
-                       }
-                       return o;
-               } finally {
-                       m.done();
-               }
-       }
-       
-       public<O> O marshal(LogTarget lt, O o, Writer writer, Class<O> clss) throws JAXBException, APIException {
-               Pooled<PMarshaller> m = mpool.get(lt);
-               try {
-                       if(qname==null) {
-                               m.content.get(pretty,fragment).marshal(o, writer);
-                       } else {
-                               m.content.get(pretty,fragment).marshal(
-                                       new JAXBElement<O>(qname, clss, o),writer);
-                       }
-                       return o;
-               } finally {
-                       m.done();
-               }
-                       
-       }
-
-       public<O> O marshal(LogTarget lt, O o, OutputStream os, Class<O> clss) throws JAXBException, APIException {
-               Pooled<PMarshaller> m = mpool.get(lt);
-               try {
-                       if(qname==null) { 
-                               m.content.get(pretty,fragment).marshal(o, os);
-                       } else {
-                               m.content.get(pretty,fragment).marshal(
-                                       new JAXBElement<O>(qname, clss, o ),os);
-                       }
-                       return o;
-               } finally {
-                       m.done();
-               }
-       }
-
-       /**
-        * @return
-        */
-       public Class<?> getMarshalClass() {
-               return cls;
-       }
-
-       public<O> String stringify(LogTarget lt, O o) throws JAXBException, APIException {
-               StringWriter sw = new StringWriter();
-               marshal(lt,o,sw);
-               return sw.toString();
-       }
-
-       public JAXBmar pretty(boolean pretty) {
-               this.pretty = pretty;
-               return this;
-       }
-       
-       public JAXBmar asFragment(boolean fragment) {
-               this.fragment = fragment;
-               return this;
-       }
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+/**\r
+ * JAXBumar.java\r
+ *\r
+ * Created on: Apr 10, 2009\r
+ * Created by: Jonathan\r
+ *\r
+ * Revamped to do away with ThreadLocal 5/27/2011, JG1555\r
+ *\r
+ * (c) 2009 SBC Knowledge Ventures, L.P. All rights reserved.\r
+ ******************************************************************* \r
+ * RESTRICTED - PROPRIETARY INFORMATION The Information contained \r
+ * herein is for use only by authorized employees of AT&T Services, \r
+ * Inc., and authorized Affiliates of AT&T Services, Inc., and is \r
+ * not for general distribution within or outside the respective \r
+ * companies. \r
+ *******************************************************************\r
+ */\r
+package org.onap.aaf.misc.env.jaxb;\r
+\r
+import java.io.OutputStream;\r
+import java.io.StringWriter;\r
+import java.io.Writer;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import javax.xml.bind.JAXBContext;\r
+import javax.xml.bind.JAXBElement;\r
+import javax.xml.bind.JAXBException;\r
+import javax.xml.bind.Marshaller;\r
+import javax.xml.namespace.QName;\r
+\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.LogTarget;\r
+import org.onap.aaf.misc.env.util.Pool;\r
+import org.onap.aaf.misc.env.util.Pool.Pooled;\r
+\r
+/**\r
+ * JAXBmar classes are inexpensive for going in and out of scope\r
+ * and have been made thread safe via Pooling\r
+\r
+ * @author Jonathan\r
+ *\r
+ */\r
+public class JAXBmar {\r
+       // Need to store off possible JAXBContexts based on Class, which will be stored in Creator\r
+       private static Map<Class<?>[],Pool<PMarshaller>> pools = new HashMap<Class<?>[], Pool<PMarshaller>>();\r
+\r
+       // Handle Marshaller class setting of properties only when needed\r
+       private class PMarshaller {\r
+               private Marshaller m;\r
+               private boolean p;\r
+               private boolean f;\r
+               \r
+               public PMarshaller(Marshaller marshaller) throws JAXBException {\r
+                       m = marshaller;\r
+               m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");\r
+               m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, p = false);\r
+               m.setProperty(Marshaller.JAXB_FRAGMENT, f = false);\r
+               }\r
+               \r
+               public Marshaller get(boolean pretty, boolean fragment) throws JAXBException {\r
+                       if(pretty != p) {\r
+                       m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, p = pretty);\r
+                       }\r
+                       if(fragment != f) {\r
+                       m.setProperty(Marshaller.JAXB_FRAGMENT, f = fragment);\r
+                       }\r
+                       return m;\r
+               }\r
+       }\r
+       \r
+       private class Creator implements Pool.Creator<PMarshaller> {\r
+               private JAXBContext jc;\r
+               private String name;\r
+               public Creator(Class<?>[] classes) throws JAXBException {\r
+                       jc = JAXBContext.newInstance(classes);\r
+                       name = "JAXBmar: " + classes[0].getName();\r
+               }\r
+               \r
+               // @Override\r
+               public PMarshaller create() throws APIException {\r
+                       try {\r
+                               return new PMarshaller(jc.createMarshaller());\r
+                       } catch (JAXBException e) {\r
+                               throw new APIException(e);\r
+                       }\r
+               }\r
+\r
+               public String toString() {\r
+                       return name;\r
+               }\r
+\r
+               // @Override\r
+               public void reuse(PMarshaller pm) {\r
+                       // Nothing to do\r
+               }\r
+               \r
+               // @Override\r
+               public void destroy(PMarshaller pm) {\r
+                       // Nothing to do\r
+               }\r
+\r
+               // @Override\r
+               public boolean isValid(PMarshaller t) {\r
+                       return true; \r
+               }\r
+       }\r
+\r
+       //TODO isn't UTF-8 a standard string somewhere for encoding?\r
+       private boolean fragment= false;\r
+       private boolean pretty=false;\r
+       private QName qname;\r
+       \r
+       private Pool<PMarshaller> mpool; // specific Pool associated with constructed Classes\r
+       private Class<?> cls;\r
+       \r
+       private Pool<PMarshaller> getPool(Class<?> ... classes) throws JAXBException {\r
+               Pool<PMarshaller> mp;\r
+               synchronized(pools) {\r
+                       mp = pools.get(classes);\r
+                       if(mp==null) {\r
+                               pools.put(classes,mp = new Pool<PMarshaller>(new Creator(classes)));\r
+                       }\r
+               }               \r
+               return mp;\r
+       }\r
+       \r
+       public JAXBmar(Class<?>... classes) throws JAXBException {\r
+               cls = classes[0];\r
+               mpool = getPool(classes);\r
+               qname = null;\r
+       }\r
+\r
+       public JAXBmar(QName theQname, Class<?>... classes) throws JAXBException {\r
+               cls = classes[0];\r
+               mpool = getPool(classes);\r
+               qname = theQname;\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public<O> O marshal(LogTarget lt,O o, Writer writer, boolean ... options) throws JAXBException, APIException {\r
+               boolean pretty, fragment;\r
+               pretty = options.length>0?options[0]:this.pretty;\r
+               fragment = options.length>1?options[1]:this.fragment;\r
+               Pooled<PMarshaller> m = mpool.get(lt);\r
+               try {\r
+                       if(qname==null) {\r
+                               m.content.get(pretty,fragment).marshal(o, writer);\r
+                       } else {\r
+                               m.content.get(pretty,fragment).marshal(\r
+                                       new JAXBElement<O>(qname, (Class<O>)cls, o ),\r
+                                       writer);\r
+                       }\r
+                       return o;\r
+               } finally {\r
+                       m.done();\r
+               }\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public<O> O marshal(LogTarget lt, O o, OutputStream os, boolean ... options) throws JAXBException, APIException {\r
+               boolean pretty, fragment;\r
+               pretty = options.length>0?options[0]:this.pretty;\r
+               fragment = options.length>1?options[1]:this.fragment;\r
+               Pooled<PMarshaller> m = mpool.get(lt);\r
+               try {\r
+                       if(qname==null) {\r
+                               m.content.get(pretty,fragment).marshal(o, os);\r
+                       } else {\r
+                               m.content.get(pretty,fragment).marshal(\r
+                                       new JAXBElement<O>(qname, (Class<O>)cls, o ),os);\r
+                       }\r
+                       return o;\r
+               } finally {\r
+                       m.done();\r
+               }\r
+       }\r
+       \r
+       public<O> O marshal(LogTarget lt, O o, Writer writer, Class<O> clss) throws JAXBException, APIException {\r
+               Pooled<PMarshaller> m = mpool.get(lt);\r
+               try {\r
+                       if(qname==null) {\r
+                               m.content.get(pretty,fragment).marshal(o, writer);\r
+                       } else {\r
+                               m.content.get(pretty,fragment).marshal(\r
+                                       new JAXBElement<O>(qname, clss, o),writer);\r
+                       }\r
+                       return o;\r
+               } finally {\r
+                       m.done();\r
+               }\r
+                       \r
+       }\r
+\r
+       public<O> O marshal(LogTarget lt, O o, OutputStream os, Class<O> clss) throws JAXBException, APIException {\r
+               Pooled<PMarshaller> m = mpool.get(lt);\r
+               try {\r
+                       if(qname==null) { \r
+                               m.content.get(pretty,fragment).marshal(o, os);\r
+                       } else {\r
+                               m.content.get(pretty,fragment).marshal(\r
+                                       new JAXBElement<O>(qname, clss, o ),os);\r
+                       }\r
+                       return o;\r
+               } finally {\r
+                       m.done();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * @return\r
+        */\r
+       public Class<?> getMarshalClass() {\r
+               return cls;\r
+       }\r
+\r
+       public<O> String stringify(LogTarget lt, O o) throws JAXBException, APIException {\r
+               StringWriter sw = new StringWriter();\r
+               marshal(lt,o,sw);\r
+               return sw.toString();\r
+       }\r
+\r
+       public JAXBmar pretty(boolean pretty) {\r
+               this.pretty = pretty;\r
+               return this;\r
+       }\r
+       \r
+       public JAXBmar asFragment(boolean fragment) {\r
+               this.fragment = fragment;\r
+               return this;\r
+       }\r
+}\r
index 7e60bce..94e9ba8 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-/**
- * JAXBumar.java
- *
- * Created on: Apr 10, 2009
- * Created by: Jonathan
- *
- * Revamped to do away with ThreadLocal 5/27/2011, JG1555
- *
- * (c) 2009 SBC Knowledge Ventures, L.P. All rights reserved.
- ******************************************************************* 
- * RESTRICTED - PROPRIETARY INFORMATION The Information contained 
- * herein is for use only by authorized employees of AT&T Services, 
- * Inc., and authorized Affiliates of AT&T Services, Inc., and is 
- * not for general distribution within or outside the respective 
- * companies. 
- *******************************************************************
- */
-package org.onap.aaf.misc.env.jaxb;
-
-import java.io.File;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.stream.XMLEventReader;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-
-import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.misc.env.LogTarget;
-import org.onap.aaf.misc.env.util.Pool;
-import org.onap.aaf.misc.env.util.Pool.Pooled;
-import org.w3c.dom.Node;
-
-/**
- * JAXBumar classes are inexpensive for going in and out of scope
- * and have been made thread safe via Pooling
- * 
- * @author Jonathan
- *
- */
-public class JAXBumar {
-       // Need to store off possible JAXBContexts based on Class, which will be stored in Creator
-       private static Map<Class<?>[],Pool<SUnmarshaller>> pools = new HashMap<Class<?>[], Pool<SUnmarshaller>>();
-
-       private Class<?> cls;
-       private Schema schema;
-       private Pool<SUnmarshaller> mpool;;
-
-       // Handle Marshaller class setting of properties only when needed
-       private class SUnmarshaller {
-               private Unmarshaller u;
-               private Schema s;
-               
-               public SUnmarshaller(Unmarshaller unmarshaller) throws JAXBException {
-                       u = unmarshaller;
-                       s = null;
-               }
-               
-               public Unmarshaller get(Schema schema) throws JAXBException {
-                       if(s != schema) {
-                               u.setSchema(s = schema);
-                       }
-                       return u;
-               }
-       }
-       
-       private class Creator implements Pool.Creator<SUnmarshaller> {
-               private JAXBContext jc;
-               private String name;
-               
-               public Creator(Class<?>[] classes) throws JAXBException {
-                       jc = JAXBContext.newInstance(classes);
-                       name = "JAXBumar: " + classes[0].getName();
-               }
-               
-               // @Override
-               public SUnmarshaller create() throws APIException {
-                       try {
-                               return new SUnmarshaller(jc.createUnmarshaller());
-                       } catch (JAXBException e) {
-                               throw new APIException(e);
-                       }
-               }
-               
-               public String toString() {
-                       return name;
-               }
-
-               // @Override
-               public void destroy(SUnmarshaller sui) {
-                       // Nothing to do
-               }
-               
-               // @Override
-               public boolean isValid(SUnmarshaller t) {
-                       return true; 
-               }
-
-               // @Override
-               public void reuse(SUnmarshaller t) {
-                       // Nothing to do here
-               }
-
-       }
-
-       private Pool<SUnmarshaller> getPool(Class<?> ... classes) throws JAXBException {
-               Pool<SUnmarshaller> mp;
-               synchronized(pools) {
-                       mp = pools.get(classes);
-                       if(mp==null) {
-                               pools.put(classes,mp = new Pool<SUnmarshaller>(new Creator(classes)));
-                       }
-               }               
-               return mp;
-       }
-
-       public JAXBumar(Class<?> ... classes) throws JAXBException {
-               cls = classes[0];
-               mpool = getPool(classes);
-               schema = null;
-       }
-       
-       /**
-        * Constructs a new JAXBumar with schema validation enabled.
-        * 
-        * @param schema
-        * @param theClass
-        * @throws JAXBException
-        */
-       public JAXBumar(Schema schema, Class<?> ... classes) throws JAXBException {
-               cls = classes[0];
-               mpool = getPool(classes);
-               this.schema = schema;
-       }
-       
-       @SuppressWarnings("unchecked")
-       public<O> O unmarshal(LogTarget env, Node node) throws JAXBException, APIException {
-               Pooled<SUnmarshaller> s = mpool.get(env);
-               try {
-                       return s.content.get(schema).unmarshal(node,(Class<O>)cls).getValue();
-               } finally {
-                       s.done();
-               }
-
-       }
-       
-       @SuppressWarnings("unchecked")
-       public<O> O unmarshal(LogTarget env, String xml) throws JAXBException, APIException {
-               if(xml==null) throw new JAXBException("Null Input for String unmarshal");
-               Pooled<SUnmarshaller> s = mpool.get(env);
-               try {
-                               return (O)s.content.get(schema).unmarshal(
-                                       new StreamSource(new StringReader(xml))
-                                       ,(Class<O>)cls).getValue();
-               } finally {
-                       s.done();
-               }
-       }
-       
-       @SuppressWarnings("unchecked")
-       public<O> O unmarshal(LogTarget env, File xmlFile) throws JAXBException, APIException {
-               Pooled<SUnmarshaller> s = mpool.get(env);
-               try {
-                       return (O)s.content.get(schema).unmarshal(xmlFile);
-               } finally {
-                       s.done();
-               }
-
-       }
-       
-       @SuppressWarnings("unchecked")
-       public<O> O unmarshal(LogTarget env,InputStream is) throws JAXBException, APIException {
-               Pooled<SUnmarshaller> s = mpool.get(env);
-               try {
-                       return (O)s.content.get(schema).unmarshal(is);
-               } finally {
-                       s.done();
-               }
-       }
-
-       @SuppressWarnings("unchecked")
-       public<O> O unmarshal(LogTarget env, Reader rdr) throws JAXBException, APIException {
-               Pooled<SUnmarshaller> s = mpool.get(env);
-               try {
-                       return (O)s.content.get(schema).unmarshal(rdr);
-               } finally {
-                       s.done();
-               }
-       }
-
-       @SuppressWarnings("unchecked")
-       public<O> O unmarshal(LogTarget env, XMLStreamReader xsr) throws JAXBException, APIException {
-               Pooled<SUnmarshaller> s = mpool.get(env);
-               try {
-                       return (O)s.content.get(schema).unmarshal(xsr,(Class<O>)cls).getValue();
-               } finally {
-                       s.done();
-               }
-       }
-
-       @SuppressWarnings("unchecked")
-       public<O> O unmarshal(LogTarget env, XMLEventReader xer) throws JAXBException, APIException {
-               Pooled<SUnmarshaller> s = mpool.get(env);
-               try {
-                       return (O)s.content.get(schema).unmarshal(xer,(Class<O>)cls).getValue();
-               } finally {
-                       s.done();
-               }
-       }
-
-       @SuppressWarnings("unchecked")
-       public<O> O newInstance() throws InstantiationException, IllegalAccessException{
-               return ((Class<O>)cls).newInstance();
-       }
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+/**\r
+ * JAXBumar.java\r
+ *\r
+ * Created on: Apr 10, 2009\r
+ * Created by: Jonathan\r
+ *\r
+ * Revamped to do away with ThreadLocal 5/27/2011, JG1555\r
+ *\r
+ * (c) 2009 SBC Knowledge Ventures, L.P. All rights reserved.\r
+ ******************************************************************* \r
+ * RESTRICTED - PROPRIETARY INFORMATION The Information contained \r
+ * herein is for use only by authorized employees of AT&T Services, \r
+ * Inc., and authorized Affiliates of AT&T Services, Inc., and is \r
+ * not for general distribution within or outside the respective \r
+ * companies. \r
+ *******************************************************************\r
+ */\r
+package org.onap.aaf.misc.env.jaxb;\r
+\r
+import java.io.File;\r
+import java.io.InputStream;\r
+import java.io.Reader;\r
+import java.io.StringReader;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import javax.xml.bind.JAXBContext;\r
+import javax.xml.bind.JAXBException;\r
+import javax.xml.bind.Unmarshaller;\r
+import javax.xml.stream.XMLEventReader;\r
+import javax.xml.stream.XMLStreamReader;\r
+import javax.xml.transform.stream.StreamSource;\r
+import javax.xml.validation.Schema;\r
+\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.LogTarget;\r
+import org.onap.aaf.misc.env.util.Pool;\r
+import org.onap.aaf.misc.env.util.Pool.Pooled;\r
+import org.w3c.dom.Node;\r
+\r
+/**\r
+ * JAXBumar classes are inexpensive for going in and out of scope\r
+ * and have been made thread safe via Pooling\r
+ * \r
+ * @author Jonathan\r
+ *\r
+ */\r
+public class JAXBumar {\r
+       // Need to store off possible JAXBContexts based on Class, which will be stored in Creator\r
+       private static Map<Class<?>[],Pool<SUnmarshaller>> pools = new HashMap<Class<?>[], Pool<SUnmarshaller>>();\r
+\r
+       private Class<?> cls;\r
+       private Schema schema;\r
+       private Pool<SUnmarshaller> mpool;;\r
+\r
+       // Handle Marshaller class setting of properties only when needed\r
+       private class SUnmarshaller {\r
+               private Unmarshaller u;\r
+               private Schema s;\r
+               \r
+               public SUnmarshaller(Unmarshaller unmarshaller) throws JAXBException {\r
+                       u = unmarshaller;\r
+                       s = null;\r
+               }\r
+               \r
+               public Unmarshaller get(Schema schema) throws JAXBException {\r
+                       if(s != schema) {\r
+                               u.setSchema(s = schema);\r
+                       }\r
+                       return u;\r
+               }\r
+       }\r
+       \r
+       private class Creator implements Pool.Creator<SUnmarshaller> {\r
+               private JAXBContext jc;\r
+               private String name;\r
+               \r
+               public Creator(Class<?>[] classes) throws JAXBException {\r
+                       jc = JAXBContext.newInstance(classes);\r
+                       name = "JAXBumar: " + classes[0].getName();\r
+               }\r
+               \r
+               // @Override\r
+               public SUnmarshaller create() throws APIException {\r
+                       try {\r
+                               return new SUnmarshaller(jc.createUnmarshaller());\r
+                       } catch (JAXBException e) {\r
+                               throw new APIException(e);\r
+                       }\r
+               }\r
+               \r
+               public String toString() {\r
+                       return name;\r
+               }\r
+\r
+               // @Override\r
+               public void destroy(SUnmarshaller sui) {\r
+                       // Nothing to do\r
+               }\r
+               \r
+               // @Override\r
+               public boolean isValid(SUnmarshaller t) {\r
+                       return true; \r
+               }\r
+\r
+               // @Override\r
+               public void reuse(SUnmarshaller t) {\r
+                       // Nothing to do here\r
+               }\r
+\r
+       }\r
+\r
+       private Pool<SUnmarshaller> getPool(Class<?> ... classes) throws JAXBException {\r
+               Pool<SUnmarshaller> mp;\r
+               synchronized(pools) {\r
+                       mp = pools.get(classes);\r
+                       if(mp==null) {\r
+                               pools.put(classes,mp = new Pool<SUnmarshaller>(new Creator(classes)));\r
+                       }\r
+               }               \r
+               return mp;\r
+       }\r
+\r
+       public JAXBumar(Class<?> ... classes) throws JAXBException {\r
+               cls = classes[0];\r
+               mpool = getPool(classes);\r
+               schema = null;\r
+       }\r
+       \r
+       /**\r
+        * Constructs a new JAXBumar with schema validation enabled.\r
+        * \r
+        * @param schema\r
+        * @param theClass\r
+        * @throws JAXBException\r
+        */\r
+       public JAXBumar(Schema schema, Class<?> ... classes) throws JAXBException {\r
+               cls = classes[0];\r
+               mpool = getPool(classes);\r
+               this.schema = schema;\r
+       }\r
+       \r
+       @SuppressWarnings("unchecked")\r
+       public<O> O unmarshal(LogTarget env, Node node) throws JAXBException, APIException {\r
+               Pooled<SUnmarshaller> s = mpool.get(env);\r
+               try {\r
+                       return s.content.get(schema).unmarshal(node,(Class<O>)cls).getValue();\r
+               } finally {\r
+                       s.done();\r
+               }\r
+\r
+       }\r
+       \r
+       @SuppressWarnings("unchecked")\r
+       public<O> O unmarshal(LogTarget env, String xml) throws JAXBException, APIException {\r
+               if(xml==null) throw new JAXBException("Null Input for String unmarshal");\r
+               Pooled<SUnmarshaller> s = mpool.get(env);\r
+               try {\r
+                               return (O)s.content.get(schema).unmarshal(\r
+                                       new StreamSource(new StringReader(xml))\r
+                                       ,(Class<O>)cls).getValue();\r
+               } finally {\r
+                       s.done();\r
+               }\r
+       }\r
+       \r
+       @SuppressWarnings("unchecked")\r
+       public<O> O unmarshal(LogTarget env, File xmlFile) throws JAXBException, APIException {\r
+               Pooled<SUnmarshaller> s = mpool.get(env);\r
+               try {\r
+                       return (O)s.content.get(schema).unmarshal(xmlFile);\r
+               } finally {\r
+                       s.done();\r
+               }\r
+\r
+       }\r
+       \r
+       @SuppressWarnings("unchecked")\r
+       public<O> O unmarshal(LogTarget env,InputStream is) throws JAXBException, APIException {\r
+               Pooled<SUnmarshaller> s = mpool.get(env);\r
+               try {\r
+                       return (O)s.content.get(schema).unmarshal(is);\r
+               } finally {\r
+                       s.done();\r
+               }\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public<O> O unmarshal(LogTarget env, Reader rdr) throws JAXBException, APIException {\r
+               Pooled<SUnmarshaller> s = mpool.get(env);\r
+               try {\r
+                       return (O)s.content.get(schema).unmarshal(rdr);\r
+               } finally {\r
+                       s.done();\r
+               }\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public<O> O unmarshal(LogTarget env, XMLStreamReader xsr) throws JAXBException, APIException {\r
+               Pooled<SUnmarshaller> s = mpool.get(env);\r
+               try {\r
+                       return (O)s.content.get(schema).unmarshal(xsr,(Class<O>)cls).getValue();\r
+               } finally {\r
+                       s.done();\r
+               }\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public<O> O unmarshal(LogTarget env, XMLEventReader xer) throws JAXBException, APIException {\r
+               Pooled<SUnmarshaller> s = mpool.get(env);\r
+               try {\r
+                       return (O)s.content.get(schema).unmarshal(xer,(Class<O>)cls).getValue();\r
+               } finally {\r
+                       s.done();\r
+               }\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public<O> O newInstance() throws InstantiationException, IllegalAccessException{\r
+               return ((Class<O>)cls).newInstance();\r
+       }\r
+}\r
index 65c5a36..ba1b981 100644 (file)
@@ -1,57 +1,57 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.old;
-
-import java.io.InputStream;
-import java.io.Reader;
-
-import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.misc.env.Env;
-
-public interface IOObjectifier<T> extends Objectifier<T> {
-       /**
-        * Marshal to Object T from a Reader, using contents from Env as necessary.<p>
-        * 
-        * 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.<p>
-        * 
-        * 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;
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.old;\r
+\r
+import java.io.InputStream;\r
+import java.io.Reader;\r
+\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.Env;\r
+\r
+public interface IOObjectifier<T> extends Objectifier<T> {\r
+       /**\r
+        * Marshal to Object T from a Reader, using contents from Env as necessary.<p>\r
+        * \r
+        * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark\r
+        * XML time, since this is often a costly process.\r
+        *\r
+        * @param env\r
+        * @param input\r
+        * @return T\r
+        * @throws APIException\r
+        */\r
+       public abstract T objectify(Env env, Reader rdr) throws APIException;\r
+       \r
+       /**\r
+        * Marshal to Object T from an InputStream, using contents from Env as necessary.<p>\r
+        * \r
+        * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark\r
+        * XML time, since this is often a costly process.\r
+        *\r
+        * @param env\r
+        * @param input\r
+        * @return T\r
+        * @throws APIException\r
+        */\r
+       public abstract T objectify(Env env, InputStream is) throws APIException;\r
+\r
+}\r
index c5f57b9..137e401 100644 (file)
@@ -1,77 +1,77 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.old;
-
-import java.io.OutputStream;
-import java.io.Writer;
-
-import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.misc.env.Env;
-
-/**
- * Allow Extended IO interface usage without muddying up the Stringifier Interface
- */
-public interface IOStringifier<T> extends Stringifier<T> {
-       /**
-        * Marshal from an Object T onto a Writer, using contents from Env as necessary.<p>
-        * 
-        * Implementations should use the {@link Env} to call "env.startTime(<string>, 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.<p>
-        * 
-        * 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<T> pretty(boolean pretty);
-
-       /**
-        * Set Generate Fragment
-        * 
-        * @param fragment
-        * @throws APIException
-        */
-       public abstract IOStringifier<T> asFragment(boolean fragment);
-
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.old;\r
+\r
+import java.io.OutputStream;\r
+import java.io.Writer;\r
+\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.Env;\r
+\r
+/**\r
+ * Allow Extended IO interface usage without muddying up the Stringifier Interface\r
+ */\r
+public interface IOStringifier<T> extends Stringifier<T> {\r
+       /**\r
+        * Marshal from an Object T onto a Writer, using contents from Env as necessary.<p>\r
+        * \r
+        * Implementations should use the {@link Env} to call "env.startTime(<string>, Env.XML)" to mark\r
+        * XML time, since this is often a costly process.\r
+        *\r
+        * @param env\r
+        * @param input\r
+        * @return String\r
+        * @throws APIException\r
+        */\r
+       public abstract void stringify(Env env, T input, Writer writer, boolean ... options) throws APIException;\r
+       \r
+       /**\r
+        * Marshal from a String to an Object T, using contents from Env as necessary.<p>\r
+        * \r
+        * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark\r
+        * XML time, since this is often a costly process.\r
+        *\r
+        * @param env\r
+        * @param input\r
+        * @return String\r
+        * @throws APIException\r
+        */\r
+       public abstract void stringify(Env env, T input, OutputStream os, boolean ... options) throws APIException;\r
+\r
+       /**\r
+        * Set Pretty XML, where possible\r
+        * \r
+        * @param pretty\r
+        * @throws APIException\r
+        */\r
+       public abstract IOStringifier<T> pretty(boolean pretty);\r
+\r
+       /**\r
+        * Set Generate Fragment\r
+        * \r
+        * @param fragment\r
+        * @throws APIException\r
+        */\r
+       public abstract IOStringifier<T> asFragment(boolean fragment);\r
+\r
+\r
+}\r
index 6ec72ba..1fd3cda 100644 (file)
@@ -1,60 +1,60 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-/**
- * 
- */
-package org.onap.aaf.misc.env.old;
-
-import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.misc.env.Env;
-import org.onap.aaf.misc.env.LifeCycle;
-
-
-/**
- * <h1>Objectifier</h1>
- * <i>Objectifier</i> abstracts the unmarshaling of an Object from a String, and 
- * the creation of an uninitialized object. 
- */
-public interface Objectifier<T> extends LifeCycle {
-       /**
-        * Marshal to Object T from a String, using contents from Env as necessary.<p>
-        * 
-        * 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;
-
-       
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+/**\r
+ * \r
+ */\r
+package org.onap.aaf.misc.env.old;\r
+\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.Env;\r
+import org.onap.aaf.misc.env.LifeCycle;\r
+\r
+\r
+/**\r
+ * <h1>Objectifier</h1>\r
+ * <i>Objectifier</i> abstracts the unmarshaling of an Object from a String, and \r
+ * the creation of an uninitialized object. \r
+ */\r
+public interface Objectifier<T> extends LifeCycle {\r
+       /**\r
+        * Marshal to Object T from a String, using contents from Env as necessary.<p>\r
+        * \r
+        * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark\r
+        * XML time, since this is often a costly process.\r
+        *\r
+        * @param env\r
+        * @param input\r
+        * @return T\r
+        * @throws APIException\r
+        */\r
+       public abstract T objectify(Env env, String input) throws APIException;\r
+\r
+       /**\r
+        * Create a new object of type T.  This is often more efficiently done with\r
+        * the underlying XML (or other) Library.\r
+        * @return T\r
+        * @throws APIException\r
+        */\r
+       public abstract T newInstance() throws APIException;\r
+\r
+       \r
 }
\ No newline at end of file
index a434261..724e9f4 100644 (file)
@@ -1,47 +1,47 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.old;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-
-import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.misc.env.Data;
-import org.onap.aaf.misc.env.DataFactory;
-import org.onap.aaf.misc.env.Env;
-
-public interface OldDataFactory<T> extends DataFactory<T> {
-       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<T> newData(T type);
-       public abstract Data<T> newDataFromStream(Env env, InputStream input) throws APIException;
-       public abstract Data<T> newDataFromString(String string);
-       
-}
-
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.old;\r
+\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
+import java.io.Reader;\r
+import java.io.Writer;\r
+\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.Data;\r
+import org.onap.aaf.misc.env.DataFactory;\r
+import org.onap.aaf.misc.env.Env;\r
+\r
+public interface OldDataFactory<T> extends DataFactory<T> {\r
+       public abstract String stringify(T type) throws APIException;\r
+       public abstract void stringify(T type, OutputStream os) throws APIException;\r
+       public abstract void stringify(T type, Writer writer) throws APIException;\r
+       public abstract T objectify(InputStream is) throws APIException;\r
+       public abstract T objectify(Reader rdr) throws APIException;\r
+       public abstract T objectify(String text) throws APIException;\r
+       public abstract T newInstance() throws APIException;\r
+       public abstract Data<T> newData(T type);\r
+       public abstract Data<T> newDataFromStream(Env env, InputStream input) throws APIException;\r
+       public abstract Data<T> newDataFromString(String string);\r
+       \r
+}\r
+\r
index 7dcdf34..eaea7f6 100644 (file)
@@ -1,48 +1,48 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.old;
-
-import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.misc.env.Env;
-import org.onap.aaf.misc.env.LifeCycle;
-
-
-/**
- * <h1>Stringifier</h1>
- * <i>Stringifier</i> abstracts the marshaling of a String to an Object
- */
-public interface Stringifier<T> extends LifeCycle {
-       
-       /**
-        * Marshal from a String to an Object T, using contents from Env as necessary.<p>
-        * 
-        * 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;
-       
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.old;\r
+\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.Env;\r
+import org.onap.aaf.misc.env.LifeCycle;\r
+\r
+\r
+/**\r
+ * <h1>Stringifier</h1>\r
+ * <i>Stringifier</i> abstracts the marshaling of a String to an Object\r
+ */\r
+public interface Stringifier<T> extends LifeCycle {\r
+       \r
+       /**\r
+        * Marshal from a String to an Object T, using contents from Env as necessary.<p>\r
+        * \r
+        * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark\r
+        * XML time, since this is often a costly process.\r
+        *\r
+        * @param env\r
+        * @param input\r
+        * @return String\r
+        * @throws APIException\r
+        */\r
+       public abstract String stringify(Env env, T input, boolean ... options) throws APIException;\r
+       \r
 }
\ No newline at end of file
index 74fbef6..ebae19b 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.util;
-
-import java.security.SecureRandom;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.TimeZone;
-import java.util.UUID;
-import java.util.logging.Formatter;
-import java.util.logging.LogRecord;
-
-import javax.xml.datatype.DatatypeConfigurationException;
-import javax.xml.datatype.DatatypeFactory;
-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.
-       */
-        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()));
-       }
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import java.security.SecureRandom;\r
+import java.text.DateFormat;\r
+import java.text.SimpleDateFormat;\r
+import java.util.Date;\r
+import java.util.GregorianCalendar;\r
+import java.util.TimeZone;\r
+import java.util.UUID;\r
+import java.util.logging.Formatter;\r
+import java.util.logging.LogRecord;\r
+\r
+import javax.xml.datatype.DatatypeConfigurationException;\r
+import javax.xml.datatype.DatatypeFactory;\r
+import javax.xml.datatype.XMLGregorianCalendar;\r
+\r
+public class Chrono {\r
+    private static final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L;\r
+\r
+       public final static DateFormat dateFmt, dateOnlyFmt, niceDateFmt, utcFmt,iso8601Fmt;\r
+       // Give general access to XML DataType Factory, since it's pretty common\r
+       public static final DatatypeFactory xmlDatatypeFactory;\r
+       \r
+       static {\r
+               try {\r
+                       xmlDatatypeFactory = DatatypeFactory.newInstance();\r
+               } catch (DatatypeConfigurationException e) {\r
+                       throw new RuntimeException(e);\r
+               }\r
+               dateOnlyFmt = new SimpleDateFormat("yyyy-MM-dd");\r
+               niceDateFmt = new SimpleDateFormat("yyyy/MM/dd HH:mm zzz");\r
+               dateFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");\r
+               utcFmt =  new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");\r
+               iso8601Fmt =  new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");\r
+               utcFmt.setTimeZone(TimeZone.getTimeZone("UTC"));\r
+       }\r
+       \r
+\r
+       public static class Formatter8601 extends Formatter {\r
+\r
+               @Override\r
+               public String format(LogRecord r) {\r
+                       StringBuilder sb = new StringBuilder();\r
+                       sb.append(dateFmt.format(new Date(r.getMillis())));\r
+                       sb.append(' ');\r
+                       sb.append(r.getThreadID());\r
+                       sb.append(' ');\r
+                       sb.append(r.getLevel());\r
+                       sb.append(": ");\r
+                       sb.append(r.getMessage());\r
+                       sb.append('\n');\r
+                       return sb.toString();\r
+               }\r
+               \r
+       }\r
+       \r
+       /**\r
+        * timeStamp\r
+        * \r
+        * Convenience method to setup an XML dateTime (XMLGregorianCalendar) with "now" \r
+        * @return\r
+        */\r
+       public static XMLGregorianCalendar timeStamp() {\r
+               return xmlDatatypeFactory.newXMLGregorianCalendar(new GregorianCalendar());\r
+       }\r
+\r
+       /**\r
+        * timestamp\r
+        * \r
+        * Convenience method to setup an XML dateTime (XMLGregorianCalendar) with passed in Date \r
+        * @param date\r
+        * @return\r
+        */\r
+       public static XMLGregorianCalendar timeStamp(Date date) {\r
+               GregorianCalendar gc = new GregorianCalendar();\r
+               gc.setTime(date);\r
+               return xmlDatatypeFactory.newXMLGregorianCalendar(gc);\r
+       }\r
+\r
+       public static XMLGregorianCalendar timeStamp(GregorianCalendar gc) {\r
+               return xmlDatatypeFactory.newXMLGregorianCalendar(gc);\r
+       }\r
+\r
+       public static String utcStamp() {\r
+               return utcFmt.format(new Date());\r
+       }\r
+\r
+       public static String utcStamp(Date date) {\r
+               if(date==null)return "";\r
+               return utcFmt.format(date);\r
+       }\r
+\r
+       public static String utcStamp(GregorianCalendar gc) {\r
+               if(gc==null)return "";\r
+               return utcFmt.format(gc.getTime());\r
+       }\r
+\r
+       public static String utcStamp(XMLGregorianCalendar xgc) {\r
+               if(xgc==null)return "";\r
+               return utcFmt.format(xgc.toGregorianCalendar().getTime());\r
+       }\r
+\r
+       public static String dateStamp() {\r
+               return dateFmt.format(new Date());\r
+       }\r
+\r
+       public static String dateStamp(GregorianCalendar gc) {\r
+               if(gc == null)return "";\r
+               return dateFmt.format(gc.getTime());\r
+       }\r
+\r
+       public static String dateStamp(Date date) {\r
+               if(date == null)return "";\r
+               return dateFmt.format(date);\r
+       }\r
+\r
+       public static String dateStamp(XMLGregorianCalendar xgc) {\r
+               if(xgc==null)return "";\r
+               return dateFmt.format(xgc.toGregorianCalendar().getTime());\r
+       }\r
+\r
+       /**\r
+        * JAXB compatible dataTime Stamp\r
+        * \r
+        * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it.\r
+        * \r
+        * @return\r
+        */\r
+       public static String dateTime() {\r
+               return dateTime(new GregorianCalendar());\r
+       }\r
+\r
+       /**\r
+        * JAXB compatible dataTime Stamp\r
+        * \r
+        * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it.\r
+        * \r
+        * @return\r
+        */\r
+       public static String dateTime(Date date) {\r
+               GregorianCalendar gc = new GregorianCalendar();\r
+               gc.setTime(date);\r
+               return dateTime(gc);\r
+       }\r
+\r
+       /**\r
+        * JAXB compatible dataTime Stamp\r
+        * \r
+        * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it.\r
+        * \r
+        * @return\r
+        */\r
+       public static String dateTime(GregorianCalendar gc) {\r
+               if(gc == null)return "";\r
+               TimeZone tz = gc.getTimeZone();\r
+               int tz1 = (tz.getRawOffset()+tz.getDSTSavings())/0x8CA0;\r
+               int tz1abs = Math.abs(tz1);\r
+               return String.format("%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d:%02d", \r
+                               gc.get(GregorianCalendar.YEAR),\r
+                               gc.get(GregorianCalendar.MONTH)+1,\r
+                               gc.get(GregorianCalendar.DAY_OF_MONTH),\r
+                               gc.get(GregorianCalendar.HOUR),\r
+                               gc.get(GregorianCalendar.MINUTE),\r
+                               gc.get(GregorianCalendar.SECOND),\r
+                               gc.get(GregorianCalendar.MILLISECOND),\r
+                               tz1==tz1abs?'+':'-',\r
+                               tz1abs/100,\r
+                               ((tz1abs-(tz1abs/100)*100)*6)/10 // Get the "10s", then convert to mins (without losing int place)\r
+                               );\r
+       }\r
+\r
+       /**\r
+        * JAXB compatible dataTime Stamp\r
+        * \r
+        * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it.\r
+        * \r
+        * @return\r
+        */\r
+       public static String dateTime(XMLGregorianCalendar xgc) {\r
+               return xgc==null?"":dateTime(xgc.toGregorianCalendar());\r
+       }\r
+\r
+       public static String dateOnlyStamp() {\r
+               return dateOnlyFmt.format(new Date());\r
+       }\r
+\r
+       public static String dateOnlyStamp(GregorianCalendar gc) {\r
+               return gc == null?"":dateOnlyFmt.format(gc.getTime());\r
+       }\r
+\r
+       public static String dateOnlyStamp(Date date) {\r
+               return date == null?"":dateOnlyFmt.format(date);\r
+       }\r
+\r
+       public static String dateOnlyStamp(XMLGregorianCalendar xgc) {\r
+               return xgc==null?"":dateOnlyFmt.format(xgc.toGregorianCalendar().getTime());\r
+       }\r
+\r
+       public static String niceDateStamp() {\r
+               return niceDateFmt.format(new Date());\r
+       }\r
+\r
+       public static String niceDateStamp(Date date) {\r
+               return date==null?"":niceDateFmt.format(date);\r
+       }\r
+\r
+       public static String niceDateStamp(GregorianCalendar gc) {\r
+               return gc==null?"":niceDateFmt.format(gc.getTime());\r
+       }\r
+\r
+       public static String niceDateStamp(XMLGregorianCalendar xgc) {\r
+               return xgc==null?"":niceDateFmt.format(xgc.toGregorianCalendar().getTime());\r
+       }\r
+\r
+\r
+       //////////////////////  HELPFUL Strings\r
+       public static final String BAD_DIR_CHARS_REGEX = "[/:\\;.]";\r
+       public static final String SPLIT_DIR_REGEX = "/";\r
+\r
+       public static long firstMomentOfDay(long utc) {\r
+               GregorianCalendar begin = new GregorianCalendar();\r
+               begin.setTimeInMillis(utc);\r
+               return firstMomentOfDay(begin).getTimeInMillis();\r
+       }       \r
+       \r
+       public static long lastMomentOfDay(long utc) {\r
+               GregorianCalendar end = new GregorianCalendar();\r
+               end.setTimeInMillis(utc);\r
+               return lastMomentOfDay(end).getTimeInMillis();\r
+       }\r
+\r
+       public static GregorianCalendar firstMomentOfDay(GregorianCalendar begin) {\r
+               if(begin==null)begin = new GregorianCalendar();\r
+               begin.set(GregorianCalendar.HOUR, 0);\r
+               begin.set(GregorianCalendar.AM_PM, GregorianCalendar.AM);\r
+               begin.set(GregorianCalendar.MINUTE, 0);\r
+               begin.set(GregorianCalendar.SECOND, 0);\r
+               begin.set(GregorianCalendar.MILLISECOND, 0);\r
+               return begin;\r
+       }       \r
+\r
+       public static GregorianCalendar lastMomentOfDay(GregorianCalendar end) {\r
+               if(end==null)end = new GregorianCalendar();\r
+               end.set(GregorianCalendar.HOUR, 11);\r
+               end.set(GregorianCalendar.MINUTE, 59);\r
+               end.set(GregorianCalendar.SECOND, 59);\r
+               end.set(GregorianCalendar.MILLISECOND, 999);\r
+               end.set(GregorianCalendar.AM_PM, GregorianCalendar.PM);\r
+               return end;\r
+       }\r
+\r
+       // UUID needs to be converted from UUID Epoch\r
+       public static final Date uuidToDate(UUID id) {\r
+               return new Date((id.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH)/10000);\r
+       }\r
+\r
+       public static final long uuidToUnix(UUID id) {\r
+               return (id.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH)/10000;\r
+       }\r
+\r
+       public static float millisFromNanos(long start, long end) {\r
+               return (end - start) / 1000000f;\r
+       }\r
+\r
+\r
+       private static long sequence = new SecureRandom().nextInt();\r
+       private static synchronized long sequence() {\r
+               return ++sequence;\r
+       }\r
+       \r
+       public static final UUID dateToUUID(Date origTime) {\r
+               return dateToUUID(origTime.getTime());\r
+       }\r
+       \r
+       public static final UUID dateToUUID(long origTime) {\r
+       /*\r
+        * From Cassandra : http://wiki.apache.org/cassandra/FAQ\r
+         Magic number obtained from #cassandra's thobbs, who\r
+         claims to have stolen it from a Python library.\r
+       */\r
+        long time = origTime * 10000 + NUM_100NS_INTERVALS_SINCE_UUID_EPOCH;\r
+        long timeLow = time &       0xffffffffL;\r
+        long timeMid = time &   0xffff00000000L;\r
+        long timeHi = time & 0xfff000000000000L;\r
+        long upperLong = (timeLow << 32) | (timeMid >> 16) | (1 << 12) | (timeHi >> 48) ;\r
+        return new java.util.UUID(upperLong, (0xC000000000000000L | sequence()));\r
+       }\r
+\r
+}\r
index 0bce473..9c4c431 100644 (file)
@@ -1,97 +1,97 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.util;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-public class DoubleOutputStream extends OutputStream {
-    private OutputStream[] oss;
-       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};
-    }
-
-    /**
-     * Write a single character.
-     * @throws IOException 
-     */
-    @Override
-    public void write(int c) throws IOException {
-       for(OutputStream os : oss) {
-               os.write(c);
-       }
-    }
-
-    /**
-     * Write a portion of an array of characters.
-     *
-     * @param  bbuf  Array of characters
-     * @param  off   Offset from which to start writing characters
-     * @param  len   Number of characters to write
-     * @throws IOException 
-     */
-    @Override
-    public void write(byte bbuf[], int off, int len) throws IOException {
-       for(OutputStream os : oss) {
-               os.write(bbuf,off,len);
-       }
-    }
-
-    @Override
-       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<oss.length;++i) {
-                       if(close[i]) {
-                               oss[i].close();
-                       }
-       }
-       }
-
-       /* (non-Javadoc)
-        * @see java.io.OutputStream#flush()
-        */
-       @Override
-       public void flush() throws IOException {
-       for(OutputStream os : oss) {
-               os.flush();
-       }
-       }
-
-
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+\r
+public class DoubleOutputStream extends OutputStream {\r
+    private OutputStream[] oss;\r
+       private boolean[] close;\r
+\r
+       /**\r
+     * Create a Double Stream Writer\r
+     * Some Streams should not be closed by this object (i.e. System.out), therefore, mark them with booleans\r
+     */\r
+    public DoubleOutputStream(OutputStream a, boolean closeA, OutputStream b, boolean closeB) {\r
+               oss = new OutputStream[] {a,b};\r
+               close = new boolean[] {closeA,closeB};\r
+    }\r
+\r
+    /**\r
+     * Write a single character.\r
+     * @throws IOException \r
+     */\r
+    @Override\r
+    public void write(int c) throws IOException {\r
+       for(OutputStream os : oss) {\r
+               os.write(c);\r
+       }\r
+    }\r
+\r
+    /**\r
+     * Write a portion of an array of characters.\r
+     *\r
+     * @param  bbuf  Array of characters\r
+     * @param  off   Offset from which to start writing characters\r
+     * @param  len   Number of characters to write\r
+     * @throws IOException \r
+     */\r
+    @Override\r
+    public void write(byte bbuf[], int off, int len) throws IOException {\r
+       for(OutputStream os : oss) {\r
+               os.write(bbuf,off,len);\r
+       }\r
+    }\r
+\r
+    @Override\r
+       public void write(byte[] b) throws IOException {\r
+       for(OutputStream os : oss) {\r
+               os.write(b);\r
+       }\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see java.io.OutputStream#close()\r
+        */\r
+       @Override\r
+       public void close() throws IOException {\r
+               for(int i=0;i<oss.length;++i) {\r
+                       if(close[i]) {\r
+                               oss[i].close();\r
+                       }\r
+       }\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see java.io.OutputStream#flush()\r
+        */\r
+       @Override\r
+       public void flush() throws IOException {\r
+       for(OutputStream os : oss) {\r
+               os.flush();\r
+       }\r
+       }\r
+\r
+\r
+\r
+}\r
index d6ac850..3e02c00 100644 (file)
@@ -1,57 +1,57 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.util;
-
-import java.util.regex.Pattern;
-
-public class IPValidator {
-       private static final Pattern ipv4_p = Pattern.compile(
-                       "^((\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.){3}\\2$"
-                       );
-
-       private static final Pattern ipv6_p = Pattern.compile(
-                       "^(([0-9a-fA-F]{0,4})([:|.])){2,7}([0-9a-fA-F]{0,4})$"
-                       );
-       
-       private static final Pattern doubleColon = Pattern.compile(
-                       ".*::.*::.*"
-                       );
-
-       private static final Pattern tooManyColon = Pattern.compile(
-                       "(.*:){1,7}"
-                       );
-
-       
-       public static boolean ipv4(String str) {
-               return ipv4_p.matcher(str).matches();
-       }
-       
-       public static boolean ipv6(String str) {
-               return ipv6_p.matcher(str).matches() &&
-                          !doubleColon.matcher(str).matches() &&
-                          !tooManyColon.matcher(str).matches();
-       }
-       
-       public static boolean ip (String str) {
-               return ipv4_p.matcher(str).matches() || ipv6(str);
-       }
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import java.util.regex.Pattern;\r
+\r
+public class IPValidator {\r
+       private static final Pattern ipv4_p = Pattern.compile(\r
+                       "^((\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.){3}\\2$"\r
+                       );\r
+\r
+       private static final Pattern ipv6_p = Pattern.compile(\r
+                       "^(([0-9a-fA-F]{0,4})([:|.])){2,7}([0-9a-fA-F]{0,4})$"\r
+                       );\r
+       \r
+       private static final Pattern doubleColon = Pattern.compile(\r
+                       ".*::.*::.*"\r
+                       );\r
+\r
+       private static final Pattern tooManyColon = Pattern.compile(\r
+                       "(.*:){1,7}"\r
+                       );\r
+\r
+       \r
+       public static boolean ipv4(String str) {\r
+               return ipv4_p.matcher(str).matches();\r
+       }\r
+       \r
+       public static boolean ipv6(String str) {\r
+               return ipv6_p.matcher(str).matches() &&\r
+                          !doubleColon.matcher(str).matches() &&\r
+                          !tooManyColon.matcher(str).matches();\r
+       }\r
+       \r
+       public static boolean ip (String str) {\r
+               return ipv4_p.matcher(str).matches() || ipv6(str);\r
+       }\r
+}\r
index 17cbff3..77ee267 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.util;
-
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.Writer;
-
-/**
- * @author Jonathan
- * 
- *         Catch \n and indent according to current indent levels of JavaGen
- */
-public class IndentPrintWriter extends PrintWriter {
-       public static int INDENT = 2;
-       private boolean addIndent;
-       private int indent;
-       private int col;
-
-       public IndentPrintWriter(Writer out) {
-               super(out);
-               addIndent = false;
-               indent = col = 0;
-       }
-       
-       public IndentPrintWriter(OutputStream out) {
-               super(out);
-               addIndent = false;
-               indent = col = 0;
-       }
-
-
-    public void write(String str) {
-       int len = str.length();
-               for(int i=0;i<len;++i) {
-                       write((int)str.charAt(i));
-               }
-    }
-    
-    public void println() {
-       write((int)'\n');
-    }
-       public void write(String str, int off, int len)  {
-               len = Math.min(str.length(),off+len);
-               for(int i=off;i<len;++i) {
-                       write((int)str.charAt(i));
-               }
-       }
-       public void write(int b) {
-               if (b == '\n') {
-                       addIndent = true;
-                       col = 0;
-               } else if (addIndent) {
-                       addIndent = false;
-                       toIndent();
-               } else {
-                       ++col;
-               }
-               super.write(b);
-       }
-
-       @Override
-       public void write(char[] buf, int off, int len) {
-               for (int i = 0; i < len; ++i)
-                       write(buf[i] + off);
-       }
-
-       public void setIndent(int size) {
-               indent = size;
-       }
-
-       public void inc() {
-               ++indent;
-       }
-       
-       public void dec() {
-               --indent;
-       }
-
-       public void toCol(int idx) {
-               while(idx>col++)super.write((int)' ');
-       }
-
-       public int getIndent() {
-               return indent;
-       }
-
-       public void toIndent() {
-               int end = indent * INDENT;
-               for (int i = 0; i < end; ++i) {
-                       super.write((int) ' ');
-               }
-               col = end;
-       }
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import java.io.OutputStream;\r
+import java.io.PrintWriter;\r
+import java.io.Writer;\r
+\r
+/**\r
+ * @author Jonathan\r
+ * \r
+ *         Catch \n and indent according to current indent levels of JavaGen\r
+ */\r
+public class IndentPrintWriter extends PrintWriter {\r
+       public static int INDENT = 2;\r
+       private boolean addIndent;\r
+       private int indent;\r
+       private int col;\r
+\r
+       public IndentPrintWriter(Writer out) {\r
+               super(out);\r
+               addIndent = false;\r
+               indent = col = 0;\r
+       }\r
+       \r
+       public IndentPrintWriter(OutputStream out) {\r
+               super(out);\r
+               addIndent = false;\r
+               indent = col = 0;\r
+       }\r
+\r
+\r
+    public void write(String str) {\r
+       int len = str.length();\r
+               for(int i=0;i<len;++i) {\r
+                       write((int)str.charAt(i));\r
+               }\r
+    }\r
+    \r
+    public void println() {\r
+       write((int)'\n');\r
+    }\r
+       public void write(String str, int off, int len)  {\r
+               len = Math.min(str.length(),off+len);\r
+               for(int i=off;i<len;++i) {\r
+                       write((int)str.charAt(i));\r
+               }\r
+       }\r
+       public void write(int b) {\r
+               if (b == '\n') {\r
+                       addIndent = true;\r
+                       col = 0;\r
+               } else if (addIndent) {\r
+                       addIndent = false;\r
+                       toIndent();\r
+               } else {\r
+                       ++col;\r
+               }\r
+               super.write(b);\r
+       }\r
+\r
+       @Override\r
+       public void write(char[] buf, int off, int len) {\r
+               for (int i = 0; i < len; ++i)\r
+                       write(buf[i] + off);\r
+       }\r
+\r
+       public void setIndent(int size) {\r
+               indent = size;\r
+       }\r
+\r
+       public void inc() {\r
+               ++indent;\r
+       }\r
+       \r
+       public void dec() {\r
+               --indent;\r
+       }\r
+\r
+       public void toCol(int idx) {\r
+               while(idx>col++)super.write((int)' ');\r
+       }\r
+\r
+       public int getIndent() {\r
+               return indent;\r
+       }\r
+\r
+       public void toIndent() {\r
+               int end = indent * INDENT;\r
+               for (int i = 0; i < end; ++i) {\r
+                       super.write((int) ' ');\r
+               }\r
+               col = end;\r
+       }\r
+}\r
index cd11dcb..1694a01 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-/*
- * Pool
- * 
- * Author: Jonathan
- * 5/27/2011
- */
-package org.onap.aaf.misc.env.util;
-
-import java.util.LinkedList;
-
-import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.misc.env.LogTarget;
-
-/**
- * This Class pools on an As-Needed-Basis any particular kind of class, which is
- * quite suitable for expensive operations.
- * 
- * The user calls "get" on a Pool, and if a waiting resource (T) is available,
- * it will be returned. Otherwise, one will be created with the "Creator" class
- * (must be defined for (T)).
- * 
- * You can Prime the instances to avoid huge startup costs
- * 
- * The returned "Pooled" object simply has to call "done()" and the object is
- * returned to the pool. If the developer does not return the object, a memory
- * leak does not occur. There are no references to the object once "get" is
- * called. However, the developer who does not return the object when done
- * obviates the point of the pool, as new Objects are created in place of the
- * Object not returned when another call to "get" is made.
- * 
- * There is a cushion of extra objects, currently defaulted to MAX_RANGE. If the
- * items returned become higher than the MAX_RANGE, the object is allowed to go
- * out of scope, and be cleaned up. the default can be changed on a per-pool
- * basis.
- * 
- * 
- * @author Jonathan
- * 
- * @param <T>
- */
-public class Pool<T> {
-       /**
-        * 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<Pooled<T>> list;
-
-       /**
-        * 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;
-
-       /**
-        * 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<T> creator;
-
-       /**
-        * Create a new Pool, given the implementation of Creator<T>, which must be
-        * able to create/destroy T objects at will.
-        * 
-        * @param creator
-        */
-       public Pool(Creator<T> creator) {
-               count = spares = 0;
-               this.creator = creator;
-               list = new LinkedList<Pooled<T>>();
-       }
-
-       /**
-        * 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<T> pt = new Pooled<T>(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<T> 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<T>" 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<T> get() throws APIException {
-               Pooled<T> 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<T>(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<T>" 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<T> get(LogTarget lt) throws APIException {
-               Pooled<T> 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<T>(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> 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<T> class.
-        * 
-        * The Pooled<T> 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<T>
-       private boolean offer(LogTarget lt, Pooled<T> 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 <T>
-        */
-       public interface Creator<T> {
-               public T create() throws APIException;
-
-               public void destroy(T t);
-
-               public boolean isValid(T t);
-
-               public void reuse(T t);
-       }
-
-       /**
-        * The "Pooled<T>" 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 <T>
-        */
-       public static class Pooled<T> {
-               public final T content;
-               private Pool<T> pool;
-               protected LogTarget logTarget;
-
-               /**
-                * Create the Wrapping Object Pooled<T>.
-                * 
-                * @param t
-                * @param pool
-                * @param logTarget
-                */
-               public Pooled(T t, Pool<T> 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<T> 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;
-               }
-
-               /**
-                * 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;
-       }
-
-       /**
-        * 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);
-       }
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+/*\r
+ * Pool\r
+ * \r
+ * Author: Jonathan\r
+ * 5/27/2011\r
+ */\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import java.util.LinkedList;\r
+\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.LogTarget;\r
+\r
+/**\r
+ * This Class pools on an As-Needed-Basis any particular kind of class, which is\r
+ * quite suitable for expensive operations.\r
+ * \r
+ * The user calls "get" on a Pool, and if a waiting resource (T) is available,\r
+ * it will be returned. Otherwise, one will be created with the "Creator" class\r
+ * (must be defined for (T)).\r
+ * \r
+ * You can Prime the instances to avoid huge startup costs\r
+ * \r
+ * The returned "Pooled" object simply has to call "done()" and the object is\r
+ * returned to the pool. If the developer does not return the object, a memory\r
+ * leak does not occur. There are no references to the object once "get" is\r
+ * called. However, the developer who does not return the object when done\r
+ * obviates the point of the pool, as new Objects are created in place of the\r
+ * Object not returned when another call to "get" is made.\r
+ * \r
+ * There is a cushion of extra objects, currently defaulted to MAX_RANGE. If the\r
+ * items returned become higher than the MAX_RANGE, the object is allowed to go\r
+ * out of scope, and be cleaned up. the default can be changed on a per-pool\r
+ * basis.\r
+ * \r
+ * \r
+ * @author Jonathan\r
+ * \r
+ * @param <T>\r
+ */\r
+public class Pool<T> {\r
+       /**\r
+        * This is a constant which specified the default maximum number of unused\r
+        * objects to be held at any given time.\r
+        */\r
+       private static final int MAX_RANGE = 6; // safety\r
+\r
+       /**\r
+        * only Simple List needed.\r
+        * \r
+        * NOTE TO MAINTAINERS: THIS OBJECT DOES IT'S OWN SYNCHRONIZATION. All\r
+        * changes that touch list must account for correctly synchronizing list.\r
+        */\r
+       private LinkedList<Pooled<T>> list;\r
+\r
+       /**\r
+        * keep track of how many elements exist, to avoid asking list.\r
+        */\r
+       private int count;\r
+\r
+       /**\r
+        * Spares are those Object that are primed and ready to go.\r
+        */\r
+       private int spares;\r
+\r
+       /**\r
+        * Actual MAX number of spares allowed to hang around. Can be set to\r
+        * something besides the default MAX_RANGE.\r
+        */\r
+       private int max_range = MAX_RANGE;\r
+\r
+       /**\r
+        * The Creator for this particular pool. It must work for type T.\r
+        */\r
+       private Creator<T> creator;\r
+\r
+       /**\r
+        * Create a new Pool, given the implementation of Creator<T>, which must be\r
+        * able to create/destroy T objects at will.\r
+        * \r
+        * @param creator\r
+        */\r
+       public Pool(Creator<T> creator) {\r
+               count = spares = 0;\r
+               this.creator = creator;\r
+               list = new LinkedList<Pooled<T>>();\r
+       }\r
+\r
+       /**\r
+        * Preallocate a certain number of T Objects. Useful for services so that\r
+        * the first transactions don't get hit with all the Object creation costs\r
+        * \r
+        * @param lt\r
+        * @param prime\r
+        * @throws APIException\r
+        */\r
+       public void prime(LogTarget lt, int prime) throws APIException {\r
+               for (int i = 0; i < prime; ++i) {\r
+                       Pooled<T> pt = new Pooled<T>(creator.create(), this, lt);\r
+                       synchronized (list) {\r
+                               list.addFirst(pt);\r
+                               ++count;\r
+                       }\r
+               }\r
+\r
+       }\r
+\r
+       /**\r
+        * Destroy and remove all remaining objects. This is valuable for closing\r
+        * down all Allocated objects cleanly for exiting. It is also a good method\r
+        * for removing objects when, for instance, all Objects are invalid because\r
+        * of broken connections, etc.\r
+        */\r
+       public void drain() {\r
+               synchronized (list) {\r
+                       for (int i = 0; i < list.size(); ++i) {\r
+                               Pooled<T> pt = list.remove();\r
+                               creator.destroy(pt.content);\r
+                               pt.logTarget.log("Pool drained ", creator.toString());\r
+                       }\r
+                       count = spares = 0;\r
+               }\r
+\r
+       }\r
+\r
+       /**\r
+        * This is the essential function for Pool. Get an Object "T" inside a\r
+        * "Pooled<T>" object. If there is a spare Object, then use it. If not, then\r
+        * create and pass back.\r
+        * \r
+        * This one uses a Null LogTarget\r
+        * \r
+        * IMPORTANT: When the use of this object is done (and the object is still\r
+        * in a valid state), then "done()" should be called immediately to allow\r
+        * the object to be reused. That is the point of the Pool...\r
+        * \r
+        * If the Object is in an invalid state, then "toss()" should be used so the\r
+        * Pool doesn't pass on invalid objects to others.\r
+        * \r
+        * @param lt\r
+        * @return\r
+        * @throws APIException\r
+        */\r
+       public Pooled<T> get() throws APIException {\r
+               Pooled<T> pt;\r
+               synchronized (list) {\r
+                       if (list.isEmpty()) {\r
+                               pt = null;\r
+                       } else {\r
+                               pt = list.removeLast();\r
+                               --count;\r
+                               creator.reuse(pt.content);\r
+                       }\r
+               }\r
+               if (pt == null) {\r
+                       if (spares < max_range)\r
+                               ++spares;\r
+                       pt = new Pooled<T>(creator.create(), this, LogTarget.NULL);\r
+               } else {\r
+                       if (spares > 1)\r
+                               --spares;\r
+               }\r
+               return pt;\r
+       }\r
+\r
+       /**\r
+        * This is the essential function for Pool. Get an Object "T" inside a\r
+        * "Pooled<T>" object. If there is a spare Object, then use it. If not, then\r
+        * create and pass back.\r
+        * \r
+        * If you don't have access to a LogTarget from Env, use LogTarget.NULL\r
+        * \r
+        * IMPORTANT: When the use of this object is done (and the object is still\r
+        * in a valid state), then "done()" should be called immediately to allow\r
+        * the object to be reused. That is the point of the Pool...\r
+        * \r
+        * If the Object is in an invalid state, then "toss()" should be used so the\r
+        * Pool doesn't pass on invalid objects to others.\r
+        * \r
+        * @param lt\r
+        * @return\r
+        * @throws APIException\r
+        */\r
+       public Pooled<T> get(LogTarget lt) throws APIException {\r
+               Pooled<T> pt;\r
+               synchronized (list) {\r
+                       if (list.isEmpty()) {\r
+                               pt = null;\r
+                       } else {\r
+                               pt = list.remove();\r
+                               --count;\r
+                               creator.reuse(pt.content);\r
+                       }\r
+               }\r
+               if (pt == null) {\r
+                       if (spares < max_range)\r
+                               ++spares;\r
+                       pt = new Pooled<T>(creator.create(), this, lt);\r
+                       lt.log("Pool created ", creator.toString());\r
+               } else {\r
+                       if (spares > 1)\r
+                               --spares;\r
+               }\r
+               return pt;\r
+       }\r
+\r
+       /**\r
+        * This function will validate whether the Objects are still in a usable\r
+        * state. If not, they are tossed from the Pool. This is valuable to have\r
+        * when Remote Connections go down, and there is a question on whether the\r
+        * Pooled Objects are still functional.\r
+        * \r
+        * @return\r
+        */\r
+       public boolean validate() {\r
+               boolean rv = true;\r
+               synchronized (list) {\r
+                       for (Pooled<T> t : list) {\r
+                               if (!creator.isValid(t.content)) {\r
+                                       rv = false;\r
+                                       t.toss();\r
+                                       list.remove(t);\r
+                               }\r
+                       }\r
+               }\r
+               return rv;\r
+       }\r
+\r
+       /**\r
+        * This is an internal method, used only by the Internal Pooled<T> class.\r
+        * \r
+        * The Pooled<T> class "offers" it's Object back after use. It is an\r
+        * "offer", because Pool will simply destroy and remove the object if it has\r
+        * more than enough spares.\r
+        * \r
+        * @param lt\r
+        * @param used\r
+        * @return\r
+        */\r
+       // Used only by Pooled<T>\r
+       private boolean offer(LogTarget lt, Pooled<T> used) {\r
+               if (count < spares) {\r
+                       synchronized (list) {\r
+                               list.addFirst(used);\r
+                               ++count;\r
+                       }\r
+                       lt.log("Pool recovered ", creator.toString());\r
+               } else {\r
+                       lt.log("Pool destroyed ", creator.toString());\r
+                       creator.destroy(used.content);\r
+               }\r
+               return false;\r
+       }\r
+\r
+       /**\r
+        * The Creator Interface give the Pool the ability to Create, Destroy and\r
+        * Validate the Objects it is maintaining. Thus, it is a specially written\r
+        * Implementation for each type.\r
+        * \r
+        * @author Jonathan\r
+        * \r
+        * @param <T>\r
+        */\r
+       public interface Creator<T> {\r
+               public T create() throws APIException;\r
+\r
+               public void destroy(T t);\r
+\r
+               public boolean isValid(T t);\r
+\r
+               public void reuse(T t);\r
+       }\r
+\r
+       /**\r
+        * The "Pooled<T>" class is the transient class that wraps the actual Object\r
+        * T for API use/ It gives the ability to return ("done()", or "toss()") the\r
+        * Object to the Pool when processing is finished.\r
+        * \r
+        * For Safety, i.e. to avoid memory leaks and invalid Object States, there\r
+        * is a "finalize" method. It is strictly for when coder forgets to return\r
+        * the object, or perhaps hasn't covered the case during Exceptions or\r
+        * Runtime Exceptions with finally (preferred). This should not be\r
+        * considered normal procedure, as finalize() is called at an undetermined\r
+        * time during garbage collection, and is thus rather useless for a Pool.\r
+        * However, we don't want Coding Mistakes to put the whole program in an\r
+        * invalid state, so if something happened such that "done()" or "toss()"\r
+        * were not called, the resource is still cleaned up as well as possible.\r
+        * \r
+        * @author Jonathan\r
+        * \r
+        * @param <T>\r
+        */\r
+       public static class Pooled<T> {\r
+               public final T content;\r
+               private Pool<T> pool;\r
+               protected LogTarget logTarget;\r
+\r
+               /**\r
+                * Create the Wrapping Object Pooled<T>.\r
+                * \r
+                * @param t\r
+                * @param pool\r
+                * @param logTarget\r
+                */\r
+               public Pooled(T t, Pool<T> pool, LogTarget logTarget) {\r
+                       content = t;\r
+                       this.pool = pool;\r
+                       this.logTarget = logTarget;\r
+               }\r
+\r
+               /**\r
+                * This is the key API for the Pool, as calling "done()" offers this\r
+                * object back to the Pool for reuse.\r
+                * \r
+                * Do not use the Pooled<T> object again after calling "done()".\r
+                */\r
+               public void done() {\r
+                       if (pool != null) {\r
+                               pool.offer(logTarget, this);\r
+                       }\r
+               }\r
+\r
+               /**\r
+                * The user of the Object may discover that the Object t is no longer in\r
+                * a valid state. Don't put Garbage back in the Refrigerator... Toss it,\r
+                * if it's no longer valid.\r
+                * \r
+                * toss() is also used for draining the Pool, etc.\r
+                * \r
+                * toss() will attempt to destroy the Object by using the Creator\r
+                * Interface.\r
+                * \r
+                */\r
+               public void toss() {\r
+                       if (pool != null) {\r
+                               pool.creator.destroy(content);\r
+                       }\r
+                       // Don't allow finalize to put it back in.\r
+                       pool = null;\r
+               }\r
+\r
+               /**\r
+                * Just in case someone neglected to offer back object... Do not rely on\r
+                * this, as there is no specific time when finalize is called, which\r
+                * rather defeats the purpose of a Pool.\r
+                */\r
+               @Override\r
+               protected void finalize() throws Throwable {\r
+                       if (pool != null) {\r
+                               done();\r
+                               pool = null;\r
+                       }\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Get the maximum number of spare objects allowed at any moment\r
+        * \r
+        * @return\r
+        */\r
+       public int getMaxRange() {\r
+               return max_range;\r
+       }\r
+\r
+       /**\r
+        * Set a Max Range for numbers of spare objects waiting to be used.\r
+        * \r
+        * No negative numbers are allowed\r
+        * \r
+        * @return\r
+        */\r
+       public void setMaxRange(int max_range) {\r
+               // Do not allow negative numbers\r
+               this.max_range = Math.max(0, max_range);\r
+       }\r
+\r
+}\r
index 5615339..56cd54e 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.util;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.misc.env.Creatable;
-import org.onap.aaf.misc.env.Env;
-import org.onap.aaf.misc.env.LifeCycle;
-
-
-/**
- * <h1>RefreshableThreadObject</h1>
- * This is a ThreadLocal like implementation, but it responds to 
- * the {@link LifeCycle} mechanism for configuration refreshes, and 
- * implements {@link Creatable} (for use in destroy, etc).<p>
- * 
- * In addition to the Thread instance semantics, it compares when the object
- * was created versus the last "refresh(env)" call when getting, for the
- * thread, and if necessary to replace the created object, destroying the 
- * previous.<p>
- * 
- * In most cases, it's better to use the new "Pool" mechanism, as it deals with 
- * gaining and returning resources on an as needed basis.  This, however, remains
- * in the cases where specific Objects need to be retained to specific Threads.<p>
- * 
- * There is no way to do this kind of specialized behavior in ThreadLocal.
- * 
- * @author Jonathan
- *
- * @param <T>
- */
-public class RefreshableThreadObject<T extends Creatable<T>> {
-       private Map<Thread,T> objs;
-       private long refreshed;
-       private Constructor<T> cnst;
-       
-       /**
-        * The passed in class <b>must</b> implement the constructor
-        * <pre>
-        *   public MyClass(Env env) {
-        *     ...
-        *   }
-        * </pre>
-        * @param clss
-        * @throws APIException
-        */
-       public RefreshableThreadObject(Class<T> clss) throws APIException {
-               objs = new ConcurrentHashMap<Thread,T>();
-               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);
-       }
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import java.lang.reflect.Constructor;\r
+import java.lang.reflect.InvocationTargetException;\r
+import java.util.Map;\r
+import java.util.concurrent.ConcurrentHashMap;\r
+\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.Creatable;\r
+import org.onap.aaf.misc.env.Env;\r
+import org.onap.aaf.misc.env.LifeCycle;\r
+\r
+\r
+/**\r
+ * <h1>RefreshableThreadObject</h1>\r
+ * This is a ThreadLocal like implementation, but it responds to \r
+ * the {@link LifeCycle} mechanism for configuration refreshes, and \r
+ * implements {@link Creatable} (for use in destroy, etc).<p>\r
+ * \r
+ * In addition to the Thread instance semantics, it compares when the object\r
+ * was created versus the last "refresh(env)" call when getting, for the\r
+ * thread, and if necessary to replace the created object, destroying the \r
+ * previous.<p>\r
+ * \r
+ * In most cases, it's better to use the new "Pool" mechanism, as it deals with \r
+ * gaining and returning resources on an as needed basis.  This, however, remains\r
+ * in the cases where specific Objects need to be retained to specific Threads.<p>\r
+ * \r
+ * There is no way to do this kind of specialized behavior in ThreadLocal.\r
+ * \r
+ * @author Jonathan\r
+ *\r
+ * @param <T>\r
+ */\r
+public class RefreshableThreadObject<T extends Creatable<T>> {\r
+       private Map<Thread,T> objs;\r
+       private long refreshed;\r
+       private Constructor<T> cnst;\r
+       \r
+       /**\r
+        * The passed in class <b>must</b> implement the constructor\r
+        * <pre>\r
+        *   public MyClass(Env env) {\r
+        *     ...\r
+        *   }\r
+        * </pre>\r
+        * @param clss\r
+        * @throws APIException\r
+        */\r
+       public RefreshableThreadObject(Class<T> clss) throws APIException {\r
+               objs = new ConcurrentHashMap<Thread,T>();\r
+               try {\r
+                       cnst = clss.getConstructor(new Class[]{Env.class} );\r
+               } catch (Exception e) {\r
+                       throw new APIException(e);\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Get the "T" class from the current thread\r
+        * \r
+        * @param env\r
+        * @return T\r
+        * @throws APIException\r
+        */\r
+       public T get(Env env) throws APIException {\r
+               Thread t = Thread.currentThread();\r
+               T obj = objs.get(t);\r
+               if(obj==null || refreshed>obj.created()) {\r
+                       try {\r
+                               obj = cnst.newInstance(new Object[]{env});\r
+                       } catch (InvocationTargetException e) {\r
+                               throw new APIException(e.getTargetException());\r
+                       } catch (Exception e) {\r
+                               throw new APIException(e);\r
+                       }\r
+                       T destroyMe = objs.put(t,obj);\r
+                       if(destroyMe!=null) {\r
+                               destroyMe.destroy(env);\r
+                       }\r
+               } \r
+               return obj;\r
+       }\r
+       \r
+       /**\r
+        * Mark the timestamp of refreshed.\r
+        * \r
+        * @param env\r
+        */\r
+       public void refresh(Env env) {\r
+               refreshed = System.currentTimeMillis();\r
+       }\r
+       \r
+       /**\r
+        * Remove the object from the Thread instances\r
+        * @param env\r
+        */\r
+       public void remove(Env env) {\r
+               T obj = objs.remove(Thread.currentThread());\r
+               if(obj!=null)\r
+                       obj.destroy(env);\r
+       }\r
+}\r
index 79a7403..57e6009 100644 (file)
@@ -1,89 +1,89 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.util;
-
-/**
- * Split by Char, optional Trim
- * 
- * Note: I read the String split and Pattern split code, and we can do this more efficiently for a single Character
- * 
- * Jonathan 8/20/2015
- */
-
-public class Split {
-         public static String[] split(char c, String value) {
-                 // 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) {
-                 // 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) {
-                 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<size;idx=value.indexOf(c,idx)) {
-                                 rv[++count]=value.substring(last,idx).trim();
-                                 last = ++idx;
-                         }
-                         rv[++count]=value.substring(last).trim();
-                 }
-                 return rv;
-         }
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.util;\r
+\r
+/**\r
+ * Split by Char, optional Trim\r
+ * \r
+ * Note: I read the String split and Pattern split code, and we can do this more efficiently for a single Character\r
+ * \r
+ * Jonathan 8/20/2015\r
+ */\r
+\r
+public class Split {\r
+         public static String[] split(char c, String value) {\r
+                 // Count items to preallocate Array (memory alloc is more expensive than counting twice)\r
+                 int count,idx;\r
+                 for(count=1,idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,++idx),++count);\r
+                 String[] rv = new String[count];\r
+                 if(count==1) {\r
+                         rv[0]=value;\r
+                 } else {\r
+                         int last=0;\r
+                         count=-1;\r
+                         for(idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,idx)) {\r
+                                 rv[++count]=value.substring(last,idx);\r
+                                 last = ++idx;\r
+                         }\r
+                         rv[++count]=value.substring(last);\r
+                 }\r
+                 return rv;\r
+         }\r
+\r
+         public static String[] splitTrim(char c, String value) {\r
+                 // Count items to preallocate Array (memory alloc is more expensive than counting twice)\r
+                 int count,idx;\r
+                 for(count=1,idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,++idx),++count);\r
+                 String[] rv = new String[count];\r
+                 if(count==1) {\r
+                         rv[0]=value.trim();\r
+                 } else {\r
+                         int last=0;\r
+                         count=-1;\r
+                         for(idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,idx)) {\r
+                                 rv[++count]=value.substring(last,idx).trim();\r
+                                 last = ++idx;\r
+                         }\r
+                         rv[++count]=value.substring(last).trim();\r
+                 }\r
+                 return rv;\r
+         }\r
+\r
+         public static String[] splitTrim(char c, String value, int size) {\r
+                 int idx;\r
+                 String[] rv = new String[size];\r
+                 if(size==1) {\r
+                         rv[0]=value.trim();\r
+                 } else {\r
+                         int last=0;\r
+                         int count=-1;\r
+                         size-=2;\r
+                         for(idx=value.indexOf(c);idx>=0 && count<size;idx=value.indexOf(c,idx)) {\r
+                                 rv[++count]=value.substring(last,idx).trim();\r
+                                 last = ++idx;\r
+                         }\r
+                         rv[++count]=value.substring(last).trim();\r
+                 }\r
+                 return rv;\r
+         }\r
+\r
+}\r
index c2a1f91..f088506 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.util;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-public class StringBuilderOutputStream extends OutputStream {
-       private StringBuilder buf;
-
-
-    /**
-     * Create a new string writer using the default initial string-buffer
-     * size.
-     */
-    public StringBuilderOutputStream() {
-       buf = new StringBuilder();
-    }
-
-    /**
-     * Create a new string writer using a passed in StringBuilder
-     * size.
-     */
-    public StringBuilderOutputStream(StringBuilder sb) {
-       buf = sb;
-    }
-
-    /**
-     * Create a new string writer using the specified initial string-buffer
-     * size.
-     *
-     * @param initialSize
-     *        The number of <tt>byte</tt> values that will fit into this buffer
-     *        before it is automatically expanded
-     *
-     * @throws IllegalArgumentException
-     *         If <tt>initialSize</tt> is negative
-     */
-    public StringBuilderOutputStream(int 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);
-    }
-
-    /**
-     * Write a portion of an array of characters.
-     *
-     * @param  bbuf  Array of characters
-     * @param  off   Offset from which to start writing characters
-     * @param  len   Number of characters to write
-     */
-    
-    public void write(byte bbuf[], int off, int len) {
-        if ((off < 0) || (off > bbuf.length) || (len < 0) ||
-            ((off + len) > bbuf.length) || ((off + len) < 0)) {
-            throw new IndexOutOfBoundsException();
-        } else if (len == 0) {
-            return;
-        }
-        buf.append(new String(bbuf, off, len));
-    }
-
-    @Override
-       public void write(byte[] b) throws IOException {
-               buf.append(new String(b));
-       }
-
-       /**
-     * Write a string.
-     */
-    public void write(String str) {
-       buf.append(str);
-    }
-
-    /**
-     * Write a portion of a string.
-     *
-     * @param  str  String to be written
-     * @param  off  Offset from which to start writing characters
-     * @param  len  Number of characters to write
-     */
-    public void write(String str, int off, int len)  {
-       buf.append(str,off,len);
-    }
-
-    public StringBuilderOutputStream append(CharSequence csq) {
-       if (csq == null) {
-               write("null");
-       } else {
-               for(int i = 0;i<csq.length();++i) {
-                       buf.append(csq.charAt(i));
-               }
-       }
-       return this;
-    }
-
-    public StringBuilderOutputStream append(CharSequence csq, int start, int end) {
-               CharSequence cs = (csq == null ? "null" : csq);
-               return append(cs.subSequence(start, end));
-    }
-
-    /**
-     * Appends the specified character to this writer. 
-     *
-     * <p> An invocation of this method of the form <tt>out.append(c)</tt>
-     * behaves in exactly the same way as the invocation
-     *
-     * <pre>
-     *     out.write(c) </pre>
-     *
-     * @param  c
-     *         The 16-bit character to append
-     *
-     * @return  This writer
-     *
-     * @since 1.5
-     */
-    public StringBuilderOutputStream append(byte c) {
-       buf.append(c);
-       return this;
-    }
-
-    /**
-     * Return the buffer's current value as a string.
-     */
-    public String toString() {
-       return buf.toString();
-    }
-
-    /**
-     * Return the string buffer itself.
-     *
-     * @return StringBuffer holding the current buffer value.
-     */
-    public StringBuilder getBuffer() {
-       return buf;
-    }
-    
-    public void reset() {
-       buf.setLength(0);
-    }
-
-       @Override
-       public void flush() throws IOException {
-       }
-
-       @Override
-       public void close() throws IOException {
-       }
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+\r
+public class StringBuilderOutputStream extends OutputStream {\r
+       private StringBuilder buf;\r
+\r
+\r
+    /**\r
+     * Create a new string writer using the default initial string-buffer\r
+     * size.\r
+     */\r
+    public StringBuilderOutputStream() {\r
+       buf = new StringBuilder();\r
+    }\r
+\r
+    /**\r
+     * Create a new string writer using a passed in StringBuilder\r
+     * size.\r
+     */\r
+    public StringBuilderOutputStream(StringBuilder sb) {\r
+       buf = sb;\r
+    }\r
+\r
+    /**\r
+     * Create a new string writer using the specified initial string-buffer\r
+     * size.\r
+     *\r
+     * @param initialSize\r
+     *        The number of <tt>byte</tt> values that will fit into this buffer\r
+     *        before it is automatically expanded\r
+     *\r
+     * @throws IllegalArgumentException\r
+     *         If <tt>initialSize</tt> is negative\r
+     */\r
+    public StringBuilderOutputStream(int initialSize) {\r
+       if (initialSize < 0) {\r
+           throw new IllegalArgumentException("Negative buffer size");\r
+       }\r
+       buf = new StringBuilder(initialSize);\r
+    }\r
+\r
+    /**\r
+     * Write a single character.\r
+     */\r
+    public void write(int c) {\r
+       buf.append((byte) c);\r
+    }\r
+\r
+    /**\r
+     * Write a portion of an array of characters.\r
+     *\r
+     * @param  bbuf  Array of characters\r
+     * @param  off   Offset from which to start writing characters\r
+     * @param  len   Number of characters to write\r
+     */\r
+    \r
+    public void write(byte bbuf[], int off, int len) {\r
+        if ((off < 0) || (off > bbuf.length) || (len < 0) ||\r
+            ((off + len) > bbuf.length) || ((off + len) < 0)) {\r
+            throw new IndexOutOfBoundsException();\r
+        } else if (len == 0) {\r
+            return;\r
+        }\r
+        buf.append(new String(bbuf, off, len));\r
+    }\r
+\r
+    @Override\r
+       public void write(byte[] b) throws IOException {\r
+               buf.append(new String(b));\r
+       }\r
+\r
+       /**\r
+     * Write a string.\r
+     */\r
+    public void write(String str) {\r
+       buf.append(str);\r
+    }\r
+\r
+    /**\r
+     * Write a portion of a string.\r
+     *\r
+     * @param  str  String to be written\r
+     * @param  off  Offset from which to start writing characters\r
+     * @param  len  Number of characters to write\r
+     */\r
+    public void write(String str, int off, int len)  {\r
+       buf.append(str,off,len);\r
+    }\r
+\r
+    public StringBuilderOutputStream append(CharSequence csq) {\r
+       if (csq == null) {\r
+               write("null");\r
+       } else {\r
+               for(int i = 0;i<csq.length();++i) {\r
+                       buf.append(csq.charAt(i));\r
+               }\r
+       }\r
+       return this;\r
+    }\r
+\r
+    public StringBuilderOutputStream append(CharSequence csq, int start, int end) {\r
+               CharSequence cs = (csq == null ? "null" : csq);\r
+               return append(cs.subSequence(start, end));\r
+    }\r
+\r
+    /**\r
+     * Appends the specified character to this writer. \r
+     *\r
+     * <p> An invocation of this method of the form <tt>out.append(c)</tt>\r
+     * behaves in exactly the same way as the invocation\r
+     *\r
+     * <pre>\r
+     *     out.write(c) </pre>\r
+     *\r
+     * @param  c\r
+     *         The 16-bit character to append\r
+     *\r
+     * @return  This writer\r
+     *\r
+     * @since 1.5\r
+     */\r
+    public StringBuilderOutputStream append(byte c) {\r
+       buf.append(c);\r
+       return this;\r
+    }\r
+\r
+    /**\r
+     * Return the buffer's current value as a string.\r
+     */\r
+    public String toString() {\r
+       return buf.toString();\r
+    }\r
+\r
+    /**\r
+     * Return the string buffer itself.\r
+     *\r
+     * @return StringBuffer holding the current buffer value.\r
+     */\r
+    public StringBuilder getBuffer() {\r
+       return buf;\r
+    }\r
+    \r
+    public void reset() {\r
+       buf.setLength(0);\r
+    }\r
+\r
+       @Override\r
+       public void flush() throws IOException {\r
+       }\r
+\r
+       @Override\r
+       public void close() throws IOException {\r
+       }\r
+\r
+}\r
index cea4d85..467598b 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.env.util;
-
-import java.io.IOException;
-import java.io.Writer;
-
-public class StringBuilderWriter extends Writer {
-       private StringBuilder buf;
-
-
-    /**
-     * Create a new string writer using the default initial string-buffer
-     * size.
-     */
-    public StringBuilderWriter() {
-       buf = new StringBuilder();
-    }
-
-    /**
-     * Create a new string writer using a passed in StringBuilder
-     * size.
-     */
-    public StringBuilderWriter(StringBuilder sb) {
-       buf = sb;
-    }
-
-    /**
-     * Create a new string writer using the specified initial string-buffer
-     * size.
-     *
-     * @param initialSize
-     *        The number of <tt>char</tt> values that will fit into this buffer
-     *        before it is automatically expanded
-     *
-     * @throws IllegalArgumentException
-     *         If <tt>initialSize</tt> is negative
-     */
-    public StringBuilderWriter(int 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);
-    }
-
-    /**
-     * Write a portion of an array of characters.
-     *
-     * @param  cbuf  Array of characters
-     * @param  off   Offset from which to start writing characters
-     * @param  len   Number of characters to write
-     */
-    public void write(char cbuf[], int off, int len) {
-        if ((off < 0) || (off > cbuf.length) || (len < 0) ||
-            ((off + len) > cbuf.length) || ((off + len) < 0)) {
-            throw new IndexOutOfBoundsException();
-        } else if (len == 0) {
-            return;
-        }
-        buf.append(cbuf, off, len);
-    }
-
-    /**
-     * Write a string.
-     */
-    public void write(String str) {
-       buf.append(str);
-    }
-
-    /**
-     * Write a portion of a string.
-     *
-     * @param  str  String to be written
-     * @param  off  Offset from which to start writing characters
-     * @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);
-    }
-
-    public StringBuilderWriter append(CharSequence csq) {
-       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));
-    }
-
-    /**
-     * Appends the specified character to this writer. 
-     *
-     * <p> An invocation of this method of the form <tt>out.append(c)</tt>
-     * behaves in exactly the same way as the invocation
-     *
-     * <pre>
-     *     out.write(c) </pre>
-     *
-     * @param  c
-     *         The 16-bit character to append
-     *
-     * @return  This writer
-     *
-     * @since 1.5
-     */
-    public StringBuilderWriter append(char c) {
-       buf.append(c);
-       return this;
-    }
-
-    /**
-     * Return the buffer's current value as a string.
-     */
-    public String toString() {
-       return buf.toString();
-    }
-
-    /**
-     * Return the string buffer itself.
-     *
-     * @return StringBuffer holding the current buffer value.
-     */
-    public StringBuilder getBuffer() {
-       return buf;
-    }
-    
-    public void reset() {
-       buf.setLength(0);
-    }
-
-       @Override
-       public void flush() throws IOException {
-       }
-
-       @Override
-       public void close() throws IOException {
-       }
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import java.io.IOException;\r
+import java.io.Writer;\r
+\r
+public class StringBuilderWriter extends Writer {\r
+       private StringBuilder buf;\r
+\r
+\r
+    /**\r
+     * Create a new string writer using the default initial string-buffer\r
+     * size.\r
+     */\r
+    public StringBuilderWriter() {\r
+       buf = new StringBuilder();\r
+    }\r
+\r
+    /**\r
+     * Create a new string writer using a passed in StringBuilder\r
+     * size.\r
+     */\r
+    public StringBuilderWriter(StringBuilder sb) {\r
+       buf = sb;\r
+    }\r
+\r
+    /**\r
+     * Create a new string writer using the specified initial string-buffer\r
+     * size.\r
+     *\r
+     * @param initialSize\r
+     *        The number of <tt>char</tt> values that will fit into this buffer\r
+     *        before it is automatically expanded\r
+     *\r
+     * @throws IllegalArgumentException\r
+     *         If <tt>initialSize</tt> is negative\r
+     */\r
+    public StringBuilderWriter(int initialSize) {\r
+       if (initialSize < 0) {\r
+           throw new IllegalArgumentException("Negative buffer size");\r
+       }\r
+       buf = new StringBuilder(initialSize);\r
+    }\r
+\r
+    /**\r
+     * Write a single character.\r
+     */\r
+    public void write(int c) {\r
+       buf.append((char) c);\r
+    }\r
+\r
+    /**\r
+     * Write a portion of an array of characters.\r
+     *\r
+     * @param  cbuf  Array of characters\r
+     * @param  off   Offset from which to start writing characters\r
+     * @param  len   Number of characters to write\r
+     */\r
+    public void write(char cbuf[], int off, int len) {\r
+        if ((off < 0) || (off > cbuf.length) || (len < 0) ||\r
+            ((off + len) > cbuf.length) || ((off + len) < 0)) {\r
+            throw new IndexOutOfBoundsException();\r
+        } else if (len == 0) {\r
+            return;\r
+        }\r
+        buf.append(cbuf, off, len);\r
+    }\r
+\r
+    /**\r
+     * Write a string.\r
+     */\r
+    public void write(String str) {\r
+       buf.append(str);\r
+    }\r
+\r
+    /**\r
+     * Write a portion of a string.\r
+     *\r
+     * @param  str  String to be written\r
+     * @param  off  Offset from which to start writing characters\r
+     * @param  len  Number of characters to write\r
+     */\r
+    public void write(String str, int off, int len)  {\r
+       char[] chars = new char[len];\r
+       str.getChars(off, off+len, chars, 0);\r
+       buf.append(chars);\r
+    }\r
+\r
+    public StringBuilderWriter append(CharSequence csq) {\r
+       if (csq == null) {\r
+               write("null");\r
+       } else {\r
+               buf.append(csq);\r
+       }\r
+       return this;\r
+    }\r
+\r
+    public StringBuilderWriter append(CharSequence csq, int start, int end) {\r
+               CharSequence cs = (csq == null ? "null" : csq);\r
+               return append(cs.subSequence(start, end));\r
+    }\r
+\r
+    /**\r
+     * Appends the specified character to this writer. \r
+     *\r
+     * <p> An invocation of this method of the form <tt>out.append(c)</tt>\r
+     * behaves in exactly the same way as the invocation\r
+     *\r
+     * <pre>\r
+     *     out.write(c) </pre>\r
+     *\r
+     * @param  c\r
+     *         The 16-bit character to append\r
+     *\r
+     * @return  This writer\r
+     *\r
+     * @since 1.5\r
+     */\r
+    public StringBuilderWriter append(char c) {\r
+       buf.append(c);\r
+       return this;\r
+    }\r
+\r
+    /**\r
+     * Return the buffer's current value as a string.\r
+     */\r
+    public String toString() {\r
+       return buf.toString();\r
+    }\r
+\r
+    /**\r
+     * Return the string buffer itself.\r
+     *\r
+     * @return StringBuffer holding the current buffer value.\r
+     */\r
+    public StringBuilder getBuffer() {\r
+       return buf;\r
+    }\r
+    \r
+    public void reset() {\r
+       buf.setLength(0);\r
+    }\r
+\r
+       @Override\r
+       public void flush() throws IOException {\r
+       }\r
+\r
+       @Override\r
+       public void close() throws IOException {\r
+       }\r
+\r
+}\r
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
new file mode 100644 (file)
index 0000000..474f646
--- /dev/null
@@ -0,0 +1,87 @@
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env;\r
+\r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertTrue;\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.times;\r
+import static org.mockito.Mockito.verify;\r
+\r
+import java.util.Date;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+\r
+public class JU_LogTargetTest {\r
+\r
+       @Mock\r
+       Throwable t;\r
+\r
+       @Before\r
+       public void setup() {\r
+               t = mock(Throwable.class);\r
+       }\r
+\r
+       @Test\r
+       public void testLogTargetNull() {\r
+               LogTarget nullTarget = LogTarget.NULL;\r
+\r
+               // Expect methods doing nothing as no implemenation provided.\r
+               nullTarget.log(new Throwable(), null, null);\r
+               nullTarget.log("String", null);\r
+               nullTarget.printf(null, null, null);\r
+\r
+               assertFalse(nullTarget.isLoggable());\r
+       }\r
+\r
+       @Test\r
+       public void testLogTargetSysOut() {\r
+               LogTarget outTarget = LogTarget.SYSOUT;\r
+\r
+               outTarget.printf("format", new Date());\r
+               outTarget.log("null", null, null);\r
+\r
+               outTarget.log(t);\r
+               outTarget.log(t, "First String Object");\r
+\r
+               assertTrue(outTarget.isLoggable());\r
+\r
+               verify(t, times(2)).printStackTrace(System.out);\r
+       }\r
+\r
+       @Test\r
+       public void testLogTargetSysErr() {\r
+               LogTarget errTarget = LogTarget.SYSERR;\r
+\r
+               errTarget.printf("format", new Date());\r
+               errTarget.log("null", "null");\r
+\r
+               errTarget.log(t);\r
+               errTarget.log(t, "First String Object");\r
+\r
+               assertTrue(errTarget.isLoggable());\r
+\r
+               verify(t, times(2)).printStackTrace(System.err);\r
+       }\r
+\r
+}\r
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
new file mode 100644 (file)
index 0000000..5eab5dd
--- /dev/null
@@ -0,0 +1,140 @@
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env.impl;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertNull;\r
+import static org.mockito.Mockito.mock;\r
+\r
+import java.applet.Applet;\r
+import java.util.Properties;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+import org.onap.aaf.misc.env.Decryptor;\r
+import org.onap.aaf.misc.env.Encryptor;\r
+import org.onap.aaf.misc.env.LogTarget;\r
+import org.onap.aaf.misc.env.TimeTaken;\r
+\r
+public class JU_BasicEnvTest {\r
+\r
+       @Mock\r
+       Decryptor decrypt;\r
+\r
+       @Mock\r
+       Encryptor encrypt;\r
+\r
+       @Before\r
+       public void setup() {\r
+               decrypt = mock(Decryptor.class);\r
+               encrypt = mock(Encryptor.class);\r
+       }\r
+\r
+       @Test\r
+       public void testLogTarget() {\r
+               Properties prop = new Properties();\r
+               BasicEnv env = new BasicEnv(prop);\r
+\r
+               assertEquals(env.fatal(), LogTarget.SYSERR);\r
+               assertEquals(env.error(), LogTarget.SYSERR);\r
+               assertEquals(env.audit(), LogTarget.SYSOUT);\r
+               assertEquals(env.warn(), LogTarget.SYSERR);\r
+               assertEquals(env.init(), LogTarget.SYSOUT);\r
+               assertEquals(env.info(), LogTarget.SYSOUT);\r
+               assertEquals(env.debug(), LogTarget.NULL);\r
+               assertEquals(env.trace(), LogTarget.NULL);\r
+\r
+               env.debug(LogTarget.SYSOUT);\r
+               assertEquals(env.debug(), LogTarget.SYSOUT);\r
+\r
+               assertNull(env.getProperty("key"));\r
+               assertEquals("default", env.getProperty("key", "default"));\r
+\r
+               env.setProperty("key", "value");\r
+               assertEquals("value", env.getProperty("key", "default"));\r
+\r
+               Properties filteredProperties = env.getProperties("key");\r
+               assertEquals(filteredProperties.size(), 1);\r
+\r
+               env.setProperty("key", null);\r
+               assertEquals("default", env.getProperty("key", "default"));\r
+\r
+               filteredProperties = env.getProperties("key1");\r
+               assertEquals(filteredProperties.size(), 0);\r
+\r
+               filteredProperties = env.getProperties();\r
+               assertEquals(filteredProperties.size(), 0);\r
+\r
+       }\r
+\r
+       @Test\r
+       public void testBasicEnv() {\r
+               Applet applet = null;\r
+\r
+               BasicEnv env = new BasicEnv(applet, "tag1", "tag2");\r
+\r
+               TimeTaken tt = env.start("Name", 2);\r
+\r
+               long end = tt.end();\r
+               StringBuilder sb = new StringBuilder();\r
+\r
+               assertEquals(tt.toString(), "Name " + (end - tt.start) / 1000000f + "ms ");\r
+               tt.output(sb);\r
+               assertEquals(sb.toString(), "XML Name " + (end - tt.start) / 1000000f + "ms");\r
+\r
+               env.set(decrypt);\r
+               assertEquals(env.decryptor(), decrypt);\r
+               env.set(encrypt);\r
+               assertEquals(env.encryptor(), encrypt);\r
+       }\r
+\r
+       @Test\r
+       public void testBasicEnvDiffFlag() {\r
+               Properties prop = new Properties();\r
+\r
+               BasicEnv env = new BasicEnv("tag1", prop);\r
+\r
+               TimeTaken tt = env.start("Name", 1);\r
+\r
+               long end = tt.end();\r
+               StringBuilder sb = new StringBuilder();\r
+\r
+               assertEquals(tt.toString(), "Name " + (end - tt.start) / 1000000f + "ms ");\r
+               tt.output(sb);\r
+               assertEquals(sb.toString(), "REMOTE Name " + (end - tt.start) / 1000000f + "ms");\r
+\r
+               tt = env.start("New Name", 4);\r
+               tt.size(10);\r
+               sb = new StringBuilder();\r
+               tt.output(sb);\r
+               assertEquals(tt.toString(), "New Name " + (end - tt.start) / 1000000f + "ms 10");\r
+               assertEquals(sb.toString(), "JSON New Name " + (end - tt.start) / 1000000f + "ms size: 10");\r
+\r
+               if (System.getProperties().keySet().iterator().hasNext()) {\r
+                       String key = (String) System.getProperties().keySet().iterator().next();\r
+\r
+                       env.loadFromSystemPropsStartsWith(key);\r
+                       assertEquals(env.getProperty(key), System.getProperties().get(key));\r
+               }\r
+       }\r
+\r
+}\r
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
new file mode 100644 (file)
index 0000000..389e7f7
--- /dev/null
@@ -0,0 +1,69 @@
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+\r
+import java.util.Calendar;\r
+import java.util.Date;\r
+import java.util.GregorianCalendar;\r
+import java.util.logging.Level;\r
+import java.util.logging.LogRecord;\r
+\r
+import javax.xml.datatype.XMLGregorianCalendar;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+public class JU_ChronoTest {\r
+\r
+       @Before\r
+       public void setUp() throws Exception {\r
+       }\r
+\r
+       @Test\r
+       public void testFormatter8601() {\r
+               Chrono.Formatter8601 formatter = new Chrono.Formatter8601();\r
+\r
+               LogRecord record = new LogRecord(Level.WARNING, "Log Record to test log formating");\r
+\r
+               Date date = new Date(118, 02, 02);\r
+               long time = date.getTime();\r
+\r
+               record.setMillis(time);\r
+\r
+               String expectedString = Chrono.dateFmt.format(date) + " " + record.getThreadID() + " " + record.getLevel()\r
+                               + ": " + record.getMessage() + "\n";\r
+               assertEquals(expectedString, formatter.format(record));\r
+       }\r
+\r
+       @Test\r
+       public void testTimeStampWithDate() {\r
+               Date date = Calendar.getInstance().getTime();\r
+               XMLGregorianCalendar timeStamp = Chrono.timeStamp(date);\r
+\r
+               GregorianCalendar gc = new GregorianCalendar();\r
+               gc.setTime(date);\r
+               XMLGregorianCalendar expectedCalendar = Chrono.xmlDatatypeFactory.newXMLGregorianCalendar(gc);\r
+\r
+               assertEquals(expectedCalendar, timeStamp);\r
+       }\r
+}\r