[AAF-23] Initial code import 93/6693/1
authorsg481n <sg481n@att.com>
Thu, 3 Aug 2017 21:44:44 +0000 (17:44 -0400)
committersg481n <sg481n@att.com>
Thu, 3 Aug 2017 21:44:44 +0000 (17:44 -0400)
Change-Id: I8c0dc03058ae4fbb85c28a050bdd77e6c372d6c3
Signed-off-by: sg481n <sg481n@att.com>
138 files changed:
env/.gitignore [new file with mode: 0644]
env/pom.xml [new file with mode: 0644]
env/src/main/java/com/att/inno/env/APIException.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/BaseDataFactory.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/Creatable.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/Data.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/DataFactory.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/Decryptor.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/Encryptor.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/Env.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/EnvJAXB.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/EnvJAXBProps.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/EnvProps.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/EnvStore.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/IOObjectifier.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/IOStringifier.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/LifeCycle.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/LogTarget.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/Objectifier.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/Slot.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/StaticSlot.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/Store.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/StoreImpl.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/Stringifier.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/TimeTaken.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/Trans.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/TransCreate.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/TransJAXB.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/TransStore.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/impl/AbsTrans.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/impl/AbsTransJAXB.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/impl/BasicEnv.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/impl/BasicTrans.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/impl/EnvFactory.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/impl/JavaUtilLogTarget.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/impl/Log4JLogTarget.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/impl/NullLifeCycle.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/jaxb/JAXBDF.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/jaxb/JAXBData.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/jaxb/JAXBObjectifier.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/jaxb/JAXBStringifier.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/jaxb/JAXBmar.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/jaxb/JAXBumar.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/old/IOObjectifier.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/old/IOStringifier.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/old/Objectifier.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/old/OldDataFactory.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/old/Stringifier.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/util/Chrono.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/util/DoubleOutputStream.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/util/IndentPrintWriter.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/util/Pool.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/util/RefreshableThreadObject.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/util/Split.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/util/StringBuilderOutputStream.java [new file with mode: 0644]
env/src/main/java/com/att/inno/env/util/StringBuilderWriter.java [new file with mode: 0644]
log4j/.gitignore [new file with mode: 0644]
log4j/pom.xml [new file with mode: 0644]
log4j/src/main/java/com/att/inno/env/log4j/LogFileNamer.java [new file with mode: 0644]
log4j/src/main/java/com/att/inno/env/log4j/PIDAccess.java [new file with mode: 0644]
log4j/src/test/java/com/att/inno/env/log4j/LogTest.java [new file with mode: 0644]
log4j/src/test/resources/log4j-test.properties [new file with mode: 0644]
pom.xml [new file with mode: 0644]
rosetta/.gitignore [new file with mode: 0644]
rosetta/pom.xml [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/InJson.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/InXML.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/JaxEval.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/JaxInfo.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/JaxSet.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/Ladder.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/Marshal.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/Nulls.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/Out.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/OutJax.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/OutJson.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/OutRaw.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/OutXML.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/Parse.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/ParseException.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/Parsed.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/Prop.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/Saved.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/XmlEscape.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/env/RosettaDF.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/env/RosettaData.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/env/RosettaEnv.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/marshal/DataWriter.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/marshal/DocMarshal.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/marshal/FieldArray.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/marshal/FieldBlob.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/marshal/FieldDate.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/marshal/FieldDateTime.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/marshal/FieldHexBinary.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/marshal/FieldMarshal.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/marshal/FieldNumeric.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/marshal/FieldString.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/marshal/ListIterator.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/marshal/ObjArray.java [new file with mode: 0644]
rosetta/src/main/java/com/att/rosetta/marshal/ObjMarshal.java [new file with mode: 0644]
rosetta/src/main/xsd/inherit.xsd [new file with mode: 0644]
rosetta/src/main/xsd/s.xsd [new file with mode: 0644]
rosetta/src/main/xsd/types.xsd [new file with mode: 0644]
rosetta/src/test/java/com/data/test/JU_FromJSON.java [new file with mode: 0644]
rosetta/src/test/java/com/data/test/JU_FromXML.java [new file with mode: 0644]
rosetta/src/test/java/com/data/test/JU_JSON.java [new file with mode: 0644]
rosetta/src/test/java/com/data/test/JU_Ladder.java [new file with mode: 0644]
rosetta/src/test/java/com/data/test/JU_Nulls.java [new file with mode: 0644]
rosetta/src/test/java/com/data/test/JU_RosettaDF.java [new file with mode: 0644]
rosetta/src/test/java/com/data/test/JU_Saved.java [new file with mode: 0644]
rosetta/src/test/java/com/data/test/JU_Stream2Obj.java [new file with mode: 0644]
rosetta/src/test/java/com/data/test/JU_Struct.java [new file with mode: 0644]
rosetta/src/test/java/com/data/test/JU_Types.java [new file with mode: 0644]
rosetta/src/test/java/com/data/test/OutDump.java [new file with mode: 0644]
rosetta/src/test/java/com/data/test/Report.java [new file with mode: 0644]
rosetta/src/test/java/com/data/test/obj/MultiMarshal.java [new file with mode: 0644]
rosetta/src/test/java/com/data/test/obj/SingleMarshal.java [new file with mode: 0644]
xgen/.gitignore [new file with mode: 0644]
xgen/pom.xml [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/Back.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/Cache.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/CacheGen.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/Code.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/DynamicCode.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/Mark.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/Section.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/XGen.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/XGenBuff.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/html/HTML4Gen.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/html/HTML5Gen.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/html/HTMLCacheGen.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/html/HTMLGen.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/html/Imports.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/html/JSGen.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/html/State.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/html/Thematic.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/xml/XMLCacheGen.java [new file with mode: 0644]
xgen/src/main/java/com/att/xgen/xml/XMLGen.java [new file with mode: 0644]

diff --git a/env/.gitignore b/env/.gitignore
new file mode 100644 (file)
index 0000000..cf85207
--- /dev/null
@@ -0,0 +1,5 @@
+/bin/
+/target/
+/.classpath
+/.project
+.settings
diff --git a/env/pom.xml b/env/pom.xml
new file mode 100644 (file)
index 0000000..6d87fee
--- /dev/null
@@ -0,0 +1,129 @@
+<!--\r
+  ============LICENSE_START====================================================\r
+  * org.onap.aai\r
+  * ===========================================================================\r
+  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+  * Copyright © 2017 Amdocs\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
+  * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+  *\r
+-->\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
+       <parent>\r
+               <groupId>com.att.inno</groupId>\r
+               <artifactId>parent</artifactId>\r
+               <version>1.2.13</version>\r
+               <relativePath>..</relativePath>\r
+       </parent>\r
+       \r
+       <modelVersion>4.0.0</modelVersion>\r
+\r
+       <artifactId>env</artifactId>\r
+       <name>Env</name>\r
+       <packaging>jar</packaging>\r
+       <url>https://github.com/att/AAF</url>\r
+       <description>INNO</description>\r
+       <licenses>\r
+               <license>\r
+               <name>BSD License</name>\r
+               <url> </url>\r
+               </license>\r
+       </licenses>\r
+\r
+       <developers>\r
+               <developer>\r
+               <name>Jonathan Gathman</name>\r
+               <email></email>\r
+       <organization>ATT</organization>\r
+       <organizationUrl></organizationUrl>\r
+               </developer>\r
+       </developers>\r
+       \r
+       <dependencies>\r
+               <dependency>\r
+                       <groupId>log4j</groupId>\r
+                       <artifactId>log4j</artifactId>\r
+                       <scope>compile</scope> <!-- Provides scope only, in case other users prefer another Logging Implementation -->\r
+               </dependency>\r
+       </dependencies>\r
+<build>\r
+       <plugins>\r
+               <plugin>\r
+                       <groupId>org.apache.maven.plugins</groupId>\r
+                       <artifactId>maven-javadoc-plugin</artifactId>\r
+                       <configuration>\r
+                       <failOnError>false</failOnError>\r
+                       </configuration>\r
+                       <executions>\r
+                               <execution>\r
+                                       <id>attach-javadocs</id>\r
+                                       <goals>\r
+                                               <goal>jar</goal>\r
+                                       </goals>\r
+                               </execution>\r
+                       </executions>\r
+               </plugin> \r
+          \r
+          \r
+              <plugin>\r
+                     <groupId>org.apache.maven.plugins</groupId>\r
+                     <artifactId>maven-source-plugin</artifactId>\r
+                     <version>2.2.1</version>\r
+                     <executions>\r
+                       <execution>\r
+                         <id>attach-sources</id>\r
+                         <goals>\r
+                           <goal>jar-no-fork</goal>\r
+                         </goals>\r
+                       </execution>\r
+                     </executions>\r
+                   </plugin>\r
+                       \r
+               <plugin>\r
+                       <groupId>org.sonatype.plugins</groupId>\r
+                       <artifactId>nexus-staging-maven-plugin</artifactId>\r
+                       <version>1.6.7</version>\r
+                       <extensions>true</extensions>\r
+                       <configuration>\r
+                       <serverId>ossrhdme</serverId>\r
+                       <nexusUrl>https://oss.sonatype.org/</nexusUrl>\r
+                       <autoReleaseAfterClose>true</autoReleaseAfterClose>\r
+                       </configuration>\r
+               </plugin>\r
+               \r
+       </plugins>\r
+\r
+       </build>\r
+       \r
+       <distributionManagement>\r
+               <snapshotRepository>\r
+                       <id>ossrhdme</id>\r
+                       <url>https://oss.sonatype.org/content/repositories/snapshots</url>\r
+               </snapshotRepository>\r
+               <repository>\r
+                       <id>ossrhdme</id>\r
+                       <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>\r
+               </repository>\r
+       </distributionManagement>\r
+       \r
+       <scm>\r
+               <connection>https://github.com/att/AAF.git</connection>\r
+               <developerConnection>${project.scm.connection}</developerConnection>\r
+               <url>http://github.com/att/AAF/tree/master</url>\r
+       </scm>\r
+</project>\r
+\r
diff --git a/env/src/main/java/com/att/inno/env/APIException.java b/env/src/main/java/com/att/inno/env/APIException.java
new file mode 100644 (file)
index 0000000..3b5242a
--- /dev/null
@@ -0,0 +1,90 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
+ *\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
diff --git a/env/src/main/java/com/att/inno/env/BaseDataFactory.java b/env/src/main/java/com/att/inno/env/BaseDataFactory.java
new file mode 100644 (file)
index 0000000..3947441
--- /dev/null
@@ -0,0 +1,463 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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.xml.sax.SAXException;\r
+\r
+import com.att.inno.env.impl.EnvFactory;\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
+ *\r
+ * @param <T>\r
+ */\r
+public class BaseDataFactory {\r
+\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(XMLConstants.W3C_XML_SCHEMA_NS_URI) { // 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
+//      *\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
+//      *\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
+//      *\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
+//      *\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
+//      *\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
+//      *\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
+//      *\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
+//      *\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
+//      *\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
+//      *\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
+//      *\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
+//      *\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
+//      *\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
+//      *\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
+//      */\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
+//      *\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
diff --git a/env/src/main/java/com/att/inno/env/Creatable.java b/env/src/main/java/com/att/inno/env/Creatable.java
new file mode 100644 (file)
index 0000000..cce9898
--- /dev/null
@@ -0,0 +1,53 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
+ *\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
diff --git a/env/src/main/java/com/att/inno/env/Data.java b/env/src/main/java/com/att/inno/env/Data.java
new file mode 100644 (file)
index 0000000..221bf7e
--- /dev/null
@@ -0,0 +1,114 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
+ *\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
+}\r
diff --git a/env/src/main/java/com/att/inno/env/DataFactory.java b/env/src/main/java/com/att/inno/env/DataFactory.java
new file mode 100644 (file)
index 0000000..c2ce717
--- /dev/null
@@ -0,0 +1,32 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/Decryptor.java b/env/src/main/java/com/att/inno/env/Decryptor.java
new file mode 100644 (file)
index 0000000..ababe37
--- /dev/null
@@ -0,0 +1,36 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/Encryptor.java b/env/src/main/java/com/att/inno/env/Encryptor.java
new file mode 100644 (file)
index 0000000..3604fc1
--- /dev/null
@@ -0,0 +1,36 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/Env.java b/env/src/main/java/com/att/inno/env/Env.java
new file mode 100644 (file)
index 0000000..4078fc6
--- /dev/null
@@ -0,0 +1,137 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
+ *\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
diff --git a/env/src/main/java/com/att/inno/env/EnvJAXB.java b/env/src/main/java/com/att/inno/env/EnvJAXB.java
new file mode 100644 (file)
index 0000000..2aef19f
--- /dev/null
@@ -0,0 +1,54 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/EnvJAXBProps.java b/env/src/main/java/com/att/inno/env/EnvJAXBProps.java
new file mode 100644 (file)
index 0000000..87b2760
--- /dev/null
@@ -0,0 +1,32 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env;\r
+\r
+/**\r
+ * An interface to express both JAXB and Property elements of Env\r
+ *\r
+ */\r
+public interface EnvJAXBProps extends EnvJAXB, EnvProps {\r
+\r
+}\r
diff --git a/env/src/main/java/com/att/inno/env/EnvProps.java b/env/src/main/java/com/att/inno/env/EnvProps.java
new file mode 100644 (file)
index 0000000..a7801c9
--- /dev/null
@@ -0,0 +1,82 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/EnvStore.java b/env/src/main/java/com/att/inno/env/EnvStore.java
new file mode 100644 (file)
index 0000000..1629718
--- /dev/null
@@ -0,0 +1,29 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env;\r
+\r
+\r
+public interface EnvStore<TRANS extends Trans> extends Env, Store, TransCreate<TRANS>{\r
+\r
+}\r
diff --git a/env/src/main/java/com/att/inno/env/IOObjectifier.java b/env/src/main/java/com/att/inno/env/IOObjectifier.java
new file mode 100644 (file)
index 0000000..6e00031
--- /dev/null
@@ -0,0 +1,56 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/IOStringifier.java b/env/src/main/java/com/att/inno/env/IOStringifier.java
new file mode 100644 (file)
index 0000000..bcc1530
--- /dev/null
@@ -0,0 +1,76 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/LifeCycle.java b/env/src/main/java/com/att/inno/env/LifeCycle.java
new file mode 100644 (file)
index 0000000..36f4d34
--- /dev/null
@@ -0,0 +1,124 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+/**\r
+ *\r
+ * Created on: Aug 19, 2009\r
+ * Created by:\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 com.att.inno.env;\r
+\r
+import com.att.inno.env.util.RefreshableThreadObject;\r
+\r
+\r
+/**\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
diff --git a/env/src/main/java/com/att/inno/env/LogTarget.java b/env/src/main/java/com/att/inno/env/LogTarget.java
new file mode 100644 (file)
index 0000000..03ddff9
--- /dev/null
@@ -0,0 +1,143 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env;\r
+\r
+import java.io.PrintStream;\r
+import java.util.Date;\r
+\r
+import com.att.inno.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
+ *\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(com.att.inno.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
+};\r
diff --git a/env/src/main/java/com/att/inno/env/Objectifier.java b/env/src/main/java/com/att/inno/env/Objectifier.java
new file mode 100644 (file)
index 0000000..3f69fac
--- /dev/null
@@ -0,0 +1,59 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+/**\r
+ * \r
+ */\r
+package com.att.inno.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
+}\r
diff --git a/env/src/main/java/com/att/inno/env/Slot.java b/env/src/main/java/com/att/inno/env/Slot.java
new file mode 100644 (file)
index 0000000..3a9157d
--- /dev/null
@@ -0,0 +1,104 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+/**\r
+ * Slot.java\r
+ *\r
+ * Created on: Dec 5, 2008\r
+ * Created by:\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 com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/StaticSlot.java b/env/src/main/java/com/att/inno/env/StaticSlot.java
new file mode 100644 (file)
index 0000000..584704c
--- /dev/null
@@ -0,0 +1,87 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+/**\r
+ * Slot.java\r
+ *\r
+ * Created on: Dec 5, 2008\r
+ * Created by:\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 com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/Store.java b/env/src/main/java/com/att/inno/env/Store.java
new file mode 100644 (file)
index 0000000..5e4a661
--- /dev/null
@@ -0,0 +1,110 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
+}\r
diff --git a/env/src/main/java/com/att/inno/env/StoreImpl.java b/env/src/main/java/com/att/inno/env/StoreImpl.java
new file mode 100644 (file)
index 0000000..98859c6
--- /dev/null
@@ -0,0 +1,238 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env;\r
+\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map.Entry;\r
+import java.util.Properties;\r
+\r
+import com.att.inno.env.util.Split;\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
+               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
+       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
diff --git a/env/src/main/java/com/att/inno/env/Stringifier.java b/env/src/main/java/com/att/inno/env/Stringifier.java
new file mode 100644 (file)
index 0000000..ce27289
--- /dev/null
@@ -0,0 +1,47 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
+}\r
diff --git a/env/src/main/java/com/att/inno/env/TimeTaken.java b/env/src/main/java/com/att/inno/env/TimeTaken.java
new file mode 100644 (file)
index 0000000..2560dd8
--- /dev/null
@@ -0,0 +1,117 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
+ *\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
diff --git a/env/src/main/java/com/att/inno/env/Trans.java b/env/src/main/java/com/att/inno/env/Trans.java
new file mode 100644 (file)
index 0000000..138ca91
--- /dev/null
@@ -0,0 +1,75 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
+ *\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
+}\r
diff --git a/env/src/main/java/com/att/inno/env/TransCreate.java b/env/src/main/java/com/att/inno/env/TransCreate.java
new file mode 100644 (file)
index 0000000..804a89e
--- /dev/null
@@ -0,0 +1,28 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env;\r
+\r
+public interface TransCreate<TRANS> {\r
+       public TRANS newTrans();\r
+}\r
diff --git a/env/src/main/java/com/att/inno/env/TransJAXB.java b/env/src/main/java/com/att/inno/env/TransJAXB.java
new file mode 100644 (file)
index 0000000..ad8beae
--- /dev/null
@@ -0,0 +1,28 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env;\r
+\r
+public interface TransJAXB extends Trans, TransStore {\r
+\r
+}\r
diff --git a/env/src/main/java/com/att/inno/env/TransStore.java b/env/src/main/java/com/att/inno/env/TransStore.java
new file mode 100644 (file)
index 0000000..a1cf6b5
--- /dev/null
@@ -0,0 +1,59 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/impl/AbsTrans.java b/env/src/main/java/com/att/inno/env/impl/AbsTrans.java
new file mode 100644 (file)
index 0000000..23f3c03
--- /dev/null
@@ -0,0 +1,216 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env.impl;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Stack;\r
+\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.LogTarget;\r
+import com.att.inno.env.Slot;\r
+import com.att.inno.env.StoreImpl;\r
+import com.att.inno.env.TimeTaken;\r
+import com.att.inno.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
+               tt.done();\r
+               trail.add(tt);\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
diff --git a/env/src/main/java/com/att/inno/env/impl/AbsTransJAXB.java b/env/src/main/java/com/att/inno/env/impl/AbsTransJAXB.java
new file mode 100644 (file)
index 0000000..5c15500
--- /dev/null
@@ -0,0 +1,59 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env.impl;\r
+\r
+import javax.xml.namespace.QName;\r
+import javax.xml.validation.Schema;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.inno.env.DataFactory;\r
+import com.att.inno.env.EnvJAXB;\r
+import com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/impl/BasicEnv.java b/env/src/main/java/com/att/inno/env/impl/BasicEnv.java
new file mode 100644 (file)
index 0000000..e18248a
--- /dev/null
@@ -0,0 +1,337 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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 com.att.inno.env.APIException;\r
+import com.att.inno.env.DataFactory;\r
+import com.att.inno.env.Decryptor;\r
+import com.att.inno.env.Encryptor;\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.EnvJAXB;\r
+import com.att.inno.env.LogTarget;\r
+import com.att.inno.env.StoreImpl;\r
+import com.att.inno.env.TimeTaken;\r
+import com.att.inno.env.TransCreate;\r
+import com.att.inno.env.TransJAXB;\r
+import com.att.inno.env.jaxb.JAXBDF;\r
+import com.att.inno.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
+ *\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
diff --git a/env/src/main/java/com/att/inno/env/impl/BasicTrans.java b/env/src/main/java/com/att/inno/env/impl/BasicTrans.java
new file mode 100644 (file)
index 0000000..c390cd5
--- /dev/null
@@ -0,0 +1,83 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env.impl;\r
+\r
+import com.att.inno.env.Decryptor;\r
+import com.att.inno.env.Encryptor;\r
+import com.att.inno.env.EnvJAXB;\r
+import com.att.inno.env.Slot;\r
+import com.att.inno.env.StaticSlot;\r
+import com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/impl/EnvFactory.java b/env/src/main/java/com/att/inno/env/impl/EnvFactory.java
new file mode 100644 (file)
index 0000000..6018990
--- /dev/null
@@ -0,0 +1,68 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env.impl;\r
+\r
+import com.att.inno.env.EnvJAXB;\r
+import com.att.inno.env.TransCreate;\r
+import com.att.inno.env.TransJAXB;\r
+\r
+/**\r
+ * EnvFactory\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
diff --git a/env/src/main/java/com/att/inno/env/impl/JavaUtilLogTarget.java b/env/src/main/java/com/att/inno/env/impl/JavaUtilLogTarget.java
new file mode 100644 (file)
index 0000000..6577ef1
--- /dev/null
@@ -0,0 +1,91 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env.impl;\r
+\r
+import java.util.logging.Level;\r
+import java.util.logging.Logger;\r
+\r
+import com.att.inno.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
+ *\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
diff --git a/env/src/main/java/com/att/inno/env/impl/Log4JLogTarget.java b/env/src/main/java/com/att/inno/env/impl/Log4JLogTarget.java
new file mode 100644 (file)
index 0000000..295f3dd
--- /dev/null
@@ -0,0 +1,111 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env.impl;\r
+\r
+import java.io.PrintWriter;\r
+\r
+import org.apache.log4j.Level;\r
+import org.apache.log4j.Logger;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.inno.env.LogTarget;\r
+import com.att.inno.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
+ *\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
+}\r
diff --git a/env/src/main/java/com/att/inno/env/impl/NullLifeCycle.java b/env/src/main/java/com/att/inno/env/impl/NullLifeCycle.java
new file mode 100644 (file)
index 0000000..5725cf1
--- /dev/null
@@ -0,0 +1,60 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+/**\r
+ * \r
+ */\r
+package com.att.inno.env.impl;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.inno.env.Env;\r
+import com.att.inno.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
+ *\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
+}\r
diff --git a/env/src/main/java/com/att/inno/env/jaxb/JAXBDF.java b/env/src/main/java/com/att/inno/env/jaxb/JAXBDF.java
new file mode 100644 (file)
index 0000000..981f257
--- /dev/null
@@ -0,0 +1,311 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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 com.att.inno.env.APIException;\r
+import com.att.inno.env.BaseDataFactory;\r
+import com.att.inno.env.Data;\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.EnvJAXB;\r
+import com.att.inno.env.TimeTaken;\r
+import com.att.inno.env.old.IOObjectifier;\r
+import com.att.inno.env.old.IOStringifier;\r
+import com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/jaxb/JAXBData.java b/env/src/main/java/com/att/inno/env/jaxb/JAXBData.java
new file mode 100644 (file)
index 0000000..b502331
--- /dev/null
@@ -0,0 +1,322 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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 com.att.inno.env.APIException;\r
+import com.att.inno.env.Data;\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.EnvJAXB;\r
+import com.att.inno.env.old.IOStringifier;\r
+import com.att.inno.env.old.Objectifier;\r
+import com.att.inno.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
+ *\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
+}\r
diff --git a/env/src/main/java/com/att/inno/env/jaxb/JAXBObjectifier.java b/env/src/main/java/com/att/inno/env/jaxb/JAXBObjectifier.java
new file mode 100644 (file)
index 0000000..bbd3227
--- /dev/null
@@ -0,0 +1,137 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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 com.att.inno.env.APIException;\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.TimeTaken;\r
+import com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/jaxb/JAXBStringifier.java b/env/src/main/java/com/att/inno/env/jaxb/JAXBStringifier.java
new file mode 100644 (file)
index 0000000..c47a392
--- /dev/null
@@ -0,0 +1,139 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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 com.att.inno.env.APIException;\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.TimeTaken;\r
+import com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/jaxb/JAXBmar.java b/env/src/main/java/com/att/inno/env/jaxb/JAXBmar.java
new file mode 100644 (file)
index 0000000..86e3c65
--- /dev/null
@@ -0,0 +1,254 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+/**\r
+ * JAXBumar.java\r
+ *\r
+ * Created on: Apr 10, 2009\r
+ * Created by: \r
+ *\r
+ * Revamped to do away with ThreadLocal 5/27/2011,\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 com.att.inno.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 com.att.inno.env.APIException;\r
+import com.att.inno.env.LogTarget;\r
+import com.att.inno.env.util.Pool;\r
+import com.att.inno.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
+ *\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
diff --git a/env/src/main/java/com/att/inno/env/jaxb/JAXBumar.java b/env/src/main/java/com/att/inno/env/jaxb/JAXBumar.java
new file mode 100644 (file)
index 0000000..5b53429
--- /dev/null
@@ -0,0 +1,244 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+/**\r
+ * JAXBumar.java\r
+ *\r
+ * Created on: Apr 10, 2009\r
+ * Created by:\r
+ *\r
+ * Revamped to do away with ThreadLocal 5/27/2011,\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 com.att.inno.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.w3c.dom.Node;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.inno.env.LogTarget;\r
+import com.att.inno.env.util.Pool;\r
+import com.att.inno.env.util.Pool.Pooled;\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
+ */\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
diff --git a/env/src/main/java/com/att/inno/env/old/IOObjectifier.java b/env/src/main/java/com/att/inno/env/old/IOObjectifier.java
new file mode 100644 (file)
index 0000000..928c589
--- /dev/null
@@ -0,0 +1,59 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env.old;\r
+\r
+import java.io.InputStream;\r
+import java.io.Reader;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/old/IOStringifier.java b/env/src/main/java/com/att/inno/env/old/IOStringifier.java
new file mode 100644 (file)
index 0000000..61dc188
--- /dev/null
@@ -0,0 +1,79 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env.old;\r
+\r
+import java.io.OutputStream;\r
+import java.io.Writer;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/old/Objectifier.java b/env/src/main/java/com/att/inno/env/old/Objectifier.java
new file mode 100644 (file)
index 0000000..19e19de
--- /dev/null
@@ -0,0 +1,62 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+/**\r
+ * \r
+ */\r
+package com.att.inno.env.old;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.inno.env.Env;\r
+import com.att.inno.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
+}\r
diff --git a/env/src/main/java/com/att/inno/env/old/OldDataFactory.java b/env/src/main/java/com/att/inno/env/old/OldDataFactory.java
new file mode 100644 (file)
index 0000000..a76e1fb
--- /dev/null
@@ -0,0 +1,49 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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 com.att.inno.env.APIException;\r
+import com.att.inno.env.Data;\r
+import com.att.inno.env.DataFactory;\r
+import com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/old/Stringifier.java b/env/src/main/java/com/att/inno/env/old/Stringifier.java
new file mode 100644 (file)
index 0000000..fa3cee0
--- /dev/null
@@ -0,0 +1,50 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env.old;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.inno.env.Env;\r
+import com.att.inno.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
+}\r
diff --git a/env/src/main/java/com/att/inno/env/util/Chrono.java b/env/src/main/java/com/att/inno/env/util/Chrono.java
new file mode 100644 (file)
index 0000000..7d81d3d
--- /dev/null
@@ -0,0 +1,308 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env.util;\r
+\r
+import java.text.DateFormat;\r
+import java.text.SimpleDateFormat;\r
+import java.util.Date;\r
+import java.util.GregorianCalendar;\r
+import java.security.SecureRandom;\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;\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
+               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
+       public static final UUID dateToUUID(Date d) {\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
+\r
+        long origTime = d.getTime();\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
diff --git a/env/src/main/java/com/att/inno/env/util/DoubleOutputStream.java b/env/src/main/java/com/att/inno/env/util/DoubleOutputStream.java
new file mode 100644 (file)
index 0000000..212f0c8
--- /dev/null
@@ -0,0 +1,99 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/util/IndentPrintWriter.java b/env/src/main/java/com/att/inno/env/util/IndentPrintWriter.java
new file mode 100644 (file)
index 0000000..48c5243
--- /dev/null
@@ -0,0 +1,115 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env.util;\r
+\r
+import java.io.OutputStream;\r
+import java.io.PrintWriter;\r
+import java.io.Writer;\r
+\r
+/**\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
diff --git a/env/src/main/java/com/att/inno/env/util/Pool.java b/env/src/main/java/com/att/inno/env/util/Pool.java
new file mode 100644 (file)
index 0000000..e631c98
--- /dev/null
@@ -0,0 +1,396 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+/*\r
+ * Pool\r
+ * \r
+ * 5/27/2011\r
+ */\r
+package com.att.inno.env.util;\r
+\r
+import java.util.LinkedList;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.inno.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
+ * \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
+        * \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
+        * \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
diff --git a/env/src/main/java/com/att/inno/env/util/RefreshableThreadObject.java b/env/src/main/java/com/att/inno/env/util/RefreshableThreadObject.java
new file mode 100644 (file)
index 0000000..78adcb9
--- /dev/null
@@ -0,0 +1,126 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env.util;\r
+\r
+import java.lang.reflect.Constructor;\r
+import java.lang.reflect.InvocationTargetException;\r
+import java.util.Collections;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.inno.env.Creatable;\r
+import com.att.inno.env.Env;\r
+import com.att.inno.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
+ *\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 = Collections.synchronizedMap(new HashMap<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
diff --git a/env/src/main/java/com/att/inno/env/util/Split.java b/env/src/main/java/com/att/inno/env/util/Split.java
new file mode 100644 (file)
index 0000000..a25f36c
--- /dev/null
@@ -0,0 +1,91 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
+ * 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
diff --git a/env/src/main/java/com/att/inno/env/util/StringBuilderOutputStream.java b/env/src/main/java/com/att/inno/env/util/StringBuilderOutputStream.java
new file mode 100644 (file)
index 0000000..a3f8f4b
--- /dev/null
@@ -0,0 +1,180 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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
diff --git a/env/src/main/java/com/att/inno/env/util/StringBuilderWriter.java b/env/src/main/java/com/att/inno/env/util/StringBuilderWriter.java
new file mode 100644 (file)
index 0000000..833bd7c
--- /dev/null
@@ -0,0 +1,174 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.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/log4j/.gitignore b/log4j/.gitignore
new file mode 100644 (file)
index 0000000..b981306
--- /dev/null
@@ -0,0 +1,4 @@
+/target/
+.settings
+.project
+.classpath
diff --git a/log4j/pom.xml b/log4j/pom.xml
new file mode 100644 (file)
index 0000000..66e307c
--- /dev/null
@@ -0,0 +1,143 @@
+<!--\r
+  ============LICENSE_START====================================================\r
+  * org.onap.aai\r
+  * ===========================================================================\r
+  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+  * Copyright © 2017 Amdocs\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
+  * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+  *\r
+-->\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
+<parent>\r
+               <groupId>com.att.inno</groupId>\r
+               <artifactId>parent</artifactId>\r
+               <version>1.2.13</version>\r
+               <relativePath>..</relativePath>\r
+       </parent>\r
+       \r
+       <name>Log4J Elements</name>\r
+       <artifactId>log4j</artifactId>\r
+       <packaging>jar</packaging>\r
+       <modelVersion>4.0.0</modelVersion>\r
+       <url>https://github.com/att/AAF</url>\r
+       <description>INNO</description>\r
+       <licenses>\r
+               <license>\r
+               <name>BSD License</name>\r
+               <url> </url>\r
+               </license>\r
+       </licenses>\r
+\r
+       <developers>\r
+               <developer>\r
+               <name>Jonathan Gathman</name>\r
+               <email></email>\r
+       <organization>ATT</organization>\r
+       <organizationUrl></organizationUrl>\r
+               </developer>\r
+       </developers>\r
+\r
+       <dependencies>\r
+               <dependency>\r
+                       <groupId>com.att.inno</groupId>\r
+                       <artifactId>env</artifactId>\r
+                       <version>${project.version}</version>\r
+               </dependency>\r
+               \r
+               <dependency>\r
+                       <groupId>net.java.dev.jna</groupId>\r
+                       <artifactId>jna-platform</artifactId>\r
+                       <version>4.0.0</version>\r
+               </dependency>\r
+       \r
+       </dependencies>\r
+       \r
+       <distributionManagement>\r
+               <snapshotRepository>\r
+                       <id>ossrhdme</id>\r
+                       <url>https://oss.sonatype.org/content/repositories/snapshots</url>\r
+               </snapshotRepository>\r
+               <repository>\r
+                       <id>ossrhdme</id>\r
+                       <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>\r
+               </repository>\r
+       </distributionManagement>\r
+       \r
+       <scm>\r
+               <connection>https://github.com/att/AAF.git</connection>\r
+               <developerConnection>${project.scm.connection}</developerConnection>\r
+               <url>http://github.com/att/AAF/tree/master</url>\r
+       </scm>\r
+\r
+       <build>\r
+               <plugins>\r
+                       <plugin>\r
+                               <groupId>org.apache.maven.plugins</groupId>\r
+                               <artifactId>maven-deploy-plugin</artifactId>\r
+                               <version>2.6</version>\r
+                               <configuration>\r
+                                       <skip>false</skip>\r
+                               </configuration>\r
+                       </plugin>\r
+                       \r
+                       <plugin>\r
+                       <groupId>org.apache.maven.plugins</groupId>\r
+                       <artifactId>maven-javadoc-plugin</artifactId>\r
+                       <configuration>\r
+                       <failOnError>false</failOnError>\r
+                       </configuration>\r
+                       <executions>\r
+                               <execution>\r
+                                       <id>attach-javadocs</id>\r
+                                       <goals>\r
+                                               <goal>jar</goal>\r
+                                       </goals>\r
+                               </execution>\r
+                       </executions>\r
+               </plugin> \r
+          \r
+          \r
+              <plugin>\r
+                     <groupId>org.apache.maven.plugins</groupId>\r
+                     <artifactId>maven-source-plugin</artifactId>\r
+                     <version>2.2.1</version>\r
+                     <executions>\r
+                       <execution>\r
+                         <id>attach-sources</id>\r
+                         <goals>\r
+                           <goal>jar-no-fork</goal>\r
+                         </goals>\r
+                       </execution>\r
+                     </executions>\r
+                   </plugin>\r
+\r
+                       <plugin>\r
+                               <groupId>org.sonatype.plugins</groupId>\r
+                               <artifactId>nexus-staging-maven-plugin</artifactId>\r
+                               <version>1.6.7</version>\r
+                               <extensions>true</extensions>\r
+                               <configuration>\r
+                               <serverId>ossrhdme</serverId>\r
+                               <nexusUrl>https://oss.sonatype.org/</nexusUrl>\r
+                               <autoReleaseAfterClose>true</autoReleaseAfterClose>\r
+                               </configuration>\r
+                       </plugin>\r
+               </plugins>\r
+       </build>\r
+       \r
+</project>\r
diff --git a/log4j/src/main/java/com/att/inno/env/log4j/LogFileNamer.java b/log4j/src/main/java/com/att/inno/env/log4j/LogFileNamer.java
new file mode 100644 (file)
index 0000000..3ef0f52
--- /dev/null
@@ -0,0 +1,83 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env.log4j;\r
+\r
+import java.io.File;\r
+import java.net.URL;\r
+\r
+public class LogFileNamer {\r
+       public static final int pid = PIDAccess.INSTANCE.getpid();\r
+       public final String root;\r
+       private boolean printPID;\r
+       \r
+       public LogFileNamer(String root) {\r
+               if(root==null || "".equals(root) || root.endsWith("/")) {\r
+                       this.root = root;\r
+               } else {\r
+                       this.root = root + "-";\r
+               }\r
+               printPID=true;\r
+       }\r
+       \r
+       public LogFileNamer noPID() {\r
+               printPID = false;\r
+               return this;\r
+       }\r
+       /**\r
+        * Accepts a String.\r
+        * If Separated by "|" then first part is the Appender name, and the second is used in the FileNaming\r
+        * (This is to allow for shortened Logger names, and more verbose file names)\r
+        * \r
+        * @param appender\r
+        * \r
+        * returns the String Appender\r
+        */\r
+       public String setAppender(String appender) {\r
+               int pipe = appender.indexOf('|');\r
+               if(pipe>=0) {\r
+                       String rv;\r
+                       System.setProperty(\r
+                               "LOG4J_FILENAME_"+(rv=appender.substring(0,pipe)),\r
+                               root + appender.substring(pipe+1) + (printPID?('-' + pid):"") + ".log");\r
+                       return rv;\r
+               } else {\r
+                       System.setProperty(\r
+                               "LOG4J_FILENAME_"+appender,\r
+                               root + appender + (printPID?('-' + pid):"") + ".log");\r
+                       return appender;\r
+               }\r
+               \r
+       }\r
+\r
+       public void configure(String props) {\r
+               String fname;\r
+               if(new File(fname="etc/"+props).exists()) {\r
+                       org.apache.log4j.PropertyConfigurator.configureAndWatch(fname,60*1000);\r
+               } else {\r
+                       URL rsrc = ClassLoader.getSystemResource(props);\r
+                       if(rsrc==null) System.err.println("Neither File: " + fname + " or resource on Classpath " + props + " exist" );\r
+                       org.apache.log4j.PropertyConfigurator.configure(rsrc);\r
+               }\r
+       }\r
+}\r
diff --git a/log4j/src/main/java/com/att/inno/env/log4j/PIDAccess.java b/log4j/src/main/java/com/att/inno/env/log4j/PIDAccess.java
new file mode 100644 (file)
index 0000000..77b77a6
--- /dev/null
@@ -0,0 +1,32 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env.log4j;\r
+\r
+import com.sun.jna.Library;\r
+import com.sun.jna.Native;\r
+\r
+public interface PIDAccess extends Library {\r
+       PIDAccess INSTANCE = (PIDAccess) Native.loadLibrary("c", PIDAccess.class);\r
+    int getpid ();\r
+}\r
diff --git a/log4j/src/test/java/com/att/inno/env/log4j/LogTest.java b/log4j/src/test/java/com/att/inno/env/log4j/LogTest.java
new file mode 100644 (file)
index 0000000..69ff8c4
--- /dev/null
@@ -0,0 +1,45 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.inno.env.log4j;\r
+\r
+import java.util.logging.Logger;\r
+\r
+\r
+public class LogTest\r
+{\r
+    public static void main(String[] args) throws Exception\r
+    {\r
+       LogFileNamer lfn = new LogFileNamer("authz");\r
+       lfn.setAppender("service");\r
+       lfn.setAppender("init");\r
+       lfn.setAppender("audit");\r
+       lfn.setAppender("test");\r
+       lfn.configure("src/test/resources/log4j-test.properties");\r
+        Logger log = Logger.getLogger( "init" );\r
+\r
+        \r
+\r
+        log.info("Hello");\r
+    }\r
+}\r
diff --git a/log4j/src/test/resources/log4j-test.properties b/log4j/src/test/resources/log4j-test.properties
new file mode 100644 (file)
index 0000000..b56e904
--- /dev/null
@@ -0,0 +1,62 @@
+#-------------------------------------------------------------------------------\r
+# ============LICENSE_START====================================================\r
+# * org.onap.aai\r
+# * ===========================================================================\r
+# * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+# * Copyright © 2017 Amdocs\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
+# * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+# *\r
+#-------------------------------------------------------------------------------\r
+###############################################################################\r
+# Copyright (c) 2016 AT&T Intellectual Property. All rights reserved.\r
+###############################################################################\r
+#\r
+# Licensed to the Apache Software Foundation (ASF) under one\r
+# or more contributor license agreements.  See the NOTICE file\r
+# distributed with this work for additional information\r
+# regarding copyright ownership.  The ASF licenses this file\r
+# to you under the Apache License, Version 2.0 (the\r
+# "License"); you may not use this file except in compliance\r
+# with the License.  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,\r
+# software distributed under the License is distributed on an\r
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
+# KIND, either express or implied.  See the License for the\r
+# specific language governing permissions and limitations\r
+# under the License.\r
+#\r
+log4j.rootLogger=INFO,test\r
+\r
+log4j.appender.test=org.apache.log4j.RollingFileAppender\r
+#log4j.appender.test.File=logs/cdv-${PID}.log\r
+log4j.appender.test.File=logs/${LOG4J_FILENAME_test}\r
+log4j.appender.test.MaxFileSize=10000KB\r
+log4j.appender.test.MaxBackupIndex=7\r
+log4j.appender.test.layout=org.apache.log4j.PatternLayout \r
+log4j.appender.test.layout.ConversionPattern=%d %p [%c] - %m %n\r
+\r
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender\r
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout\r
+log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m %n\r
+\r
+# General Apache libraries\r
+log4j.logger.org.apache=WARN\r
+\r
+log4j.DEBUG=true\r
diff --git a/pom.xml b/pom.xml
new file mode 100644 (file)
index 0000000..610f7f5
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,213 @@
+<!--
+  ============LICENSE_START====================================================
+  * org.onap.aai
+  * ===========================================================================
+  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+  * Copyright © 2017 Amdocs
+  * ===========================================================================
+  * Licensed under the Apache License, Version 2.0 (the "License");
+  * you may not use this file except in compliance with the License.
+  * You may obtain a copy of the License at
+  * 
+   *      http://www.apache.org/licenses/LICENSE-2.0
+  * 
+   * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
+  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  * See the License for the specific language governing permissions and
+  * limitations under the License.
+  * ============LICENSE_END====================================================
+  *
+  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+  *
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <groupId>com.att.inno</groupId>
+       <artifactId>parent</artifactId>
+       <name>Parent POM for JG Innovation</name>
+       <version>1.2.13</version>
+       <packaging>pom</packaging>
+       <url>https://github.com/att/AAF</url>
+       <description>INNO</description>
+       <licenses>
+               <license>
+               <name>BSD License</name>
+               <url> </url>
+               </license>
+       </licenses>
+
+       <developers>
+               <developer>
+               <name>Jonathan Gathman</name>
+               <email></email>
+       <organization>ATT</organization>
+       <organizationUrl></organizationUrl>
+               </developer>
+       </developers>
+
+       <properties>
+               <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+               <project.cadiVersion>1.3.2</project.cadiVersion>
+       </properties>
+
+       <dependencies>
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <version>4.10</version>
+                       <scope>test</scope>
+               </dependency>   
+       </dependencies>
+
+       <build>
+               <testSourceDirectory>src/test/java</testSourceDirectory>
+                       <plugins>
+                               <plugin>
+                                       <groupId>org.apache.maven.plugins</groupId>
+                                       <version>2.4</version>
+                                       <artifactId>maven-jar-plugin</artifactId>
+                                       <configuration>
+                                               <outputDirectory>target</outputDirectory>
+                                       </configuration>
+                               </plugin>
+                               
+                               <plugin>
+                                 <groupId>org.apache.maven.plugins</groupId>
+                                 <artifactId>maven-surefire-plugin</artifactId>
+                                 <version>2.17</version>
+                                 <configuration>
+                                       <skipTests>false</skipTests>
+                                       <includes>
+                                         <include>**/JU*.java</include>
+                                       </includes>
+       
+                                 </configuration>
+                               </plugin>
+       
+                               <plugin>
+                                       <inherited>true</inherited>
+                                       <groupId>org.apache.maven.plugins</groupId>
+                                       <artifactId>maven-compiler-plugin</artifactId>
+                                          
+                                       <configuration>
+                                               <source>1.6</source>
+                                               <target>1.6</target>
+                                       </configuration>
+                               </plugin>
+                               <plugin>
+                       <groupId>org.apache.maven.plugins</groupId>
+                       <artifactId>maven-javadoc-plugin</artifactId>
+                       <configuration>
+                       <failOnError>false</failOnError>
+                       </configuration>
+                       <executions>
+                               <execution>
+                                       <id>attach-javadocs</id>
+                                       <goals>
+                                               <goal>jar</goal>
+                                       </goals>
+                               </execution>
+                       </executions>
+               </plugin> 
+          
+          
+              <plugin>
+                     <groupId>org.apache.maven.plugins</groupId>
+                     <artifactId>maven-source-plugin</artifactId>
+                     <version>2.2.1</version>
+                     <executions>
+                       <execution>
+                         <id>attach-sources</id>
+                         <goals>
+                           <goal>jar-no-fork</goal>
+                         </goals>
+                       </execution>
+                     </executions>
+                   </plugin>
+       
+                       
+               <plugin>
+                       <groupId>org.sonatype.plugins</groupId>
+                       <artifactId>nexus-staging-maven-plugin</artifactId>
+                       <version>1.6.7</version>
+                       <extensions>true</extensions>
+                       <configuration>
+                       <serverId>ossrhdme</serverId>
+                       <nexusUrl>https://oss.sonatype.org/</nexusUrl>
+                       <autoReleaseAfterClose>true</autoReleaseAfterClose>
+                       </configuration>
+               </plugin>
+
+
+       </plugins>
+</build>
+
+<distributionManagement>
+               <snapshotRepository>
+                       <id>ossrhdme</id>
+                       <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+               </snapshotRepository>
+               <repository>
+                       <id>ossrhdme</id>
+                       <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
+               </repository>
+       </distributionManagement>
+       
+       <scm>
+               <connection>https://github.com/att/AAF.git</connection>
+               <developerConnection>${project.scm.connection}</developerConnection>
+               <url>http://github.com/att/AAF/tree/master</url>
+       </scm>
+
+       <modules>
+               <module>env</module>
+               <module>xgen</module>
+               <module>rosetta</module>
+
+               <!-- 
+               <module>persist</module>
+               <module>fsdb</module>
+               <module>rosetta</module>
+               <module>persist-fsdb</module>
+               <module>rmodel</module>
+               <module>rclient</module>
+               <module>rserv</module>
+               <module>fsdbrserv</module>
+               <module>guigen</module>
+               <module>mdgui</module>
+               <module>poll</module>
+               <module>ngreq</module>
+               <module>lpeer</module>
+                -->
+               <module>log4j</module>
+       </modules>
+
+       <dependencyManagement>
+               <dependencies>
+                       <dependency>
+                               <groupId>com.att.cadi</groupId>
+                               <artifactId>cadi-core</artifactId>
+                               <version>${project.cadiVersion}</version>
+                       </dependency>
+                       <dependency>
+                               <groupId>com.att.cadi</groupId>
+                               <artifactId>cadi-aaf</artifactId>
+                               <version>${project.cadiVersion}</version>
+                       </dependency>
+                       <dependency>
+                               <groupId>log4j</groupId>
+                               <artifactId>log4j</artifactId>
+                               <version>1.2.17</version>
+                       </dependency>
+                       <dependency>
+                               <groupId>org.slf4j</groupId>
+                               <artifactId>slf4j-log4j12</artifactId>
+                               <version>1.7.5</version>
+                       </dependency>
+               </dependencies>
+       </dependencyManagement>
+
+
+</project>
diff --git a/rosetta/.gitignore b/rosetta/.gitignore
new file mode 100644 (file)
index 0000000..cf85207
--- /dev/null
@@ -0,0 +1,5 @@
+/bin/
+/target/
+/.classpath
+/.project
+.settings
diff --git a/rosetta/pom.xml b/rosetta/pom.xml
new file mode 100644 (file)
index 0000000..b073fcb
--- /dev/null
@@ -0,0 +1,225 @@
+<!--\r
+  ============LICENSE_START====================================================\r
+  * org.onap.aai\r
+  * ===========================================================================\r
+  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+  * Copyright © 2017 Amdocs\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
+  * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+  *\r
+-->\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
+<parent>\r
+               <groupId>com.att.inno</groupId>\r
+               <artifactId>parent</artifactId>\r
+               <version>1.2.13</version>\r
+               <relativePath>..</relativePath>\r
+       </parent>\r
+       \r
+       <name>Rosetta</name>\r
+       <artifactId>rosetta</artifactId>\r
+       <packaging>jar</packaging>\r
+       <modelVersion>4.0.0</modelVersion>\r
+       <url>https://github.com/att/AAF</url>\r
+       <description>INNO</description>\r
+       <licenses>\r
+               <license>\r
+               <name>BSD License</name>\r
+               <url> </url>\r
+               </license>\r
+       </licenses>\r
+\r
+       <developers>\r
+               <developer>\r
+               <name>Jonathan Gathman</name>\r
+               <email></email>\r
+       <organization>ATT</organization>\r
+       <organizationUrl></organizationUrl>\r
+               </developer>\r
+       </developers>\r
+\r
+       <dependencies>\r
+               <dependency>\r
+                       <groupId>com.att.inno</groupId>\r
+                       <artifactId>env</artifactId>\r
+                       <version>${project.version}</version>\r
+               </dependency>\r
+               \r
+               <!-- dependency>\r
+                       <groupId>com.att.cadi</groupId>\r
+                       <artifactId>cadi-core</artifactId>\r
+                       <scope>compile</scope>\r
+               </dependency>\r
+               <dependency>\r
+                       <groupId>com.att.aft</groupId>\r
+                       <artifactId>dme2</artifactId>\r
+                       <scope>provided</scope>\r
+               </dependency-->\r
+               \r
+       </dependencies>\r
+\r
+       <distributionManagement>\r
+               <snapshotRepository>\r
+                       <id>ossrhdme</id>\r
+                       <url>https://oss.sonatype.org/content/repositories/snapshots</url>\r
+               </snapshotRepository>\r
+               <repository>\r
+                       <id>ossrhdme</id>\r
+                       <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>\r
+               </repository>\r
+       </distributionManagement>\r
+       \r
+       <scm>\r
+               <connection>https://github.com/att/AAF.git</connection>\r
+               <developerConnection>${project.scm.connection}</developerConnection>\r
+               <url>http://github.com/att/AAF/tree/master</url>\r
+       </scm>\r
+       \r
+       <build>\r
+               <plugins>\r
+                       <plugin>\r
+                               <groupId>org.codehaus.mojo</groupId>\r
+                               <artifactId>jaxb2-maven-plugin</artifactId>\r
+                               <version>1.3</version>\r
+                               <executions>\r
+                                       <execution>\r
+                                               <goals>\r
+                                                       <goal>xjc</goal>\r
+                                               </goals>\r
+                                       </execution>\r
+                               </executions>\r
+                               <configuration>\r
+                                       <schemaDirectory>src/main/xsd</schemaDirectory>\r
+                               </configuration>\r
+                       </plugin>\r
+\r
+                       <plugin>\r
+                               <groupId>org.apache.maven.plugins</groupId>\r
+                               <artifactId>maven-jar-plugin</artifactId>\r
+                               <configuration>\r
+                                       <outputDirectory>target</outputDirectory>\r
+                                       <includes>\r
+                                               <include>**/com/att/rosetta/**</include>\r
+                                       </includes>\r
+                               </configuration>\r
+                       </plugin>\r
+               <!--    <plugin>\r
+                               <groupId>org.apache.maven.plugins</groupId>\r
+                               <artifactId>maven-source-plugin</artifactId>\r
+                               <version>2.4</version>\r
+                               <configuration>\r
+                                       <outputDirectory>target</outputDirectory>\r
+                                       <skipSource>false</skipSource>\r
+                                       <attach>false</attach>\r
+                                       <forceCreation>true</forceCreation>\r
+                                       <useDefaultManifestFile>true</useDefaultManifestFile>\r
+                               </configuration>\r
+                       </plugin>  -->\r
+\r
+                       <!-- plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> \r
+                               <archive> <manifest> <mainClass>com.att.rest.Main</mainClass> </manifest> \r
+                               </archive> <descriptorRefs> <discriptorRef>jar-with-dependencies</discriptorRef> \r
+                               <filters> </filters> </descriptorRefs> </configuration> </plugin -->\r
+                       <plugin>\r
+                               <groupId>org.apache.maven.plugins</groupId>\r
+                               <artifactId>maven-deploy-plugin</artifactId>\r
+                               <version>2.6</version>\r
+                               <configuration>\r
+                                       <skip>false</skip>\r
+                               </configuration>\r
+                       </plugin>\r
+                       \r
+                       <plugin>\r
+                       <groupId>org.apache.maven.plugins</groupId>\r
+                       <artifactId>maven-javadoc-plugin</artifactId>\r
+                       <configuration>\r
+                       <failOnError>false</failOnError>\r
+                       </configuration>\r
+                       <executions>\r
+                               <execution>\r
+                                       <id>attach-javadocs</id>\r
+                                       <goals>\r
+                                               <goal>jar</goal>\r
+                                       </goals>\r
+                               </execution>\r
+                       </executions>\r
+               </plugin> \r
+          \r
+          \r
+              <plugin>\r
+                     <groupId>org.apache.maven.plugins</groupId>\r
+                     <artifactId>maven-source-plugin</artifactId>\r
+                     <version>2.2.1</version>\r
+                     <executions>\r
+                       <execution>\r
+                         <id>attach-sources</id>\r
+                         <goals>\r
+                           <goal>jar-no-fork</goal>\r
+                         </goals>\r
+                       </execution>\r
+                     </executions>\r
+                   </plugin>\r
+\r
+                       \r
+               <plugin>\r
+                       <groupId>org.sonatype.plugins</groupId>\r
+                       <artifactId>nexus-staging-maven-plugin</artifactId>\r
+                       <version>1.6.7</version>\r
+                       <extensions>true</extensions>\r
+                       <configuration>\r
+                       <serverId>ossrhdme</serverId>\r
+                       <nexusUrl>https://oss.sonatype.org/</nexusUrl>\r
+                       <autoReleaseAfterClose>true</autoReleaseAfterClose>\r
+                       </configuration>\r
+               </plugin>\r
+                       \r
+                       <!--This plugin's configuration is used to store Eclipse m2e settings \r
+                               only. It has no influence on the Maven build itself. -->\r
+                       <plugin>\r
+                               <groupId>org.eclipse.m2e</groupId>\r
+                               <artifactId>lifecycle-mapping</artifactId>\r
+                               <version>1.0.0</version>\r
+                               <configuration>\r
+                                       <lifecycleMappingMetadata>\r
+                                               <pluginExecutions>\r
+                                                       <pluginExecution>\r
+                                                               <pluginExecutionFilter>\r
+                                                                       <groupId>\r
+                                                                               org.codehaus.mojo\r
+                                                                       </groupId>\r
+                                                                       <artifactId>\r
+                                                                               jaxb2-maven-plugin\r
+                                                                       </artifactId>\r
+                                                                       <versionRange>\r
+                                                                               [1.3,)\r
+                                                                       </versionRange>\r
+                                                                       <goals>\r
+                                                                               <goal>xjc</goal>\r
+                                                                       </goals>\r
+                                                               </pluginExecutionFilter>\r
+                                                               <action>\r
+                                                                       <ignore></ignore>\r
+                                                               </action>\r
+                                                       </pluginExecution>\r
+                                               </pluginExecutions>\r
+                                       </lifecycleMappingMetadata>\r
+                               </configuration>\r
+                       </plugin>\r
+               </plugins>\r
+</build>\r
+       \r
+</project>\r
diff --git a/rosetta/src/main/java/com/att/rosetta/InJson.java b/rosetta/src/main/java/com/att/rosetta/InJson.java
new file mode 100644 (file)
index 0000000..9462e67
--- /dev/null
@@ -0,0 +1,156 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+import java.io.IOException;\r
+import java.io.Reader;\r
+\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.TimeTaken;\r
+import com.att.rosetta.InJson.State;\r
+\r
+public class InJson implements Parse<Reader, State> {\r
+       public Parsed<State> parse(Reader r, Parsed<State> parsed) throws ParseException {\r
+               // First things first, if there's a "leftover" event, process that immediately\r
+               State state = (State)parsed.state;\r
+               if(state.unsent > 0) {\r
+                       parsed.event = state.unsent;\r
+                       state.unsent = 0;\r
+                       return parsed;\r
+               }\r
+               \r
+               int ch;\r
+               char c;\r
+               StringBuilder sb = parsed.sb;\r
+               boolean inQuotes = false, escaped = false;\r
+               boolean go = true;\r
+               try {\r
+                       // Gather data from Reader, looking for special characters when not in Quotes\r
+                       while(go && (ch=r.read())>=0) {\r
+                               if(state.braces>=0 || ch==Parse.START_OBJ) { // ignore garbage/whitespace before content\r
+                                       c=(char)ch;\r
+                                       // Character is a quote.  \r
+                                       if(c=='"') {\r
+                                               if(inQuotes) {\r
+                                                       if(escaped) {  // if escaped Quote, add to data.\r
+                                                               sb.append(c);\r
+                                                               escaped = false;\r
+                                                       } else {\r
+                                                               inQuotes = false;\r
+                                                       }\r
+                                               } else {\r
+                                                       parsed.isString=true;\r
+                                                       inQuotes = true;\r
+                                               }\r
+                                       } else { // Not a Quote\r
+                                               if(inQuotes) {\r
+                                                       if(c=='\\') {\r
+                                                               if(escaped) {\r
+                                                                       sb.append("\\\\");\r
+                                                                       escaped = false;\r
+                                                               } else {\r
+                                                                       escaped = true;\r
+                                                               }\r
+                                                       } else {\r
+                                                               sb.append(c);\r
+                                                       }\r
+                                               } else {\r
+                                                       switch(c) {\r
+                                                               case ':':\r
+                                                                       parsed.dataIsName();\r
+                                                                       parsed.isString = false;\r
+                                                                       break;\r
+                                                               case Parse.START_OBJ:\r
+                                                                       if(state.braces++ == 0) {\r
+                                                                               parsed.event = START_DOC;\r
+                                                                               state.unsent = c;\r
+                                                                       } else {\r
+                                                                               parsed.event = c;\r
+                                                                       }\r
+                                                                       go = false;\r
+                                                                       break;\r
+                                                               case Parse.END_OBJ:\r
+                                                                       if(--state.braces == 0) {\r
+                                                                               parsed.event = c;\r
+                                                                               state.unsent = END_DOC;\r
+                                                                       } else {\r
+                                                                               parsed.event = c;\r
+                                                                       }\r
+                                                                       go = false;\r
+                                                                       break;\r
+                                                               // These three end the data gathering, and send it along with the event that is ending the data gathering\r
+                                                               case Parse.NEXT:\r
+                                                                       if(parsed.name.startsWith("__")) {\r
+                                                                               parsed.event = Parse.ATTRIB;\r
+                                                                               parsed.name = parsed.name.substring(2);\r
+                                                                       } else {\r
+                                                                               parsed.event = c;\r
+                                                                       }\r
+                                                                       go = false;\r
+                                                                       break;\r
+                                                               case Parse.START_ARRAY:\r
+                                                               case Parse.END_ARRAY:\r
+                                                                       parsed.event = c;\r
+                                                                       go = false;\r
+                                                                       break;\r
+                                                                               \r
+                                                               // The Escape Sequence, for Quote marks within Quotes\r
+                                                               case '\\':\r
+                                                               // Ignore these, unless within quotes, at which point data-gather\r
+                                                               case ' ':\r
+                                                               case '\b':\r
+                                                               case '\f':\r
+                                                               case '\n':\r
+                                                               case '\r':\r
+                                                               case '\t':\r
+                                                                       break;\r
+                                                               // Normal data... gather it\r
+                                                               default:\r
+                                                                       sb.append(c);\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       return parsed;\r
+               } catch (IOException e) {\r
+                       throw new ParseException(e);\r
+               }\r
+       }\r
+\r
+       public static class State {\r
+               public int braces = 0;\r
+               public char unsent = 0;\r
+       }\r
+       \r
+//     @Override\r
+       public Parsed<State> newParsed() {\r
+               return new Parsed<State>(new State()); // no State needed\r
+       }\r
+\r
+//     @Override\r
+       public TimeTaken start(Env env) {\r
+               return env.start("Rosetta JSON In", Env.JSON);\r
+       }\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/InXML.java b/rosetta/src/main/java/com/att/rosetta/InXML.java
new file mode 100644 (file)
index 0000000..1c56e14
--- /dev/null
@@ -0,0 +1,488 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+import java.io.IOException;\r
+import java.io.Reader;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Stack;\r
+\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.TimeTaken;\r
+import com.att.rosetta.InXML.State;\r
+\r
+public class InXML implements Parse<Reader, State> {\r
+       // package on purpose\r
+       JaxInfo jaxInfo;\r
+\r
+       public InXML(JaxInfo jaxInfo) {\r
+               this.jaxInfo = jaxInfo;\r
+       }\r
+       \r
+       public InXML(Class<?> cls, String ... rootNs) throws SecurityException, NoSuchFieldException, ClassNotFoundException, ParseException {\r
+               jaxInfo = JaxInfo.build(cls,rootNs);\r
+       }\r
+\r
+\r
+       // @Override\r
+       public Parsed<State> parse(Reader r, Parsed<State> parsed) throws ParseException {\r
+               State state = parsed.state;\r
+               \r
+               // OK, before anything else, see if there is leftover processing, if so, do it!\r
+               if(state.unevaluated!=null) {\r
+                       DerTag dt = state.unevaluated;\r
+                       state.unevaluated = null;\r
+                       if(!state.greatExp.eval(parsed, dt))return parsed;\r
+               }\r
+\r
+               if(state.hasAttributes()) {\r
+                       Prop prop = state.pop();\r
+                       parsed.event = Parse.ATTRIB;\r
+                       parsed.name = prop.tag;\r
+                       parsed.sb.append(prop.value);\r
+                       parsed.isString=true;\r
+                       return parsed;\r
+               }\r
+               int ch;\r
+               char c;\r
+               boolean inQuotes = false, escaped = false;\r
+\r
+               StringBuilder sb = parsed.sb, tempSB = new StringBuilder();\r
+               boolean go = true;\r
+               \r
+               try {\r
+                       while(go && (ch=r.read())>=0) {\r
+                               c = (char)ch;\r
+                               if(c == '"') {\r
+                                       if(state.greatExp instanceof LeafExpectations) { // within a set of Tags, make a Quote\r
+                                               sb.append(c);\r
+                                       } else {\r
+                                               if(inQuotes) {\r
+                                                       if(escaped) {\r
+                                                               sb.append('\\');\r
+                                                               sb.append(c);\r
+                                                               escaped = false;\r
+                                                       } else {\r
+                                                               inQuotes = false;\r
+                                                       }\r
+                                               } else {\r
+                                                       parsed.isString=true;\r
+                                                       inQuotes = true;\r
+                                               }\r
+                                       }\r
+                               } else if(inQuotes) {\r
+                                       sb.append(c);\r
+                               } else if(c=='&') {\r
+                                       XmlEscape.xmlEscape(sb,r);\r
+                               } else {\r
+                                       switch(c) {\r
+                                               case '<':\r
+                                                       DerTag tag=new DerTag().parse(r, tempSB);\r
+                                                       go = state.greatExp.eval(parsed, tag);\r
+                                                       break;\r
+                                               default:\r
+                                                       // don't add Whitespace to start of SB... saves removing later\r
+                                                       if(sb.length()>0) {\r
+                                                               sb.append(c);\r
+                                                       } else if(!Character.isWhitespace(c)) { \r
+                                                               sb.append(c);\r
+                                                       }\r
+                                               }\r
+                               }\r
+                       }\r
+                       return parsed;\r
+               } catch (IOException e) {\r
+                       throw new ParseException(e);\r
+               }\r
+       }\r
+       \r
+       public static final class DerTag {\r
+               public String name;\r
+               public boolean isEndTag;\r
+               public List<Prop> props;\r
+               private boolean isXmlInfo;\r
+               //private String ns; \r
+               \r
+               public DerTag() {\r
+                       name=null;\r
+                       isEndTag = false;\r
+                       props = null;\r
+                       isXmlInfo = false;\r
+               }\r
+               \r
+               public DerTag parse(Reader r, StringBuilder sb) throws ParseException {\r
+                       int ch;\r
+                       char c;\r
+                       boolean inQuotes = false, escaped = false;\r
+                       boolean go = true;\r
+                       String tag = null;\r
+                       \r
+                       try {\r
+                               if((ch = r.read())<0) throw new ParseException("Reader content ended before complete");\r
+                               if(ch=='?') {\r
+                                       isXmlInfo = true;\r
+                               }\r
+                               // TODO Check for !-- comments\r
+                               do {\r
+                                       c=(char)ch;\r
+                                       if(c=='"') {\r
+                                                       if(inQuotes) {\r
+                                                               if(escaped) {\r
+                                                                       sb.append(c);\r
+                                                                       escaped = false;\r
+                                                               } else {\r
+                                                                       inQuotes = false;\r
+                                                               }\r
+                                                       } else {\r
+                                                               inQuotes = true;\r
+                                                       }\r
+                                       } else if(inQuotes) {\r
+                                               sb.append(c);\r
+                                       } else {\r
+                                               switch(c) {\r
+                                                       case '/':\r
+                                                               isEndTag = true;\r
+                                                               break;\r
+                                                       case ' ':\r
+                                                               endField(tag,sb);\r
+                                                               tag = null;\r
+                                                               break;\r
+                                                       case '>':\r
+                                                               endField(tag,sb);\r
+                                                               go = false;\r
+                                                               break;\r
+                                                       case '=':\r
+                                                               tag = sb.toString();\r
+                                                               sb.setLength(0);\r
+                                                               break;\r
+//                                                     case ':':\r
+//                                                             ns = sb.toString();\r
+//                                                             sb.setLength(0);\r
+//                                                             break;\r
+                                                       case '?':\r
+                                                               if(!isXmlInfo)sb.append(c);\r
+                                                               break;\r
+                                                       default:\r
+                                                               sb.append(c);\r
+                                               }\r
+                                       }\r
+                               } while(go && (ch=r.read())>=0);\r
+                       } catch (IOException e) {\r
+                               throw new ParseException(e);\r
+                       }\r
+                       return this;\r
+               }\r
+\r
+               private void endField(String tag, StringBuilder sb) {\r
+                       if(name==null) {\r
+                               name = sb.toString();\r
+                               sb.setLength(0);\r
+                       } else {\r
+                               String value = sb.toString();\r
+                               sb.setLength(0);\r
+                               if(tag !=null && value != null) {\r
+                                       if(props==null)props = new ArrayList<Prop>();\r
+                                       props.add(new Prop(tag,value));\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               public String toString() {\r
+                       StringBuilder sb = new StringBuilder();\r
+                       sb.append(isEndTag?"End":"Start");\r
+                       sb.append(" Tag\n");\r
+                       sb.append("  Name: ");\r
+                       sb.append(name);\r
+                       if(props!=null) for(Prop p : props) {\r
+                               sb.append("\n     ");\r
+                               sb.append(p.tag);\r
+                               sb.append("=\"");\r
+                               sb.append(p.value);\r
+                               sb.append('"');\r
+                       }\r
+                       return sb.toString();\r
+               }\r
+       }\r
+       \r
+       private static class ArrayState {\r
+               public boolean firstObj = true;\r
+               public boolean didNext = false;\r
+       }\r
+\r
+       public static class State {\r
+               public GreatExpectations greatExp;\r
+               public DerTag unevaluated;\r
+               public Stack<ArrayState> arrayInfo;\r
+               private List<Prop> attribs;\r
+               private int idx;\r
+               public State(JaxInfo ji, DerTag dt) throws ParseException {\r
+                       greatExp = new RootExpectations(this, ji, null);\r
+                       unevaluated = null;\r
+                       attribs = null;;\r
+               }\r
+               \r
+               public boolean hasAttributes() {\r
+                       return attribs!=null && idx<attribs.size();\r
+               }\r
+\r
+               public void push(Prop prop) {\r
+                       if(attribs==null) {\r
+                               attribs = new ArrayList<Prop>();\r
+                               idx = 0;\r
+                       }\r
+                       attribs.add(prop);\r
+               }\r
+               \r
+               public Prop pop() {\r
+                       Prop rv = null;\r
+                       if(attribs!=null) {\r
+                               rv = attribs.get(idx++);\r
+                               if(idx>=attribs.size())attribs = null;\r
+                       }\r
+                       return rv;\r
+               }\r
+       }\r
+       \r
+       private static abstract class GreatExpectations {\r
+               protected JaxInfo ji;\r
+               protected GreatExpectations prev;\r
+               private Map<String,String> ns;\r
+               \r
+               public GreatExpectations(State state, JaxInfo curr, GreatExpectations prev, DerTag derTag) throws ParseException {\r
+                       this.prev = prev;\r
+                       ns = null;\r
+                       ji = getDerived(state, curr,derTag);\r
+               }\r
+               \r
+               public abstract boolean eval(Parsed<State> parsed, DerTag derTag) throws ParseException;\r
+\r
+               // Recursively look back for any namespaces\r
+               protected Map<String,String> getNS() {\r
+                       if(ns!=null)return ns;\r
+                       if(prev!=null) {\r
+                               return prev.getNS();\r
+                       }\r
+                       return null;\r
+               }\r
+\r
+               private void addNS(Prop prop) {\r
+                       Map<String,String> existingNS = getNS();\r
+                       if(ns==null)ns = new HashMap<String,String>();\r
+                       // First make a copy of previous NSs so that we have everything we need, but can overwrite, if necessary\r
+                       if(existingNS!=null && ns!=existingNS) {\r
+                               ns.putAll(ns);\r
+                       }\r
+                       ns.put(prop.tag, prop.value);\r
+               }\r
+\r
+               private JaxInfo getDerived(State state, JaxInfo ji, DerTag derTag) throws ParseException {\r
+                       if(derTag==null)return ji;\r
+                       \r
+                       List<Prop> props = derTag.props;\r
+                       \r
+                       Prop derived = null;\r
+                       if(props!=null) {\r
+                               // Load Namespaces (if any)\r
+                               for(Prop prop : props) {\r
+                                       if(prop.tag.startsWith("xmlns:")) {\r
+                                               addNS(prop);\r
+                                       }\r
+                               }\r
+                               for(Prop prop : props) {\r
+                                       if(prop.tag.endsWith(":type")) {\r
+                                               int idx = prop.tag.indexOf(':');\r
+                                               String potentialNS = "xmlns:"+prop.tag.substring(0,idx);\r
+                                               Map<String,String> ns = getNS();\r
+                                               boolean noNamespace = false;\r
+                                               if(ns==null) {\r
+                                                       noNamespace = true;\r
+                                               } else {\r
+                                                       String nsVal = ns.get(potentialNS);\r
+                                                       if(nsVal==null) noNamespace = true;\r
+                                                       else {\r
+                                                               derived = new Prop(Parsed.EXTENSION_TAG,prop.value);\r
+                                                               state.push(derived);\r
+                                                       }\r
+                                               }\r
+                                               if(noNamespace) {\r
+                                                       throw new ParseException(prop.tag + " utilizes an invalid Namespace prefix");\r
+                                               }\r
+                                       } else if(!prop.tag.startsWith("xmlns")) {\r
+                                               state.push(prop);\r
+                                       }\r
+                               }\r
+                       }\r
+                       return derived==null?ji:ji.getDerived(derived.value);\r
+               }\r
+       }\r
+       \r
+       private static class RootExpectations extends GreatExpectations {\r
+               \r
+               public RootExpectations(State state, JaxInfo curr, GreatExpectations prev) throws ParseException {\r
+                       super(state,curr,prev, null);\r
+               }\r
+               \r
+               // @Override\r
+               public boolean eval(Parsed<State> parsed, DerTag derTag) throws ParseException {\r
+                       if(derTag.isXmlInfo) {\r
+                               parsed.event = START_DOC;\r
+                       } else if(ji.name.equals(derTag.name)) {\r
+                               if(derTag.isEndTag) {\r
+                                       parsed.event = END_DOC;\r
+                                       parsed.state.greatExp = prev;\r
+                               } else {\r
+                                       //parsed.name = derTag.name;\r
+                                       parsed.event = START_OBJ;\r
+                                       parsed.state.greatExp = new ObjectExpectations(parsed.state,ji, this, false, derTag);   \r
+                               }\r
+                       }\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       private static class ObjectExpectations extends GreatExpectations {\r
+               private boolean printName;\r
+\r
+               public ObjectExpectations(State state, JaxInfo curr, GreatExpectations prev, boolean printName, DerTag derTag) throws ParseException {\r
+                       super(state, curr, prev, derTag);\r
+                       this.printName=printName;\r
+               }\r
+\r
+               // @Override\r
+               public boolean eval(Parsed<State> parsed, DerTag derTag) throws ParseException {\r
+                       if(derTag.isEndTag && ji.name.equals(derTag.name)) {\r
+                               parsed.state.greatExp = prev;\r
+                               parsed.event = END_OBJ;\r
+                               if(printName)parsed.name = ji.name;\r
+                       } else {\r
+                               //Standard Members\r
+                               for(JaxInfo memb : ji.members) {\r
+                                       if(memb.name.equals(derTag.name)) {\r
+                                               parsed.name = memb.name;\r
+                                               if(memb.isArray) {\r
+                                                       parsed.state.unevaluated = derTag; // evaluate within Array Context\r
+                                                       parsed.event = START_ARRAY;\r
+                                                       parsed.state.greatExp = new ArrayExpectations(parsed.state,memb,this);\r
+                                                       return false;\r
+                                               } else if(memb.isObject()) {\r
+                                                       if(derTag.isEndTag) {\r
+                                                               throw new ParseException("Unexpected End Tag </" + derTag.name + '>');\r
+                                                       } else {\r
+                                                               parsed.event = START_OBJ;\r
+\r
+                                                               parsed.state.greatExp = new ObjectExpectations(parsed.state, memb,this,true,derTag);\r
+                                                               return false;\r
+                                                       }\r
+                                               } else { // a leaf\r
+                                                       if(derTag.isEndTag) {\r
+                                                                throw new ParseException("Misplaced End Tag </" + parsed.name + '>');\r
+                                                       } else {\r
+                                                               parsed.state.greatExp = new LeafExpectations(parsed.state,memb, this);\r
+                                                               return true; // finish out Leaf without returning\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+                               throw new ParseException("Unexpected Tag <" + derTag.name + '>');\r
+                       }\r
+                       return false;\r
+               }\r
+       }\r
+       \r
+       private static class LeafExpectations extends GreatExpectations {\r
+               public LeafExpectations(State state, JaxInfo curr, GreatExpectations prev) throws ParseException {\r
+                       super(state, curr, prev, null);\r
+               }\r
+\r
+               // @Override\r
+               public boolean eval(Parsed<State> parsed, DerTag derTag) throws ParseException {\r
+                       if(ji.name.equals(derTag.name) && derTag.isEndTag) {\r
+                               parsed.event = NEXT;\r
+                               parsed.isString = ji.isString;\r
+                               parsed.state.greatExp = prev;\r
+                       } else {\r
+                               throw new ParseException("Expected </" + ji.name + '>');\r
+                       }\r
+                       return false;\r
+               }               \r
+       }\r
+\r
+       private static class ArrayExpectations extends GreatExpectations {\r
+               public ArrayExpectations(State state, JaxInfo ji, GreatExpectations prev) throws ParseException {\r
+                       super(state, ji, prev,null);\r
+                       if(state.arrayInfo==null)state.arrayInfo=new Stack<ArrayState>();\r
+                       state.arrayInfo.push(new ArrayState());\r
+               }\r
+               // @Override\r
+               public boolean eval(Parsed<State> parsed, DerTag derTag) throws ParseException {\r
+                       if(ji.name.equals(derTag.name) && !derTag.isEndTag) {\r
+                               if(ji.isObject()) {\r
+                                       if(derTag.isEndTag) {\r
+                                               throw new ParseException("Unexpected End Tag </" + derTag.name + '>');\r
+                                       } else {\r
+                                               ArrayState ai = parsed.state.arrayInfo.peek();  \r
+                                               if(ai.firstObj || ai.didNext) {\r
+                                                       ai.firstObj = false;\r
+                                                       ai.didNext = false;\r
+                                                       parsed.event = START_OBJ;\r
+                                                       parsed.name=derTag.name;\r
+                                                       parsed.state.greatExp = new ObjectExpectations(parsed.state,ji,this,true, derTag);\r
+                                               } else {\r
+                                                       ai.didNext = true;\r
+                                                       parsed.event = NEXT;\r
+                                                       parsed.state.unevaluated = derTag;\r
+                                               }\r
+                                       }\r
+                               } else { // a leave\r
+                                       if(derTag.isEndTag) {\r
+                                                throw new ParseException("Misplaced End Tag </" + parsed.name + '>');\r
+                                       } else {\r
+                                               parsed.state.greatExp = new LeafExpectations(parsed.state, ji, this);\r
+                                               return true; // finish out Leaf without returning\r
+                                       }\r
+                               }\r
+                       } else { // Tag now different... Array is done\r
+                               parsed.state.unevaluated = derTag;\r
+                               parsed.event=END_ARRAY;\r
+                               parsed.state.greatExp = prev;\r
+                               parsed.state.arrayInfo.pop();\r
+                       }\r
+                       return false;\r
+               }               \r
+       }\r
+       // @Override\r
+       public Parsed<State> newParsed() throws ParseException {\r
+               return new Parsed<State>(new State(jaxInfo, null));\r
+       }\r
+\r
+       // @Override\r
+       public TimeTaken start(Env env) {\r
+               return env.start("Rosetta XML In", Env.XML);\r
+       }\r
+       \r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/JaxEval.java b/rosetta/src/main/java/com/att/rosetta/JaxEval.java
new file mode 100644 (file)
index 0000000..72a89f2
--- /dev/null
@@ -0,0 +1,28 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+public interface JaxEval{\r
+       public abstract JaxEval eval(Parsed<?> p) throws ParseException;\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/JaxInfo.java b/rosetta/src/main/java/com/att/rosetta/JaxInfo.java
new file mode 100644 (file)
index 0000000..23785af
--- /dev/null
@@ -0,0 +1,250 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+import java.lang.reflect.Field;\r
+import java.lang.reflect.Type;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import javax.xml.bind.annotation.XmlElement;\r
+import javax.xml.bind.annotation.XmlRootElement;\r
+import javax.xml.bind.annotation.XmlSchema;\r
+import javax.xml.bind.annotation.XmlType;\r
+import javax.xml.datatype.XMLGregorianCalendar;\r
+\r
+public class JaxInfo {\r
+       private static final String DEFAULT = "##default";\r
+       public static final int DATA = 0;\r
+       public static final int ARRAY = 1;\r
+       public static final int OBJECT = 2;\r
+       \r
+       public final String name;\r
+       public final Class<?> clss;\r
+       public Map<String, JaxInfo> extensions; // Classes, which might be found at runtime, that extend this class.  Lazy Instantiation\r
+       public final JaxInfo[] members;\r
+       public final boolean isArray;\r
+       public final boolean isString;\r
+       public final boolean required;\r
+       public final boolean nillable;\r
+       public String ns;\r
+       public boolean isObject() {return members!=null;}\r
+       \r
+       private JaxInfo(String n, String ns, Class<?> c, JaxInfo[] members, boolean string, boolean array, boolean required, boolean nillable) {\r
+               name = n;\r
+               this.ns = ns;\r
+               clss = c;\r
+               this.members = members;\r
+               this.isString = string;\r
+               isArray = array;\r
+               this.required = required;\r
+               this.nillable = nillable;\r
+               extensions = null;\r
+       }\r
+       \r
+\r
+       public int getType() {\r
+               if(isArray)return ARRAY;\r
+               else if(members!=null)return OBJECT;\r
+               return DATA;\r
+       }\r
+       \r
+       public JaxInfo getDerived(String derivedName) {\r
+               JaxInfo derived;\r
+               // Lazy Instantiation\r
+               if(extensions == null) {\r
+                       extensions = new HashMap<String,JaxInfo>();\r
+                       derived = null;\r
+               } else {\r
+                       derived = extensions.get(derivedName);\r
+               }\r
+               \r
+               if(derived == null) {\r
+                       //TODO for the moment, Classes are in same package\r
+                       Package pkg = clss.getPackage();\r
+                       try {\r
+                               Class<?> dc = getClass().getClassLoader().loadClass(pkg.getName()+'.'+Character.toUpperCase(derivedName.charAt(0))+derivedName.substring(1));\r
+                               derived = JaxInfo.build(dc, this); // Use this JAXInfo's name so the tags are correct\r
+                               extensions.put(derivedName, derived);\r
+                       } catch (Exception e) {\r
+                               e.printStackTrace();\r
+                       }\r
+               }\r
+               return derived;\r
+       }\r
+\r
+       public static JaxInfo get(JaxInfo[] fields, String name) {\r
+               for(JaxInfo f : fields) {\r
+                       if(name.equals(f.name)) return f;\r
+               }\r
+               return null;\r
+       }\r
+\r
+       /**\r
+        * Build up JAXB Information (recursively)\r
+        * \r
+        * @param cls\r
+        * @param rootNns\r
+        * @return\r
+        * @throws SecurityException\r
+        * @throws NoSuchFieldException\r
+        * @throws ClassNotFoundException\r
+        * @throws ParseException\r
+        */\r
+       public static JaxInfo build(Class<?> cls, JaxInfo parent) throws NoSuchFieldException, ClassNotFoundException, ParseException {\r
+               return new JaxInfo(parent.name,parent.ns, cls,buildFields(cls,parent.ns),parent.isString, parent.isArray,parent.required,parent.nillable);\r
+       }\r
+       /**\r
+        * Build up JAXB Information (recursively)\r
+        * \r
+        * @param cls\r
+        * @param rootNns\r
+        * @return\r
+        * @throws SecurityException\r
+        * @throws NoSuchFieldException\r
+        * @throws ClassNotFoundException\r
+        * @throws ParseException\r
+        */\r
+       public static JaxInfo build(Class<?> cls, String ... rootNns) throws SecurityException, NoSuchFieldException, ClassNotFoundException, ParseException {\r
+               String defaultNS;\r
+               if(rootNns.length>0 && rootNns[0]!=null) {\r
+                       defaultNS = rootNns[0];\r
+               } else {\r
+                       Package pkg = cls.getPackage();\r
+                       XmlSchema xs = pkg.getAnnotation(XmlSchema.class);\r
+                       defaultNS = xs==null?"":xs.namespace();\r
+               }\r
+               String name;\r
+               if(rootNns.length>1) {\r
+                       name = rootNns[1];\r
+               } else {\r
+                       XmlRootElement xre = cls.getAnnotation(XmlRootElement.class);\r
+                       if(xre!=null) {\r
+                               name = xre.name();\r
+                       } else {\r
+                               XmlType xt = cls.getAnnotation(XmlType.class);\r
+                               if(xt!=null) {\r
+                                       name=xt.name();\r
+                               } else {\r
+                                       throw new ParseException("Need a JAXB Object with XmlRootElement, or stipulate in parms");\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               return new JaxInfo(name,defaultNS, cls,buildFields(cls,defaultNS),false,false,false,false);\r
+       }\r
+       \r
+       // Build up the name and members of this particular class\r
+       // This is recursive, if a member is a JAXB Object as well.\r
+       private static JaxInfo[] buildFields(Class<?> clazz, String defaultNS) throws SecurityException, NoSuchFieldException, ClassNotFoundException {\r
+               ArrayList<JaxInfo> fields = null; // allow for lazy instantiation, because many structures won't have XmlType\r
+               Class<?> cls = clazz;\r
+               // Build up Method names from JAXB Annotations\r
+               XmlType xt;\r
+               while((xt = cls.getAnnotation(XmlType.class))!=null) {\r
+                       if(fields==null)fields = new ArrayList<JaxInfo>();\r
+                       for(String field : xt.propOrder()) {\r
+                               if("".equals(field)) break; // odd bug.  "" returned when no fields exist, rather than empty array\r
+                               Field rf = cls.getDeclaredField(field);\r
+                               Class<?> ft = rf.getType();\r
+                               \r
+                               boolean required = false;\r
+                               boolean nillable = false;\r
+                               String xmlName = field;\r
+                               String namespace = defaultNS;\r
+                               \r
+                               XmlElement xe = rf.getAnnotation(XmlElement.class);\r
+                               if(xe!=null) {\r
+                                       xmlName=xe.name();\r
+                                       required = xe.required();\r
+                                       nillable = false;\r
+                                       if(DEFAULT.equals(xmlName)) {\r
+                                               xmlName = field;\r
+                                       }\r
+                                       namespace = xe.namespace();\r
+                                       if(DEFAULT.equals(namespace)) {\r
+                                               namespace = defaultNS;\r
+                                       }\r
+                               }\r
+                               // If object is a List, then it is possible multiple, per XML/JAXB evaluation\r
+                               if(ft.isAssignableFrom(List.class)) {\r
+                                       Type t = rf.getGenericType();\r
+                                       String classname = t.toString();\r
+                                       int start = classname.indexOf('<');\r
+                                       int end = classname.indexOf('>');\r
+                                       Class<?> genClass = Class.forName(classname.substring(start+1, end));\r
+                                       xe = genClass.getAnnotation(XmlElement.class);\r
+                                       if(xe!=null && !DEFAULT.equals(xe.namespace())) {\r
+                                               namespace = xe.namespace();\r
+                                       }\r
+                                       // add recursed recursed member, marked as array\r
+                                       fields.add(new JaxInfo(xmlName,namespace,genClass,buildFields(genClass,namespace), genClass.equals(String.class),true,required,nillable));\r
+                               } else {\r
+                                       boolean isString = ft.equals(String.class) || ft.equals(XMLGregorianCalendar.class);\r
+                                       // add recursed member\r
+                                       fields.add(new JaxInfo(xmlName,namespace,ft,buildFields(ft,namespace),isString,false,required,nillable));\r
+                               }\r
+                       }\r
+                       cls = cls.getSuperclass();\r
+               };\r
+               if(fields!=null) {\r
+                       JaxInfo[] rv = new JaxInfo[fields.size()];\r
+                       fields.toArray(rv);\r
+                       return rv;\r
+               } else {\r
+                       return null;\r
+               }\r
+       }\r
+\r
+\r
+       public StringBuilder dump(StringBuilder sb, int idx) {\r
+               for(int i=0;i<idx;++i)sb.append(' ');\r
+               sb.append("Field ");\r
+               sb.append(name);\r
+               sb.append(" [");\r
+               sb.append(clss.getName());\r
+               sb.append("] ");\r
+               if(isArray)sb.append(" (array)");\r
+               if(required)sb.append(" (required)");\r
+               if(nillable)sb.append(" (nillable)");\r
+               if(members!=null) {\r
+                       for(JaxInfo f : members) {\r
+                               sb.append('\n');\r
+                               f.dump(sb,idx+2);\r
+                       }\r
+               }\r
+               return sb;\r
+       }\r
+\r
+       public String toString() {\r
+               StringBuilder sb = new StringBuilder();\r
+               sb.append("Structure of ");\r
+               sb.append(clss.getName());\r
+               sb.append('\n');\r
+               dump(sb,2);\r
+               return sb.toString();\r
+       }\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/JaxSet.java b/rosetta/src/main/java/com/att/rosetta/JaxSet.java
new file mode 100644 (file)
index 0000000..515c2c1
--- /dev/null
@@ -0,0 +1,92 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+import java.lang.reflect.Method;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import java.util.TreeMap;\r
+\r
+import javax.xml.bind.annotation.XmlType;\r
+\r
+/**\r
+ * For specific XML class, quickly find a Setter Method which will load the object\r
+ * \r
+ * Object type of Setter must match String at this time.\r
+ * \r
+ *\r
+ * @param <T>\r
+ */\r
+public class JaxSet<T> {\r
+       private static Map<Class<?>,JaxSet<?>> jsets = new HashMap<Class<?>,JaxSet<?>>();\r
+       private Map<String,Setter<T>> members;\r
+\r
+       private JaxSet(Class<?> cls) {\r
+               members = new TreeMap<String, Setter<T>>();\r
+               XmlType xmltype = cls.getAnnotation(XmlType.class);\r
+               Class<?> paramType[] = new Class[] {String.class};\r
+               for(String str : xmltype.propOrder()) {\r
+                       try {\r
+                               String setName = "set" + Character.toUpperCase(str.charAt(0)) + str.subSequence(1, str.length());\r
+                               Method meth = cls.getMethod(setName,paramType );\r
+                               if(meth!=null) {\r
+                                       members.put(str, new Setter<T>(meth) {\r
+                                               public void set(T o, Object t) throws ParseException {\r
+                                                       try {\r
+                                                               this.meth.invoke(o, t);\r
+                                                       } catch (Exception e) {\r
+                                                               throw new ParseException(e);\r
+                                                       }\r
+                                               }\r
+                                       });\r
+                               }\r
+                       } catch (Exception e) {\r
+                               // oops\r
+                       }\r
+               }\r
+       }\r
+       \r
+       public static abstract class Setter<O> {\r
+               protected final Method meth;\r
+               public Setter(Method meth) {\r
+                       this.meth = meth;\r
+               }\r
+               public abstract void set(O o, Object obj) throws ParseException;\r
+       }\r
+\r
+       public static <X> JaxSet<X> get(Class<?> cls) {\r
+               synchronized(jsets) {\r
+                       @SuppressWarnings("unchecked")\r
+                       JaxSet<X> js = (JaxSet<X>)jsets.get(cls);\r
+                       if(js == null) {\r
+                               jsets.put(cls, js = new JaxSet<X>(cls));\r
+                       }\r
+                       return js;\r
+               }\r
+       }\r
+\r
+       public Setter<T> get(String key) {\r
+               return members.get(key);\r
+       }\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/Ladder.java b/rosetta/src/main/java/com/att/rosetta/Ladder.java
new file mode 100644 (file)
index 0000000..95f5174
--- /dev/null
@@ -0,0 +1,114 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+\r
+/**\r
+ * A Ladder is a Stack like Storage Class, but where you can ascend and descend while\r
+ * the elements exists.\r
+ * \r
+ * Like an extension ladder, you can make taller as you go\r
+ * \r
+ *\r
+ */\r
+public class Ladder<T> {\r
+       public static final int DEFAULT_INIT_SIZE=8;\r
+       private final int init_size;\r
+       private int rung; // as in ladder\r
+       private Object[] struts;\r
+\r
+       public Ladder() {\r
+               rung=0;\r
+               init_size = DEFAULT_INIT_SIZE;\r
+               struts=new Object[init_size];\r
+       }\r
+\r
+       public Ladder(int initSize) {\r
+               rung=0;\r
+               init_size = initSize;\r
+               struts=new Object[init_size];\r
+       }\r
+\r
+       public void bottom() {\r
+               rung = 0;\r
+       }\r
+       \r
+       public void top() {\r
+               rung = struts.length-1;\r
+               while(rung>0 && struts[rung]==null)--rung;\r
+       }\r
+       \r
+       public int howHigh() {\r
+               return rung;\r
+       }\r
+       \r
+       public void jumpTo(int rung) {\r
+               if(rung>=struts.length) {\r
+                       Object[] temp = new Object[init_size*((rung/init_size)+1)];\r
+                       System.arraycopy(struts, 0, temp, 0, struts.length);\r
+                       struts = temp;\r
+               }\r
+               this.rung = rung;\r
+       }\r
+       \r
+       public int height() {\r
+               return struts.length;\r
+       }\r
+       \r
+       public void cutTo(int rungs) {\r
+               Object[] temp = new Object[rungs];\r
+               System.arraycopy(struts, 0, temp, 0, Math.min(rungs, struts.length));\r
+               struts = temp;\r
+       }\r
+       \r
+       public void ascend() {\r
+               ++rung;\r
+               if(rung>=struts.length) {\r
+                       Object[] temp = new Object[struts.length+init_size];\r
+                       System.arraycopy(struts, 0, temp, 0, struts.length);\r
+                       struts = temp;\r
+               }\r
+       }\r
+       \r
+       public void descend() {\r
+               --rung;\r
+       }\r
+       \r
+       @SuppressWarnings("unchecked")\r
+       public T peek() {\r
+               return (T)struts[rung];\r
+       }\r
+       \r
+       public void push(T t) {\r
+               struts[rung]=t;\r
+       }\r
+       \r
+       @SuppressWarnings("unchecked")\r
+       public T pop() {\r
+               T t = (T)struts[rung];\r
+               struts[rung]=null;\r
+               return t;\r
+       }\r
+\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/Marshal.java b/rosetta/src/main/java/com/att/rosetta/Marshal.java
new file mode 100644 (file)
index 0000000..52c97c6
--- /dev/null
@@ -0,0 +1,83 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+import java.util.Iterator;\r
+\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.TimeTaken;\r
+\r
+public abstract class Marshal<T> implements Parse<T, Marshal.State> {\r
+\r
+       /* (non-Javadoc)\r
+        * @see com.att.rosetta.Parse#newParsed()\r
+        */\r
+       @Override\r
+       public Parsed<State> newParsed() throws ParseException {\r
+               return new Parsed<State>(new State());\r
+       }\r
+\r
+       @Override\r
+       public TimeTaken start(Env env) {\r
+               //TODO is a way to mark not-JSON?\r
+               return env.start("Rosetta Marshal", Env.JSON);\r
+       };\r
+\r
+       public static class State {\r
+               // Note:  Need a STATEFUL stack... one that will remain stateful until marked as finished\r
+               // "finished" is know by Iterators with no more to do/null\r
+               // Thus the concept of "Ladder", which one ascends and decends\r
+               public Ladder<Iterator<?>> ladder = new Ladder<Iterator<?>>();\r
+               public boolean smallest = true;\r
+       }\r
+\r
+       public static final Iterator<Void> DONE_ITERATOR = new Iterator<Void>() {\r
+               @Override\r
+               public boolean hasNext() {\r
+                       return false;\r
+               }\r
+\r
+               @Override\r
+               public Void next() {\r
+                       return null;\r
+               }\r
+\r
+               @Override\r
+               public void remove() {\r
+               }\r
+       };\r
+\r
+       /**\r
+        * Typical definition of Done is when Iterator in Ladder is "DONE_ITERATOR"\r
+        * \r
+        * It is important, however, that the "Ladder Rung" is set to the right level.\r
+        * \r
+        * @param state\r
+        * @return\r
+        */\r
+       public boolean amFinished(State state) {\r
+               return DONE_ITERATOR.equals(state.ladder.peek());\r
+       }\r
+\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/Nulls.java b/rosetta/src/main/java/com/att/rosetta/Nulls.java
new file mode 100644 (file)
index 0000000..74cc56e
--- /dev/null
@@ -0,0 +1,68 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+import java.io.IOException;\r
+import java.io.Reader;\r
+import java.io.Writer;\r
+\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.TimeTaken;\r
+\r
+public class Nulls {\r
+       public static final Parse<Reader, ?> IN = new Parse<Reader, Void>() {\r
+\r
+               // @Override\r
+               public Parsed<Void> parse(Reader r, Parsed<Void> parsed)throws ParseException {\r
+                       parsed.event = Parse.END_DOC;\r
+                       return parsed;\r
+               }\r
+\r
+               // @Override\r
+               public Parsed<Void> newParsed() {\r
+                       Parsed<Void> parsed = new Parsed<Void>();\r
+                       parsed.event = Parse.END_DOC;\r
+                       return parsed;\r
+               }\r
+\r
+               // @Override\r
+               public TimeTaken start(Env env) {\r
+                       return env.start("IN", Env.SUB);\r
+               }\r
+               \r
+       };\r
+       \r
+       public static final Out OUT = new Out() {\r
+\r
+               // @Override\r
+               public <IN,S> void extract(IN in, Writer writer, Parse<IN, S> parse, boolean ... options)throws IOException, ParseException {\r
+               }\r
+               @Override\r
+               public String logName() {\r
+                       return "Rosetta NULL";\r
+               }\r
+\r
+\r
+       };\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/Out.java b/rosetta/src/main/java/com/att/rosetta/Out.java
new file mode 100644 (file)
index 0000000..c2ad448
--- /dev/null
@@ -0,0 +1,45 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.io.OutputStreamWriter;\r
+import java.io.Writer;\r
+\r
+public abstract class Out {\r
+       public abstract<IN,S> void extract(IN in, Writer writer, Parse<IN, S> parse, boolean ... options) throws IOException, ParseException;\r
+       \r
+       public<IN,S> void extract(IN in, OutputStream os, Parse<IN, S> parse, boolean ... options) throws IOException, ParseException {\r
+               Writer w = new OutputStreamWriter(os);\r
+               try {\r
+                       extract(in, w, parse, options);\r
+               } finally {\r
+                       w.flush();\r
+               }\r
+       }\r
+       \r
+       public abstract String logName();\r
+       \r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/OutJax.java b/rosetta/src/main/java/com/att/rosetta/OutJax.java
new file mode 100644 (file)
index 0000000..ec04f43
--- /dev/null
@@ -0,0 +1,54 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+import java.io.IOException;\r
+import java.io.Writer;\r
+\r
+public class OutJax extends Out {\r
+       private JaxEval jaxEval;\r
+\r
+       public OutJax(JaxEval je) {\r
+               this.jaxEval = je;\r
+       }\r
+\r
+       @Override\r
+       public <IN,S> void extract(IN in, Writer writer, Parse<IN, S> parse, boolean... options) throws IOException, ParseException {\r
+               Parsed<S> p = parse.newParsed();\r
+               JaxEval je = this.jaxEval;\r
+               while((p = parse.parse(in,p.reuse())).valid()) {\r
+                       if(je==null)throw new ParseException("Incomplete content");\r
+                       je = je.eval(p);\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public String logName() {\r
+               return "Rosetta JAX";\r
+       }\r
+\r
+\r
+\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/OutJson.java b/rosetta/src/main/java/com/att/rosetta/OutJson.java
new file mode 100644 (file)
index 0000000..98dd162
--- /dev/null
@@ -0,0 +1,234 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+import java.io.IOException;\r
+import java.io.Writer;\r
+import java.util.Stack;\r
+\r
+import com.att.inno.env.util.IndentPrintWriter;\r
+\r
+public class OutJson extends Out {\r
+\r
+       @Override\r
+       public<IN,S> void extract(IN in, Writer writer, Parse<IN, S> prs, boolean ... options) throws IOException, ParseException {\r
+               Parsed<S> p = prs.newParsed();\r
+               IndentPrintWriter ipw;\r
+               if(options.length>0 && options[0]) { // is Pretty\r
+                       ipw = writer instanceof IndentPrintWriter?(IndentPrintWriter)writer:new IndentPrintWriter(writer);\r
+                       writer = ipw;\r
+               } else {\r
+                       ipw = null;\r
+               }\r
+               \r
+               // If it's a fragment, print first Object Name.  If root Object, skip first name\r
+               Stack<LevelStack> jsonLevel = new Stack<LevelStack>();\r
+               jsonLevel.push(new LevelStack(options.length>1 && options[1]));\r
+               boolean print = true, hadData=false;\r
+               char afterName=0, beforeName=0, maybe = 0, prev=0;\r
+               \r
+               int count = 0;\r
+               while((p = prs.parse(in,p.reuse())).valid()) {\r
+                       ++count;\r
+                       switch(p.event) {\r
+                               case 1: \r
+                                       continue;\r
+                               case 2:\r
+                                       if(count==2) { // it's empty, write open/close on it's own\r
+                                               writer.append('{');\r
+                                               writer.append('}');\r
+                                       }\r
+                                       writer.flush();\r
+                                       return;\r
+                               case '{':\r
+                                       afterName = '{';\r
+                                       if(jsonLevel.peek().printObjectName) {\r
+                                               print = true;\r
+                                       } else { // don't print names on first\r
+                                               print=false; \r
+                                       }\r
+                                       maybe=jsonLevel.peek().listItem();\r
+                                       jsonLevel.push(new LevelStack(true));\r
+                                       break;\r
+                               case '}':\r
+                                       if(p.hasData()) { // if we have data, we print that, so may need to prepend a comma.\r
+                                               maybe = jsonLevel.peek().listItem();\r
+                                       } else { // No data means just print, \r
+                                               p.name = ""; // XML tags come through with names, but no data\r
+                                       } \r
+                                       print = true;\r
+                                       jsonLevel.pop();\r
+                                       afterName = p.event;\r
+                                       break;\r
+                               case '[':\r
+                                       afterName = p.event;\r
+                                       if((prev==',' && !hadData) || prev==']')maybe=',';\r
+                                       else maybe = jsonLevel.peek().listItem();\r
+\r
+                                       jsonLevel.push(new LevelStack(false));\r
+                                       print=true;\r
+                                       break;\r
+                               case ']':\r
+                                       afterName = p.event;\r
+                                       if(p.hasData()) {\r
+                                               if(prev==',' && !hadData)maybe=',';\r
+                                               else maybe = jsonLevel.peek().listItem();\r
+                                       } else {\r
+                                               p.name = ""; // XML tags come through with names, but no data\r
+                                       } \r
+                                       jsonLevel.pop();\r
+\r
+                                       print = true;\r
+                                       break;\r
+                               case   3:\r
+                               case ',':\r
+                                       if(!p.hasData()) {\r
+                                               p.isString=false;\r
+                                               print=false;\r
+                                       } else {\r
+                                               maybe=jsonLevel.peek().listItem();\r
+                                               print = true;\r
+                                       }\r
+                                       break;\r
+                               default:\r
+                                       print = true;\r
+                       }\r
+               \r
+                       if(maybe!=0) {\r
+                               if(ipw==null)writer.append(maybe); \r
+                               else ipw.println(maybe);\r
+                               maybe = 0;\r
+                       }\r
+                       \r
+                       if(beforeName!=0) {\r
+                               if(ipw==null)writer.append(beforeName);\r
+                               else ipw.println(beforeName);\r
+                               beforeName = 0;\r
+                       }\r
+                       if(print) {\r
+                               if(p.hasName()) {\r
+                                       writer.append('"');\r
+                                       if(p.event==3)writer.append("__");\r
+                                       writer.append(p.name);\r
+                                       writer.append("\":");\r
+                               } \r
+                               if(p.hasData()) {\r
+                                       if(p.isString) {\r
+                                               writer.append('"');\r
+                                               escapedWrite(writer, p.sb);\r
+                                               writer.append('"');\r
+                                       } else if(p.sb.length()>0) {\r
+                                               writer.append(p.sb);\r
+                                       }\r
+                               }\r
+                       }\r
+                       if(afterName!=0) {\r
+                               if(ipw==null)writer.append(afterName);\r
+                               else {\r
+                                       switch(afterName) {\r
+                                               case '{':\r
+                                                       ipw.println(afterName);\r
+                                                       ipw.inc();\r
+                                                       break;\r
+                                               case '}':\r
+                                                       ipw.dec();\r
+                                                       ipw.println();\r
+                                                       ipw.print(afterName);\r
+                                                       break;\r
+                                               case ']':\r
+                                                       if(prev=='}' || prev==',')ipw.println();\r
+                                                       ipw.dec();\r
+                                                       ipw.print(afterName);\r
+                                                       break;\r
+\r
+                                               case ',':\r
+                                                       ipw.println(afterName);\r
+                                                       break;\r
+                                               default:\r
+                                                       ipw.print(afterName);\r
+                                       }\r
+                               }\r
+                               afterName = 0;\r
+                       }\r
+                       \r
+                       if(ipw!=null) {\r
+                               switch(p.event) {\r
+                                       case '[':\r
+                                               ipw.inc();\r
+                                               ipw.println();\r
+                                               break;\r
+                               }\r
+                       }\r
+                       prev = p.event;\r
+                       hadData = p.hasData();\r
+\r
+               }\r
+               writer.flush();\r
+       }\r
+\r
+       private void escapedWrite(Writer writer, StringBuilder sb) throws IOException {\r
+               char c;\r
+               for(int i=0;i<sb.length();++i) {\r
+                       switch(c=sb.charAt(i)) {\r
+                               case '\\':\r
+                                       writer.append(c);\r
+                                       if(i<sb.length()) {\r
+                                               c=sb.charAt(++i);\r
+                                               writer.append(c);\r
+                                       }\r
+                                       break;\r
+                               case '"':\r
+                                       writer.append('\\');\r
+                                       // Passthrough on purpose\r
+                               default:\r
+                                       writer.append(c);\r
+                       }\r
+               }\r
+\r
+               \r
+       }\r
+\r
+       @Override\r
+       public String logName() {\r
+               return "Rosetta JSON";\r
+       }\r
+\r
+       private static class LevelStack {\r
+               public boolean printObjectName=false;\r
+               private boolean first_n_List=true;\r
+               \r
+               public LevelStack(boolean printObjectName) {\r
+                       this.printObjectName = printObjectName;\r
+               }\r
+               \r
+               public char listItem() {\r
+                       if(first_n_List) {\r
+                               first_n_List=false;\r
+                               return 0;\r
+                       } else {\r
+                               return ',';\r
+                       }\r
+               }\r
+       }\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/OutRaw.java b/rosetta/src/main/java/com/att/rosetta/OutRaw.java
new file mode 100644 (file)
index 0000000..1a5d8d0
--- /dev/null
@@ -0,0 +1,48 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+import java.io.IOException;\r
+import java.io.Writer;\r
+\r
+public class OutRaw extends Out{\r
+\r
+       @Override\r
+       public<IN,S> void extract(IN in, Writer writer, Parse<IN,S> prs, boolean ... options) throws IOException, ParseException {\r
+               Parsed<S> p = prs.newParsed();\r
+               \r
+               while((p = prs.parse(in,p.reuse())).valid()) { \r
+                       writer.append(p.toString());\r
+                       writer.append('\n');\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public String logName() {\r
+               return "Rosetta RAW";\r
+       }\r
+\r
+\r
+\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/OutXML.java b/rosetta/src/main/java/com/att/rosetta/OutXML.java
new file mode 100644 (file)
index 0000000..cfef897
--- /dev/null
@@ -0,0 +1,227 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+import java.io.IOException;\r
+import java.io.Writer;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Stack;\r
+\r
+import com.att.inno.env.util.IndentPrintWriter;\r
+import com.att.inno.env.util.StringBuilderWriter;\r
+\r
+public class OutXML extends Out{\r
+       private static final String XMLNS_XSI = "xmlns:xsi";\r
+       public static final String XML_INFO = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"; \r
+       public static final String XML_SCHEMA_INSTANCE = "http://www.w3.org/2001/XMLSchema-instance";\r
+       \r
+       private String root;\r
+       private List<Prop> props;\r
+\r
+       public OutXML(String root, String ... params) {\r
+               this.root = root;\r
+               props = new ArrayList<Prop>();\r
+               for(String p : params) {\r
+                       String[] tv=p.split("=");\r
+                       if(tv.length==2)\r
+                               props.add(new Prop(tv[0],tv[1]));\r
+               }\r
+       }\r
+       \r
+       public OutXML(JaxInfo jaxInfo) {\r
+               this(jaxInfo.name,genNS(jaxInfo));\r
+       }\r
+       \r
+       public OutXML(InXML inXML) {\r
+               this(inXML.jaxInfo.name,genNS(inXML.jaxInfo));\r
+       }\r
+       \r
+       private static String[] genNS(JaxInfo jaxInfo) {\r
+               return new String[] {"xmlns=" + jaxInfo.ns};\r
+       }\r
+       \r
+       \r
+       @Override\r
+       public<IN,S> void extract(IN in, Writer writer, Parse<IN,S> prs, boolean ... options) throws IOException, ParseException {\r
+               Parsed<S> p = prs.newParsed();\r
+               Stack<Level> stack = new Stack<Level>();\r
+               // If it's an IndentPrintWriter, it is pretty printing.\r
+               boolean pretty = (options.length>0&&options[0]);\r
+       \r
+               IndentPrintWriter ipw;\r
+               if(pretty) {\r
+                       if(writer instanceof IndentPrintWriter) {\r
+                               ipw = (IndentPrintWriter)writer;\r
+                       } else {\r
+                               writer = ipw = new IndentPrintWriter(writer);\r
+                       }\r
+               } else {\r
+                       ipw=null;\r
+               }\r
+               boolean closeTag = false;\r
+               Level level = new Level(null);\r
+               while((p = prs.parse(in,p.reuse())).valid()) {\r
+                       if(!p.hasName() && level.multi!=null) {\r
+                               p.name=level.multi;\r
+                       }\r
+                       if(closeTag && p.event!=Parse.ATTRIB) {\r
+                               writer.append('>');\r
+                               if(pretty)writer.append('\n');\r
+                               closeTag = false;\r
+                       }\r
+                       switch(p.event) {\r
+                               case Parse.START_DOC:\r
+                                       if(!(options.length>1&&options[1])) // if not a fragment, print XML Info data\r
+                                               if(pretty)ipw.println(XML_INFO);\r
+                                               else writer.append(XML_INFO);\r
+                                       break;\r
+                               case Parse.END_DOC:\r
+                                       break;\r
+                               case Parse.START_OBJ:\r
+                                       stack.push(level);\r
+                                       level = new Level(level);\r
+                                       if(p.hasName()) {\r
+                                               closeTag = tag(writer,level.sbw,pretty,pretty,p.name,null);\r
+                                       } else if(root!=null && stack.size()==1) { // first Object\r
+                                               closeTag = tag(writer,level.sbw,pretty,pretty,root,null);\r
+                                               // Write Root Props\r
+                                               for(Prop prop : props) {\r
+                                                       attrib(writer,pretty,prop.tag, prop.value,level);\r
+                                               }\r
+                                       }\r
+                                       if(pretty)ipw.inc();\r
+                                       break;\r
+                               case Parse.END_OBJ:\r
+                                       if(p.hasData())  \r
+                                               closeTag = tag(writer,writer,pretty,false,p.name, XmlEscape.convert(p.sb));\r
+                                       if(pretty)ipw.dec();\r
+                                       writer.append(level.sbw.getBuffer());\r
+                                       level = stack.pop();\r
+                                       break;\r
+                               case Parse.START_ARRAY: \r
+                                       level.multi = p.name;\r
+                                       break;\r
+                               case Parse.END_ARRAY:\r
+                                       if(p.hasData()) \r
+                                               closeTag = tag(writer,writer,pretty,false, p.name, XmlEscape.convert(p.sb));\r
+                                       level.multi=null;\r
+                                       break;\r
+                               case Parse.ATTRIB:\r
+                                       if(p.hasData()) \r
+                                               attrib(writer,pretty,p.name, XmlEscape.convert(p.sb), level);\r
+                                       break;\r
+                               case Parse.NEXT:\r
+                                       if(p.hasData())\r
+                                               closeTag = tag(writer,writer,pretty, false,p.name, XmlEscape.convert(p.sb));\r
+                                       break;\r
+                       }\r
+               }\r
+               writer.append(level.sbw.getBuffer());\r
+               writer.flush();\r
+       }\r
+       \r
+       private class Level {\r
+               public final StringBuilderWriter sbw;\r
+               public String multi;\r
+               private Level prev;\r
+               private Map<String,String> nses;\r
+               \r
+               public Level(Level level) {\r
+                       sbw = new StringBuilderWriter();\r
+                       multi = null;\r
+                       prev = level;\r
+               }\r
+\r
+               public boolean hasPrinted(String ns, String value, boolean create) {\r
+                       boolean rv = false;\r
+                       if(nses==null) {\r
+                               if(prev!=null)rv = prev.hasPrinted(ns, value, false);\r
+                       } else {\r
+                               String v = nses.get(ns);\r
+                               return value.equals(v); // note: accomodates not finding NS as well\r
+                       }\r
+                       \r
+                       if(create && !rv) {\r
+                               if(nses == null) nses = new HashMap<String,String>();\r
+                               nses.put(ns, value);\r
+                       }\r
+                       return rv;\r
+               }\r
+               \r
+               \r
+               \r
+       }\r
+       \r
+       private boolean tag(Writer fore, Writer aft, boolean pretty, boolean returns, String tag, String data) throws IOException {\r
+               fore.append('<');\r
+               fore.append(tag);\r
+               if(data!=null) {\r
+                       fore.append('>'); // if no data, it may need some attributes...\r
+                       fore.append(data);\r
+                       if(returns)fore.append('\n');\r
+               }\r
+               aft.append("</");\r
+               aft.append(tag);\r
+               aft.append(">");\r
+               if(pretty)aft.append('\n');\r
+               return data==null;\r
+       }\r
+       \r
+       private void attrib(Writer fore, boolean pretty, String tag, String value, Level level) throws IOException {\r
+               String realTag = tag.startsWith("__")?tag.substring(2):tag; // remove __\r
+               if(realTag.equals(Parsed.EXTENSION_TAG)) { // Convert Derived name into XML defined Inheritance\r
+                       fore.append(" xsi:type=\"");\r
+                       fore.append(value);\r
+                       fore.append('"');\r
+                       if(!level.hasPrinted(XMLNS_XSI, XML_SCHEMA_INSTANCE,true)) {\r
+                               fore.append(' ');\r
+                               fore.append(XMLNS_XSI);\r
+                               fore.append("=\"");\r
+                               fore.append(XML_SCHEMA_INSTANCE);\r
+                               fore.append("\"");\r
+                       }\r
+               } else {\r
+                       if(realTag.startsWith("xmlns:") ) {\r
+                               if(level.hasPrinted(realTag, value, true)) {\r
+                                       return;\r
+                               }\r
+                       }\r
+                       fore.append(' ');\r
+                       fore.append(realTag);  \r
+                       fore.append("=\"");\r
+                       fore.append(value);\r
+                       fore.append('"');\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public String logName() {\r
+               return "Rosetta XML";\r
+       }\r
+\r
+\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/Parse.java b/rosetta/src/main/java/com/att/rosetta/Parse.java
new file mode 100644 (file)
index 0000000..93415b4
--- /dev/null
@@ -0,0 +1,47 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.TimeTaken;\r
+\r
+public interface Parse<IN, S> {\r
+       public Parsed<S> parse(IN in, Parsed<S> parsed) throws ParseException;\r
+       \r
+       // EVENTS\r
+       public static final char NONE = 0;\r
+       public static final char START_DOC = 1;\r
+       public static final char END_DOC = 2;\r
+       public static final char ATTRIB = 3;\r
+       \r
+       public static final char NEXT = ',';\r
+       public static final char START_OBJ = '{';\r
+       public static final char END_OBJ = '}';\r
+       public static final char START_ARRAY = '[';\r
+       public static final char END_ARRAY = ']';\r
+       \r
+       public Parsed<S> newParsed() throws ParseException;\r
+       public TimeTaken start(Env env); \r
+       \r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/ParseException.java b/rosetta/src/main/java/com/att/rosetta/ParseException.java
new file mode 100644 (file)
index 0000000..f086d00
--- /dev/null
@@ -0,0 +1,44 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+public class ParseException extends Exception {\r
+       private static final long serialVersionUID = 7808836939102997012L;\r
+\r
+       public ParseException() {\r
+       }\r
+\r
+       public ParseException(String message) {\r
+               super(message);\r
+       }\r
+\r
+       public ParseException(Throwable cause) {\r
+               super(cause);\r
+       }\r
+\r
+       public ParseException(String message, Throwable cause) {\r
+               super(message, cause);\r
+       }\r
+\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/Parsed.java b/rosetta/src/main/java/com/att/rosetta/Parsed.java
new file mode 100644 (file)
index 0000000..412251f
--- /dev/null
@@ -0,0 +1,91 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+\r
+public class Parsed<S> {\r
+       public static final String EXTENSION_TAG="extension";\r
+       \r
+       public boolean isString;\r
+       \r
+       public StringBuilder sb;\r
+       public char event;\r
+       public String name;\r
+       public S state;\r
+\r
+       public Parsed() {\r
+               this(null);\r
+       }\r
+\r
+       // Package on purpose\r
+       Parsed(S theState) {\r
+               sb = new StringBuilder();\r
+               isString = false;\r
+               event = Parse.NONE;\r
+               name = "";\r
+               state = theState;\r
+       }\r
+\r
+       public boolean valid() {\r
+               return event!=Parse.NONE;\r
+       }\r
+       \r
+       public Parsed<S> reuse() {\r
+               isString=false;\r
+               sb.setLength(0);\r
+               event = Parse.NONE;\r
+               name = "";\r
+               // don't touch T...\r
+               return this;\r
+       }\r
+\r
+       public void dataIsName() {\r
+               name = sb.toString();\r
+               sb.setLength(0);\r
+       }\r
+\r
+       public boolean hasName() {\r
+               return name.length()>0;\r
+       }\r
+\r
+       public boolean hasData() {\r
+               return sb.length()>0;\r
+       }\r
+       \r
+       public String toString() {\r
+               StringBuilder sb2 = new StringBuilder();\r
+               if(event<40)sb2.append((int)event);\r
+               else sb2.append(event);\r
+               sb2.append(" - ");\r
+               sb2.append(name);\r
+               if(sb.length()>0) {\r
+                       sb2.append(" : ");\r
+                       if(isString)sb2.append('"');\r
+                       sb2.append(sb);\r
+                       if(isString)sb2.append('"');\r
+               }\r
+               return sb2.toString();\r
+       }\r
+\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/Prop.java b/rosetta/src/main/java/com/att/rosetta/Prop.java
new file mode 100644 (file)
index 0000000..78a8125
--- /dev/null
@@ -0,0 +1,45 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+class Prop {\r
+       public String tag;\r
+       public String value;\r
+       public Prop(String t, String v) {\r
+               tag = t;\r
+               value =v;\r
+       }\r
+       \r
+       public Prop(String t_equals_v) {\r
+               String[] tv = t_equals_v.split("=");\r
+               if(tv.length>1) {\r
+                       tag = tv[0];\r
+                       value = tv[1];\r
+               }                               \r
+       }\r
+\r
+       public String toString() {\r
+               return tag + '=' + value;\r
+       }\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/Saved.java b/rosetta/src/main/java/com/att/rosetta/Saved.java
new file mode 100644 (file)
index 0000000..bc7e106
--- /dev/null
@@ -0,0 +1,195 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+import java.io.IOException;\r
+import java.io.Reader;\r
+import java.io.Writer;\r
+import java.util.List;\r
+\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.TimeTaken;\r
+import com.att.rosetta.Saved.State;\r
+\r
+/**\r
+ * An Out Object that will save off produced Parsed Stream and \r
+ * a Parse (In) Object that will reproduce Parsed Stream on demand\r
+ *  \r
+ *\r
+ */\r
+public class Saved extends Out implements Parse<Reader, State>{\r
+       private static final String ROSETTA_SAVED = "Rosetta Saved";\r
+       private final static int INIT_SIZE=128;\r
+       private Content content[];\r
+       private int idx;\r
+       private boolean append = false;\r
+       \r
+       /**\r
+        * Read from Parsed Stream and save\r
+        */\r
+       // @Override\r
+       public<IN,S> void extract(IN in, Writer ignore, Parse<IN,S> parser, boolean ... options) throws IOException, ParseException {\r
+               Parsed<S> p = parser.newParsed();\r
+               if(!append) {\r
+                       // reuse array  if not too big\r
+                       if(content==null||content.length>INIT_SIZE*3) {\r
+                               content = new Content[INIT_SIZE];\r
+                               idx = -1;\r
+                       } else do {\r
+                               content[idx]=null;\r
+                       } while(--idx>=0);\r
+               }\r
+               \r
+               // Note: idx needs to be -1 on initialization and no appendages\r
+               while((p = parser.parse(in,p.reuse())).valid()) {\r
+                       if(!(append && (p.event==START_DOC || p.event==END_DOC))) { // skip any start/end of document in appendages\r
+                               if(++idx>=content.length) {\r
+                                       Content temp[] = new Content[content.length*2];\r
+                                       System.arraycopy(content, 0, temp, 0, idx);\r
+                                       content = temp;\r
+                               }\r
+                               content[idx]= new Content(p);\r
+                       }\r
+               }\r
+       }\r
+       \r
+       // @Override\r
+       public Parsed<State> parse(Reader ignore, Parsed<State> parsed) throws ParseException {\r
+               int i;\r
+               if((i=parsed.state.count++)<=idx) \r
+                       content[i].load(parsed);\r
+               else \r
+                       parsed.event = Parse.NONE; \r
+               return parsed;\r
+       }\r
+\r
+       public Content[] cut(char event, int count) {\r
+               append = true;\r
+               for(int i=idx;i>=0;--i) {\r
+                       if(content[i].event==event) count--;\r
+                       if(count==0) {\r
+                               Content[] appended = new Content[idx-i+1];\r
+                               System.arraycopy(content, i, appended, 0, appended.length);\r
+                               idx = i-1;\r
+                               return appended;\r
+                       }\r
+               }\r
+               return new Content[0];\r
+       }\r
+\r
+       public void paste(Content[] appended) {\r
+               if(appended!=null) {\r
+                       if(idx+appended.length>content.length) {\r
+                               Content temp[] = new Content[content.length*2];\r
+                               System.arraycopy(content, 0, temp, 0, idx);\r
+                               content = temp;\r
+                       }\r
+                       System.arraycopy(appended,0,content,idx+1,appended.length);\r
+                       idx+=appended.length;\r
+               }\r
+               this.append = false;\r
+       }\r
+\r
+       public static class State {\r
+               public int count = 0;\r
+       }\r
+       \r
+       public static class Content {\r
+               private boolean isString;\r
+               private char event;\r
+               private String name;\r
+               private List<Prop> props;\r
+               private String str;\r
+               \r
+               public Content(Parsed<?> p) {\r
+                       isString = p.isString;\r
+                       event = p.event;\r
+                       name = p.name;\r
+                       // avoid copying, because most elements don't have content\r
+                       // Cannot set to "equals", because sb ends up being cleared (and reused)\r
+                       str = p.sb.length()==0?null:p.sb.toString();\r
+               }\r
+\r
+               public void load(Parsed<State> p) {\r
+                       p.isString = isString;\r
+                       p.event = event;\r
+                       p.name = name;\r
+                       if(str!=null)\r
+                               p.sb.append(str);\r
+               }\r
+               \r
+               public String toString() {\r
+                       StringBuilder sb = new StringBuilder();\r
+                       sb.append(event);\r
+                       sb.append(" - ");\r
+                       sb.append(name);\r
+                       sb.append(": ");\r
+                       if(isString)sb.append('"');\r
+                       sb.append(str);\r
+                       if(isString)sb.append('"');\r
+                       sb.append(' ');\r
+                       if(props!=null) {\r
+                               boolean comma = false;\r
+                               for(Prop prop : props) {\r
+                                       if(comma)sb.append(',');\r
+                                       else comma = true;\r
+                                       sb.append(prop.tag);\r
+                                       sb.append('=');\r
+                                       sb.append(prop.value);\r
+                               }\r
+                       }\r
+                       return sb.toString();\r
+               }\r
+       }\r
+       \r
+       //// @Override\r
+       public Parsed<State> newParsed() {\r
+               Parsed<State> ps = new Parsed<State>(new State());\r
+               return ps;\r
+       }\r
+\r
+       /**\r
+        * Convenience function\r
+        * @param rdr\r
+        * @param in\r
+        * @throws IOException\r
+        * @throws ParseException\r
+        */\r
+       public<IN,S> void load(IN in, Parse<IN, S> parser) throws IOException, ParseException {\r
+               extract(in,(Writer)null, parser);\r
+       }\r
+\r
+\r
+       // @Override\r
+       public TimeTaken start(Env env) {\r
+               return env.start(ROSETTA_SAVED, 0);\r
+       }\r
+       \r
+       @Override\r
+       public String logName() {\r
+               return ROSETTA_SAVED;\r
+       }\r
+\r
+\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/XmlEscape.java b/rosetta/src/main/java/com/att/rosetta/XmlEscape.java
new file mode 100644 (file)
index 0000000..c61a80d
--- /dev/null
@@ -0,0 +1,373 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta;\r
+\r
+import java.io.IOException;\r
+import java.io.Reader;\r
+import java.util.Map.Entry;\r
+import java.util.TreeMap;\r
+\r
+public class XmlEscape {\r
+       private XmlEscape() {}\r
+       \r
+       private static final TreeMap<String,Integer> charMap; // see initialization at end\r
+       private static final TreeMap<Integer,String> intMap; // see initialization at end\r
+\r
+       public static void xmlEscape(StringBuilder sb, Reader r) throws ParseException {\r
+               try {\r
+                       int c;\r
+                       StringBuilder esc = new StringBuilder();\r
+                       for(int cnt = 0;cnt<9 /*max*/; ++cnt) {\r
+                               if((c=r.read())<0)throw new ParseException("Invalid Data: Unfinished Escape Sequence");\r
+                               if(c!=';') { \r
+                                       esc.append((char)c);\r
+                               } else { // evaluate\r
+                                       Integer i = charMap.get(esc.toString());\r
+                                       if(i==null) {\r
+                                               // leave in nasty XML format for now.\r
+                                               sb.append('&');\r
+                                               sb.append(esc);\r
+                                               sb.append(';');\r
+                                       } else {\r
+                                               sb.append((char)i.intValue());\r
+                                       }\r
+                                       break;\r
+                               }\r
+                       }\r
+                       \r
+                       \r
+               } catch (IOException e) {\r
+                       throw new ParseException(e);\r
+               }\r
+       }\r
+       \r
+       public static void xmlEscape(StringBuilder sb, int chr) {\r
+               sb.append('&');\r
+               sb.append(intMap.get(chr));\r
+               sb.append(';');\r
+       }\r
+       \r
+       public static String convert(StringBuilder insb) {\r
+               int idx, ch;\r
+               StringBuilder sb=null;\r
+               for(idx=0;idx<insb.length();++idx) {\r
+                       ch = insb.charAt(idx);\r
+                       if(ch>=160 || ch==34 || ch==38 || ch==39 || ch==60 || ch==62) {\r
+                               sb = new StringBuilder();\r
+                               sb.append(insb,0,idx);\r
+                               break;\r
+                       }\r
+               }\r
+               \r
+               if(sb==null)return insb.toString();\r
+                       \r
+               for(int i=idx;i<insb.length();++i) {\r
+                       ch = insb.charAt(i);\r
+                       if(ch<160) {\r
+                               switch(ch) {\r
+                                       case 34: sb.append("&quot;"); break;\r
+                                       case 38: sb.append("&amp;"); break;\r
+                                       case 39: sb.append("&apos;"); break;\r
+                                       case 60: sb.append("&lt;"); break;\r
+                                       case 62: sb.append("&gt;"); break;\r
+                                       default:\r
+                                               sb.append((char)ch);\r
+                               }\r
+                       } else { // use map\r
+                               String s = intMap.get(ch);\r
+                               if(s==null)sb.append((char)ch);\r
+                               else {\r
+                                       sb.append('&');\r
+                                       sb.append(s);\r
+                                       sb.append(';');\r
+                               }\r
+                       }\r
+               }\r
+               return sb.toString();\r
+       }\r
+\r
+       static {\r
+               charMap = new TreeMap<String, Integer>();\r
+               intMap = new TreeMap<Integer,String>();\r
+               charMap.put("quot", 34);\r
+               charMap.put("amp",38);\r
+               charMap.put("apos",39);\r
+               charMap.put("lt",60);\r
+               charMap.put("gt",62);\r
+               charMap.put("nbsp",160);\r
+               charMap.put("iexcl",161);\r
+               charMap.put("cent",162);\r
+               charMap.put("pound",163);\r
+               charMap.put("curren",164);\r
+               charMap.put("yen",165);\r
+               charMap.put("brvbar",166);\r
+               charMap.put("sect",167);\r
+               charMap.put("uml",168);\r
+               charMap.put("copy",169);\r
+               charMap.put("ordf",170);\r
+               charMap.put("laquo",171);\r
+               charMap.put("not",172);\r
+               charMap.put("shy",173);\r
+               charMap.put("reg",174);\r
+               charMap.put("macr",175);\r
+               charMap.put("deg",176);\r
+               charMap.put("plusmn",177);\r
+               charMap.put("sup2",178);\r
+               charMap.put("sup3",179);\r
+               charMap.put("acute",180);\r
+               charMap.put("micro",181);\r
+               charMap.put("para",182);\r
+               charMap.put("middot",183);\r
+               charMap.put("cedil",184);\r
+               charMap.put("sup1",185);\r
+               charMap.put("ordm",186);\r
+               charMap.put("raquo",187);\r
+               charMap.put("frac14",188);\r
+               charMap.put("frac12",189);\r
+               charMap.put("frac34",190);\r
+               charMap.put("iquest",191);\r
+               charMap.put("Agrave",192);\r
+               charMap.put("Aacute",193);\r
+               charMap.put("Acirc",194);\r
+               charMap.put("Atilde",195);\r
+               charMap.put("Auml",196);\r
+               charMap.put("Aring",197);\r
+               charMap.put("AElig",198);\r
+               charMap.put("Ccedil",199);\r
+               charMap.put("Egrave",200);\r
+               charMap.put("Eacute",201);\r
+               charMap.put("Ecirc",202);\r
+               charMap.put("Euml",203);\r
+               charMap.put("Igrave",204);\r
+               charMap.put("Iacute",205);\r
+               charMap.put("Icirc",206);\r
+               charMap.put("Iuml",207);\r
+               charMap.put("ETH",208);\r
+               charMap.put("Ntilde",209);\r
+               charMap.put("Ograve",210);\r
+               charMap.put("Oacute",211);\r
+               charMap.put("Ocirc",212);\r
+               charMap.put("Otilde",213);\r
+               charMap.put("Ouml",214);\r
+               charMap.put("times",215);\r
+               charMap.put("Oslash",216);\r
+               charMap.put("Ugrave",217);\r
+               charMap.put("Uacute",218);\r
+               charMap.put("Ucirc",219);\r
+               charMap.put("Uuml",220);\r
+               charMap.put("Yacute",221);\r
+               charMap.put("THORN",222);\r
+               charMap.put("szlig",223);\r
+               charMap.put("agrave",224);\r
+               charMap.put("aacute",225);\r
+               charMap.put("acirc",226);\r
+               charMap.put("atilde",227);\r
+               charMap.put("auml",228);\r
+               charMap.put("aring",229);\r
+               charMap.put("aelig",230);\r
+               charMap.put("ccedil",231);\r
+               charMap.put("egrave",232);\r
+               charMap.put("eacute",233);\r
+               charMap.put("ecirc",234);\r
+               charMap.put("euml",235);\r
+               charMap.put("igrave",236);\r
+               charMap.put("iacute",237);\r
+               charMap.put("icirc",238);\r
+               charMap.put("iuml",239);\r
+               charMap.put("eth",240);\r
+               charMap.put("ntilde",241);\r
+               charMap.put("ograve",242);\r
+               charMap.put("oacute",243);\r
+               charMap.put("ocirc",244);\r
+               charMap.put("otilde",245);\r
+               charMap.put("ouml",246);\r
+               charMap.put("divide",247);\r
+               charMap.put("oslash",248);\r
+               charMap.put("ugrave",249);\r
+               charMap.put("uacute",250);\r
+               charMap.put("ucirc",251);\r
+               charMap.put("uuml",252);\r
+               charMap.put("yacute",253);\r
+               charMap.put("thorn",254);\r
+               charMap.put("yuml",255);\r
+               charMap.put("OElig",338);\r
+               charMap.put("oelig",339);\r
+               charMap.put("Scaron",352);\r
+               charMap.put("scaron",353);\r
+               charMap.put("Yuml",376);\r
+               charMap.put("fnof",402);\r
+               charMap.put("circ",710);\r
+               charMap.put("tilde",732);\r
+               charMap.put("Alpha",913);\r
+               charMap.put("Beta",914);\r
+               charMap.put("Gamma",915);\r
+               charMap.put("Delta",916);\r
+               charMap.put("Epsilon",917);\r
+               charMap.put("Zeta",918);\r
+               charMap.put("Eta",919);\r
+               charMap.put("Theta",920);\r
+               charMap.put("Iota",921);\r
+               charMap.put("Kappa",922);\r
+               charMap.put("Lambda",923);\r
+               charMap.put("Mu",924);\r
+               charMap.put("Nu",925);\r
+               charMap.put("Xi",926);\r
+               charMap.put("Omicron",927);\r
+               charMap.put("Pi",928);\r
+               charMap.put("Rho",929);\r
+               charMap.put("Sigma",931);\r
+               charMap.put("Tau",932);\r
+               charMap.put("Upsilon",933);\r
+               charMap.put("Phi",934);\r
+               charMap.put("Chi",935);\r
+               charMap.put("Psi",936);\r
+               charMap.put("Omega",937);\r
+               charMap.put("alpha",945);\r
+               charMap.put("beta",946);\r
+               charMap.put("gamma",947);\r
+               charMap.put("delta",948);\r
+               charMap.put("epsilon",949);\r
+               charMap.put("zeta",950);\r
+               charMap.put("eta",951);\r
+               charMap.put("theta",952);\r
+               charMap.put("iota",953);\r
+               charMap.put("kappa",954);\r
+               charMap.put("lambda",955);\r
+               charMap.put("mu",956);\r
+               charMap.put("nu",957);\r
+               charMap.put("xi",958);\r
+               charMap.put("omicron",959);\r
+               charMap.put("pi",960);\r
+               charMap.put("rho",961);\r
+               charMap.put("sigmaf",962);\r
+               charMap.put("sigma",963);\r
+               charMap.put("tau",964);\r
+               charMap.put("upsilon",965);\r
+               charMap.put("phi",966);\r
+               charMap.put("chi",967);\r
+               charMap.put("psi",968);\r
+               charMap.put("omega",969);\r
+               charMap.put("thetasym",977);\r
+               charMap.put("upsih",978);\r
+               charMap.put("piv",982);\r
+               charMap.put("ensp",8194);\r
+               charMap.put("emsp",8195);\r
+               charMap.put("thinsp",8201);\r
+               charMap.put("zwnj",8204);\r
+               charMap.put("zwj",8205);\r
+               charMap.put("lrm",8206);\r
+               charMap.put("rlm",8207);\r
+               charMap.put("ndash",8211);\r
+               charMap.put("mdash",8212);\r
+               charMap.put("lsquo",8216);\r
+               charMap.put("rsquo",8217);\r
+               charMap.put("sbquo",8218);\r
+               charMap.put("ldquo",8220);\r
+               charMap.put("rdquo",8221);\r
+               charMap.put("bdquo",8222);\r
+               charMap.put("dagger",8224);\r
+               charMap.put("Dagger",8225);\r
+               charMap.put("bull",8226);\r
+               charMap.put("hellip",8230);\r
+               charMap.put("permil",8240);\r
+               charMap.put("prime",8242);\r
+               charMap.put("Prime",8243);\r
+               charMap.put("lsaquo",8249);\r
+               charMap.put("rsaquo",8250);\r
+               charMap.put("oline",8254);\r
+               charMap.put("frasl",8260);\r
+               charMap.put("euro",8364);\r
+               charMap.put("image",8465);\r
+               charMap.put("weierp",8472);\r
+               charMap.put("real",8476);\r
+               charMap.put("trade",8482);\r
+               charMap.put("alefsym",8501);\r
+               charMap.put("larr",8592);\r
+               charMap.put("uarr",8593);\r
+               charMap.put("rarr",8594);\r
+               charMap.put("darr",8595);\r
+               charMap.put("harr",8596);\r
+               charMap.put("crarr",8629);\r
+               charMap.put("lArr",8656);\r
+               charMap.put("uArr",8657);\r
+               charMap.put("rArr",8658);\r
+               charMap.put("dArr",8659);\r
+               charMap.put("hArr",8660);\r
+               charMap.put("forall",8704);\r
+               charMap.put("part",8706);\r
+               charMap.put("exist",8707);\r
+               charMap.put("empty",8709);\r
+               charMap.put("nabla",8711);\r
+               charMap.put("isin",8712);\r
+               charMap.put("notin",8713);\r
+               charMap.put("ni",8715);\r
+               charMap.put("prod",8719);\r
+               charMap.put("sum",8721);\r
+               charMap.put("minus",8722);\r
+               charMap.put("lowast",8727);\r
+               charMap.put("radic",8730);\r
+               charMap.put("prop",8733);\r
+               charMap.put("infin",8734);\r
+               charMap.put("ang",8736);\r
+               charMap.put("and",8743);\r
+               charMap.put("or",8744);\r
+               charMap.put("cap",8745);\r
+               charMap.put("cup",8746);\r
+               charMap.put("int",8747);\r
+               charMap.put("there4",8756);\r
+               charMap.put("sim",8764);\r
+               charMap.put("cong",8773);\r
+               charMap.put("asymp",8776);\r
+               charMap.put("ne",8800);\r
+               charMap.put("equiv",8801);\r
+               charMap.put("le",8804);\r
+               charMap.put("ge",8805);\r
+               charMap.put("sub",8834);\r
+               charMap.put("sup",8835);\r
+               charMap.put("nsub",8836);\r
+               charMap.put("sube",8838);\r
+               charMap.put("supe",8839);\r
+               charMap.put("oplus",8853);\r
+               charMap.put("otimes",8855);\r
+               charMap.put("perp",8869);\r
+               charMap.put("sdot",8901);\r
+               charMap.put("lceil",8968);\r
+               charMap.put("rceil",8969);\r
+               charMap.put("lfloor",8970);\r
+               charMap.put("rfloor",8971);\r
+               charMap.put("lang",9001);\r
+               charMap.put("rang",9002);\r
+               charMap.put("loz",9674);\r
+               charMap.put("spades",9824);\r
+               charMap.put("clubs",9827);\r
+               charMap.put("hearts",9829);\r
+               charMap.put("diams",9830);\r
+               \r
+               for( Entry<String, Integer> es: charMap.entrySet()) {\r
+                       if(es.getValue()>=160); // save small space... note that no longer has amp, etc.\r
+                       intMap.put(es.getValue(), es.getKey());\r
+               }\r
+       }\r
+\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/env/RosettaDF.java b/rosetta/src/main/java/com/att/rosetta/env/RosettaDF.java
new file mode 100644 (file)
index 0000000..7198c76
--- /dev/null
@@ -0,0 +1,267 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta.env;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.io.OutputStreamWriter;\r
+import java.io.Reader;\r
+import java.io.StringReader;\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 com.att.inno.env.APIException;\r
+import com.att.inno.env.BaseDataFactory;\r
+import com.att.inno.env.Data;\r
+import com.att.inno.env.Data.TYPE;\r
+import com.att.inno.env.DataFactory;\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.TimeTaken;\r
+import com.att.inno.env.Trans;\r
+import com.att.inno.env.jaxb.JAXBmar;\r
+import com.att.inno.env.jaxb.JAXBumar;\r
+import com.att.rosetta.InJson;\r
+import com.att.rosetta.InXML;\r
+import com.att.rosetta.JaxInfo;\r
+import com.att.rosetta.Marshal;\r
+import com.att.rosetta.Out;\r
+import com.att.rosetta.OutJson;\r
+import com.att.rosetta.OutRaw;\r
+import com.att.rosetta.OutXML;\r
+import com.att.rosetta.Parse;\r
+import com.att.rosetta.ParseException;\r
+import com.att.rosetta.marshal.DocMarshal;\r
+\r
+public class RosettaDF<T> extends BaseDataFactory implements DataFactory<T>  {\r
+       \r
+       static InJson inJSON = new InJson();\r
+       InXML  inXML;\r
+\r
+       static OutJson outJSON = new OutJson();\r
+       OutXML outXML;\r
+       static OutRaw outRAW = new OutRaw();\r
+       \r
+       // Temporary until we write JAXB impl...\r
+       JAXBmar jaxMar;\r
+       JAXBumar jaxUmar;\r
+       \r
+       private Parse<Reader,?> defaultIn;\r
+       private Out defaultOut;\r
+       private RosettaEnv env;\r
+       private TYPE inType;\r
+       private TYPE outType;\r
+       private int defOption;\r
+       Marshal<T> marshal = null;\r
+       \r
+\r
+       /**\r
+        * Private constructor to setup Type specific data manipulators\r
+        * @param schema\r
+        * @param rootNs\r
+        * @param cls\r
+        * @throws SecurityException\r
+        * @throws NoSuchFieldException\r
+        * @throws ClassNotFoundException\r
+        * @throws ParseException\r
+        * @throws JAXBException\r
+        */\r
+       // package on purpose\r
+       RosettaDF(RosettaEnv env, Schema schema, String rootNs, Class<T> cls) throws APIException {\r
+               this.env = env;\r
+               try {\r
+               // Note: rootNs can be null, in order to derive content from Class.  \r
+               JaxInfo ji = rootNs==null?JaxInfo.build(cls):JaxInfo.build(cls,rootNs);\r
+               // Note: JAXBmar sets qname to null if not exists\r
+               jaxMar = new JAXBmar(rootNs==null?null:new QName("xmlns",rootNs),cls);\r
+               // Note: JAXBumar sets schema to null if not exists\r
+               jaxUmar = new JAXBumar(schema, cls);\r
+               \r
+               defaultIn = inXML = new InXML(ji);\r
+               defaultOut = outXML = new OutXML(ji);\r
+               inType=outType=Data.TYPE.XML;\r
+               defOption = 0;\r
+               } catch (Exception e) {\r
+                       throw new APIException(e);\r
+               }\r
+       }\r
+       \r
+\r
+       // @Override\r
+       public RosettaData<T> newData() {\r
+               RosettaData<T> data = new RosettaData<T>(env, this)                     \r
+                       .in(inType)\r
+                       .out(outType)\r
+                       .option(defOption);\r
+               return data;\r
+       }\r
+\r
+       // @Override\r
+       public RosettaData<T> newData(Env trans) {\r
+               RosettaData<T> data = new RosettaData<T>(trans, this)\r
+                       .in(inType)\r
+                       .out(outType)\r
+                       .option(defOption);\r
+               return data;\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       // @Override\r
+       public Class<T> getTypeClass() {\r
+               return (Class<T>)jaxMar.getMarshalClass();\r
+       }\r
+\r
+       public RosettaDF<T> in(Data.TYPE type) {\r
+               inType = type;\r
+               defaultIn=getIn(type==Data.TYPE.DEFAULT?Data.TYPE.JSON:type);\r
+               return this;\r
+       }\r
+\r
+       /**\r
+        * If exists, first option is "Pretty", second is "Fragment"\r
+        * \r
+        * @param options\r
+        * @return\r
+        */\r
+       public RosettaDF<T> out(Data.TYPE type) {\r
+               outType = type;\r
+               defaultOut = getOut(type==Data.TYPE.DEFAULT?Data.TYPE.JSON:type);\r
+               return this;\r
+       }\r
+       \r
+       public Parse<Reader,?> getIn(Data.TYPE type) {\r
+               switch(type) {\r
+                       case DEFAULT:\r
+                               return defaultIn;\r
+                       case JSON:\r
+                               return inJSON;\r
+                       case XML:\r
+                               return inXML;\r
+                       default:\r
+                               return defaultIn;\r
+               }\r
+       }\r
+       \r
+       public Out getOut(Data.TYPE type) {\r
+               switch(type) {\r
+                       case DEFAULT:\r
+                               return defaultOut;\r
+                       case JSON:\r
+                               return outJSON;\r
+                       case XML:\r
+                               return outXML;\r
+                       case RAW:\r
+                               return outRAW;\r
+                       default:\r
+                               return defaultOut;\r
+               }\r
+       }\r
+       \r
+       public int logType(com.att.inno.env.Data.TYPE ot) {\r
+               switch(ot) {\r
+                       case JSON:\r
+                               return Env.JSON;\r
+                       default:\r
+                               return Env.XML;\r
+               }\r
+       }\r
+\r
+\r
+       public RosettaEnv getEnv() {\r
+               return env;\r
+       }\r
+\r
+\r
+       public Data.TYPE getInType() {\r
+               return inType;\r
+       }\r
+\r
+       public Data.TYPE getOutType() {\r
+               return outType;\r
+       }\r
+\r
+       public RosettaDF<T> option(int option) {\r
+               defOption = option;\r
+               \r
+               return this;\r
+       }\r
+\r
+       /**\r
+        * Assigning Root Marshal Object\r
+        * \r
+        * Will wrap with DocMarshal Object if not already\r
+        * \r
+        * @param marshal\r
+        * @return\r
+        */\r
+       public RosettaDF<T> rootMarshal(Marshal<T> marshal) {\r
+               if(marshal instanceof DocMarshal) {\r
+                       this.marshal = marshal;\r
+               } else {\r
+                       this.marshal = DocMarshal.root(marshal);\r
+               }\r
+               return this;\r
+       }\r
+       \r
+       public void direct(Trans trans, T t, OutputStream os, boolean ... options) throws APIException, IOException {\r
+               Out out = getOut(outType);\r
+               TimeTaken tt = trans.start(out.logName(),logType(outType)); // determine from Out.. without dependency on Env?\r
+               try {\r
+                       if(marshal==null) { // Unknown marshaller... do working XML marshal/extraction\r
+                               StringWriter sw = new StringWriter();\r
+                               jaxMar.marshal(trans.debug(), t, sw, options);\r
+                               out.extract(new StringReader(sw.toString()), new OutputStreamWriter(os), inXML,options);\r
+                       } else {\r
+                               out.extract(t, new OutputStreamWriter(os), marshal,options);\r
+                       }\r
+               } catch (Exception e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+       public void direct(Trans trans, T t, Writer writer, boolean ... options) throws APIException, IOException {\r
+               Out out = getOut(outType);\r
+               TimeTaken tt = trans.start(out.logName(),logType(outType)); // determine from Out.. without dependency on Env?\r
+               try {\r
+                       if(marshal==null) { // Unknown marshaller... do working XML marshal/extraction\r
+                               StringWriter sw = new StringWriter();\r
+                               jaxMar.marshal(trans.debug(), t, sw, options);\r
+                               out.extract(new StringReader(sw.toString()), writer, inXML,options);\r
+                       } else {\r
+                               out.extract(t, writer, marshal,options);\r
+                       }\r
+               } catch (Exception e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/env/RosettaData.java b/rosetta/src/main/java/com/att/rosetta/env/RosettaData.java
new file mode 100644 (file)
index 0000000..e07e883
--- /dev/null
@@ -0,0 +1,314 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta.env;\r
+\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.InputStreamReader;\r
+import java.io.OutputStream;\r
+import java.io.OutputStreamWriter;\r
+import java.io.Reader;\r
+import java.io.StringReader;\r
+import java.io.StringWriter;\r
+import java.io.Writer;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.inno.env.Data;\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.TimeTaken;\r
+import com.att.rosetta.Out;\r
+import com.att.rosetta.Parse;\r
+import com.att.rosetta.Saved;\r
+\r
+public class RosettaData<T> implements Data<T>{\r
+       private Env trans;\r
+       private RosettaDF<T> df;\r
+       private Saved saved;\r
+       private TYPE inType, outType;\r
+       // Note: This is an array of boolean in order to pass into other methods\r
+       private boolean options[] = new boolean[] {false, false};\r
+       // Temp Storage of XML.  Only when we must use JAXB to read in Objects\r
+       private String xml,json;\r
+       \r
+       // package on purpose\r
+       RosettaData(Env env, RosettaDF<T> rosettaDF) {\r
+               df = rosettaDF;\r
+               saved = new Saved(); // Note: Saved constructs storage as needed...\r
+               trans = env;\r
+               inType = df.getInType();\r
+               outType = df.getOutType(); // take defaults\r
+       }\r
+\r
+//     // @Override\r
+       public RosettaData<T> in(TYPE rosettaType) {\r
+               inType = rosettaType;\r
+               return this;\r
+       }\r
+       \r
+//     // @Override\r
+       public RosettaData<T> out(TYPE rosettaType) {\r
+               outType = rosettaType;\r
+               return this;\r
+       }\r
+\r
+//     // @Override\r
+       public RosettaData<T> load(Reader rdr) throws APIException {\r
+               Parse<Reader,?> in = df.getIn(inType);\r
+               TimeTaken tt = in.start(trans);\r
+               try {\r
+                       saved.extract(rdr, (Writer)null, in);\r
+                       xml=json=null;\r
+               } catch (Exception e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+               return this;\r
+       }\r
+       \r
+       // @Override\r
+       public RosettaData<T> load(InputStream is) throws APIException {\r
+               Parse<Reader,?> in = df.getIn(inType);\r
+               TimeTaken tt = in.start(trans);\r
+               try {\r
+                       saved.extract(new InputStreamReader(is), (Writer)null, in);\r
+                       xml=json=null;\r
+               } catch (Exception e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+               return this;\r
+       }\r
+\r
+       // @Override\r
+       public RosettaData<T> load(String str) throws APIException {\r
+               Parse<Reader,?> in = df.getIn(inType);\r
+               TimeTaken tt = in.start(trans);\r
+               try {\r
+                       saved.extract(new StringReader(str), (Writer)null, in);\r
+                       switch(inType) {\r
+                               case XML:\r
+                                       xml = str;\r
+                                       break;\r
+                               case JSON:\r
+                                       json = str;\r
+                                       break;\r
+                               default:\r
+                                       \r
+                               }\r
+               } catch (Exception e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+               return this;\r
+       }\r
+\r
+       // @Override\r
+       public RosettaData<T> load(T t) throws APIException {\r
+               Parse<?,?> in = df.getIn(inType);\r
+               TimeTaken tt = in.start(trans);\r
+               try {\r
+                       if(df.marshal==null) { // Unknown marshaller... do working XML marshal/extraction\r
+                               StringWriter sw = new StringWriter();\r
+                               df.jaxMar.marshal(trans.debug(), t, sw, options);\r
+                               saved.extract(new StringReader(xml = sw.toString()), (Writer)null, df.inXML);\r
+                       } else {\r
+                               saved.extract(t, (Writer)null, df.marshal);\r
+                       }\r
+               } catch (Exception e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+               return this;\r
+       }\r
+\r
+       public Saved getEvents() {\r
+               return saved;\r
+       }\r
+       \r
+       // @Override\r
+       public T asObject() throws APIException {\r
+               Out out = df.getOut(TYPE.XML);\r
+               TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env?\r
+               try {\r
+                       //TODO Replace JAXB with Direct Object method!!!\r
+                       StringWriter sw = new StringWriter();\r
+                       out.extract(null, sw, saved);\r
+                       return df.jaxUmar.unmarshal(trans.debug(), sw.toString());\r
+               } catch (Exception e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+       // @Override\r
+       public String asString() throws APIException {\r
+               Out out = df.getOut(outType);\r
+               TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env?\r
+               try {\r
+                       if(outType==TYPE.XML) {\r
+                               if(xml==null) {\r
+                                       StringWriter sw = new StringWriter();\r
+                                       out.extract(null, sw, saved, options);\r
+                                       xml = sw.toString();\r
+                               }\r
+                               return xml;\r
+                       } else {  // is JSON\r
+                               if(json==null) {\r
+                                       StringWriter sw = new StringWriter();\r
+                                       out.extract(null, sw, saved, options);\r
+                                       json = sw.toString();\r
+                               }\r
+                               return json;\r
+                       }\r
+               } catch (Exception e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+\r
+       // @Override\r
+       public RosettaData<T> to(OutputStream os) throws APIException, IOException {\r
+               Out out = df.getOut(outType);\r
+               TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env?\r
+               try {\r
+                       if(outType==TYPE.XML && xml!=null) {\r
+                               os.write(xml.getBytes());\r
+                       } else if(outType==TYPE.JSON && json!=null) {\r
+                               os.write(json.getBytes());\r
+                       } else { \r
+                               out.extract(null, os, saved, options);\r
+                       }\r
+               } catch (Exception e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+               return this;\r
+       }\r
+\r
+       // @Override\r
+       public RosettaData<T> to(Writer writer) throws APIException, IOException {\r
+               Out out = df.getOut(outType);\r
+               TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env?\r
+               try {\r
+                       if(outType==TYPE.XML && xml!=null) {\r
+                               writer.append(xml);\r
+                       } else if(outType==TYPE.JSON && json!=null) {\r
+                               writer.append(json);\r
+                       } else { \r
+                               out.extract(null, writer, saved, options);\r
+                       }\r
+               } catch (Exception e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+               return this;\r
+       }\r
+       \r
+       // @Override\r
+       public Class<T> getTypeClass() {\r
+               return df.getTypeClass();\r
+       }\r
+\r
+       private static final boolean[] emptyOption = new boolean[0];\r
+       \r
+       public void direct(InputStream is, OutputStream os) throws APIException, IOException {\r
+               direct(is,os,emptyOption);\r
+       }\r
+       \r
+       public void direct(Reader reader, Writer writer, boolean ... options) throws APIException, IOException {\r
+               Parse<Reader,?> in = df.getIn(inType);\r
+               Out out = df.getOut(outType);\r
+               TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env?\r
+               try {\r
+                       out.extract(reader, writer, in,options);\r
+               } catch (Exception e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+       public void direct(T t, Writer writer, boolean ... options) throws APIException, IOException {\r
+               Out out = df.getOut(outType);\r
+               TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env?\r
+               try {\r
+                       if(df.marshal==null) { // Unknown marshaller... do working XML marshal/extraction\r
+                               StringWriter sw = new StringWriter();\r
+                               df.jaxMar.marshal(trans.debug(), t, sw, options);\r
+                               out.extract(new StringReader(xml = sw.toString()), writer, df.inXML,options);\r
+                       } else {\r
+                               out.extract(t, writer, df.marshal,options);\r
+                       }\r
+               } catch (Exception e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+       public void direct(T t, OutputStream os, boolean ... options) throws APIException, IOException {\r
+               Out out = df.getOut(outType);\r
+               TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env?\r
+               try {\r
+                       if(df.marshal==null) { // Unknown marshaller... do working XML marshal/extraction\r
+                               if(outType.equals(TYPE.XML)) {\r
+                                       df.jaxMar.marshal(trans.debug(), t, os, options);\r
+                               } else {\r
+                                       StringWriter sw = new StringWriter();\r
+                                       df.jaxMar.marshal(trans.debug(), t, sw, options);\r
+                                       out.extract(new StringReader(xml = sw.toString()), new OutputStreamWriter(os), df.inXML,options);\r
+                               }\r
+                       } else {\r
+                               out.extract(t, new OutputStreamWriter(os), df.marshal,options);\r
+                       }\r
+\r
+               } catch (Exception e) {\r
+                       throw new APIException(e);\r
+               } finally {\r
+                       tt.done();\r
+               }\r
+       }\r
+\r
+       \r
+       public void direct(InputStream is, OutputStream os, boolean ... options) throws APIException, IOException {\r
+               direct(new InputStreamReader(is),new OutputStreamWriter(os), options);\r
+       }\r
+\r
+       // // @Override\r
+       public RosettaData<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
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/env/RosettaEnv.java b/rosetta/src/main/java/com/att/rosetta/env/RosettaEnv.java
new file mode 100644 (file)
index 0000000..78f963b
--- /dev/null
@@ -0,0 +1,90 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta.env;\r
+\r
+import java.applet.Applet;\r
+import java.util.Properties;\r
+\r
+import javax.xml.namespace.QName;\r
+import javax.xml.validation.Schema;\r
+\r
+import com.att.inno.env.APIException;\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
+ *\r
+ */\r
+public class RosettaEnv extends com.att.inno.env.impl.BasicEnv {\r
+\r
+       public RosettaEnv() {\r
+               super();\r
+       }\r
+\r
+       public RosettaEnv(Applet applet, String... tags) {\r
+               super(applet, tags);\r
+       }\r
+\r
+       public RosettaEnv(String[] args) {\r
+               super(args);\r
+       }\r
+\r
+       public RosettaEnv(String tag, String[] args) {\r
+               super(tag, args);\r
+       }\r
+\r
+       public RosettaEnv(String tag, Properties props) {\r
+               super(tag, props);\r
+       }\r
+\r
+       public RosettaEnv(Properties props) {\r
+               super(props);\r
+       }\r
+       \r
+       @SuppressWarnings("unchecked")\r
+       @Override\r
+       public <T> RosettaDF<T> newDataFactory(Class<?>... classes) throws APIException {\r
+               return new RosettaDF<T>(this, null, null, (Class<T>)classes[0]);\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       @Override\r
+       public <T> RosettaDF<T> newDataFactory(Schema schema, Class<?>... classes) throws APIException {\r
+                       return new RosettaDF<T>(this, schema, null, (Class<T>)classes[0]);\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       @Override\r
+       public<T> RosettaDF<T> newDataFactory(QName qName, Class<?> ... classes) throws APIException {\r
+               return new RosettaDF<T>(this, null, qName.getNamespaceURI(),(Class<T>)classes[0]);\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       @Override\r
+       public<T> RosettaDF<T> newDataFactory(Schema schema, QName qName, Class<?> ... classes) throws APIException {\r
+               return new RosettaDF<T>(this, schema,qName.getNamespaceURI(),(Class<T>)classes[0]);\r
+       }\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/DataWriter.java b/rosetta/src/main/java/com/att/rosetta/marshal/DataWriter.java
new file mode 100644 (file)
index 0000000..8d972d8
--- /dev/null
@@ -0,0 +1,140 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta.marshal;\r
+\r
+import javax.xml.datatype.XMLGregorianCalendar;\r
+\r
+import com.att.inno.env.util.Chrono;\r
+\r
+/**\r
+ * We make these objects instead of static functions so they can be passed into \r
+ * FieldArray.\r
+ * \r
+ *\r
+ * @param <T>\r
+ */\r
+public abstract class DataWriter<T> {\r
+       public abstract boolean write(T t, StringBuilder sb);\r
+       \r
+       public final static DataWriter<String> STRING = new DataWriter<String>() {\r
+               @Override\r
+               public boolean write(String s, StringBuilder sb) {\r
+                       sb.append(s);\r
+                       return true;\r
+               }               \r
+       };\r
+       \r
+       public final static DataWriter<Integer> INTEGER = new DataWriter<Integer>() {\r
+               @Override\r
+               public boolean write(Integer i, StringBuilder sb) {\r
+                       sb.append(i);\r
+                       return false;\r
+               }               \r
+       };\r
+       \r
+       public final static DataWriter<Long> LONG = new DataWriter<Long>() {\r
+               @Override\r
+               public boolean write(Long t, StringBuilder sb) {\r
+                       sb.append(t);\r
+                       return false;\r
+               }               \r
+       };\r
+\r
+       public final static DataWriter<Byte> BYTE = new DataWriter<Byte>() {\r
+               @Override\r
+               public boolean write(Byte t, StringBuilder sb) {\r
+                       sb.append(t);\r
+                       return false;\r
+               }               \r
+       };\r
+\r
+       public final static DataWriter<Character> CHAR = new DataWriter<Character>() {\r
+               @Override\r
+               public boolean write(Character t, StringBuilder sb) {\r
+                       sb.append(t);\r
+                       return true;\r
+               }               \r
+       };\r
+\r
+       public final static DataWriter<Boolean> BOOL = new DataWriter<Boolean>() {\r
+               @Override\r
+               public boolean write(Boolean t, StringBuilder sb) {\r
+                       sb.append(t);\r
+                       return true;\r
+               }               \r
+       };\r
+\r
+\r
+       /*\r
+       public final static DataWriter<byte[]> BYTE_ARRAY = new DataWriter<byte[]>() {\r
+               @Override\r
+               public boolean write(byte[] ba, StringBuilder sb) {\r
+                       ByteArrayInputStream bais = new ByteArrayInputStream(ba);\r
+                       StringBuilderOutputStream sbos = new StringBuilderOutputStream(sb);\r
+//                     try {\r
+                               //TODO find Base64\r
+//                             Symm.base64noSplit().encode(bais, sbos);\r
+//                     } catch (IOException e) {\r
+//                             // leave blank\r
+//                     }\r
+                       return true;\r
+               }\r
+               \r
+       };\r
+       */\r
+\r
+       public final static DataWriter<XMLGregorianCalendar> DATE = new DataWriter<XMLGregorianCalendar>() {\r
+               @Override\r
+               public boolean write(XMLGregorianCalendar t, StringBuilder sb) {\r
+                       sb.append(Chrono.dateOnlyStamp(t));\r
+                       return true;\r
+               }\r
+       };\r
+       \r
+       public final static DataWriter<XMLGregorianCalendar> DATE_TIME = new DataWriter<XMLGregorianCalendar>() {\r
+               @Override\r
+               public boolean write(XMLGregorianCalendar t, StringBuilder sb) {\r
+                       sb.append(Chrono.dateTime(t));\r
+                       return true;\r
+               }\r
+       };\r
+\r
+       private static final char[] chars="0123456789ABCDEF".toCharArray();\r
+       public final static DataWriter<byte[]> HEX_BINARY = new DataWriter<byte[]>() {\r
+               @Override\r
+               public boolean write(byte[] ba, StringBuilder sb) {\r
+                       // FYI, doing this because don't want intermediate \r
+                       // String in "HexString" or the processing in\r
+                       // "String.format"\r
+                       //sb.append("0x");\r
+                       for(int i=0;i<ba.length;++i) {\r
+                               byte b = ba[i];\r
+                               sb.append(chars[((b&0xF0)>>4)]);\r
+                               sb.append(chars[b&0xF]);\r
+                       }\r
+                       return true;\r
+               }\r
+       };\r
+\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/DocMarshal.java b/rosetta/src/main/java/com/att/rosetta/marshal/DocMarshal.java
new file mode 100644 (file)
index 0000000..27a4364
--- /dev/null
@@ -0,0 +1,84 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta.marshal;\r
+\r
+import java.util.Iterator;\r
+\r
+import com.att.rosetta.Ladder;\r
+import com.att.rosetta.Marshal;\r
+import com.att.rosetta.ParseException;\r
+import com.att.rosetta.Parsed;\r
+\r
+public class DocMarshal<T> extends Marshal<T> {\r
+       private Marshal<T> root;\r
+       \r
+       public DocMarshal(Marshal<T> root) {\r
+               this.root = root;\r
+       }\r
+       \r
+       @Override\r
+       public Parsed<State> parse(T t, Parsed<State> parsed) throws ParseException {\r
+               Ladder<Iterator<?>> ladder = parsed.state.ladder;\r
+               Iterator<?> iter = ladder.peek();\r
+               if(iter==null) {\r
+                       ladder.push(PENDING_ITERATOR);\r
+                       parsed.event = START_DOC;\r
+               } else if (DONE_ITERATOR.equals(iter)) {\r
+               } else {\r
+                       ladder.ascend(); // look at field info\r
+                               Iterator<?> currFieldIter = ladder.peek();\r
+                               if(!DONE_ITERATOR.equals(currFieldIter)){\r
+                                       parsed = root.parse(t, parsed);\r
+                               }\r
+                       ladder.descend();\r
+                       if(DONE_ITERATOR.equals(currFieldIter) || parsed.event==NONE) {\r
+                               parsed.event = END_DOC;\r
+                               ladder.push(DONE_ITERATOR);\r
+                       }\r
+               }\r
+               return parsed; // if unchanged, then it will end process\r
+\r
+       }\r
+\r
+       public static final Iterator<Void> PENDING_ITERATOR = new Iterator<Void>() {\r
+               @Override\r
+               public boolean hasNext() {\r
+                       return false;\r
+               }\r
+\r
+               @Override\r
+               public Void next() {\r
+                       return null;\r
+               }\r
+\r
+               @Override\r
+               public void remove() {\r
+               }\r
+       };\r
+\r
+       public static<T> DocMarshal<T> root(Marshal<T> m) {\r
+               return (DocMarshal<T>)new DocMarshal<T>(m);\r
+       }\r
+\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/FieldArray.java b/rosetta/src/main/java/com/att/rosetta/marshal/FieldArray.java
new file mode 100644 (file)
index 0000000..7931e73
--- /dev/null
@@ -0,0 +1,94 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta.marshal;\r
+\r
+import java.util.Iterator;\r
+import java.util.List;\r
+\r
+import com.att.rosetta.Ladder;\r
+import com.att.rosetta.Marshal;\r
+import com.att.rosetta.ParseException;\r
+import com.att.rosetta.Parsed;\r
+\r
+\r
+public abstract class FieldArray<T,S> extends Marshal<T> {\r
+       private DataWriter<S> dataWriter;\r
+       private String name;\r
+\r
+       public FieldArray(String name, DataWriter<S> dw) {\r
+               this.name = name;\r
+               dataWriter = dw;\r
+       }\r
+       \r
+       @SuppressWarnings("unchecked")\r
+       @Override\r
+       public Parsed<State> parse(T t, Parsed<State> parsed) throws ParseException {\r
+               Ladder<Iterator<?>> ladder = parsed.state.ladder;\r
+               Iterator<?> iter = ladder.peek();\r
+               if(iter==null) {\r
+                       List<S> list = data(t);\r
+                       if(list.isEmpty() && parsed.state.smallest) {\r
+                               ladder.push(DONE_ITERATOR);\r
+                       } else {\r
+                               ladder.push(new ListIterator<S>(list));\r
+                               parsed.event = START_ARRAY;\r
+                               parsed.name = name;\r
+                       }\r
+               } else if (DONE_ITERATOR.equals(iter)) {\r
+               } else {\r
+                       ladder.ascend(); // look at field info\r
+                               Iterator<?> memIter = ladder.peek();\r
+                               ListIterator<S> mems = (ListIterator<S>)iter;\r
+                               S mem;\r
+                               if(memIter==null) {\r
+                                       mem=mems.next();\r
+                               } else if(!DONE_ITERATOR.equals(memIter)) {\r
+                                       mem=mems.peek();\r
+                               } else if(iter.hasNext()) {\r
+                                       mem=null;\r
+                                       ladder.push(null);\r
+                               } else {\r
+                                       mem=null;\r
+                               }\r
+                               \r
+                               if(mem!=null) {\r
+                                       parsed.isString=dataWriter.write(mem, parsed.sb);\r
+                                       parsed.event = NEXT;\r
+                               }\r
+                       ladder.descend();\r
+                       if(mem==null) {\r
+                               if(iter.hasNext()) {\r
+                                       parsed.event = NEXT;\r
+                               } else {\r
+                                       parsed.event = END_ARRAY;\r
+                                       ladder.push(DONE_ITERATOR);\r
+                               }\r
+                       }\r
+               }\r
+               return parsed; // if unchanged, then it will end process\r
+       }\r
+\r
+       protected abstract List<S> data(T t);\r
+\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/FieldBlob.java b/rosetta/src/main/java/com/att/rosetta/marshal/FieldBlob.java
new file mode 100644 (file)
index 0000000..b80cb48
--- /dev/null
@@ -0,0 +1,40 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta.marshal;\r
+\r
+public abstract class FieldBlob<T> extends FieldMarshal<T>{\r
+       public FieldBlob(String name) {\r
+               super(name);\r
+       }\r
+\r
+       protected abstract byte[] data(T t); \r
+\r
+       @Override\r
+       protected boolean data(T t, StringBuilder sb) {\r
+               return false;\r
+               // unimplemented \r
+               //return DataWriter.BYTE_ARRAY.write(data(t),sb);\r
+       }\r
+\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/FieldDate.java b/rosetta/src/main/java/com/att/rosetta/marshal/FieldDate.java
new file mode 100644 (file)
index 0000000..c2a8c03
--- /dev/null
@@ -0,0 +1,39 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta.marshal;\r
+\r
+import javax.xml.datatype.XMLGregorianCalendar;\r
+\r
+public abstract class FieldDate<T> extends FieldMarshal<T> {\r
+       public FieldDate(String name) {\r
+               super(name);\r
+       }\r
+\r
+       @Override\r
+       final protected boolean data(T t, StringBuilder sb) {\r
+               return DataWriter.DATE.write(data(t), sb);\r
+       }\r
+\r
+       protected abstract XMLGregorianCalendar data(T t); \r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/FieldDateTime.java b/rosetta/src/main/java/com/att/rosetta/marshal/FieldDateTime.java
new file mode 100644 (file)
index 0000000..ce14c7f
--- /dev/null
@@ -0,0 +1,39 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta.marshal;\r
+\r
+import javax.xml.datatype.XMLGregorianCalendar;\r
+\r
+public abstract class FieldDateTime<T> extends FieldMarshal<T> {\r
+       public FieldDateTime(String name) {\r
+               super(name);\r
+       }\r
+\r
+       @Override\r
+       final protected boolean data(T t, StringBuilder sb) {\r
+               return DataWriter.DATE_TIME.write(data(t), sb);\r
+       }\r
+\r
+       protected abstract XMLGregorianCalendar data(T t); \r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/FieldHexBinary.java b/rosetta/src/main/java/com/att/rosetta/marshal/FieldHexBinary.java
new file mode 100644 (file)
index 0000000..125f332
--- /dev/null
@@ -0,0 +1,37 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta.marshal;\r
+\r
+public abstract class FieldHexBinary<T> extends FieldMarshal<T>{\r
+       public FieldHexBinary(String name) {\r
+               super(name);\r
+       }\r
+\r
+       protected abstract byte[] data(T t); \r
+\r
+       @Override\r
+       protected boolean data(T t, StringBuilder sb) {\r
+               return DataWriter.HEX_BINARY.write(data(t), sb);\r
+       }\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/FieldMarshal.java b/rosetta/src/main/java/com/att/rosetta/marshal/FieldMarshal.java
new file mode 100644 (file)
index 0000000..63ba3b9
--- /dev/null
@@ -0,0 +1,61 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta.marshal;\r
+\r
+\r
+import com.att.rosetta.Marshal;\r
+import com.att.rosetta.Parse;\r
+import com.att.rosetta.Parsed;\r
+\r
+public abstract class FieldMarshal<T> extends Marshal<T> {\r
+       private String name;\r
+\r
+       public FieldMarshal(String name) {\r
+               this.name = name;\r
+       }\r
+       \r
+       public String getName() {\r
+               return name;\r
+       }\r
+       \r
+       @Override\r
+       public Parsed<State> parse(T t, Parsed<State> parsed) {\r
+               parsed.state.ladder.push(DONE_ITERATOR);\r
+               parsed.event = Parse.NEXT;\r
+               parsed.name = name;\r
+               parsed.isString = data(t,parsed.sb);\r
+               return parsed;\r
+       }\r
+\r
+       /**\r
+        * Write Value to StringBuilder\r
+        * Return true if value looks like a String\r
+        *        false if it is Numeric\r
+        * @param t\r
+        * @param sb\r
+        * @return\r
+        */\r
+       protected abstract boolean data(T t, StringBuilder sb);\r
+       \r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/FieldNumeric.java b/rosetta/src/main/java/com/att/rosetta/marshal/FieldNumeric.java
new file mode 100644 (file)
index 0000000..b53f12e
--- /dev/null
@@ -0,0 +1,38 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta.marshal;\r
+\r
+public abstract class FieldNumeric<N,T> extends FieldMarshal<T> {\r
+       public FieldNumeric(String name) {\r
+               super(name);\r
+       }\r
+\r
+       @Override\r
+       final protected boolean data(T t, StringBuilder sb) {\r
+               sb.append(data(t));\r
+               return false;\r
+       }\r
+\r
+       protected abstract N data(T t); \r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/FieldString.java b/rosetta/src/main/java/com/att/rosetta/marshal/FieldString.java
new file mode 100644 (file)
index 0000000..6fd3424
--- /dev/null
@@ -0,0 +1,38 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta.marshal;\r
+\r
+public abstract class FieldString<T> extends FieldMarshal<T> {\r
+       public FieldString(String name) {\r
+               super(name);\r
+       }\r
+\r
+       protected abstract String data(T t); \r
+\r
+       @Override\r
+       final protected boolean data(T t, StringBuilder sb) {\r
+               return DataWriter.STRING.write(data(t), sb);\r
+       }\r
+\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/ListIterator.java b/rosetta/src/main/java/com/att/rosetta/marshal/ListIterator.java
new file mode 100644 (file)
index 0000000..b444c68
--- /dev/null
@@ -0,0 +1,60 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta.marshal;\r
+\r
+import java.util.Iterator;\r
+import java.util.List;\r
+\r
+/**\r
+ * Need an Iterator that can peek the current value without changing\r
+ *\r
+ * @param <T>\r
+ */\r
+final class ListIterator<T> implements Iterator<T> {\r
+       private T curr;\r
+       private Iterator<T> delg;\r
+       public ListIterator(List<T> list) {\r
+               curr = null;\r
+               delg = list.iterator(); \r
+       }\r
+       @Override\r
+       public boolean hasNext() {\r
+               return delg.hasNext();\r
+       }\r
+\r
+       @Override\r
+       public T next() {\r
+               return curr = delg.hasNext()?delg.next():null;\r
+       }\r
+       \r
+       public T peek() {\r
+               return curr==null?next():curr;\r
+       }\r
+\r
+       @Override\r
+       public void remove() {\r
+               delg.remove();\r
+       }\r
+       \r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/ObjArray.java b/rosetta/src/main/java/com/att/rosetta/marshal/ObjArray.java
new file mode 100644 (file)
index 0000000..89e07c5
--- /dev/null
@@ -0,0 +1,92 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta.marshal;\r
+\r
+import java.util.Iterator;\r
+import java.util.List;\r
+\r
+import com.att.rosetta.Ladder;\r
+import com.att.rosetta.Marshal;\r
+import com.att.rosetta.ParseException;\r
+import com.att.rosetta.Parsed;\r
+\r
+\r
+public abstract class ObjArray<T,S> extends Marshal<T> {\r
+       private String name;\r
+       private Marshal<S> subMarshaller;\r
+\r
+       public ObjArray(String name, Marshal<S> subMarshaller) {\r
+               this.name = name;\r
+               this.subMarshaller = subMarshaller;\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       @Override\r
+       public Parsed<State> parse(T t, Parsed<State> parsed) throws ParseException {\r
+               Ladder<Iterator<?>> ladder = parsed.state.ladder;\r
+               Iterator<?> iter = ladder.peek();\r
+               if(iter==null) {\r
+                       List<S> list = data(t);\r
+                       if(list.isEmpty() && parsed.state.smallest) {\r
+                               ladder.push(DONE_ITERATOR);\r
+                       } else {\r
+                               ladder.push(new ListIterator<S>(list));\r
+                               parsed.event = START_ARRAY;\r
+                               parsed.name = name;\r
+                       }\r
+               } else if (DONE_ITERATOR.equals(iter)) {\r
+               } else {\r
+                       ladder.ascend(); // look at field info\r
+                               Iterator<?> memIter = ladder.peek();\r
+                               ListIterator<S> mems = (ListIterator<S>)iter;\r
+                               S mem;\r
+                               if(memIter==null) {\r
+                                       mem=mems.next();\r
+                               } else if(!DONE_ITERATOR.equals(memIter)) {\r
+                                       mem=mems.peek();\r
+                               } else if(iter.hasNext()) {\r
+                                       mem=null;\r
+                                       ladder.push(null);\r
+                               } else {\r
+                                       mem=null;\r
+                               }\r
+                               \r
+                               if(mem!=null)\r
+                                       parsed = subMarshaller.parse(mem, parsed);\r
+                       ladder.descend();\r
+                       if(mem==null) {\r
+                               if(iter.hasNext()) {\r
+                                       parsed.event = NEXT;\r
+                               } else {\r
+                                       parsed.event = END_ARRAY;\r
+                                       ladder.push(DONE_ITERATOR);\r
+                               }\r
+                       }\r
+               }\r
+               return parsed; // if unchanged, then it will end process\r
+       }\r
+\r
+       protected abstract List<S> data(T t);\r
+\r
+}\r
diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/ObjMarshal.java b/rosetta/src/main/java/com/att/rosetta/marshal/ObjMarshal.java
new file mode 100644 (file)
index 0000000..981dd78
--- /dev/null
@@ -0,0 +1,129 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.rosetta.marshal;\r
+\r
+import java.util.Iterator;\r
+\r
+import com.att.rosetta.Ladder;\r
+import com.att.rosetta.Marshal;\r
+import com.att.rosetta.ParseException;\r
+import com.att.rosetta.Parsed;\r
+\r
+/**\r
+ * Object Marshal\r
+ * Assumes has Fields and other Objects\r
+ * s\r
+ *\r
+ * @param <T>\r
+ */\r
+public abstract class ObjMarshal<T> extends Marshal<T> {\r
+       // Note: Not Using List or ArrayList, because there is no "Peek" concept in their iterator.\r
+       private Marshal<T>[] pml;\r
+       private int end=0;\r
+       \r
+       /**\r
+        * @param pm\r
+        */\r
+       @SuppressWarnings("unchecked")\r
+       protected void add(Marshal<T> pm) {\r
+               if(pml==null) {\r
+                       pml = new Marshal[Ladder.DEFAULT_INIT_SIZE]; \r
+               } else if(end>pml.length) {\r
+                       Object temp[] = pml; \r
+                       pml = new Marshal[pml.length+Ladder.DEFAULT_INIT_SIZE];\r
+                       System.arraycopy(temp, 0, pml, 0, pml.length);\r
+               }\r
+               pml[end]=pm;\r
+               ++end;\r
+       }\r
+       \r
+       /* (non-Javadoc)\r
+        * @see com.att.rosetta.Parse#parse(java.lang.Object, com.att.rosetta.Parsed)\r
+        */\r
+       @SuppressWarnings("unchecked")\r
+       @Override\r
+       public Parsed<State> parse(T in, Parsed<State> parsed) throws ParseException {\r
+               Ladder<Iterator<?>> ladder = parsed.state.ladder;\r
+               Iterator<Marshal<T>> iter = (Iterator<Marshal<T>>)ladder.peek();\r
+               if(iter==null) {\r
+                       if(pml.length>0) {\r
+                               ladder.push(new FieldsIterator());\r
+                               parsed.event = START_OBJ;\r
+                       } else {\r
+                               ladder.push(DONE_ITERATOR);\r
+                       }\r
+               } else if (DONE_ITERATOR.equals(iter)) {\r
+               } else {\r
+                       FieldsIterator fields = (FieldsIterator)iter;\r
+                       ladder.ascend(); // look at field info\r
+                               Iterator<?> currFieldIter = ladder.peek();\r
+                               Marshal<T> marshal;\r
+                               if(currFieldIter==null) {\r
+                                       marshal=fields.next();\r
+                               } else if(!DONE_ITERATOR.equals(currFieldIter)) {\r
+                                       marshal=fields.peek();\r
+                                       if(marshal==null && fields.hasNext())marshal=fields.next();\r
+                               } else if(fields.hasNext()) {\r
+                                       marshal=fields.next();\r
+                                       ladder.push(null);\r
+                               } else {\r
+                                       marshal=null;\r
+                               }\r
+                               \r
+                               if(marshal!=null)\r
+                                       parsed = marshal.parse(in, parsed);\r
+                       ladder.descend();\r
+                       if(marshal==null || parsed.event==NONE) {\r
+                               parsed.event = END_OBJ;\r
+                               ladder.push(DONE_ITERATOR);\r
+                       }\r
+               }\r
+               return parsed; // if unchanged, then it will end process\r
+       }\r
+\r
+       private class FieldsIterator implements Iterator<Marshal<T>> {\r
+               private int idx = -1;\r
+\r
+               @Override\r
+               public boolean hasNext() {\r
+                       return idx<end;\r
+               }\r
+\r
+               @Override\r
+               public Marshal<T> next() {\r
+                       return pml[++idx];\r
+               }\r
+\r
+               public Marshal<T> peek() {\r
+                       return idx<0?null:pml[idx];\r
+               }\r
+               \r
+               @Override\r
+               public void remove() {\r
+                       pml[idx]=null;\r
+               }\r
+               \r
+       }\r
+\r
+}\r
diff --git a/rosetta/src/main/xsd/inherit.xsd b/rosetta/src/main/xsd/inherit.xsd
new file mode 100644 (file)
index 0000000..9c11ef0
--- /dev/null
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!--\r
+  ============LICENSE_START====================================================\r
+  * org.onap.aai\r
+  * ===========================================================================\r
+  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+  * Copyright © 2017 Amdocs\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
+  * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+  *\r
+-->\r
+<xs:schema elementFormDefault="qualified" \r
+       targetNamespace="urn:inherit"\r
+       xmlns="urn:inherit" \r
+       xmlns:xs="http://www.w3.org/2001/XMLSchema"\r
+       >\r
+       \r
+       <xs:complexType name="baseType">\r
+               <xs:sequence>\r
+                       <xs:element name="name" type="xs:string" minOccurs="1" maxOccurs="1" />\r
+                       <xs:element name="num" type="xs:short" minOccurs="0" maxOccurs="1" />\r
+               </xs:sequence> \r
+       </xs:complexType>\r
+       \r
+       <xs:complexType name="derivedA">\r
+               <xs:annotation>\r
+                       <xs:documentation>Select one of the items</xs:documentation>\r
+               </xs:annotation>\r
+               <xs:complexContent>\r
+                       <xs:extension base="baseType">\r
+                               <xs:sequence>\r
+                                       <xs:element name="shortName" type="xs:string" minOccurs="0" maxOccurs="1" />\r
+                                       <xs:element name="value" type="xs:string" minOccurs="0" maxOccurs="unbounded" />\r
+                               </xs:sequence>  \r
+                       </xs:extension>\r
+               </xs:complexContent>\r
+       </xs:complexType>\r
+                        \r
+       <xs:element name="root">\r
+               <xs:complexType>\r
+                       <xs:sequence>\r
+                               <xs:element name="base" type="baseType" minOccurs="0" maxOccurs="unbounded" />          \r
+                       </xs:sequence>\r
+               </xs:complexType>\r
+       </xs:element>\r
+       \r
+</xs:schema>\r
diff --git a/rosetta/src/main/xsd/s.xsd b/rosetta/src/main/xsd/s.xsd
new file mode 100644 (file)
index 0000000..8a530a7
--- /dev/null
@@ -0,0 +1,67 @@
+<!--\r
+  ============LICENSE_START====================================================\r
+  * org.onap.aai\r
+  * ===========================================================================\r
+  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+  * Copyright © 2017 Amdocs\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
+  * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+  *\r
+-->\r
+<xs:schema elementFormDefault="qualified" \r
+                  targetNamespace="urn:s:xsd" \r
+                  xmlns:s="urn:s:xsd" \r
+                  xmlns:xs="http://www.w3.org/2001/XMLSchema"\r
+                  >\r
+                  \r
+       <xs:element name="SampleData">\r
+               <xs:complexType>\r
+                       <xs:sequence>\r
+                               <xs:element name="id" type="xs:string" minOccurs="1" maxOccurs="1" />\r
+                               <xs:element name="date" type="xs:long"/>\r
+                               <xs:element name="item" type="xs:string" maxOccurs="unbounded" />                                \r
+                       </xs:sequence>\r
+               </xs:complexType>\r
+       </xs:element>\r
+       \r
+       <xs:element name="LargerData">\r
+               <xs:complexType>\r
+                       <xs:sequence>\r
+                               <xs:element ref="s:SampleData" minOccurs="1" maxOccurs="unbounded"/>\r
+                               <xs:element name="fluff" type="xs:string"/>\r
+                       </xs:sequence>\r
+               </xs:complexType>\r
+       </xs:element>\r
+       \r
+       <xs:element name="LargerDatas">\r
+               <xs:complexType>\r
+                       <xs:sequence>\r
+                               <xs:element ref="s:LargerData" minOccurs="1" maxOccurs = "unbounded"/>\r
+                       </xs:sequence>\r
+               </xs:complexType>\r
+       </xs:element>\r
+       \r
+\r
+       <xs:element name="Multi">\r
+               <xs:complexType>\r
+                       <xs:sequence>\r
+                               <xs:element name="f1" type="xs:string" minOccurs="0" maxOccurs = "unbounded"/>\r
+                               <xs:element name="f2" type="xs:string" minOccurs="0" maxOccurs = "unbounded"/>\r
+                       </xs:sequence>\r
+               </xs:complexType>\r
+       </xs:element>\r
+       \r
+</xs:schema>\r
diff --git a/rosetta/src/main/xsd/types.xsd b/rosetta/src/main/xsd/types.xsd
new file mode 100644 (file)
index 0000000..588d9d4
--- /dev/null
@@ -0,0 +1,49 @@
+<!--\r
+  ============LICENSE_START====================================================\r
+  * org.onap.aai\r
+  * ===========================================================================\r
+  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+  * Copyright © 2017 Amdocs\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
+  * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+  *\r
+-->\r
+<xs:schema elementFormDefault="qualified" \r
+                  targetNamespace="urn:types:xsd" \r
+                  xmlns:s="urn:types:xsd" \r
+                  xmlns:xs="http://www.w3.org/2001/XMLSchema"\r
+                  >\r
+       <xs:element name="multi">\r
+               <xs:complexType>\r
+                       <xs:sequence>\r
+                               <xs:element name="single" minOccurs="0" maxOccurs="unbounded">\r
+                                       <xs:complexType>\r
+                                               <xs:sequence>\r
+                                                       <xs:element name="str" type="xs:string" minOccurs="1" maxOccurs="1" />\r
+                                                       <xs:element name="int" type="xs:int" minOccurs="1" maxOccurs="1" />\r
+                                                       <xs:element name="long" type="xs:long" minOccurs="1" maxOccurs="1" />\r
+                                                       <xs:element name="date" type="xs:date" minOccurs="1" maxOccurs="1" />\r
+                                                       <xs:element name="datetime" type="xs:dateTime" minOccurs="1" maxOccurs="1" />\r
+                                                       <xs:element name="binary" type="xs:hexBinary" minOccurs="1" maxOccurs="1" />\r
+                                                       <xs:element name="array" type="xs:string" minOccurs="0" maxOccurs="unbounded" />\r
+                                               </xs:sequence>\r
+                                       </xs:complexType>\r
+                               </xs:element>\r
+                       </xs:sequence>\r
+               </xs:complexType>\r
+       </xs:element>              \r
+                  \r
+</xs:schema>\r
diff --git a/rosetta/src/test/java/com/data/test/JU_FromJSON.java b/rosetta/src/test/java/com/data/test/JU_FromJSON.java
new file mode 100644 (file)
index 0000000..4e3d211
--- /dev/null
@@ -0,0 +1,271 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.data.test;\r
+\r
+import java.io.Reader;\r
+import java.io.StringReader;\r
+\r
+import org.junit.Test;\r
+\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.LogTarget;\r
+import com.att.inno.env.TimeTaken;\r
+import com.att.inno.env.Trans;\r
+import com.att.inno.env.impl.EnvFactory;\r
+import com.att.inno.env.jaxb.JAXBmar;\r
+import com.att.inno.env.util.IndentPrintWriter;\r
+import com.att.inno.env.util.StringBuilderWriter;\r
+import com.att.rosetta.InJson;\r
+import com.att.rosetta.Out;\r
+import com.att.rosetta.OutJson;\r
+import com.att.rosetta.OutRaw;\r
+import com.att.rosetta.OutXML;\r
+\r
+import junit.framework.Assert;\r
+import s.xsd.LargerData;\r
+import s.xsd.SampleData;\r
+\r
+public class JU_FromJSON {\r
+       private static int ITERATIONS = 10000;\r
+       static String str = "{\"SampleData\":[" +\r
+                                                  "{\"id\":\"sd object \\\"1\\\"\",\"date\":1316084944213,\"item\":[\"Item 1.1\",\"Item 1.2\"]}," +\r
+                                                  "{\"id\":\"sd object \\\"2\\\"\",\"date\":1316084945343,\"item\":[\"Item 2.1\",\"Item 2.2\"]}],\"fluff\":\"MyFluff\"}";\r
+       InJson inJSON = new InJson();\r
+\r
+       @Test\r
+       public void rawParse() throws Exception {\r
+               System.out.println("*** PARSE JSON -> RAW Dump ***");\r
+               System.out.println(str);\r
+               StringBuilderWriter sbw = new StringBuilderWriter();\r
+               new OutRaw().extract(new StringReader(str),sbw,inJSON);\r
+               System.out.println(sbw.getBuffer());\r
+       }\r
+       \r
+       @Test\r
+       public void parseJSON2Dump() throws Exception {\r
+               System.out.println("*** PARSE JSON -> Dump ***");\r
+               System.out.println(str);\r
+               StringBuilderWriter sbw = new StringBuilderWriter(1024);\r
+               \r
+               new OutDump().extract(new StringReader(str), sbw, inJSON);\r
+               \r
+               System.out.println(sbw.getBuffer());\r
+       }\r
+       \r
+       @Test\r
+       public void nonprettyJSON() throws Exception {\r
+               System.out.println("*** JSON -> (Intermediate Stream) -> Non-pretty JSON ***");\r
+               System.out.println(str);\r
+               StringBuilderWriter sbw = new StringBuilderWriter(1024);\r
+\r
+               Out jout = new OutJson();\r
+               Trans trans;\r
+               Report report = new Report(ITERATIONS,"JSON");\r
+               do {\r
+                       sbw.reset();\r
+                       trans = EnvFactory.newTrans();\r
+                       Reader sr = new StringReader(str);\r
+                       TimeTaken tt = trans.start("Parse JSON", Env.JSON);\r
+                       try {\r
+                               jout.extract(sr, sbw, inJSON);\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+                       report.glean(trans,Env.JSON);\r
+               } while(report.go());\r
+               \r
+               String result = sbw.toString();\r
+               System.out.println(result);\r
+               Assert.assertEquals(result, str);\r
+               report.report(sbw);\r
+               System.out.println(sbw.toString());\r
+       }\r
+       \r
+       @Test\r
+       public void parseJSON2JSON() throws Exception {\r
+               System.out.println("*** JSON -> (Intermediate Stream) -> Pretty JSON ***");\r
+               System.out.println(str);\r
+\r
+               StringBuilderWriter sbw = new StringBuilderWriter(1024);\r
+               \r
+               Out jout = new OutJson();\r
+               Trans trans;\r
+               Report report = new Report(ITERATIONS,"JSON");\r
+               do {\r
+                       sbw.reset();\r
+                       trans = EnvFactory.newTrans();\r
+                       Reader sr = new StringReader(str);\r
+                       TimeTaken tt = trans.start("Parse JSON", Env.JSON);\r
+                       try {\r
+                               jout.extract(sr, sbw, inJSON,true);\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+                       report.glean(trans,Env.JSON);\r
+               } while(report.go());\r
+               \r
+               report.report(sbw);\r
+               System.out.println(sbw.toString());\r
+       }\r
+\r
+       @Test\r
+       public void parseJSON2XML() throws Exception {\r
+               System.out.println("*** PARSE JSON -> XML ***");\r
+               System.out.println(str);\r
+\r
+               StringBuilderWriter sbw = new StringBuilderWriter(1024);\r
+               \r
+               Out xout = new OutXML("LargerData","xmlns=urn:s:xsd");\r
+               Trans trans;\r
+               Report report = new Report(ITERATIONS,"JSON");\r
+               do {\r
+                       sbw.reset();\r
+                       trans = EnvFactory.newTrans();\r
+                       Reader sr = new StringReader(str);\r
+                       TimeTaken tt = trans.start("Parse JSON", Env.JSON);\r
+                       try {\r
+                               xout.extract(sr, sbw, inJSON);\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+                       report.glean(trans,Env.JSON);\r
+               } while(report.go());\r
+               \r
+               report.report(sbw);\r
+               System.out.println(sbw.toString());\r
+       }\r
+\r
+       @Test\r
+       public void parseJSON2PrettyXML() throws Exception {\r
+               System.out.println("*** PARSE JSON -> Pretty XML ***");\r
+               System.out.println(str);\r
+\r
+               StringBuilderWriter sbw = new StringBuilderWriter(1024);\r
+               IndentPrintWriter ipw = new IndentPrintWriter(sbw);\r
+               \r
+               Out xout = new OutXML("LargerData","xmlns=urn:s:xsd");\r
+               Trans trans;\r
+               Report report = new Report(ITERATIONS,"JSON");\r
+               do {\r
+                       sbw.reset();\r
+                       trans = EnvFactory.newTrans();\r
+                       Reader sr = new StringReader(str);\r
+                       TimeTaken tt = trans.start("Parse JSON", Env.JSON);\r
+                       try {\r
+                               xout.extract(sr, ipw, inJSON);\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+                       report.glean(trans,Env.JSON);\r
+               } while(report.go());\r
+               \r
+               report.report(sbw);\r
+               System.out.println(sbw.toString());\r
+       }\r
+       \r
+               \r
+       @Test\r
+       public void jaxbObj2XML() throws Exception {\r
+               System.out.println("*** JAXB Object -> XML ***");\r
+\r
+               LargerData ld = new LargerData();\r
+               SampleData sd = new SampleData();\r
+               sd.setDate(System.currentTimeMillis());\r
+               sd.setId("sd object \"1\"");\r
+               sd.getItem().add("Item 1.1");\r
+               sd.getItem().add("Item 1.2");\r
+               ld.getSampleData().add(sd);\r
+               sd = new SampleData();\r
+               sd.setDate(System.currentTimeMillis());\r
+               sd.setId("sd object \"2\"");\r
+               sd.getItem().add("Item 2.1");\r
+               sd.getItem().add("Item 2.2");\r
+               ld.getSampleData().add(sd);\r
+               ld.setFluff("MyFluff");\r
+               \r
+               JAXBmar jaxBmar = new JAXBmar(LargerData.class);\r
+               //jaxBmar.asFragment(true);\r
+               //jaxBmar.pretty(true);\r
+               StringBuilderWriter sbw = new StringBuilderWriter(1024);\r
+\r
+               Trans trans;\r
+               Report report = new Report(ITERATIONS,"XML");\r
+               do {\r
+                       sbw.reset();\r
+                       trans = EnvFactory.newTrans();\r
+                       TimeTaken tt = trans.start("JAXB", Env.XML);\r
+                       try {\r
+                               jaxBmar.marshal(LogTarget.NULL, ld, sbw);\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+                       report.glean(trans,Env.XML);\r
+               } while(report.go());\r
+               \r
+               report.report(sbw);\r
+               System.out.println(sbw.toString());\r
+       }\r
+\r
+       @Test\r
+       public void jaxbObj2PrettyXML() throws Exception {\r
+               System.out.println("*** JAXB Object -> Pretty XML ***");\r
+\r
+               LargerData ld = new LargerData();\r
+               SampleData sd = new SampleData();\r
+               sd.setDate(System.currentTimeMillis());\r
+               sd.setId("sd object \"1\"");\r
+               sd.getItem().add("Item 1.1");\r
+               sd.getItem().add("Item 1.2");\r
+               ld.getSampleData().add(sd);\r
+               sd = new SampleData();\r
+               sd.setDate(System.currentTimeMillis());\r
+               sd.setId("sd object \"2\"");\r
+               sd.getItem().add("Item 2.1");\r
+               sd.getItem().add("Item 2.2");\r
+               ld.getSampleData().add(sd);\r
+               ld.setFluff("MyFluff");\r
+               \r
+               JAXBmar jaxBmar = new JAXBmar(LargerData.class);\r
+               //jaxBmar.asFragment(true);\r
+               jaxBmar.pretty(true);\r
+               StringBuilderWriter sbw = new StringBuilderWriter(1024);\r
+\r
+               Trans trans;\r
+               Report report = new Report(ITERATIONS,"XML");\r
+               do {\r
+                       sbw.reset();\r
+                       trans = EnvFactory.newTrans();\r
+                       TimeTaken tt = trans.start("JAXB", Env.XML);\r
+                       try {\r
+                               jaxBmar.marshal(LogTarget.NULL, ld, sbw);\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+                       report.glean(trans,Env.XML);\r
+               } while(report.go());\r
+\r
+               report.report(sbw);\r
+               System.out.println(sbw.toString());\r
+       }\r
+}\r
diff --git a/rosetta/src/test/java/com/data/test/JU_FromXML.java b/rosetta/src/test/java/com/data/test/JU_FromXML.java
new file mode 100644 (file)
index 0000000..506b6c8
--- /dev/null
@@ -0,0 +1,262 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.data.test;\r
+\r
+import java.io.Reader;\r
+import java.io.StringReader;\r
+\r
+import org.junit.Test;\r
+\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.LogTarget;\r
+import com.att.inno.env.TimeTaken;\r
+import com.att.inno.env.Trans;\r
+import com.att.inno.env.Trans.Metric;\r
+import com.att.inno.env.impl.EnvFactory;\r
+import com.att.inno.env.jaxb.JAXBmar;\r
+import com.att.inno.env.jaxb.JAXBumar;\r
+import com.att.inno.env.util.StringBuilderWriter;\r
+import com.att.rosetta.InXML;\r
+import com.att.rosetta.Out;\r
+import com.att.rosetta.OutJson;\r
+import com.att.rosetta.OutRaw;\r
+import com.att.rosetta.OutXML;\r
+\r
+import s.xsd.LargerData;\r
+\r
+public class JU_FromXML {\r
+       private static int ITERATIONS = 1;\r
+               ;\r
+       \r
+       private final static String xml = \r
+       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +\r
+       "<LargerData xmlns=\"urn:s:xsd\">\n" +\r
+       "   <SampleData>\n" +\r
+       "      <id>sd object 1</id>\n" +\r
+       "        <date>1346765355134</date>\n" +\r
+       "        <item>Item 1.1</item>\n" +\r
+       "        <item>Item 1.2</item>\n" +\r
+       "   </SampleData>\n" +\r
+       "   <SampleData>\n" +\r
+       "        <id>sd object 2</id>\n" +\r
+       "        <date>1346765355134</date>\n" +\r
+       "        <item>Item 2.1</item>\n" +\r
+       "        <item>Item 2.2</item>\n" +\r
+       "   </SampleData>\n" +\r
+       "   <fluff>MyFluff</fluff>\n" +\r
+       "</LargerData>\n";\r
+       \r
+       \r
+       @Test\r
+       public void test() throws Exception {\r
+               InXML inXML = new InXML(LargerData.class);\r
+               \r
+               System.out.println(xml);\r
+               StringBuilderWriter sbw = new StringBuilderWriter(1024);\r
+               \r
+               Reader rdr = new StringReader(xml);\r
+               \r
+               new OutRaw().extract(rdr, sbw, inXML);\r
+               System.out.println(sbw.getBuffer());\r
+       }\r
+       \r
+\r
+       @Test\r
+       public void xml2JSON() throws Exception {\r
+               System.out.println("*** XML -> JSON  (No Warm up) ***");\r
+               Out jout = new OutJson();\r
+               InXML inXML = new InXML(LargerData.class);\r
+\r
+               StringBuilderWriter sbw = new StringBuilderWriter(1024);\r
+               \r
+               Trans trans;\r
+               Report report = new Report(ITERATIONS,"XML");\r
+               do {\r
+                       sbw.reset();\r
+                       trans = EnvFactory.newTrans();\r
+                       Reader sr = new StringReader(xml);\r
+                       TimeTaken tt = trans.start("Parse XML", Env.XML);\r
+                       try {\r
+                               jout.extract(sr, sbw, inXML);\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+                       report.glean(trans,Env.XML);\r
+               } while(report.go());\r
+               \r
+               report.report(sbw);\r
+               System.out.println(sbw.toString());\r
+       }\r
+\r
+       @Test\r
+       public void xml2XML() throws Exception {\r
+               System.out.println("*** XML -> (Event Queue) -> XML (No Warm up) ***");\r
+               Out xout = new OutXML("LargerData");\r
+               InXML inXML = new InXML(LargerData.class);\r
+\r
+               StringBuilderWriter sbw = new StringBuilderWriter(1024);\r
+               \r
+               Trans trans;\r
+               Report report = new Report(ITERATIONS,"XML");\r
+               do {\r
+                       sbw.reset();\r
+                       trans = EnvFactory.newTrans();\r
+                       Reader sr = new StringReader(xml);\r
+                       TimeTaken tt = trans.start("Parse XML", Env.XML);\r
+                       try {\r
+                               xout.extract(sr, sbw, inXML);\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+                       report.glean(trans,Env.XML);\r
+               } while(report.go());\r
+               \r
+               report.report(sbw);\r
+               System.out.println(sbw.toString());\r
+       }\r
+       \r
+       \r
+       @Test\r
+       public void warmup() throws Exception {\r
+               if(ITERATIONS>20) {\r
+                       System.out.println("*** Warmup JAXB ***");\r
+                       \r
+                       JAXBumar jaxbUmar = new JAXBumar(LargerData.class);\r
+                       JAXBmar jaxBmar = new JAXBmar(LargerData.class);\r
+                       //jaxBmar.asFragment(true);\r
+                       //jaxBmar.pretty(true);\r
+                       StringBuilderWriter sbw = new StringBuilderWriter(1024);\r
+       \r
+\r
+                       LargerData ld;\r
+                       Trans trans;\r
+                       Report report = new Report(ITERATIONS,"XML");\r
+                       do {\r
+                               sbw.reset();\r
+                               trans = EnvFactory.newTrans();\r
+                               TimeTaken all = trans.start("Combo", Env.SUB);\r
+                               try {\r
+                                       TimeTaken tt = trans.start("JAXB Unmarshal", Env.XML);\r
+                                       try {\r
+                                               ld = jaxbUmar.unmarshal(LogTarget.NULL, xml);\r
+                                       } finally {\r
+                                               tt.done();\r
+                                       }\r
+                                       tt = trans.start("JAXB marshal", Env.XML);\r
+                                       try {\r
+                                               jaxBmar.marshal(LogTarget.NULL, ld, sbw);\r
+                                       } finally {\r
+                                               tt.done();\r
+                                       }\r
+                               } finally {\r
+                                       all.done();\r
+                               }\r
+                               report.glean(trans,Env.XML);\r
+                       } while(report.go());\r
+                       \r
+                       report.report(sbw);\r
+                       System.out.println(sbw.toString());\r
+               }\r
+       }\r
+       @Test\r
+       public void xml2jaxb2xml() throws Exception {\r
+               System.out.println("*** XML -> JAXB Object -> XML ***");\r
+               JAXBumar jaxbUmar = new JAXBumar(LargerData.class);\r
+               JAXBmar jaxBmar = new JAXBmar(LargerData.class);\r
+               //jaxBmar.asFragment(true);\r
+               //jaxBmar.pretty(true);\r
+               StringBuilderWriter sbw = new StringBuilderWriter(1024);\r
+\r
+               LargerData ld;\r
+               Trans trans;\r
+               Report report = new Report(ITERATIONS,"XML");\r
+               do {\r
+                       sbw.reset();\r
+                       trans = EnvFactory.newTrans();\r
+                       TimeTaken all = trans.start("Combo", Env.SUB);\r
+                       try {\r
+                               TimeTaken tt = trans.start("JAXB Unmarshal", Env.XML);\r
+                               try {\r
+                                       ld = jaxbUmar.unmarshal(LogTarget.NULL, xml);\r
+                               } finally {\r
+                                       tt.done();\r
+                               }\r
+                               tt = trans.start("JAXB marshal", Env.XML);\r
+                               try {\r
+                                       jaxBmar.marshal(LogTarget.NULL, ld, sbw);\r
+                               } finally {\r
+                                       tt.done();\r
+                               }\r
+                       } finally {\r
+                               all.done();\r
+                       }\r
+                       report.glean(trans,Env.XML);\r
+               } while(report.go());\r
+               \r
+               report.report(sbw);\r
+               System.out.println(sbw.toString());     }\r
+\r
+       @Test\r
+       public void xml2jaxb2PrettyXml() throws Exception {\r
+               System.out.println("*** XML -> JAXB Object -> Pretty XML ***");\r
+               JAXBumar jaxbUmar = new JAXBumar(LargerData.class);\r
+               JAXBmar jaxBmar = new JAXBmar(LargerData.class);\r
+               //jaxBmar.asFragment(true);\r
+               jaxBmar.pretty(true);\r
+               StringBuilderWriter sbw = new StringBuilderWriter(1024);\r
+\r
+               Trans trans = EnvFactory.newTrans();\r
+               LargerData ld;\r
+               for(int i=0;i<ITERATIONS;++i) {\r
+                       sbw.reset();\r
+                       TimeTaken all = trans.start("Combo", Env.SUB);\r
+                       try {\r
+                               TimeTaken tt = trans.start("JAXB Unmarshal", Env.XML);\r
+                               try {\r
+                                       ld = jaxbUmar.unmarshal(LogTarget.NULL, xml);\r
+                               } finally {\r
+                                       tt.done();\r
+                               }\r
+                               tt = trans.start("JAXB marshal", Env.XML);\r
+                               try {\r
+                                       jaxBmar.marshal(LogTarget.NULL, ld, sbw);\r
+                               } finally {\r
+                                       tt.done();\r
+                               }\r
+                       } finally {\r
+                               all.done();\r
+                       }\r
+               }\r
+               sbw.append('\n');\r
+               Metric m;\r
+               if(ITERATIONS>20) {\r
+                       m = trans.auditTrail(0,null);\r
+               } else {\r
+                       m = trans.auditTrail(0, sbw.getBuffer());\r
+                       System.out.println(sbw.getBuffer());\r
+               }\r
+               System.out.println(ITERATIONS + " entries, Total Time: " + m.total + "ms, Avg Time: " + m.total/ITERATIONS + "ms");\r
+       }\r
+\r
+}\r
diff --git a/rosetta/src/test/java/com/data/test/JU_JSON.java b/rosetta/src/test/java/com/data/test/JU_JSON.java
new file mode 100644 (file)
index 0000000..9b1d715
--- /dev/null
@@ -0,0 +1,138 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.data.test;\r
+\r
+import java.io.IOException;\r
+import java.io.Reader;\r
+import java.io.StringReader;\r
+import java.io.StringWriter;\r
+\r
+import org.junit.Test;\r
+\r
+import com.att.rosetta.InJson;\r
+import com.att.rosetta.Out;\r
+import com.att.rosetta.OutJson;\r
+import com.att.rosetta.OutRaw;\r
+import com.att.rosetta.Parse;\r
+import com.att.rosetta.ParseException;\r
+\r
+import junit.framework.Assert;\r
+\r
+public class JU_JSON {\r
+\r
+       @Test\r
+       public void test() throws IOException, ParseException {\r
+               InJson jin = new InJson();\r
+               Out jout = new OutJson();\r
+\r
+               go(jin, jout, "{\"id\":\"Me, Myself\",\"date\":1353094689100}");\r
+               \r
+               go(jin, jout, "{\"id\":\"My ID 1\",\"desc\":\"My Description 1\",\"comment\":[\"My Comment 1\"],\"utc\":1360418381310}");\r
+               go(jin, jout, "{\"id\":\"My ID 1\",\"desc\":\"My Description 1\",\"comment\":[\"My Comment 1\",\"My Comment 2\"],\"utc\":1360418381310}");\r
+\r
+               go(jin, jout, "{\"SampleData\":[" +\r
+                                  "{\"id\":\"sd object \\\"1\\\"\",\"date\":1316084944213,\"item\":[\"Item 1.1\",\"Item 1.2\"]}," +\r
+                                  "{\"id\":\"sd object \\\"2\\\"\",\"date\":1316084945343,\"item\":[\"Item 2.1\",\"Item 2.2\"]}],\"fluff\":\"MyFluff\"}"\r
+                                  );\r
+               \r
+               go(jin, jout, "{\"SampleData\":[{\"date\":1316084945343}],\"fluff\":\"MyFluff\"}");\r
+               \r
+               go(jin, jout, "{\"id\":\"Me,[}[eg[)(:x,\\\" Myself\",\"date\":1353094689100}");\r
+               \r
+               go(jin,jout, "{\"userid\":\"ab1234\",\"timestamp\":1353097388531,\"item\":[{\"tag\":\"color\",\"value\":\"Mauve\"},{\"tag\":\"shirtsize\",\"value\":\"Xtra Large\"}]}");\r
+               //go()\r
+               //"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><vote xmlns=\"urn:poll.att.com\"><userid>ab1234</userid><timestamp>1353082669667</timestamp></vote>");\r
+               \r
+               // 3/11/2015 jcg found a case with missing comma\r
+               go(jin,jout, "{\"start\":\"2015-03-11T18:18:05.580-05:00\",\"end\":\"2015-09-11-05:00\",\"force\":\"false\",\"perm\":{\"type\":\"com.att.myns.mytype\",\"instance\":\"myInstance\",\"action\":\"myAction\"}"\r
+                               + ",\"role\":\"com.att.myns.myrole\"}");\r
+\r
+               // 3/12/2015 jcg Kurt Schurenberg noticed an issue of object names in an array.  This is valid code.\r
+               go(jin,jout, "{\"role\":[{\"name\":\"com.att.myns.myrole\",\"perms\":[{\"type\":\"com.att.myns.mytype\",\"instance\":\"myAction\"},{\"type\":\"com.att.myns.mytype\",\"instance\":\"myOtherAction\"}]}"\r
+                               + ",{\"name\":\"com.att.myns.myOtherRole\",\"perms\":[{\"type\":\"com.att.myns.myOtherType\",\"instance\":\"myAction\"},{\"type\":\"com.att.myns.myOthertype\",\"instance\":\"myOtherAction\"}]}]}");\r
+\r
+               // 3/13/2015 - discovered with complex Response\r
+               go(jin,jout, "{\"meth\":\"GET\",\"path\":\"/authz/perms/:type\",\"desc\":\"GetPermsByType\",\"comments\":[\"List All Permissions that match :type listed\"],"\r
+                               + "\"contentType\":[\"application/Permissions+json;q=1.0;charset=utf-8;version=1.1,application/json;q=1.0;version=1.1\""\r
+                               + ",\"application/Perms+xml;q=1.0;charset=utf-8;version=2.0,text/xml;q=1.0;version=2.0\",\"application/Perms+json;q=1.0;charset=utf-8;version=2.0,application/json;q=1.0;version=2.0,*/*;q=1.0\""\r
+                               + ",\"application/Permissions+xml;q=1.0;charset=utf-8;version=1.1,text/xml;q=1.0;version=1.1\"]}"); \r
+               \r
+\r
+               // Test a Windoze "Pretty Print", validate skipping of Windoze characters as well as other odd control characters listed\r
+               // in json.org\r
+               StringWriter sw = new StringWriter();\r
+               jout.extract(new StringReader(\r
+                               "{\b\f\n\r\t \"id\""\r
+                               + ":\"Me, \b\f\n\r\tMyself\",\"date\":1353094689100"\r
+                               + "\b\f\n\r\t }"\r
+                               ),sw,jin);\r
+               Assert.assertEquals("{\"id\":\"Me, \b\f\n\r\tMyself\",\"date\":1353094689100}",sw.toString());\r
+               System.out.println(sw.toString());\r
+               \r
+               // 10/01/2015 jcg AAF-703 Ron Gallagher, this response is ok    \r
+               go(jin,jout, "{\"perm\":[{\"type\":\"com.att.myns.myPerm\",\"action\":\"myAction\",\"description\":\"something\"}]}");\r
+               // but when description:"" causes extra comma at end\r
+               go(jin,jout, "{\"perm\":[{\"type\":\"com.att.myns.myPerm\",\"action\":\"myAction\",\"description\":\"\"}]}","{\"perm\":[{\"type\":\"com.att.myns.myPerm\",\"action\":\"myAction\"}]}");\r
+               // Test other empty string scenarios\r
+               go(jin,jout, "{\"perm\":[{\"type\":\"\",\"action\":\"\",\"description\":\"\"}]}","{\"perm\":[{}]}");\r
+               go(jin,jout, "{\"perm\":[{\"type\":\"\",\"action\":\"\",\"description\":\"hi\"}]}","{\"perm\":[{\"description\":\"hi\"}]}");\r
+               go(jin,jout, "{\"perm\":[{\"type\":\"\",\"action\":\"myAction\",\"description\":\"\"}]}","{\"perm\":[{\"action\":\"myAction\"}]}");\r
+               \r
+               \r
+               go(jin,jout, "{\"perm\":[{\"type\":\"com.att.myns.myPerm\",\"action\":,\"description\":\"something\"}]}","{\"perm\":[{\"type\":\"com.att.myns.myPerm\",\"description\":\"something\"}]}");\r
+               \r
+               go(jin, jout, "{\"name\":\"\\\"hello\\\"\"}");\r
+               \r
+               go(jin, jout, "{\"name\":\"\\\\\"}");\r
+\r
+               go(jin, jout, "{\"role\":\"com.att.scamper.UserStory0152 7_IT-00323-a-admin\",\"perm\":{\"type\":\"com.att.scamper.application\",\"instance\":\"_()`!@#\\\\$%^=+][{}<>/.-valid.app.name-is_good\",\"action\":\"Administrator\"}}");\r
+               \r
+       \r
+       }\r
+       \r
+       \r
+       private void go(Parse<Reader,?> in, Out out, String str) throws IOException, ParseException {\r
+               go(in,out,str,str);\r
+       }\r
+\r
+\r
+       private void go(Parse<Reader, ?> in, Out out, String str, String cmp) throws IOException, ParseException {\r
+               \r
+               System.out.println(str);\r
+               StringWriter sw = new StringWriter(1024);\r
+               out.extract(new StringReader(str), sw, in);\r
+               System.out.println(sw);\r
+               String result = sw.toString();\r
+               \r
+               if(!result.equals(cmp)) {\r
+                       sw.getBuffer().setLength(0);\r
+                       new OutRaw().extract(new StringReader(str), sw, in);\r
+                       System.out.println(sw);\r
+               }\r
+\r
+               Assert.assertEquals(cmp,result);\r
+               System.out.println();\r
+\r
+       }\r
+}\r
diff --git a/rosetta/src/test/java/com/data/test/JU_Ladder.java b/rosetta/src/test/java/com/data/test/JU_Ladder.java
new file mode 100644 (file)
index 0000000..78d6a10
--- /dev/null
@@ -0,0 +1,80 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.data.test;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+\r
+import org.junit.Test;\r
+import static org.junit.Assert.*;\r
+\r
+import com.att.rosetta.Ladder;\r
+\r
+public class JU_Ladder {\r
+\r
+       @Test\r
+       public void test() {\r
+               Ladder<String> ladder = new Ladder<String>();\r
+               \r
+               for(int i=0;i<30;++i) {\r
+                       for(int j=0;j<i;++j)ladder.ascend();\r
+                       String str = "Rung " + i;\r
+                       assertEquals(ladder.peek(),null);\r
+                       ladder.push(str);\r
+                       assertEquals(str,ladder.peek());\r
+                       assertEquals(str,ladder.pop());\r
+                       assertEquals(null,ladder.peek());\r
+                       for(int j=0;j<i;++j)ladder.descend();\r
+               }\r
+               assertEquals(ladder.height(),32); // Sizing, when naturally created is by 8\r
+               \r
+               ladder.cutTo(8);\r
+               assertEquals(ladder.height(),8); \r
+               \r
+               for(int i=0;i<30;++i) {\r
+                       ladder.jumpTo(i);\r
+                       String str = "Rung " + i;\r
+                       assertEquals(ladder.peek(),null);\r
+                       ladder.push(str);\r
+                       assertEquals(ladder.peek(),str);\r
+               }\r
+\r
+               ladder.bottom();\r
+               \r
+               for(int i=0;i<30;++i) {\r
+                       assertEquals("Rung " + i,ladder.peek());\r
+                       ladder.ascend();\r
+               }\r
+               \r
+               ladder.bottom();\r
+               ladder.top();\r
+               assertEquals("Rung 29",ladder.peek());\r
+               \r
+               for(int i=0;i<30;++i) {\r
+                       ladder.jumpTo(i);\r
+                       assertEquals("Rung " + i,ladder.peek());\r
+               }\r
+\r
+       }\r
+\r
+}\r
diff --git a/rosetta/src/test/java/com/data/test/JU_Nulls.java b/rosetta/src/test/java/com/data/test/JU_Nulls.java
new file mode 100644 (file)
index 0000000..657b883
--- /dev/null
@@ -0,0 +1,72 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.data.test;\r
+\r
+import org.junit.AfterClass;\r
+import org.junit.Test;\r
+\r
+import com.att.inno.env.Data;\r
+import com.att.rosetta.env.RosettaDF;\r
+import com.att.rosetta.env.RosettaData;\r
+import com.att.rosetta.env.RosettaEnv;\r
+\r
+import junit.framework.Assert;\r
+import s.xsd.LargerData;\r
+import s.xsd.SampleData;\r
+\r
+public class JU_Nulls {\r
+\r
+       @AfterClass\r
+       public static void tearDownAfterClass() throws Exception {\r
+       }\r
+\r
+       @Test\r
+       public void test() {\r
+               RosettaEnv env = new RosettaEnv();\r
+               try {\r
+                       RosettaDF<LargerData> df = env.newDataFactory(LargerData.class);\r
+                       df.out(Data.TYPE.JSON);\r
+                       LargerData urr = new LargerData();\r
+                       SampleData sd = new SampleData();\r
+                       sd.setDate(1444125487798L);\r
+                       sd.setId(null);\r
+                       urr.getSampleData().add(sd);\r
+                       urr.setFluff(null);\r
+                       RosettaData<LargerData> data = df.newData();\r
+//                     StringWriter sw = new StringWriter();\r
+//                     df.direct(trans, urr, sw);\r
+//                     System.out.println(sw.toString());\r
+                       data.load(urr);\r
+                       System.out.println(data.asString());\r
+                       Assert.assertEquals("{\"SampleData\":[{\"date\":1444125487798}]}", data.asString());\r
+                       \r
+                       System.out.println(data.out(Data.TYPE.RAW).asString());\r
+               } catch (Exception e) {\r
+                       // TODO Auto-generated catch block\r
+                       e.printStackTrace();\r
+               }\r
+               \r
+       }\r
+\r
+}\r
diff --git a/rosetta/src/test/java/com/data/test/JU_RosettaDF.java b/rosetta/src/test/java/com/data/test/JU_RosettaDF.java
new file mode 100644 (file)
index 0000000..90342b4
--- /dev/null
@@ -0,0 +1,165 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.data.test;\r
+\r
+import java.io.StringReader;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+\r
+import com.att.inno.env.Data;\r
+import com.att.inno.env.Data.TYPE;\r
+import com.att.inno.env.TimeTaken;\r
+import com.att.inno.env.Trans;\r
+import com.att.inno.env.impl.EnvFactory;\r
+import com.att.inno.env.jaxb.JAXBmar;\r
+import com.att.inno.env.util.StringBuilderWriter;\r
+import com.att.rosetta.env.RosettaDF;\r
+import com.att.rosetta.env.RosettaData;\r
+import com.att.rosetta.env.RosettaEnv;\r
+\r
+import s.xsd.LargerData;\r
+import s.xsd.Multi;\r
+import s.xsd.SampleData;\r
+\r
+public class JU_RosettaDF {\r
+       public static int ITERATIONS = 1;\r
+\r
+       @Test\r
+       public void testCached() throws Exception {\r
+               RosettaEnv env = new RosettaEnv();\r
+               RosettaDF<LargerData> df = env.newDataFactory(LargerData.class);\r
+               JAXBmar jmar = new JAXBmar(LargerData.class);\r
+\r
+               StringBuilderWriter sbw = new StringBuilderWriter(1024);\r
+               Trans trans = EnvFactory.newTrans();\r
+\r
+               Report report = new Report(ITERATIONS,"Load JSON","Extract JAXB", "JAXB Marshal", "Cached to XML", "Cached to JSON");\r
+               do {\r
+                       sbw.reset();\r
+                       trans = EnvFactory.newTrans();\r
+                       Data<LargerData> data;\r
+                       TimeTaken tt = trans.start("Load JSON", 1);\r
+                       try {\r
+                               data = df.newData(trans).out(Data.TYPE.JSON).in(Data.TYPE.JSON).load(JU_FromJSON.str);\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+                       LargerData ld;\r
+                       tt = trans.start("Extract JAXB", 2);\r
+                       try {\r
+                               ld = data.asObject();\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+\r
+                       tt = trans.start("JAXB marshal", 3);\r
+                       try {\r
+                               jmar.marshal(trans.debug(), ld, sbw);\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+                       sbw.append('\n');\r
+                       \r
+                       tt = trans.start("To XML from Cache",4);\r
+                       try {\r
+                               data.out(Data.TYPE.XML).to(sbw);\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+                       \r
+                       sbw.append('\n');\r
+                       \r
+                       tt = trans.start("To JSON from Cache",5);\r
+                       try {\r
+                               data.out(Data.TYPE.JSON).to(sbw);\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+                       report.glean(trans, 1,2,3,4,5);\r
+               } while(report.go());\r
+               \r
+               report.report(sbw);\r
+               System.out.println(sbw);\r
+               \r
+       }\r
+\r
+       @Test\r
+       public void testDirect() throws Exception {\r
+               RosettaEnv env = new RosettaEnv();\r
+               RosettaDF<LargerData> df = env.newDataFactory(LargerData.class);\r
+\r
+               StringBuilderWriter sbw = new StringBuilderWriter(1024);\r
+               Trans trans = EnvFactory.newTrans();\r
+\r
+               Report report = new Report(ITERATIONS);\r
+               do {\r
+                       sbw.reset();\r
+                       trans = EnvFactory.newTrans();\r
+                       RosettaData<?> data = df.newData(trans).in(Data.TYPE.JSON).out(Data.TYPE.XML);\r
+                       data.direct(new StringReader(JU_FromJSON.str), sbw);\r
+                       report.glean(trans);\r
+               } while(report.go());\r
+               \r
+               report.report(sbw);\r
+               System.out.println(sbw);\r
+               \r
+       }\r
+       \r
+       @Test\r
+       public void testMulti() throws Exception {\r
+               RosettaEnv env = new RosettaEnv();\r
+               RosettaDF<Multi> df = env.newDataFactory(Multi.class);\r
+\r
+//             StringBuilderWriter sbw = new StringBuilderWriter(1024);\r
+//             Trans trans = EnvFactory.newTrans();\r
+\r
+               Multi m = new Multi();\r
+               m.getF1().add("String1");\r
+               m.getF2().add("String2");\r
+               \r
+               System.out.println(df.newData().load(m).out(TYPE.RAW).asString());\r
+               System.out.println(df.newData().load(m).out(TYPE.JSON).asString());\r
+               \r
+       }\r
+\r
+       @Test\r
+       public void testQuotes() throws Exception {\r
+               RosettaEnv env = new RosettaEnv();\r
+               RosettaDF<SampleData> df = env.newDataFactory(SampleData.class);\r
+\r
+               SampleData sd = new SampleData();\r
+               sd.setId("\"AT&T Services, Inc.\"");\r
+               System.out.println(sd.getId());\r
+               String out =df.newData().load(sd).out(TYPE.JSON).asString();\r
+               System.out.println(out);\r
+               Assert.assertEquals(\r
+                               "{\"id\":\"\\\"AT&T Services, Inc.\\\"\",\"date\":0}",\r
+                               out);\r
+               \r
+               SampleData sd2 = df.newData().in(TYPE.JSON).load(out).asObject();\r
+               System.out.println(sd2.getId());\r
+               Assert.assertEquals(sd.getId(),sd2.getId());\r
+       }\r
+}\r
diff --git a/rosetta/src/test/java/com/data/test/JU_Saved.java b/rosetta/src/test/java/com/data/test/JU_Saved.java
new file mode 100644 (file)
index 0000000..220bdf7
--- /dev/null
@@ -0,0 +1,107 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.data.test;\r
+\r
+import java.io.Reader;\r
+import java.io.StringReader;\r
+\r
+import org.junit.Test;\r
+\r
+import com.att.inno.env.TimeTaken;\r
+import com.att.inno.env.Trans;\r
+import com.att.inno.env.impl.EnvFactory;\r
+import com.att.inno.env.util.StringBuilderWriter;\r
+import com.att.rosetta.InJson;\r
+import com.att.rosetta.JaxInfo;\r
+import com.att.rosetta.OutJson;\r
+import com.att.rosetta.OutXML;\r
+import com.att.rosetta.Saved;\r
+\r
+import s.xsd.LargerData;\r
+\r
+public class JU_Saved<b> {\r
+       private static int ITERATIONS = 100000;\r
+\r
+       @Test\r
+       public void test() throws Exception {\r
+               InJson inJSON = new InJson();\r
+               OutDump dump = new OutDump();\r
+               JaxInfo ji = JaxInfo.build(LargerData.class);\r
+               OutXML xml = new OutXML(ji);;\r
+               OutJson json = new OutJson();\r
+               \r
+               Saved saved = new Saved();\r
+               \r
+               StringBuilderWriter sbw = new StringBuilderWriter(1024);\r
+               \r
+               Trans trans;\r
+               Report report = new Report(ITERATIONS,"Save","Dump","XML ","JSON");\r
+               do {\r
+                       sbw.reset();\r
+                       trans = EnvFactory.newTrans();\r
+                       Reader sr = new StringReader(JU_FromJSON.str);\r
+                       TimeTaken tt = trans.start("Parse Text, and Save", 1);\r
+                       try {\r
+                               saved.load(sr, inJSON);\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+\r
+//                     sbw.append("==== Start Direct Raw =====\n");\r
+//                     new OutRaw().extract(new StringReader(JU_FromJSON.str), sbw, inJSON);\r
+//                     \r
+//                     sbw.append("==== Start Raw from Saved =====\n");\r
+//                     new OutRaw().extract(null,sbw,saved);\r
+\r
+                       sbw.append("==== Start Dump from Saved =====\n");\r
+                       tt = trans.start("Dump", 2);\r
+                       try {\r
+                               dump.extract(null,sbw,saved);\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+                       \r
+                       sbw.append("\n==== Start XML =====\n");\r
+                       tt = trans.start("XML", 3);\r
+                       try {\r
+                               xml.extract(null,sbw,saved);\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+                       \r
+                       sbw.append("\n==== Start JSON =====\n");\r
+                       tt = trans.start("JSON", 4);\r
+                       try {\r
+                               json.extract(null,sbw,saved);\r
+                       } finally {\r
+                               tt.done();\r
+                       }\r
+                       report.glean(trans,1,2,3,4);\r
+               } while(report.go());\r
+               \r
+               report.report(sbw);\r
+               System.out.println(sbw.toString());\r
+\r
+       }\r
+}\r
diff --git a/rosetta/src/test/java/com/data/test/JU_Stream2Obj.java b/rosetta/src/test/java/com/data/test/JU_Stream2Obj.java
new file mode 100644 (file)
index 0000000..c714b57
--- /dev/null
@@ -0,0 +1,126 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.data.test;\r
+\r
+import java.io.IOException;\r
+import java.io.Reader;\r
+import java.io.StringReader;\r
+import java.io.StringWriter;\r
+\r
+import org.junit.Test;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.inno.env.Data;\r
+import com.att.inno.env.DataFactory;\r
+import com.att.inno.env.EnvJAXB;\r
+import com.att.inno.env.impl.BasicEnv;\r
+import com.att.rosetta.InJson;\r
+import com.att.rosetta.InXML;\r
+import com.att.rosetta.Out;\r
+import com.att.rosetta.OutJson;\r
+import com.att.rosetta.OutRaw;\r
+import com.att.rosetta.OutXML;\r
+import com.att.rosetta.Parse;\r
+import com.att.rosetta.ParseException;\r
+\r
+import inherit.DerivedA;\r
+import inherit.Root;\r
+\r
+public class JU_Stream2Obj {\r
+\r
+       /*\r
+       <?xml version="1.0" encoding=Config.UTF-8 standalone="yes"?>\r
+       <root xmlns="urn:inherit">\r
+         <base xsi:type="derivedA" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+           <name>myDerivedA_1</name>\r
+           <num>1432</num>\r
+           <shortName>mda_1</shortName>\r
+           <value>value_1</value>\r
+           <value>value_2</value>\r
+         </base>\r
+       </root>\r
+       \r
+       {"base":[{"__extension":"derivedA","name":"myDerivedA_1","num":1432,"shortName":"mda_1","value":["value_1","value_2"]}]}\r
+       */\r
+\r
+       @Test\r
+       public void json2Obj() throws APIException, SecurityException, NoSuchFieldException, ClassNotFoundException, ParseException, IOException {\r
+               DerivedA da = new DerivedA();\r
+               da.setName("myDerivedA_1");\r
+               da.setNum((short)1432);\r
+               da.setShortName("mda_1");\r
+               da.getValue().add("value_1");\r
+               da.getValue().add("value_2");\r
+               \r
+               Root root = new Root();\r
+               root.getBase().add(da);\r
+\r
+               da = new DerivedA();\r
+               da.setName("myDerivedA_2");\r
+               da.setNum((short)1432);\r
+               da.setShortName("mda_2");\r
+               da.getValue().add("value_2.1");\r
+               da.getValue().add("value_2.2");\r
+               root.getBase().add(da);\r
+               \r
+               EnvJAXB env = new BasicEnv();\r
+               DataFactory<Root> rootDF = env.newDataFactory(Root.class);\r
+               \r
+               String xml = rootDF.newData(env).out(Data.TYPE.XML).load(root).option(Data.PRETTY).asString();\r
+               System.out.println(xml);\r
+\r
+               InXML inXML;\r
+               Parse<Reader,?> in = inXML = new InXML(Root.class);\r
+               Out out = new OutRaw();\r
+\r
+               StringWriter sw = new StringWriter();\r
+               out.extract(new StringReader(xml), sw, in);\r
+               System.out.println(sw.toString());\r
+\r
+               \r
+               out = new OutJson();\r
+\r
+               sw = new StringWriter();\r
+               out.extract(new StringReader(xml), sw, in);\r
+               String json;\r
+               System.out.println(json = sw.toString());\r
+               \r
+               in = new InJson();\r
+               out = new OutRaw();\r
+\r
+               sw = new StringWriter();\r
+               out.extract(new StringReader(json), sw, in);\r
+               System.out.println(sw.toString());\r
+               \r
+               out = new OutXML(inXML);\r
+\r
+               sw = new StringWriter();\r
+               out.extract(new StringReader(json), sw, in, true);\r
+               System.out.println(sw.toString());\r
+\r
+               System.out.flush();\r
+\r
+       }\r
+\r
+}\r
diff --git a/rosetta/src/test/java/com/data/test/JU_Struct.java b/rosetta/src/test/java/com/data/test/JU_Struct.java
new file mode 100644 (file)
index 0000000..1d1ee96
--- /dev/null
@@ -0,0 +1,76 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.data.test;\r
+\r
+import org.junit.Test;\r
+\r
+import com.att.rosetta.JaxInfo;\r
+\r
+import s.xsd.LargerData;\r
+\r
+public class JU_Struct {\r
+       public final static String XML ="<LargerData xmlns=\"urn:s:xsd\">\n" +\r
+                                                                           "<SampleData>\n" +\r
+                                                                               "<id>sd object 1</id>\n" +\r
+                                                                               "<date>1346439215932</date>\n" +\r
+                                                                               "<item>Item 1.1</item>\n" +\r
+                                                                               "<item>Item 1.2</item>\n" +\r
+                                                                           "</SampleData>\n" +\r
+                                                                           "<SampleData>\n" +\r
+                                                                               "<id>sd object 2</id>\n" +\r
+                                                                               "<date>1346439215932</date>\n" +\r
+                                                                               "<item>Item 2.1</item>\n" +\r
+                                                                               "<item>Item 2.2</item>\n" +\r
+                                                                           "</SampleData>\n" +\r
+                                                                           "<fluff>MyFluff</fluff>\n" +\r
+                                                                       "</LargerData>\n";\r
+       \r
+//     @Test\r
+//     public void test2() throws Exception  {\r
+//\r
+//             SampleData sd = new SampleData();\r
+//             sd.setDate(new Date().getTime());\r
+//             sd.setId("myId");\r
+//             sd.getItem().add("Item 1.1");\r
+//             \r
+//             InObj<SampleData> inObj = new InObj<SampleData>(SampleData.class);\r
+//\r
+//             JaxSet<SampleData> jaxSet = JaxSet.get(SampleData.class);\r
+//             Setter<SampleData> setter = jaxSet.setter("id");\r
+//             setter.set(sd, "Your ID");\r
+//             \r
+//             for(Entry<String, Getter<SampleData>> es : jaxSet.getters()) {\r
+//                     System.out.print(es.getKey());\r
+//                     System.out.print(' ');\r
+//                     System.out.println(es.getValue().get(sd));\r
+//             }\r
+//     }\r
+       \r
+       @Test\r
+       public void test() throws Exception  {\r
+               JaxInfo ji = JaxInfo.build(LargerData.class);\r
+               System.out.println(ji);\r
+       }\r
+\r
+}\r
diff --git a/rosetta/src/test/java/com/data/test/JU_Types.java b/rosetta/src/test/java/com/data/test/JU_Types.java
new file mode 100644 (file)
index 0000000..02f5ac3
--- /dev/null
@@ -0,0 +1,304 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.data.test;\r
+\r
+import java.io.StringWriter;\r
+\r
+import javax.xml.datatype.XMLGregorianCalendar;\r
+import javax.xml.namespace.QName;\r
+\r
+import org.junit.Test;\r
+\r
+import com.att.inno.env.Data;\r
+import com.att.inno.env.Data.TYPE;\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.Trans;\r
+import com.att.inno.env.Trans.Metric;\r
+import com.att.inno.env.jaxb.JAXBmar;\r
+import com.att.inno.env.jaxb.JAXBumar;\r
+import com.att.inno.env.util.Chrono;\r
+import com.att.inno.env.util.StringBuilderWriter;\r
+import com.att.rosetta.OutJson;\r
+import com.att.rosetta.OutRaw;\r
+import com.att.rosetta.OutXML;\r
+import com.att.rosetta.env.RosettaDF;\r
+import com.att.rosetta.env.RosettaData;\r
+import com.att.rosetta.env.RosettaEnv;\r
+import com.att.rosetta.marshal.DocMarshal;\r
+import com.data.test.obj.MultiMarshal;\r
+import com.data.test.obj.SingleMarshal;\r
+\r
+import types.xsd.Multi;\r
+import types.xsd.Multi.Single;\r
+\r
+public class JU_Types {\r
+\r
+       @Test\r
+       public void single() throws Exception {\r
+               Single single = setSData();\r
+               SingleMarshal psingle = new SingleMarshal();\r
+               \r
+               OutRaw raw = new OutRaw();\r
+               OutJson json = new OutJson();\r
+               OutXML xml = new OutXML("Single","xmlns=urn:types:xsd");\r
+               \r
+               \r
+               System.out.println("===== RAW =====");\r
+               raw.extract(single, System.out, psingle);\r
+\r
+               System.out.println("\n===== JSON =====");\r
+               json.extract(single, System.out, psingle);\r
+               \r
+               System.out.println("\n\n===== Pretty JSON =====");\r
+               json.extract(single, System.out, psingle, true);\r
+\r
+               System.out.println("\n\n===== XML =====");\r
+               xml.extract(single, System.out, psingle,false);\r
+\r
+               System.out.println("\n\n===== Pretty XML =====");\r
+               xml.extract(single, System.out, psingle, true);\r
+\r
+               RosettaEnv env = new RosettaEnv();\r
+               StringWriter sw = new StringWriter();\r
+               xml.extract(single, sw, psingle, true);\r
+               JAXBumar jumar = new JAXBumar(single.getClass());\r
+               JAXBmar jmar = new JAXBmar(new QName("Single","urn.types.xsd"),single.getClass());\r
+               jmar.pretty(true);\r
+               sw = new StringWriter();\r
+               jmar.marshal(env.info(), single, sw);\r
+               System.out.println(sw);\r
+               Single news = jumar.unmarshal(env.info(), sw.toString());\r
+//             System.out.println(news.getDatetime());\r
+//             sw = new StringWriter();\r
+//             news.setDatetime(Chrono.timeStamp());\r
+//             xml.extract(single, sw, psingle, true);\r
+               news = jumar.unmarshal(env.info(), sw.toString());\r
+               System.out.println(sw.toString());\r
+               \r
+               String sample = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"\r
+                               + "\n<ns2:urn.types.xsd xmlns:ns2=\"Single\" xmlns=\"urn:types:xsd\">"\r
+                               + "\n<str>MyString</str>"\r
+                               + "\n<int>2147483647</int>"\r
+                               + "\n<long>9223372036854775807</long>"\r
+                               + "\n<date>2015-05-27-05:00</date>"\r
+                               + "\n<datetime>2015-05-27T07:05:04.234-05:00</datetime>"\r
+                               + "\n<binary>FF00FF0E082507807F</binary>"\r
+                               + "\n<array>String 1</array>"\r
+                               + "\n<array>String 2</array>"\r
+                               + "\n</ns2:urn.types.xsd>";\r
+               System.out.println(sample);\r
+               news = jumar.unmarshal(env.info(), sample);\r
+\r
+               System.out.println(news.getDatetime());\r
+\r
+       }\r
+       \r
+       @Test\r
+       public void multi() throws Exception {\r
+               OutRaw raw = new OutRaw();\r
+               OutJson json = new OutJson();\r
+               OutXML xml = new OutXML("Multi","xmlns=urn:types:xsd");\r
+\r
+               Multi multi = new Multi();\r
+               MultiMarshal pmulti = new MultiMarshal();\r
+       \r
+               for(int i=0;i<10;++i) {\r
+                       System.out.println("===== Multi Iteration " + i + " =====");\r
+                       if(i>0) {\r
+                               multi.getSingle().add(setSData());\r
+                       }\r
+                       System.out.println("  ===== RAW =====");\r
+                       raw.extract(multi, System.out, pmulti);\r
+                       \r
+                       System.out.println("\n  ===== JSON =====");\r
+                       json.extract(multi, System.out, pmulti);\r
+                       \r
+                       System.out.println("\n\n  ===== Pretty JSON =====");\r
+                       json.extract(multi, System.out, pmulti, true);\r
+       \r
+                       System.out.println("\n\n  ===== XML =====");\r
+                       xml.extract(multi, System.out, pmulti,false);\r
+       \r
+                       System.out.println("\n\n  ===== Pretty XML =====");\r
+                       xml.extract(multi, System.out, pmulti, true);\r
+               }\r
+       }\r
+\r
+       @Test\r
+       public void doc() throws Exception {\r
+               OutRaw raw = new OutRaw();\r
+               OutJson json = new OutJson();\r
+               OutXML xml = new OutXML("Multi","xmlns=urn:types:xsd");\r
+\r
+               Multi multi = new Multi();\r
+               DocMarshal<Multi> doc = DocMarshal.root(new MultiMarshal());\r
+       \r
+               for(int i=0;i<3;++i) {\r
+                       System.out.println("===== Multi Iteration " + i + " =====");\r
+                       if(i>0) {\r
+                               multi.getSingle().add(setSData());\r
+                       }\r
+                       System.out.println("  ===== RAW =====");\r
+                       raw.extract(multi, System.out, doc);\r
+                       \r
+                       System.out.println("\n  ===== JSON =====");\r
+                       json.extract(multi, System.out, doc);\r
+                       \r
+                       System.out.println("\n\n  ===== Pretty JSON =====");\r
+                       json.extract(multi, System.out, doc, true);\r
+       \r
+                       System.out.println("\n\n  ===== XML =====");\r
+                       xml.extract(multi, System.out, doc,false);\r
+       \r
+                       System.out.println("\n\n  ===== Pretty XML =====");\r
+                       xml.extract(multi, System.out, doc, true);\r
+               }\r
+       }\r
+\r
+\r
+//     @Test\r
+//     public void saved() throws Exception {\r
+//             Saved saved = new Saved();\r
+//             saved.extract(in, ignore, parser, options);\r
+//     }\r
+       \r
+       @Test\r
+       public void df() throws Exception {\r
+               RosettaEnv env = new RosettaEnv();\r
+               RosettaDF<Multi> df = env.newDataFactory(Multi.class);\r
+               df.out(TYPE.JSON).option(Data.PRETTY);\r
+               \r
+               Multi multi = new Multi();\r
+               multi.getSingle().add(setSData());\r
+               \r
+\r
+               System.out.println("========== Original loading");\r
+               Trans trans = env.newTrans();\r
+               RosettaData<Multi> data = df.newData(trans);\r
+               // Prime pump\r
+               for(int i=0;i<100;++i) {\r
+                       data.load(multi);\r
+               }\r
+               trans = env.newTrans();\r
+               data = df.newData(trans);\r
+               \r
+               int iters = 10000;\r
+               for(int i=0;i<iters;++i) {\r
+                       data.load(multi);\r
+               }\r
+               Metric metrics = trans.auditTrail(0, null,Env.JSON,Env.XML);\r
+               System.out.println(data.asString());\r
+               System.out.println(metrics.total/iters + "ms avg");\r
+\r
+               System.out.println("========== New loading");\r
+               // With new\r
+               df.rootMarshal(DocMarshal.root(new MultiMarshal()));\r
+               trans = env.newTrans();\r
+               data = df.newData(trans);\r
+\r
+               // Prime pump\r
+               for(int i=0;i<100;++i) {\r
+                       data.load(multi);\r
+               }\r
+               trans = env.newTrans();\r
+               data = df.newData(trans);\r
+               \r
+               for(int i=0;i<iters;++i) {\r
+                       data.load(multi);\r
+               }\r
+               metrics = trans.auditTrail(0, null,Env.JSON,Env.XML);\r
+               System.out.println(data.asString());\r
+               System.out.println(metrics.total/iters + "ms avg");\r
+               \r
+               // Assert.assertEquals(first, second);\r
+\r
+               System.out.println("========== Direct Object to JSON String");\r
+               trans = env.newTrans();\r
+               data = df.newData(trans);\r
+               StringBuilderWriter sbw = new StringBuilderWriter(256);\r
+               // Prime pump\r
+               for(int i=0;i<100;++i) {\r
+                       sbw.reset();\r
+                       data.direct(multi, sbw, true);\r
+               }\r
+               trans = env.newTrans();\r
+               data = df.newData(trans);\r
+\r
+               for(int i=0;i<iters;++i) {\r
+                       sbw.reset();\r
+                       data.direct(multi, sbw, true);\r
+               }\r
+               \r
+               metrics = trans.auditTrail(0, null,Env.JSON,Env.XML);\r
+               System.out.println(sbw.toString());\r
+               System.out.println(metrics.total/iters + "ms avg");\r
+               \r
+       }\r
+       \r
+       private Single setSData() {\r
+               Single s = new Single();\r
+               s.setStr("MyString");\r
+               s.setInt(Integer.MAX_VALUE);\r
+               s.setLong(Long.MAX_VALUE);\r
+               XMLGregorianCalendar ts = Chrono.timeStamp();\r
+               s.setDate(ts);\r
+               s.setDatetime(ts);\r
+               byte[] bytes= new byte[] {-1,0,(byte)0XFF,0xE,0x8,0x25,0x7,Byte.MIN_VALUE,Byte.MAX_VALUE};\r
+               s.setBinary(bytes);\r
+               s.getArray().add("String 1");\r
+               s.getArray().add("String 2");\r
+               return s;\r
+       }\r
+\r
+//     @Test\r
+//     public void jsonInOut() throws IOException, ParseException {\r
+//             Parse<?> jin = new InJson();\r
+//             Out jout = new OutJson();\r
+//\r
+////           go(jin, jout, "{\"id\":\"Me, Myself\",\"date\":1353094689100}");\r
+//                     \r
+//     }\r
+       \r
+       \r
+       /*\r
+       private void go(Parse<Reader,?> in, Out out, String str) throws IOException, ParseException {\r
+               \r
+               System.out.println(str);\r
+               StringWriter sw = new StringWriter(1024);\r
+               out.extract(new StringReader(str), sw, in);\r
+               System.out.println(sw);\r
+               String result = sw.toString();\r
+               \r
+               if(!result.equals(str)) {\r
+                       sw.getBuffer().setLength(0);\r
+                       new OutRaw().extract(new StringReader(str), sw, in);\r
+                       System.out.println(sw);\r
+               }\r
+\r
+               Assert.assertEquals(str,result);\r
+               System.out.println();\r
+\r
+       }\r
+       */\r
+}\r
diff --git a/rosetta/src/test/java/com/data/test/OutDump.java b/rosetta/src/test/java/com/data/test/OutDump.java
new file mode 100644 (file)
index 0000000..cd65e15
--- /dev/null
@@ -0,0 +1,93 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.data.test;\r
+\r
+import java.io.IOException;\r
+import java.io.Writer;\r
+\r
+import com.att.inno.env.util.IndentPrintWriter;\r
+import com.att.rosetta.Out;\r
+import com.att.rosetta.Parse;\r
+import com.att.rosetta.ParseException;\r
+import com.att.rosetta.Parsed;\r
+\r
+public class OutDump extends Out{\r
+\r
+       @Override\r
+       public<IN, S> void extract(IN in, Writer writer, Parse<IN,S> prs, boolean ... options) throws IOException, ParseException {\r
+               IndentPrintWriter ipw = writer instanceof IndentPrintWriter?(IndentPrintWriter)writer:new IndentPrintWriter(writer);\r
+\r
+               Parsed<S> p = prs.newParsed();\r
+               \r
+               while((p = prs.parse(in,p.reuse())).valid()) {\r
+                       switch(p.event) {\r
+                               case Parse.START_OBJ:\r
+                                       ipw.append("Start Object ");\r
+                                       ipw.append(p.name);\r
+                                       ipw.inc();\r
+                                       break;\r
+                               case Parse.END_OBJ: \r
+                                       printData(ipw,p);\r
+                                       ipw.dec();\r
+                                       ipw.append("End Object ");\r
+                                       ipw.append(p.name);\r
+                                       break;\r
+                               case Parse.START_ARRAY:\r
+                                       ipw.inc();\r
+                                       ipw.append("Start Array ");\r
+                                       ipw.append(p.name);\r
+                                       ipw.append('\n');\r
+                                       break;\r
+                               case Parse.END_ARRAY: \r
+                                       printData(ipw,p);\r
+                                       ipw.dec();\r
+                                       ipw.append("End Array ");\r
+                                       ipw.append('\n');\r
+                                       break;\r
+                               case Parse.NEXT:\r
+                                       printData(ipw,p);\r
+                                       break;\r
+                       }\r
+               }\r
+       }\r
+       \r
+       private void printData(IndentPrintWriter ipw, Parsed<?> parsed) {\r
+               if(parsed.hasData()) {\r
+                       ipw.append("Data:[");\r
+                       if(parsed.hasName()) {\r
+                               ipw.append(parsed.name);\r
+                               ipw.append(" : "); \r
+                       }\r
+                       ipw.append(parsed.sb);\r
+                       ipw.append("]");\r
+                       ipw.append('\n');\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public String logName() {\r
+               return "Rosetta OutDump";\r
+       }\r
+\r
+}\r
diff --git a/rosetta/src/test/java/com/data/test/Report.java b/rosetta/src/test/java/com/data/test/Report.java
new file mode 100644 (file)
index 0000000..d05443a
--- /dev/null
@@ -0,0 +1,69 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.data.test;\r
+\r
+import java.io.IOException;\r
+import java.io.Writer;\r
+\r
+import com.att.inno.env.Trans;\r
+import com.att.inno.env.Trans.Metric;\r
+\r
+public class Report {\r
+       float total;\r
+       float buckets[];\r
+       String[] names;\r
+       private int iterations;\r
+       private int count;\r
+       \r
+       public Report(int iters, String ... names) {\r
+               iterations = iters;\r
+               buckets = new float[names.length];\r
+               this.names = names;\r
+               total=0;\r
+               count = 0;\r
+       }\r
+       \r
+       public void glean(Trans trans, int ... type) {\r
+               Metric m = trans.auditTrail(0, null, type);\r
+               total+=m.total;\r
+               int min = Math.min(buckets.length, m.buckets.length);\r
+               for(int b=0;b<min;++b) {\r
+                       buckets[b]+=m.buckets[b];\r
+               }\r
+       }\r
+       \r
+       public boolean go() {\r
+               return ++count<iterations;\r
+       }\r
+       \r
+       \r
+       public void report(Writer sbw) throws IOException {\r
+               sbw.append("\n"+count + " entries, Total Time: " + total + "ms, Avg Time: " + total/count + "ms\n");\r
+               int min = Math.min(buckets.length, names.length);\r
+               for(int i=0;i<min;++i) {\r
+                       sbw.append("  Time: " + names[i] + ' ' + buckets[i] + "ms, Avg Time: " + buckets[i]/count + "ms\n");\r
+               }\r
+\r
+       }\r
+}\r
diff --git a/rosetta/src/test/java/com/data/test/obj/MultiMarshal.java b/rosetta/src/test/java/com/data/test/obj/MultiMarshal.java
new file mode 100644 (file)
index 0000000..1ef81e2
--- /dev/null
@@ -0,0 +1,43 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.data.test.obj;\r
+\r
+import java.util.List;\r
+\r
+import com.att.rosetta.marshal.ObjArray;\r
+import com.att.rosetta.marshal.ObjMarshal;\r
+\r
+import types.xsd.Multi;\r
+import types.xsd.Multi.Single;\r
+\r
+public class MultiMarshal extends ObjMarshal<Multi> {\r
+       public MultiMarshal() {\r
+               add(new ObjArray<Multi,Single>("single",new SingleMarshal()) {\r
+                       @Override\r
+                       protected List<Single> data(Multi t) {\r
+                               return t.getSingle();\r
+                       }\r
+               });\r
+       }\r
+}\r
diff --git a/rosetta/src/test/java/com/data/test/obj/SingleMarshal.java b/rosetta/src/test/java/com/data/test/obj/SingleMarshal.java
new file mode 100644 (file)
index 0000000..1546622
--- /dev/null
@@ -0,0 +1,93 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.data.test.obj;\r
+\r
+import java.util.List;\r
+\r
+import javax.xml.datatype.XMLGregorianCalendar;\r
+\r
+import com.att.rosetta.marshal.DataWriter;\r
+import com.att.rosetta.marshal.FieldArray;\r
+import com.att.rosetta.marshal.FieldDate;\r
+import com.att.rosetta.marshal.FieldDateTime;\r
+import com.att.rosetta.marshal.FieldHexBinary;\r
+import com.att.rosetta.marshal.FieldNumeric;\r
+import com.att.rosetta.marshal.FieldString;\r
+import com.att.rosetta.marshal.ObjMarshal;\r
+\r
+import types.xsd.Multi.Single;\r
+\r
+public class SingleMarshal extends ObjMarshal<Single> {\r
+       public SingleMarshal() {\r
+               add(new FieldString<Single>("str") {\r
+                       @Override\r
+                       protected String data(Single t) {\r
+                               return t.getStr();\r
+                       }\r
+               });\r
+               \r
+               add(new FieldNumeric<Integer, Single>("int") {\r
+                       @Override\r
+                       protected Integer data(Single t) {\r
+                               return t.getInt();\r
+                       }\r
+               });\r
+               \r
+               add(new FieldNumeric<Long,Single>("long") {\r
+                       @Override\r
+                       protected Long data(Single t) {\r
+                               return t.getLong();\r
+                       }\r
+               });\r
+\r
+               add(new FieldDate<Single>("date") {\r
+                       @Override\r
+                       protected XMLGregorianCalendar data(Single t) {\r
+                               return t.getDate();\r
+                       }\r
+               });\r
+\r
+               add(new FieldDateTime<Single>("datetime") {\r
+                       @Override\r
+                       protected XMLGregorianCalendar data(Single t) {\r
+                               return t.getDate();\r
+                       }\r
+               });\r
+               \r
+               add(new FieldHexBinary<Single>("binary") {\r
+                       @Override\r
+                       protected byte[] data(Single t) {\r
+                               return t.getBinary();\r
+                       }\r
+               });\r
+               \r
+               add(new FieldArray<Single,String>("array", DataWriter.STRING) {\r
+                       @Override\r
+                       protected List<String> data(Single t) {\r
+                               return t.getArray();\r
+                       }\r
+               });\r
+\r
+       }\r
+}\r
diff --git a/xgen/.gitignore b/xgen/.gitignore
new file mode 100644 (file)
index 0000000..cf85207
--- /dev/null
@@ -0,0 +1,5 @@
+/bin/
+/target/
+/.classpath
+/.project
+.settings
diff --git a/xgen/pom.xml b/xgen/pom.xml
new file mode 100644 (file)
index 0000000..5b558ea
--- /dev/null
@@ -0,0 +1,129 @@
+<!--\r
+  ============LICENSE_START====================================================\r
+  * org.onap.aai\r
+  * ===========================================================================\r
+  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+  * Copyright © 2017 Amdocs\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
+  * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+  *\r
+-->\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
+       <parent>\r
+               <groupId>com.att.inno</groupId>\r
+               <artifactId>parent</artifactId>\r
+               <version>1.2.13</version>\r
+               <relativePath>..</relativePath>\r
+       </parent>\r
+       \r
+       <modelVersion>4.0.0</modelVersion>\r
+       <artifactId>xgen</artifactId>\r
+       <name>XGen</name>\r
+       \r
+       <packaging>jar</packaging>\r
+       <url>https://github.com/att/AAF</url>\r
+       <description>INNO</description>\r
+       <licenses>\r
+               <license>\r
+               <name>BSD License</name>\r
+               <url> </url>\r
+               </license>\r
+       </licenses>\r
+\r
+       <developers>\r
+               <developer>\r
+               <name>Jonathan Gathman</name>\r
+               <email></email>\r
+       <organization>ATT</organization>\r
+       <organizationUrl></organizationUrl>\r
+               </developer>\r
+       </developers>\r
+       \r
+       <dependencies>\r
+               <dependency>\r
+                       <groupId>com.att.inno</groupId>\r
+                       <artifactId>env</artifactId>\r
+                       <version>${project.version}</version>\r
+               </dependency>\r
+       </dependencies>\r
+       \r
+       <distributionManagement>\r
+               <snapshotRepository>\r
+                       <id>ossrhdme</id>\r
+                       <url>https://oss.sonatype.org/content/repositories/snapshots</url>\r
+               </snapshotRepository>\r
+               <repository>\r
+                       <id>ossrhdme</id>\r
+                       <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>\r
+               </repository>\r
+       </distributionManagement>\r
+       \r
+       <scm>\r
+               <connection>https://github.com/att/AAF.git</connection>\r
+               <developerConnection>${project.scm.connection}</developerConnection>\r
+               <url>http://github.com/att/AAF/tree/master</url>\r
+       </scm>\r
+       <build>\r
+               <plugins>\r
+                       <plugin>\r
+                       <groupId>org.apache.maven.plugins</groupId>\r
+                       <artifactId>maven-javadoc-plugin</artifactId>\r
+                       <configuration>\r
+                       <failOnError>false</failOnError>\r
+                       </configuration>\r
+                       <executions>\r
+                               <execution>\r
+                                       <id>attach-javadocs</id>\r
+                                       <goals>\r
+                                               <goal>jar</goal>\r
+                                       </goals>\r
+                               </execution>\r
+                       </executions>\r
+               </plugin> \r
+          \r
+          \r
+              <plugin>\r
+                     <groupId>org.apache.maven.plugins</groupId>\r
+                     <artifactId>maven-source-plugin</artifactId>\r
+                     <version>2.2.1</version>\r
+                     <executions>\r
+                       <execution>\r
+                         <id>attach-sources</id>\r
+                         <goals>\r
+                           <goal>jar-no-fork</goal>\r
+                         </goals>\r
+                       </execution>\r
+                     </executions>\r
+                   </plugin>\r
+\r
+\r
+                       <plugin>\r
+                               <groupId>org.sonatype.plugins</groupId>\r
+                               <artifactId>nexus-staging-maven-plugin</artifactId>\r
+                               <version>1.6.7</version>\r
+                               <extensions>true</extensions>\r
+                               <configuration>\r
+                               <serverId>ossrhdme</serverId>\r
+                               <nexusUrl>https://oss.sonatype.org/</nexusUrl>\r
+                               <autoReleaseAfterClose>true</autoReleaseAfterClose>\r
+                               </configuration>\r
+                       </plugin>\r
+                       \r
+               </plugins>\r
+       </build>\r
+\r
+</project>\r
diff --git a/xgen/src/main/java/com/att/xgen/Back.java b/xgen/src/main/java/com/att/xgen/Back.java
new file mode 100644 (file)
index 0000000..e2b94b2
--- /dev/null
@@ -0,0 +1,36 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen;\r
+\r
+public class Back {\r
+       public String str;\r
+       public boolean dec;\r
+       public boolean cr;\r
+       \r
+       public Back(String string, boolean decrement, boolean newline) {\r
+               str = string;\r
+               dec = decrement;\r
+               cr = newline;\r
+       }\r
+}\r
diff --git a/xgen/src/main/java/com/att/xgen/Cache.java b/xgen/src/main/java/com/att/xgen/Cache.java
new file mode 100644 (file)
index 0000000..31f7420
--- /dev/null
@@ -0,0 +1,39 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen;\r
+\r
+\r
+public interface Cache<G extends XGen<G>> {\r
+       public void dynamic(G hgen, Code<G> code);\r
+       \r
+       public static class Null<N extends XGen<N>> implements Cache<N> {\r
+               @Override\r
+               public void dynamic(N hgen, Code<N> code) {} // NO_OP, no matter what type\r
+\r
+               @SuppressWarnings("rawtypes")\r
+               private static Null<?> singleton = new Null();\r
+               public static Null<?> singleton() { return singleton;}\r
+       }\r
+\r
+}\r
diff --git a/xgen/src/main/java/com/att/xgen/CacheGen.java b/xgen/src/main/java/com/att/xgen/CacheGen.java
new file mode 100644 (file)
index 0000000..b3e0491
--- /dev/null
@@ -0,0 +1,133 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.io.OutputStreamWriter;\r
+import java.io.Writer;\r
+import java.util.ArrayList;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.Trans;\r
+import com.att.xgen.html.State;\r
+import com.att.xgen.html.Thematic;\r
+\r
+\r
+public abstract class CacheGen<G extends XGen<G>> {\r
+       public static final int NO_FLAGS = 0x0;\r
+       public final static int PRETTY  = 0x1;\r
+       public final static int XML             = 0x2;\r
+       public final static int HTML4   = 0x4;\r
+       public final static int HTML5   = 0x8;\r
+\r
+       \r
+       private ArrayList<Section<G>> sections = new ArrayList<Section<G>>();\r
+       private int flags;\r
+       private final Thematic thematic;\r
+\r
+       public CacheGen(int flags, Code<G> code) throws APIException, IOException {\r
+               this.flags = flags;\r
+               final XGenBuff<G> buff = new XGenBuff<G>(flags,this);\r
+               // Run to gather Strings and Code Class Segments\r
+               buff.run(new Cache<G>() {\r
+                               @Override\r
+                               public void dynamic(G hgen, Code<G> code) {\r
+                                       sections.add(buff.newSection());\r
+                                       sections.add(new Dynamic(hgen.getIndent(),code));\r
+                               }\r
+                       },code);\r
+               sections.add(buff.newSection());\r
+       \r
+               // If Code implements thematic, set for later\r
+               thematic = code instanceof Thematic?(Thematic)code:null;\r
+\r
+       }\r
+       \r
+       public abstract G create(int htmlStyle, Writer w);\r
+\r
+       public void replay(State<Env> state, Trans trans, OutputStream os, String theme) throws IOException, APIException {\r
+               replay(state, trans, new OutputStreamWriter(os), theme);\r
+       }\r
+       \r
+       public void replay(State<Env> state, Trans trans,Writer w, String theme) throws IOException, APIException {\r
+               if(thematic!=null) {\r
+                       theme = thematic.themeResolve(theme);\r
+               }\r
+               /* Theme\r
+               trans.setTheme(theme);\r
+               int htmlStyle = state.htmlVer(theme);\r
+               */\r
+               \r
+               XGenBuff<G> buff = new XGenBuff<G>(flags,this);\r
+               \r
+               // forward\r
+               int indent = 0;\r
+               Section<G> s;\r
+               int i=0;\r
+               @SuppressWarnings("unchecked")\r
+               Section<G>[] reverse = new Section[sections.size()];\r
+               for(Section<G> section : sections) {\r
+                       s = section.use(state, trans, buff); // note, doesn't change cached, only dynamic, which is created for thread\r
+                       int tempIndent = s.getIndent();\r
+                       s.setIndent(indent);\r
+                       s.forward(w);\r
+                       s.setIndent(tempIndent);\r
+                       indent = tempIndent;\r
+                       reverse[i++]=s;\r
+               }\r
+\r
+               for(--i;i>=0;--i) {\r
+                       reverse[i].back(w);\r
+               }\r
+               w.flush();\r
+       }\r
+       \r
+       private class Dynamic extends Section<G> {\r
+               private Code<G> code;\r
+               \r
+               public Dynamic(int indent, Code<G> code) {\r
+                       this.code = code;\r
+                       this.indent = indent;\r
+               }\r
+\r
+               @SuppressWarnings("unchecked")\r
+               public Section<G> use(State<Env> state, Trans trans, XGenBuff<G> buff) throws APIException, IOException {\r
+                       // Clone Dynamic to make Thread Safe\r
+                       Dynamic d = new Dynamic(indent,code);\r
+                       buff.setIndent(indent);\r
+                       if(code instanceof DynamicCode) {\r
+                               buff.run(state,trans,Cache.Null.singleton(), (DynamicCode<G,?,? extends Trans>)code);\r
+                       } else {\r
+                               buff.run((Cache<G>)Cache.Null.singleton(), code);\r
+                       }\r
+                       Section<G> s = buff.newSection();\r
+                       d.indent = s.indent;\r
+                       d.forward = s.forward;\r
+                       d.backward = s.backward;\r
+                       return d;\r
+               }\r
+       }\r
+}\r
diff --git a/xgen/src/main/java/com/att/xgen/Code.java b/xgen/src/main/java/com/att/xgen/Code.java
new file mode 100644 (file)
index 0000000..556b05a
--- /dev/null
@@ -0,0 +1,32 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen;\r
+\r
+import java.io.IOException;\r
+\r
+import com.att.inno.env.APIException;\r
+\r
+public interface Code<G extends XGen<G>> {\r
+       public void code(Cache<G> cache, G xgen) throws APIException, IOException;\r
+}\r
diff --git a/xgen/src/main/java/com/att/xgen/DynamicCode.java b/xgen/src/main/java/com/att/xgen/DynamicCode.java
new file mode 100644 (file)
index 0000000..810f918
--- /dev/null
@@ -0,0 +1,45 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen;\r
+\r
+import java.io.IOException;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.Trans;\r
+import com.att.xgen.html.State;\r
+\r
+/**\r
+ * Special Code Interface to gain access to Transaction\r
+ * and State information\r
+ *\r
+ */\r
+public abstract class DynamicCode<G extends XGen<G>, AS extends State<Env>, TRANS extends Trans> implements Code<G> {\r
+       public abstract void code(AS state, TRANS trans, Cache<G> cache, G xgen) throws APIException, IOException;\r
+       \r
+       // We expect not to have this section of the code engaged at any time\r
+       public void code(Cache<G> cache, G xgen) throws APIException, IOException {\r
+               code(null, null,cache,xgen);\r
+       }\r
+}\r
diff --git a/xgen/src/main/java/com/att/xgen/Mark.java b/xgen/src/main/java/com/att/xgen/Mark.java
new file mode 100644 (file)
index 0000000..e2e87d3
--- /dev/null
@@ -0,0 +1,42 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen;\r
+\r
+public class Mark {\r
+       // package on purpose\r
+       int spot = 0;\r
+       public String comment;\r
+       \r
+       public Mark() {\r
+               comment = null; \r
+       }\r
+       \r
+       public Mark(String string) {\r
+               comment = string;\r
+       }\r
+\r
+       public void spot(int spot) {\r
+               this.spot = spot;\r
+       }\r
+}\r
diff --git a/xgen/src/main/java/com/att/xgen/Section.java b/xgen/src/main/java/com/att/xgen/Section.java
new file mode 100644 (file)
index 0000000..7fa5761
--- /dev/null
@@ -0,0 +1,63 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen;\r
+\r
+import java.io.IOException;\r
+import java.io.Writer;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.Trans;\r
+import com.att.xgen.html.State;\r
+\r
+public class Section<G extends XGen<G>> {\r
+       protected int indent;\r
+       protected String forward;\r
+       protected String backward;\r
+       \r
+       // Default is to use the set Strings (static) \r
+       public Section<G> use(State<Env> state, Trans trans, XGenBuff<G> buff) throws APIException, IOException {\r
+               return this;\r
+       }\r
+       \r
+       public int getIndent() {\r
+               return indent;\r
+       }\r
+\r
+       public void setIndent(int indent) {\r
+               this.indent = indent;\r
+       }\r
+\r
+       public void forward(Writer w) throws IOException {\r
+               w.write(forward);\r
+       }\r
+       \r
+       public void back(Writer w) throws IOException {\r
+               w.write(backward);\r
+       }\r
+       \r
+       public String toString() {\r
+               return forward;\r
+       }\r
+}\r
diff --git a/xgen/src/main/java/com/att/xgen/XGen.java b/xgen/src/main/java/com/att/xgen/XGen.java
new file mode 100644 (file)
index 0000000..1ca6f46
--- /dev/null
@@ -0,0 +1,298 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen;\r
+\r
+import java.io.PrintWriter;\r
+import java.io.Writer;\r
+import java.util.Stack;\r
+\r
+import com.att.inno.env.util.IndentPrintWriter;\r
+import com.att.inno.env.util.StringBuilderWriter;\r
+\r
+public class XGen<RT extends XGen<RT>> {\r
+\r
+       public static int COMMENT_COLUMN = 40;\r
+       private StringBuilder backSB = new StringBuilder();\r
+       private Stack<Back> backStack = new Stack<Back>();\r
+       \r
+       protected XGen(Writer w) {\r
+               forward = new IndentPrintWriter(w);\r
+       }\r
+\r
+       public int pushBack(Back b) {\r
+               int rv = backStack.size();\r
+               backStack.push(b);\r
+               return rv;\r
+       }\r
+\r
+       public boolean pretty = false;\r
+       protected IndentPrintWriter forward;\r
+\r
+       public IndentPrintWriter getWriter() {\r
+               return forward;\r
+       }\r
+\r
+       protected PrintWriter back = new PrintWriter(\r
+                               new StringBuilderWriter(backSB));\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public RT pretty() {\r
+               pretty = true;\r
+               return (RT) this;\r
+       }\r
+\r
+       protected void prettyln(PrintWriter pw) {\r
+               if(pretty)pw.println();\r
+       }\r
+\r
+       public RT leaf(Mark mark, String tag, String ... args) {\r
+               mark.spot = backStack.size();\r
+               return leaf(tag, args);\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public RT leaf(String tag, String ... attrs) {\r
+               forward.append('<');\r
+               forward.append(tag);\r
+               addAttrs(attrs);\r
+               forward.append('>');\r
+               back.append("</");\r
+               back.append(tag);\r
+               back.append('>');\r
+               backStack.push(new Back(backSB.toString(), false, true));\r
+               backSB.setLength(0);\r
+               return (RT)this;\r
+       }\r
+\r
+       public RT incr(String tag, String ... args) {\r
+               return incr(null, tag, false, args);\r
+       }\r
+\r
+       public RT incr(String tag, boolean oneLine, String ... args) {\r
+               return incr(null, tag, oneLine, args);\r
+       }\r
+\r
+       public RT incr(Mark mark) {\r
+               return incr(mark,mark.comment, false, new String[0]);\r
+       }\r
+\r
+       public RT incr(Mark mark, String tag, String ... attrs) {\r
+               return incr(mark, tag, false, attrs);\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public RT incr(Mark mark, String tag, boolean oneLine, String ... attrs) {\r
+               forward.append('<');\r
+               forward.append(tag);\r
+               addAttrs(attrs);\r
+               forward.append('>');\r
+               \r
+               back.append("</");\r
+               back.append(tag);\r
+               back.append('>');\r
+       \r
+               if(pretty) {\r
+                       if(mark!=null && mark.comment!=null) {\r
+                               int fi = forward.getIndent()*IndentPrintWriter.INDENT;\r
+                               for(int i = fi+backSB.length();i<=COMMENT_COLUMN;++i) {\r
+                                       back.append(' ');\r
+                               }\r
+                               back.append("<!-- end ");\r
+                               back.append(mark.comment);\r
+                               back.append(" -->");\r
+                               \r
+                               forward.toCol(COMMENT_COLUMN);\r
+                               forward.append("<!-- begin ");\r
+                               forward.append(mark.comment);\r
+                               forward.append(" -->");\r
+                       }\r
+                       forward.inc();\r
+                       if(!oneLine) {\r
+                               forward.println();\r
+                       }\r
+                       back.println();\r
+               }\r
+               if(mark!=null)mark.spot = backStack.size();\r
+               backStack.push(new Back(backSB.toString(),true, false));\r
+               backSB.setLength(0);\r
+               return (RT)this;\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public RT tagOnly(String tag, String ... attrs) {\r
+               forward.append('<');\r
+               forward.append(tag);\r
+               addAttrs(attrs);\r
+               forward.append(" />");\r
+               if(pretty) {\r
+                       forward.println();\r
+               }\r
+               return (RT)this;\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public RT text(String txt) {\r
+               forward.append(txt);\r
+               return (RT)this;\r
+       }\r
+       \r
+       @SuppressWarnings("unchecked")\r
+       public RT xml(String txt) {\r
+               for(int i=0; i<txt.length();++i) {\r
+                       char c = txt.charAt(i);\r
+                       switch(c) {\r
+                               case '<':\r
+                                       forward.append("&lt;");\r
+                                       break;\r
+                               case '>':\r
+                                       forward.append("&gt;");\r
+                                       break;\r
+                               case '&':\r
+                                       forward.append("&amp;");\r
+                                       break;\r
+                               default:\r
+                                       forward.append(c);\r
+                       }\r
+               }\r
+               return (RT)this;\r
+       }\r
+\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public RT textCR(int tabs, String txt) {\r
+               for(int i=0;i<tabs;++i) {\r
+                       forward.append("  ");\r
+               }\r
+               forward.append(txt);\r
+               if(pretty)forward.println();\r
+               return (RT)this;\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public RT value() {\r
+               Mark mark = new Mark();\r
+               mark.spot = backStack.size()-1;\r
+               end(mark);\r
+               return (RT)this;\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public RT value(String txt) {\r
+               forward.append(txt);\r
+               Mark mark = new Mark();\r
+               mark.spot = backStack.size()-1;\r
+               end(mark);\r
+               return (RT)this;\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public RT value(String txt, int levels) {\r
+               forward.append(txt);\r
+               Mark mark = new Mark();\r
+               mark.spot = backStack.size()-levels;\r
+               end(mark);\r
+               return (RT)this;\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public RT end(Mark mark) {\r
+               int size = backStack.size();\r
+               Back c;\r
+               boolean println = false;\r
+               for(int i=mark==null?0:mark.spot;i<size;++i) {\r
+                       c = backStack.pop();\r
+                       if(c.dec)forward.dec();\r
+                       forward.append(c.str);\r
+                       println = c.cr;\r
+               }\r
+               if(pretty && println) {\r
+                       forward.println();\r
+               }\r
+               return (RT)this;\r
+       }\r
+\r
+       public RT end() {\r
+               Mark mark = new Mark();\r
+               mark.spot=backStack.size()-1;\r
+               if(mark.spot<0)mark.spot=0;\r
+               return end(mark);\r
+       }\r
+\r
+       public RT end(int i) {\r
+               Mark mark = new Mark();\r
+               mark.spot=backStack.size()-i;\r
+               if(mark.spot<0)mark.spot=0;\r
+               return end(mark);\r
+       }\r
+\r
+       public void endAll() {\r
+               end(new Mark());\r
+               forward.flush();\r
+       }\r
+\r
+       protected void addAttrs(String[] attrs) {\r
+               if(attrs!=null) {\r
+                       for(String attr : attrs) {\r
+                               if(attr!=null && attr.length()>0) {\r
+                                       forward.append(' ');\r
+                                       String[] split = attr.split("=",2);\r
+                                       switch(split.length) {\r
+                                               case 0:\r
+                                                       break;\r
+                                               case 1:\r
+                                                       forward.append(split[0]);\r
+//                                                     forward.append("=\"\"");\r
+                                                       break;\r
+                                               default:\r
+                                                       forward.append(split[0]);\r
+                                                       forward.append("=\"");\r
+                                                       forward.append(split[1]);\r
+                                                       forward.append('"');\r
+                                                       break;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       @SuppressWarnings("unchecked")\r
+       public RT comment(String string) {\r
+               if(pretty) {\r
+                       forward.print("<!--  ");\r
+                       forward.print(string);\r
+                       forward.println("  -->");\r
+               }\r
+               return (RT)this;\r
+       }\r
+\r
+       public void setIndent(int indent) {\r
+               forward.setIndent(indent);\r
+               forward.toIndent();\r
+       }\r
+\r
+       public int getIndent() {\r
+               return forward.getIndent();\r
+       }\r
+\r
+}\r
diff --git a/xgen/src/main/java/com/att/xgen/XGenBuff.java b/xgen/src/main/java/com/att/xgen/XGenBuff.java
new file mode 100644 (file)
index 0000000..d27b030
--- /dev/null
@@ -0,0 +1,88 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen;\r
+\r
+import java.io.IOException;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.inno.env.Env;\r
+import com.att.inno.env.Trans;\r
+import com.att.inno.env.util.StringBuilderWriter;\r
+import com.att.xgen.html.State;\r
+\r
+public class XGenBuff<G extends XGen<G>> {\r
+       private G xgen;\r
+       private StringBuilder sb;\r
+       // private String forward, backward;\r
+       \r
+       public XGenBuff(int flags, CacheGen<G> cg) {\r
+               sb = new StringBuilder();\r
+               xgen = cg.create(flags, new StringBuilderWriter(sb));\r
+       }\r
+\r
+       /**\r
+        * Normal case of building up Cached HTML without transaction info\r
+        * \r
+        * @param cache\r
+        * @param code\r
+        * @throws APIException\r
+        * @throws IOException\r
+        */\r
+       public void run(Cache<G> cache, Code<G> code) throws APIException, IOException {\r
+               code.code(cache, xgen);\r
+       }\r
+\r
+       /**\r
+        * Special Case where code is dynamic, so give access to State and Trans info\r
+        *  \r
+        * @param state\r
+        * @param trans\r
+        * @param cache\r
+        * @param code\r
+        * @throws APIException\r
+        * @throws IOException\r
+        */\r
+       @SuppressWarnings({ "unchecked", "rawtypes" })\r
+       public void run(State<Env> state, Trans trans, Cache cache, DynamicCode code) throws APIException, IOException {\r
+                       code.code(state, trans, cache, xgen);\r
+       }\r
+       \r
+       public int getIndent() {\r
+               return xgen.getIndent();\r
+       }\r
+\r
+       public void setIndent(int indent) {\r
+               xgen.setIndent(indent);\r
+       }\r
+\r
+       public Section<G> newSection() {\r
+               Section<G> s = new Section<G>();\r
+               s.indent = xgen.getIndent();\r
+               s.forward = sb.toString();\r
+               sb.setLength(0);\r
+               s.backward = sb.toString();\r
+               sb.setLength(0);\r
+               return s;\r
+       }\r
+}\r
diff --git a/xgen/src/main/java/com/att/xgen/html/HTML4Gen.java b/xgen/src/main/java/com/att/xgen/html/HTML4Gen.java
new file mode 100644 (file)
index 0000000..7be425a
--- /dev/null
@@ -0,0 +1,145 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen.html;\r
+\r
+import java.io.Writer;\r
+\r
+import com.att.xgen.Mark;\r
+\r
+public class HTML4Gen extends HTMLGen {\r
+       private final static String DOCTYPE = \r
+               /*\r
+               "<!DOCTYPE HTML PUBLIC " +\r
+               "\"-//W3C//DTD HTML 4.01 Transitional//EN\" " +\r
+               "\"http://www.w3.org/TR/html3/loose.dtd\">";\r
+               "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"" +\r
+               " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";\r
+               */\r
+               "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" +\r
+               " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";\r
+\r
+       public HTML4Gen(Writer w) {\r
+               super(w);\r
+       }\r
+\r
+       @Override\r
+       public HTMLGen html(String ... attrib) {\r
+               forward.println(DOCTYPE);\r
+               return incr("html","xmlns=http://www.w3.org/1999/xhtml","xml:lang=en","lang=en");\r
+               \r
+       }\r
+\r
+       @Override\r
+       public Mark head() {\r
+               Mark head = new Mark("head");\r
+               incr(head);\r
+               return head;\r
+       }\r
+\r
+       @Override\r
+       public Mark body(String ... attrs) {\r
+               Mark body = new Mark("body");\r
+               incr(body,"body",attrs);\r
+               return body;\r
+       }\r
+       \r
+       @Override\r
+       public HTML4Gen charset(String charset) {\r
+               forward.append("<meta http-equiv=\"Content-type\" content=\"text.hml; charset=");\r
+               forward.append(charset);\r
+               forward.append("\">");\r
+               prettyln(forward);\r
+               return this;\r
+       }\r
+\r
+       @Override\r
+       public Mark header(String ... attribs) {\r
+               String[] a = new String[attribs.length+1];\r
+               a[0]="header";\r
+               System.arraycopy(attribs, 0, a, 1, attribs.length);\r
+               return divID(a);\r
+       }\r
+\r
+       @Override\r
+       public Mark footer(String ... attribs) {\r
+               String[] a = new String[attribs.length+1];\r
+               a[0]="footer";\r
+               System.arraycopy(attribs, 0, a, 1, attribs.length);\r
+               return divID(a);\r
+       }\r
+\r
+       @Override\r
+       public Mark section(String ... attribs) {\r
+               String[] a = new String[attribs.length+1];\r
+               a[0]="section";\r
+               System.arraycopy(attribs, 0, a, 1, attribs.length);\r
+               return divID(a);\r
+       }\r
+\r
+       @Override\r
+       public Mark article(String ... attribs) {\r
+               String[] a = new String[attribs.length+1];\r
+               a[0]="attrib";\r
+               System.arraycopy(attribs, 0, a, 1, attribs.length);\r
+               return divID(a);\r
+       }\r
+\r
+       @Override\r
+       public Mark aside(String ... attribs) {\r
+               String[] a = new String[attribs.length+1];\r
+               a[0]="aside";\r
+               System.arraycopy(attribs, 0, a, 1, attribs.length);\r
+               return divID(a);\r
+       }\r
+\r
+       @Override\r
+       public Mark nav(String ... attribs) {\r
+               String[] a = new String[attribs.length+1];\r
+               a[0]="nav";\r
+               System.arraycopy(attribs, 0, a, 1, attribs.length);\r
+               return divID(a);\r
+       }\r
+\r
+//     @Override\r
+//     protected void importCSS(Imports imports) {\r
+//             if(imports.css.size()==1) {\r
+//                     cssInline(imports.css.get(0));\r
+//             } else {\r
+//                     text("<style type=\"text/css\">");\r
+//                     prettyln(forward);\r
+//                     forward.inc();\r
+//                     for(String str : imports.css) {\r
+//                             forward.print("@import url(\"");\r
+//                             forward.print(imports.themePath(null));\r
+//                             forward.print(str);\r
+//                             forward.print("\");");\r
+//                             prettyln(forward);\r
+//                     }\r
+//                     forward.dec();\r
+//                     forward.print("</style>");\r
+//                     prettyln(forward);\r
+//             }\r
+//     }\r
+       \r
+}\r
diff --git a/xgen/src/main/java/com/att/xgen/html/HTML5Gen.java b/xgen/src/main/java/com/att/xgen/html/HTML5Gen.java
new file mode 100644 (file)
index 0000000..f41575c
--- /dev/null
@@ -0,0 +1,157 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen.html;\r
+\r
+import java.io.Writer;\r
+\r
+import com.att.xgen.Mark;\r
+\r
+public class HTML5Gen extends HTMLGen {\r
+       public HTML5Gen(Writer w) {\r
+               super(w);\r
+       }\r
+\r
+       @Override\r
+       public HTMLGen html(String ... attrib) {\r
+               //forward.println("<!DOCTYPE html>");\r
+               incr("html",attrib);\r
+               return this;\r
+       }\r
+       \r
+       @Override\r
+       public Mark head() {\r
+               Mark head = new Mark("head");\r
+               incr(head).directive("meta","charset=utf-8");\r
+               return head;\r
+       }\r
+\r
+       @Override\r
+       public Mark body(String ... attrs) {\r
+               Mark body = new Mark("body");\r
+               incr(body,"body",attrs);\r
+               //chromeFrame();\r
+               return body;\r
+       }\r
+       \r
+       @Override\r
+       public HTML5Gen charset(String charset) {\r
+               forward.append("<meta charset=\"");\r
+               forward.append(charset);\r
+               forward.append("\">");\r
+               prettyln(forward);\r
+               return this;\r
+       }\r
+\r
+       @Override\r
+       public Mark header(String ... attribs) {\r
+               Mark mark = new Mark("header");\r
+               incr(mark, mark.comment, attribs);\r
+               return mark;\r
+       }\r
+\r
+       @Override\r
+       public Mark footer(String ... attribs) {\r
+               Mark mark = new Mark("footer");\r
+               incr(mark, mark.comment, attribs);\r
+               return mark;\r
+       }\r
+\r
+       @Override\r
+       public Mark section(String ... attribs) {\r
+               Mark mark = new Mark("section");\r
+               incr(mark, mark.comment,attribs);\r
+               return mark;\r
+       }\r
+\r
+       @Override\r
+       public Mark article(String ... attribs) {\r
+               Mark mark = new Mark("article");\r
+               incr(mark, mark.comment,attribs);\r
+               return mark;\r
+       }\r
+\r
+       @Override\r
+       public Mark aside(String ... attribs) {\r
+               Mark mark = new Mark("aside");\r
+               incr(mark, mark.comment,attribs);\r
+               return mark;\r
+       }\r
+\r
+       @Override\r
+       public Mark nav(String ... attribs) {\r
+               Mark mark = new Mark("nav");\r
+               incr(mark, mark.comment,attribs);\r
+               return mark;\r
+       }\r
+       \r
+\r
+//     @Override\r
+//     protected void importCSS(Imports imports) {\r
+//             if(imports.css.size() == 1) {\r
+//                     cssInline(imports.css.get(0));\r
+//             } else {\r
+//                     for(String str : imports.css) {\r
+//                             forward.print("<link rel=\"stylesheet\" href=\"");\r
+//                             forward.print(imports.themePath(null));\r
+//                             forward.print(str);\r
+//                             forward.println("\">");\r
+//                     }\r
+//             }\r
+//     }\r
+//\r
+\r
+       /*\r
+       public void chromeFrame() {\r
+               this.textCR(0,"<!--[if IE]>");\r
+               Mark mark = new Mark();\r
+               this.leaf(mark, "script","type=text/javascript","src=http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js")\r
+                       .end(mark);\r
+               this.incr(mark, "style")\r
+                       .textCR(0,".chromeFrameInstallDefaultStyle {")\r
+                       .textCR(1,"width: 100%; /* default is 800px * /")\r
+                       .textCR(1,"border: 5px solid blue;")\r
+                       .textCR(0,"}")\r
+                       .end(mark);\r
+\r
+               this.incr(mark,"div","id=prompt"); // auto comment would break IE specific Script\r
+               // "if IE without GCF, prompt goes here"\r
+               this.text("Please load this plugin to run ClientSide Websockets")\r
+                       .end(mark);\r
+\r
+               this.incr(mark, "script")\r
+                       .textCR(0, "// The conditional ensures that this code will only execute in IE,")\r
+                               .textCR(0, "// Therefore we can use the IE-specific attachEvent without worry")\r
+                               .textCR(0, "window.attachEvent('onload', function() {")\r
+                               .textCR(1,"CFInstall.check({")\r
+                                       .textCR(2,"mode: 'inline', // the default")\r
+                                       .textCR(2,"node: 'prompt'")\r
+                               .textCR(1, "});")\r
+                       .textCR(0, "});")\r
+                       .end(mark);\r
+                       \r
+               this.textCR(0,"<![endif]-->");\r
+       }\r
+       */\r
+\r
+}\r
diff --git a/xgen/src/main/java/com/att/xgen/html/HTMLCacheGen.java b/xgen/src/main/java/com/att/xgen/html/HTMLCacheGen.java
new file mode 100644 (file)
index 0000000..23a4234
--- /dev/null
@@ -0,0 +1,61 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen.html;\r
+\r
+import java.io.IOException;\r
+import java.io.Writer;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.xgen.CacheGen;\r
+import com.att.xgen.Code;\r
+\r
+public class HTMLCacheGen extends CacheGen<HTMLGen> {\r
+       protected int flags;\r
+\r
+       public HTMLCacheGen(int flags, Code<HTMLGen> code) throws APIException,IOException {\r
+               super(flags, code);\r
+               this.flags = flags;\r
+       }\r
+\r
+       @Override\r
+       public HTMLGen create(int htmlStyle, Writer w) {\r
+               HTMLGen hg;\r
+               switch(htmlStyle&(CacheGen.HTML4|CacheGen.HTML5)) {\r
+                       case CacheGen.HTML4:\r
+                               hg = new HTML4Gen(w);\r
+                               break;\r
+                       case CacheGen.HTML5:\r
+                       default:\r
+                               hg = new HTML5Gen(w);\r
+                               break;\r
+\r
+               }\r
+               hg.pretty = (htmlStyle&CacheGen.PRETTY)>0;\r
+               return hg;\r
+       }\r
+\r
+       protected HTMLGen clone(Writer w) {\r
+               return create(flags,w);\r
+       }\r
+}\r
diff --git a/xgen/src/main/java/com/att/xgen/html/HTMLGen.java b/xgen/src/main/java/com/att/xgen/html/HTMLGen.java
new file mode 100644 (file)
index 0000000..e40b588
--- /dev/null
@@ -0,0 +1,242 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen.html;\r
+\r
+import java.io.Writer;\r
+\r
+import com.att.xgen.Mark;\r
+import com.att.xgen.XGen;\r
+\r
+public abstract class HTMLGen extends XGen<HTMLGen> {\r
+       public static final String A = "a";\r
+       public static final String P = "p";\r
+       public static final String LI = "li";\r
+       public static final String OL = "ol";\r
+       public static final String UL = "ul";\r
+       \r
+       \r
+       public static final String TABLE = "table";\r
+       public static final String THEAD = "thead";\r
+       public static final String TBODY = "tbody";\r
+       public static final String TR = "tr";\r
+       public static final String TH = "th";\r
+       public static final String TD = "td";\r
+       \r
+       public static final String TITLE = "title";\r
+       public static final String H1 = "h1";\r
+       public static final String H2 = "h2";\r
+       public static final String H3 = "h3";\r
+       public static final String H4 = "h4";\r
+       public static final String H5 = "h5";\r
+       \r
+       \r
+       \r
+       // --------------------------- HTML Version Specific -----------------------\r
+       public abstract HTMLGen html(String ... attributes);\r
+       public abstract HTMLGen charset(String charset);\r
+       public abstract Mark head();\r
+       public abstract Mark body(String ... attribs);\r
+\r
+       \r
+       // HTML 5 has simplified sectioning\r
+       public abstract Mark header(String ... attribs);\r
+       public abstract Mark footer(String ... attribs);\r
+       public abstract Mark section(String ... attribs);\r
+       public abstract Mark article(String ... attribs);\r
+       public abstract Mark aside(String ... attribs);\r
+       public abstract Mark nav(String ... attribs);\r
+\r
+       // --------------------------- HTML Version Specific -----------------------\r
+\r
+       public HTMLGen imports(Imports imports) {\r
+               //this.imports=imports;\r
+               for(String str : imports.css) {\r
+                       forward.print("<link rel=\"stylesheet\" href=\"");\r
+                       forward.print(imports.themePath(null));\r
+                       forward.print(str);\r
+                       forward.println("\">");\r
+               }\r
+\r
+               for(String str : imports.js) {\r
+                       forward.print("<script type=\"text/javascript\" src=\"");\r
+                       forward.print(imports.themePath(null));\r
+                       forward.print(str);\r
+                       forward.println("\"></script>");\r
+               }\r
+               return this;\r
+       }\r
+       \r
+       public HTMLGen jsVars(String ... attrs) {\r
+               forward.println("<script type=text/javascript>");\r
+               if(attrs!=null) {\r
+                       for(int i=0; i<attrs.length;++i) {\r
+                               forward.append(' ');\r
+                               String[] split = attrs[i].split("=",2);\r
+                               switch(split.length) {\r
+                                       case 2:\r
+                                               forward.print("  var ");\r
+                                               forward.append(split[0]);\r
+                                               forward.append("='");\r
+                                               forward.append(split[1]);\r
+                                               forward.println("';");\r
+                                               break;\r
+                               }\r
+                       }\r
+               }\r
+               forward.println("</script>");\r
+               return this;\r
+       }\r
+\r
+       public HTMLGen(Writer w) {\r
+               super(w);\r
+       }\r
+\r
+       /**\r
+        * Use "directive" to handle non-ended HTML tags like <meta ... >  and <link ...>\r
+        * @param tag\r
+        * @param attrs\r
+        * @return\r
+        */\r
+       public HTMLGen directive(String tag, String ... attrs) {\r
+               forward.append('<');\r
+               forward.append(tag);\r
+               addAttrs(attrs);\r
+               forward.append('>');\r
+               if(pretty) {\r
+                       forward.println();\r
+               }\r
+               return this;\r
+       }\r
+\r
+       public Mark divID(String ... attrs) {\r
+               Mark div;\r
+               if(attrs.length>0) {\r
+                       div = new Mark(attrs[0]);\r
+                       attrs[0]="id="+attrs[0];\r
+               } else {\r
+                       div = new Mark();\r
+               }\r
+               incr(div, "div", attrs);\r
+               return div;\r
+       }\r
+\r
+       public HTMLGen img(String ... attrs) {\r
+               return tagOnly("img", attrs);\r
+       }\r
+       \r
+       /**\r
+        * Input Cheesecake... creates a Label and Field in the form of Table Rows.\r
+        * Make sure you create a table first, ie.  incr(HTMLGen.TABLE);\r
+        * \r
+        * Setting Required to "true" will add required Attribute to both Label and Field.  In HTML5, "required" in the input will\r
+        * validate there is data in the fields before submitting.  "required" does nothing for label, but allows for\r
+        * easy CSS coding... "label[required] { ... }", so that colors can be changed\r
+        * \r
+        * @param id\r
+        * @param label\r
+        * @param required\r
+        * @param attrs\r
+        * @return\r
+        */\r
+       public HTMLGen input(String id, String label, boolean required, String ... attrs) {\r
+               Mark mtr = new Mark(TR);\r
+               Mark mtd = new Mark(TD);\r
+               incr(mtr);\r
+               incr(mtd);\r
+               incr("label",true, "for="+id,required?"required":null).text(label).end();\r
+               end(mtd);\r
+               String nattrs[] = new String[attrs.length+(required?3:2)];\r
+               nattrs[0]="id="+id;\r
+               nattrs[1]="name="+id;\r
+               System.arraycopy(attrs, 0, nattrs, 2, attrs.length);\r
+               if(required) {\r
+                       nattrs[nattrs.length-1]="required";\r
+               }\r
+               incr(mtd);\r
+               tagOnly("input",nattrs);\r
+               end(mtr);\r
+               return this;\r
+       }\r
+       \r
+       //  Common tags that do not have standard endings.  These are here to help people who don't know to pick directive  \r
+       public HTMLGen br() {\r
+               forward.append("<br>");\r
+               if(pretty) {\r
+                       forward.println();\r
+               }\r
+               return this;\r
+       }\r
+\r
+       public HTMLGen p(String ... text) {\r
+               forward.append("<p>");\r
+               for(String s : text) {\r
+                       forward.append(s);\r
+               }\r
+               if(pretty) {\r
+                       forward.println();\r
+               }\r
+               return this;\r
+       }\r
+\r
+       public HTMLGen hr() {\r
+               forward.append("<hr>");\r
+               if(pretty) {\r
+                       forward.println();\r
+               }\r
+               return this;\r
+       }\r
+\r
+       public JSGen js(Mark mark) {\r
+               return new JSGen(mark, this);\r
+       }\r
+\r
+       public JSGen js() {\r
+               return js(null);\r
+       }\r
+//\r
+//     protected void cssInline(String filename) {\r
+//             File file = new File(imports.webDir,filename);\r
+//             try {\r
+//                     String line;\r
+//                     BufferedReader br = new BufferedReader(new FileReader(file));\r
+//                     try {\r
+//                             forward.print("<style>");\r
+//                             prettyln(forward);\r
+//                             while((line=br.readLine())!=null) {\r
+//                                     forward.print((pretty?line:line.trim()));\r
+//                                     prettyln(forward);\r
+//                             }                       \r
+//                     }finally {\r
+//                             forward.print("</style>");\r
+//                             prettyln(forward);\r
+//                             br.close();\r
+//                     }\r
+//             } catch (IOException e) {\r
+//                     e.printStackTrace();\r
+//                     // Can't read, suffice to import normally?\r
+//                     // for now, just skip\r
+//             }\r
+//     }\r
+       \r
+}\r
diff --git a/xgen/src/main/java/com/att/xgen/html/Imports.java b/xgen/src/main/java/com/att/xgen/html/Imports.java
new file mode 100644 (file)
index 0000000..d47b663
--- /dev/null
@@ -0,0 +1,100 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen.html;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+public class Imports implements Thematic{\r
+       List<String> css,js;\r
+       public final int backdots;\r
+//     public final File webDir;\r
+       private String theme;\r
+       \r
+       public Imports(int backdots) {\r
+//             this.webDir = webDir;\r
+               \r
+               css = new ArrayList<String>();\r
+               js = new ArrayList<String>();\r
+               this.backdots = backdots;\r
+               theme = "";\r
+       }\r
+       \r
+       public Imports css(String str) {\r
+               css.add(str);\r
+               return this;\r
+       }\r
+       \r
+       public Imports js(String str) {\r
+               js.add(str);\r
+               return this;\r
+       }\r
+\r
+       public Imports theme(String str) {\r
+               theme = str==null?"":str;\r
+               return this;\r
+       }\r
+\r
+       /**\r
+        * Pass in a possible Theme.  If it is "" or null, it will resolve to default Theme set in Imports\r
+        * \r
+        * @param theTheme\r
+        * @return\r
+        */\r
+       @Override\r
+       public String themePath(String theTheme) {\r
+               StringBuilder src = dots(new StringBuilder());\r
+               if(theTheme==null||theTheme.length()==0) {\r
+                       src.append(theme);\r
+                       if(theme.length()>0)src.append('/');\r
+               } else {\r
+                       src.append(theTheme);\r
+                       src.append('/');\r
+               }\r
+\r
+               return src.toString();\r
+       }\r
+       \r
+       /**\r
+        * Pass in a possible Theme.  If it is "" or null, it will resolve to default Theme set in Imports\r
+        * \r
+        * @param theTheme\r
+        * @return\r
+        */\r
+       @Override\r
+       public String themeResolve(String theTheme) {\r
+               return (theTheme==null||theTheme.length()==0)\r
+                       ?theme\r
+                       :theTheme;\r
+       }\r
+\r
+       public StringBuilder dots(StringBuilder src) {\r
+               for(int i=0;i<backdots;++i) {\r
+                       src.append("../");\r
+               }\r
+               return src;\r
+       }\r
+       \r
+};\r
+\r
diff --git a/xgen/src/main/java/com/att/xgen/html/JSGen.java b/xgen/src/main/java/com/att/xgen/html/JSGen.java
new file mode 100644 (file)
index 0000000..664f399
--- /dev/null
@@ -0,0 +1,206 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen.html;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.FileReader;\r
+import java.io.IOException;\r
+\r
+import com.att.inno.env.util.IndentPrintWriter;\r
+import com.att.xgen.Back;\r
+import com.att.xgen.Mark;\r
+\r
+\r
+public class JSGen {\r
+       private HTMLGen htmlGen;\r
+       private IndentPrintWriter ipw;\r
+       private Mark mark;\r
+\r
+       public JSGen(Mark mark, HTMLGen hg) {\r
+               this.mark = mark==null?new Mark():mark;\r
+               hg.incr(this.mark, "script", "language=javascript", "type=text/javascript");\r
+               htmlGen = hg;\r
+               ipw = hg.getWriter();\r
+       }\r
+\r
+       public JSGen inline(String filename, int tabstop) throws IOException {\r
+               BufferedReader br = new BufferedReader(new FileReader(filename));\r
+               int indent = htmlGen.getIndent();\r
+               try {\r
+                       boolean pretty = htmlGen.pretty;\r
+                       String line, el;\r
+                       int l, end;\r
+                       while((line=br.readLine())!=null) {\r
+                               if(pretty) {\r
+                                       String[] elements = line.split("\t");\r
+                                       \r
+                                       for(int i=0; i<elements.length;++i) {\r
+                                               el = elements[i];\r
+                                               l = el.length();\r
+                                               if(l==0) {// was a Tab\r
+                                                       ipw.print("  ");\r
+                                               } else {\r
+                                                       el = el.trim();\r
+                                                       l = l-el.length();\r
+                                                       end = l/tabstop;\r
+                                                       for(int j=0;j<end;++j) {\r
+                                                               ipw.print("  ");\r
+                                                       }\r
+                                                       end = l%tabstop;\r
+                                                       for(int j=0;j<end;++j) {\r
+                                                               ipw.print(' ');\r
+                                                       }\r
+                                                       if(i>0) ipw.print(' ');\r
+                                                               ipw.print(el);\r
+                                                       }\r
+                                       }\r
+                                       ipw.println();\r
+                               } else {\r
+                                       ipw.print(line.trim());\r
+                               }\r
+                       }\r
+               } finally {\r
+                       htmlGen.setIndent(indent);\r
+                       try {\r
+                               br.close();\r
+                       } catch (IOException e) {\r
+                               e.printStackTrace();\r
+                       }\r
+               }\r
+               return this;\r
+       }\r
+       \r
+       public JSGen pst(String ... lines) {\r
+               return pst(null, lines);\r
+       }\r
+       \r
+       public JSGen pst(Mark jm, String ... lines) {\r
+               if(lines.length>0) ipw.append(lines[0]);\r
+               ipw.append('(');\r
+               for(int i=1;i<lines.length;++i) {\r
+                       ipw.print(lines[i]);\r
+                       ipw.print(", ");\r
+               }\r
+               Back back;\r
+\r
+               if(htmlGen.pretty) {\r
+                       back = new Back(");\n",false,false);\r
+               } else {\r
+                       back = new Back(");",false,false);\r
+               }\r
+               int spot = htmlGen.pushBack(back);\r
+               if(jm!=null)jm.spot(spot);\r
+               return this;\r
+       }\r
+       \r
+       public JSGen li(String ... lines) {\r
+               int current = ipw.getIndent();\r
+               for(int i=0;i<lines.length;++i) {\r
+                       if(i==1)ipw.inc();\r
+                       if(i>0)ipw.println();\r
+                       ipw.print(lines[i]);\r
+               }\r
+               ipw.setIndent(current);\r
+               ipw.append(';');\r
+               if(htmlGen.pretty)ipw.println();\r
+               return this;\r
+       }\r
+       \r
+       public JSGen text(String text) {\r
+               ipw.append(text);\r
+               if(htmlGen.pretty)ipw.println();\r
+               return this;\r
+       }\r
+\r
+       public JSGen function(String name, String ... params) {\r
+               return function(null, name, params);\r
+       }\r
+       \r
+       public JSGen jqfunc(Mark mark, String name, String ... params) {\r
+               pst(mark,"$").function(name, params);\r
+               return this;\r
+       }\r
+       \r
+       public JSGen function(Mark jm, String name, String ... params) {\r
+               ipw.print("function ");\r
+               ipw.print(name);\r
+               ipw.print('(');\r
+               for(int i=0;i<params.length;++i) {\r
+                       if(i!=0)ipw.print(", ");\r
+                       ipw.print(params[i]);\r
+               }\r
+               ipw.print(") {");\r
+               if(htmlGen.pretty) {\r
+                       ipw.println();\r
+                       ipw.inc();\r
+               }\r
+               int spot = htmlGen.pushBack(new Back("}",true,true));\r
+               if(jm!=null)jm.spot(spot); \r
+               return this;\r
+       }\r
+       \r
+       public JSGen cb(String ... lines) {\r
+               return cb(null,lines);\r
+       }\r
+\r
+       public JSGen cb(Mark jm, String ... lines) {\r
+               int current = ipw.getIndent();\r
+               for(int i=0;i<lines.length;++i) {\r
+                       if(i==1)ipw.inc();\r
+                       if(i>0)ipw.println();\r
+                       ipw.print(lines[i]);\r
+               }\r
+               ipw.setIndent(current);\r
+               ipw.print('{');\r
+               if(htmlGen.pretty) {\r
+                       ipw.println();\r
+                       ipw.inc();\r
+               }\r
+               int spot = htmlGen.pushBack(new Back("}",true,true));\r
+               if(jm!=null)jm.spot(spot); \r
+               return this;\r
+\r
+       }\r
+\r
+       \r
+       public JSGen comment(String ... lines) {\r
+               if(htmlGen.pretty) {\r
+                       for(int i=0;i<lines.length;++i) {\r
+                               ipw.print("// ");\r
+                               ipw.println(lines[i]);\r
+                       }\r
+               }\r
+               return this;\r
+       }\r
+       \r
+       public JSGen end(Mark mark) {\r
+               htmlGen.end(mark);\r
+               return this;\r
+       }\r
+       \r
+       public HTMLGen done() {\r
+               return htmlGen.end(mark);\r
+       }\r
+       \r
+}\r
diff --git a/xgen/src/main/java/com/att/xgen/html/State.java b/xgen/src/main/java/com/att/xgen/html/State.java
new file mode 100644 (file)
index 0000000..23b0807
--- /dev/null
@@ -0,0 +1,29 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen.html;\r
+\r
+import com.att.inno.env.Env;\r
+\r
+public interface State<ENV extends Env> {\r
+}\r
diff --git a/xgen/src/main/java/com/att/xgen/html/Thematic.java b/xgen/src/main/java/com/att/xgen/html/Thematic.java
new file mode 100644 (file)
index 0000000..a0d4ddb
--- /dev/null
@@ -0,0 +1,29 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen.html;\r
+\r
+public interface Thematic {\r
+       String themePath(String theTheme);\r
+       String themeResolve(String theTheme);\r
+}\r
diff --git a/xgen/src/main/java/com/att/xgen/xml/XMLCacheGen.java b/xgen/src/main/java/com/att/xgen/xml/XMLCacheGen.java
new file mode 100644 (file)
index 0000000..8fc2692
--- /dev/null
@@ -0,0 +1,47 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen.xml;\r
+\r
+import java.io.IOException;\r
+import java.io.Writer;\r
+\r
+import com.att.inno.env.APIException;\r
+import com.att.xgen.CacheGen;\r
+import com.att.xgen.Code;\r
+\r
+public class XMLCacheGen extends CacheGen<XMLGen> {\r
+\r
+       public XMLCacheGen(int flags, Code<XMLGen> code) throws APIException,\r
+                       IOException {\r
+               super(flags, code);\r
+       }\r
+\r
+       @Override\r
+       public XMLGen create(int style, Writer w) {\r
+               XMLGen xg = new XMLGen(w);\r
+               xg.pretty = (style & PRETTY)==PRETTY;\r
+               return xg;\r
+       }\r
+\r
+}\r
diff --git a/xgen/src/main/java/com/att/xgen/xml/XMLGen.java b/xgen/src/main/java/com/att/xgen/xml/XMLGen.java
new file mode 100644 (file)
index 0000000..2321724
--- /dev/null
@@ -0,0 +1,46 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aai\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * Copyright © 2017 Amdocs\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
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package com.att.xgen.xml;\r
+\r
+import java.io.Writer;\r
+\r
+import com.att.xgen.XGen;;\r
+\r
+public class XMLGen extends XGen<XMLGen> {\r
+       private final String XML_TAG; \r
+       \r
+       public XMLGen(Writer w) {\r
+               this(w,"UTF-8");\r
+       }\r
+       \r
+       public XMLGen(Writer w, String encoding) {\r
+               super(w);\r
+               XML_TAG="<?xml version=\"1.0\" encoding=\"" + encoding + "\" standalone=\"yes\"?>"; \r
+       }\r
+\r
+       public XMLGen xml() {\r
+               forward.println(XML_TAG);\r
+               return this;\r
+       }\r
+}\r