From bfc9888bc95e567d7c1a02306254099283827988 Mon Sep 17 00:00:00 2001 From: sg481n Date: Thu, 24 Aug 2017 00:58:40 -0400 Subject: Update project structure to org.onap.aaf Update package structure from com.att to org.onap.aaf and add distribution management and repositories. Issue-id: AAF-23 Change-Id: I1b2381a58b08d147a0dfffd086aabd37ecfc3090 Signed-off-by: sg481n --- env/pom.xml | 2 +- .../main/java/com/att/inno/env/APIException.java | 89 ---- .../java/com/att/inno/env/BaseDataFactory.java | 462 ------------------- env/src/main/java/com/att/inno/env/Creatable.java | 52 --- env/src/main/java/com/att/inno/env/Data.java | 113 ----- .../main/java/com/att/inno/env/DataFactory.java | 31 -- env/src/main/java/com/att/inno/env/Decryptor.java | 35 -- env/src/main/java/com/att/inno/env/Encryptor.java | 35 -- env/src/main/java/com/att/inno/env/Env.java | 136 ------ env/src/main/java/com/att/inno/env/EnvJAXB.java | 53 --- .../main/java/com/att/inno/env/EnvJAXBProps.java | 31 -- env/src/main/java/com/att/inno/env/EnvProps.java | 81 ---- env/src/main/java/com/att/inno/env/EnvStore.java | 28 -- .../main/java/com/att/inno/env/IOObjectifier.java | 55 --- .../main/java/com/att/inno/env/IOStringifier.java | 75 ---- env/src/main/java/com/att/inno/env/LifeCycle.java | 123 ------ env/src/main/java/com/att/inno/env/LogTarget.java | 142 ------ .../main/java/com/att/inno/env/Objectifier.java | 58 --- env/src/main/java/com/att/inno/env/Slot.java | 103 ----- env/src/main/java/com/att/inno/env/StaticSlot.java | 86 ---- env/src/main/java/com/att/inno/env/Store.java | 109 ----- env/src/main/java/com/att/inno/env/StoreImpl.java | 237 ---------- .../main/java/com/att/inno/env/Stringifier.java | 46 -- env/src/main/java/com/att/inno/env/TimeTaken.java | 116 ----- env/src/main/java/com/att/inno/env/Trans.java | 74 ---- .../main/java/com/att/inno/env/TransCreate.java | 27 -- env/src/main/java/com/att/inno/env/TransJAXB.java | 27 -- env/src/main/java/com/att/inno/env/TransStore.java | 58 --- .../main/java/com/att/inno/env/impl/AbsTrans.java | 215 --------- .../java/com/att/inno/env/impl/AbsTransJAXB.java | 58 --- .../main/java/com/att/inno/env/impl/BasicEnv.java | 336 -------------- .../java/com/att/inno/env/impl/BasicTrans.java | 82 ---- .../java/com/att/inno/env/impl/EnvFactory.java | 67 --- .../com/att/inno/env/impl/JavaUtilLogTarget.java | 90 ---- .../java/com/att/inno/env/impl/Log4JLogTarget.java | 110 ----- .../java/com/att/inno/env/impl/NullLifeCycle.java | 59 --- .../main/java/com/att/inno/env/jaxb/JAXBDF.java | 310 ------------- .../main/java/com/att/inno/env/jaxb/JAXBData.java | 321 -------------- .../com/att/inno/env/jaxb/JAXBObjectifier.java | 136 ------ .../com/att/inno/env/jaxb/JAXBStringifier.java | 138 ------ .../main/java/com/att/inno/env/jaxb/JAXBmar.java | 253 ----------- .../main/java/com/att/inno/env/jaxb/JAXBumar.java | 243 ---------- .../java/com/att/inno/env/old/IOObjectifier.java | 58 --- .../java/com/att/inno/env/old/IOStringifier.java | 78 ---- .../java/com/att/inno/env/old/Objectifier.java | 61 --- .../java/com/att/inno/env/old/OldDataFactory.java | 48 -- .../java/com/att/inno/env/old/Stringifier.java | 49 --- .../main/java/com/att/inno/env/util/Chrono.java | 307 ------------- .../com/att/inno/env/util/DoubleOutputStream.java | 98 ----- .../com/att/inno/env/util/IndentPrintWriter.java | 114 ----- env/src/main/java/com/att/inno/env/util/Pool.java | 395 ----------------- .../att/inno/env/util/RefreshableThreadObject.java | 125 ------ env/src/main/java/com/att/inno/env/util/Split.java | 90 ---- .../inno/env/util/StringBuilderOutputStream.java | 179 -------- .../com/att/inno/env/util/StringBuilderWriter.java | 173 -------- .../java/org/onap/aaf/inno/env/APIException.java | 89 ++++ .../org/onap/aaf/inno/env/BaseDataFactory.java | 461 +++++++++++++++++++ .../main/java/org/onap/aaf/inno/env/Creatable.java | 52 +++ env/src/main/java/org/onap/aaf/inno/env/Data.java | 113 +++++ .../java/org/onap/aaf/inno/env/DataFactory.java | 31 ++ .../main/java/org/onap/aaf/inno/env/Decryptor.java | 35 ++ .../main/java/org/onap/aaf/inno/env/Encryptor.java | 35 ++ env/src/main/java/org/onap/aaf/inno/env/Env.java | 136 ++++++ .../main/java/org/onap/aaf/inno/env/EnvJAXB.java | 53 +++ .../java/org/onap/aaf/inno/env/EnvJAXBProps.java | 31 ++ .../main/java/org/onap/aaf/inno/env/EnvProps.java | 81 ++++ .../main/java/org/onap/aaf/inno/env/EnvStore.java | 28 ++ .../java/org/onap/aaf/inno/env/IOObjectifier.java | 55 +++ .../java/org/onap/aaf/inno/env/IOStringifier.java | 75 ++++ .../main/java/org/onap/aaf/inno/env/LifeCycle.java | 123 ++++++ .../main/java/org/onap/aaf/inno/env/LogTarget.java | 142 ++++++ .../java/org/onap/aaf/inno/env/Objectifier.java | 58 +++ env/src/main/java/org/onap/aaf/inno/env/Slot.java | 103 +++++ .../java/org/onap/aaf/inno/env/StaticSlot.java | 86 ++++ env/src/main/java/org/onap/aaf/inno/env/Store.java | 109 +++++ .../main/java/org/onap/aaf/inno/env/StoreImpl.java | 238 ++++++++++ .../java/org/onap/aaf/inno/env/Stringifier.java | 46 ++ .../main/java/org/onap/aaf/inno/env/TimeTaken.java | 116 +++++ env/src/main/java/org/onap/aaf/inno/env/Trans.java | 74 ++++ .../java/org/onap/aaf/inno/env/TransCreate.java | 27 ++ .../main/java/org/onap/aaf/inno/env/TransJAXB.java | 27 ++ .../java/org/onap/aaf/inno/env/TransStore.java | 58 +++ .../java/org/onap/aaf/inno/env/impl/AbsTrans.java | 215 +++++++++ .../org/onap/aaf/inno/env/impl/AbsTransJAXB.java | 58 +++ .../java/org/onap/aaf/inno/env/impl/BasicEnv.java | 336 ++++++++++++++ .../org/onap/aaf/inno/env/impl/BasicTrans.java | 82 ++++ .../org/onap/aaf/inno/env/impl/EnvFactory.java | 67 +++ .../onap/aaf/inno/env/impl/JavaUtilLogTarget.java | 90 ++++ .../org/onap/aaf/inno/env/impl/Log4JLogTarget.java | 109 +++++ .../org/onap/aaf/inno/env/impl/NullLifeCycle.java | 59 +++ .../java/org/onap/aaf/inno/env/jaxb/JAXBDF.java | 310 +++++++++++++ .../java/org/onap/aaf/inno/env/jaxb/JAXBData.java | 321 ++++++++++++++ .../onap/aaf/inno/env/jaxb/JAXBObjectifier.java | 136 ++++++ .../onap/aaf/inno/env/jaxb/JAXBStringifier.java | 138 ++++++ .../java/org/onap/aaf/inno/env/jaxb/JAXBmar.java | 253 +++++++++++ .../java/org/onap/aaf/inno/env/jaxb/JAXBumar.java | 242 ++++++++++ .../org/onap/aaf/inno/env/old/IOObjectifier.java | 58 +++ .../org/onap/aaf/inno/env/old/IOStringifier.java | 78 ++++ .../org/onap/aaf/inno/env/old/Objectifier.java | 61 +++ .../org/onap/aaf/inno/env/old/OldDataFactory.java | 48 ++ .../org/onap/aaf/inno/env/old/Stringifier.java | 49 +++ .../java/org/onap/aaf/inno/env/util/Chrono.java | 307 +++++++++++++ .../onap/aaf/inno/env/util/DoubleOutputStream.java | 98 +++++ .../onap/aaf/inno/env/util/IndentPrintWriter.java | 114 +++++ .../main/java/org/onap/aaf/inno/env/util/Pool.java | 395 +++++++++++++++++ .../aaf/inno/env/util/RefreshableThreadObject.java | 125 ++++++ .../java/org/onap/aaf/inno/env/util/Split.java | 90 ++++ .../inno/env/util/StringBuilderOutputStream.java | 179 ++++++++ .../aaf/inno/env/util/StringBuilderWriter.java | 173 ++++++++ log4j/pom.xml | 4 +- .../java/com/att/inno/env/log4j/LogFileNamer.java | 82 ---- .../java/com/att/inno/env/log4j/PIDAccess.java | 31 -- .../org/onap/aaf/inno/env/log4j/LogFileNamer.java | 82 ++++ .../org/onap/aaf/inno/env/log4j/PIDAccess.java | 31 ++ .../test/java/com/att/inno/env/log4j/LogTest.java | 44 -- .../java/org/onap/aaf/inno/env/log4j/LogTest.java | 46 ++ pom.xml | 49 ++- rosetta/pom.xml | 25 +- rosetta/src/main/java/com/att/rosetta/InJson.java | 155 ------- rosetta/src/main/java/com/att/rosetta/InXML.java | 487 --------------------- rosetta/src/main/java/com/att/rosetta/JaxEval.java | 27 -- rosetta/src/main/java/com/att/rosetta/JaxInfo.java | 249 ----------- rosetta/src/main/java/com/att/rosetta/JaxSet.java | 91 ---- rosetta/src/main/java/com/att/rosetta/Ladder.java | 113 ----- rosetta/src/main/java/com/att/rosetta/Marshal.java | 82 ---- rosetta/src/main/java/com/att/rosetta/Nulls.java | 67 --- rosetta/src/main/java/com/att/rosetta/Out.java | 44 -- rosetta/src/main/java/com/att/rosetta/OutJax.java | 53 --- rosetta/src/main/java/com/att/rosetta/OutJson.java | 233 ---------- rosetta/src/main/java/com/att/rosetta/OutRaw.java | 47 -- rosetta/src/main/java/com/att/rosetta/OutXML.java | 226 ---------- rosetta/src/main/java/com/att/rosetta/Parse.java | 46 -- .../main/java/com/att/rosetta/ParseException.java | 43 -- rosetta/src/main/java/com/att/rosetta/Parsed.java | 90 ---- rosetta/src/main/java/com/att/rosetta/Prop.java | 44 -- rosetta/src/main/java/com/att/rosetta/Saved.java | 194 -------- .../src/main/java/com/att/rosetta/XmlEscape.java | 372 ---------------- .../main/java/com/att/rosetta/env/RosettaDF.java | 266 ----------- .../main/java/com/att/rosetta/env/RosettaData.java | 313 ------------- .../main/java/com/att/rosetta/env/RosettaEnv.java | 89 ---- .../java/com/att/rosetta/marshal/DataWriter.java | 139 ------ .../java/com/att/rosetta/marshal/DocMarshal.java | 83 ---- .../java/com/att/rosetta/marshal/FieldArray.java | 93 ---- .../java/com/att/rosetta/marshal/FieldBlob.java | 39 -- .../java/com/att/rosetta/marshal/FieldDate.java | 38 -- .../com/att/rosetta/marshal/FieldDateTime.java | 38 -- .../com/att/rosetta/marshal/FieldHexBinary.java | 36 -- .../java/com/att/rosetta/marshal/FieldMarshal.java | 60 --- .../java/com/att/rosetta/marshal/FieldNumeric.java | 37 -- .../java/com/att/rosetta/marshal/FieldString.java | 37 -- .../java/com/att/rosetta/marshal/ListIterator.java | 59 --- .../java/com/att/rosetta/marshal/ObjArray.java | 91 ---- .../java/com/att/rosetta/marshal/ObjMarshal.java | 128 ------ .../src/main/java/org/onap/aaf/rosetta/InJson.java | 155 +++++++ .../src/main/java/org/onap/aaf/rosetta/InXML.java | 487 +++++++++++++++++++++ .../main/java/org/onap/aaf/rosetta/JaxEval.java | 27 ++ .../main/java/org/onap/aaf/rosetta/JaxInfo.java | 249 +++++++++++ .../src/main/java/org/onap/aaf/rosetta/JaxSet.java | 91 ++++ .../src/main/java/org/onap/aaf/rosetta/Ladder.java | 113 +++++ .../main/java/org/onap/aaf/rosetta/Marshal.java | 82 ++++ .../src/main/java/org/onap/aaf/rosetta/Nulls.java | 67 +++ .../src/main/java/org/onap/aaf/rosetta/Out.java | 44 ++ .../src/main/java/org/onap/aaf/rosetta/OutJax.java | 53 +++ .../main/java/org/onap/aaf/rosetta/OutJson.java | 233 ++++++++++ .../src/main/java/org/onap/aaf/rosetta/OutRaw.java | 47 ++ .../src/main/java/org/onap/aaf/rosetta/OutXML.java | 226 ++++++++++ .../src/main/java/org/onap/aaf/rosetta/Parse.java | 46 ++ .../java/org/onap/aaf/rosetta/ParseException.java | 43 ++ .../src/main/java/org/onap/aaf/rosetta/Parsed.java | 90 ++++ .../src/main/java/org/onap/aaf/rosetta/Prop.java | 44 ++ .../src/main/java/org/onap/aaf/rosetta/Saved.java | 194 ++++++++ .../main/java/org/onap/aaf/rosetta/XmlEscape.java | 372 ++++++++++++++++ .../java/org/onap/aaf/rosetta/env/RosettaDF.java | 266 +++++++++++ .../java/org/onap/aaf/rosetta/env/RosettaData.java | 313 +++++++++++++ .../java/org/onap/aaf/rosetta/env/RosettaEnv.java | 89 ++++ .../org/onap/aaf/rosetta/marshal/DataWriter.java | 139 ++++++ .../org/onap/aaf/rosetta/marshal/DocMarshal.java | 83 ++++ .../org/onap/aaf/rosetta/marshal/FieldArray.java | 93 ++++ .../org/onap/aaf/rosetta/marshal/FieldBlob.java | 39 ++ .../org/onap/aaf/rosetta/marshal/FieldDate.java | 38 ++ .../onap/aaf/rosetta/marshal/FieldDateTime.java | 38 ++ .../onap/aaf/rosetta/marshal/FieldHexBinary.java | 36 ++ .../org/onap/aaf/rosetta/marshal/FieldMarshal.java | 60 +++ .../org/onap/aaf/rosetta/marshal/FieldNumeric.java | 37 ++ .../org/onap/aaf/rosetta/marshal/FieldString.java | 37 ++ .../org/onap/aaf/rosetta/marshal/ListIterator.java | 59 +++ .../org/onap/aaf/rosetta/marshal/ObjArray.java | 91 ++++ .../org/onap/aaf/rosetta/marshal/ObjMarshal.java | 128 ++++++ .../src/test/java/com/data/test/JU_FromJSON.java | 27 +- .../src/test/java/com/data/test/JU_FromXML.java | 29 +- rosetta/src/test/java/com/data/test/JU_JSON.java | 13 +- rosetta/src/test/java/com/data/test/JU_Ladder.java | 4 +- rosetta/src/test/java/com/data/test/JU_Nulls.java | 9 +- .../src/test/java/com/data/test/JU_RosettaDF.java | 21 +- rosetta/src/test/java/com/data/test/JU_Saved.java | 19 +- .../src/test/java/com/data/test/JU_Stream2Obj.java | 27 +- rosetta/src/test/java/com/data/test/JU_Struct.java | 3 +- rosetta/src/test/java/com/data/test/JU_Types.java | 32 +- rosetta/src/test/java/com/data/test/OutDump.java | 10 +- rosetta/src/test/java/com/data/test/Report.java | 4 +- .../test/java/com/data/test/obj/MultiMarshal.java | 4 +- .../test/java/com/data/test/obj/SingleMarshal.java | 16 +- xgen/pom.xml | 4 +- xgen/src/main/java/com/att/xgen/Back.java | 35 -- xgen/src/main/java/com/att/xgen/Cache.java | 38 -- xgen/src/main/java/com/att/xgen/CacheGen.java | 132 ------ xgen/src/main/java/com/att/xgen/Code.java | 31 -- xgen/src/main/java/com/att/xgen/DynamicCode.java | 44 -- xgen/src/main/java/com/att/xgen/Mark.java | 41 -- xgen/src/main/java/com/att/xgen/Section.java | 62 --- xgen/src/main/java/com/att/xgen/XGen.java | 297 ------------- xgen/src/main/java/com/att/xgen/XGenBuff.java | 87 ---- xgen/src/main/java/com/att/xgen/html/HTML4Gen.java | 144 ------ xgen/src/main/java/com/att/xgen/html/HTML5Gen.java | 156 ------- .../main/java/com/att/xgen/html/HTMLCacheGen.java | 60 --- xgen/src/main/java/com/att/xgen/html/HTMLGen.java | 241 ---------- xgen/src/main/java/com/att/xgen/html/Imports.java | 99 ----- xgen/src/main/java/com/att/xgen/html/JSGen.java | 205 --------- xgen/src/main/java/com/att/xgen/html/State.java | 28 -- xgen/src/main/java/com/att/xgen/html/Thematic.java | 28 -- .../main/java/com/att/xgen/xml/XMLCacheGen.java | 46 -- xgen/src/main/java/com/att/xgen/xml/XMLGen.java | 45 -- xgen/src/main/java/org/onap/aaf/xgen/Back.java | 35 ++ xgen/src/main/java/org/onap/aaf/xgen/Cache.java | 38 ++ xgen/src/main/java/org/onap/aaf/xgen/CacheGen.java | 132 ++++++ xgen/src/main/java/org/onap/aaf/xgen/Code.java | 31 ++ .../main/java/org/onap/aaf/xgen/DynamicCode.java | 44 ++ xgen/src/main/java/org/onap/aaf/xgen/Mark.java | 41 ++ xgen/src/main/java/org/onap/aaf/xgen/Section.java | 62 +++ xgen/src/main/java/org/onap/aaf/xgen/XGen.java | 297 +++++++++++++ xgen/src/main/java/org/onap/aaf/xgen/XGenBuff.java | 87 ++++ .../main/java/org/onap/aaf/xgen/html/HTML4Gen.java | 144 ++++++ .../main/java/org/onap/aaf/xgen/html/HTML5Gen.java | 156 +++++++ .../java/org/onap/aaf/xgen/html/HTMLCacheGen.java | 60 +++ .../main/java/org/onap/aaf/xgen/html/HTMLGen.java | 241 ++++++++++ .../main/java/org/onap/aaf/xgen/html/Imports.java | 99 +++++ .../main/java/org/onap/aaf/xgen/html/JSGen.java | 205 +++++++++ .../main/java/org/onap/aaf/xgen/html/State.java | 28 ++ .../main/java/org/onap/aaf/xgen/html/Thematic.java | 28 ++ .../java/org/onap/aaf/xgen/xml/XMLCacheGen.java | 46 ++ .../main/java/org/onap/aaf/xgen/xml/XMLGen.java | 45 ++ 241 files changed, 12999 insertions(+), 13023 deletions(-) delete mode 100644 env/src/main/java/com/att/inno/env/APIException.java delete mode 100644 env/src/main/java/com/att/inno/env/BaseDataFactory.java delete mode 100644 env/src/main/java/com/att/inno/env/Creatable.java delete mode 100644 env/src/main/java/com/att/inno/env/Data.java delete mode 100644 env/src/main/java/com/att/inno/env/DataFactory.java delete mode 100644 env/src/main/java/com/att/inno/env/Decryptor.java delete mode 100644 env/src/main/java/com/att/inno/env/Encryptor.java delete mode 100644 env/src/main/java/com/att/inno/env/Env.java delete mode 100644 env/src/main/java/com/att/inno/env/EnvJAXB.java delete mode 100644 env/src/main/java/com/att/inno/env/EnvJAXBProps.java delete mode 100644 env/src/main/java/com/att/inno/env/EnvProps.java delete mode 100644 env/src/main/java/com/att/inno/env/EnvStore.java delete mode 100644 env/src/main/java/com/att/inno/env/IOObjectifier.java delete mode 100644 env/src/main/java/com/att/inno/env/IOStringifier.java delete mode 100644 env/src/main/java/com/att/inno/env/LifeCycle.java delete mode 100644 env/src/main/java/com/att/inno/env/LogTarget.java delete mode 100644 env/src/main/java/com/att/inno/env/Objectifier.java delete mode 100644 env/src/main/java/com/att/inno/env/Slot.java delete mode 100644 env/src/main/java/com/att/inno/env/StaticSlot.java delete mode 100644 env/src/main/java/com/att/inno/env/Store.java delete mode 100644 env/src/main/java/com/att/inno/env/StoreImpl.java delete mode 100644 env/src/main/java/com/att/inno/env/Stringifier.java delete mode 100644 env/src/main/java/com/att/inno/env/TimeTaken.java delete mode 100644 env/src/main/java/com/att/inno/env/Trans.java delete mode 100644 env/src/main/java/com/att/inno/env/TransCreate.java delete mode 100644 env/src/main/java/com/att/inno/env/TransJAXB.java delete mode 100644 env/src/main/java/com/att/inno/env/TransStore.java delete mode 100644 env/src/main/java/com/att/inno/env/impl/AbsTrans.java delete mode 100644 env/src/main/java/com/att/inno/env/impl/AbsTransJAXB.java delete mode 100644 env/src/main/java/com/att/inno/env/impl/BasicEnv.java delete mode 100644 env/src/main/java/com/att/inno/env/impl/BasicTrans.java delete mode 100644 env/src/main/java/com/att/inno/env/impl/EnvFactory.java delete mode 100644 env/src/main/java/com/att/inno/env/impl/JavaUtilLogTarget.java delete mode 100644 env/src/main/java/com/att/inno/env/impl/Log4JLogTarget.java delete mode 100644 env/src/main/java/com/att/inno/env/impl/NullLifeCycle.java delete mode 100644 env/src/main/java/com/att/inno/env/jaxb/JAXBDF.java delete mode 100644 env/src/main/java/com/att/inno/env/jaxb/JAXBData.java delete mode 100644 env/src/main/java/com/att/inno/env/jaxb/JAXBObjectifier.java delete mode 100644 env/src/main/java/com/att/inno/env/jaxb/JAXBStringifier.java delete mode 100644 env/src/main/java/com/att/inno/env/jaxb/JAXBmar.java delete mode 100644 env/src/main/java/com/att/inno/env/jaxb/JAXBumar.java delete mode 100644 env/src/main/java/com/att/inno/env/old/IOObjectifier.java delete mode 100644 env/src/main/java/com/att/inno/env/old/IOStringifier.java delete mode 100644 env/src/main/java/com/att/inno/env/old/Objectifier.java delete mode 100644 env/src/main/java/com/att/inno/env/old/OldDataFactory.java delete mode 100644 env/src/main/java/com/att/inno/env/old/Stringifier.java delete mode 100644 env/src/main/java/com/att/inno/env/util/Chrono.java delete mode 100644 env/src/main/java/com/att/inno/env/util/DoubleOutputStream.java delete mode 100644 env/src/main/java/com/att/inno/env/util/IndentPrintWriter.java delete mode 100644 env/src/main/java/com/att/inno/env/util/Pool.java delete mode 100644 env/src/main/java/com/att/inno/env/util/RefreshableThreadObject.java delete mode 100644 env/src/main/java/com/att/inno/env/util/Split.java delete mode 100644 env/src/main/java/com/att/inno/env/util/StringBuilderOutputStream.java delete mode 100644 env/src/main/java/com/att/inno/env/util/StringBuilderWriter.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/APIException.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/BaseDataFactory.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/Creatable.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/Data.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/DataFactory.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/Decryptor.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/Encryptor.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/Env.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/EnvJAXB.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/EnvJAXBProps.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/EnvProps.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/EnvStore.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/IOObjectifier.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/IOStringifier.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/LifeCycle.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/LogTarget.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/Objectifier.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/Slot.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/StaticSlot.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/Store.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/StoreImpl.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/Stringifier.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/TimeTaken.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/Trans.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/TransCreate.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/TransJAXB.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/TransStore.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/impl/AbsTrans.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/impl/AbsTransJAXB.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/impl/BasicEnv.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/impl/BasicTrans.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/impl/EnvFactory.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/impl/JavaUtilLogTarget.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/impl/Log4JLogTarget.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/impl/NullLifeCycle.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBDF.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBData.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBObjectifier.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBStringifier.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBmar.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBumar.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/old/IOObjectifier.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/old/IOStringifier.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/old/Objectifier.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/old/OldDataFactory.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/old/Stringifier.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/util/Chrono.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/util/DoubleOutputStream.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/util/IndentPrintWriter.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/util/Pool.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/util/RefreshableThreadObject.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/util/Split.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/util/StringBuilderOutputStream.java create mode 100644 env/src/main/java/org/onap/aaf/inno/env/util/StringBuilderWriter.java delete mode 100644 log4j/src/main/java/com/att/inno/env/log4j/LogFileNamer.java delete mode 100644 log4j/src/main/java/com/att/inno/env/log4j/PIDAccess.java create mode 100644 log4j/src/main/java/org/onap/aaf/inno/env/log4j/LogFileNamer.java create mode 100644 log4j/src/main/java/org/onap/aaf/inno/env/log4j/PIDAccess.java delete mode 100644 log4j/src/test/java/com/att/inno/env/log4j/LogTest.java create mode 100644 log4j/src/test/java/org/onap/aaf/inno/env/log4j/LogTest.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/InJson.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/InXML.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/JaxEval.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/JaxInfo.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/JaxSet.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/Ladder.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/Marshal.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/Nulls.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/Out.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/OutJax.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/OutJson.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/OutRaw.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/OutXML.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/Parse.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/ParseException.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/Parsed.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/Prop.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/Saved.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/XmlEscape.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/env/RosettaDF.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/env/RosettaData.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/env/RosettaEnv.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/marshal/DataWriter.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/marshal/DocMarshal.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/marshal/FieldArray.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/marshal/FieldBlob.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/marshal/FieldDate.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/marshal/FieldDateTime.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/marshal/FieldHexBinary.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/marshal/FieldMarshal.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/marshal/FieldNumeric.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/marshal/FieldString.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/marshal/ListIterator.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/marshal/ObjArray.java delete mode 100644 rosetta/src/main/java/com/att/rosetta/marshal/ObjMarshal.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/InJson.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/InXML.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/JaxEval.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/JaxInfo.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/JaxSet.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/Ladder.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/Marshal.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/Nulls.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/Out.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/OutJax.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/OutJson.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/OutRaw.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/OutXML.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/Parse.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/ParseException.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/Parsed.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/Prop.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/Saved.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/XmlEscape.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/env/RosettaDF.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/env/RosettaData.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/env/RosettaEnv.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/marshal/DataWriter.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/marshal/DocMarshal.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldArray.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldBlob.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldDate.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldDateTime.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldHexBinary.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldMarshal.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldNumeric.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldString.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/marshal/ListIterator.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/marshal/ObjArray.java create mode 100644 rosetta/src/main/java/org/onap/aaf/rosetta/marshal/ObjMarshal.java delete mode 100644 xgen/src/main/java/com/att/xgen/Back.java delete mode 100644 xgen/src/main/java/com/att/xgen/Cache.java delete mode 100644 xgen/src/main/java/com/att/xgen/CacheGen.java delete mode 100644 xgen/src/main/java/com/att/xgen/Code.java delete mode 100644 xgen/src/main/java/com/att/xgen/DynamicCode.java delete mode 100644 xgen/src/main/java/com/att/xgen/Mark.java delete mode 100644 xgen/src/main/java/com/att/xgen/Section.java delete mode 100644 xgen/src/main/java/com/att/xgen/XGen.java delete mode 100644 xgen/src/main/java/com/att/xgen/XGenBuff.java delete mode 100644 xgen/src/main/java/com/att/xgen/html/HTML4Gen.java delete mode 100644 xgen/src/main/java/com/att/xgen/html/HTML5Gen.java delete mode 100644 xgen/src/main/java/com/att/xgen/html/HTMLCacheGen.java delete mode 100644 xgen/src/main/java/com/att/xgen/html/HTMLGen.java delete mode 100644 xgen/src/main/java/com/att/xgen/html/Imports.java delete mode 100644 xgen/src/main/java/com/att/xgen/html/JSGen.java delete mode 100644 xgen/src/main/java/com/att/xgen/html/State.java delete mode 100644 xgen/src/main/java/com/att/xgen/html/Thematic.java delete mode 100644 xgen/src/main/java/com/att/xgen/xml/XMLCacheGen.java delete mode 100644 xgen/src/main/java/com/att/xgen/xml/XMLGen.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/Back.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/Cache.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/CacheGen.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/Code.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/DynamicCode.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/Mark.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/Section.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/XGen.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/XGenBuff.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/html/HTML4Gen.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/html/HTML5Gen.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/html/HTMLCacheGen.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/html/HTMLGen.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/html/Imports.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/html/JSGen.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/html/State.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/html/Thematic.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/xml/XMLCacheGen.java create mode 100644 xgen/src/main/java/org/onap/aaf/xgen/xml/XMLGen.java diff --git a/env/pom.xml b/env/pom.xml index 5f501a8..24bdaff 100644 --- a/env/pom.xml +++ b/env/pom.xml @@ -23,7 +23,7 @@ - com.att.inno + org.onap.aaf.inno parent 1.0.0-SNAPSHOT .. diff --git a/env/src/main/java/com/att/inno/env/APIException.java b/env/src/main/java/com/att/inno/env/APIException.java deleted file mode 100644 index 677513b..0000000 --- a/env/src/main/java/com/att/inno/env/APIException.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - - -/** - * An Exception with the ability to hold a payload.

- * - * This is important, because sometimes, the output of a Framework - * may be a descriptive object which doesn't inherit from Throwable - * and thus cannot be attached in "initCause".

- * - * Examples may be a SOAP Fault. - * - * - */ -public class APIException extends Exception { - - private Object payload = null; - - /** - * @param t - */ - public APIException(Throwable t) { - super(t); - } - - /** - * @param string - */ - public APIException(String string) { - super(string); - } - - /** - * @param errorMessage - * @param t - */ - public APIException(String errorMessage, Throwable t) { - super(errorMessage,t); - } - - /** - * Return payload, or null if none was set. Type is up to the calling - * System. - * - * @return Object - */ - public Object getPayload() { - return payload; - } - - /** - * Set a specific payload into this Exception, which doesn't necessarily - * inherit from Throwable. - * - * @param payload - * @return APIException - */ - public APIException setPayload(Object payload) { - this.payload = payload; - return this; - } - - /** - * Java expected serial ID - */ - private static final long serialVersionUID = 3505343458251445169L; -} diff --git a/env/src/main/java/com/att/inno/env/BaseDataFactory.java b/env/src/main/java/com/att/inno/env/BaseDataFactory.java deleted file mode 100644 index b04f115..0000000 --- a/env/src/main/java/com/att/inno/env/BaseDataFactory.java +++ /dev/null @@ -1,462 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; - -import javax.xml.XMLConstants; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlSchema; -import javax.xml.namespace.QName; -import javax.xml.transform.Source; -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; - -import org.xml.sax.SAXException; - -import com.att.inno.env.impl.EnvFactory; - - - -/** - * DataFactory Constructor will create the Stringifiers and Objectifiers necessary - * by Type and store the Class of the Type for quick creation of Data Objects - * with reused (and thread safe) components - * s - * Native Types are included. - * Those types covered by Env Implementation are covered dynamically. - * Types outside of Env mechanism can be added with "add" function - * - * - * @param - */ -public class BaseDataFactory { - - /** - * Generate a Schema Object for use in validation based on FileNames. - * - * WARNING: The java.xml.binding code requires YOU to figure out what order the - * files go in. If there is an import from A in B, then you must list A first. - * - * @param err - * @param filenames - * @return - * @throws APIException - */ - public static Schema genSchema(Store env, String ... filenames) throws APIException { - String schemaDir = env.get( - env.staticSlot(EnvFactory.SCHEMA_DIR), - EnvFactory.DEFAULT_SCHEMA_DIR); - File dir = new File(schemaDir); - if(!dir.exists())throw new APIException("Schema Directory " + schemaDir + " does not exist. You can set this with " + EnvFactory.SCHEMA_DIR + " property"); - FileInputStream[] fis = new FileInputStream[filenames.length]; - Source[] sources = new Source[filenames.length]; - File f; - for(int i=0; i clss) throws APIException { - // Obtain the Necessary info for QName from Requirement - XmlRootElement xre = clss.getAnnotation(XmlRootElement.class); - if(xre==null)throw new APIException(clss.getName() + " does not have an XmlRootElement annotation"); - Package pkg = clss.getPackage(); - XmlSchema xs = pkg.getAnnotation(XmlSchema.class); - if(xs==null) throw new APIException(clss.getName() + " package-info does not have an XmlSchema annotation"); - return new QName(xs.namespace(),xre.name()); - } - - ///////////////////////////////////////////// - // Native Type Converters - ///////////////////////////////////////////// -// /** -// * StringStringifier -// * -// * Support the Native Type String.. just return it back -// * -// * -// */ -// public static class StringStringifier extends NullLifeCycle implements Stringifier { -// /* (non-Javadoc) -// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) -// */ -// public String stringify(Env env, String input) throws APIException { -// return input; -// } -// }; -// -// /** -// * StringObjectifier -// * -// * Support the Native Type String.. just return it back -// * -// * -// */ -// public static class StringObjectifier extends NullLifeCycle implements Objectifier { -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) -// */ -// public String objectify(Env env, String input) throws APIException { -// return input; -// } -// -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#newObject() -// */ -// public String newInstance() throws APIException { -// return ""; -// } -// }; -// -// /** -// * LongStringifier -// * -// * Support the Native Type Long.. use Long parse functions -// * -// * -// */ -// public static class LongStringifier extends NullLifeCycle implements Stringifier { -// public String stringify(Env env, Long input) throws APIException { -// return input.toString(); -// } -// } -// -// /** -// * LongObjectifier -// * -// * Support the Native Type Long.. use Long parse functions -// * -// * -// */ -// public static class LongObjectifier extends NullLifeCycle implements Objectifier { -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) -// */ -// public Long objectify(Env env, String input) throws APIException { -// try { -// return new Long(input); -// } catch (Exception e) { -// APIException ae = new APIException("Cannot create a \"Long\" from [" + input + ']'); -// ae.initCause(e); -// throw ae; -// } -// } -// -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#newObject() -// */ -// public Long newInstance() throws APIException { -// return 0L; -// } -// } -// -// /** -// * IntegerStringifier -// * -// * Support the Native Integer.. use Integer parse functions -// * -// * -// */ -// public static class IntegerStringifier extends NullLifeCycle implements Stringifier { -// /* (non-Javadoc) -// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) -// */ -// public String stringify(Env env, Integer input) throws APIException { -// return input.toString(); -// } -// } -// -// /** -// * IntegerObjectifier -// * -// * Support the Native Integer.. use Integer parse functions -// * -// * -// */ -// public static class IntegerObjectifier extends NullLifeCycle implements Objectifier { -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) -// */ -// public Integer objectify(Env env, String input) throws APIException { -// try { -// return new Integer(input); -// } catch (Exception e) { -// APIException ae = new APIException("Cannot create a \"Integer\" from [" + input + ']'); -// ae.initCause(e); -// throw ae; -// } -// } -// -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#newObject() -// */ -// public Integer newInstance() throws APIException { -// return 0; -// } -// } -// -// /** -// * ShortStringifier -// * -// * Support the Native Short.. use Short parse functions -// * -// * -// */ -// public static class ShortStringifier extends NullLifeCycle implements Stringifier { -// public String stringify(Env env, Short input) throws APIException { -// return input.toString(); -// } -// } -// -// /** -// * ShortObjectifier -// * -// * Support the Native Short.. use Short parse functions -// * -// * -// */ -// public static class ShortObjectifier extends NullLifeCycle implements Objectifier { -// public Short objectify(Env env, String input) throws APIException { -// try { -// return new Short(input); -// } catch (Exception e) { -// APIException ae = new APIException("Cannot create a \"Short\" from [" + input + ']'); -// ae.initCause(e); -// throw ae; -// } -// } -// -// public Short newInstance() throws APIException { -// return 0; -// } -// } -// -// /** -// * ByteStringifier -// * -// * Support the Native Byte.. use Byte parse functions -// * -// * -// */ -// public static class ByteStringifier extends NullLifeCycle implements Stringifier { -// /* (non-Javadoc) -// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) -// */ -// public String stringify(Env env, Byte input) throws APIException { -// return input.toString(); -// } -// } -// -// /** -// * ByteObjectifier -// * -// * Support the Native Byte.. use Byte parse functions -// * -// * -// */ -// public static class ByteObjectifier extends NullLifeCycle implements Objectifier { -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) -// */ -// public Byte objectify(Env env, String input) throws APIException { -// try { -// return new Byte(input); -// } catch (Exception e) { -// APIException ae = new APIException("Cannot create a \"Byte\" from [" + input + ']'); -// ae.initCause(e); -// throw ae; -// } -// } -// -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#newObject() -// */ -// public Byte newInstance() throws APIException { -// return 0; -// } -// } -// -// /** -// * CharacterStringifier -// * -// * Support the Native Character.. use Character parse functions -// * -// * -// */ -// public static class CharacterStringifier extends NullLifeCycle implements Stringifier { -// /* (non-Javadoc) -// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) -// */ -// public String stringify(Env env, Character input) throws APIException { -// return input.toString(); -// } -// } -// -// /** -// * CharacterObjectifier -// * -// * Support the Native Character.. use Character parse functions -// * -// * -// */ -// public static class CharacterObjectifier extends NullLifeCycle implements Objectifier { -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) -// */ -// public Character objectify(Env env, String input) throws APIException { -// int length = input.length(); -// if(length<1 || length>1) { -// throw new APIException("String [" + input + "] does not represent a single Character"); -// } -// return input.charAt(0); -// } -// -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#newObject() -// */ -// public Character newInstance() throws APIException { -// return 0; -// } -// } -// -// /** -// * FloatStringifier -// * -// * Support the Native Float.. use Float parse functions -// * -// * -// */ -// public static class FloatStringifier extends NullLifeCycle implements Stringifier { -// /* (non-Javadoc) -// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) -// */ -// public String stringify(Env env, Float input) throws APIException { -// return input.toString(); -// } -// } -// -// /** -// * FloatObjectifier -// * -// * Support the Native Float.. use Float parse functions -// * -// * -// */ -// public static class FloatObjectifier extends NullLifeCycle implements Objectifier { -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) -// */ -// public Float objectify(Env env, String input) throws APIException { -// try { -// return new Float(input); -// } catch (Exception e) { -// APIException ae = new APIException("Cannot create a \"Float\" from [" + input + ']'); -// ae.initCause(e); -// throw ae; -// } -// } -// -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#newObject() -// */ -// public Float newInstance() throws APIException { -// return 0.0f; -// } -// } -// -// /** -// * DoubleStringifier -// * -// * Support the Native Double.. use Double parse functions -// * -// */ -// public static class DoubleStringifier extends NullLifeCycle implements Stringifier { -// /* (non-Javadoc) -// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) -// */ -// public String stringify(Env env, Double input) throws APIException { -// return input.toString(); -// } -// } -// -// /** -// * DoubleObjectifier -// * -// * Support the Native Double.. use Double parse functions -// * -// * -// */ -// public static class DoubleObjectifier extends NullLifeCycle implements Objectifier { -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) -// */ -// public Double objectify(Env env, String input) throws APIException { -// try { -// return new Double(input); -// } catch (Exception e) { -// APIException ae = new APIException("Cannot create a \"Double\" from [" + input + ']'); -// ae.initCause(e); -// throw ae; -// } -// } -// -// /* (non-Javadoc) -// * @see com.att.env.Objectifier#newObject() -// */ -// public Double newInstance() throws APIException { -// return 0.0; -// } -// } - -} diff --git a/env/src/main/java/com/att/inno/env/Creatable.java b/env/src/main/java/com/att/inno/env/Creatable.java deleted file mode 100644 index e7d7907..0000000 --- a/env/src/main/java/com/att/inno/env/Creatable.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - - -/** - *

Creatable

- * **Must implement constructor T(ENV env, long currentTimeMillis);**

- * - * This interface exists to cover basic LifeCycle semantics so that Objects - * can be created dynamically and managed at a basic level (destroy(env)). - * - * - * @param - */ -public interface Creatable { - /** - * Return the timestamp (Unix long) when this object was created.

- * This can be used to see if the object is out of date in certain - * circumstances, or perhaps has already been notified in others. - * - * @return long - */ - public abstract long created(); - - /** - * Allow LifeCycle aware process to signal this element as destroyed. - * - * @param env - */ - public abstract void destroy(Env env); -} diff --git a/env/src/main/java/com/att/inno/env/Data.java b/env/src/main/java/com/att/inno/env/Data.java deleted file mode 100644 index f52eec3..0000000 --- a/env/src/main/java/com/att/inno/env/Data.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.Writer; -/** - *

Data

- * Data facilitates lazy marshaling of data with a pre-determined - * marshaling mechanism.

- * - * It stores either Object (defined by Generic {@literal }) or String.

- * - * On asking for Object of type {@literal }, it will respond with the object - * if it exists, or unmarshal the string and pass the result back.

- * - * On asking for String, it will respond with the String - * if it exists, or marshal the String and pass the result back.

- * - * the "options" available on several functions control the output of this particular call. When - * blank, they will default to the DataFactory defaults. When present, they override this - * particular call. - * The available options are "pretty" (for XML and JSON) and "fragment" (XML only concept), which drops - * the "" header so you can create larger XML documents from the output. - * - * - * @param - */ -public interface Data { - static enum TYPE {XML,JSON,JAXB,RAW,DEFAULT}; - // can & with 0xFFFF; -// public static final int XML = 0x1; -// public static final int JSON = 0x2; -// public static final int JAXB = 0x4; -// public static final int RAW = 0x1000; - - // can & with 0xF00000; - public static final int PRETTY = 0x100000; - public static final int FRAGMENT = 0x200000; - - /** - * Respond with the String if it exists, or marshal the String and pass the result back. - * - * However, use the Env the Data Object was created with. - * - * @return String - * @throws APIException - */ - public String asString() throws APIException; - - /** - * Respond with the Object of type {@literal } if it exists, or unmarshal from String - * and pass the result back.

- * - * However, use the Env the Data Object was created with. - * - * @return T - * @throws APIException - */ - public T asObject() throws APIException; - - /** - * Set a particular option on an existing Out - * - * if int is negative, it should remove the option - * @param option - */ - public Data option(int option); - - public Data to(OutputStream os) throws APIException, IOException; - public Data to(Writer writer) throws APIException, IOException; - - public Data load(T t) throws APIException; - public Data load(String str) throws APIException; - public Data load(InputStream is) throws APIException; - public Data load(Reader rdr) throws APIException; - - public Data in(TYPE type); - public Data out(TYPE type); - /** - * Return the Class Type supported by this DataObject - * - * @return {@literal Class} - */ - public Class getTypeClass(); - - public void direct(InputStream input, OutputStream output) throws APIException, IOException; - - -} diff --git a/env/src/main/java/com/att/inno/env/DataFactory.java b/env/src/main/java/com/att/inno/env/DataFactory.java deleted file mode 100644 index 5243ec9..0000000 --- a/env/src/main/java/com/att/inno/env/DataFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - - -public interface DataFactory { - public abstract Data newData(); - public abstract Data newData(Env trans); // and Env or Trans object - public abstract Class getTypeClass(); -} - diff --git a/env/src/main/java/com/att/inno/env/Decryptor.java b/env/src/main/java/com/att/inno/env/Decryptor.java deleted file mode 100644 index 13e0270..0000000 --- a/env/src/main/java/com/att/inno/env/Decryptor.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - - -public interface Decryptor { - public String decrypt(String tag); - - public static final Decryptor NULL = new Decryptor() { - @Override - public String decrypt(String tag) { - return tag; - } - }; -} diff --git a/env/src/main/java/com/att/inno/env/Encryptor.java b/env/src/main/java/com/att/inno/env/Encryptor.java deleted file mode 100644 index 8f3877b..0000000 --- a/env/src/main/java/com/att/inno/env/Encryptor.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - - -public interface Encryptor { - public String encrypt(String data); - - public static final Encryptor NULL = new Encryptor() { - @Override - public String encrypt(String data) { - return data; - } - }; -} diff --git a/env/src/main/java/com/att/inno/env/Env.java b/env/src/main/java/com/att/inno/env/Env.java deleted file mode 100644 index aa71709..0000000 --- a/env/src/main/java/com/att/inno/env/Env.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - - -/** - *

Env

- * Env is the basic representation of what can be obtained from the - * Environment. Environments also need the ability to Log and Track Time, so - * to keep the interfaces clean, Env Interface inherits from Trans. This does NOT - * mean that all Environments are Transactions... It only means Environments need - * to Log and Track Times. - * .

- * - * Using this abstraction, Components can be built on a modular basis, - * and still have the essentials of functioning within the service mechanism.

- * - * Thus, for instance, an Module could be made to work in two separate - * service types, with substantial differences in choices of logging, or auditing, - * and still have reasonably deep insight, such as the exact time a - * remote service was invoked.

- * - * There is a bit of an assumption corresponding to the reality of the 2000s that - * XML plays a part in most service work. - * - * - */ -public interface Env { - /** - * Very Severe Error may cause program to abort - */ - public LogTarget fatal(); - - /** - * Severe Error, but program might continue running - */ - public LogTarget error(); - - /** - * Required Audit statements - * @return - */ - public LogTarget audit(); - - /** - * Initialization steps... Allows a Logger to separate startup info - * @return - */ - public LogTarget init(); - - /** - * Potentially harmful situations - * @return - */ - public LogTarget warn(); - - /** - * Course Grained highlights of program progress - * @return - */ - public LogTarget info(); - - /** - * Fine-grained informational events useful for debugging - * @return - */ - public LogTarget debug(); - - /** - * Finest grained Informational events... more detailed than Debug - * @return - */ - public LogTarget trace(); - - - /** - * Basic and Common Audit info... - * - * Note Apps can define, but should use Integers after 0x1F. They can combine with "&" - */ - public static final int REMOTE = 0x01; - public static final int XML = 0x02; - public static final int JSON = 0x04; - public static final int SUB = 0x08; - public static final int CHECKPOINT = 0x10; - public static final int ALWAYS = 0x20; // Mark as a line to print, even in WARN+ mode - - - - /** - * Start a Time Trail with differentiation by flag. This can be Defined By above flags or combined with - * app flag definitions - * - * @param string - * @param flag - * @return - */ - public TimeTaken start(String name, int flag); - - public String setProperty(String tag, String value); - public String getProperty(String tag); - public String getProperty(String tag, String deflt); - - /** - * Passwords should be encrypted on the disk. Use this method to apply decryption before - * using. The Implementation should give ways to decrypt - * - * @param tag - * @return - */ - public Decryptor decryptor(); - - public Encryptor encryptor(); - -} - diff --git a/env/src/main/java/com/att/inno/env/EnvJAXB.java b/env/src/main/java/com/att/inno/env/EnvJAXB.java deleted file mode 100644 index f75203c..0000000 --- a/env/src/main/java/com/att/inno/env/EnvJAXB.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - -import javax.xml.namespace.QName; -import javax.xml.validation.Schema; - -public interface EnvJAXB extends EnvStore { - /** - * Obtain a DataInterface from this Environment - * - * @param - * @param classes - * @return - * @throws APIException - */ - public DataFactory newDataFactory(Class... classes) throws APIException; - - /** - * Obtain a DataInterface from this Environment, with Validating Schema - * - * @param - * @param classes - * @return - * @throws APIException - */ - public DataFactory newDataFactory(Schema schema, Class... classes) throws APIException; - - public DataFactory newDataFactory(QName qName, Class ... classes) throws APIException; - - public DataFactory newDataFactory(Schema schema, QName qName, Class ... classes) throws APIException; - -} diff --git a/env/src/main/java/com/att/inno/env/EnvJAXBProps.java b/env/src/main/java/com/att/inno/env/EnvJAXBProps.java deleted file mode 100644 index 2e0f977..0000000 --- a/env/src/main/java/com/att/inno/env/EnvJAXBProps.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - -/** - * An interface to express both JAXB and Property elements of Env - * - */ -public interface EnvJAXBProps extends EnvJAXB, EnvProps { - -} diff --git a/env/src/main/java/com/att/inno/env/EnvProps.java b/env/src/main/java/com/att/inno/env/EnvProps.java deleted file mode 100644 index e18787a..0000000 --- a/env/src/main/java/com/att/inno/env/EnvProps.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - -import java.util.Map; - -public interface EnvProps extends Env { - public interface EnvProperty { - public String getProperty(String input); - }; - - /** - * Obtain a Property (String) based on a Key. Implementor decides how - * that works, i.e. from a complex set of Configurations, or just - * "System" (Java standard) - * - * @param key - * @return APIException - */ - public String getProperty(String key); - - /** - * Obtain a Property (String) based on a Key. Implementor decides how - * that works, i.e. from a complex set of Configurations, or just - * "System" (Java standard) - * - * If Property Value is null, then default will be used. - * @param key - * @return APIException - */ - public String getProperty(String tag, String defaultValue); - - /** - * Set a Property (String) based on a Key accessible to all in Env. Implementor decides how - * that works, i.e. from a complex set of Configurations, or just - * "System" (Java standard) - * - * @param key - * @return APIException - */ - public String setProperty(String key, String value); - - /** - * Get the SubProperties based on key. - * - * use "false" to remove prefix, "true" to leave prefix in. - * - * @param key - * @return APIException - * Given a known property set (or in this case, properties starting with key), - * return map of all properties with appropriate key names - */ - public Map getSubProperties(String key, boolean includePrefix); - - /** - * Get all of the properties in the Environment - * @return - */ - public Map getProperties(); - -} diff --git a/env/src/main/java/com/att/inno/env/EnvStore.java b/env/src/main/java/com/att/inno/env/EnvStore.java deleted file mode 100644 index 5872a3e..0000000 --- a/env/src/main/java/com/att/inno/env/EnvStore.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - - -public interface EnvStore extends Env, Store, TransCreate{ - -} diff --git a/env/src/main/java/com/att/inno/env/IOObjectifier.java b/env/src/main/java/com/att/inno/env/IOObjectifier.java deleted file mode 100644 index 35358aa..0000000 --- a/env/src/main/java/com/att/inno/env/IOObjectifier.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - -import java.io.InputStream; -import java.io.Reader; - -public interface IOObjectifier extends Objectifier { - /** - * Marshal to Object T from a Reader, using contents from Env as necessary.

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

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return T - * @throws APIException - */ - public abstract T objectify(Env env, InputStream is) throws APIException; - -} diff --git a/env/src/main/java/com/att/inno/env/IOStringifier.java b/env/src/main/java/com/att/inno/env/IOStringifier.java deleted file mode 100644 index c1dccce..0000000 --- a/env/src/main/java/com/att/inno/env/IOStringifier.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - -import java.io.OutputStream; -import java.io.Writer; - -/** - * Allow Extended IO interface usage without muddying up the Stringifier Interface - */ -public interface IOStringifier extends Stringifier { - /** - * Marshal from an Object T onto a Writer, using contents from Env as necessary.

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

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return String - * @throws APIException - */ - public abstract void stringify(Env env, T input, OutputStream os, boolean ... options) throws APIException; - - /** - * Set Pretty XML, where possible - * - * @param pretty - * @throws APIException - */ - public abstract IOStringifier pretty(boolean pretty); - - /** - * Set Generate Fragment - * - * @param fragment - * @throws APIException - */ - public abstract IOStringifier asFragment(boolean fragment); - - -} diff --git a/env/src/main/java/com/att/inno/env/LifeCycle.java b/env/src/main/java/com/att/inno/env/LifeCycle.java deleted file mode 100644 index 7a359bd..0000000 --- a/env/src/main/java/com/att/inno/env/LifeCycle.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -/** - * - * Created on: Aug 19, 2009 - * Created by: - * - * (c) 2009 SBC Knowledge Ventures, L.P. All rights reserved. - ******************************************************************* - * RESTRICTED - PROPRIETARY INFORMATION The Information contained - * herein is for use only by authorized employees of AT&T Services, - * Inc., and authorized Affiliates of AT&T Services, Inc., and is - * not for general distribution within or outside the respective - * companies. - ******************************************************************* - */ -package com.att.inno.env; - -import com.att.inno.env.util.RefreshableThreadObject; - - -/** - * - */ -public interface LifeCycle { - /** - * The Service using LifeCycle Elements is required to call this method at - * the appropriate startup time. This is better for services than a simple - * static call, because the exact moment of starting can be determined - * programatically. - *

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

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

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

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

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

- * - *

IMPORTANT:

- * The LifeCycle implementor cannot guarantee it will not be in the middle - * of a transaction, so it would behoove the implementor to construct - * content that does not affect anything until finished, then apply to an - * appropriate atomic action (i.e. setting an Object to a field), or even - * synchronizing. - * - * If you are using Java's "ThreadLocal", consider - * {@link RefreshableThreadObject}, because it implements LifeCycle, and - * responds to the refresh command. - * - * @param env - * @throws APIException - */ - public abstract void refresh(Env env) throws APIException; - - /** - * Parallel to threadPrestart, threadDestroy tells the implementor that the - * service is ending this particular thread, and to take this opportunity to - * close out any content specific to this thread that can be closed. - * - * @param env - * @throws APIException - */ - public abstract void threadDestroy(Env env) throws APIException; - - /** - * Parallel to servicePrestart, serviceDestroy tells the implementor that - * the service is ending, and to take this opportunity to close out any - * content under it's control that can or should be closed explicitly. - */ - public abstract void serviceDestroy(Env env) throws APIException; -} diff --git a/env/src/main/java/com/att/inno/env/LogTarget.java b/env/src/main/java/com/att/inno/env/LogTarget.java deleted file mode 100644 index ca4f8b3..0000000 --- a/env/src/main/java/com/att/inno/env/LogTarget.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - -import java.io.PrintStream; -import java.util.Date; - -import com.att.inno.env.util.Chrono; - -/** - * LogTarget is the interface with which to assign any kind of Logging Implementations. - * - * Implement for any Logging Library of your choice, and for any logging string Format desired. - * - * Included are several Static Implementations for various uses: - * NULL: Does nothing with Logging Messages - * SYSOUT: Writes messages in general form to System Out - * SYSERR: Writes messages in general form to System Err - * - * - */ -public interface LogTarget { - public abstract void log(Object... msgs); - public abstract void log(Throwable e, Object ... msgs); - public abstract boolean isLoggable(); - public abstract void printf(String fmt, Object ... vars); - - // A Convenient LogTarget to insert when a NO-OP is desired. - public static final LogTarget NULL = new LogTarget() { - public void log(Object ... msgs) { - } - - public void log(Throwable t, Object ... msgs) { - } - - public boolean isLoggable() { - return false; - } - - @Override - public void printf(String fmt, Object ... vars) { - } - }; - - // A Convenient LogTarget to write to the Console - public static final LogTarget SYSOUT = new LogTarget() { - public void log(Object ... msgs) { - PrintStream out = System.out; - out.print(com.att.inno.env.util.Chrono.dateFmt.format(new Date())); - out.print(": "); - for(Object str : msgs) { - if(str!=null) { - out.print(str.toString()); - out.print(' '); - } else { - out.print("null "); - } - } - out.println(); - } - - public void log(Throwable t, Object ... msgs) { - PrintStream out = System.out; - out.print(Chrono.dateFmt.format(new Date())); - out.print(": "); - for(Object str : msgs) { - out.print(str.toString()); - out.print(' '); - } - out.println(); - t.printStackTrace(out); - out.println(); - } - - public boolean isLoggable() { - return true; - } - - @Override - public void printf(String fmt, Object ... vars) { - log(String.format(fmt,vars)); - } - }; - - // A Convenient LogTarget to write to the Console - public static final LogTarget SYSERR = new LogTarget() { - public void log(Object ... msgs) { - PrintStream out = System.err; - out.print(Chrono.dateFmt.format(new Date())); - out.print(": "); - for(Object str : msgs) { - out.print(str.toString()); - out.print(' '); - } - out.println(); - out.flush(); - } - - public void log(Throwable t, Object ... msgs) { - PrintStream out = System.err; - out.print(Chrono.dateFmt.format(new Date())); - out.print(": "); - for(Object str : msgs) { - out.print(str.toString()); - out.print(' '); - } - out.println(); - t.printStackTrace(out); - } - - public boolean isLoggable() { - return true; - } - @Override - public void printf(String fmt, Object ... vars) { - log(String.format(fmt,vars)); - } - - }; - - -}; diff --git a/env/src/main/java/com/att/inno/env/Objectifier.java b/env/src/main/java/com/att/inno/env/Objectifier.java deleted file mode 100644 index ed3c38e..0000000 --- a/env/src/main/java/com/att/inno/env/Objectifier.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -/** - * - */ -package com.att.inno.env; - - - -/** - *

Objectifier

- * Objectifier abstracts the unmarshaling of an Object from a String, and - * the creation of an uninitialized object. - */ -public interface Objectifier extends LifeCycle { - /** - * Marshal to Object T from a String, using contents from Env as necessary.

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return T - * @throws APIException - */ - public abstract T objectify(Env env, String input) throws APIException; - - /** - * Create a new object of type T. This is often more efficiently done with - * the underlying XML (or other) Library. - * @return T - * @throws APIException - */ - public abstract T newInstance() throws APIException; - - -} diff --git a/env/src/main/java/com/att/inno/env/Slot.java b/env/src/main/java/com/att/inno/env/Slot.java deleted file mode 100644 index 8f976d8..0000000 --- a/env/src/main/java/com/att/inno/env/Slot.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -/** - * Slot.java - * - * Created on: Dec 5, 2008 - * Created by: - * - * (c) 2008 SBC Knowledge Ventures, L.P. All rights reserved. - ******************************************************************* - * RESTRICTED - PROPRIETARY INFORMATION The Information contained - * herein is for use only by authorized employees of AT&T Services, - * Inc., and authorized Affiliates of AT&T Services, Inc., and is - * not for general distribution within or outside the respective - * companies. - ******************************************************************* - */ -package com.att.inno.env; - -/** - * Slot's are used to store and retrieve data in the transaction's State object. - */ -public final class Slot { - - /* - * The name of the Slot. - */ - private final String key; - - /* - * The index of the State's local map associated with this Slot. - */ - final int slot; - - /** - * Constructs a new Slot. - * - * @param index - * The index of State's local map this Slot is associated with. - * @param name - * The name of the Slot's key. - */ - Slot(int index, String name) { - slot = index; - key = name; - } - - /** - * Debug method only to print key=slot pairs. - */ - public String toString() { - return key + '=' + slot; - } - - /** - * Returns the name of this Slot's key. - * - * @return - * The name of this Slot's key. - */ - public String getKey() { - return key; - } - - /** - * Put an Object into the slot on the State - * @param state - * @param obj - */ - public void put(Object[] state, Object obj) { - state[slot]=obj; - } - - /** - * Get an Object from the slot on the State - * @param state - * @param obj - */ - public Object get(Object[] state) { - return state[slot]; - } - -} diff --git a/env/src/main/java/com/att/inno/env/StaticSlot.java b/env/src/main/java/com/att/inno/env/StaticSlot.java deleted file mode 100644 index 0fe8f36..0000000 --- a/env/src/main/java/com/att/inno/env/StaticSlot.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -/** - * Slot.java - * - * Created on: Dec 5, 2008 - * Created by: - * - * (c)2008 SBC Knowledge Ventures, L.P. All rights reserved. - ******************************************************************* - * RESTRICTED - PROPRIETARY INFORMATION The Information contained - * herein is for use only by authorized employees of AT&T Services, - * Inc., and authorized Affiliates of AT&T Services, Inc., and is - * not for general distribution within or outside the respective - * companies. - ******************************************************************* - */ -package com.att.inno.env; - -/** - * StaticSlot's are used to store and retrieve data from the Organizer that does not change. - */ -public final class StaticSlot { - - /* - * The name of the StaticSlot. - */ - private final String key; - - /* - * The index of the Organizer's static map associated with this StaticSlot. - */ - final int slot; - - /** - * Constructs a new StaticSlot. - * - * @param index - * The index of Organizer's static map this StaticSlot is associated with. - * @param name - * The name of the StaticSlot's key. - */ - StaticSlot(int index, String name) { - slot = index; - key = name; - } - - /** - * Debug method only to print key=slot pairs. - */ - public String toString() { - return key + '=' + slot; - } - - /** - * Returns the name of this StaticSlot's key. - * - * @return - * The name of this StaticSlot's key. - */ - public String getKey() { - return key; - } - -} - diff --git a/env/src/main/java/com/att/inno/env/Store.java b/env/src/main/java/com/att/inno/env/Store.java deleted file mode 100644 index fa7e339..0000000 --- a/env/src/main/java/com/att/inno/env/Store.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - -import java.util.List; - -public interface Store { - /** - * Returns the Slot assigned to the supplied name. - * - * @param name - * The name of the Slot to acquire. - * @return - * The Slot associated with the supplied name. - */ - public abstract Slot slot(String name); - - /** - * Returns the existing Slot associated with the supplied name, or null if it doesn't exist. - * - * @param name - * The name of the Slot to get. - * @return - * The Slot assigned to the supplied name, or null if it doesn't exist. - * - */ - public abstract Slot existingSlot(String name); - - /** - * Returns the names used while creating Slots in a List - * - * @return - */ - public abstract List existingSlotNames(); - - /** - * Returns the StaticSlot assigned to the supplied name. - * - * @param name - * The name of the StaticSlot to acquire. - * @return - * The StaticSlot associated with the supplied name. - */ - public abstract StaticSlot staticSlot(String name); - - /** - * Returns the names used while creating Static Slots in a List - * - * @return - */ - public abstract List existingStaticSlotNames(); - - /** - * Store the supplied value in the StaticSlot of the Organizer's static state. - * - * @param slot - * The StaticSlot used to store the object. - * @param value - * The object to store. - */ - public abstract void put(StaticSlot slot, Object value); - - /** - * Returns an Object from the Organizer's static state, or the Default if null - * - * @param slot - * The StaticSlot to retrieve the data from. - * @return - * The Object located in the supplied StaticSlot of the Organizer's static state. - */ - public abstract T get(StaticSlot slot, T dflt); - - /** - * Returns an Object from the Organizer's static state - * - * @param slot - * The StaticSlot to retrieve the data from. - * @return - * The Object located in the supplied StaticSlot of the Organizer's static state. - */ - public abstract T get(StaticSlot slot); - -// /** -// * Transfer (targeted) Args to Slots -// * -// * Transfer Strings with format "tag=value" into Static Slots -// */ -// public abstract void transfer(String args[], String ... tagss); -} diff --git a/env/src/main/java/com/att/inno/env/StoreImpl.java b/env/src/main/java/com/att/inno/env/StoreImpl.java deleted file mode 100644 index 482d0d6..0000000 --- a/env/src/main/java/com/att/inno/env/StoreImpl.java +++ /dev/null @@ -1,237 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map.Entry; -import java.util.Properties; - -import com.att.inno.env.util.Split; - - -public class StoreImpl implements Store { - /* - * The re-adjustment factor for growing the Static State array. - */ - private static final int growSize = 10; - - /* - * The index reference for Slot assignment. - */ - private int local; - - /* - * The index reference for StaticSlot assignment. - */ - private int stat; - - /* - * The name/slot map for local (transaction specific) State. - */ - private HashMap localMap; - - /* - * The name/slot map for Static State. - */ - private HashMap staticMap; - - private Object[] staticState; - - public StoreImpl() { - staticState = new Object[growSize]; - staticMap = new HashMap(); - localMap = new HashMap(); - } - - public StoreImpl(String tag) { - staticState = new Object[growSize]; - staticMap = new HashMap(); - localMap = new HashMap(); - } - - - public StoreImpl(String tag, String[] args) { - staticState = new Object[growSize]; - staticMap = new HashMap(); - localMap = new HashMap(); - - if(tag!=null) { - String tequals = tag + '='; - for(String arg : args) { - if(arg.startsWith(tequals) && !arg.equals(tequals)) { // needs to have something after = - Properties props = new Properties(); - for(String f : Split.split(File.pathSeparatorChar,arg.substring(tequals.length()))) { - moreProps(new File(f),props); - } - for(Entry es : props.entrySet()) { - put(staticSlot(es.getKey().toString()),es.getValue()); - } - } - } - } - - // Make sure properties on command line override those in Props - propsFromArgs(tag,args); - } - - public StoreImpl(String tag, Properties props) { - staticState = new Object[growSize]; - staticMap = new HashMap(); - localMap = new HashMap(); - - if(tag!=null) { - String fname = props.getProperty(tag); - if(fname!=null) { - for(String f : Split.split(File.pathSeparatorChar,fname)) { - if(!moreProps(new File(f),props)) { - System.err.println("Unable to load Properties from " + f); - } - } - } - } - - for(Entry es : props.entrySet()) { - put(staticSlot(es.getKey().toString()),es.getValue()); - } - } - - public void propsFromArgs(String tag, String[] args) { - for(String arg : args) { - String sarg[] = Split.split('=',arg); - if(sarg.length==2) { - if(tag.equals(sarg[0])) { - for(String fname : Split.split(File.pathSeparatorChar,sarg[1])) { - moreProps(new File(fname),null /* no target */); - } - } - put(staticSlot(sarg[0]),sarg[1]); - } - } - } - - private boolean moreProps(File f, Properties target) { - if(f.exists()) { - Properties props = new Properties(); - try { - FileInputStream fis = new FileInputStream(f); - try { - props.load(fis); - if(target!=null) { - target.load(fis); - } - } finally { - fis.close(); - } - } catch(IOException e) { - System.err.println(e); - } - for(Entry es : props.entrySet()) { - put(staticSlot(es.getKey().toString()),es.getValue()); - } - return true; - } else { - return false; - } - } - - public Object[] newTransState() { - return new Object[local]; - } - - /* (non-Javadoc) - * @see com.att.env.Store#slot(java.lang.String) - */ - public synchronized Slot slot(String name) { - name = name == null ? "" : name.trim(); - Slot slot = localMap.get(name); - if (slot == null) { - slot = new Slot(local++, name); - localMap.put(name, slot); - } - return slot; - } - - - /* (non-Javadoc) - * @see com.att.env.Store#existingSlot(java.lang.String) - */ - public Slot existingSlot(String name) { - return localMap.get(name); - } - - /* (non-Javadoc) - * @see com.att.env.Store#existingSlotNames() - */ - public List existingSlotNames() { - return new ArrayList(localMap.keySet()); - } - - /* (non-Javadoc) - * @see com.att.env.Store#staticSlot(java.lang.String) - */ - public synchronized StaticSlot staticSlot(String name) { - name = name == null ? "" : name.trim(); - StaticSlot slot = staticMap.get(name); - if (slot == null) { - if (stat%growSize == 0) { - Object[] temp = staticState; - staticState = new Object[temp.length+growSize]; - System.arraycopy(temp, 0, staticState, 0, temp.length); - } - slot = new StaticSlot(stat++, name); - staticMap.put(name, slot); - } - return slot; - } - - /* (non-Javadoc) - * @see com.att.env.Store#put(com.att.env.StaticSlot, java.lang.Object) - */ - public void put(StaticSlot slot, Object value) { - staticState[slot.slot] = value; - } - - /* (non-Javadoc) - * @see com.att.env.Store#get(com.att.env.StaticSlot T defaultObject) - */ - @SuppressWarnings("unchecked") - public T get(StaticSlot sslot,T dflt) { - T t = (T)staticState[sslot.slot]; - return t==null?dflt:t; - } - - @SuppressWarnings("unchecked") - public T get(StaticSlot sslot) { - return (T)staticState[sslot.slot]; - } - - public List existingStaticSlotNames() { - return new ArrayList(staticMap.keySet()); - } -} - diff --git a/env/src/main/java/com/att/inno/env/Stringifier.java b/env/src/main/java/com/att/inno/env/Stringifier.java deleted file mode 100644 index 3d3f43c..0000000 --- a/env/src/main/java/com/att/inno/env/Stringifier.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - - - -/** - *

Stringifier

- * Stringifier abstracts the marshaling of a String to an Object - */ -public interface Stringifier extends LifeCycle { - - /** - * Marshal from a String to an Object T, using contents from Env as necessary.

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return String - * @throws APIException - */ - public abstract String stringify(Env env, T input, boolean ... options) throws APIException; - -} diff --git a/env/src/main/java/com/att/inno/env/TimeTaken.java b/env/src/main/java/com/att/inno/env/TimeTaken.java deleted file mode 100644 index 5bdaa1b..0000000 --- a/env/src/main/java/com/att/inno/env/TimeTaken.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - -/** - *

TimeTaken

- * This simple interface allows for many different kinds of - * Audit Logs to be accomplished, by assuming that the creation - * of this object indicates "start", and the calling of "done" - * ends. - * - * The implementor of this class can easily be stored in efficient - * mechanisms to minimize impact of Auditing on performance. - * - * - */ -public abstract class TimeTaken { - public final long start; - protected long end, size; - public final int flag; - public final String name; - - /** - * The name is as it will appear when written to output (abstract method) - * - * The flag is an integer which can be System type (XML, REMOTE, etc), or End User defined for reporting purposes - * - * @param name - * @param flag - */ - public TimeTaken(String name, int flag) { - start = System.nanoTime(); - this.flag = flag; - this.name = name; - size = -1; - } - - - /** - * Call this when process is done to state ending time.

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

- * - *

-	 *   TimeTaken tt = env.startSubTime();
-	 *   try {
-	 *       process.me(); // code to be timed.
-	 *   } finally {
-	 *   	 tt.done();
-	 *   }
-	 * 
- */ - public void done() { - end = System.nanoTime(); - } - - - /** - * For sizable contents, set the size. Implementations can simply write a no-op if they don't wish to - * store the size. - * - * @param size - */ - public void size(long theSize) { - size = theSize; - } - - /** - * Give readonly access to End, which isn't final - * @return - */ - public long end() { - return end; - } - - /** - * Time is taken in NanoSeconds. This method converts to decimals of Milliseconds - * @return - */ - public float millis() { - return (end-start)/1000000f; - } - /** - * Write self to a String Builder (for making Audits) - * @param sb - */ - public abstract void output(StringBuilder sb); - - /** - * For Debugging - */ - public String toString() { - return name + ' ' + millis() + "ms " + (size>0?Long.toString(size):""); - } - -} diff --git a/env/src/main/java/com/att/inno/env/Trans.java b/env/src/main/java/com/att/inno/env/Trans.java deleted file mode 100644 index 2e584c1..0000000 --- a/env/src/main/java/com/att/inno/env/Trans.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - - - - -/** - * A Trans is like an Env, however, it's purpose it to track the Transient - * Data associated with Transactions, or other short term elements. - * - * Any Object implementing Trans should expect to go in an out of scope quickly - * - * Implementations should also overload the concepts of "Start", etc and build up - * and Audit Log, so it can implement "metric" below - * - * All Transactions (i.e. a call to a service) will need these items. - * - * - */ -public interface Trans extends Env { - /** - * Add a completed entry in the Audit Trail for tracking purposes. - * - * @param text - */ - public void checkpoint(String text); - - /** - * Add a completed entry in the Audit Trail for tracking purposes, and combine flag with "CHECKPOINT" - * - * @param text - */ - public void checkpoint(String text, int additionalFlag); - - /** - * Output an Audit Trail onto the StringBuilder - * - * Load metrics into an array of floats from passed in Flags - * - * @param flag - * @param sb - * @return - */ - public Metric auditTrail(LogTarget lt, int indent, StringBuilder sb, int ... flag); - - public Metric auditTrail(int indent, StringBuilder sb, int ... flag); - - public class Metric { - public float[] buckets; - public float total; - public int entries; - } -} diff --git a/env/src/main/java/com/att/inno/env/TransCreate.java b/env/src/main/java/com/att/inno/env/TransCreate.java deleted file mode 100644 index b6db5b4..0000000 --- a/env/src/main/java/com/att/inno/env/TransCreate.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - -public interface TransCreate { - public TRANS newTrans(); -} diff --git a/env/src/main/java/com/att/inno/env/TransJAXB.java b/env/src/main/java/com/att/inno/env/TransJAXB.java deleted file mode 100644 index ffd25d7..0000000 --- a/env/src/main/java/com/att/inno/env/TransJAXB.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - -public interface TransJAXB extends Trans, TransStore { - -} diff --git a/env/src/main/java/com/att/inno/env/TransStore.java b/env/src/main/java/com/att/inno/env/TransStore.java deleted file mode 100644 index acfcf47..0000000 --- a/env/src/main/java/com/att/inno/env/TransStore.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env; - -public interface TransStore extends Trans { - /** - * Returns the Slot assigned to the supplied name. - * - * @param name - * The name of the Slot to acquire. - * @return - * The Slot associated with the supplied name. - */ - public abstract Slot slot(String name); - - /** - * Put data into the right slot - */ - public void put(Slot slot, Object value); - - /** - * Get data from the right slot - * - * This will do a cast to the expected type derived from Default - */ - public T get(Slot slot, T deflt); - - /** - * Returns an Object from the Organizer's static state, or the Default if null - * - * @param slot - * The StaticSlot to retrieve the data from. - * @return - * The Object located in the supplied StaticSlot of the Organizer's static state. - */ - public abstract T get(StaticSlot slot, T dflt); - -} 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 deleted file mode 100644 index 4f370c7..0000000 --- a/env/src/main/java/com/att/inno/env/impl/AbsTrans.java +++ /dev/null @@ -1,215 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.impl; - -import java.util.ArrayList; -import java.util.List; -import java.util.Stack; - -import com.att.inno.env.Env; -import com.att.inno.env.LogTarget; -import com.att.inno.env.Slot; -import com.att.inno.env.StoreImpl; -import com.att.inno.env.TimeTaken; -import com.att.inno.env.TransStore; - -public abstract class AbsTrans implements TransStore { - private static final float[] EMPTYF = new float[0]; - private static final Object[] EMPTYO = new Object[0]; - - protected ENV delegate; - protected List trail = new ArrayList(30); - private Object[] state; - - - public AbsTrans(ENV delegate) { - this.delegate = delegate; - state = delegate instanceof StoreImpl?((StoreImpl) delegate).newTransState():EMPTYO; - } - - // @Override - public LogTarget fatal() { - return delegate.fatal(); - } - -// @Override - public LogTarget error() { - return delegate.error(); - } - -// @Override - public LogTarget audit() { - return delegate.audit(); - } - -// @Override - public LogTarget init() { - return delegate.init(); - } - -// @Override - public LogTarget warn() { - return delegate.warn(); - } - -// @Override - public LogTarget info() { - return delegate.info(); - } - -// @Override - public LogTarget debug() { - return delegate.debug(); - } - -// @Override - public LogTarget trace() { - return delegate.trace(); - } - - /** - * Let the final Trans Implementation choose the exact kind of TimeTaken to use - * @param name - * @param flag - * @return - */ - protected abstract TimeTaken newTimeTaken(String name, int flag); - -// @Override - public final TimeTaken start(String name, int flag) { - TimeTaken tt = newTimeTaken(name,flag); - trail.add(tt); - return tt; - } - -// @Override - public final void checkpoint(String name) { - TimeTaken tt = newTimeTaken(name,CHECKPOINT); - tt.done(); - trail.add(tt); - } - - public final void checkpoint(String name, int additionalFlag) { - TimeTaken tt = newTimeTaken(name,CHECKPOINT|additionalFlag); - tt.done(); - trail.add(tt); - } - - @Override - public Metric auditTrail(int indent, StringBuilder sb, int ... flags) { - return auditTrail(info(),indent,sb,flags); - } - - @Override - public Metric auditTrail(LogTarget lt, int indent, StringBuilder sb, int ... flags) { - Metric metric = new Metric(); - int last = (metric.entries = trail.size()) -1; - metric.buckets = flags.length==0?EMPTYF:new float[flags.length]; - if(last>=0) { - TimeTaken first = trail.get(0); - // If first entry is sub, then it's actually the last "end" as well - // otherwise, check end - //long end = (first.flag&SUB)==SUB?first.end():trail.get(last).end(); - long end = trail.get(last).end(); - metric.total = (end - first.start) / 1000000f; - } - - if(sb==null) { - for(TimeTaken tt : trail) { - float ms = tt.millis(); - for(int i=0;i stack = new Stack(); - for(TimeTaken tt : trail) { - // Create Indentation based on SUB - while(!stack.isEmpty() && tt.end()>stack.peek()) { - --indent; - stack.pop(); - } - for(int i=0;i T get(Slot slot, T deflt) { - Object o; - try { - o = slot.get(state); - } catch(ArrayIndexOutOfBoundsException e) { - // Env State Size has changed because of dynamic Object creation... Rare event, but needs to be covered - Object[] temp = ((StoreImpl) delegate).newTransState(); - System.arraycopy(state, 0, temp, 0, state.length); - state = temp; - o=null; - } - return o==null?deflt:(T)o; - } - - -} diff --git a/env/src/main/java/com/att/inno/env/impl/AbsTransJAXB.java b/env/src/main/java/com/att/inno/env/impl/AbsTransJAXB.java deleted file mode 100644 index 186d0af..0000000 --- a/env/src/main/java/com/att/inno/env/impl/AbsTransJAXB.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.impl; - -import javax.xml.namespace.QName; -import javax.xml.validation.Schema; - -import com.att.inno.env.APIException; -import com.att.inno.env.DataFactory; -import com.att.inno.env.EnvJAXB; -import com.att.inno.env.TransJAXB; - -public abstract class AbsTransJAXB extends AbsTrans implements TransJAXB { - public AbsTransJAXB(EnvJAXB env) { - super(env); - } - -// @Override - public DataFactory newDataFactory(Class... classes) throws APIException { - return delegate.newDataFactory(classes); - } - -// @Override - public DataFactory newDataFactory(Schema schema, Class... classes) throws APIException { - return delegate.newDataFactory(schema, classes); - } - -// @Override - public DataFactory newDataFactory(QName qName, Class... classes) throws APIException { - return delegate.newDataFactory(qName, classes); - } - -// @Override - public DataFactory newDataFactory(Schema schema, QName qName, Class... classes) throws APIException { - return delegate.newDataFactory(schema, qName, classes); - } - -} 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 deleted file mode 100644 index af2f103..0000000 --- a/env/src/main/java/com/att/inno/env/impl/BasicEnv.java +++ /dev/null @@ -1,336 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.impl; - -import java.applet.Applet; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.Properties; - -import javax.xml.namespace.QName; -import javax.xml.validation.Schema; - -import com.att.inno.env.APIException; -import com.att.inno.env.DataFactory; -import com.att.inno.env.Decryptor; -import com.att.inno.env.Encryptor; -import com.att.inno.env.Env; -import com.att.inno.env.EnvJAXB; -import com.att.inno.env.LogTarget; -import com.att.inno.env.StoreImpl; -import com.att.inno.env.TimeTaken; -import com.att.inno.env.TransCreate; -import com.att.inno.env.TransJAXB; -import com.att.inno.env.jaxb.JAXBDF; -import com.att.inno.env.util.Split; - -/** - * An essential Implementation of Env, which will fully function, without any sort - * of configuration. - * - * Use as a basis for Group level Env, just overriding where needed. - * - */ -public class BasicEnv extends StoreImpl implements EnvJAXB, TransCreate{ - protected LogTarget fatal=LogTarget.SYSERR; - protected LogTarget error=LogTarget.SYSERR; - protected LogTarget audit=LogTarget.SYSOUT; - protected LogTarget init=LogTarget.SYSOUT; - protected LogTarget warn=LogTarget.SYSERR; - protected LogTarget info=LogTarget.SYSOUT; - protected LogTarget debug=LogTarget.NULL; - protected LogTarget trace=LogTarget.NULL; -// protected Map props; - -// private boolean sysprops; - - public BasicEnv(String ... args) { - super(null,args); - } - - public BasicEnv(String tag, String[] args) { - super(tag, args); - } - - - /** - * Suitable for use in Applets... obtain all the values - * listed for the variable String arg "tags" - */ - public BasicEnv(Applet applet, String ... tags) { - super(null, tags); -// props = new HashMap(); -// String value; -// for(int i=0;i=0) { - sb.append(" size: "); - sb.append(Long.toString(size)); - } - } - } - }; - } - - // @Override - public String getProperty(String key) { - return get(staticSlot(key),null); - } - - public Properties getProperties(String ... filter) { - Properties props = new Properties(); - boolean yes; - for(String key : existingStaticSlotNames()) { - if(filter.length>0) { - yes = false; - for(String f : filter) { - if(key.startsWith(f)) { - yes = true; - break; - } - } - } else { - yes = true; - } - if(yes) { - String value = getProperty(key); - if(value!=null) { - props.put(key, value); - } - } - } - return props; - } - - // @Override - public String getProperty(String key, String defaultValue) { - return get(staticSlot(key),defaultValue); - } - - // @Override - public String setProperty(String key, String value) { - put(staticSlot(key),value==null?null:value.trim()); - return value; - } - - protected Decryptor decryptor = Decryptor.NULL; - protected Encryptor encryptor = Encryptor.NULL; - - - public Decryptor decryptor() { - return decryptor; - } - - public void set(Decryptor newDecryptor) { - decryptor = newDecryptor; - } - - public Encryptor encryptor() { - return encryptor; - } - - public void set(Encryptor newEncryptor) { - encryptor = newEncryptor; - } - - -// @SuppressWarnings("unchecked") - // @Override - public DataFactory newDataFactory(Class... classes) throws APIException { -// if(String.class.isAssignableFrom(classes[0])) -// return (DataFactory) new StringDF(this); - return new JAXBDF(this,classes); - } - -// @SuppressWarnings("unchecked") - // @Override - public DataFactory newDataFactory(Schema schema, Class... classes) throws APIException { -// if(String.class.isAssignableFrom(classes[0])) -// return (DataFactory) new StringDF(this); - return new JAXBDF(this, schema, classes); - } - -// @SuppressWarnings("unchecked") - // @Override - public DataFactory newDataFactory(QName qName, Class ... classes) throws APIException { -// if(String.class.isAssignableFrom(classes[0])) -// return (DataFactory) new StringDF(this); - return new JAXBDF(this, qName, classes); - } - - // @Override - public DataFactory newDataFactory(Schema schema, QName qName, Class ... classes) throws APIException { - return new JAXBDF(this, schema, qName, classes); - } - - // @Override - public BasicTrans newTrans() { - return new BasicTrans(this); - } - - public void loadFromSystemPropsStartsWith(String ... str) { - for(String name : System.getProperties().stringPropertyNames()) { - for(String s : str) { - if(name.startsWith(s)) { - setProperty(name, System.getProperty(name)); - } - } - } - } - - /** - * - * - */ - public void loadToSystemPropsStartsWith(String ... str) { - String value; - for(String name : existingStaticSlotNames()) { - for(String s : str) { - if(name.startsWith(s)) { - if((value = getProperty(name))!=null) - System.setProperty(name,value); - } - } - } - } - - public void loadPropFiles(String tag, ClassLoader classloader) throws IOException { - String propfiles = getProperty(tag); - if(propfiles!=null) { - for(String pf : Split.splitTrim(File.pathSeparatorChar, propfiles)) { - InputStream is = classloader==null?null:classloader.getResourceAsStream(pf); - if(is==null) { - File f = new File(pf); - if(f.exists()) { - is = new FileInputStream(f); - } - } - if(is!=null) { - BufferedReader br = new BufferedReader(new InputStreamReader(is)); - try { - String line; - while((line=br.readLine())!=null) { - line = line.trim(); - if(!line.startsWith("#")) { - String[] tv = Split.splitTrim('=', line); - if(tv.length==2) { - setProperty(tv[0],tv[1]); - } - } - } - } finally { - try { - br.close(); - } catch (IOException e) { - error().log(e); - } - } - } - } - } - } -} 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 deleted file mode 100644 index ec36b57..0000000 --- a/env/src/main/java/com/att/inno/env/impl/BasicTrans.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.impl; - -import com.att.inno.env.Decryptor; -import com.att.inno.env.Encryptor; -import com.att.inno.env.EnvJAXB; -import com.att.inno.env.Slot; -import com.att.inno.env.StaticSlot; -import com.att.inno.env.TimeTaken; - - -public class BasicTrans extends AbsTransJAXB { - - public BasicTrans(EnvJAXB env) { - super(env); - } - - @Override - protected TimeTaken newTimeTaken(String name, int flag) { - /** - * Note: could have created a different format for Time Taken, but using BasicEnv's instead - */ - return delegate.start(name, flag); - } - - public Slot slot(String name) { - return delegate.slot(name); - } - - public T get(StaticSlot slot) { - return delegate.get(slot); - } - - public T get(StaticSlot slot, T dflt) { - return delegate.get(slot,dflt); - } - - public String setProperty(String tag, String value) { - delegate.setProperty(tag, value); - return value; - } - - public String getProperty(String tag) { - return delegate.getProperty(tag); - } - - public String getProperty(String tag, String deflt) { - return delegate.getProperty(tag, deflt); - } - - @Override - public Decryptor decryptor() { - return delegate.decryptor(); - } - - @Override - public Encryptor encryptor() { - return delegate.encryptor(); - } - -} 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 deleted file mode 100644 index 1826265..0000000 --- a/env/src/main/java/com/att/inno/env/impl/EnvFactory.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.impl; - -import com.att.inno.env.EnvJAXB; -import com.att.inno.env.TransCreate; -import com.att.inno.env.TransJAXB; - -/** - * EnvFactory - * - */ -public class EnvFactory { - - public static final String SCHEMA_DIR = "env-schema_dir"; - public static final String DEFAULT_SCHEMA_DIR = "src/main/xsd"; - static BasicEnv singleton; - - static { - singleton = new BasicEnv(); - } - public static BasicEnv singleton() { - return singleton; - } - - public static void setSingleton(BasicEnv be) { - singleton = be; - } - - public static TransJAXB newTrans() { - return new BasicTrans(singleton); - } - - public static TransJAXB newTrans(EnvJAXB env) { - return new BasicTrans(env); - } - - public static TransCreate transCreator() { - return new TransCreate() { - // @Override - public BasicTrans newTrans() { - return singleton.newTrans(); - } - }; - } -} - 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 deleted file mode 100644 index 87a1b64..0000000 --- a/env/src/main/java/com/att/inno/env/impl/JavaUtilLogTarget.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.impl; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import com.att.inno.env.LogTarget; - -/** - * This LogTarget Implementation is included mostly because the JavaUtil based logging is included in the - * JDK. This makes the default implementation independent of any external Jars. - * - * Log4j is often considered more Enterprise capable. See Log4JLogTarget for that implementation - * - * - */ -public class JavaUtilLogTarget implements LogTarget { - private Level level; - private Logger log; - - public JavaUtilLogTarget(Logger logger, Level theLevel) { - log = logger; - level = theLevel; - } - - public boolean isLoggable() { - return log.isLoggable(level); - } - - public void log(Object ... msgs) { - if(log.isLoggable(level)) { - StringBuilder sb = new StringBuilder(); - String msg; - for(int i=0;i0) { - int sbl = sb.length(); - if(sbl>0) { - char last = sb.charAt(sbl-1); - if(" (.".indexOf(last)<0 && "().".indexOf(msg.charAt(0))<0)sb.append(' '); - } - sb.append(msg); - } - } - log.log(level, sb.toString()); - } - } - - public void log(Throwable e, Object ... msgs) { - String str = e.getLocalizedMessage(); - if(str==null) { - str = e.getMessage(); - } - if(str==null) { - str = e.getClass().getName(); - } - log.log(level,str,msgs); - } - - /* (non-Javadoc) - * @see com.att.inno.env.LogTarget#printf(java.lang.String, java.lang.String[]) - */ - @Override - public void printf(String fmt, Object ... vars) { - if(log.isLoggable(level)) { - log.log(level,String.format(fmt,vars)); - } - } -} diff --git a/env/src/main/java/com/att/inno/env/impl/Log4JLogTarget.java b/env/src/main/java/com/att/inno/env/impl/Log4JLogTarget.java deleted file mode 100644 index d176cd6..0000000 --- a/env/src/main/java/com/att/inno/env/impl/Log4JLogTarget.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.impl; - -import java.io.PrintWriter; - -import org.apache.log4j.Level; -import org.apache.log4j.Logger; - -import com.att.inno.env.APIException; -import com.att.inno.env.LogTarget; -import com.att.inno.env.util.StringBuilderWriter; - -/** - * Many services have chosen to use Log4J for their lower level Logging Implementation. This LogTarget will allow - * any of the messages sent to be set to the appropriate Log4J level. - * - * - */ -public class Log4JLogTarget implements LogTarget { - private Level level; - private Logger log; - - public Log4JLogTarget(String loggerName, Level level) throws APIException { - this.level = level; - if (loggerName != null && loggerName.length() > 0) { - log = Logger.getLogger(loggerName); - } else { - log = Logger.getRootLogger(); - } - } - - // @Override - public boolean isLoggable() { - return log.isEnabledFor(level); - } - - // @Override - public void log(Object... msgs) { - log(null, msgs); - } - - // @Override - public void log(Throwable e, Object... msgs) { - if (log.isEnabledFor(level)) { - StringBuilder sb = new StringBuilder(); - - String msg; - if (e != null) { - e.printStackTrace(new PrintWriter(new StringBuilderWriter(sb))); - } - for (int i = 0; i < msgs.length; ++i) { - if(msgs[i]!=null) { - msg = msgs[i].toString(); - if (msg != null && msg.length() > 0) { - int sbl = sb.length(); - if (sbl > 0) { - char last = sb.charAt(sbl - 1); - if (" (.".indexOf(last) < 0 - && "().".indexOf(msg.charAt(0)) < 0) - sb.append(' '); - } - sb.append(msg); - } - } - } - log.log(level, sb.toString()); - } - } - - /* (non-Javadoc) - * @see com.att.inno.env.LogTarget#printf(java.lang.String, java.lang.String[]) - */ - @Override - public void printf(String fmt, Object ... vars) { - if(log.isEnabledFor(level)) { - log.log(level,String.format(fmt,vars)); - } - } - - public static void setLog4JEnv(String loggerName, BasicEnv env) throws APIException { - env.fatal = new Log4JLogTarget(loggerName,Level.FATAL); - env.error = new Log4JLogTarget(loggerName,Level.ERROR); - env.warn = env.audit = env.init = new Log4JLogTarget(loggerName,Level.WARN); - env.info = new Log4JLogTarget(loggerName,Level.INFO); - env.debug = new Log4JLogTarget(loggerName,Level.DEBUG); - env.trace = new Log4JLogTarget(loggerName,Level.TRACE); - } - -} 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 deleted file mode 100644 index 1897195..0000000 --- a/env/src/main/java/com/att/inno/env/impl/NullLifeCycle.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -/** - * - */ -package com.att.inno.env.impl; - -import com.att.inno.env.APIException; -import com.att.inno.env.Env; -import com.att.inno.env.LifeCycle; - - - -/** - *

NullLifeCycle

- * - * This is a convenience class for those Objects which should - * implement LifeCycle, but don't have anything to do in any of the - * LifeCycle methods defined. Extending - * NullLifeCycle reduces the required methods for the class by 5. - * Any one or two of them can be overloaded.

- * - * If more are overloaded, it is - * recommended just to implement LifeCycle. - *

- * - * This only works, though, if the Object doesn't need to extend something - * else, due to Java's Single Extension policy. In other cases, just - * implement LifeCycle, and leave them empty. - * - * - */ -public class NullLifeCycle implements LifeCycle { - public void servicePrestart(Env env) throws APIException {} - public void threadPrestart(Env env) throws APIException {} - public void refresh(Env env) throws APIException {} - public void threadDestroy(Env env) throws APIException {} - public void serviceDestroy(Env env) throws APIException {} -} 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 deleted file mode 100644 index d2ef3c6..0000000 --- a/env/src/main/java/com/att/inno/env/jaxb/JAXBDF.java +++ /dev/null @@ -1,310 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.jaxb; - -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.StringWriter; -import java.io.Writer; - -import javax.xml.bind.JAXBException; -import javax.xml.namespace.QName; -import javax.xml.validation.Schema; - -import com.att.inno.env.APIException; -import com.att.inno.env.BaseDataFactory; -import com.att.inno.env.Data; -import com.att.inno.env.Env; -import com.att.inno.env.EnvJAXB; -import com.att.inno.env.TimeTaken; -import com.att.inno.env.old.IOObjectifier; -import com.att.inno.env.old.IOStringifier; -import com.att.inno.env.old.OldDataFactory; - -public class JAXBDF extends BaseDataFactory implements OldDataFactory,IOObjectifier, IOStringifier { - // Package on purpose - EnvJAXB primaryEnv; - JAXBumar jumar; - JAXBmar jmar; - - public JAXBDF(EnvJAXB env, Class ... classes) throws APIException { - try { - primaryEnv = env; - jumar = new JAXBumar(classes); - jmar = new JAXBmar(classes) ; - } catch (JAXBException e) { - throw new APIException(e); - } - } - - public JAXBDF(EnvJAXB env, Schema schema, Class ... classes) throws APIException { - try { - primaryEnv = env; - jumar = new JAXBumar(schema, classes); - jmar = new JAXBmar(classes); - } catch (JAXBException e) { - throw new APIException(e); - } - } - - public JAXBDF(EnvJAXB env, QName qname, Class ... classes) throws APIException { - try { - primaryEnv = env; - jumar = new JAXBumar(classes); - jmar = new JAXBmar(qname, classes); - } catch (JAXBException e) { - throw new APIException(e); - } - } - - public JAXBDF(EnvJAXB env, Schema schema, QName qname, Class ... classes) throws APIException { - try { - primaryEnv = env; - jumar = new JAXBumar(schema, classes); - jmar = new JAXBmar(qname, classes); - } catch (JAXBException e) { - throw new APIException(e); - } - } - - // @Override - public T newInstance() throws APIException { - try { - return jumar.newInstance(); - } catch (Exception e) { - throw new APIException(e); - } - } - - // @Override - public IOStringifier pretty(boolean pretty) { - jmar.pretty(pretty); - return this; - } - - // @Override - public IOStringifier asFragment(boolean fragment) { - jmar.asFragment(fragment); - return this; - } - - // @Override - public void servicePrestart(Env env) throws APIException { - } - - // @Override - public void threadPrestart(Env env) throws APIException { - } - - // @Override - public void refresh(Env env) throws APIException { - } - - // @Override - public void threadDestroy(Env env) throws APIException { - } - - // @Override - public void serviceDestroy(Env env) throws APIException { - } - - @SuppressWarnings("unchecked") - // @Override - public Data newData() { - return new JAXBData(primaryEnv, this, new JAXBStringifier(jmar), new JAXBObjectifier(jumar),"",(Class)jmar.getMarshalClass()); - } - - @SuppressWarnings("unchecked") - // @Override - public Data newData(Env env) { - return new JAXBData(env, this,new JAXBStringifier(jmar), new JAXBObjectifier(jumar),"",(Class)jmar.getMarshalClass()); - } - - // @Override - public Data newData(T type) { - return new JAXBData(primaryEnv, this, new JAXBStringifier(jmar), new JAXBObjectifier(jumar), type); - } - - // @Override - public Data newDataFromStream(Env env, InputStream input) throws APIException { - //TODO Write an unvalidated String using STAX checking for end of Doc? - // perhaps key evaluation as well. - try { - T t = jumar.unmarshal(env.debug(), input); - return new JAXBData(primaryEnv, this, new JAXBStringifier(jmar), new JAXBObjectifier(jumar),t); - } catch(JAXBException e) { - throw new APIException(e); - } - } - - @SuppressWarnings("unchecked") - // @Override - public Data newDataFromString(String string) { - return new JAXBData(primaryEnv, this,new JAXBStringifier(jmar), new JAXBObjectifier(jumar), string,(Class)jmar.getMarshalClass()); - } - - /////////// Old DataFactory Interface - // @Override - public String stringify(T type) throws APIException { - try { - StringWriter sw = new StringWriter(); - jmar.marshal(primaryEnv.debug(), type, sw); - return sw.toString(); - } catch (JAXBException e) { - throw new APIException(e); - } - } - - // @Override - public void stringify(T type, Writer writer) throws APIException { - try { - jmar.marshal(primaryEnv.debug(), type, writer); - } catch (JAXBException e) { - throw new APIException(e); - } - } - - // @Override - public void stringify(T type, OutputStream os) throws APIException { - try { - jmar.marshal(primaryEnv.debug(), type, os); - } catch (JAXBException e) { - throw new APIException(e); - } - } - - /////////// New DataFactory Interface - // @Override - public String stringify(Env env, T input, boolean ... options) throws APIException { - try { - StringWriter sw = new StringWriter(); - TimeTaken tt = env.start("JAXB Stringify", Env.XML); - try { - jmar.marshal(env.debug(), input, sw, options); - } finally { - tt.done(); - } - String str = sw.toString(); - tt.size(str.getBytes().length); - return str; - } catch (JAXBException e) { - throw new APIException(e); - } - } - - // @Override - public void stringify(Env env, T input, Writer writer, boolean ... options) throws APIException { - TimeTaken tt = env.start("JAXB Stringify", Env.XML); - try { - jmar.marshal(env.debug(), input, writer, options); - } catch (JAXBException e) { - throw new APIException(e); - } finally { - tt.done(); - } - } - - // @Override - public void stringify(Env env, T input, OutputStream os, boolean ... options) throws APIException { - TimeTaken tt = env.start("JAXB Stringify", Env.XML); - try { - jmar.marshal(env.debug(), input, os, options); - } catch (JAXBException e) { - throw new APIException(e); - } finally { - tt.done(); - } - } - - // @Override - public T objectify(Env env, Reader rdr) throws APIException { - TimeTaken tt = env.start("JAXB Objectify", Env.XML); - try { - return jumar.unmarshal(env.debug(), rdr); - } catch (JAXBException e) { - throw new APIException(e); - } finally { - tt.done(); - } - } - - // @Override - public T objectify(Reader rdr) throws APIException { - try { - return jumar.unmarshal(primaryEnv.debug(), rdr); - } catch (JAXBException e) { - throw new APIException(e); - } - } - - // @Override - public T objectify(Env env, InputStream is) throws APIException { - TimeTaken tt = env.start("JAXB Objectify", Env.XML); - try { - return jumar.unmarshal(env.debug(), is); - } catch (JAXBException e) { - throw new APIException(e); - } finally { - tt.done(); - } - } - - // @Override - public T objectify(InputStream is) throws APIException { - try { - return jumar.unmarshal(primaryEnv.debug(), is); - } catch (JAXBException e) { - throw new APIException(e); - } - } - - // @Override - public T objectify(Env env, String input) throws APIException { - TimeTaken tt = env.start("JAXB Objectify", Env.XML); - tt.size(input.getBytes().length); - try { - return jumar.unmarshal(env.debug(), input); - } catch (JAXBException e) { - throw new APIException(e); - } finally { - tt.done(); - } - } - - // @Override - public T objectify(String text) throws APIException { - try { - return jumar.unmarshal(primaryEnv.debug(), text); - } catch (JAXBException e) { - throw new APIException(e); - } - } - - @SuppressWarnings("unchecked") - // @Override - public Class getTypeClass() { - return (Class)jmar.getMarshalClass(); - } - -} 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 deleted file mode 100644 index 9f51edb..0000000 --- a/env/src/main/java/com/att/inno/env/jaxb/JAXBData.java +++ /dev/null @@ -1,321 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.jaxb; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.Writer; - -import javax.xml.bind.JAXBException; - -import com.att.inno.env.APIException; -import com.att.inno.env.Data; -import com.att.inno.env.Env; -import com.att.inno.env.EnvJAXB; -import com.att.inno.env.old.IOStringifier; -import com.att.inno.env.old.Objectifier; -import com.att.inno.env.old.Stringifier; -/** - *

Data

- * Data facilitates lazy marshaling of data with a pre-determined - * marshaling mechanism.

- * - * It stores either Object (defined by Generic {@literal }) or String.

- * - * On asking for Object of type {@literal }, it will respond with the object - * if it exists, or unmarshal the string and pass the result back.

- * - * On asking for String, it will respond with the String - * if it exists, or marshal the String and pass the result back.

- * - * - * @param - */ -public final class JAXBData implements Data{ - private Stringifier stringifier; - private Objectifier objectifier; - private String dataAsString; - private T dataAsObject; - private Class tclass; - private JAXBDF df; - private Env creatingEnv; - private boolean options[] = new boolean[] {false, false}; - - /** - * Construct a Data Object with an appropriate Stringifier, Objectifier and Class to support - * - * @param env - * @param strfr - * @param objfr - * @param text - * @param typeClass - */ - JAXBData(Env env, JAXBDF df, Stringifier strfr, Objectifier objfr, String text, Class typeClass) { - dataAsString = text; - dataAsObject = null; - stringifier = strfr; - objectifier = objfr; - tclass = typeClass; - creatingEnv = env; - this.df = df; - } - - - /** - * Construct a Data Object with an appropriate Stringifier, Objectifier and Object (which will - * yield it's class) - * - * @param env - * @param strfr - * @param objfr - * @param object - */ - @SuppressWarnings("unchecked") - JAXBData(Env env, JAXBDF df, Stringifier strfr, Objectifier objfr, T object) { - dataAsString = null; - dataAsObject = object; - stringifier = strfr; - objectifier = objfr; - tclass = (Class) object.getClass(); - creatingEnv = env; - this.df = df; - } - - /** - * Respond with the String if it exists, or marshal the String and pass the result back.

- * - * Explicitly use a specific Env for logging purposes - * - * @param env - * @return String - * @throws APIException - */ - public String asString(EnvJAXB env) throws APIException { - if(dataAsString!=null) { - return dataAsString; - } else { - return dataAsString = stringifier.stringify(env, dataAsObject); - } - } - - /** - * Respond with the String if it exists, or marshal the String and pass the result back. - * - * However, use the Env the Data Object was created with. - * - * @return String - * @throws APIException - */ - // @Override - public String asString() throws APIException { - if(dataAsString!=null) { - return dataAsString; - } else { - return dataAsString = stringifier.stringify(creatingEnv, dataAsObject,options); - } - } - - public Data to(OutputStream os) throws APIException, IOException { - if(dataAsString!=null) { - os.write(dataAsString.getBytes()); - } else if (stringifier instanceof IOStringifier){ - ((IOStringifier)stringifier).stringify(creatingEnv, dataAsObject, os, options); - } else { - dataAsString = stringifier.stringify(creatingEnv, dataAsObject, options); - os.write(dataAsString.getBytes()); - } - return this; - } - - - // @Override - public JAXBData to(Writer writer) throws APIException, IOException { - if(dataAsString!=null) { - writer.write(dataAsString); - } else if (stringifier instanceof IOStringifier){ - ((IOStringifier)stringifier).stringify(creatingEnv, dataAsObject, writer, options); - } else { - dataAsString = stringifier.stringify(creatingEnv, dataAsObject, options); - writer.write(dataAsString); - } - return this; - } - - - public InputStream getInputStream() throws APIException { - if(dataAsString==null) { - dataAsString = stringifier.stringify(creatingEnv,dataAsObject,options); - } - return new ByteArrayInputStream(dataAsString.getBytes()); - } - - /** - * Respond with the Object of type {@literal } if it exists, or unmarshal from String - * and pass the result back.

- * - * Explicitly use a specific Env for logging purposes - * - * @param env - * @return T - * @throws APIException - */ - - public T asObject(EnvJAXB env) throws APIException { - if(dataAsObject !=null) { - return dataAsObject; - } else { - // Some Java compilers need two statements here - dataAsObject = objectifier.objectify(env, dataAsString); - return dataAsObject; - } - } - - /** - * Respond with the Object of type {@literal } if it exists, or unmarshal from String - * and pass the result back.

- * - * However, use the Env the Data Object was created with. - * - * @return T - * @throws APIException - */ - // @Override - public T asObject() throws APIException { - if(dataAsObject !=null) { - return dataAsObject; - } else { - // Some Java compilers need two statements here - dataAsObject = objectifier.objectify(creatingEnv, dataAsString); - return dataAsObject; - } - } - - - /** - * Return the Class Type supported by this DataObject - * - * @return {@literal Class} - */ - // @Override - public Class getTypeClass() { - return tclass; - } - - - /** - * For Debugging Convenience, we marshal to String if possible. - * - * Behavior is essentially the same as asString(), except asString() throws - * an APIException.

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

- * - * Therefore, use "asString()" where possible in actual Transactional code. - * - * @see java.lang.Object#toString() - */ - // @Override - public String toString() { - if(dataAsString!=null) { - return dataAsString; - } else { - try { - return dataAsString = stringifier.stringify(creatingEnv, dataAsObject); - } catch (APIException e) { - return "ERROR - Can't Stringify from Object " + e.getLocalizedMessage(); - } - } - } - - public Data load(T t) throws APIException { - dataAsObject = t; - dataAsString = null; - return this; - } - - - public Data load(String str) throws APIException { - dataAsObject = null; - dataAsString = str; - return this; - } - - - public Data load(InputStream is) throws APIException { - try { - dataAsObject = df.jumar.unmarshal(creatingEnv.debug(),is); - dataAsString = null; - } catch (JAXBException e) { - throw new APIException(e); - } - return this; - } - - - public Data load(Reader rdr) throws APIException { - try { - dataAsObject = df.jumar.unmarshal(creatingEnv.debug(),rdr); - dataAsString = null; - } catch (JAXBException e) { - throw new APIException(e); - } - return this; - } - - - // @Override - public void direct(InputStream input, OutputStream output) throws APIException, IOException { - byte b[] = new byte[128]; - int count; - do { - count = input.read(b); - if(count>0)output.write(b, 0, count); - } while(count>=0); - } - - - // @Override - public Data out(TYPE type) { - // it's going to be XML regardless... - return this; - } - - - // @Override - public Data in(TYPE type) { - // Not Supported... will still be XML - return this; - } - - - // @Override - public Data option(int option) { - options[0] = (option&Data.PRETTY)==Data.PRETTY; - options[1] = (option&Data.FRAGMENT)==Data.FRAGMENT; - return this; - } - -} diff --git a/env/src/main/java/com/att/inno/env/jaxb/JAXBObjectifier.java b/env/src/main/java/com/att/inno/env/jaxb/JAXBObjectifier.java deleted file mode 100644 index c311c9f..0000000 --- a/env/src/main/java/com/att/inno/env/jaxb/JAXBObjectifier.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.jaxb; - -import java.io.InputStream; -import java.io.Reader; - -import javax.xml.bind.JAXBException; -import javax.xml.validation.Schema; - -import com.att.inno.env.APIException; -import com.att.inno.env.Env; -import com.att.inno.env.TimeTaken; -import com.att.inno.env.old.IOObjectifier; - -/** - * Allow Extended IO interface usage without muddying up the Stringifier Interface - */ -public class JAXBObjectifier implements IOObjectifier { - private JAXBumar jumar; - - public JAXBObjectifier(Schema schema, Class... classes) throws APIException { - try { - jumar = new JAXBumar(schema, classes); - } catch (JAXBException e) { - throw new APIException(e); - } - } - - public JAXBObjectifier(Class... classes) throws APIException { - try { - jumar = new JAXBumar(classes); - } catch (JAXBException e) { - throw new APIException(e); - } - } - - // package on purpose - JAXBObjectifier(JAXBumar jumar) { - this.jumar = jumar; - } - - @SuppressWarnings("unchecked") - // @Override - public T objectify(Env env, String input) throws APIException { - TimeTaken tt = env.start("JAXB Unmarshal", Env.XML); - try { - tt.size(input.length()); - return (T)jumar.unmarshal(env.debug(), input); - } catch (JAXBException e) { - throw new APIException(e); - } finally { - tt.done(); - } - } - - @SuppressWarnings("unchecked") - // @Override - public T objectify(Env env, Reader rdr) throws APIException { - //TODO create a Reader that Counts? - TimeTaken tt = env.start("JAXB Unmarshal", Env.XML); - try { - return (T)jumar.unmarshal(env.debug(), rdr); - } catch (JAXBException e) { - throw new APIException(e); - } finally { - tt.done(); - } - } - - - @SuppressWarnings("unchecked") - // @Override - public T objectify(Env env, InputStream is) throws APIException { - //TODO create a Reader that Counts? - TimeTaken tt = env.start("JAXB Unmarshal", Env.XML); - try { - return (T)jumar.unmarshal(env.debug(), is); - } catch (JAXBException e) { - throw new APIException(e); - } finally { - tt.done(); - } - } - - - public void servicePrestart(Env env) throws APIException { - } - - public void threadPrestart(Env env) throws APIException { - } - - // // @Override - public void refresh(Env env) throws APIException { - } - - // // @Override - public void threadDestroy(Env env) throws APIException { - } - - // // @Override - public void serviceDestroy(Env env) throws APIException { - } - - - @SuppressWarnings("unchecked") - public T newInstance() throws APIException { - try { - return (T)jumar.newInstance(); - } catch (Exception e) { - throw new APIException(e); - } - } - -} - diff --git a/env/src/main/java/com/att/inno/env/jaxb/JAXBStringifier.java b/env/src/main/java/com/att/inno/env/jaxb/JAXBStringifier.java deleted file mode 100644 index c98214b..0000000 --- a/env/src/main/java/com/att/inno/env/jaxb/JAXBStringifier.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.jaxb; - -import java.io.OutputStream; -import java.io.StringWriter; -import java.io.Writer; - -import javax.xml.bind.JAXBException; -import javax.xml.namespace.QName; - -import com.att.inno.env.APIException; -import com.att.inno.env.Env; -import com.att.inno.env.TimeTaken; -import com.att.inno.env.old.IOStringifier; - -public class JAXBStringifier implements IOStringifier { - private JAXBmar jmar; - - public JAXBStringifier(Class... classes) throws APIException { - try { - jmar = new JAXBmar(classes); - } catch (JAXBException e) { - throw new APIException(e); - } - } - - public JAXBStringifier(QName qname, Class... classes) - throws APIException { - try { - jmar = new JAXBmar(qname, classes); - } catch (JAXBException e) { - throw new APIException(e); - } - } - - // package on purpose - JAXBStringifier(JAXBmar jmar) { - this.jmar = jmar; - } - - // // @Override - public void stringify(Env env, T input, Writer writer, boolean ... options) - throws APIException { - TimeTaken tt = env.start("JAXB Marshal", Env.XML); - try { - jmar.marshal(env.debug(), input, writer, options); - } catch (JAXBException e) { - throw new APIException(e); - } finally { - tt.done(); - } - } - - // @Override - public void stringify(Env env, T input, OutputStream os, boolean ... options) - throws APIException { - // TODO create an OutputStream that Counts? - TimeTaken tt = env.start("JAXB Marshal", Env.XML); - try { - jmar.marshal(env.debug(), input, os, options); - } catch (JAXBException e) { - throw new APIException(e); - } finally { - tt.done(); - } - } - - // @Override - public String stringify(Env env, T input, boolean ... options) throws APIException { - TimeTaken tt = env.start("JAXB Marshal", Env.XML); - StringWriter sw = new StringWriter(); - try { - jmar.marshal(env.debug(), input, sw, options); - String rv = sw.toString(); - tt.size(rv.length()); - return rv; - } catch (JAXBException e) { - tt.size(0); - throw new APIException(e); - } finally { - tt.done(); - } - } - - // // @Override - public void servicePrestart(Env env) throws APIException { - } - - // // @Override - public void threadPrestart(Env env) throws APIException { - } - - // // @Override - public void refresh(Env env) throws APIException { - } - - // // @Override - public void threadDestroy(Env env) throws APIException { - } - - // // @Override - public void serviceDestroy(Env env) throws APIException { - } - - // @Override - public JAXBStringifier pretty(boolean pretty) { - jmar.pretty(pretty); - return this; - } - - // @Override - public JAXBStringifier asFragment(boolean fragment) { - jmar.asFragment(fragment); - return this; - } - -} 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 deleted file mode 100644 index dbdf092..0000000 --- a/env/src/main/java/com/att/inno/env/jaxb/JAXBmar.java +++ /dev/null @@ -1,253 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -/** - * JAXBumar.java - * - * Created on: Apr 10, 2009 - * Created by: - * - * Revamped to do away with ThreadLocal 5/27/2011, - * - * (c) 2009 SBC Knowledge Ventures, L.P. All rights reserved. - ******************************************************************* - * RESTRICTED - PROPRIETARY INFORMATION The Information contained - * herein is for use only by authorized employees of AT&T Services, - * Inc., and authorized Affiliates of AT&T Services, Inc., and is - * not for general distribution within or outside the respective - * companies. - ******************************************************************* - */ -package com.att.inno.env.jaxb; - -import java.io.OutputStream; -import java.io.StringWriter; -import java.io.Writer; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.namespace.QName; - -import com.att.inno.env.APIException; -import com.att.inno.env.LogTarget; -import com.att.inno.env.util.Pool; -import com.att.inno.env.util.Pool.Pooled; - -/** - * JAXBmar classes are inexpensive for going in and out of scope - * and have been made thread safe via Pooling - - * - */ -public class JAXBmar { - // Need to store off possible JAXBContexts based on Class, which will be stored in Creator - private static Map[],Pool> pools = new HashMap[], Pool>(); - - // Handle Marshaller class setting of properties only when needed - private class PMarshaller { - private Marshaller m; - private boolean p; - private boolean f; - - public PMarshaller(Marshaller marshaller) throws JAXBException { - m = marshaller; - m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); - m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, p = false); - m.setProperty(Marshaller.JAXB_FRAGMENT, f = false); - } - - public Marshaller get(boolean pretty, boolean fragment) throws JAXBException { - if(pretty != p) { - m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, p = pretty); - } - if(fragment != f) { - m.setProperty(Marshaller.JAXB_FRAGMENT, f = fragment); - } - return m; - } - } - - private class Creator implements Pool.Creator { - private JAXBContext jc; - private String name; - public Creator(Class[] classes) throws JAXBException { - jc = JAXBContext.newInstance(classes); - name = "JAXBmar: " + classes[0].getName(); - } - - // @Override - public PMarshaller create() throws APIException { - try { - return new PMarshaller(jc.createMarshaller()); - } catch (JAXBException e) { - throw new APIException(e); - } - } - - public String toString() { - return name; - } - - // @Override - public void reuse(PMarshaller pm) { - // Nothing to do - } - - // @Override - public void destroy(PMarshaller pm) { - // Nothing to do - } - - // @Override - public boolean isValid(PMarshaller t) { - return true; - } - } - - //TODO isn't UTF-8 a standard string somewhere for encoding? - private boolean fragment= false; - private boolean pretty=false; - private QName qname; - - private Pool mpool; // specific Pool associated with constructed Classes - private Class cls; - - private Pool getPool(Class ... classes) throws JAXBException { - Pool mp; - synchronized(pools) { - mp = pools.get(classes); - if(mp==null) { - pools.put(classes,mp = new Pool(new Creator(classes))); - } - } - return mp; - } - - public JAXBmar(Class... classes) throws JAXBException { - cls = classes[0]; - mpool = getPool(classes); - qname = null; - } - - public JAXBmar(QName theQname, Class... classes) throws JAXBException { - cls = classes[0]; - mpool = getPool(classes); - qname = theQname; - } - - @SuppressWarnings("unchecked") - public O marshal(LogTarget lt,O o, Writer writer, boolean ... options) throws JAXBException, APIException { - boolean pretty, fragment; - pretty = options.length>0?options[0]:this.pretty; - fragment = options.length>1?options[1]:this.fragment; - Pooled m = mpool.get(lt); - try { - if(qname==null) { - m.content.get(pretty,fragment).marshal(o, writer); - } else { - m.content.get(pretty,fragment).marshal( - new JAXBElement(qname, (Class)cls, o ), - writer); - } - return o; - } finally { - m.done(); - } - } - - @SuppressWarnings("unchecked") - public O marshal(LogTarget lt, O o, OutputStream os, boolean ... options) throws JAXBException, APIException { - boolean pretty, fragment; - pretty = options.length>0?options[0]:this.pretty; - fragment = options.length>1?options[1]:this.fragment; - Pooled m = mpool.get(lt); - try { - if(qname==null) { - m.content.get(pretty,fragment).marshal(o, os); - } else { - m.content.get(pretty,fragment).marshal( - new JAXBElement(qname, (Class)cls, o ),os); - } - return o; - } finally { - m.done(); - } - } - - public O marshal(LogTarget lt, O o, Writer writer, Class clss) throws JAXBException, APIException { - Pooled m = mpool.get(lt); - try { - if(qname==null) { - m.content.get(pretty,fragment).marshal(o, writer); - } else { - m.content.get(pretty,fragment).marshal( - new JAXBElement(qname, clss, o),writer); - } - return o; - } finally { - m.done(); - } - - } - - public O marshal(LogTarget lt, O o, OutputStream os, Class clss) throws JAXBException, APIException { - Pooled m = mpool.get(lt); - try { - if(qname==null) { - m.content.get(pretty,fragment).marshal(o, os); - } else { - m.content.get(pretty,fragment).marshal( - new JAXBElement(qname, clss, o ),os); - } - return o; - } finally { - m.done(); - } - } - - /** - * @return - */ - public Class getMarshalClass() { - return cls; - } - - public String stringify(LogTarget lt, O o) throws JAXBException, APIException { - StringWriter sw = new StringWriter(); - marshal(lt,o,sw); - return sw.toString(); - } - - public JAXBmar pretty(boolean pretty) { - this.pretty = pretty; - return this; - } - - public JAXBmar asFragment(boolean fragment) { - this.fragment = fragment; - return this; - } -} diff --git a/env/src/main/java/com/att/inno/env/jaxb/JAXBumar.java b/env/src/main/java/com/att/inno/env/jaxb/JAXBumar.java deleted file mode 100644 index eab30e6..0000000 --- a/env/src/main/java/com/att/inno/env/jaxb/JAXBumar.java +++ /dev/null @@ -1,243 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -/** - * JAXBumar.java - * - * Created on: Apr 10, 2009 - * Created by: - * - * Revamped to do away with ThreadLocal 5/27/2011, - * - * (c) 2009 SBC Knowledge Ventures, L.P. All rights reserved. - ******************************************************************* - * RESTRICTED - PROPRIETARY INFORMATION The Information contained - * herein is for use only by authorized employees of AT&T Services, - * Inc., and authorized Affiliates of AT&T Services, Inc., and is - * not for general distribution within or outside the respective - * companies. - ******************************************************************* - */ -package com.att.inno.env.jaxb; - -import java.io.File; -import java.io.InputStream; -import java.io.Reader; -import java.io.StringReader; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; -import javax.xml.stream.XMLEventReader; -import javax.xml.stream.XMLStreamReader; -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.Schema; - -import org.w3c.dom.Node; - -import com.att.inno.env.APIException; -import com.att.inno.env.LogTarget; -import com.att.inno.env.util.Pool; -import com.att.inno.env.util.Pool.Pooled; - -/** - * JAXBumar classes are inexpensive for going in and out of scope - * and have been made thread safe via Pooling - * - */ -public class JAXBumar { - // Need to store off possible JAXBContexts based on Class, which will be stored in Creator - private static Map[],Pool> pools = new HashMap[], Pool>(); - - private Class cls; - private Schema schema; - private Pool mpool;; - - // Handle Marshaller class setting of properties only when needed - private class SUnmarshaller { - private Unmarshaller u; - private Schema s; - - public SUnmarshaller(Unmarshaller unmarshaller) throws JAXBException { - u = unmarshaller; - s = null; - } - - public Unmarshaller get(Schema schema) throws JAXBException { - if(s != schema) { - u.setSchema(s = schema); - } - return u; - } - } - - private class Creator implements Pool.Creator { - private JAXBContext jc; - private String name; - - public Creator(Class[] classes) throws JAXBException { - jc = JAXBContext.newInstance(classes); - name = "JAXBumar: " + classes[0].getName(); - } - - // @Override - public SUnmarshaller create() throws APIException { - try { - return new SUnmarshaller(jc.createUnmarshaller()); - } catch (JAXBException e) { - throw new APIException(e); - } - } - - public String toString() { - return name; - } - - // @Override - public void destroy(SUnmarshaller sui) { - // Nothing to do - } - - // @Override - public boolean isValid(SUnmarshaller t) { - return true; - } - - // @Override - public void reuse(SUnmarshaller t) { - // Nothing to do here - } - - } - - private Pool getPool(Class ... classes) throws JAXBException { - Pool mp; - synchronized(pools) { - mp = pools.get(classes); - if(mp==null) { - pools.put(classes,mp = new Pool(new Creator(classes))); - } - } - return mp; - } - - public JAXBumar(Class ... classes) throws JAXBException { - cls = classes[0]; - mpool = getPool(classes); - schema = null; - } - - /** - * Constructs a new JAXBumar with schema validation enabled. - * - * @param schema - * @param theClass - * @throws JAXBException - */ - public JAXBumar(Schema schema, Class ... classes) throws JAXBException { - cls = classes[0]; - mpool = getPool(classes); - this.schema = schema; - } - - @SuppressWarnings("unchecked") - public O unmarshal(LogTarget env, Node node) throws JAXBException, APIException { - Pooled s = mpool.get(env); - try { - return s.content.get(schema).unmarshal(node,(Class)cls).getValue(); - } finally { - s.done(); - } - - } - - @SuppressWarnings("unchecked") - public O unmarshal(LogTarget env, String xml) throws JAXBException, APIException { - if(xml==null) throw new JAXBException("Null Input for String unmarshal"); - Pooled s = mpool.get(env); - try { - return (O)s.content.get(schema).unmarshal( - new StreamSource(new StringReader(xml)) - ,(Class)cls).getValue(); - } finally { - s.done(); - } - } - - @SuppressWarnings("unchecked") - public O unmarshal(LogTarget env, File xmlFile) throws JAXBException, APIException { - Pooled s = mpool.get(env); - try { - return (O)s.content.get(schema).unmarshal(xmlFile); - } finally { - s.done(); - } - - } - - @SuppressWarnings("unchecked") - public O unmarshal(LogTarget env,InputStream is) throws JAXBException, APIException { - Pooled s = mpool.get(env); - try { - return (O)s.content.get(schema).unmarshal(is); - } finally { - s.done(); - } - } - - @SuppressWarnings("unchecked") - public O unmarshal(LogTarget env, Reader rdr) throws JAXBException, APIException { - Pooled s = mpool.get(env); - try { - return (O)s.content.get(schema).unmarshal(rdr); - } finally { - s.done(); - } - } - - @SuppressWarnings("unchecked") - public O unmarshal(LogTarget env, XMLStreamReader xsr) throws JAXBException, APIException { - Pooled s = mpool.get(env); - try { - return (O)s.content.get(schema).unmarshal(xsr,(Class)cls).getValue(); - } finally { - s.done(); - } - } - - @SuppressWarnings("unchecked") - public O unmarshal(LogTarget env, XMLEventReader xer) throws JAXBException, APIException { - Pooled s = mpool.get(env); - try { - return (O)s.content.get(schema).unmarshal(xer,(Class)cls).getValue(); - } finally { - s.done(); - } - } - - @SuppressWarnings("unchecked") - public O newInstance() throws InstantiationException, IllegalAccessException{ - return ((Class)cls).newInstance(); - } -} diff --git a/env/src/main/java/com/att/inno/env/old/IOObjectifier.java b/env/src/main/java/com/att/inno/env/old/IOObjectifier.java deleted file mode 100644 index 9932e20..0000000 --- a/env/src/main/java/com/att/inno/env/old/IOObjectifier.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.old; - -import java.io.InputStream; -import java.io.Reader; - -import com.att.inno.env.APIException; -import com.att.inno.env.Env; - -public interface IOObjectifier extends Objectifier { - /** - * Marshal to Object T from a Reader, using contents from Env as necessary.

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

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return T - * @throws APIException - */ - public abstract T objectify(Env env, InputStream is) throws APIException; - -} 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 deleted file mode 100644 index 18ef170..0000000 --- a/env/src/main/java/com/att/inno/env/old/IOStringifier.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.old; - -import java.io.OutputStream; -import java.io.Writer; - -import com.att.inno.env.APIException; -import com.att.inno.env.Env; - -/** - * Allow Extended IO interface usage without muddying up the Stringifier Interface - */ -public interface IOStringifier extends Stringifier { - /** - * Marshal from an Object T onto a Writer, using contents from Env as necessary.

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

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return String - * @throws APIException - */ - public abstract void stringify(Env env, T input, OutputStream os, boolean ... options) throws APIException; - - /** - * Set Pretty XML, where possible - * - * @param pretty - * @throws APIException - */ - public abstract IOStringifier pretty(boolean pretty); - - /** - * Set Generate Fragment - * - * @param fragment - * @throws APIException - */ - public abstract IOStringifier asFragment(boolean fragment); - - -} 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 deleted file mode 100644 index 55e9685..0000000 --- a/env/src/main/java/com/att/inno/env/old/Objectifier.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -/** - * - */ -package com.att.inno.env.old; - -import com.att.inno.env.APIException; -import com.att.inno.env.Env; -import com.att.inno.env.LifeCycle; - - -/** - *

Objectifier

- * Objectifier abstracts the unmarshaling of an Object from a String, and - * the creation of an uninitialized object. - */ -public interface Objectifier extends LifeCycle { - /** - * Marshal to Object T from a String, using contents from Env as necessary.

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return T - * @throws APIException - */ - public abstract T objectify(Env env, String input) throws APIException; - - /** - * Create a new object of type T. This is often more efficiently done with - * the underlying XML (or other) Library. - * @return T - * @throws APIException - */ - public abstract T newInstance() throws APIException; - - -} 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 deleted file mode 100644 index 6bf0995..0000000 --- a/env/src/main/java/com/att/inno/env/old/OldDataFactory.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.old; - -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.Writer; - -import com.att.inno.env.APIException; -import com.att.inno.env.Data; -import com.att.inno.env.DataFactory; -import com.att.inno.env.Env; - -public interface OldDataFactory extends DataFactory { - public abstract String stringify(T type) throws APIException; - public abstract void stringify(T type, OutputStream os) throws APIException; - public abstract void stringify(T type, Writer writer) throws APIException; - public abstract T objectify(InputStream is) throws APIException; - public abstract T objectify(Reader rdr) throws APIException; - public abstract T objectify(String text) throws APIException; - public abstract T newInstance() throws APIException; - public abstract Data newData(T type); - public abstract Data newDataFromStream(Env env, InputStream input) throws APIException; - public abstract Data newDataFromString(String string); - -} - 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 deleted file mode 100644 index db9401f..0000000 --- a/env/src/main/java/com/att/inno/env/old/Stringifier.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.old; - -import com.att.inno.env.APIException; -import com.att.inno.env.Env; -import com.att.inno.env.LifeCycle; - - -/** - *

Stringifier

- * Stringifier abstracts the marshaling of a String to an Object - */ -public interface Stringifier extends LifeCycle { - - /** - * Marshal from a String to an Object T, using contents from Env as necessary.

- * - * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark - * XML time, since this is often a costly process. - * - * @param env - * @param input - * @return String - * @throws APIException - */ - public abstract String stringify(Env env, T input, boolean ... options) throws APIException; - -} 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 deleted file mode 100644 index 8b840d0..0000000 --- a/env/src/main/java/com/att/inno/env/util/Chrono.java +++ /dev/null @@ -1,307 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.util; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.GregorianCalendar; -import java.security.SecureRandom; -import java.util.TimeZone; -import java.util.UUID; -import java.util.logging.Formatter; -import java.util.logging.LogRecord; - -import javax.xml.datatype.DatatypeConfigurationException; -import javax.xml.datatype.DatatypeFactory; -import javax.xml.datatype.XMLGregorianCalendar; - -public class Chrono { - private static final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L; - - public final static DateFormat dateFmt, dateOnlyFmt, niceDateFmt, utcFmt; - // Give general access to XML DataType Factory, since it's pretty common - public static final DatatypeFactory xmlDatatypeFactory; - - static { - try { - xmlDatatypeFactory = DatatypeFactory.newInstance(); - } catch (DatatypeConfigurationException e) { - throw new RuntimeException(e); - } - dateOnlyFmt = new SimpleDateFormat("yyyy-MM-dd"); - niceDateFmt = new SimpleDateFormat("yyyy/MM/dd HH:mm zzz"); - dateFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); - utcFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); - utcFmt.setTimeZone(TimeZone.getTimeZone("UTC")); - } - - - public static class Formatter8601 extends Formatter { - - @Override - public String format(LogRecord r) { - StringBuilder sb = new StringBuilder(); - sb.append(dateFmt.format(new Date(r.getMillis()))); - sb.append(' '); - sb.append(r.getThreadID()); - sb.append(' '); - sb.append(r.getLevel()); - sb.append(": "); - sb.append(r.getMessage()); - sb.append('\n'); - return sb.toString(); - } - - } - - /** - * timeStamp - * - * Convenience method to setup an XML dateTime (XMLGregorianCalendar) with "now" - * @return - */ - public static XMLGregorianCalendar timeStamp() { - return xmlDatatypeFactory.newXMLGregorianCalendar(new GregorianCalendar()); - } - - /** - * timestamp - * - * Convenience method to setup an XML dateTime (XMLGregorianCalendar) with passed in Date - * @param date - * @return - */ - public static XMLGregorianCalendar timeStamp(Date date) { - GregorianCalendar gc = new GregorianCalendar(); - gc.setTime(date); - return xmlDatatypeFactory.newXMLGregorianCalendar(gc); - } - - public static XMLGregorianCalendar timeStamp(GregorianCalendar gc) { - return xmlDatatypeFactory.newXMLGregorianCalendar(gc); - } - - public static String utcStamp() { - return utcFmt.format(new Date()); - } - - public static String utcStamp(Date date) { - if(date==null)return ""; - return utcFmt.format(date); - } - - public static String utcStamp(GregorianCalendar gc) { - if(gc==null)return ""; - return utcFmt.format(gc.getTime()); - } - - public static String utcStamp(XMLGregorianCalendar xgc) { - if(xgc==null)return ""; - return utcFmt.format(xgc.toGregorianCalendar().getTime()); - } - - public static String dateStamp() { - return dateFmt.format(new Date()); - } - - public static String dateStamp(GregorianCalendar gc) { - if(gc == null)return ""; - return dateFmt.format(gc.getTime()); - } - - public static String dateStamp(Date date) { - if(date == null)return ""; - return dateFmt.format(date); - } - - public static String dateStamp(XMLGregorianCalendar xgc) { - if(xgc==null)return ""; - return dateFmt.format(xgc.toGregorianCalendar().getTime()); - } - - /** - * JAXB compatible dataTime Stamp - * - * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it. - * - * @return - */ - public static String dateTime() { - return dateTime(new GregorianCalendar()); - } - - /** - * JAXB compatible dataTime Stamp - * - * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it. - * - * @return - */ - public static String dateTime(Date date) { - GregorianCalendar gc = new GregorianCalendar(); - gc.setTime(date); - return dateTime(gc); - } - - /** - * JAXB compatible dataTime Stamp - * - * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it. - * - * @return - */ - public static String dateTime(GregorianCalendar gc) { - if(gc == null)return ""; - TimeZone tz = gc.getTimeZone(); - int tz1 = (tz.getRawOffset()+tz.getDSTSavings())/0x8CA0; - int tz1abs = Math.abs(tz1); - return String.format("%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d:%02d", - gc.get(GregorianCalendar.YEAR), - gc.get(GregorianCalendar.MONTH)+1, - gc.get(GregorianCalendar.DAY_OF_MONTH), - gc.get(GregorianCalendar.HOUR), - gc.get(GregorianCalendar.MINUTE), - gc.get(GregorianCalendar.SECOND), - gc.get(GregorianCalendar.MILLISECOND), - tz1==tz1abs?'+':'-', - tz1abs/100, - ((tz1abs-(tz1abs/100)*100)*6)/10 // Get the "10s", then convert to mins (without losing int place) - ); - } - - /** - * JAXB compatible dataTime Stamp - * - * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it. - * - * @return - */ - public static String dateTime(XMLGregorianCalendar xgc) { - return xgc==null?"":dateTime(xgc.toGregorianCalendar()); - } - - public static String dateOnlyStamp() { - return dateOnlyFmt.format(new Date()); - } - - public static String dateOnlyStamp(GregorianCalendar gc) { - return gc == null?"":dateOnlyFmt.format(gc.getTime()); - } - - public static String dateOnlyStamp(Date date) { - return date == null?"":dateOnlyFmt.format(date); - } - - public static String dateOnlyStamp(XMLGregorianCalendar xgc) { - return xgc==null?"":dateOnlyFmt.format(xgc.toGregorianCalendar().getTime()); - } - - public static String niceDateStamp() { - return niceDateFmt.format(new Date()); - } - - public static String niceDateStamp(Date date) { - return date==null?"":niceDateFmt.format(date); - } - - public static String niceDateStamp(GregorianCalendar gc) { - return gc==null?"":niceDateFmt.format(gc.getTime()); - } - - public static String niceDateStamp(XMLGregorianCalendar xgc) { - return xgc==null?"":niceDateFmt.format(xgc.toGregorianCalendar().getTime()); - } - - - ////////////////////// HELPFUL Strings - public static final String BAD_DIR_CHARS_REGEX = "[/:\\;.]"; - public static final String SPLIT_DIR_REGEX = "/"; - - public static long firstMomentOfDay(long utc) { - GregorianCalendar begin = new GregorianCalendar(); - begin.setTimeInMillis(utc); - return firstMomentOfDay(begin).getTimeInMillis(); - } - - public static long lastMomentOfDay(long utc) { - GregorianCalendar end = new GregorianCalendar(); - end.setTimeInMillis(utc); - return lastMomentOfDay(end).getTimeInMillis(); - } - - public static GregorianCalendar firstMomentOfDay(GregorianCalendar begin) { - if(begin==null)begin = new GregorianCalendar(); - begin.set(GregorianCalendar.HOUR, 0); - begin.set(GregorianCalendar.AM_PM, GregorianCalendar.AM); - begin.set(GregorianCalendar.MINUTE, 0); - begin.set(GregorianCalendar.SECOND, 0); - begin.set(GregorianCalendar.MILLISECOND, 0); - return begin; - } - - public static GregorianCalendar lastMomentOfDay(GregorianCalendar end) { - if(end==null)end = new GregorianCalendar(); - end.set(GregorianCalendar.HOUR, 11); - end.set(GregorianCalendar.MINUTE, 59); - end.set(GregorianCalendar.SECOND, 59); - end.set(GregorianCalendar.MILLISECOND, 999); - end.set(GregorianCalendar.AM_PM, GregorianCalendar.PM); - return end; - } - - // UUID needs to be converted from UUID Epoch - public static final Date uuidToDate(UUID id) { - return new Date((id.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH)/10000); - } - - public static final long uuidToUnix(UUID id) { - return (id.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH)/10000; - } - - public static float millisFromNanos(long start, long end) { - return (end - start) / 1000000f; - } - - - private static long sequence = new SecureRandom().nextInt(); - private static synchronized long sequence() { - return ++sequence; - } - public static final UUID dateToUUID(Date d) { - /* - * From Cassandra : http://wiki.apache.org/cassandra/FAQ - Magic number obtained from #cassandra's thobbs, who - claims to have stolen it from a Python library. - */ - - long origTime = d.getTime(); - long time = origTime * 10000 + NUM_100NS_INTERVALS_SINCE_UUID_EPOCH; - long timeLow = time & 0xffffffffL; - long timeMid = time & 0xffff00000000L; - long timeHi = time & 0xfff000000000000L; - long upperLong = (timeLow << 32) | (timeMid >> 16) | (1 << 12) | (timeHi >> 48) ; - return new java.util.UUID(upperLong, (0xC000000000000000L | sequence())); - } - -} diff --git a/env/src/main/java/com/att/inno/env/util/DoubleOutputStream.java b/env/src/main/java/com/att/inno/env/util/DoubleOutputStream.java deleted file mode 100644 index eab33b1..0000000 --- a/env/src/main/java/com/att/inno/env/util/DoubleOutputStream.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.util; - -import java.io.IOException; -import java.io.OutputStream; - -public class DoubleOutputStream extends OutputStream { - private OutputStream[] oss; - private boolean[] close; - - /** - * Create a Double Stream Writer - * Some Streams should not be closed by this object (i.e. System.out), therefore, mark them with booleans - */ - public DoubleOutputStream(OutputStream a, boolean closeA, OutputStream b, boolean closeB) { - oss = new OutputStream[] {a,b}; - close = new boolean[] {closeA,closeB}; - } - - /** - * Write a single character. - * @throws IOException - */ - @Override - public void write(int c) throws IOException { - for(OutputStream os : oss) { - os.write(c); - } - } - - /** - * Write a portion of an array of characters. - * - * @param bbuf Array of characters - * @param off Offset from which to start writing characters - * @param len Number of characters to write - * @throws IOException - */ - @Override - public void write(byte bbuf[], int off, int len) throws IOException { - for(OutputStream os : oss) { - os.write(bbuf,off,len); - } - } - - @Override - public void write(byte[] b) throws IOException { - for(OutputStream os : oss) { - os.write(b); - } - } - - /* (non-Javadoc) - * @see java.io.OutputStream#close() - */ - @Override - public void close() throws IOException { - for(int i=0;icol++)super.write((int)' '); - } - - public int getIndent() { - return indent; - } - - public void toIndent() { - int end = indent * INDENT; - for (int i = 0; i < end; ++i) { - super.write((int) ' '); - } - col = end; - } -} 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 deleted file mode 100644 index e8ba8ce..0000000 --- a/env/src/main/java/com/att/inno/env/util/Pool.java +++ /dev/null @@ -1,395 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -/* - * Pool - * - * 5/27/2011 - */ -package com.att.inno.env.util; - -import java.util.LinkedList; - -import com.att.inno.env.APIException; -import com.att.inno.env.LogTarget; - -/** - * This Class pools on an As-Needed-Basis any particular kind of class, which is - * quite suitable for expensive operations. - * - * The user calls "get" on a Pool, and if a waiting resource (T) is available, - * it will be returned. Otherwise, one will be created with the "Creator" class - * (must be defined for (T)). - * - * You can Prime the instances to avoid huge startup costs - * - * The returned "Pooled" object simply has to call "done()" and the object is - * returned to the pool. If the developer does not return the object, a memory - * leak does not occur. There are no references to the object once "get" is - * called. However, the developer who does not return the object when done - * obviates the point of the pool, as new Objects are created in place of the - * Object not returned when another call to "get" is made. - * - * There is a cushion of extra objects, currently defaulted to MAX_RANGE. If the - * items returned become higher than the MAX_RANGE, the object is allowed to go - * out of scope, and be cleaned up. the default can be changed on a per-pool - * basis. - * - * - * - * @param - */ -public class Pool { - /** - * This is a constant which specified the default maximum number of unused - * objects to be held at any given time. - */ - private static final int MAX_RANGE = 6; // safety - - /** - * only Simple List needed. - * - * NOTE TO MAINTAINERS: THIS OBJECT DOES IT'S OWN SYNCHRONIZATION. All - * changes that touch list must account for correctly synchronizing list. - */ - private LinkedList> list; - - /** - * keep track of how many elements exist, to avoid asking list. - */ - private int count; - - /** - * Spares are those Object that are primed and ready to go. - */ - private int spares; - - /** - * Actual MAX number of spares allowed to hang around. Can be set to - * something besides the default MAX_RANGE. - */ - private int max_range = MAX_RANGE; - - /** - * The Creator for this particular pool. It must work for type T. - */ - private Creator creator; - - /** - * Create a new Pool, given the implementation of Creator, which must be - * able to create/destroy T objects at will. - * - * @param creator - */ - public Pool(Creator creator) { - count = spares = 0; - this.creator = creator; - list = new LinkedList>(); - } - - /** - * Preallocate a certain number of T Objects. Useful for services so that - * the first transactions don't get hit with all the Object creation costs - * - * @param lt - * @param prime - * @throws APIException - */ - public void prime(LogTarget lt, int prime) throws APIException { - for (int i = 0; i < prime; ++i) { - Pooled pt = new Pooled(creator.create(), this, lt); - synchronized (list) { - list.addFirst(pt); - ++count; - } - } - - } - - /** - * Destroy and remove all remaining objects. This is valuable for closing - * down all Allocated objects cleanly for exiting. It is also a good method - * for removing objects when, for instance, all Objects are invalid because - * of broken connections, etc. - */ - public void drain() { - synchronized (list) { - for (int i = 0; i < list.size(); ++i) { - Pooled pt = list.remove(); - creator.destroy(pt.content); - pt.logTarget.log("Pool drained ", creator.toString()); - } - count = spares = 0; - } - - } - - /** - * This is the essential function for Pool. Get an Object "T" inside a - * "Pooled" object. If there is a spare Object, then use it. If not, then - * create and pass back. - * - * This one uses a Null LogTarget - * - * IMPORTANT: When the use of this object is done (and the object is still - * in a valid state), then "done()" should be called immediately to allow - * the object to be reused. That is the point of the Pool... - * - * If the Object is in an invalid state, then "toss()" should be used so the - * Pool doesn't pass on invalid objects to others. - * - * @param lt - * @return - * @throws APIException - */ - public Pooled get() throws APIException { - Pooled pt; - synchronized (list) { - if (list.isEmpty()) { - pt = null; - } else { - pt = list.removeLast(); - --count; - creator.reuse(pt.content); - } - } - if (pt == null) { - if (spares < max_range) - ++spares; - pt = new Pooled(creator.create(), this, LogTarget.NULL); - } else { - if (spares > 1) - --spares; - } - return pt; - } - - /** - * This is the essential function for Pool. Get an Object "T" inside a - * "Pooled" object. If there is a spare Object, then use it. If not, then - * create and pass back. - * - * If you don't have access to a LogTarget from Env, use LogTarget.NULL - * - * IMPORTANT: When the use of this object is done (and the object is still - * in a valid state), then "done()" should be called immediately to allow - * the object to be reused. That is the point of the Pool... - * - * If the Object is in an invalid state, then "toss()" should be used so the - * Pool doesn't pass on invalid objects to others. - * - * @param lt - * @return - * @throws APIException - */ - public Pooled get(LogTarget lt) throws APIException { - Pooled pt; - synchronized (list) { - if (list.isEmpty()) { - pt = null; - } else { - pt = list.remove(); - --count; - creator.reuse(pt.content); - } - } - if (pt == null) { - if (spares < max_range) - ++spares; - pt = new Pooled(creator.create(), this, lt); - lt.log("Pool created ", creator.toString()); - } else { - if (spares > 1) - --spares; - } - return pt; - } - - /** - * This function will validate whether the Objects are still in a usable - * state. If not, they are tossed from the Pool. This is valuable to have - * when Remote Connections go down, and there is a question on whether the - * Pooled Objects are still functional. - * - * @return - */ - public boolean validate() { - boolean rv = true; - synchronized (list) { - for (Pooled t : list) { - if (!creator.isValid(t.content)) { - rv = false; - t.toss(); - list.remove(t); - } - } - } - return rv; - } - - /** - * This is an internal method, used only by the Internal Pooled class. - * - * The Pooled class "offers" it's Object back after use. It is an - * "offer", because Pool will simply destroy and remove the object if it has - * more than enough spares. - * - * @param lt - * @param used - * @return - */ - // Used only by Pooled - private boolean offer(LogTarget lt, Pooled used) { - if (count < spares) { - synchronized (list) { - list.addFirst(used); - ++count; - } - lt.log("Pool recovered ", creator.toString()); - } else { - lt.log("Pool destroyed ", creator.toString()); - creator.destroy(used.content); - } - return false; - } - - /** - * The Creator Interface give the Pool the ability to Create, Destroy and - * Validate the Objects it is maintaining. Thus, it is a specially written - * Implementation for each type. - * - * - * @param - */ - public interface Creator { - public T create() throws APIException; - - public void destroy(T t); - - public boolean isValid(T t); - - public void reuse(T t); - } - - /** - * The "Pooled" class is the transient class that wraps the actual Object - * T for API use/ It gives the ability to return ("done()", or "toss()") the - * Object to the Pool when processing is finished. - * - * For Safety, i.e. to avoid memory leaks and invalid Object States, there - * is a "finalize" method. It is strictly for when coder forgets to return - * the object, or perhaps hasn't covered the case during Exceptions or - * Runtime Exceptions with finally (preferred). This should not be - * considered normal procedure, as finalize() is called at an undetermined - * time during garbage collection, and is thus rather useless for a Pool. - * However, we don't want Coding Mistakes to put the whole program in an - * invalid state, so if something happened such that "done()" or "toss()" - * were not called, the resource is still cleaned up as well as possible. - * - * - * @param - */ - public static class Pooled { - public final T content; - private Pool pool; - protected LogTarget logTarget; - - /** - * Create the Wrapping Object Pooled. - * - * @param t - * @param pool - * @param logTarget - */ - public Pooled(T t, Pool pool, LogTarget logTarget) { - content = t; - this.pool = pool; - this.logTarget = logTarget; - } - - /** - * This is the key API for the Pool, as calling "done()" offers this - * object back to the Pool for reuse. - * - * Do not use the Pooled object again after calling "done()". - */ - public void done() { - if (pool != null) { - pool.offer(logTarget, this); - } - } - - /** - * The user of the Object may discover that the Object t is no longer in - * a valid state. Don't put Garbage back in the Refrigerator... Toss it, - * if it's no longer valid. - * - * toss() is also used for draining the Pool, etc. - * - * toss() will attempt to destroy the Object by using the Creator - * Interface. - * - */ - public void toss() { - if (pool != null) { - pool.creator.destroy(content); - } - // Don't allow finalize to put it back in. - pool = null; - } - - /** - * Just in case someone neglected to offer back object... Do not rely on - * this, as there is no specific time when finalize is called, which - * rather defeats the purpose of a Pool. - */ - @Override - protected void finalize() throws Throwable { - if (pool != null) { - done(); - pool = null; - } - } - } - - /** - * Get the maximum number of spare objects allowed at any moment - * - * @return - */ - public int getMaxRange() { - return max_range; - } - - /** - * Set a Max Range for numbers of spare objects waiting to be used. - * - * No negative numbers are allowed - * - * @return - */ - public void setMaxRange(int max_range) { - // Do not allow negative numbers - this.max_range = Math.max(0, max_range); - } - -} 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 deleted file mode 100644 index 10bb8aa..0000000 --- a/env/src/main/java/com/att/inno/env/util/RefreshableThreadObject.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.util; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import com.att.inno.env.APIException; -import com.att.inno.env.Creatable; -import com.att.inno.env.Env; -import com.att.inno.env.LifeCycle; - - -/** - *

RefreshableThreadObject

- * This is a ThreadLocal like implementation, but it responds to - * the {@link LifeCycle} mechanism for configuration refreshes, and - * implements {@link Creatable} (for use in destroy, etc).

- * - * In addition to the Thread instance semantics, it compares when the object - * was created versus the last "refresh(env)" call when getting, for the - * thread, and if necessary to replace the created object, destroying the - * previous.

- * - * In most cases, it's better to use the new "Pool" mechanism, as it deals with - * gaining and returning resources on an as needed basis. This, however, remains - * in the cases where specific Objects need to be retained to specific Threads.

- * - * There is no way to do this kind of specialized behavior in ThreadLocal. - * - * - * @param - */ -public class RefreshableThreadObject> { - private Map objs; - private long refreshed; - private Constructor cnst; - - /** - * The passed in class must implement the constructor - *

-	 *   public MyClass(Env env) {
-	 *     ...
-	 *   }
-	 * 
- * @param clss - * @throws APIException - */ - public RefreshableThreadObject(Class clss) throws APIException { - objs = Collections.synchronizedMap(new HashMap()); - try { - cnst = clss.getConstructor(new Class[]{Env.class} ); - } catch (Exception e) { - throw new APIException(e); - } - } - - /** - * Get the "T" class from the current thread - * - * @param env - * @return T - * @throws APIException - */ - public T get(Env env) throws APIException { - Thread t = Thread.currentThread(); - T obj = objs.get(t); - if(obj==null || refreshed>obj.created()) { - try { - obj = cnst.newInstance(new Object[]{env}); - } catch (InvocationTargetException e) { - throw new APIException(e.getTargetException()); - } catch (Exception e) { - throw new APIException(e); - } - T destroyMe = objs.put(t,obj); - if(destroyMe!=null) { - destroyMe.destroy(env); - } - } - return obj; - } - - /** - * Mark the timestamp of refreshed. - * - * @param env - */ - public void refresh(Env env) { - refreshed = System.currentTimeMillis(); - } - - /** - * Remove the object from the Thread instances - * @param env - */ - public void remove(Env env) { - T obj = objs.remove(Thread.currentThread()); - if(obj!=null) - obj.destroy(env); - } -} diff --git a/env/src/main/java/com/att/inno/env/util/Split.java b/env/src/main/java/com/att/inno/env/util/Split.java deleted file mode 100644 index b813ac0..0000000 --- a/env/src/main/java/com/att/inno/env/util/Split.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.util; - -/** - * Split by Char, optional Trim - * - * Note: I read the String split and Pattern split code, and we can do this more efficiently for a single Character - * - * 8/20/2015 - */ - -public class Split { - public static String[] split(char c, String value) { - // Count items to preallocate Array (memory alloc is more expensive than counting twice) - int count,idx; - for(count=1,idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,++idx),++count); - String[] rv = new String[count]; - if(count==1) { - rv[0]=value; - } else { - int last=0; - count=-1; - for(idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,idx)) { - rv[++count]=value.substring(last,idx); - last = ++idx; - } - rv[++count]=value.substring(last); - } - return rv; - } - - public static String[] splitTrim(char c, String value) { - // Count items to preallocate Array (memory alloc is more expensive than counting twice) - int count,idx; - for(count=1,idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,++idx),++count); - String[] rv = new String[count]; - if(count==1) { - rv[0]=value.trim(); - } else { - int last=0; - count=-1; - for(idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,idx)) { - rv[++count]=value.substring(last,idx).trim(); - last = ++idx; - } - rv[++count]=value.substring(last).trim(); - } - return rv; - } - - public static String[] splitTrim(char c, String value, int size) { - int idx; - String[] rv = new String[size]; - if(size==1) { - rv[0]=value.trim(); - } else { - int last=0; - int count=-1; - size-=2; - for(idx=value.indexOf(c);idx>=0 && countbyte values that will fit into this buffer - * before it is automatically expanded - * - * @throws IllegalArgumentException - * If initialSize is negative - */ - public StringBuilderOutputStream(int initialSize) { - if (initialSize < 0) { - throw new IllegalArgumentException("Negative buffer size"); - } - buf = new StringBuilder(initialSize); - } - - /** - * Write a single character. - */ - public void write(int c) { - buf.append((byte) c); - } - - /** - * Write a portion of an array of characters. - * - * @param bbuf Array of characters - * @param off Offset from which to start writing characters - * @param len Number of characters to write - */ - - public void write(byte bbuf[], int off, int len) { - if ((off < 0) || (off > bbuf.length) || (len < 0) || - ((off + len) > bbuf.length) || ((off + len) < 0)) { - throw new IndexOutOfBoundsException(); - } else if (len == 0) { - return; - } - buf.append(new String(bbuf, off, len)); - } - - @Override - public void write(byte[] b) throws IOException { - buf.append(new String(b)); - } - - /** - * Write a string. - */ - public void write(String str) { - buf.append(str); - } - - /** - * Write a portion of a string. - * - * @param str String to be written - * @param off Offset from which to start writing characters - * @param len Number of characters to write - */ - public void write(String str, int off, int len) { - buf.append(str,off,len); - } - - public StringBuilderOutputStream append(CharSequence csq) { - if (csq == null) { - write("null"); - } else { - for(int i = 0;i An invocation of this method of the form out.append(c) - * behaves in exactly the same way as the invocation - * - *
-     *     out.write(c) 
- * - * @param c - * The 16-bit character to append - * - * @return This writer - * - * @since 1.5 - */ - public StringBuilderOutputStream append(byte c) { - buf.append(c); - return this; - } - - /** - * Return the buffer's current value as a string. - */ - public String toString() { - return buf.toString(); - } - - /** - * Return the string buffer itself. - * - * @return StringBuffer holding the current buffer value. - */ - public StringBuilder getBuffer() { - return buf; - } - - public void reset() { - buf.setLength(0); - } - - @Override - public void flush() throws IOException { - } - - @Override - public void close() throws IOException { - } - -} 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 deleted file mode 100644 index 632ff60..0000000 --- a/env/src/main/java/com/att/inno/env/util/StringBuilderWriter.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.util; - -import java.io.IOException; -import java.io.Writer; - -public class StringBuilderWriter extends Writer { - private StringBuilder buf; - - - /** - * Create a new string writer using the default initial string-buffer - * size. - */ - public StringBuilderWriter() { - buf = new StringBuilder(); - } - - /** - * Create a new string writer using a passed in StringBuilder - * size. - */ - public StringBuilderWriter(StringBuilder sb) { - buf = sb; - } - - /** - * Create a new string writer using the specified initial string-buffer - * size. - * - * @param initialSize - * The number of char values that will fit into this buffer - * before it is automatically expanded - * - * @throws IllegalArgumentException - * If initialSize is negative - */ - public StringBuilderWriter(int initialSize) { - if (initialSize < 0) { - throw new IllegalArgumentException("Negative buffer size"); - } - buf = new StringBuilder(initialSize); - } - - /** - * Write a single character. - */ - public void write(int c) { - buf.append((char) c); - } - - /** - * Write a portion of an array of characters. - * - * @param cbuf Array of characters - * @param off Offset from which to start writing characters - * @param len Number of characters to write - */ - public void write(char cbuf[], int off, int len) { - if ((off < 0) || (off > cbuf.length) || (len < 0) || - ((off + len) > cbuf.length) || ((off + len) < 0)) { - throw new IndexOutOfBoundsException(); - } else if (len == 0) { - return; - } - buf.append(cbuf, off, len); - } - - /** - * Write a string. - */ - public void write(String str) { - buf.append(str); - } - - /** - * Write a portion of a string. - * - * @param str String to be written - * @param off Offset from which to start writing characters - * @param len Number of characters to write - */ - public void write(String str, int off, int len) { - char[] chars = new char[len]; - str.getChars(off, off+len, chars, 0); - buf.append(chars); - } - - public StringBuilderWriter append(CharSequence csq) { - if (csq == null) { - write("null"); - } else { - buf.append(csq); - } - return this; - } - - public StringBuilderWriter append(CharSequence csq, int start, int end) { - CharSequence cs = (csq == null ? "null" : csq); - return append(cs.subSequence(start, end)); - } - - /** - * Appends the specified character to this writer. - * - *

An invocation of this method of the form out.append(c) - * behaves in exactly the same way as the invocation - * - *

-     *     out.write(c) 
- * - * @param c - * The 16-bit character to append - * - * @return This writer - * - * @since 1.5 - */ - public StringBuilderWriter append(char c) { - buf.append(c); - return this; - } - - /** - * Return the buffer's current value as a string. - */ - public String toString() { - return buf.toString(); - } - - /** - * Return the string buffer itself. - * - * @return StringBuffer holding the current buffer value. - */ - public StringBuilder getBuffer() { - return buf; - } - - public void reset() { - buf.setLength(0); - } - - @Override - public void flush() throws IOException { - } - - @Override - public void close() throws IOException { - } - -} diff --git a/env/src/main/java/org/onap/aaf/inno/env/APIException.java b/env/src/main/java/org/onap/aaf/inno/env/APIException.java new file mode 100644 index 0000000..016eea7 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/APIException.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + + +/** + * An Exception with the ability to hold a payload.

+ * + * This is important, because sometimes, the output of a Framework + * may be a descriptive object which doesn't inherit from Throwable + * and thus cannot be attached in "initCause".

+ * + * Examples may be a SOAP Fault. + * + * + */ +public class APIException extends Exception { + + private Object payload = null; + + /** + * @param t + */ + public APIException(Throwable t) { + super(t); + } + + /** + * @param string + */ + public APIException(String string) { + super(string); + } + + /** + * @param errorMessage + * @param t + */ + public APIException(String errorMessage, Throwable t) { + super(errorMessage,t); + } + + /** + * Return payload, or null if none was set. Type is up to the calling + * System. + * + * @return Object + */ + public Object getPayload() { + return payload; + } + + /** + * Set a specific payload into this Exception, which doesn't necessarily + * inherit from Throwable. + * + * @param payload + * @return APIException + */ + public APIException setPayload(Object payload) { + this.payload = payload; + return this; + } + + /** + * Java expected serial ID + */ + private static final long serialVersionUID = 3505343458251445169L; +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/BaseDataFactory.java b/env/src/main/java/org/onap/aaf/inno/env/BaseDataFactory.java new file mode 100644 index 0000000..b65ba56 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/BaseDataFactory.java @@ -0,0 +1,461 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; + +import javax.xml.XMLConstants; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSchema; +import javax.xml.namespace.QName; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; + +import org.onap.aaf.inno.env.impl.EnvFactory; +import org.xml.sax.SAXException; + + + +/** + * DataFactory Constructor will create the Stringifiers and Objectifiers necessary + * by Type and store the Class of the Type for quick creation of Data Objects + * with reused (and thread safe) components + * s + * Native Types are included. + * Those types covered by Env Implementation are covered dynamically. + * Types outside of Env mechanism can be added with "add" function + * + * + * @param + */ +public class BaseDataFactory { + + /** + * Generate a Schema Object for use in validation based on FileNames. + * + * WARNING: The java.xml.binding code requires YOU to figure out what order the + * files go in. If there is an import from A in B, then you must list A first. + * + * @param err + * @param filenames + * @return + * @throws APIException + */ + public static Schema genSchema(Store env, String ... filenames) throws APIException { + String schemaDir = env.get( + env.staticSlot(EnvFactory.SCHEMA_DIR), + EnvFactory.DEFAULT_SCHEMA_DIR); + File dir = new File(schemaDir); + if(!dir.exists())throw new APIException("Schema Directory " + schemaDir + " does not exist. You can set this with " + EnvFactory.SCHEMA_DIR + " property"); + FileInputStream[] fis = new FileInputStream[filenames.length]; + Source[] sources = new Source[filenames.length]; + File f; + for(int i=0; i clss) throws APIException { + // Obtain the Necessary info for QName from Requirement + XmlRootElement xre = clss.getAnnotation(XmlRootElement.class); + if(xre==null)throw new APIException(clss.getName() + " does not have an XmlRootElement annotation"); + Package pkg = clss.getPackage(); + XmlSchema xs = pkg.getAnnotation(XmlSchema.class); + if(xs==null) throw new APIException(clss.getName() + " package-info does not have an XmlSchema annotation"); + return new QName(xs.namespace(),xre.name()); + } + + ///////////////////////////////////////////// + // Native Type Converters + ///////////////////////////////////////////// +// /** +// * StringStringifier +// * +// * Support the Native Type String.. just return it back +// * +// * +// */ +// public static class StringStringifier extends NullLifeCycle implements Stringifier { +// /* (non-Javadoc) +// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) +// */ +// public String stringify(Env env, String input) throws APIException { +// return input; +// } +// }; +// +// /** +// * StringObjectifier +// * +// * Support the Native Type String.. just return it back +// * +// * +// */ +// public static class StringObjectifier extends NullLifeCycle implements Objectifier { +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) +// */ +// public String objectify(Env env, String input) throws APIException { +// return input; +// } +// +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#newObject() +// */ +// public String newInstance() throws APIException { +// return ""; +// } +// }; +// +// /** +// * LongStringifier +// * +// * Support the Native Type Long.. use Long parse functions +// * +// * +// */ +// public static class LongStringifier extends NullLifeCycle implements Stringifier { +// public String stringify(Env env, Long input) throws APIException { +// return input.toString(); +// } +// } +// +// /** +// * LongObjectifier +// * +// * Support the Native Type Long.. use Long parse functions +// * +// * +// */ +// public static class LongObjectifier extends NullLifeCycle implements Objectifier { +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) +// */ +// public Long objectify(Env env, String input) throws APIException { +// try { +// return new Long(input); +// } catch (Exception e) { +// APIException ae = new APIException("Cannot create a \"Long\" from [" + input + ']'); +// ae.initCause(e); +// throw ae; +// } +// } +// +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#newObject() +// */ +// public Long newInstance() throws APIException { +// return 0L; +// } +// } +// +// /** +// * IntegerStringifier +// * +// * Support the Native Integer.. use Integer parse functions +// * +// * +// */ +// public static class IntegerStringifier extends NullLifeCycle implements Stringifier { +// /* (non-Javadoc) +// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) +// */ +// public String stringify(Env env, Integer input) throws APIException { +// return input.toString(); +// } +// } +// +// /** +// * IntegerObjectifier +// * +// * Support the Native Integer.. use Integer parse functions +// * +// * +// */ +// public static class IntegerObjectifier extends NullLifeCycle implements Objectifier { +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) +// */ +// public Integer objectify(Env env, String input) throws APIException { +// try { +// return new Integer(input); +// } catch (Exception e) { +// APIException ae = new APIException("Cannot create a \"Integer\" from [" + input + ']'); +// ae.initCause(e); +// throw ae; +// } +// } +// +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#newObject() +// */ +// public Integer newInstance() throws APIException { +// return 0; +// } +// } +// +// /** +// * ShortStringifier +// * +// * Support the Native Short.. use Short parse functions +// * +// * +// */ +// public static class ShortStringifier extends NullLifeCycle implements Stringifier { +// public String stringify(Env env, Short input) throws APIException { +// return input.toString(); +// } +// } +// +// /** +// * ShortObjectifier +// * +// * Support the Native Short.. use Short parse functions +// * +// * +// */ +// public static class ShortObjectifier extends NullLifeCycle implements Objectifier { +// public Short objectify(Env env, String input) throws APIException { +// try { +// return new Short(input); +// } catch (Exception e) { +// APIException ae = new APIException("Cannot create a \"Short\" from [" + input + ']'); +// ae.initCause(e); +// throw ae; +// } +// } +// +// public Short newInstance() throws APIException { +// return 0; +// } +// } +// +// /** +// * ByteStringifier +// * +// * Support the Native Byte.. use Byte parse functions +// * +// * +// */ +// public static class ByteStringifier extends NullLifeCycle implements Stringifier { +// /* (non-Javadoc) +// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) +// */ +// public String stringify(Env env, Byte input) throws APIException { +// return input.toString(); +// } +// } +// +// /** +// * ByteObjectifier +// * +// * Support the Native Byte.. use Byte parse functions +// * +// * +// */ +// public static class ByteObjectifier extends NullLifeCycle implements Objectifier { +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) +// */ +// public Byte objectify(Env env, String input) throws APIException { +// try { +// return new Byte(input); +// } catch (Exception e) { +// APIException ae = new APIException("Cannot create a \"Byte\" from [" + input + ']'); +// ae.initCause(e); +// throw ae; +// } +// } +// +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#newObject() +// */ +// public Byte newInstance() throws APIException { +// return 0; +// } +// } +// +// /** +// * CharacterStringifier +// * +// * Support the Native Character.. use Character parse functions +// * +// * +// */ +// public static class CharacterStringifier extends NullLifeCycle implements Stringifier { +// /* (non-Javadoc) +// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) +// */ +// public String stringify(Env env, Character input) throws APIException { +// return input.toString(); +// } +// } +// +// /** +// * CharacterObjectifier +// * +// * Support the Native Character.. use Character parse functions +// * +// * +// */ +// public static class CharacterObjectifier extends NullLifeCycle implements Objectifier { +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) +// */ +// public Character objectify(Env env, String input) throws APIException { +// int length = input.length(); +// if(length<1 || length>1) { +// throw new APIException("String [" + input + "] does not represent a single Character"); +// } +// return input.charAt(0); +// } +// +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#newObject() +// */ +// public Character newInstance() throws APIException { +// return 0; +// } +// } +// +// /** +// * FloatStringifier +// * +// * Support the Native Float.. use Float parse functions +// * +// * +// */ +// public static class FloatStringifier extends NullLifeCycle implements Stringifier { +// /* (non-Javadoc) +// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) +// */ +// public String stringify(Env env, Float input) throws APIException { +// return input.toString(); +// } +// } +// +// /** +// * FloatObjectifier +// * +// * Support the Native Float.. use Float parse functions +// * +// * +// */ +// public static class FloatObjectifier extends NullLifeCycle implements Objectifier { +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) +// */ +// public Float objectify(Env env, String input) throws APIException { +// try { +// return new Float(input); +// } catch (Exception e) { +// APIException ae = new APIException("Cannot create a \"Float\" from [" + input + ']'); +// ae.initCause(e); +// throw ae; +// } +// } +// +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#newObject() +// */ +// public Float newInstance() throws APIException { +// return 0.0f; +// } +// } +// +// /** +// * DoubleStringifier +// * +// * Support the Native Double.. use Double parse functions +// * +// */ +// public static class DoubleStringifier extends NullLifeCycle implements Stringifier { +// /* (non-Javadoc) +// * @see com.att.env.Stringifier#stringify(com.att.env.Env, java.lang.Object) +// */ +// public String stringify(Env env, Double input) throws APIException { +// return input.toString(); +// } +// } +// +// /** +// * DoubleObjectifier +// * +// * Support the Native Double.. use Double parse functions +// * +// * +// */ +// public static class DoubleObjectifier extends NullLifeCycle implements Objectifier { +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#objectify(com.att.env.Env, java.lang.String) +// */ +// public Double objectify(Env env, String input) throws APIException { +// try { +// return new Double(input); +// } catch (Exception e) { +// APIException ae = new APIException("Cannot create a \"Double\" from [" + input + ']'); +// ae.initCause(e); +// throw ae; +// } +// } +// +// /* (non-Javadoc) +// * @see com.att.env.Objectifier#newObject() +// */ +// public Double newInstance() throws APIException { +// return 0.0; +// } +// } + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/Creatable.java b/env/src/main/java/org/onap/aaf/inno/env/Creatable.java new file mode 100644 index 0000000..4863808 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/Creatable.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + + +/** + *

Creatable

+ * **Must implement constructor T(ENV env, long currentTimeMillis);**

+ * + * This interface exists to cover basic LifeCycle semantics so that Objects + * can be created dynamically and managed at a basic level (destroy(env)). + * + * + * @param + */ +public interface Creatable { + /** + * Return the timestamp (Unix long) when this object was created.

+ * This can be used to see if the object is out of date in certain + * circumstances, or perhaps has already been notified in others. + * + * @return long + */ + public abstract long created(); + + /** + * Allow LifeCycle aware process to signal this element as destroyed. + * + * @param env + */ + public abstract void destroy(Env env); +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/Data.java b/env/src/main/java/org/onap/aaf/inno/env/Data.java new file mode 100644 index 0000000..754770c --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/Data.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; +import java.io.Writer; +/** + *

Data

+ * Data facilitates lazy marshaling of data with a pre-determined + * marshaling mechanism.

+ * + * It stores either Object (defined by Generic {@literal }) or String.

+ * + * On asking for Object of type {@literal }, it will respond with the object + * if it exists, or unmarshal the string and pass the result back.

+ * + * On asking for String, it will respond with the String + * if it exists, or marshal the String and pass the result back.

+ * + * the "options" available on several functions control the output of this particular call. When + * blank, they will default to the DataFactory defaults. When present, they override this + * particular call. + * The available options are "pretty" (for XML and JSON) and "fragment" (XML only concept), which drops + * the "" header so you can create larger XML documents from the output. + * + * + * @param + */ +public interface Data { + static enum TYPE {XML,JSON,JAXB,RAW,DEFAULT}; + // can & with 0xFFFF; +// public static final int XML = 0x1; +// public static final int JSON = 0x2; +// public static final int JAXB = 0x4; +// public static final int RAW = 0x1000; + + // can & with 0xF00000; + public static final int PRETTY = 0x100000; + public static final int FRAGMENT = 0x200000; + + /** + * Respond with the String if it exists, or marshal the String and pass the result back. + * + * However, use the Env the Data Object was created with. + * + * @return String + * @throws APIException + */ + public String asString() throws APIException; + + /** + * Respond with the Object of type {@literal } if it exists, or unmarshal from String + * and pass the result back.

+ * + * However, use the Env the Data Object was created with. + * + * @return T + * @throws APIException + */ + public T asObject() throws APIException; + + /** + * Set a particular option on an existing Out + * + * if int is negative, it should remove the option + * @param option + */ + public Data option(int option); + + public Data to(OutputStream os) throws APIException, IOException; + public Data to(Writer writer) throws APIException, IOException; + + public Data load(T t) throws APIException; + public Data load(String str) throws APIException; + public Data load(InputStream is) throws APIException; + public Data load(Reader rdr) throws APIException; + + public Data in(TYPE type); + public Data out(TYPE type); + /** + * Return the Class Type supported by this DataObject + * + * @return {@literal Class} + */ + public Class getTypeClass(); + + public void direct(InputStream input, OutputStream output) throws APIException, IOException; + + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/DataFactory.java b/env/src/main/java/org/onap/aaf/inno/env/DataFactory.java new file mode 100644 index 0000000..f724681 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/DataFactory.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + + +public interface DataFactory { + public abstract Data newData(); + public abstract Data newData(Env trans); // and Env or Trans object + public abstract Class getTypeClass(); +} + diff --git a/env/src/main/java/org/onap/aaf/inno/env/Decryptor.java b/env/src/main/java/org/onap/aaf/inno/env/Decryptor.java new file mode 100644 index 0000000..0042ecc --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/Decryptor.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + + +public interface Decryptor { + public String decrypt(String tag); + + public static final Decryptor NULL = new Decryptor() { + @Override + public String decrypt(String tag) { + return tag; + } + }; +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/Encryptor.java b/env/src/main/java/org/onap/aaf/inno/env/Encryptor.java new file mode 100644 index 0000000..d1e5e15 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/Encryptor.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + + +public interface Encryptor { + public String encrypt(String data); + + public static final Encryptor NULL = new Encryptor() { + @Override + public String encrypt(String data) { + return data; + } + }; +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/Env.java b/env/src/main/java/org/onap/aaf/inno/env/Env.java new file mode 100644 index 0000000..046fd8f --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/Env.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + + +/** + *

Env

+ * Env is the basic representation of what can be obtained from the + * Environment. Environments also need the ability to Log and Track Time, so + * to keep the interfaces clean, Env Interface inherits from Trans. This does NOT + * mean that all Environments are Transactions... It only means Environments need + * to Log and Track Times. + * .

+ * + * Using this abstraction, Components can be built on a modular basis, + * and still have the essentials of functioning within the service mechanism.

+ * + * Thus, for instance, an Module could be made to work in two separate + * service types, with substantial differences in choices of logging, or auditing, + * and still have reasonably deep insight, such as the exact time a + * remote service was invoked.

+ * + * There is a bit of an assumption corresponding to the reality of the 2000s that + * XML plays a part in most service work. + * + * + */ +public interface Env { + /** + * Very Severe Error may cause program to abort + */ + public LogTarget fatal(); + + /** + * Severe Error, but program might continue running + */ + public LogTarget error(); + + /** + * Required Audit statements + * @return + */ + public LogTarget audit(); + + /** + * Initialization steps... Allows a Logger to separate startup info + * @return + */ + public LogTarget init(); + + /** + * Potentially harmful situations + * @return + */ + public LogTarget warn(); + + /** + * Course Grained highlights of program progress + * @return + */ + public LogTarget info(); + + /** + * Fine-grained informational events useful for debugging + * @return + */ + public LogTarget debug(); + + /** + * Finest grained Informational events... more detailed than Debug + * @return + */ + public LogTarget trace(); + + + /** + * Basic and Common Audit info... + * + * Note Apps can define, but should use Integers after 0x1F. They can combine with "&" + */ + public static final int REMOTE = 0x01; + public static final int XML = 0x02; + public static final int JSON = 0x04; + public static final int SUB = 0x08; + public static final int CHECKPOINT = 0x10; + public static final int ALWAYS = 0x20; // Mark as a line to print, even in WARN+ mode + + + + /** + * Start a Time Trail with differentiation by flag. This can be Defined By above flags or combined with + * app flag definitions + * + * @param string + * @param flag + * @return + */ + public TimeTaken start(String name, int flag); + + public String setProperty(String tag, String value); + public String getProperty(String tag); + public String getProperty(String tag, String deflt); + + /** + * Passwords should be encrypted on the disk. Use this method to apply decryption before + * using. The Implementation should give ways to decrypt + * + * @param tag + * @return + */ + public Decryptor decryptor(); + + public Encryptor encryptor(); + +} + diff --git a/env/src/main/java/org/onap/aaf/inno/env/EnvJAXB.java b/env/src/main/java/org/onap/aaf/inno/env/EnvJAXB.java new file mode 100644 index 0000000..82f5fe1 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/EnvJAXB.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + +import javax.xml.namespace.QName; +import javax.xml.validation.Schema; + +public interface EnvJAXB extends EnvStore { + /** + * Obtain a DataInterface from this Environment + * + * @param + * @param classes + * @return + * @throws APIException + */ + public DataFactory newDataFactory(Class... classes) throws APIException; + + /** + * Obtain a DataInterface from this Environment, with Validating Schema + * + * @param + * @param classes + * @return + * @throws APIException + */ + public DataFactory newDataFactory(Schema schema, Class... classes) throws APIException; + + public DataFactory newDataFactory(QName qName, Class ... classes) throws APIException; + + public DataFactory newDataFactory(Schema schema, QName qName, Class ... classes) throws APIException; + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/EnvJAXBProps.java b/env/src/main/java/org/onap/aaf/inno/env/EnvJAXBProps.java new file mode 100644 index 0000000..797d7ad --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/EnvJAXBProps.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + +/** + * An interface to express both JAXB and Property elements of Env + * + */ +public interface EnvJAXBProps extends EnvJAXB, EnvProps { + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/EnvProps.java b/env/src/main/java/org/onap/aaf/inno/env/EnvProps.java new file mode 100644 index 0000000..6349875 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/EnvProps.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + +import java.util.Map; + +public interface EnvProps extends Env { + public interface EnvProperty { + public String getProperty(String input); + }; + + /** + * Obtain a Property (String) based on a Key. Implementor decides how + * that works, i.e. from a complex set of Configurations, or just + * "System" (Java standard) + * + * @param key + * @return APIException + */ + public String getProperty(String key); + + /** + * Obtain a Property (String) based on a Key. Implementor decides how + * that works, i.e. from a complex set of Configurations, or just + * "System" (Java standard) + * + * If Property Value is null, then default will be used. + * @param key + * @return APIException + */ + public String getProperty(String tag, String defaultValue); + + /** + * Set a Property (String) based on a Key accessible to all in Env. Implementor decides how + * that works, i.e. from a complex set of Configurations, or just + * "System" (Java standard) + * + * @param key + * @return APIException + */ + public String setProperty(String key, String value); + + /** + * Get the SubProperties based on key. + * + * use "false" to remove prefix, "true" to leave prefix in. + * + * @param key + * @return APIException + * Given a known property set (or in this case, properties starting with key), + * return map of all properties with appropriate key names + */ + public Map getSubProperties(String key, boolean includePrefix); + + /** + * Get all of the properties in the Environment + * @return + */ + public Map getProperties(); + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/EnvStore.java b/env/src/main/java/org/onap/aaf/inno/env/EnvStore.java new file mode 100644 index 0000000..90dbd36 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/EnvStore.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + + +public interface EnvStore extends Env, Store, TransCreate{ + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/IOObjectifier.java b/env/src/main/java/org/onap/aaf/inno/env/IOObjectifier.java new file mode 100644 index 0000000..d963329 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/IOObjectifier.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + +import java.io.InputStream; +import java.io.Reader; + +public interface IOObjectifier extends Objectifier { + /** + * Marshal to Object T from a Reader, using contents from Env as necessary.

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

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return T + * @throws APIException + */ + public abstract T objectify(Env env, InputStream is) throws APIException; + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/IOStringifier.java b/env/src/main/java/org/onap/aaf/inno/env/IOStringifier.java new file mode 100644 index 0000000..0a9686d --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/IOStringifier.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + +import java.io.OutputStream; +import java.io.Writer; + +/** + * Allow Extended IO interface usage without muddying up the Stringifier Interface + */ +public interface IOStringifier extends Stringifier { + /** + * Marshal from an Object T onto a Writer, using contents from Env as necessary.

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

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return String + * @throws APIException + */ + public abstract void stringify(Env env, T input, OutputStream os, boolean ... options) throws APIException; + + /** + * Set Pretty XML, where possible + * + * @param pretty + * @throws APIException + */ + public abstract IOStringifier pretty(boolean pretty); + + /** + * Set Generate Fragment + * + * @param fragment + * @throws APIException + */ + public abstract IOStringifier asFragment(boolean fragment); + + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/LifeCycle.java b/env/src/main/java/org/onap/aaf/inno/env/LifeCycle.java new file mode 100644 index 0000000..b2c454a --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/LifeCycle.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +/** + * + * Created on: Aug 19, 2009 + * Created by: + * + * (c) 2009 SBC Knowledge Ventures, L.P. All rights reserved. + ******************************************************************* + * RESTRICTED - PROPRIETARY INFORMATION The Information contained + * herein is for use only by authorized employees of AT&T Services, + * Inc., and authorized Affiliates of AT&T Services, Inc., and is + * not for general distribution within or outside the respective + * companies. + ******************************************************************* + */ +package org.onap.aaf.inno.env; + +import org.onap.aaf.inno.env.util.RefreshableThreadObject; + + +/** + * + */ +public interface LifeCycle { + /** + * The Service using LifeCycle Elements is required to call this method at + * the appropriate startup time. This is better for services than a simple + * static call, because the exact moment of starting can be determined + * programatically. + *

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

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

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

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

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

+ * + *

IMPORTANT:

+ * The LifeCycle implementor cannot guarantee it will not be in the middle + * of a transaction, so it would behoove the implementor to construct + * content that does not affect anything until finished, then apply to an + * appropriate atomic action (i.e. setting an Object to a field), or even + * synchronizing. + * + * If you are using Java's "ThreadLocal", consider + * {@link RefreshableThreadObject}, because it implements LifeCycle, and + * responds to the refresh command. + * + * @param env + * @throws APIException + */ + public abstract void refresh(Env env) throws APIException; + + /** + * Parallel to threadPrestart, threadDestroy tells the implementor that the + * service is ending this particular thread, and to take this opportunity to + * close out any content specific to this thread that can be closed. + * + * @param env + * @throws APIException + */ + public abstract void threadDestroy(Env env) throws APIException; + + /** + * Parallel to servicePrestart, serviceDestroy tells the implementor that + * the service is ending, and to take this opportunity to close out any + * content under it's control that can or should be closed explicitly. + */ + public abstract void serviceDestroy(Env env) throws APIException; +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/LogTarget.java b/env/src/main/java/org/onap/aaf/inno/env/LogTarget.java new file mode 100644 index 0000000..65868ed --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/LogTarget.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + +import java.io.PrintStream; +import java.util.Date; + +import org.onap.aaf.inno.env.util.Chrono; + +/** + * LogTarget is the interface with which to assign any kind of Logging Implementations. + * + * Implement for any Logging Library of your choice, and for any logging string Format desired. + * + * Included are several Static Implementations for various uses: + * NULL: Does nothing with Logging Messages + * SYSOUT: Writes messages in general form to System Out + * SYSERR: Writes messages in general form to System Err + * + * + */ +public interface LogTarget { + public abstract void log(Object... msgs); + public abstract void log(Throwable e, Object ... msgs); + public abstract boolean isLoggable(); + public abstract void printf(String fmt, Object ... vars); + + // A Convenient LogTarget to insert when a NO-OP is desired. + public static final LogTarget NULL = new LogTarget() { + public void log(Object ... msgs) { + } + + public void log(Throwable t, Object ... msgs) { + } + + public boolean isLoggable() { + return false; + } + + @Override + public void printf(String fmt, Object ... vars) { + } + }; + + // A Convenient LogTarget to write to the Console + public static final LogTarget SYSOUT = new LogTarget() { + public void log(Object ... msgs) { + PrintStream out = System.out; + out.print(org.onap.aaf.inno.env.util.Chrono.dateFmt.format(new Date())); + out.print(": "); + for(Object str : msgs) { + if(str!=null) { + out.print(str.toString()); + out.print(' '); + } else { + out.print("null "); + } + } + out.println(); + } + + public void log(Throwable t, Object ... msgs) { + PrintStream out = System.out; + out.print(Chrono.dateFmt.format(new Date())); + out.print(": "); + for(Object str : msgs) { + out.print(str.toString()); + out.print(' '); + } + out.println(); + t.printStackTrace(out); + out.println(); + } + + public boolean isLoggable() { + return true; + } + + @Override + public void printf(String fmt, Object ... vars) { + log(String.format(fmt,vars)); + } + }; + + // A Convenient LogTarget to write to the Console + public static final LogTarget SYSERR = new LogTarget() { + public void log(Object ... msgs) { + PrintStream out = System.err; + out.print(Chrono.dateFmt.format(new Date())); + out.print(": "); + for(Object str : msgs) { + out.print(str.toString()); + out.print(' '); + } + out.println(); + out.flush(); + } + + public void log(Throwable t, Object ... msgs) { + PrintStream out = System.err; + out.print(Chrono.dateFmt.format(new Date())); + out.print(": "); + for(Object str : msgs) { + out.print(str.toString()); + out.print(' '); + } + out.println(); + t.printStackTrace(out); + } + + public boolean isLoggable() { + return true; + } + @Override + public void printf(String fmt, Object ... vars) { + log(String.format(fmt,vars)); + } + + }; + + +}; diff --git a/env/src/main/java/org/onap/aaf/inno/env/Objectifier.java b/env/src/main/java/org/onap/aaf/inno/env/Objectifier.java new file mode 100644 index 0000000..7123e62 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/Objectifier.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +/** + * + */ +package org.onap.aaf.inno.env; + + + +/** + *

Objectifier

+ * Objectifier abstracts the unmarshaling of an Object from a String, and + * the creation of an uninitialized object. + */ +public interface Objectifier extends LifeCycle { + /** + * Marshal to Object T from a String, using contents from Env as necessary.

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return T + * @throws APIException + */ + public abstract T objectify(Env env, String input) throws APIException; + + /** + * Create a new object of type T. This is often more efficiently done with + * the underlying XML (or other) Library. + * @return T + * @throws APIException + */ + public abstract T newInstance() throws APIException; + + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/Slot.java b/env/src/main/java/org/onap/aaf/inno/env/Slot.java new file mode 100644 index 0000000..0d7bb15 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/Slot.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +/** + * Slot.java + * + * Created on: Dec 5, 2008 + * Created by: + * + * (c) 2008 SBC Knowledge Ventures, L.P. All rights reserved. + ******************************************************************* + * RESTRICTED - PROPRIETARY INFORMATION The Information contained + * herein is for use only by authorized employees of AT&T Services, + * Inc., and authorized Affiliates of AT&T Services, Inc., and is + * not for general distribution within or outside the respective + * companies. + ******************************************************************* + */ +package org.onap.aaf.inno.env; + +/** + * Slot's are used to store and retrieve data in the transaction's State object. + */ +public final class Slot { + + /* + * The name of the Slot. + */ + private final String key; + + /* + * The index of the State's local map associated with this Slot. + */ + final int slot; + + /** + * Constructs a new Slot. + * + * @param index + * The index of State's local map this Slot is associated with. + * @param name + * The name of the Slot's key. + */ + Slot(int index, String name) { + slot = index; + key = name; + } + + /** + * Debug method only to print key=slot pairs. + */ + public String toString() { + return key + '=' + slot; + } + + /** + * Returns the name of this Slot's key. + * + * @return + * The name of this Slot's key. + */ + public String getKey() { + return key; + } + + /** + * Put an Object into the slot on the State + * @param state + * @param obj + */ + public void put(Object[] state, Object obj) { + state[slot]=obj; + } + + /** + * Get an Object from the slot on the State + * @param state + * @param obj + */ + public Object get(Object[] state) { + return state[slot]; + } + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/StaticSlot.java b/env/src/main/java/org/onap/aaf/inno/env/StaticSlot.java new file mode 100644 index 0000000..9a60be0 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/StaticSlot.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +/** + * Slot.java + * + * Created on: Dec 5, 2008 + * Created by: + * + * (c)2008 SBC Knowledge Ventures, L.P. All rights reserved. + ******************************************************************* + * RESTRICTED - PROPRIETARY INFORMATION The Information contained + * herein is for use only by authorized employees of AT&T Services, + * Inc., and authorized Affiliates of AT&T Services, Inc., and is + * not for general distribution within or outside the respective + * companies. + ******************************************************************* + */ +package org.onap.aaf.inno.env; + +/** + * StaticSlot's are used to store and retrieve data from the Organizer that does not change. + */ +public final class StaticSlot { + + /* + * The name of the StaticSlot. + */ + private final String key; + + /* + * The index of the Organizer's static map associated with this StaticSlot. + */ + final int slot; + + /** + * Constructs a new StaticSlot. + * + * @param index + * The index of Organizer's static map this StaticSlot is associated with. + * @param name + * The name of the StaticSlot's key. + */ + StaticSlot(int index, String name) { + slot = index; + key = name; + } + + /** + * Debug method only to print key=slot pairs. + */ + public String toString() { + return key + '=' + slot; + } + + /** + * Returns the name of this StaticSlot's key. + * + * @return + * The name of this StaticSlot's key. + */ + public String getKey() { + return key; + } + +} + diff --git a/env/src/main/java/org/onap/aaf/inno/env/Store.java b/env/src/main/java/org/onap/aaf/inno/env/Store.java new file mode 100644 index 0000000..362520c --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/Store.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + +import java.util.List; + +public interface Store { + /** + * Returns the Slot assigned to the supplied name. + * + * @param name + * The name of the Slot to acquire. + * @return + * The Slot associated with the supplied name. + */ + public abstract Slot slot(String name); + + /** + * Returns the existing Slot associated with the supplied name, or null if it doesn't exist. + * + * @param name + * The name of the Slot to get. + * @return + * The Slot assigned to the supplied name, or null if it doesn't exist. + * + */ + public abstract Slot existingSlot(String name); + + /** + * Returns the names used while creating Slots in a List + * + * @return + */ + public abstract List existingSlotNames(); + + /** + * Returns the StaticSlot assigned to the supplied name. + * + * @param name + * The name of the StaticSlot to acquire. + * @return + * The StaticSlot associated with the supplied name. + */ + public abstract StaticSlot staticSlot(String name); + + /** + * Returns the names used while creating Static Slots in a List + * + * @return + */ + public abstract List existingStaticSlotNames(); + + /** + * Store the supplied value in the StaticSlot of the Organizer's static state. + * + * @param slot + * The StaticSlot used to store the object. + * @param value + * The object to store. + */ + public abstract void put(StaticSlot slot, Object value); + + /** + * Returns an Object from the Organizer's static state, or the Default if null + * + * @param slot + * The StaticSlot to retrieve the data from. + * @return + * The Object located in the supplied StaticSlot of the Organizer's static state. + */ + public abstract T get(StaticSlot slot, T dflt); + + /** + * Returns an Object from the Organizer's static state + * + * @param slot + * The StaticSlot to retrieve the data from. + * @return + * The Object located in the supplied StaticSlot of the Organizer's static state. + */ + public abstract T get(StaticSlot slot); + +// /** +// * Transfer (targeted) Args to Slots +// * +// * Transfer Strings with format "tag=value" into Static Slots +// */ +// public abstract void transfer(String args[], String ... tagss); +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/StoreImpl.java b/env/src/main/java/org/onap/aaf/inno/env/StoreImpl.java new file mode 100644 index 0000000..63e39f4 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/StoreImpl.java @@ -0,0 +1,238 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import org.onap.aaf.inno.env.util.Split; + +import java.util.Properties; + + +public class StoreImpl implements Store { + /* + * The re-adjustment factor for growing the Static State array. + */ + private static final int growSize = 10; + + /* + * The index reference for Slot assignment. + */ + private int local; + + /* + * The index reference for StaticSlot assignment. + */ + private int stat; + + /* + * The name/slot map for local (transaction specific) State. + */ + private HashMap localMap; + + /* + * The name/slot map for Static State. + */ + private HashMap staticMap; + + private Object[] staticState; + + public StoreImpl() { + staticState = new Object[growSize]; + staticMap = new HashMap(); + localMap = new HashMap(); + } + + public StoreImpl(String tag) { + staticState = new Object[growSize]; + staticMap = new HashMap(); + localMap = new HashMap(); + } + + + public StoreImpl(String tag, String[] args) { + staticState = new Object[growSize]; + staticMap = new HashMap(); + localMap = new HashMap(); + + if(tag!=null) { + String tequals = tag + '='; + for(String arg : args) { + if(arg.startsWith(tequals) && !arg.equals(tequals)) { // needs to have something after = + Properties props = new Properties(); + for(String f : Split.split(File.pathSeparatorChar,arg.substring(tequals.length()))) { + moreProps(new File(f),props); + } + for(Entry es : props.entrySet()) { + put(staticSlot(es.getKey().toString()),es.getValue()); + } + } + } + } + + // Make sure properties on command line override those in Props + propsFromArgs(tag,args); + } + + public StoreImpl(String tag, Properties props) { + staticState = new Object[growSize]; + staticMap = new HashMap(); + localMap = new HashMap(); + + if(tag!=null) { + String fname = props.getProperty(tag); + if(fname!=null) { + for(String f : Split.split(File.pathSeparatorChar,fname)) { + if(!moreProps(new File(f),props)) { + System.err.println("Unable to load Properties from " + f); + } + } + } + } + + for(Entry es : props.entrySet()) { + put(staticSlot(es.getKey().toString()),es.getValue()); + } + } + + public void propsFromArgs(String tag, String[] args) { + for(String arg : args) { + String sarg[] = Split.split('=',arg); + if(sarg.length==2) { + if(tag.equals(sarg[0])) { + for(String fname : Split.split(File.pathSeparatorChar,sarg[1])) { + moreProps(new File(fname),null /* no target */); + } + } + put(staticSlot(sarg[0]),sarg[1]); + } + } + } + + private boolean moreProps(File f, Properties target) { + if(f.exists()) { + Properties props = new Properties(); + try { + FileInputStream fis = new FileInputStream(f); + try { + props.load(fis); + if(target!=null) { + target.load(fis); + } + } finally { + fis.close(); + } + } catch(IOException e) { + System.err.println(e); + } + for(Entry es : props.entrySet()) { + put(staticSlot(es.getKey().toString()),es.getValue()); + } + return true; + } else { + return false; + } + } + + public Object[] newTransState() { + return new Object[local]; + } + + /* (non-Javadoc) + * @see com.att.env.Store#slot(java.lang.String) + */ + public synchronized Slot slot(String name) { + name = name == null ? "" : name.trim(); + Slot slot = localMap.get(name); + if (slot == null) { + slot = new Slot(local++, name); + localMap.put(name, slot); + } + return slot; + } + + + /* (non-Javadoc) + * @see com.att.env.Store#existingSlot(java.lang.String) + */ + public Slot existingSlot(String name) { + return localMap.get(name); + } + + /* (non-Javadoc) + * @see com.att.env.Store#existingSlotNames() + */ + public List existingSlotNames() { + return new ArrayList(localMap.keySet()); + } + + /* (non-Javadoc) + * @see com.att.env.Store#staticSlot(java.lang.String) + */ + public synchronized StaticSlot staticSlot(String name) { + name = name == null ? "" : name.trim(); + StaticSlot slot = staticMap.get(name); + if (slot == null) { + if (stat%growSize == 0) { + Object[] temp = staticState; + staticState = new Object[temp.length+growSize]; + System.arraycopy(temp, 0, staticState, 0, temp.length); + } + slot = new StaticSlot(stat++, name); + staticMap.put(name, slot); + } + return slot; + } + + /* (non-Javadoc) + * @see com.att.env.Store#put(com.att.env.StaticSlot, java.lang.Object) + */ + public void put(StaticSlot slot, Object value) { + staticState[slot.slot] = value; + } + + /* (non-Javadoc) + * @see com.att.env.Store#get(com.att.env.StaticSlot T defaultObject) + */ + @SuppressWarnings("unchecked") + public T get(StaticSlot sslot,T dflt) { + T t = (T)staticState[sslot.slot]; + return t==null?dflt:t; + } + + @SuppressWarnings("unchecked") + public T get(StaticSlot sslot) { + return (T)staticState[sslot.slot]; + } + + public List existingStaticSlotNames() { + return new ArrayList(staticMap.keySet()); + } +} + diff --git a/env/src/main/java/org/onap/aaf/inno/env/Stringifier.java b/env/src/main/java/org/onap/aaf/inno/env/Stringifier.java new file mode 100644 index 0000000..fb6c152 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/Stringifier.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + + + +/** + *

Stringifier

+ * Stringifier abstracts the marshaling of a String to an Object + */ +public interface Stringifier extends LifeCycle { + + /** + * Marshal from a String to an Object T, using contents from Env as necessary.

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return String + * @throws APIException + */ + public abstract String stringify(Env env, T input, boolean ... options) throws APIException; + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/TimeTaken.java b/env/src/main/java/org/onap/aaf/inno/env/TimeTaken.java new file mode 100644 index 0000000..c092eb6 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/TimeTaken.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + +/** + *

TimeTaken

+ * This simple interface allows for many different kinds of + * Audit Logs to be accomplished, by assuming that the creation + * of this object indicates "start", and the calling of "done" + * ends. + * + * The implementor of this class can easily be stored in efficient + * mechanisms to minimize impact of Auditing on performance. + * + * + */ +public abstract class TimeTaken { + public final long start; + protected long end, size; + public final int flag; + public final String name; + + /** + * The name is as it will appear when written to output (abstract method) + * + * The flag is an integer which can be System type (XML, REMOTE, etc), or End User defined for reporting purposes + * + * @param name + * @param flag + */ + public TimeTaken(String name, int flag) { + start = System.nanoTime(); + this.flag = flag; + this.name = name; + size = -1; + } + + + /** + * Call this when process is done to state ending time.

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

+ * + *

+	 *   TimeTaken tt = env.startSubTime();
+	 *   try {
+	 *       process.me(); // code to be timed.
+	 *   } finally {
+	 *   	 tt.done();
+	 *   }
+	 * 
+ */ + public void done() { + end = System.nanoTime(); + } + + + /** + * For sizable contents, set the size. Implementations can simply write a no-op if they don't wish to + * store the size. + * + * @param size + */ + public void size(long theSize) { + size = theSize; + } + + /** + * Give readonly access to End, which isn't final + * @return + */ + public long end() { + return end; + } + + /** + * Time is taken in NanoSeconds. This method converts to decimals of Milliseconds + * @return + */ + public float millis() { + return (end-start)/1000000f; + } + /** + * Write self to a String Builder (for making Audits) + * @param sb + */ + public abstract void output(StringBuilder sb); + + /** + * For Debugging + */ + public String toString() { + return name + ' ' + millis() + "ms " + (size>0?Long.toString(size):""); + } + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/Trans.java b/env/src/main/java/org/onap/aaf/inno/env/Trans.java new file mode 100644 index 0000000..6ffeacb --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/Trans.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + + + + +/** + * A Trans is like an Env, however, it's purpose it to track the Transient + * Data associated with Transactions, or other short term elements. + * + * Any Object implementing Trans should expect to go in an out of scope quickly + * + * Implementations should also overload the concepts of "Start", etc and build up + * and Audit Log, so it can implement "metric" below + * + * All Transactions (i.e. a call to a service) will need these items. + * + * + */ +public interface Trans extends Env { + /** + * Add a completed entry in the Audit Trail for tracking purposes. + * + * @param text + */ + public void checkpoint(String text); + + /** + * Add a completed entry in the Audit Trail for tracking purposes, and combine flag with "CHECKPOINT" + * + * @param text + */ + public void checkpoint(String text, int additionalFlag); + + /** + * Output an Audit Trail onto the StringBuilder + * + * Load metrics into an array of floats from passed in Flags + * + * @param flag + * @param sb + * @return + */ + public Metric auditTrail(LogTarget lt, int indent, StringBuilder sb, int ... flag); + + public Metric auditTrail(int indent, StringBuilder sb, int ... flag); + + public class Metric { + public float[] buckets; + public float total; + public int entries; + } +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/TransCreate.java b/env/src/main/java/org/onap/aaf/inno/env/TransCreate.java new file mode 100644 index 0000000..a64bacf --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/TransCreate.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + +public interface TransCreate { + public TRANS newTrans(); +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/TransJAXB.java b/env/src/main/java/org/onap/aaf/inno/env/TransJAXB.java new file mode 100644 index 0000000..36372a6 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/TransJAXB.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + +public interface TransJAXB extends Trans, TransStore { + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/TransStore.java b/env/src/main/java/org/onap/aaf/inno/env/TransStore.java new file mode 100644 index 0000000..1dcf69b --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/TransStore.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env; + +public interface TransStore extends Trans { + /** + * Returns the Slot assigned to the supplied name. + * + * @param name + * The name of the Slot to acquire. + * @return + * The Slot associated with the supplied name. + */ + public abstract Slot slot(String name); + + /** + * Put data into the right slot + */ + public void put(Slot slot, Object value); + + /** + * Get data from the right slot + * + * This will do a cast to the expected type derived from Default + */ + public T get(Slot slot, T deflt); + + /** + * Returns an Object from the Organizer's static state, or the Default if null + * + * @param slot + * The StaticSlot to retrieve the data from. + * @return + * The Object located in the supplied StaticSlot of the Organizer's static state. + */ + public abstract T get(StaticSlot slot, T dflt); + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/impl/AbsTrans.java b/env/src/main/java/org/onap/aaf/inno/env/impl/AbsTrans.java new file mode 100644 index 0000000..c3dea8a --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/impl/AbsTrans.java @@ -0,0 +1,215 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.impl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; + +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.LogTarget; +import org.onap.aaf.inno.env.Slot; +import org.onap.aaf.inno.env.StoreImpl; +import org.onap.aaf.inno.env.TimeTaken; +import org.onap.aaf.inno.env.TransStore; + +public abstract class AbsTrans implements TransStore { + private static final float[] EMPTYF = new float[0]; + private static final Object[] EMPTYO = new Object[0]; + + protected ENV delegate; + protected List trail = new ArrayList(30); + private Object[] state; + + + public AbsTrans(ENV delegate) { + this.delegate = delegate; + state = delegate instanceof StoreImpl?((StoreImpl) delegate).newTransState():EMPTYO; + } + + // @Override + public LogTarget fatal() { + return delegate.fatal(); + } + +// @Override + public LogTarget error() { + return delegate.error(); + } + +// @Override + public LogTarget audit() { + return delegate.audit(); + } + +// @Override + public LogTarget init() { + return delegate.init(); + } + +// @Override + public LogTarget warn() { + return delegate.warn(); + } + +// @Override + public LogTarget info() { + return delegate.info(); + } + +// @Override + public LogTarget debug() { + return delegate.debug(); + } + +// @Override + public LogTarget trace() { + return delegate.trace(); + } + + /** + * Let the final Trans Implementation choose the exact kind of TimeTaken to use + * @param name + * @param flag + * @return + */ + protected abstract TimeTaken newTimeTaken(String name, int flag); + +// @Override + public final TimeTaken start(String name, int flag) { + TimeTaken tt = newTimeTaken(name,flag); + trail.add(tt); + return tt; + } + +// @Override + public final void checkpoint(String name) { + TimeTaken tt = newTimeTaken(name,CHECKPOINT); + tt.done(); + trail.add(tt); + } + + public final void checkpoint(String name, int additionalFlag) { + TimeTaken tt = newTimeTaken(name,CHECKPOINT|additionalFlag); + tt.done(); + trail.add(tt); + } + + @Override + public Metric auditTrail(int indent, StringBuilder sb, int ... flags) { + return auditTrail(info(),indent,sb,flags); + } + + @Override + public Metric auditTrail(LogTarget lt, int indent, StringBuilder sb, int ... flags) { + Metric metric = new Metric(); + int last = (metric.entries = trail.size()) -1; + metric.buckets = flags.length==0?EMPTYF:new float[flags.length]; + if(last>=0) { + TimeTaken first = trail.get(0); + // If first entry is sub, then it's actually the last "end" as well + // otherwise, check end + //long end = (first.flag&SUB)==SUB?first.end():trail.get(last).end(); + long end = trail.get(last).end(); + metric.total = (end - first.start) / 1000000f; + } + + if(sb==null) { + for(TimeTaken tt : trail) { + float ms = tt.millis(); + for(int i=0;i stack = new Stack(); + for(TimeTaken tt : trail) { + // Create Indentation based on SUB + while(!stack.isEmpty() && tt.end()>stack.peek()) { + --indent; + stack.pop(); + } + for(int i=0;i T get(Slot slot, T deflt) { + Object o; + try { + o = slot.get(state); + } catch(ArrayIndexOutOfBoundsException e) { + // Env State Size has changed because of dynamic Object creation... Rare event, but needs to be covered + Object[] temp = ((StoreImpl) delegate).newTransState(); + System.arraycopy(state, 0, temp, 0, state.length); + state = temp; + o=null; + } + return o==null?deflt:(T)o; + } + + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/impl/AbsTransJAXB.java b/env/src/main/java/org/onap/aaf/inno/env/impl/AbsTransJAXB.java new file mode 100644 index 0000000..b0e08a3 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/impl/AbsTransJAXB.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.impl; + +import javax.xml.namespace.QName; +import javax.xml.validation.Schema; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.DataFactory; +import org.onap.aaf.inno.env.EnvJAXB; +import org.onap.aaf.inno.env.TransJAXB; + +public abstract class AbsTransJAXB extends AbsTrans implements TransJAXB { + public AbsTransJAXB(EnvJAXB env) { + super(env); + } + +// @Override + public DataFactory newDataFactory(Class... classes) throws APIException { + return delegate.newDataFactory(classes); + } + +// @Override + public DataFactory newDataFactory(Schema schema, Class... classes) throws APIException { + return delegate.newDataFactory(schema, classes); + } + +// @Override + public DataFactory newDataFactory(QName qName, Class... classes) throws APIException { + return delegate.newDataFactory(qName, classes); + } + +// @Override + public DataFactory newDataFactory(Schema schema, QName qName, Class... classes) throws APIException { + return delegate.newDataFactory(schema, qName, classes); + } + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/impl/BasicEnv.java b/env/src/main/java/org/onap/aaf/inno/env/impl/BasicEnv.java new file mode 100644 index 0000000..eab5494 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/impl/BasicEnv.java @@ -0,0 +1,336 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.impl; + +import java.applet.Applet; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Properties; + +import javax.xml.namespace.QName; +import javax.xml.validation.Schema; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.DataFactory; +import org.onap.aaf.inno.env.Decryptor; +import org.onap.aaf.inno.env.Encryptor; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.EnvJAXB; +import org.onap.aaf.inno.env.LogTarget; +import org.onap.aaf.inno.env.StoreImpl; +import org.onap.aaf.inno.env.TimeTaken; +import org.onap.aaf.inno.env.TransCreate; +import org.onap.aaf.inno.env.TransJAXB; +import org.onap.aaf.inno.env.jaxb.JAXBDF; +import org.onap.aaf.inno.env.util.Split; + +/** + * An essential Implementation of Env, which will fully function, without any sort + * of configuration. + * + * Use as a basis for Group level Env, just overriding where needed. + * + */ +public class BasicEnv extends StoreImpl implements EnvJAXB, TransCreate{ + protected LogTarget fatal=LogTarget.SYSERR; + protected LogTarget error=LogTarget.SYSERR; + protected LogTarget audit=LogTarget.SYSOUT; + protected LogTarget init=LogTarget.SYSOUT; + protected LogTarget warn=LogTarget.SYSERR; + protected LogTarget info=LogTarget.SYSOUT; + protected LogTarget debug=LogTarget.NULL; + protected LogTarget trace=LogTarget.NULL; +// protected Map props; + +// private boolean sysprops; + + public BasicEnv(String ... args) { + super(null,args); + } + + public BasicEnv(String tag, String[] args) { + super(tag, args); + } + + + /** + * Suitable for use in Applets... obtain all the values + * listed for the variable String arg "tags" + */ + public BasicEnv(Applet applet, String ... tags) { + super(null, tags); +// props = new HashMap(); +// String value; +// for(int i=0;i=0) { + sb.append(" size: "); + sb.append(Long.toString(size)); + } + } + } + }; + } + + // @Override + public String getProperty(String key) { + return get(staticSlot(key),null); + } + + public Properties getProperties(String ... filter) { + Properties props = new Properties(); + boolean yes; + for(String key : existingStaticSlotNames()) { + if(filter.length>0) { + yes = false; + for(String f : filter) { + if(key.startsWith(f)) { + yes = true; + break; + } + } + } else { + yes = true; + } + if(yes) { + String value = getProperty(key); + if(value!=null) { + props.put(key, value); + } + } + } + return props; + } + + // @Override + public String getProperty(String key, String defaultValue) { + return get(staticSlot(key),defaultValue); + } + + // @Override + public String setProperty(String key, String value) { + put(staticSlot(key),value==null?null:value.trim()); + return value; + } + + protected Decryptor decryptor = Decryptor.NULL; + protected Encryptor encryptor = Encryptor.NULL; + + + public Decryptor decryptor() { + return decryptor; + } + + public void set(Decryptor newDecryptor) { + decryptor = newDecryptor; + } + + public Encryptor encryptor() { + return encryptor; + } + + public void set(Encryptor newEncryptor) { + encryptor = newEncryptor; + } + + +// @SuppressWarnings("unchecked") + // @Override + public DataFactory newDataFactory(Class... classes) throws APIException { +// if(String.class.isAssignableFrom(classes[0])) +// return (DataFactory) new StringDF(this); + return new JAXBDF(this,classes); + } + +// @SuppressWarnings("unchecked") + // @Override + public DataFactory newDataFactory(Schema schema, Class... classes) throws APIException { +// if(String.class.isAssignableFrom(classes[0])) +// return (DataFactory) new StringDF(this); + return new JAXBDF(this, schema, classes); + } + +// @SuppressWarnings("unchecked") + // @Override + public DataFactory newDataFactory(QName qName, Class ... classes) throws APIException { +// if(String.class.isAssignableFrom(classes[0])) +// return (DataFactory) new StringDF(this); + return new JAXBDF(this, qName, classes); + } + + // @Override + public DataFactory newDataFactory(Schema schema, QName qName, Class ... classes) throws APIException { + return new JAXBDF(this, schema, qName, classes); + } + + // @Override + public BasicTrans newTrans() { + return new BasicTrans(this); + } + + public void loadFromSystemPropsStartsWith(String ... str) { + for(String name : System.getProperties().stringPropertyNames()) { + for(String s : str) { + if(name.startsWith(s)) { + setProperty(name, System.getProperty(name)); + } + } + } + } + + /** + * + * + */ + public void loadToSystemPropsStartsWith(String ... str) { + String value; + for(String name : existingStaticSlotNames()) { + for(String s : str) { + if(name.startsWith(s)) { + if((value = getProperty(name))!=null) + System.setProperty(name,value); + } + } + } + } + + public void loadPropFiles(String tag, ClassLoader classloader) throws IOException { + String propfiles = getProperty(tag); + if(propfiles!=null) { + for(String pf : Split.splitTrim(File.pathSeparatorChar, propfiles)) { + InputStream is = classloader==null?null:classloader.getResourceAsStream(pf); + if(is==null) { + File f = new File(pf); + if(f.exists()) { + is = new FileInputStream(f); + } + } + if(is!=null) { + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + try { + String line; + while((line=br.readLine())!=null) { + line = line.trim(); + if(!line.startsWith("#")) { + String[] tv = Split.splitTrim('=', line); + if(tv.length==2) { + setProperty(tv[0],tv[1]); + } + } + } + } finally { + try { + br.close(); + } catch (IOException e) { + error().log(e); + } + } + } + } + } + } +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/impl/BasicTrans.java b/env/src/main/java/org/onap/aaf/inno/env/impl/BasicTrans.java new file mode 100644 index 0000000..55f89fa --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/impl/BasicTrans.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.impl; + +import org.onap.aaf.inno.env.Decryptor; +import org.onap.aaf.inno.env.Encryptor; +import org.onap.aaf.inno.env.EnvJAXB; +import org.onap.aaf.inno.env.Slot; +import org.onap.aaf.inno.env.StaticSlot; +import org.onap.aaf.inno.env.TimeTaken; + + +public class BasicTrans extends AbsTransJAXB { + + public BasicTrans(EnvJAXB env) { + super(env); + } + + @Override + protected TimeTaken newTimeTaken(String name, int flag) { + /** + * Note: could have created a different format for Time Taken, but using BasicEnv's instead + */ + return delegate.start(name, flag); + } + + public Slot slot(String name) { + return delegate.slot(name); + } + + public T get(StaticSlot slot) { + return delegate.get(slot); + } + + public T get(StaticSlot slot, T dflt) { + return delegate.get(slot,dflt); + } + + public String setProperty(String tag, String value) { + delegate.setProperty(tag, value); + return value; + } + + public String getProperty(String tag) { + return delegate.getProperty(tag); + } + + public String getProperty(String tag, String deflt) { + return delegate.getProperty(tag, deflt); + } + + @Override + public Decryptor decryptor() { + return delegate.decryptor(); + } + + @Override + public Encryptor encryptor() { + return delegate.encryptor(); + } + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/impl/EnvFactory.java b/env/src/main/java/org/onap/aaf/inno/env/impl/EnvFactory.java new file mode 100644 index 0000000..5216cf6 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/impl/EnvFactory.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.impl; + +import org.onap.aaf.inno.env.EnvJAXB; +import org.onap.aaf.inno.env.TransCreate; +import org.onap.aaf.inno.env.TransJAXB; + +/** + * EnvFactory + * + */ +public class EnvFactory { + + public static final String SCHEMA_DIR = "env-schema_dir"; + public static final String DEFAULT_SCHEMA_DIR = "src/main/xsd"; + static BasicEnv singleton; + + static { + singleton = new BasicEnv(); + } + public static BasicEnv singleton() { + return singleton; + } + + public static void setSingleton(BasicEnv be) { + singleton = be; + } + + public static TransJAXB newTrans() { + return new BasicTrans(singleton); + } + + public static TransJAXB newTrans(EnvJAXB env) { + return new BasicTrans(env); + } + + public static TransCreate transCreator() { + return new TransCreate() { + // @Override + public BasicTrans newTrans() { + return singleton.newTrans(); + } + }; + } +} + diff --git a/env/src/main/java/org/onap/aaf/inno/env/impl/JavaUtilLogTarget.java b/env/src/main/java/org/onap/aaf/inno/env/impl/JavaUtilLogTarget.java new file mode 100644 index 0000000..8c6e566 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/impl/JavaUtilLogTarget.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.impl; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.onap.aaf.inno.env.LogTarget; + +/** + * This LogTarget Implementation is included mostly because the JavaUtil based logging is included in the + * JDK. This makes the default implementation independent of any external Jars. + * + * Log4j is often considered more Enterprise capable. See Log4JLogTarget for that implementation + * + * + */ +public class JavaUtilLogTarget implements LogTarget { + private Level level; + private Logger log; + + public JavaUtilLogTarget(Logger logger, Level theLevel) { + log = logger; + level = theLevel; + } + + public boolean isLoggable() { + return log.isLoggable(level); + } + + public void log(Object ... msgs) { + if(log.isLoggable(level)) { + StringBuilder sb = new StringBuilder(); + String msg; + for(int i=0;i0) { + int sbl = sb.length(); + if(sbl>0) { + char last = sb.charAt(sbl-1); + if(" (.".indexOf(last)<0 && "().".indexOf(msg.charAt(0))<0)sb.append(' '); + } + sb.append(msg); + } + } + log.log(level, sb.toString()); + } + } + + public void log(Throwable e, Object ... msgs) { + String str = e.getLocalizedMessage(); + if(str==null) { + str = e.getMessage(); + } + if(str==null) { + str = e.getClass().getName(); + } + log.log(level,str,msgs); + } + + /* (non-Javadoc) + * @see com.att.inno.env.LogTarget#printf(java.lang.String, java.lang.String[]) + */ + @Override + public void printf(String fmt, Object ... vars) { + if(log.isLoggable(level)) { + log.log(level,String.format(fmt,vars)); + } + } +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/impl/Log4JLogTarget.java b/env/src/main/java/org/onap/aaf/inno/env/impl/Log4JLogTarget.java new file mode 100644 index 0000000..6abf7c9 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/impl/Log4JLogTarget.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.impl; + +import java.io.PrintWriter; + +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.LogTarget; +import org.onap.aaf.inno.env.util.StringBuilderWriter; + +/** + * Many services have chosen to use Log4J for their lower level Logging Implementation. This LogTarget will allow + * any of the messages sent to be set to the appropriate Log4J level. + * + * + */ +public class Log4JLogTarget implements LogTarget { + private Level level; + private Logger log; + + public Log4JLogTarget(String loggerName, Level level) throws APIException { + this.level = level; + if (loggerName != null && loggerName.length() > 0) { + log = Logger.getLogger(loggerName); + } else { + log = Logger.getRootLogger(); + } + } + + // @Override + public boolean isLoggable() { + return log.isEnabledFor(level); + } + + // @Override + public void log(Object... msgs) { + log(null, msgs); + } + + // @Override + public void log(Throwable e, Object... msgs) { + if (log.isEnabledFor(level)) { + StringBuilder sb = new StringBuilder(); + + String msg; + if (e != null) { + e.printStackTrace(new PrintWriter(new StringBuilderWriter(sb))); + } + for (int i = 0; i < msgs.length; ++i) { + if(msgs[i]!=null) { + msg = msgs[i].toString(); + if (msg != null && msg.length() > 0) { + int sbl = sb.length(); + if (sbl > 0) { + char last = sb.charAt(sbl - 1); + if (" (.".indexOf(last) < 0 + && "().".indexOf(msg.charAt(0)) < 0) + sb.append(' '); + } + sb.append(msg); + } + } + } + log.log(level, sb.toString()); + } + } + + /* (non-Javadoc) + * @see com.att.inno.env.LogTarget#printf(java.lang.String, java.lang.String[]) + */ + @Override + public void printf(String fmt, Object ... vars) { + if(log.isEnabledFor(level)) { + log.log(level,String.format(fmt,vars)); + } + } + + public static void setLog4JEnv(String loggerName, BasicEnv env) throws APIException { + env.fatal = new Log4JLogTarget(loggerName,Level.FATAL); + env.error = new Log4JLogTarget(loggerName,Level.ERROR); + env.warn = env.audit = env.init = new Log4JLogTarget(loggerName,Level.WARN); + env.info = new Log4JLogTarget(loggerName,Level.INFO); + env.debug = new Log4JLogTarget(loggerName,Level.DEBUG); + env.trace = new Log4JLogTarget(loggerName,Level.TRACE); + } + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/impl/NullLifeCycle.java b/env/src/main/java/org/onap/aaf/inno/env/impl/NullLifeCycle.java new file mode 100644 index 0000000..75ce6c9 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/impl/NullLifeCycle.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +/** + * + */ +package org.onap.aaf.inno.env.impl; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.LifeCycle; + + + +/** + *

NullLifeCycle

+ * + * This is a convenience class for those Objects which should + * implement LifeCycle, but don't have anything to do in any of the + * LifeCycle methods defined. Extending + * NullLifeCycle reduces the required methods for the class by 5. + * Any one or two of them can be overloaded.

+ * + * If more are overloaded, it is + * recommended just to implement LifeCycle. + *

+ * + * This only works, though, if the Object doesn't need to extend something + * else, due to Java's Single Extension policy. In other cases, just + * implement LifeCycle, and leave them empty. + * + * + */ +public class NullLifeCycle implements LifeCycle { + public void servicePrestart(Env env) throws APIException {} + public void threadPrestart(Env env) throws APIException {} + public void refresh(Env env) throws APIException {} + public void threadDestroy(Env env) throws APIException {} + public void serviceDestroy(Env env) throws APIException {} +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBDF.java b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBDF.java new file mode 100644 index 0000000..dec3efa --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBDF.java @@ -0,0 +1,310 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.jaxb; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; +import java.io.StringWriter; +import java.io.Writer; + +import javax.xml.bind.JAXBException; +import javax.xml.namespace.QName; +import javax.xml.validation.Schema; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.BaseDataFactory; +import org.onap.aaf.inno.env.Data; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.EnvJAXB; +import org.onap.aaf.inno.env.TimeTaken; +import org.onap.aaf.inno.env.old.IOObjectifier; +import org.onap.aaf.inno.env.old.IOStringifier; +import org.onap.aaf.inno.env.old.OldDataFactory; + +public class JAXBDF extends BaseDataFactory implements OldDataFactory,IOObjectifier, IOStringifier { + // Package on purpose + EnvJAXB primaryEnv; + JAXBumar jumar; + JAXBmar jmar; + + public JAXBDF(EnvJAXB env, Class ... classes) throws APIException { + try { + primaryEnv = env; + jumar = new JAXBumar(classes); + jmar = new JAXBmar(classes) ; + } catch (JAXBException e) { + throw new APIException(e); + } + } + + public JAXBDF(EnvJAXB env, Schema schema, Class ... classes) throws APIException { + try { + primaryEnv = env; + jumar = new JAXBumar(schema, classes); + jmar = new JAXBmar(classes); + } catch (JAXBException e) { + throw new APIException(e); + } + } + + public JAXBDF(EnvJAXB env, QName qname, Class ... classes) throws APIException { + try { + primaryEnv = env; + jumar = new JAXBumar(classes); + jmar = new JAXBmar(qname, classes); + } catch (JAXBException e) { + throw new APIException(e); + } + } + + public JAXBDF(EnvJAXB env, Schema schema, QName qname, Class ... classes) throws APIException { + try { + primaryEnv = env; + jumar = new JAXBumar(schema, classes); + jmar = new JAXBmar(qname, classes); + } catch (JAXBException e) { + throw new APIException(e); + } + } + + // @Override + public T newInstance() throws APIException { + try { + return jumar.newInstance(); + } catch (Exception e) { + throw new APIException(e); + } + } + + // @Override + public IOStringifier pretty(boolean pretty) { + jmar.pretty(pretty); + return this; + } + + // @Override + public IOStringifier asFragment(boolean fragment) { + jmar.asFragment(fragment); + return this; + } + + // @Override + public void servicePrestart(Env env) throws APIException { + } + + // @Override + public void threadPrestart(Env env) throws APIException { + } + + // @Override + public void refresh(Env env) throws APIException { + } + + // @Override + public void threadDestroy(Env env) throws APIException { + } + + // @Override + public void serviceDestroy(Env env) throws APIException { + } + + @SuppressWarnings("unchecked") + // @Override + public Data newData() { + return new JAXBData(primaryEnv, this, new JAXBStringifier(jmar), new JAXBObjectifier(jumar),"",(Class)jmar.getMarshalClass()); + } + + @SuppressWarnings("unchecked") + // @Override + public Data newData(Env env) { + return new JAXBData(env, this,new JAXBStringifier(jmar), new JAXBObjectifier(jumar),"",(Class)jmar.getMarshalClass()); + } + + // @Override + public Data newData(T type) { + return new JAXBData(primaryEnv, this, new JAXBStringifier(jmar), new JAXBObjectifier(jumar), type); + } + + // @Override + public Data newDataFromStream(Env env, InputStream input) throws APIException { + //TODO Write an unvalidated String using STAX checking for end of Doc? + // perhaps key evaluation as well. + try { + T t = jumar.unmarshal(env.debug(), input); + return new JAXBData(primaryEnv, this, new JAXBStringifier(jmar), new JAXBObjectifier(jumar),t); + } catch(JAXBException e) { + throw new APIException(e); + } + } + + @SuppressWarnings("unchecked") + // @Override + public Data newDataFromString(String string) { + return new JAXBData(primaryEnv, this,new JAXBStringifier(jmar), new JAXBObjectifier(jumar), string,(Class)jmar.getMarshalClass()); + } + + /////////// Old DataFactory Interface + // @Override + public String stringify(T type) throws APIException { + try { + StringWriter sw = new StringWriter(); + jmar.marshal(primaryEnv.debug(), type, sw); + return sw.toString(); + } catch (JAXBException e) { + throw new APIException(e); + } + } + + // @Override + public void stringify(T type, Writer writer) throws APIException { + try { + jmar.marshal(primaryEnv.debug(), type, writer); + } catch (JAXBException e) { + throw new APIException(e); + } + } + + // @Override + public void stringify(T type, OutputStream os) throws APIException { + try { + jmar.marshal(primaryEnv.debug(), type, os); + } catch (JAXBException e) { + throw new APIException(e); + } + } + + /////////// New DataFactory Interface + // @Override + public String stringify(Env env, T input, boolean ... options) throws APIException { + try { + StringWriter sw = new StringWriter(); + TimeTaken tt = env.start("JAXB Stringify", Env.XML); + try { + jmar.marshal(env.debug(), input, sw, options); + } finally { + tt.done(); + } + String str = sw.toString(); + tt.size(str.getBytes().length); + return str; + } catch (JAXBException e) { + throw new APIException(e); + } + } + + // @Override + public void stringify(Env env, T input, Writer writer, boolean ... options) throws APIException { + TimeTaken tt = env.start("JAXB Stringify", Env.XML); + try { + jmar.marshal(env.debug(), input, writer, options); + } catch (JAXBException e) { + throw new APIException(e); + } finally { + tt.done(); + } + } + + // @Override + public void stringify(Env env, T input, OutputStream os, boolean ... options) throws APIException { + TimeTaken tt = env.start("JAXB Stringify", Env.XML); + try { + jmar.marshal(env.debug(), input, os, options); + } catch (JAXBException e) { + throw new APIException(e); + } finally { + tt.done(); + } + } + + // @Override + public T objectify(Env env, Reader rdr) throws APIException { + TimeTaken tt = env.start("JAXB Objectify", Env.XML); + try { + return jumar.unmarshal(env.debug(), rdr); + } catch (JAXBException e) { + throw new APIException(e); + } finally { + tt.done(); + } + } + + // @Override + public T objectify(Reader rdr) throws APIException { + try { + return jumar.unmarshal(primaryEnv.debug(), rdr); + } catch (JAXBException e) { + throw new APIException(e); + } + } + + // @Override + public T objectify(Env env, InputStream is) throws APIException { + TimeTaken tt = env.start("JAXB Objectify", Env.XML); + try { + return jumar.unmarshal(env.debug(), is); + } catch (JAXBException e) { + throw new APIException(e); + } finally { + tt.done(); + } + } + + // @Override + public T objectify(InputStream is) throws APIException { + try { + return jumar.unmarshal(primaryEnv.debug(), is); + } catch (JAXBException e) { + throw new APIException(e); + } + } + + // @Override + public T objectify(Env env, String input) throws APIException { + TimeTaken tt = env.start("JAXB Objectify", Env.XML); + tt.size(input.getBytes().length); + try { + return jumar.unmarshal(env.debug(), input); + } catch (JAXBException e) { + throw new APIException(e); + } finally { + tt.done(); + } + } + + // @Override + public T objectify(String text) throws APIException { + try { + return jumar.unmarshal(primaryEnv.debug(), text); + } catch (JAXBException e) { + throw new APIException(e); + } + } + + @SuppressWarnings("unchecked") + // @Override + public Class getTypeClass() { + return (Class)jmar.getMarshalClass(); + } + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBData.java b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBData.java new file mode 100644 index 0000000..3b51256 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBData.java @@ -0,0 +1,321 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.jaxb; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; +import java.io.Writer; + +import javax.xml.bind.JAXBException; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.Data; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.EnvJAXB; +import org.onap.aaf.inno.env.old.IOStringifier; +import org.onap.aaf.inno.env.old.Objectifier; +import org.onap.aaf.inno.env.old.Stringifier; +/** + *

Data

+ * Data facilitates lazy marshaling of data with a pre-determined + * marshaling mechanism.

+ * + * It stores either Object (defined by Generic {@literal }) or String.

+ * + * On asking for Object of type {@literal }, it will respond with the object + * if it exists, or unmarshal the string and pass the result back.

+ * + * On asking for String, it will respond with the String + * if it exists, or marshal the String and pass the result back.

+ * + * + * @param + */ +public final class JAXBData implements Data{ + private Stringifier stringifier; + private Objectifier objectifier; + private String dataAsString; + private T dataAsObject; + private Class tclass; + private JAXBDF df; + private Env creatingEnv; + private boolean options[] = new boolean[] {false, false}; + + /** + * Construct a Data Object with an appropriate Stringifier, Objectifier and Class to support + * + * @param env + * @param strfr + * @param objfr + * @param text + * @param typeClass + */ + JAXBData(Env env, JAXBDF df, Stringifier strfr, Objectifier objfr, String text, Class typeClass) { + dataAsString = text; + dataAsObject = null; + stringifier = strfr; + objectifier = objfr; + tclass = typeClass; + creatingEnv = env; + this.df = df; + } + + + /** + * Construct a Data Object with an appropriate Stringifier, Objectifier and Object (which will + * yield it's class) + * + * @param env + * @param strfr + * @param objfr + * @param object + */ + @SuppressWarnings("unchecked") + JAXBData(Env env, JAXBDF df, Stringifier strfr, Objectifier objfr, T object) { + dataAsString = null; + dataAsObject = object; + stringifier = strfr; + objectifier = objfr; + tclass = (Class) object.getClass(); + creatingEnv = env; + this.df = df; + } + + /** + * Respond with the String if it exists, or marshal the String and pass the result back.

+ * + * Explicitly use a specific Env for logging purposes + * + * @param env + * @return String + * @throws APIException + */ + public String asString(EnvJAXB env) throws APIException { + if(dataAsString!=null) { + return dataAsString; + } else { + return dataAsString = stringifier.stringify(env, dataAsObject); + } + } + + /** + * Respond with the String if it exists, or marshal the String and pass the result back. + * + * However, use the Env the Data Object was created with. + * + * @return String + * @throws APIException + */ + // @Override + public String asString() throws APIException { + if(dataAsString!=null) { + return dataAsString; + } else { + return dataAsString = stringifier.stringify(creatingEnv, dataAsObject,options); + } + } + + public Data to(OutputStream os) throws APIException, IOException { + if(dataAsString!=null) { + os.write(dataAsString.getBytes()); + } else if (stringifier instanceof IOStringifier){ + ((IOStringifier)stringifier).stringify(creatingEnv, dataAsObject, os, options); + } else { + dataAsString = stringifier.stringify(creatingEnv, dataAsObject, options); + os.write(dataAsString.getBytes()); + } + return this; + } + + + // @Override + public JAXBData to(Writer writer) throws APIException, IOException { + if(dataAsString!=null) { + writer.write(dataAsString); + } else if (stringifier instanceof IOStringifier){ + ((IOStringifier)stringifier).stringify(creatingEnv, dataAsObject, writer, options); + } else { + dataAsString = stringifier.stringify(creatingEnv, dataAsObject, options); + writer.write(dataAsString); + } + return this; + } + + + public InputStream getInputStream() throws APIException { + if(dataAsString==null) { + dataAsString = stringifier.stringify(creatingEnv,dataAsObject,options); + } + return new ByteArrayInputStream(dataAsString.getBytes()); + } + + /** + * Respond with the Object of type {@literal } if it exists, or unmarshal from String + * and pass the result back.

+ * + * Explicitly use a specific Env for logging purposes + * + * @param env + * @return T + * @throws APIException + */ + + public T asObject(EnvJAXB env) throws APIException { + if(dataAsObject !=null) { + return dataAsObject; + } else { + // Some Java compilers need two statements here + dataAsObject = objectifier.objectify(env, dataAsString); + return dataAsObject; + } + } + + /** + * Respond with the Object of type {@literal } if it exists, or unmarshal from String + * and pass the result back.

+ * + * However, use the Env the Data Object was created with. + * + * @return T + * @throws APIException + */ + // @Override + public T asObject() throws APIException { + if(dataAsObject !=null) { + return dataAsObject; + } else { + // Some Java compilers need two statements here + dataAsObject = objectifier.objectify(creatingEnv, dataAsString); + return dataAsObject; + } + } + + + /** + * Return the Class Type supported by this DataObject + * + * @return {@literal Class} + */ + // @Override + public Class getTypeClass() { + return tclass; + } + + + /** + * For Debugging Convenience, we marshal to String if possible. + * + * Behavior is essentially the same as asString(), except asString() throws + * an APIException.

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

+ * + * Therefore, use "asString()" where possible in actual Transactional code. + * + * @see java.lang.Object#toString() + */ + // @Override + public String toString() { + if(dataAsString!=null) { + return dataAsString; + } else { + try { + return dataAsString = stringifier.stringify(creatingEnv, dataAsObject); + } catch (APIException e) { + return "ERROR - Can't Stringify from Object " + e.getLocalizedMessage(); + } + } + } + + public Data load(T t) throws APIException { + dataAsObject = t; + dataAsString = null; + return this; + } + + + public Data load(String str) throws APIException { + dataAsObject = null; + dataAsString = str; + return this; + } + + + public Data load(InputStream is) throws APIException { + try { + dataAsObject = df.jumar.unmarshal(creatingEnv.debug(),is); + dataAsString = null; + } catch (JAXBException e) { + throw new APIException(e); + } + return this; + } + + + public Data load(Reader rdr) throws APIException { + try { + dataAsObject = df.jumar.unmarshal(creatingEnv.debug(),rdr); + dataAsString = null; + } catch (JAXBException e) { + throw new APIException(e); + } + return this; + } + + + // @Override + public void direct(InputStream input, OutputStream output) throws APIException, IOException { + byte b[] = new byte[128]; + int count; + do { + count = input.read(b); + if(count>0)output.write(b, 0, count); + } while(count>=0); + } + + + // @Override + public Data out(TYPE type) { + // it's going to be XML regardless... + return this; + } + + + // @Override + public Data in(TYPE type) { + // Not Supported... will still be XML + return this; + } + + + // @Override + public Data option(int option) { + options[0] = (option&Data.PRETTY)==Data.PRETTY; + options[1] = (option&Data.FRAGMENT)==Data.FRAGMENT; + return this; + } + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBObjectifier.java b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBObjectifier.java new file mode 100644 index 0000000..880aa21 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBObjectifier.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.jaxb; + +import java.io.InputStream; +import java.io.Reader; + +import javax.xml.bind.JAXBException; +import javax.xml.validation.Schema; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.TimeTaken; +import org.onap.aaf.inno.env.old.IOObjectifier; + +/** + * Allow Extended IO interface usage without muddying up the Stringifier Interface + */ +public class JAXBObjectifier implements IOObjectifier { + private JAXBumar jumar; + + public JAXBObjectifier(Schema schema, Class... classes) throws APIException { + try { + jumar = new JAXBumar(schema, classes); + } catch (JAXBException e) { + throw new APIException(e); + } + } + + public JAXBObjectifier(Class... classes) throws APIException { + try { + jumar = new JAXBumar(classes); + } catch (JAXBException e) { + throw new APIException(e); + } + } + + // package on purpose + JAXBObjectifier(JAXBumar jumar) { + this.jumar = jumar; + } + + @SuppressWarnings("unchecked") + // @Override + public T objectify(Env env, String input) throws APIException { + TimeTaken tt = env.start("JAXB Unmarshal", Env.XML); + try { + tt.size(input.length()); + return (T)jumar.unmarshal(env.debug(), input); + } catch (JAXBException e) { + throw new APIException(e); + } finally { + tt.done(); + } + } + + @SuppressWarnings("unchecked") + // @Override + public T objectify(Env env, Reader rdr) throws APIException { + //TODO create a Reader that Counts? + TimeTaken tt = env.start("JAXB Unmarshal", Env.XML); + try { + return (T)jumar.unmarshal(env.debug(), rdr); + } catch (JAXBException e) { + throw new APIException(e); + } finally { + tt.done(); + } + } + + + @SuppressWarnings("unchecked") + // @Override + public T objectify(Env env, InputStream is) throws APIException { + //TODO create a Reader that Counts? + TimeTaken tt = env.start("JAXB Unmarshal", Env.XML); + try { + return (T)jumar.unmarshal(env.debug(), is); + } catch (JAXBException e) { + throw new APIException(e); + } finally { + tt.done(); + } + } + + + public void servicePrestart(Env env) throws APIException { + } + + public void threadPrestart(Env env) throws APIException { + } + + // // @Override + public void refresh(Env env) throws APIException { + } + + // // @Override + public void threadDestroy(Env env) throws APIException { + } + + // // @Override + public void serviceDestroy(Env env) throws APIException { + } + + + @SuppressWarnings("unchecked") + public T newInstance() throws APIException { + try { + return (T)jumar.newInstance(); + } catch (Exception e) { + throw new APIException(e); + } + } + +} + diff --git a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBStringifier.java b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBStringifier.java new file mode 100644 index 0000000..3fcfaa8 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBStringifier.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.jaxb; + +import java.io.OutputStream; +import java.io.StringWriter; +import java.io.Writer; + +import javax.xml.bind.JAXBException; +import javax.xml.namespace.QName; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.TimeTaken; +import org.onap.aaf.inno.env.old.IOStringifier; + +public class JAXBStringifier implements IOStringifier { + private JAXBmar jmar; + + public JAXBStringifier(Class... classes) throws APIException { + try { + jmar = new JAXBmar(classes); + } catch (JAXBException e) { + throw new APIException(e); + } + } + + public JAXBStringifier(QName qname, Class... classes) + throws APIException { + try { + jmar = new JAXBmar(qname, classes); + } catch (JAXBException e) { + throw new APIException(e); + } + } + + // package on purpose + JAXBStringifier(JAXBmar jmar) { + this.jmar = jmar; + } + + // // @Override + public void stringify(Env env, T input, Writer writer, boolean ... options) + throws APIException { + TimeTaken tt = env.start("JAXB Marshal", Env.XML); + try { + jmar.marshal(env.debug(), input, writer, options); + } catch (JAXBException e) { + throw new APIException(e); + } finally { + tt.done(); + } + } + + // @Override + public void stringify(Env env, T input, OutputStream os, boolean ... options) + throws APIException { + // TODO create an OutputStream that Counts? + TimeTaken tt = env.start("JAXB Marshal", Env.XML); + try { + jmar.marshal(env.debug(), input, os, options); + } catch (JAXBException e) { + throw new APIException(e); + } finally { + tt.done(); + } + } + + // @Override + public String stringify(Env env, T input, boolean ... options) throws APIException { + TimeTaken tt = env.start("JAXB Marshal", Env.XML); + StringWriter sw = new StringWriter(); + try { + jmar.marshal(env.debug(), input, sw, options); + String rv = sw.toString(); + tt.size(rv.length()); + return rv; + } catch (JAXBException e) { + tt.size(0); + throw new APIException(e); + } finally { + tt.done(); + } + } + + // // @Override + public void servicePrestart(Env env) throws APIException { + } + + // // @Override + public void threadPrestart(Env env) throws APIException { + } + + // // @Override + public void refresh(Env env) throws APIException { + } + + // // @Override + public void threadDestroy(Env env) throws APIException { + } + + // // @Override + public void serviceDestroy(Env env) throws APIException { + } + + // @Override + public JAXBStringifier pretty(boolean pretty) { + jmar.pretty(pretty); + return this; + } + + // @Override + public JAXBStringifier asFragment(boolean fragment) { + jmar.asFragment(fragment); + return this; + } + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBmar.java b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBmar.java new file mode 100644 index 0000000..d07c246 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBmar.java @@ -0,0 +1,253 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +/** + * JAXBumar.java + * + * Created on: Apr 10, 2009 + * Created by: + * + * Revamped to do away with ThreadLocal 5/27/2011, + * + * (c) 2009 SBC Knowledge Ventures, L.P. All rights reserved. + ******************************************************************* + * RESTRICTED - PROPRIETARY INFORMATION The Information contained + * herein is for use only by authorized employees of AT&T Services, + * Inc., and authorized Affiliates of AT&T Services, Inc., and is + * not for general distribution within or outside the respective + * companies. + ******************************************************************* + */ +package org.onap.aaf.inno.env.jaxb; + +import java.io.OutputStream; +import java.io.StringWriter; +import java.io.Writer; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.namespace.QName; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.LogTarget; +import org.onap.aaf.inno.env.util.Pool; +import org.onap.aaf.inno.env.util.Pool.Pooled; + +/** + * JAXBmar classes are inexpensive for going in and out of scope + * and have been made thread safe via Pooling + + * + */ +public class JAXBmar { + // Need to store off possible JAXBContexts based on Class, which will be stored in Creator + private static Map[],Pool> pools = new HashMap[], Pool>(); + + // Handle Marshaller class setting of properties only when needed + private class PMarshaller { + private Marshaller m; + private boolean p; + private boolean f; + + public PMarshaller(Marshaller marshaller) throws JAXBException { + m = marshaller; + m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, p = false); + m.setProperty(Marshaller.JAXB_FRAGMENT, f = false); + } + + public Marshaller get(boolean pretty, boolean fragment) throws JAXBException { + if(pretty != p) { + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, p = pretty); + } + if(fragment != f) { + m.setProperty(Marshaller.JAXB_FRAGMENT, f = fragment); + } + return m; + } + } + + private class Creator implements Pool.Creator { + private JAXBContext jc; + private String name; + public Creator(Class[] classes) throws JAXBException { + jc = JAXBContext.newInstance(classes); + name = "JAXBmar: " + classes[0].getName(); + } + + // @Override + public PMarshaller create() throws APIException { + try { + return new PMarshaller(jc.createMarshaller()); + } catch (JAXBException e) { + throw new APIException(e); + } + } + + public String toString() { + return name; + } + + // @Override + public void reuse(PMarshaller pm) { + // Nothing to do + } + + // @Override + public void destroy(PMarshaller pm) { + // Nothing to do + } + + // @Override + public boolean isValid(PMarshaller t) { + return true; + } + } + + //TODO isn't UTF-8 a standard string somewhere for encoding? + private boolean fragment= false; + private boolean pretty=false; + private QName qname; + + private Pool mpool; // specific Pool associated with constructed Classes + private Class cls; + + private Pool getPool(Class ... classes) throws JAXBException { + Pool mp; + synchronized(pools) { + mp = pools.get(classes); + if(mp==null) { + pools.put(classes,mp = new Pool(new Creator(classes))); + } + } + return mp; + } + + public JAXBmar(Class... classes) throws JAXBException { + cls = classes[0]; + mpool = getPool(classes); + qname = null; + } + + public JAXBmar(QName theQname, Class... classes) throws JAXBException { + cls = classes[0]; + mpool = getPool(classes); + qname = theQname; + } + + @SuppressWarnings("unchecked") + public O marshal(LogTarget lt,O o, Writer writer, boolean ... options) throws JAXBException, APIException { + boolean pretty, fragment; + pretty = options.length>0?options[0]:this.pretty; + fragment = options.length>1?options[1]:this.fragment; + Pooled m = mpool.get(lt); + try { + if(qname==null) { + m.content.get(pretty,fragment).marshal(o, writer); + } else { + m.content.get(pretty,fragment).marshal( + new JAXBElement(qname, (Class)cls, o ), + writer); + } + return o; + } finally { + m.done(); + } + } + + @SuppressWarnings("unchecked") + public O marshal(LogTarget lt, O o, OutputStream os, boolean ... options) throws JAXBException, APIException { + boolean pretty, fragment; + pretty = options.length>0?options[0]:this.pretty; + fragment = options.length>1?options[1]:this.fragment; + Pooled m = mpool.get(lt); + try { + if(qname==null) { + m.content.get(pretty,fragment).marshal(o, os); + } else { + m.content.get(pretty,fragment).marshal( + new JAXBElement(qname, (Class)cls, o ),os); + } + return o; + } finally { + m.done(); + } + } + + public O marshal(LogTarget lt, O o, Writer writer, Class clss) throws JAXBException, APIException { + Pooled m = mpool.get(lt); + try { + if(qname==null) { + m.content.get(pretty,fragment).marshal(o, writer); + } else { + m.content.get(pretty,fragment).marshal( + new JAXBElement(qname, clss, o),writer); + } + return o; + } finally { + m.done(); + } + + } + + public O marshal(LogTarget lt, O o, OutputStream os, Class clss) throws JAXBException, APIException { + Pooled m = mpool.get(lt); + try { + if(qname==null) { + m.content.get(pretty,fragment).marshal(o, os); + } else { + m.content.get(pretty,fragment).marshal( + new JAXBElement(qname, clss, o ),os); + } + return o; + } finally { + m.done(); + } + } + + /** + * @return + */ + public Class getMarshalClass() { + return cls; + } + + public String stringify(LogTarget lt, O o) throws JAXBException, APIException { + StringWriter sw = new StringWriter(); + marshal(lt,o,sw); + return sw.toString(); + } + + public JAXBmar pretty(boolean pretty) { + this.pretty = pretty; + return this; + } + + public JAXBmar asFragment(boolean fragment) { + this.fragment = fragment; + return this; + } +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBumar.java b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBumar.java new file mode 100644 index 0000000..cd31301 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/jaxb/JAXBumar.java @@ -0,0 +1,242 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +/** + * JAXBumar.java + * + * Created on: Apr 10, 2009 + * Created by: + * + * Revamped to do away with ThreadLocal 5/27/2011, + * + * (c) 2009 SBC Knowledge Ventures, L.P. All rights reserved. + ******************************************************************* + * RESTRICTED - PROPRIETARY INFORMATION The Information contained + * herein is for use only by authorized employees of AT&T Services, + * Inc., and authorized Affiliates of AT&T Services, Inc., and is + * not for general distribution within or outside the respective + * companies. + ******************************************************************* + */ +package org.onap.aaf.inno.env.jaxb; + +import java.io.File; +import java.io.InputStream; +import java.io.Reader; +import java.io.StringReader; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.XMLStreamReader; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.LogTarget; +import org.onap.aaf.inno.env.util.Pool; +import org.onap.aaf.inno.env.util.Pool.Pooled; +import org.w3c.dom.Node; + +/** + * JAXBumar classes are inexpensive for going in and out of scope + * and have been made thread safe via Pooling + * + */ +public class JAXBumar { + // Need to store off possible JAXBContexts based on Class, which will be stored in Creator + private static Map[],Pool> pools = new HashMap[], Pool>(); + + private Class cls; + private Schema schema; + private Pool mpool;; + + // Handle Marshaller class setting of properties only when needed + private class SUnmarshaller { + private Unmarshaller u; + private Schema s; + + public SUnmarshaller(Unmarshaller unmarshaller) throws JAXBException { + u = unmarshaller; + s = null; + } + + public Unmarshaller get(Schema schema) throws JAXBException { + if(s != schema) { + u.setSchema(s = schema); + } + return u; + } + } + + private class Creator implements Pool.Creator { + private JAXBContext jc; + private String name; + + public Creator(Class[] classes) throws JAXBException { + jc = JAXBContext.newInstance(classes); + name = "JAXBumar: " + classes[0].getName(); + } + + // @Override + public SUnmarshaller create() throws APIException { + try { + return new SUnmarshaller(jc.createUnmarshaller()); + } catch (JAXBException e) { + throw new APIException(e); + } + } + + public String toString() { + return name; + } + + // @Override + public void destroy(SUnmarshaller sui) { + // Nothing to do + } + + // @Override + public boolean isValid(SUnmarshaller t) { + return true; + } + + // @Override + public void reuse(SUnmarshaller t) { + // Nothing to do here + } + + } + + private Pool getPool(Class ... classes) throws JAXBException { + Pool mp; + synchronized(pools) { + mp = pools.get(classes); + if(mp==null) { + pools.put(classes,mp = new Pool(new Creator(classes))); + } + } + return mp; + } + + public JAXBumar(Class ... classes) throws JAXBException { + cls = classes[0]; + mpool = getPool(classes); + schema = null; + } + + /** + * Constructs a new JAXBumar with schema validation enabled. + * + * @param schema + * @param theClass + * @throws JAXBException + */ + public JAXBumar(Schema schema, Class ... classes) throws JAXBException { + cls = classes[0]; + mpool = getPool(classes); + this.schema = schema; + } + + @SuppressWarnings("unchecked") + public O unmarshal(LogTarget env, Node node) throws JAXBException, APIException { + Pooled s = mpool.get(env); + try { + return s.content.get(schema).unmarshal(node,(Class)cls).getValue(); + } finally { + s.done(); + } + + } + + @SuppressWarnings("unchecked") + public O unmarshal(LogTarget env, String xml) throws JAXBException, APIException { + if(xml==null) throw new JAXBException("Null Input for String unmarshal"); + Pooled s = mpool.get(env); + try { + return (O)s.content.get(schema).unmarshal( + new StreamSource(new StringReader(xml)) + ,(Class)cls).getValue(); + } finally { + s.done(); + } + } + + @SuppressWarnings("unchecked") + public O unmarshal(LogTarget env, File xmlFile) throws JAXBException, APIException { + Pooled s = mpool.get(env); + try { + return (O)s.content.get(schema).unmarshal(xmlFile); + } finally { + s.done(); + } + + } + + @SuppressWarnings("unchecked") + public O unmarshal(LogTarget env,InputStream is) throws JAXBException, APIException { + Pooled s = mpool.get(env); + try { + return (O)s.content.get(schema).unmarshal(is); + } finally { + s.done(); + } + } + + @SuppressWarnings("unchecked") + public O unmarshal(LogTarget env, Reader rdr) throws JAXBException, APIException { + Pooled s = mpool.get(env); + try { + return (O)s.content.get(schema).unmarshal(rdr); + } finally { + s.done(); + } + } + + @SuppressWarnings("unchecked") + public O unmarshal(LogTarget env, XMLStreamReader xsr) throws JAXBException, APIException { + Pooled s = mpool.get(env); + try { + return (O)s.content.get(schema).unmarshal(xsr,(Class)cls).getValue(); + } finally { + s.done(); + } + } + + @SuppressWarnings("unchecked") + public O unmarshal(LogTarget env, XMLEventReader xer) throws JAXBException, APIException { + Pooled s = mpool.get(env); + try { + return (O)s.content.get(schema).unmarshal(xer,(Class)cls).getValue(); + } finally { + s.done(); + } + } + + @SuppressWarnings("unchecked") + public O newInstance() throws InstantiationException, IllegalAccessException{ + return ((Class)cls).newInstance(); + } +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/old/IOObjectifier.java b/env/src/main/java/org/onap/aaf/inno/env/old/IOObjectifier.java new file mode 100644 index 0000000..ca79afd --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/old/IOObjectifier.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.old; + +import java.io.InputStream; +import java.io.Reader; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.Env; + +public interface IOObjectifier extends Objectifier { + /** + * Marshal to Object T from a Reader, using contents from Env as necessary.

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

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return T + * @throws APIException + */ + public abstract T objectify(Env env, InputStream is) throws APIException; + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/old/IOStringifier.java b/env/src/main/java/org/onap/aaf/inno/env/old/IOStringifier.java new file mode 100644 index 0000000..f2b60fd --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/old/IOStringifier.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.old; + +import java.io.OutputStream; +import java.io.Writer; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.Env; + +/** + * Allow Extended IO interface usage without muddying up the Stringifier Interface + */ +public interface IOStringifier extends Stringifier { + /** + * Marshal from an Object T onto a Writer, using contents from Env as necessary.

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

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return String + * @throws APIException + */ + public abstract void stringify(Env env, T input, OutputStream os, boolean ... options) throws APIException; + + /** + * Set Pretty XML, where possible + * + * @param pretty + * @throws APIException + */ + public abstract IOStringifier pretty(boolean pretty); + + /** + * Set Generate Fragment + * + * @param fragment + * @throws APIException + */ + public abstract IOStringifier asFragment(boolean fragment); + + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/old/Objectifier.java b/env/src/main/java/org/onap/aaf/inno/env/old/Objectifier.java new file mode 100644 index 0000000..15536ad --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/old/Objectifier.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +/** + * + */ +package org.onap.aaf.inno.env.old; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.LifeCycle; + + +/** + *

Objectifier

+ * Objectifier abstracts the unmarshaling of an Object from a String, and + * the creation of an uninitialized object. + */ +public interface Objectifier extends LifeCycle { + /** + * Marshal to Object T from a String, using contents from Env as necessary.

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return T + * @throws APIException + */ + public abstract T objectify(Env env, String input) throws APIException; + + /** + * Create a new object of type T. This is often more efficiently done with + * the underlying XML (or other) Library. + * @return T + * @throws APIException + */ + public abstract T newInstance() throws APIException; + + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/old/OldDataFactory.java b/env/src/main/java/org/onap/aaf/inno/env/old/OldDataFactory.java new file mode 100644 index 0000000..92126ef --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/old/OldDataFactory.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.old; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; +import java.io.Writer; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.Data; +import org.onap.aaf.inno.env.DataFactory; +import org.onap.aaf.inno.env.Env; + +public interface OldDataFactory extends DataFactory { + public abstract String stringify(T type) throws APIException; + public abstract void stringify(T type, OutputStream os) throws APIException; + public abstract void stringify(T type, Writer writer) throws APIException; + public abstract T objectify(InputStream is) throws APIException; + public abstract T objectify(Reader rdr) throws APIException; + public abstract T objectify(String text) throws APIException; + public abstract T newInstance() throws APIException; + public abstract Data newData(T type); + public abstract Data newDataFromStream(Env env, InputStream input) throws APIException; + public abstract Data newDataFromString(String string); + +} + diff --git a/env/src/main/java/org/onap/aaf/inno/env/old/Stringifier.java b/env/src/main/java/org/onap/aaf/inno/env/old/Stringifier.java new file mode 100644 index 0000000..42869c7 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/old/Stringifier.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.old; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.LifeCycle; + + +/** + *

Stringifier

+ * Stringifier abstracts the marshaling of a String to an Object + */ +public interface Stringifier extends LifeCycle { + + /** + * Marshal from a String to an Object T, using contents from Env as necessary.

+ * + * Implementations should use the {@link Env} to call "env.startXMLTime()" to mark + * XML time, since this is often a costly process. + * + * @param env + * @param input + * @return String + * @throws APIException + */ + public abstract String stringify(Env env, T input, boolean ... options) throws APIException; + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/util/Chrono.java b/env/src/main/java/org/onap/aaf/inno/env/util/Chrono.java new file mode 100644 index 0000000..8d32590 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/util/Chrono.java @@ -0,0 +1,307 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.util; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.GregorianCalendar; +import java.security.SecureRandom; +import java.util.TimeZone; +import java.util.UUID; +import java.util.logging.Formatter; +import java.util.logging.LogRecord; + +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; + +public class Chrono { + private static final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L; + + public final static DateFormat dateFmt, dateOnlyFmt, niceDateFmt, utcFmt; + // Give general access to XML DataType Factory, since it's pretty common + public static final DatatypeFactory xmlDatatypeFactory; + + static { + try { + xmlDatatypeFactory = DatatypeFactory.newInstance(); + } catch (DatatypeConfigurationException e) { + throw new RuntimeException(e); + } + dateOnlyFmt = new SimpleDateFormat("yyyy-MM-dd"); + niceDateFmt = new SimpleDateFormat("yyyy/MM/dd HH:mm zzz"); + dateFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); + utcFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); + utcFmt.setTimeZone(TimeZone.getTimeZone("UTC")); + } + + + public static class Formatter8601 extends Formatter { + + @Override + public String format(LogRecord r) { + StringBuilder sb = new StringBuilder(); + sb.append(dateFmt.format(new Date(r.getMillis()))); + sb.append(' '); + sb.append(r.getThreadID()); + sb.append(' '); + sb.append(r.getLevel()); + sb.append(": "); + sb.append(r.getMessage()); + sb.append('\n'); + return sb.toString(); + } + + } + + /** + * timeStamp + * + * Convenience method to setup an XML dateTime (XMLGregorianCalendar) with "now" + * @return + */ + public static XMLGregorianCalendar timeStamp() { + return xmlDatatypeFactory.newXMLGregorianCalendar(new GregorianCalendar()); + } + + /** + * timestamp + * + * Convenience method to setup an XML dateTime (XMLGregorianCalendar) with passed in Date + * @param date + * @return + */ + public static XMLGregorianCalendar timeStamp(Date date) { + GregorianCalendar gc = new GregorianCalendar(); + gc.setTime(date); + return xmlDatatypeFactory.newXMLGregorianCalendar(gc); + } + + public static XMLGregorianCalendar timeStamp(GregorianCalendar gc) { + return xmlDatatypeFactory.newXMLGregorianCalendar(gc); + } + + public static String utcStamp() { + return utcFmt.format(new Date()); + } + + public static String utcStamp(Date date) { + if(date==null)return ""; + return utcFmt.format(date); + } + + public static String utcStamp(GregorianCalendar gc) { + if(gc==null)return ""; + return utcFmt.format(gc.getTime()); + } + + public static String utcStamp(XMLGregorianCalendar xgc) { + if(xgc==null)return ""; + return utcFmt.format(xgc.toGregorianCalendar().getTime()); + } + + public static String dateStamp() { + return dateFmt.format(new Date()); + } + + public static String dateStamp(GregorianCalendar gc) { + if(gc == null)return ""; + return dateFmt.format(gc.getTime()); + } + + public static String dateStamp(Date date) { + if(date == null)return ""; + return dateFmt.format(date); + } + + public static String dateStamp(XMLGregorianCalendar xgc) { + if(xgc==null)return ""; + return dateFmt.format(xgc.toGregorianCalendar().getTime()); + } + + /** + * JAXB compatible dataTime Stamp + * + * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it. + * + * @return + */ + public static String dateTime() { + return dateTime(new GregorianCalendar()); + } + + /** + * JAXB compatible dataTime Stamp + * + * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it. + * + * @return + */ + public static String dateTime(Date date) { + GregorianCalendar gc = new GregorianCalendar(); + gc.setTime(date); + return dateTime(gc); + } + + /** + * JAXB compatible dataTime Stamp + * + * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it. + * + * @return + */ + public static String dateTime(GregorianCalendar gc) { + if(gc == null)return ""; + TimeZone tz = gc.getTimeZone(); + int tz1 = (tz.getRawOffset()+tz.getDSTSavings())/0x8CA0; + int tz1abs = Math.abs(tz1); + return String.format("%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d:%02d", + gc.get(GregorianCalendar.YEAR), + gc.get(GregorianCalendar.MONTH)+1, + gc.get(GregorianCalendar.DAY_OF_MONTH), + gc.get(GregorianCalendar.HOUR), + gc.get(GregorianCalendar.MINUTE), + gc.get(GregorianCalendar.SECOND), + gc.get(GregorianCalendar.MILLISECOND), + tz1==tz1abs?'+':'-', + tz1abs/100, + ((tz1abs-(tz1abs/100)*100)*6)/10 // Get the "10s", then convert to mins (without losing int place) + ); + } + + /** + * JAXB compatible dataTime Stamp + * + * Java 6 does not format Timezone with -05:00 format, and JAXB XML breaks without it. + * + * @return + */ + public static String dateTime(XMLGregorianCalendar xgc) { + return xgc==null?"":dateTime(xgc.toGregorianCalendar()); + } + + public static String dateOnlyStamp() { + return dateOnlyFmt.format(new Date()); + } + + public static String dateOnlyStamp(GregorianCalendar gc) { + return gc == null?"":dateOnlyFmt.format(gc.getTime()); + } + + public static String dateOnlyStamp(Date date) { + return date == null?"":dateOnlyFmt.format(date); + } + + public static String dateOnlyStamp(XMLGregorianCalendar xgc) { + return xgc==null?"":dateOnlyFmt.format(xgc.toGregorianCalendar().getTime()); + } + + public static String niceDateStamp() { + return niceDateFmt.format(new Date()); + } + + public static String niceDateStamp(Date date) { + return date==null?"":niceDateFmt.format(date); + } + + public static String niceDateStamp(GregorianCalendar gc) { + return gc==null?"":niceDateFmt.format(gc.getTime()); + } + + public static String niceDateStamp(XMLGregorianCalendar xgc) { + return xgc==null?"":niceDateFmt.format(xgc.toGregorianCalendar().getTime()); + } + + + ////////////////////// HELPFUL Strings + public static final String BAD_DIR_CHARS_REGEX = "[/:\\;.]"; + public static final String SPLIT_DIR_REGEX = "/"; + + public static long firstMomentOfDay(long utc) { + GregorianCalendar begin = new GregorianCalendar(); + begin.setTimeInMillis(utc); + return firstMomentOfDay(begin).getTimeInMillis(); + } + + public static long lastMomentOfDay(long utc) { + GregorianCalendar end = new GregorianCalendar(); + end.setTimeInMillis(utc); + return lastMomentOfDay(end).getTimeInMillis(); + } + + public static GregorianCalendar firstMomentOfDay(GregorianCalendar begin) { + if(begin==null)begin = new GregorianCalendar(); + begin.set(GregorianCalendar.HOUR, 0); + begin.set(GregorianCalendar.AM_PM, GregorianCalendar.AM); + begin.set(GregorianCalendar.MINUTE, 0); + begin.set(GregorianCalendar.SECOND, 0); + begin.set(GregorianCalendar.MILLISECOND, 0); + return begin; + } + + public static GregorianCalendar lastMomentOfDay(GregorianCalendar end) { + if(end==null)end = new GregorianCalendar(); + end.set(GregorianCalendar.HOUR, 11); + end.set(GregorianCalendar.MINUTE, 59); + end.set(GregorianCalendar.SECOND, 59); + end.set(GregorianCalendar.MILLISECOND, 999); + end.set(GregorianCalendar.AM_PM, GregorianCalendar.PM); + return end; + } + + // UUID needs to be converted from UUID Epoch + public static final Date uuidToDate(UUID id) { + return new Date((id.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH)/10000); + } + + public static final long uuidToUnix(UUID id) { + return (id.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH)/10000; + } + + public static float millisFromNanos(long start, long end) { + return (end - start) / 1000000f; + } + + + private static long sequence = new SecureRandom().nextInt(); + private static synchronized long sequence() { + return ++sequence; + } + public static final UUID dateToUUID(Date d) { + /* + * From Cassandra : http://wiki.apache.org/cassandra/FAQ + Magic number obtained from #cassandra's thobbs, who + claims to have stolen it from a Python library. + */ + + long origTime = d.getTime(); + long time = origTime * 10000 + NUM_100NS_INTERVALS_SINCE_UUID_EPOCH; + long timeLow = time & 0xffffffffL; + long timeMid = time & 0xffff00000000L; + long timeHi = time & 0xfff000000000000L; + long upperLong = (timeLow << 32) | (timeMid >> 16) | (1 << 12) | (timeHi >> 48) ; + return new java.util.UUID(upperLong, (0xC000000000000000L | sequence())); + } + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/util/DoubleOutputStream.java b/env/src/main/java/org/onap/aaf/inno/env/util/DoubleOutputStream.java new file mode 100644 index 0000000..074b221 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/util/DoubleOutputStream.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.util; + +import java.io.IOException; +import java.io.OutputStream; + +public class DoubleOutputStream extends OutputStream { + private OutputStream[] oss; + private boolean[] close; + + /** + * Create a Double Stream Writer + * Some Streams should not be closed by this object (i.e. System.out), therefore, mark them with booleans + */ + public DoubleOutputStream(OutputStream a, boolean closeA, OutputStream b, boolean closeB) { + oss = new OutputStream[] {a,b}; + close = new boolean[] {closeA,closeB}; + } + + /** + * Write a single character. + * @throws IOException + */ + @Override + public void write(int c) throws IOException { + for(OutputStream os : oss) { + os.write(c); + } + } + + /** + * Write a portion of an array of characters. + * + * @param bbuf Array of characters + * @param off Offset from which to start writing characters + * @param len Number of characters to write + * @throws IOException + */ + @Override + public void write(byte bbuf[], int off, int len) throws IOException { + for(OutputStream os : oss) { + os.write(bbuf,off,len); + } + } + + @Override + public void write(byte[] b) throws IOException { + for(OutputStream os : oss) { + os.write(b); + } + } + + /* (non-Javadoc) + * @see java.io.OutputStream#close() + */ + @Override + public void close() throws IOException { + for(int i=0;icol++)super.write((int)' '); + } + + public int getIndent() { + return indent; + } + + public void toIndent() { + int end = indent * INDENT; + for (int i = 0; i < end; ++i) { + super.write((int) ' '); + } + col = end; + } +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/util/Pool.java b/env/src/main/java/org/onap/aaf/inno/env/util/Pool.java new file mode 100644 index 0000000..204d51a --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/util/Pool.java @@ -0,0 +1,395 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +/* + * Pool + * + * 5/27/2011 + */ +package org.onap.aaf.inno.env.util; + +import java.util.LinkedList; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.LogTarget; + +/** + * This Class pools on an As-Needed-Basis any particular kind of class, which is + * quite suitable for expensive operations. + * + * The user calls "get" on a Pool, and if a waiting resource (T) is available, + * it will be returned. Otherwise, one will be created with the "Creator" class + * (must be defined for (T)). + * + * You can Prime the instances to avoid huge startup costs + * + * The returned "Pooled" object simply has to call "done()" and the object is + * returned to the pool. If the developer does not return the object, a memory + * leak does not occur. There are no references to the object once "get" is + * called. However, the developer who does not return the object when done + * obviates the point of the pool, as new Objects are created in place of the + * Object not returned when another call to "get" is made. + * + * There is a cushion of extra objects, currently defaulted to MAX_RANGE. If the + * items returned become higher than the MAX_RANGE, the object is allowed to go + * out of scope, and be cleaned up. the default can be changed on a per-pool + * basis. + * + * + * + * @param + */ +public class Pool { + /** + * This is a constant which specified the default maximum number of unused + * objects to be held at any given time. + */ + private static final int MAX_RANGE = 6; // safety + + /** + * only Simple List needed. + * + * NOTE TO MAINTAINERS: THIS OBJECT DOES IT'S OWN SYNCHRONIZATION. All + * changes that touch list must account for correctly synchronizing list. + */ + private LinkedList> list; + + /** + * keep track of how many elements exist, to avoid asking list. + */ + private int count; + + /** + * Spares are those Object that are primed and ready to go. + */ + private int spares; + + /** + * Actual MAX number of spares allowed to hang around. Can be set to + * something besides the default MAX_RANGE. + */ + private int max_range = MAX_RANGE; + + /** + * The Creator for this particular pool. It must work for type T. + */ + private Creator creator; + + /** + * Create a new Pool, given the implementation of Creator, which must be + * able to create/destroy T objects at will. + * + * @param creator + */ + public Pool(Creator creator) { + count = spares = 0; + this.creator = creator; + list = new LinkedList>(); + } + + /** + * Preallocate a certain number of T Objects. Useful for services so that + * the first transactions don't get hit with all the Object creation costs + * + * @param lt + * @param prime + * @throws APIException + */ + public void prime(LogTarget lt, int prime) throws APIException { + for (int i = 0; i < prime; ++i) { + Pooled pt = new Pooled(creator.create(), this, lt); + synchronized (list) { + list.addFirst(pt); + ++count; + } + } + + } + + /** + * Destroy and remove all remaining objects. This is valuable for closing + * down all Allocated objects cleanly for exiting. It is also a good method + * for removing objects when, for instance, all Objects are invalid because + * of broken connections, etc. + */ + public void drain() { + synchronized (list) { + for (int i = 0; i < list.size(); ++i) { + Pooled pt = list.remove(); + creator.destroy(pt.content); + pt.logTarget.log("Pool drained ", creator.toString()); + } + count = spares = 0; + } + + } + + /** + * This is the essential function for Pool. Get an Object "T" inside a + * "Pooled" object. If there is a spare Object, then use it. If not, then + * create and pass back. + * + * This one uses a Null LogTarget + * + * IMPORTANT: When the use of this object is done (and the object is still + * in a valid state), then "done()" should be called immediately to allow + * the object to be reused. That is the point of the Pool... + * + * If the Object is in an invalid state, then "toss()" should be used so the + * Pool doesn't pass on invalid objects to others. + * + * @param lt + * @return + * @throws APIException + */ + public Pooled get() throws APIException { + Pooled pt; + synchronized (list) { + if (list.isEmpty()) { + pt = null; + } else { + pt = list.removeLast(); + --count; + creator.reuse(pt.content); + } + } + if (pt == null) { + if (spares < max_range) + ++spares; + pt = new Pooled(creator.create(), this, LogTarget.NULL); + } else { + if (spares > 1) + --spares; + } + return pt; + } + + /** + * This is the essential function for Pool. Get an Object "T" inside a + * "Pooled" object. If there is a spare Object, then use it. If not, then + * create and pass back. + * + * If you don't have access to a LogTarget from Env, use LogTarget.NULL + * + * IMPORTANT: When the use of this object is done (and the object is still + * in a valid state), then "done()" should be called immediately to allow + * the object to be reused. That is the point of the Pool... + * + * If the Object is in an invalid state, then "toss()" should be used so the + * Pool doesn't pass on invalid objects to others. + * + * @param lt + * @return + * @throws APIException + */ + public Pooled get(LogTarget lt) throws APIException { + Pooled pt; + synchronized (list) { + if (list.isEmpty()) { + pt = null; + } else { + pt = list.remove(); + --count; + creator.reuse(pt.content); + } + } + if (pt == null) { + if (spares < max_range) + ++spares; + pt = new Pooled(creator.create(), this, lt); + lt.log("Pool created ", creator.toString()); + } else { + if (spares > 1) + --spares; + } + return pt; + } + + /** + * This function will validate whether the Objects are still in a usable + * state. If not, they are tossed from the Pool. This is valuable to have + * when Remote Connections go down, and there is a question on whether the + * Pooled Objects are still functional. + * + * @return + */ + public boolean validate() { + boolean rv = true; + synchronized (list) { + for (Pooled t : list) { + if (!creator.isValid(t.content)) { + rv = false; + t.toss(); + list.remove(t); + } + } + } + return rv; + } + + /** + * This is an internal method, used only by the Internal Pooled class. + * + * The Pooled class "offers" it's Object back after use. It is an + * "offer", because Pool will simply destroy and remove the object if it has + * more than enough spares. + * + * @param lt + * @param used + * @return + */ + // Used only by Pooled + private boolean offer(LogTarget lt, Pooled used) { + if (count < spares) { + synchronized (list) { + list.addFirst(used); + ++count; + } + lt.log("Pool recovered ", creator.toString()); + } else { + lt.log("Pool destroyed ", creator.toString()); + creator.destroy(used.content); + } + return false; + } + + /** + * The Creator Interface give the Pool the ability to Create, Destroy and + * Validate the Objects it is maintaining. Thus, it is a specially written + * Implementation for each type. + * + * + * @param + */ + public interface Creator { + public T create() throws APIException; + + public void destroy(T t); + + public boolean isValid(T t); + + public void reuse(T t); + } + + /** + * The "Pooled" class is the transient class that wraps the actual Object + * T for API use/ It gives the ability to return ("done()", or "toss()") the + * Object to the Pool when processing is finished. + * + * For Safety, i.e. to avoid memory leaks and invalid Object States, there + * is a "finalize" method. It is strictly for when coder forgets to return + * the object, or perhaps hasn't covered the case during Exceptions or + * Runtime Exceptions with finally (preferred). This should not be + * considered normal procedure, as finalize() is called at an undetermined + * time during garbage collection, and is thus rather useless for a Pool. + * However, we don't want Coding Mistakes to put the whole program in an + * invalid state, so if something happened such that "done()" or "toss()" + * were not called, the resource is still cleaned up as well as possible. + * + * + * @param + */ + public static class Pooled { + public final T content; + private Pool pool; + protected LogTarget logTarget; + + /** + * Create the Wrapping Object Pooled. + * + * @param t + * @param pool + * @param logTarget + */ + public Pooled(T t, Pool pool, LogTarget logTarget) { + content = t; + this.pool = pool; + this.logTarget = logTarget; + } + + /** + * This is the key API for the Pool, as calling "done()" offers this + * object back to the Pool for reuse. + * + * Do not use the Pooled object again after calling "done()". + */ + public void done() { + if (pool != null) { + pool.offer(logTarget, this); + } + } + + /** + * The user of the Object may discover that the Object t is no longer in + * a valid state. Don't put Garbage back in the Refrigerator... Toss it, + * if it's no longer valid. + * + * toss() is also used for draining the Pool, etc. + * + * toss() will attempt to destroy the Object by using the Creator + * Interface. + * + */ + public void toss() { + if (pool != null) { + pool.creator.destroy(content); + } + // Don't allow finalize to put it back in. + pool = null; + } + + /** + * Just in case someone neglected to offer back object... Do not rely on + * this, as there is no specific time when finalize is called, which + * rather defeats the purpose of a Pool. + */ + @Override + protected void finalize() throws Throwable { + if (pool != null) { + done(); + pool = null; + } + } + } + + /** + * Get the maximum number of spare objects allowed at any moment + * + * @return + */ + public int getMaxRange() { + return max_range; + } + + /** + * Set a Max Range for numbers of spare objects waiting to be used. + * + * No negative numbers are allowed + * + * @return + */ + public void setMaxRange(int max_range) { + // Do not allow negative numbers + this.max_range = Math.max(0, max_range); + } + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/util/RefreshableThreadObject.java b/env/src/main/java/org/onap/aaf/inno/env/util/RefreshableThreadObject.java new file mode 100644 index 0000000..af2cc2f --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/util/RefreshableThreadObject.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.util; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.Creatable; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.LifeCycle; + + +/** + *

RefreshableThreadObject

+ * This is a ThreadLocal like implementation, but it responds to + * the {@link LifeCycle} mechanism for configuration refreshes, and + * implements {@link Creatable} (for use in destroy, etc).

+ * + * In addition to the Thread instance semantics, it compares when the object + * was created versus the last "refresh(env)" call when getting, for the + * thread, and if necessary to replace the created object, destroying the + * previous.

+ * + * In most cases, it's better to use the new "Pool" mechanism, as it deals with + * gaining and returning resources on an as needed basis. This, however, remains + * in the cases where specific Objects need to be retained to specific Threads.

+ * + * There is no way to do this kind of specialized behavior in ThreadLocal. + * + * + * @param + */ +public class RefreshableThreadObject> { + private Map objs; + private long refreshed; + private Constructor cnst; + + /** + * The passed in class must implement the constructor + *

+	 *   public MyClass(Env env) {
+	 *     ...
+	 *   }
+	 * 
+ * @param clss + * @throws APIException + */ + public RefreshableThreadObject(Class clss) throws APIException { + objs = Collections.synchronizedMap(new HashMap()); + try { + cnst = clss.getConstructor(new Class[]{Env.class} ); + } catch (Exception e) { + throw new APIException(e); + } + } + + /** + * Get the "T" class from the current thread + * + * @param env + * @return T + * @throws APIException + */ + public T get(Env env) throws APIException { + Thread t = Thread.currentThread(); + T obj = objs.get(t); + if(obj==null || refreshed>obj.created()) { + try { + obj = cnst.newInstance(new Object[]{env}); + } catch (InvocationTargetException e) { + throw new APIException(e.getTargetException()); + } catch (Exception e) { + throw new APIException(e); + } + T destroyMe = objs.put(t,obj); + if(destroyMe!=null) { + destroyMe.destroy(env); + } + } + return obj; + } + + /** + * Mark the timestamp of refreshed. + * + * @param env + */ + public void refresh(Env env) { + refreshed = System.currentTimeMillis(); + } + + /** + * Remove the object from the Thread instances + * @param env + */ + public void remove(Env env) { + T obj = objs.remove(Thread.currentThread()); + if(obj!=null) + obj.destroy(env); + } +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/util/Split.java b/env/src/main/java/org/onap/aaf/inno/env/util/Split.java new file mode 100644 index 0000000..1ccfc46 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/util/Split.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.util; + +/** + * Split by Char, optional Trim + * + * Note: I read the String split and Pattern split code, and we can do this more efficiently for a single Character + * + * 8/20/2015 + */ + +public class Split { + public static String[] split(char c, String value) { + // Count items to preallocate Array (memory alloc is more expensive than counting twice) + int count,idx; + for(count=1,idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,++idx),++count); + String[] rv = new String[count]; + if(count==1) { + rv[0]=value; + } else { + int last=0; + count=-1; + for(idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,idx)) { + rv[++count]=value.substring(last,idx); + last = ++idx; + } + rv[++count]=value.substring(last); + } + return rv; + } + + public static String[] splitTrim(char c, String value) { + // Count items to preallocate Array (memory alloc is more expensive than counting twice) + int count,idx; + for(count=1,idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,++idx),++count); + String[] rv = new String[count]; + if(count==1) { + rv[0]=value.trim(); + } else { + int last=0; + count=-1; + for(idx=value.indexOf(c);idx>=0;idx=value.indexOf(c,idx)) { + rv[++count]=value.substring(last,idx).trim(); + last = ++idx; + } + rv[++count]=value.substring(last).trim(); + } + return rv; + } + + public static String[] splitTrim(char c, String value, int size) { + int idx; + String[] rv = new String[size]; + if(size==1) { + rv[0]=value.trim(); + } else { + int last=0; + int count=-1; + size-=2; + for(idx=value.indexOf(c);idx>=0 && countbyte values that will fit into this buffer + * before it is automatically expanded + * + * @throws IllegalArgumentException + * If initialSize is negative + */ + public StringBuilderOutputStream(int initialSize) { + if (initialSize < 0) { + throw new IllegalArgumentException("Negative buffer size"); + } + buf = new StringBuilder(initialSize); + } + + /** + * Write a single character. + */ + public void write(int c) { + buf.append((byte) c); + } + + /** + * Write a portion of an array of characters. + * + * @param bbuf Array of characters + * @param off Offset from which to start writing characters + * @param len Number of characters to write + */ + + public void write(byte bbuf[], int off, int len) { + if ((off < 0) || (off > bbuf.length) || (len < 0) || + ((off + len) > bbuf.length) || ((off + len) < 0)) { + throw new IndexOutOfBoundsException(); + } else if (len == 0) { + return; + } + buf.append(new String(bbuf, off, len)); + } + + @Override + public void write(byte[] b) throws IOException { + buf.append(new String(b)); + } + + /** + * Write a string. + */ + public void write(String str) { + buf.append(str); + } + + /** + * Write a portion of a string. + * + * @param str String to be written + * @param off Offset from which to start writing characters + * @param len Number of characters to write + */ + public void write(String str, int off, int len) { + buf.append(str,off,len); + } + + public StringBuilderOutputStream append(CharSequence csq) { + if (csq == null) { + write("null"); + } else { + for(int i = 0;i An invocation of this method of the form out.append(c) + * behaves in exactly the same way as the invocation + * + *
+     *     out.write(c) 
+ * + * @param c + * The 16-bit character to append + * + * @return This writer + * + * @since 1.5 + */ + public StringBuilderOutputStream append(byte c) { + buf.append(c); + return this; + } + + /** + * Return the buffer's current value as a string. + */ + public String toString() { + return buf.toString(); + } + + /** + * Return the string buffer itself. + * + * @return StringBuffer holding the current buffer value. + */ + public StringBuilder getBuffer() { + return buf; + } + + public void reset() { + buf.setLength(0); + } + + @Override + public void flush() throws IOException { + } + + @Override + public void close() throws IOException { + } + +} diff --git a/env/src/main/java/org/onap/aaf/inno/env/util/StringBuilderWriter.java b/env/src/main/java/org/onap/aaf/inno/env/util/StringBuilderWriter.java new file mode 100644 index 0000000..48fa808 --- /dev/null +++ b/env/src/main/java/org/onap/aaf/inno/env/util/StringBuilderWriter.java @@ -0,0 +1,173 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.util; + +import java.io.IOException; +import java.io.Writer; + +public class StringBuilderWriter extends Writer { + private StringBuilder buf; + + + /** + * Create a new string writer using the default initial string-buffer + * size. + */ + public StringBuilderWriter() { + buf = new StringBuilder(); + } + + /** + * Create a new string writer using a passed in StringBuilder + * size. + */ + public StringBuilderWriter(StringBuilder sb) { + buf = sb; + } + + /** + * Create a new string writer using the specified initial string-buffer + * size. + * + * @param initialSize + * The number of char values that will fit into this buffer + * before it is automatically expanded + * + * @throws IllegalArgumentException + * If initialSize is negative + */ + public StringBuilderWriter(int initialSize) { + if (initialSize < 0) { + throw new IllegalArgumentException("Negative buffer size"); + } + buf = new StringBuilder(initialSize); + } + + /** + * Write a single character. + */ + public void write(int c) { + buf.append((char) c); + } + + /** + * Write a portion of an array of characters. + * + * @param cbuf Array of characters + * @param off Offset from which to start writing characters + * @param len Number of characters to write + */ + public void write(char cbuf[], int off, int len) { + if ((off < 0) || (off > cbuf.length) || (len < 0) || + ((off + len) > cbuf.length) || ((off + len) < 0)) { + throw new IndexOutOfBoundsException(); + } else if (len == 0) { + return; + } + buf.append(cbuf, off, len); + } + + /** + * Write a string. + */ + public void write(String str) { + buf.append(str); + } + + /** + * Write a portion of a string. + * + * @param str String to be written + * @param off Offset from which to start writing characters + * @param len Number of characters to write + */ + public void write(String str, int off, int len) { + char[] chars = new char[len]; + str.getChars(off, off+len, chars, 0); + buf.append(chars); + } + + public StringBuilderWriter append(CharSequence csq) { + if (csq == null) { + write("null"); + } else { + buf.append(csq); + } + return this; + } + + public StringBuilderWriter append(CharSequence csq, int start, int end) { + CharSequence cs = (csq == null ? "null" : csq); + return append(cs.subSequence(start, end)); + } + + /** + * Appends the specified character to this writer. + * + *

An invocation of this method of the form out.append(c) + * behaves in exactly the same way as the invocation + * + *

+     *     out.write(c) 
+ * + * @param c + * The 16-bit character to append + * + * @return This writer + * + * @since 1.5 + */ + public StringBuilderWriter append(char c) { + buf.append(c); + return this; + } + + /** + * Return the buffer's current value as a string. + */ + public String toString() { + return buf.toString(); + } + + /** + * Return the string buffer itself. + * + * @return StringBuffer holding the current buffer value. + */ + public StringBuilder getBuffer() { + return buf; + } + + public void reset() { + buf.setLength(0); + } + + @Override + public void flush() throws IOException { + } + + @Override + public void close() throws IOException { + } + +} diff --git a/log4j/pom.xml b/log4j/pom.xml index 0c07f0a..8053a2a 100644 --- a/log4j/pom.xml +++ b/log4j/pom.xml @@ -23,7 +23,7 @@ - com.att.inno + org.onap.aaf.inno parent 1.0.0-SNAPSHOT .. @@ -61,7 +61,7 @@ - com.att.inno + org.onap.aaf.inno env ${project.version} 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 deleted file mode 100644 index 335fbcd..0000000 --- a/log4j/src/main/java/com/att/inno/env/log4j/LogFileNamer.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.log4j; - -import java.io.File; -import java.net.URL; - -public class LogFileNamer { - public static final int pid = PIDAccess.INSTANCE.getpid(); - public final String root; - private boolean printPID; - - public LogFileNamer(String root) { - if(root==null || "".equals(root) || root.endsWith("/")) { - this.root = root; - } else { - this.root = root + "-"; - } - printPID=true; - } - - public LogFileNamer noPID() { - printPID = false; - return this; - } - /** - * Accepts a String. - * If Separated by "|" then first part is the Appender name, and the second is used in the FileNaming - * (This is to allow for shortened Logger names, and more verbose file names) - * - * @param appender - * - * returns the String Appender - */ - public String setAppender(String appender) { - int pipe = appender.indexOf('|'); - if(pipe>=0) { - String rv; - System.setProperty( - "LOG4J_FILENAME_"+(rv=appender.substring(0,pipe)), - root + appender.substring(pipe+1) + (printPID?('-' + pid):"") + ".log"); - return rv; - } else { - System.setProperty( - "LOG4J_FILENAME_"+appender, - root + appender + (printPID?('-' + pid):"") + ".log"); - return appender; - } - - } - - public void configure(String props) { - String fname; - if(new File(fname="etc/"+props).exists()) { - org.apache.log4j.PropertyConfigurator.configureAndWatch(fname,60*1000); - } else { - URL rsrc = ClassLoader.getSystemResource(props); - if(rsrc==null) System.err.println("Neither File: " + fname + " or resource on Classpath " + props + " exist" ); - org.apache.log4j.PropertyConfigurator.configure(rsrc); - } - } -} 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 deleted file mode 100644 index a4f1d98..0000000 --- a/log4j/src/main/java/com/att/inno/env/log4j/PIDAccess.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.log4j; - -import com.sun.jna.Library; -import com.sun.jna.Native; - -public interface PIDAccess extends Library { - PIDAccess INSTANCE = (PIDAccess) Native.loadLibrary("c", PIDAccess.class); - int getpid (); -} diff --git a/log4j/src/main/java/org/onap/aaf/inno/env/log4j/LogFileNamer.java b/log4j/src/main/java/org/onap/aaf/inno/env/log4j/LogFileNamer.java new file mode 100644 index 0000000..e1abe10 --- /dev/null +++ b/log4j/src/main/java/org/onap/aaf/inno/env/log4j/LogFileNamer.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.log4j; + +import java.io.File; +import java.net.URL; + +public class LogFileNamer { + public static final int pid = PIDAccess.INSTANCE.getpid(); + public final String root; + private boolean printPID; + + public LogFileNamer(String root) { + if(root==null || "".equals(root) || root.endsWith("/")) { + this.root = root; + } else { + this.root = root + "-"; + } + printPID=true; + } + + public LogFileNamer noPID() { + printPID = false; + return this; + } + /** + * Accepts a String. + * If Separated by "|" then first part is the Appender name, and the second is used in the FileNaming + * (This is to allow for shortened Logger names, and more verbose file names) + * + * @param appender + * + * returns the String Appender + */ + public String setAppender(String appender) { + int pipe = appender.indexOf('|'); + if(pipe>=0) { + String rv; + System.setProperty( + "LOG4J_FILENAME_"+(rv=appender.substring(0,pipe)), + root + appender.substring(pipe+1) + (printPID?('-' + pid):"") + ".log"); + return rv; + } else { + System.setProperty( + "LOG4J_FILENAME_"+appender, + root + appender + (printPID?('-' + pid):"") + ".log"); + return appender; + } + + } + + public void configure(String props) { + String fname; + if(new File(fname="etc/"+props).exists()) { + org.apache.log4j.PropertyConfigurator.configureAndWatch(fname,60*1000); + } else { + URL rsrc = ClassLoader.getSystemResource(props); + if(rsrc==null) System.err.println("Neither File: " + fname + " or resource on Classpath " + props + " exist" ); + org.apache.log4j.PropertyConfigurator.configure(rsrc); + } + } +} diff --git a/log4j/src/main/java/org/onap/aaf/inno/env/log4j/PIDAccess.java b/log4j/src/main/java/org/onap/aaf/inno/env/log4j/PIDAccess.java new file mode 100644 index 0000000..1a949a7 --- /dev/null +++ b/log4j/src/main/java/org/onap/aaf/inno/env/log4j/PIDAccess.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.log4j; + +import com.sun.jna.Library; +import com.sun.jna.Native; + +public interface PIDAccess extends Library { + PIDAccess INSTANCE = (PIDAccess) Native.loadLibrary("c", PIDAccess.class); + int getpid (); +} 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 deleted file mode 100644 index f3594f5..0000000 --- a/log4j/src/test/java/com/att/inno/env/log4j/LogTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.inno.env.log4j; - -import java.util.logging.Logger; - - -public class LogTest -{ - public static void main(String[] args) throws Exception - { - LogFileNamer lfn = new LogFileNamer("authz"); - lfn.setAppender("service"); - lfn.setAppender("init"); - lfn.setAppender("audit"); - lfn.setAppender("test"); - lfn.configure("src/test/resources/log4j-test.properties"); - Logger log = Logger.getLogger( "init" ); - - - - log.info("Hello"); - } -} diff --git a/log4j/src/test/java/org/onap/aaf/inno/env/log4j/LogTest.java b/log4j/src/test/java/org/onap/aaf/inno/env/log4j/LogTest.java new file mode 100644 index 0000000..d34ed19 --- /dev/null +++ b/log4j/src/test/java/org/onap/aaf/inno/env/log4j/LogTest.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.inno.env.log4j; + +import java.util.logging.Logger; + +import org.onap.aaf.inno.env.log4j.LogFileNamer; + + +public class LogTest +{ + public static void main(String[] args) throws Exception + { + LogFileNamer lfn = new LogFileNamer("authz"); + lfn.setAppender("service"); + lfn.setAppender("init"); + lfn.setAppender("audit"); + lfn.setAppender("test"); + lfn.configure("src/test/resources/log4j-test.properties"); + Logger log = Logger.getLogger( "init" ); + + + + log.info("Hello"); + } +} diff --git a/pom.xml b/pom.xml index a79a537..9bec264 100644 --- a/pom.xml +++ b/pom.xml @@ -1,30 +1,31 @@ 4.0.0 - com.att.inno + org.onap.aaf.inno parent inno 1.0.0-SNAPSHOT @@ -205,12 +206,12 @@ - com.att.cadi + org.onap.aaf.cadi cadi-core ${project.cadiVersion} - com.att.cadi + org.onap.aaf.cadi cadi-aaf ${project.cadiVersion} diff --git a/rosetta/pom.xml b/rosetta/pom.xml index 644c21b..0c9238b 100644 --- a/rosetta/pom.xml +++ b/rosetta/pom.xml @@ -23,7 +23,7 @@ - com.att.inno + org.onap.aaf.inno parent 1.0.0-SNAPSHOT .. @@ -61,18 +61,18 @@ - com.att.inno + org.onap.aaf.inno env ${project.version} @@ -109,23 +109,6 @@ - - - org.apache.maven.plugins maven-deploy-plugin diff --git a/rosetta/src/main/java/com/att/rosetta/InJson.java b/rosetta/src/main/java/com/att/rosetta/InJson.java deleted file mode 100644 index ba14c4a..0000000 --- a/rosetta/src/main/java/com/att/rosetta/InJson.java +++ /dev/null @@ -1,155 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta; - -import java.io.IOException; -import java.io.Reader; - -import com.att.inno.env.Env; -import com.att.inno.env.TimeTaken; -import com.att.rosetta.InJson.State; - -public class InJson implements Parse { - public Parsed parse(Reader r, Parsed parsed) throws ParseException { - // First things first, if there's a "leftover" event, process that immediately - State state = (State)parsed.state; - if(state.unsent > 0) { - parsed.event = state.unsent; - state.unsent = 0; - return parsed; - } - - int ch; - char c; - StringBuilder sb = parsed.sb; - boolean inQuotes = false, escaped = false; - boolean go = true; - try { - // Gather data from Reader, looking for special characters when not in Quotes - while(go && (ch=r.read())>=0) { - if(state.braces>=0 || ch==Parse.START_OBJ) { // ignore garbage/whitespace before content - c=(char)ch; - // Character is a quote. - if(c=='"') { - if(inQuotes) { - if(escaped) { // if escaped Quote, add to data. - sb.append(c); - escaped = false; - } else { - inQuotes = false; - } - } else { - parsed.isString=true; - inQuotes = true; - } - } else { // Not a Quote - if(inQuotes) { - if(c=='\\') { - if(escaped) { - sb.append("\\\\"); - escaped = false; - } else { - escaped = true; - } - } else { - sb.append(c); - } - } else { - switch(c) { - case ':': - parsed.dataIsName(); - parsed.isString = false; - break; - case Parse.START_OBJ: - if(state.braces++ == 0) { - parsed.event = START_DOC; - state.unsent = c; - } else { - parsed.event = c; - } - go = false; - break; - case Parse.END_OBJ: - if(--state.braces == 0) { - parsed.event = c; - state.unsent = END_DOC; - } else { - parsed.event = c; - } - go = false; - break; - // These three end the data gathering, and send it along with the event that is ending the data gathering - case Parse.NEXT: - if(parsed.name.startsWith("__")) { - parsed.event = Parse.ATTRIB; - parsed.name = parsed.name.substring(2); - } else { - parsed.event = c; - } - go = false; - break; - case Parse.START_ARRAY: - case Parse.END_ARRAY: - parsed.event = c; - go = false; - break; - - // The Escape Sequence, for Quote marks within Quotes - case '\\': - // Ignore these, unless within quotes, at which point data-gather - case ' ': - case '\b': - case '\f': - case '\n': - case '\r': - case '\t': - break; - // Normal data... gather it - default: - sb.append(c); - } - } - } - } - } - return parsed; - } catch (IOException e) { - throw new ParseException(e); - } - } - - public static class State { - public int braces = 0; - public char unsent = 0; - } - -// @Override - public Parsed newParsed() { - return new Parsed(new State()); // no State needed - } - -// @Override - public TimeTaken start(Env env) { - return env.start("Rosetta JSON In", Env.JSON); - } -} diff --git a/rosetta/src/main/java/com/att/rosetta/InXML.java b/rosetta/src/main/java/com/att/rosetta/InXML.java deleted file mode 100644 index 945fb75..0000000 --- a/rosetta/src/main/java/com/att/rosetta/InXML.java +++ /dev/null @@ -1,487 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta; - -import java.io.IOException; -import java.io.Reader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Stack; - -import com.att.inno.env.Env; -import com.att.inno.env.TimeTaken; -import com.att.rosetta.InXML.State; - -public class InXML implements Parse { - // package on purpose - JaxInfo jaxInfo; - - public InXML(JaxInfo jaxInfo) { - this.jaxInfo = jaxInfo; - } - - public InXML(Class cls, String ... rootNs) throws SecurityException, NoSuchFieldException, ClassNotFoundException, ParseException { - jaxInfo = JaxInfo.build(cls,rootNs); - } - - - // @Override - public Parsed parse(Reader r, Parsed parsed) throws ParseException { - State state = parsed.state; - - // OK, before anything else, see if there is leftover processing, if so, do it! - if(state.unevaluated!=null) { - DerTag dt = state.unevaluated; - state.unevaluated = null; - if(!state.greatExp.eval(parsed, dt))return parsed; - } - - if(state.hasAttributes()) { - Prop prop = state.pop(); - parsed.event = Parse.ATTRIB; - parsed.name = prop.tag; - parsed.sb.append(prop.value); - parsed.isString=true; - return parsed; - } - int ch; - char c; - boolean inQuotes = false, escaped = false; - - StringBuilder sb = parsed.sb, tempSB = new StringBuilder(); - boolean go = true; - - try { - while(go && (ch=r.read())>=0) { - c = (char)ch; - if(c == '"') { - if(state.greatExp instanceof LeafExpectations) { // within a set of Tags, make a Quote - sb.append(c); - } else { - if(inQuotes) { - if(escaped) { - sb.append('\\'); - sb.append(c); - escaped = false; - } else { - inQuotes = false; - } - } else { - parsed.isString=true; - inQuotes = true; - } - } - } else if(inQuotes) { - sb.append(c); - } else if(c=='&') { - XmlEscape.xmlEscape(sb,r); - } else { - switch(c) { - case '<': - DerTag tag=new DerTag().parse(r, tempSB); - go = state.greatExp.eval(parsed, tag); - break; - default: - // don't add Whitespace to start of SB... saves removing later - if(sb.length()>0) { - sb.append(c); - } else if(!Character.isWhitespace(c)) { - sb.append(c); - } - } - } - } - return parsed; - } catch (IOException e) { - throw new ParseException(e); - } - } - - public static final class DerTag { - public String name; - public boolean isEndTag; - public List props; - private boolean isXmlInfo; - //private String ns; - - public DerTag() { - name=null; - isEndTag = false; - props = null; - isXmlInfo = false; - } - - public DerTag parse(Reader r, StringBuilder sb) throws ParseException { - int ch; - char c; - boolean inQuotes = false, escaped = false; - boolean go = true; - String tag = null; - - try { - if((ch = r.read())<0) throw new ParseException("Reader content ended before complete"); - if(ch=='?') { - isXmlInfo = true; - } - // TODO Check for !-- comments - do { - c=(char)ch; - if(c=='"') { - if(inQuotes) { - if(escaped) { - sb.append(c); - escaped = false; - } else { - inQuotes = false; - } - } else { - inQuotes = true; - } - } else if(inQuotes) { - sb.append(c); - } else { - switch(c) { - case '/': - isEndTag = true; - break; - case ' ': - endField(tag,sb); - tag = null; - break; - case '>': - endField(tag,sb); - go = false; - break; - case '=': - tag = sb.toString(); - sb.setLength(0); - break; -// case ':': -// ns = sb.toString(); -// sb.setLength(0); -// break; - case '?': - if(!isXmlInfo)sb.append(c); - break; - default: - sb.append(c); - } - } - } while(go && (ch=r.read())>=0); - } catch (IOException e) { - throw new ParseException(e); - } - return this; - } - - private void endField(String tag, StringBuilder sb) { - if(name==null) { - name = sb.toString(); - sb.setLength(0); - } else { - String value = sb.toString(); - sb.setLength(0); - if(tag !=null && value != null) { - if(props==null)props = new ArrayList(); - props.add(new Prop(tag,value)); - } - } - } - - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(isEndTag?"End":"Start"); - sb.append(" Tag\n"); - sb.append(" Name: "); - sb.append(name); - if(props!=null) for(Prop p : props) { - sb.append("\n "); - sb.append(p.tag); - sb.append("=\""); - sb.append(p.value); - sb.append('"'); - } - return sb.toString(); - } - } - - private static class ArrayState { - public boolean firstObj = true; - public boolean didNext = false; - } - - public static class State { - public GreatExpectations greatExp; - public DerTag unevaluated; - public Stack arrayInfo; - private List attribs; - private int idx; - public State(JaxInfo ji, DerTag dt) throws ParseException { - greatExp = new RootExpectations(this, ji, null); - unevaluated = null; - attribs = null;; - } - - public boolean hasAttributes() { - return attribs!=null && idx(); - idx = 0; - } - attribs.add(prop); - } - - public Prop pop() { - Prop rv = null; - if(attribs!=null) { - rv = attribs.get(idx++); - if(idx>=attribs.size())attribs = null; - } - return rv; - } - } - - private static abstract class GreatExpectations { - protected JaxInfo ji; - protected GreatExpectations prev; - private Map ns; - - public GreatExpectations(State state, JaxInfo curr, GreatExpectations prev, DerTag derTag) throws ParseException { - this.prev = prev; - ns = null; - ji = getDerived(state, curr,derTag); - } - - public abstract boolean eval(Parsed parsed, DerTag derTag) throws ParseException; - - // Recursively look back for any namespaces - protected Map getNS() { - if(ns!=null)return ns; - if(prev!=null) { - return prev.getNS(); - } - return null; - } - - private void addNS(Prop prop) { - Map existingNS = getNS(); - if(ns==null)ns = new HashMap(); - // First make a copy of previous NSs so that we have everything we need, but can overwrite, if necessary - if(existingNS!=null && ns!=existingNS) { - ns.putAll(ns); - } - ns.put(prop.tag, prop.value); - } - - private JaxInfo getDerived(State state, JaxInfo ji, DerTag derTag) throws ParseException { - if(derTag==null)return ji; - - List props = derTag.props; - - Prop derived = null; - if(props!=null) { - // Load Namespaces (if any) - for(Prop prop : props) { - if(prop.tag.startsWith("xmlns:")) { - addNS(prop); - } - } - for(Prop prop : props) { - if(prop.tag.endsWith(":type")) { - int idx = prop.tag.indexOf(':'); - String potentialNS = "xmlns:"+prop.tag.substring(0,idx); - Map ns = getNS(); - boolean noNamespace = false; - if(ns==null) { - noNamespace = true; - } else { - String nsVal = ns.get(potentialNS); - if(nsVal==null) noNamespace = true; - else { - derived = new Prop(Parsed.EXTENSION_TAG,prop.value); - state.push(derived); - } - } - if(noNamespace) { - throw new ParseException(prop.tag + " utilizes an invalid Namespace prefix"); - } - } else if(!prop.tag.startsWith("xmlns")) { - state.push(prop); - } - } - } - return derived==null?ji:ji.getDerived(derived.value); - } - } - - private static class RootExpectations extends GreatExpectations { - - public RootExpectations(State state, JaxInfo curr, GreatExpectations prev) throws ParseException { - super(state,curr,prev, null); - } - - // @Override - public boolean eval(Parsed parsed, DerTag derTag) throws ParseException { - if(derTag.isXmlInfo) { - parsed.event = START_DOC; - } else if(ji.name.equals(derTag.name)) { - if(derTag.isEndTag) { - parsed.event = END_DOC; - parsed.state.greatExp = prev; - } else { - //parsed.name = derTag.name; - parsed.event = START_OBJ; - parsed.state.greatExp = new ObjectExpectations(parsed.state,ji, this, false, derTag); - } - } - return false; - } - } - - private static class ObjectExpectations extends GreatExpectations { - private boolean printName; - - public ObjectExpectations(State state, JaxInfo curr, GreatExpectations prev, boolean printName, DerTag derTag) throws ParseException { - super(state, curr, prev, derTag); - this.printName=printName; - } - - // @Override - public boolean eval(Parsed parsed, DerTag derTag) throws ParseException { - if(derTag.isEndTag && ji.name.equals(derTag.name)) { - parsed.state.greatExp = prev; - parsed.event = END_OBJ; - if(printName)parsed.name = ji.name; - } else { - //Standard Members - for(JaxInfo memb : ji.members) { - if(memb.name.equals(derTag.name)) { - parsed.name = memb.name; - if(memb.isArray) { - parsed.state.unevaluated = derTag; // evaluate within Array Context - parsed.event = START_ARRAY; - parsed.state.greatExp = new ArrayExpectations(parsed.state,memb,this); - return false; - } else if(memb.isObject()) { - if(derTag.isEndTag) { - throw new ParseException("Unexpected End Tag '); - } else { - parsed.event = START_OBJ; - - parsed.state.greatExp = new ObjectExpectations(parsed.state, memb,this,true,derTag); - return false; - } - } else { // a leaf - if(derTag.isEndTag) { - throw new ParseException("Misplaced End Tag '); - } else { - parsed.state.greatExp = new LeafExpectations(parsed.state,memb, this); - return true; // finish out Leaf without returning - } - } - } - } - - throw new ParseException("Unexpected Tag <" + derTag.name + '>'); - } - return false; - } - } - - private static class LeafExpectations extends GreatExpectations { - public LeafExpectations(State state, JaxInfo curr, GreatExpectations prev) throws ParseException { - super(state, curr, prev, null); - } - - // @Override - public boolean eval(Parsed parsed, DerTag derTag) throws ParseException { - if(ji.name.equals(derTag.name) && derTag.isEndTag) { - parsed.event = NEXT; - parsed.isString = ji.isString; - parsed.state.greatExp = prev; - } else { - throw new ParseException("Expected '); - } - return false; - } - } - - private static class ArrayExpectations extends GreatExpectations { - public ArrayExpectations(State state, JaxInfo ji, GreatExpectations prev) throws ParseException { - super(state, ji, prev,null); - if(state.arrayInfo==null)state.arrayInfo=new Stack(); - state.arrayInfo.push(new ArrayState()); - } - // @Override - public boolean eval(Parsed parsed, DerTag derTag) throws ParseException { - if(ji.name.equals(derTag.name) && !derTag.isEndTag) { - if(ji.isObject()) { - if(derTag.isEndTag) { - throw new ParseException("Unexpected End Tag '); - } else { - ArrayState ai = parsed.state.arrayInfo.peek(); - if(ai.firstObj || ai.didNext) { - ai.firstObj = false; - ai.didNext = false; - parsed.event = START_OBJ; - parsed.name=derTag.name; - parsed.state.greatExp = new ObjectExpectations(parsed.state,ji,this,true, derTag); - } else { - ai.didNext = true; - parsed.event = NEXT; - parsed.state.unevaluated = derTag; - } - } - } else { // a leave - if(derTag.isEndTag) { - throw new ParseException("Misplaced End Tag '); - } else { - parsed.state.greatExp = new LeafExpectations(parsed.state, ji, this); - return true; // finish out Leaf without returning - } - } - } else { // Tag now different... Array is done - parsed.state.unevaluated = derTag; - parsed.event=END_ARRAY; - parsed.state.greatExp = prev; - parsed.state.arrayInfo.pop(); - } - return false; - } - } - // @Override - public Parsed newParsed() throws ParseException { - return new Parsed(new State(jaxInfo, null)); - } - - // @Override - public TimeTaken start(Env env) { - return env.start("Rosetta XML In", Env.XML); - } - -} diff --git a/rosetta/src/main/java/com/att/rosetta/JaxEval.java b/rosetta/src/main/java/com/att/rosetta/JaxEval.java deleted file mode 100644 index 22bdde2..0000000 --- a/rosetta/src/main/java/com/att/rosetta/JaxEval.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta; - -public interface JaxEval{ - public abstract JaxEval eval(Parsed p) throws ParseException; -} diff --git a/rosetta/src/main/java/com/att/rosetta/JaxInfo.java b/rosetta/src/main/java/com/att/rosetta/JaxInfo.java deleted file mode 100644 index c7c0430..0000000 --- a/rosetta/src/main/java/com/att/rosetta/JaxInfo.java +++ /dev/null @@ -1,249 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta; - -import java.lang.reflect.Field; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlSchema; -import javax.xml.bind.annotation.XmlType; -import javax.xml.datatype.XMLGregorianCalendar; - -public class JaxInfo { - private static final String DEFAULT = "##default"; - public static final int DATA = 0; - public static final int ARRAY = 1; - public static final int OBJECT = 2; - - public final String name; - public final Class clss; - public Map extensions; // Classes, which might be found at runtime, that extend this class. Lazy Instantiation - public final JaxInfo[] members; - public final boolean isArray; - public final boolean isString; - public final boolean required; - public final boolean nillable; - public String ns; - public boolean isObject() {return members!=null;} - - private JaxInfo(String n, String ns, Class c, JaxInfo[] members, boolean string, boolean array, boolean required, boolean nillable) { - name = n; - this.ns = ns; - clss = c; - this.members = members; - this.isString = string; - isArray = array; - this.required = required; - this.nillable = nillable; - extensions = null; - } - - - public int getType() { - if(isArray)return ARRAY; - else if(members!=null)return OBJECT; - return DATA; - } - - public JaxInfo getDerived(String derivedName) { - JaxInfo derived; - // Lazy Instantiation - if(extensions == null) { - extensions = new HashMap(); - derived = null; - } else { - derived = extensions.get(derivedName); - } - - if(derived == null) { - //TODO for the moment, Classes are in same package - Package pkg = clss.getPackage(); - try { - Class dc = getClass().getClassLoader().loadClass(pkg.getName()+'.'+Character.toUpperCase(derivedName.charAt(0))+derivedName.substring(1)); - derived = JaxInfo.build(dc, this); // Use this JAXInfo's name so the tags are correct - extensions.put(derivedName, derived); - } catch (Exception e) { - e.printStackTrace(); - } - } - return derived; - } - - public static JaxInfo get(JaxInfo[] fields, String name) { - for(JaxInfo f : fields) { - if(name.equals(f.name)) return f; - } - return null; - } - - /** - * Build up JAXB Information (recursively) - * - * @param cls - * @param rootNns - * @return - * @throws SecurityException - * @throws NoSuchFieldException - * @throws ClassNotFoundException - * @throws ParseException - */ - public static JaxInfo build(Class cls, JaxInfo parent) throws NoSuchFieldException, ClassNotFoundException, ParseException { - return new JaxInfo(parent.name,parent.ns, cls,buildFields(cls,parent.ns),parent.isString, parent.isArray,parent.required,parent.nillable); - } - /** - * Build up JAXB Information (recursively) - * - * @param cls - * @param rootNns - * @return - * @throws SecurityException - * @throws NoSuchFieldException - * @throws ClassNotFoundException - * @throws ParseException - */ - public static JaxInfo build(Class cls, String ... rootNns) throws SecurityException, NoSuchFieldException, ClassNotFoundException, ParseException { - String defaultNS; - if(rootNns.length>0 && rootNns[0]!=null) { - defaultNS = rootNns[0]; - } else { - Package pkg = cls.getPackage(); - XmlSchema xs = pkg.getAnnotation(XmlSchema.class); - defaultNS = xs==null?"":xs.namespace(); - } - String name; - if(rootNns.length>1) { - name = rootNns[1]; - } else { - XmlRootElement xre = cls.getAnnotation(XmlRootElement.class); - if(xre!=null) { - name = xre.name(); - } else { - XmlType xt = cls.getAnnotation(XmlType.class); - if(xt!=null) { - name=xt.name(); - } else { - throw new ParseException("Need a JAXB Object with XmlRootElement, or stipulate in parms"); - } - } - } - - return new JaxInfo(name,defaultNS, cls,buildFields(cls,defaultNS),false,false,false,false); - } - - // Build up the name and members of this particular class - // This is recursive, if a member is a JAXB Object as well. - private static JaxInfo[] buildFields(Class clazz, String defaultNS) throws SecurityException, NoSuchFieldException, ClassNotFoundException { - ArrayList fields = null; // allow for lazy instantiation, because many structures won't have XmlType - Class cls = clazz; - // Build up Method names from JAXB Annotations - XmlType xt; - while((xt = cls.getAnnotation(XmlType.class))!=null) { - if(fields==null)fields = new ArrayList(); - for(String field : xt.propOrder()) { - if("".equals(field)) break; // odd bug. "" returned when no fields exist, rather than empty array - Field rf = cls.getDeclaredField(field); - Class ft = rf.getType(); - - boolean required = false; - boolean nillable = false; - String xmlName = field; - String namespace = defaultNS; - - XmlElement xe = rf.getAnnotation(XmlElement.class); - if(xe!=null) { - xmlName=xe.name(); - required = xe.required(); - nillable = false; - if(DEFAULT.equals(xmlName)) { - xmlName = field; - } - namespace = xe.namespace(); - if(DEFAULT.equals(namespace)) { - namespace = defaultNS; - } - } - // If object is a List, then it is possible multiple, per XML/JAXB evaluation - if(ft.isAssignableFrom(List.class)) { - Type t = rf.getGenericType(); - String classname = t.toString(); - int start = classname.indexOf('<'); - int end = classname.indexOf('>'); - Class genClass = Class.forName(classname.substring(start+1, end)); - xe = genClass.getAnnotation(XmlElement.class); - if(xe!=null && !DEFAULT.equals(xe.namespace())) { - namespace = xe.namespace(); - } - // add recursed recursed member, marked as array - fields.add(new JaxInfo(xmlName,namespace,genClass,buildFields(genClass,namespace), genClass.equals(String.class),true,required,nillable)); - } else { - boolean isString = ft.equals(String.class) || ft.equals(XMLGregorianCalendar.class); - // add recursed member - fields.add(new JaxInfo(xmlName,namespace,ft,buildFields(ft,namespace),isString,false,required,nillable)); - } - } - cls = cls.getSuperclass(); - }; - if(fields!=null) { - JaxInfo[] rv = new JaxInfo[fields.size()]; - fields.toArray(rv); - return rv; - } else { - return null; - } - } - - - public StringBuilder dump(StringBuilder sb, int idx) { - for(int i=0;i - */ -public class JaxSet { - private static Map,JaxSet> jsets = new HashMap,JaxSet>(); - private Map> members; - - private JaxSet(Class cls) { - members = new TreeMap>(); - XmlType xmltype = cls.getAnnotation(XmlType.class); - Class paramType[] = new Class[] {String.class}; - for(String str : xmltype.propOrder()) { - try { - String setName = "set" + Character.toUpperCase(str.charAt(0)) + str.subSequence(1, str.length()); - Method meth = cls.getMethod(setName,paramType ); - if(meth!=null) { - members.put(str, new Setter(meth) { - public void set(T o, Object t) throws ParseException { - try { - this.meth.invoke(o, t); - } catch (Exception e) { - throw new ParseException(e); - } - } - }); - } - } catch (Exception e) { - // oops - } - } - } - - public static abstract class Setter { - protected final Method meth; - public Setter(Method meth) { - this.meth = meth; - } - public abstract void set(O o, Object obj) throws ParseException; - } - - public static JaxSet get(Class cls) { - synchronized(jsets) { - @SuppressWarnings("unchecked") - JaxSet js = (JaxSet)jsets.get(cls); - if(js == null) { - jsets.put(cls, js = new JaxSet(cls)); - } - return js; - } - } - - public Setter get(String key) { - return members.get(key); - } -} diff --git a/rosetta/src/main/java/com/att/rosetta/Ladder.java b/rosetta/src/main/java/com/att/rosetta/Ladder.java deleted file mode 100644 index 46377db..0000000 --- a/rosetta/src/main/java/com/att/rosetta/Ladder.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta; - - -/** - * A Ladder is a Stack like Storage Class, but where you can ascend and descend while - * the elements exists. - * - * Like an extension ladder, you can make taller as you go - * - * - */ -public class Ladder { - public static final int DEFAULT_INIT_SIZE=8; - private final int init_size; - private int rung; // as in ladder - private Object[] struts; - - public Ladder() { - rung=0; - init_size = DEFAULT_INIT_SIZE; - struts=new Object[init_size]; - } - - public Ladder(int initSize) { - rung=0; - init_size = initSize; - struts=new Object[init_size]; - } - - public void bottom() { - rung = 0; - } - - public void top() { - rung = struts.length-1; - while(rung>0 && struts[rung]==null)--rung; - } - - public int howHigh() { - return rung; - } - - public void jumpTo(int rung) { - if(rung>=struts.length) { - Object[] temp = new Object[init_size*((rung/init_size)+1)]; - System.arraycopy(struts, 0, temp, 0, struts.length); - struts = temp; - } - this.rung = rung; - } - - public int height() { - return struts.length; - } - - public void cutTo(int rungs) { - Object[] temp = new Object[rungs]; - System.arraycopy(struts, 0, temp, 0, Math.min(rungs, struts.length)); - struts = temp; - } - - public void ascend() { - ++rung; - if(rung>=struts.length) { - Object[] temp = new Object[struts.length+init_size]; - System.arraycopy(struts, 0, temp, 0, struts.length); - struts = temp; - } - } - - public void descend() { - --rung; - } - - @SuppressWarnings("unchecked") - public T peek() { - return (T)struts[rung]; - } - - public void push(T t) { - struts[rung]=t; - } - - @SuppressWarnings("unchecked") - public T pop() { - T t = (T)struts[rung]; - struts[rung]=null; - return t; - } - -} diff --git a/rosetta/src/main/java/com/att/rosetta/Marshal.java b/rosetta/src/main/java/com/att/rosetta/Marshal.java deleted file mode 100644 index 07480b3..0000000 --- a/rosetta/src/main/java/com/att/rosetta/Marshal.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta; - -import java.util.Iterator; - -import com.att.inno.env.Env; -import com.att.inno.env.TimeTaken; - -public abstract class Marshal implements Parse { - - /* (non-Javadoc) - * @see com.att.rosetta.Parse#newParsed() - */ - @Override - public Parsed newParsed() throws ParseException { - return new Parsed(new State()); - } - - @Override - public TimeTaken start(Env env) { - //TODO is a way to mark not-JSON? - return env.start("Rosetta Marshal", Env.JSON); - }; - - public static class State { - // Note: Need a STATEFUL stack... one that will remain stateful until marked as finished - // "finished" is know by Iterators with no more to do/null - // Thus the concept of "Ladder", which one ascends and decends - public Ladder> ladder = new Ladder>(); - public boolean smallest = true; - } - - public static final Iterator DONE_ITERATOR = new Iterator() { - @Override - public boolean hasNext() { - return false; - } - - @Override - public Void next() { - return null; - } - - @Override - public void remove() { - } - }; - - /** - * Typical definition of Done is when Iterator in Ladder is "DONE_ITERATOR" - * - * It is important, however, that the "Ladder Rung" is set to the right level. - * - * @param state - * @return - */ - public boolean amFinished(State state) { - return DONE_ITERATOR.equals(state.ladder.peek()); - } - -} diff --git a/rosetta/src/main/java/com/att/rosetta/Nulls.java b/rosetta/src/main/java/com/att/rosetta/Nulls.java deleted file mode 100644 index a261888..0000000 --- a/rosetta/src/main/java/com/att/rosetta/Nulls.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta; - -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; - -import com.att.inno.env.Env; -import com.att.inno.env.TimeTaken; - -public class Nulls { - public static final Parse IN = new Parse() { - - // @Override - public Parsed parse(Reader r, Parsed parsed)throws ParseException { - parsed.event = Parse.END_DOC; - return parsed; - } - - // @Override - public Parsed newParsed() { - Parsed parsed = new Parsed(); - parsed.event = Parse.END_DOC; - return parsed; - } - - // @Override - public TimeTaken start(Env env) { - return env.start("IN", Env.SUB); - } - - }; - - public static final Out OUT = new Out() { - - // @Override - public void extract(IN in, Writer writer, Parse parse, boolean ... options)throws IOException, ParseException { - } - @Override - public String logName() { - return "Rosetta NULL"; - } - - - }; -} diff --git a/rosetta/src/main/java/com/att/rosetta/Out.java b/rosetta/src/main/java/com/att/rosetta/Out.java deleted file mode 100644 index e870eb5..0000000 --- a/rosetta/src/main/java/com/att/rosetta/Out.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; - -public abstract class Out { - public abstract void extract(IN in, Writer writer, Parse parse, boolean ... options) throws IOException, ParseException; - - public void extract(IN in, OutputStream os, Parse parse, boolean ... options) throws IOException, ParseException { - Writer w = new OutputStreamWriter(os); - try { - extract(in, w, parse, options); - } finally { - w.flush(); - } - } - - public abstract String logName(); - -} diff --git a/rosetta/src/main/java/com/att/rosetta/OutJax.java b/rosetta/src/main/java/com/att/rosetta/OutJax.java deleted file mode 100644 index 7f0e1f4..0000000 --- a/rosetta/src/main/java/com/att/rosetta/OutJax.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta; - -import java.io.IOException; -import java.io.Writer; - -public class OutJax extends Out { - private JaxEval jaxEval; - - public OutJax(JaxEval je) { - this.jaxEval = je; - } - - @Override - public void extract(IN in, Writer writer, Parse parse, boolean... options) throws IOException, ParseException { - Parsed p = parse.newParsed(); - JaxEval je = this.jaxEval; - while((p = parse.parse(in,p.reuse())).valid()) { - if(je==null)throw new ParseException("Incomplete content"); - je = je.eval(p); - } - - } - - @Override - public String logName() { - return "Rosetta JAX"; - } - - - -} diff --git a/rosetta/src/main/java/com/att/rosetta/OutJson.java b/rosetta/src/main/java/com/att/rosetta/OutJson.java deleted file mode 100644 index 69994d4..0000000 --- a/rosetta/src/main/java/com/att/rosetta/OutJson.java +++ /dev/null @@ -1,233 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta; - -import java.io.IOException; -import java.io.Writer; -import java.util.Stack; - -import com.att.inno.env.util.IndentPrintWriter; - -public class OutJson extends Out { - - @Override - public void extract(IN in, Writer writer, Parse prs, boolean ... options) throws IOException, ParseException { - Parsed p = prs.newParsed(); - IndentPrintWriter ipw; - if(options.length>0 && options[0]) { // is Pretty - ipw = writer instanceof IndentPrintWriter?(IndentPrintWriter)writer:new IndentPrintWriter(writer); - writer = ipw; - } else { - ipw = null; - } - - // If it's a fragment, print first Object Name. If root Object, skip first name - Stack jsonLevel = new Stack(); - jsonLevel.push(new LevelStack(options.length>1 && options[1])); - boolean print = true, hadData=false; - char afterName=0, beforeName=0, maybe = 0, prev=0; - - int count = 0; - while((p = prs.parse(in,p.reuse())).valid()) { - ++count; - switch(p.event) { - case 1: - continue; - case 2: - if(count==2) { // it's empty, write open/close on it's own - writer.append('{'); - writer.append('}'); - } - writer.flush(); - return; - case '{': - afterName = '{'; - if(jsonLevel.peek().printObjectName) { - print = true; - } else { // don't print names on first - print=false; - } - maybe=jsonLevel.peek().listItem(); - jsonLevel.push(new LevelStack(true)); - break; - case '}': - if(p.hasData()) { // if we have data, we print that, so may need to prepend a comma. - maybe = jsonLevel.peek().listItem(); - } else { // No data means just print, - p.name = ""; // XML tags come through with names, but no data - } - print = true; - jsonLevel.pop(); - afterName = p.event; - break; - case '[': - afterName = p.event; - if((prev==',' && !hadData) || prev==']')maybe=','; - else maybe = jsonLevel.peek().listItem(); - - jsonLevel.push(new LevelStack(false)); - print=true; - break; - case ']': - afterName = p.event; - if(p.hasData()) { - if(prev==',' && !hadData)maybe=','; - else maybe = jsonLevel.peek().listItem(); - } else { - p.name = ""; // XML tags come through with names, but no data - } - jsonLevel.pop(); - - print = true; - break; - case 3: - case ',': - if(!p.hasData()) { - p.isString=false; - print=false; - } else { - maybe=jsonLevel.peek().listItem(); - print = true; - } - break; - default: - print = true; - } - - if(maybe!=0) { - if(ipw==null)writer.append(maybe); - else ipw.println(maybe); - maybe = 0; - } - - if(beforeName!=0) { - if(ipw==null)writer.append(beforeName); - else ipw.println(beforeName); - beforeName = 0; - } - if(print) { - if(p.hasName()) { - writer.append('"'); - if(p.event==3)writer.append("__"); - writer.append(p.name); - writer.append("\":"); - } - if(p.hasData()) { - if(p.isString) { - writer.append('"'); - escapedWrite(writer, p.sb); - writer.append('"'); - } else if(p.sb.length()>0) { - writer.append(p.sb); - } - } - } - if(afterName!=0) { - if(ipw==null)writer.append(afterName); - else { - switch(afterName) { - case '{': - ipw.println(afterName); - ipw.inc(); - break; - case '}': - ipw.dec(); - ipw.println(); - ipw.print(afterName); - break; - case ']': - if(prev=='}' || prev==',')ipw.println(); - ipw.dec(); - ipw.print(afterName); - break; - - case ',': - ipw.println(afterName); - break; - default: - ipw.print(afterName); - } - } - afterName = 0; - } - - if(ipw!=null) { - switch(p.event) { - case '[': - ipw.inc(); - ipw.println(); - break; - } - } - prev = p.event; - hadData = p.hasData(); - - } - writer.flush(); - } - - private void escapedWrite(Writer writer, StringBuilder sb) throws IOException { - char c; - for(int i=0;i void extract(IN in, Writer writer, Parse prs, boolean ... options) throws IOException, ParseException { - Parsed p = prs.newParsed(); - - while((p = prs.parse(in,p.reuse())).valid()) { - writer.append(p.toString()); - writer.append('\n'); - } - } - - @Override - public String logName() { - return "Rosetta RAW"; - } - - - -} diff --git a/rosetta/src/main/java/com/att/rosetta/OutXML.java b/rosetta/src/main/java/com/att/rosetta/OutXML.java deleted file mode 100644 index b062d3c..0000000 --- a/rosetta/src/main/java/com/att/rosetta/OutXML.java +++ /dev/null @@ -1,226 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta; - -import java.io.IOException; -import java.io.Writer; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Stack; - -import com.att.inno.env.util.IndentPrintWriter; -import com.att.inno.env.util.StringBuilderWriter; - -public class OutXML extends Out{ - private static final String XMLNS_XSI = "xmlns:xsi"; - public static final String XML_INFO = ""; - public static final String XML_SCHEMA_INSTANCE = "http://www.w3.org/2001/XMLSchema-instance"; - - private String root; - private List props; - - public OutXML(String root, String ... params) { - this.root = root; - props = new ArrayList(); - for(String p : params) { - String[] tv=p.split("="); - if(tv.length==2) - props.add(new Prop(tv[0],tv[1])); - } - } - - public OutXML(JaxInfo jaxInfo) { - this(jaxInfo.name,genNS(jaxInfo)); - } - - public OutXML(InXML inXML) { - this(inXML.jaxInfo.name,genNS(inXML.jaxInfo)); - } - - private static String[] genNS(JaxInfo jaxInfo) { - return new String[] {"xmlns=" + jaxInfo.ns}; - } - - - @Override - public void extract(IN in, Writer writer, Parse prs, boolean ... options) throws IOException, ParseException { - Parsed p = prs.newParsed(); - Stack stack = new Stack(); - // If it's an IndentPrintWriter, it is pretty printing. - boolean pretty = (options.length>0&&options[0]); - - IndentPrintWriter ipw; - if(pretty) { - if(writer instanceof IndentPrintWriter) { - ipw = (IndentPrintWriter)writer; - } else { - writer = ipw = new IndentPrintWriter(writer); - } - } else { - ipw=null; - } - boolean closeTag = false; - Level level = new Level(null); - while((p = prs.parse(in,p.reuse())).valid()) { - if(!p.hasName() && level.multi!=null) { - p.name=level.multi; - } - if(closeTag && p.event!=Parse.ATTRIB) { - writer.append('>'); - if(pretty)writer.append('\n'); - closeTag = false; - } - switch(p.event) { - case Parse.START_DOC: - if(!(options.length>1&&options[1])) // if not a fragment, print XML Info data - if(pretty)ipw.println(XML_INFO); - else writer.append(XML_INFO); - break; - case Parse.END_DOC: - break; - case Parse.START_OBJ: - stack.push(level); - level = new Level(level); - if(p.hasName()) { - closeTag = tag(writer,level.sbw,pretty,pretty,p.name,null); - } else if(root!=null && stack.size()==1) { // first Object - closeTag = tag(writer,level.sbw,pretty,pretty,root,null); - // Write Root Props - for(Prop prop : props) { - attrib(writer,pretty,prop.tag, prop.value,level); - } - } - if(pretty)ipw.inc(); - break; - case Parse.END_OBJ: - if(p.hasData()) - closeTag = tag(writer,writer,pretty,false,p.name, XmlEscape.convert(p.sb)); - if(pretty)ipw.dec(); - writer.append(level.sbw.getBuffer()); - level = stack.pop(); - break; - case Parse.START_ARRAY: - level.multi = p.name; - break; - case Parse.END_ARRAY: - if(p.hasData()) - closeTag = tag(writer,writer,pretty,false, p.name, XmlEscape.convert(p.sb)); - level.multi=null; - break; - case Parse.ATTRIB: - if(p.hasData()) - attrib(writer,pretty,p.name, XmlEscape.convert(p.sb), level); - break; - case Parse.NEXT: - if(p.hasData()) - closeTag = tag(writer,writer,pretty, false,p.name, XmlEscape.convert(p.sb)); - break; - } - } - writer.append(level.sbw.getBuffer()); - writer.flush(); - } - - private class Level { - public final StringBuilderWriter sbw; - public String multi; - private Level prev; - private Map nses; - - public Level(Level level) { - sbw = new StringBuilderWriter(); - multi = null; - prev = level; - } - - public boolean hasPrinted(String ns, String value, boolean create) { - boolean rv = false; - if(nses==null) { - if(prev!=null)rv = prev.hasPrinted(ns, value, false); - } else { - String v = nses.get(ns); - return value.equals(v); // note: accomodates not finding NS as well - } - - if(create && !rv) { - if(nses == null) nses = new HashMap(); - nses.put(ns, value); - } - return rv; - } - - - - } - - private boolean tag(Writer fore, Writer aft, boolean pretty, boolean returns, String tag, String data) throws IOException { - fore.append('<'); - fore.append(tag); - if(data!=null) { - fore.append('>'); // if no data, it may need some attributes... - fore.append(data); - if(returns)fore.append('\n'); - } - aft.append(""); - if(pretty)aft.append('\n'); - return data==null; - } - - private void attrib(Writer fore, boolean pretty, String tag, String value, Level level) throws IOException { - String realTag = tag.startsWith("__")?tag.substring(2):tag; // remove __ - if(realTag.equals(Parsed.EXTENSION_TAG)) { // Convert Derived name into XML defined Inheritance - fore.append(" xsi:type=\""); - fore.append(value); - fore.append('"'); - if(!level.hasPrinted(XMLNS_XSI, XML_SCHEMA_INSTANCE,true)) { - fore.append(' '); - fore.append(XMLNS_XSI); - fore.append("=\""); - fore.append(XML_SCHEMA_INSTANCE); - fore.append("\""); - } - } else { - if(realTag.startsWith("xmlns:") ) { - if(level.hasPrinted(realTag, value, true)) { - return; - } - } - fore.append(' '); - fore.append(realTag); - fore.append("=\""); - fore.append(value); - fore.append('"'); - } - } - - @Override - public String logName() { - return "Rosetta XML"; - } - - -} diff --git a/rosetta/src/main/java/com/att/rosetta/Parse.java b/rosetta/src/main/java/com/att/rosetta/Parse.java deleted file mode 100644 index e66f798..0000000 --- a/rosetta/src/main/java/com/att/rosetta/Parse.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta; - -import com.att.inno.env.Env; -import com.att.inno.env.TimeTaken; - -public interface Parse { - public Parsed parse(IN in, Parsed parsed) throws ParseException; - - // EVENTS - public static final char NONE = 0; - public static final char START_DOC = 1; - public static final char END_DOC = 2; - public static final char ATTRIB = 3; - - public static final char NEXT = ','; - public static final char START_OBJ = '{'; - public static final char END_OBJ = '}'; - public static final char START_ARRAY = '['; - public static final char END_ARRAY = ']'; - - public Parsed newParsed() throws ParseException; - public TimeTaken start(Env env); - -} diff --git a/rosetta/src/main/java/com/att/rosetta/ParseException.java b/rosetta/src/main/java/com/att/rosetta/ParseException.java deleted file mode 100644 index ac51dbd..0000000 --- a/rosetta/src/main/java/com/att/rosetta/ParseException.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta; - -public class ParseException extends Exception { - private static final long serialVersionUID = 7808836939102997012L; - - public ParseException() { - } - - public ParseException(String message) { - super(message); - } - - public ParseException(Throwable cause) { - super(cause); - } - - public ParseException(String message, Throwable cause) { - super(message, cause); - } - -} diff --git a/rosetta/src/main/java/com/att/rosetta/Parsed.java b/rosetta/src/main/java/com/att/rosetta/Parsed.java deleted file mode 100644 index 705dd8e..0000000 --- a/rosetta/src/main/java/com/att/rosetta/Parsed.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta; - - -public class Parsed { - public static final String EXTENSION_TAG="extension"; - - public boolean isString; - - public StringBuilder sb; - public char event; - public String name; - public S state; - - public Parsed() { - this(null); - } - - // Package on purpose - Parsed(S theState) { - sb = new StringBuilder(); - isString = false; - event = Parse.NONE; - name = ""; - state = theState; - } - - public boolean valid() { - return event!=Parse.NONE; - } - - public Parsed reuse() { - isString=false; - sb.setLength(0); - event = Parse.NONE; - name = ""; - // don't touch T... - return this; - } - - public void dataIsName() { - name = sb.toString(); - sb.setLength(0); - } - - public boolean hasName() { - return name.length()>0; - } - - public boolean hasData() { - return sb.length()>0; - } - - public String toString() { - StringBuilder sb2 = new StringBuilder(); - if(event<40)sb2.append((int)event); - else sb2.append(event); - sb2.append(" - "); - sb2.append(name); - if(sb.length()>0) { - sb2.append(" : "); - if(isString)sb2.append('"'); - sb2.append(sb); - if(isString)sb2.append('"'); - } - return sb2.toString(); - } - -} diff --git a/rosetta/src/main/java/com/att/rosetta/Prop.java b/rosetta/src/main/java/com/att/rosetta/Prop.java deleted file mode 100644 index aa728fe..0000000 --- a/rosetta/src/main/java/com/att/rosetta/Prop.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta; - -class Prop { - public String tag; - public String value; - public Prop(String t, String v) { - tag = t; - value =v; - } - - public Prop(String t_equals_v) { - String[] tv = t_equals_v.split("="); - if(tv.length>1) { - tag = tv[0]; - value = tv[1]; - } - } - - public String toString() { - return tag + '=' + value; - } -} diff --git a/rosetta/src/main/java/com/att/rosetta/Saved.java b/rosetta/src/main/java/com/att/rosetta/Saved.java deleted file mode 100644 index 7e27a58..0000000 --- a/rosetta/src/main/java/com/att/rosetta/Saved.java +++ /dev/null @@ -1,194 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta; - -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; -import java.util.List; - -import com.att.inno.env.Env; -import com.att.inno.env.TimeTaken; -import com.att.rosetta.Saved.State; - -/** - * An Out Object that will save off produced Parsed Stream and - * a Parse (In) Object that will reproduce Parsed Stream on demand - * - * - */ -public class Saved extends Out implements Parse{ - private static final String ROSETTA_SAVED = "Rosetta Saved"; - private final static int INIT_SIZE=128; - private Content content[]; - private int idx; - private boolean append = false; - - /** - * Read from Parsed Stream and save - */ - // @Override - public void extract(IN in, Writer ignore, Parse parser, boolean ... options) throws IOException, ParseException { - Parsed p = parser.newParsed(); - if(!append) { - // reuse array if not too big - if(content==null||content.length>INIT_SIZE*3) { - content = new Content[INIT_SIZE]; - idx = -1; - } else do { - content[idx]=null; - } while(--idx>=0); - } - - // Note: idx needs to be -1 on initialization and no appendages - while((p = parser.parse(in,p.reuse())).valid()) { - if(!(append && (p.event==START_DOC || p.event==END_DOC))) { // skip any start/end of document in appendages - if(++idx>=content.length) { - Content temp[] = new Content[content.length*2]; - System.arraycopy(content, 0, temp, 0, idx); - content = temp; - } - content[idx]= new Content(p); - } - } - } - - // @Override - public Parsed parse(Reader ignore, Parsed parsed) throws ParseException { - int i; - if((i=parsed.state.count++)<=idx) - content[i].load(parsed); - else - parsed.event = Parse.NONE; - return parsed; - } - - public Content[] cut(char event, int count) { - append = true; - for(int i=idx;i>=0;--i) { - if(content[i].event==event) count--; - if(count==0) { - Content[] appended = new Content[idx-i+1]; - System.arraycopy(content, i, appended, 0, appended.length); - idx = i-1; - return appended; - } - } - return new Content[0]; - } - - public void paste(Content[] appended) { - if(appended!=null) { - if(idx+appended.length>content.length) { - Content temp[] = new Content[content.length*2]; - System.arraycopy(content, 0, temp, 0, idx); - content = temp; - } - System.arraycopy(appended,0,content,idx+1,appended.length); - idx+=appended.length; - } - this.append = false; - } - - public static class State { - public int count = 0; - } - - public static class Content { - private boolean isString; - private char event; - private String name; - private List props; - private String str; - - public Content(Parsed p) { - isString = p.isString; - event = p.event; - name = p.name; - // avoid copying, because most elements don't have content - // Cannot set to "equals", because sb ends up being cleared (and reused) - str = p.sb.length()==0?null:p.sb.toString(); - } - - public void load(Parsed p) { - p.isString = isString; - p.event = event; - p.name = name; - if(str!=null) - p.sb.append(str); - } - - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(event); - sb.append(" - "); - sb.append(name); - sb.append(": "); - if(isString)sb.append('"'); - sb.append(str); - if(isString)sb.append('"'); - sb.append(' '); - if(props!=null) { - boolean comma = false; - for(Prop prop : props) { - if(comma)sb.append(','); - else comma = true; - sb.append(prop.tag); - sb.append('='); - sb.append(prop.value); - } - } - return sb.toString(); - } - } - - //// @Override - public Parsed newParsed() { - Parsed ps = new Parsed(new State()); - return ps; - } - - /** - * Convenience function - * @param rdr - * @param in - * @throws IOException - * @throws ParseException - */ - public void load(IN in, Parse parser) throws IOException, ParseException { - extract(in,(Writer)null, parser); - } - - - // @Override - public TimeTaken start(Env env) { - return env.start(ROSETTA_SAVED, 0); - } - - @Override - public String logName() { - return ROSETTA_SAVED; - } - - -} diff --git a/rosetta/src/main/java/com/att/rosetta/XmlEscape.java b/rosetta/src/main/java/com/att/rosetta/XmlEscape.java deleted file mode 100644 index a98cf56..0000000 --- a/rosetta/src/main/java/com/att/rosetta/XmlEscape.java +++ /dev/null @@ -1,372 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta; - -import java.io.IOException; -import java.io.Reader; -import java.util.Map.Entry; -import java.util.TreeMap; - -public class XmlEscape { - private XmlEscape() {} - - private static final TreeMap charMap; // see initialization at end - private static final TreeMap intMap; // see initialization at end - - public static void xmlEscape(StringBuilder sb, Reader r) throws ParseException { - try { - int c; - StringBuilder esc = new StringBuilder(); - for(int cnt = 0;cnt<9 /*max*/; ++cnt) { - if((c=r.read())<0)throw new ParseException("Invalid Data: Unfinished Escape Sequence"); - if(c!=';') { - esc.append((char)c); - } else { // evaluate - Integer i = charMap.get(esc.toString()); - if(i==null) { - // leave in nasty XML format for now. - sb.append('&'); - sb.append(esc); - sb.append(';'); - } else { - sb.append((char)i.intValue()); - } - break; - } - } - - - } catch (IOException e) { - throw new ParseException(e); - } - } - - public static void xmlEscape(StringBuilder sb, int chr) { - sb.append('&'); - sb.append(intMap.get(chr)); - sb.append(';'); - } - - public static String convert(StringBuilder insb) { - int idx, ch; - StringBuilder sb=null; - for(idx=0;idx=160 || ch==34 || ch==38 || ch==39 || ch==60 || ch==62) { - sb = new StringBuilder(); - sb.append(insb,0,idx); - break; - } - } - - if(sb==null)return insb.toString(); - - for(int i=idx;i(); - intMap = new TreeMap(); - charMap.put("quot", 34); - charMap.put("amp",38); - charMap.put("apos",39); - charMap.put("lt",60); - charMap.put("gt",62); - charMap.put("nbsp",160); - charMap.put("iexcl",161); - charMap.put("cent",162); - charMap.put("pound",163); - charMap.put("curren",164); - charMap.put("yen",165); - charMap.put("brvbar",166); - charMap.put("sect",167); - charMap.put("uml",168); - charMap.put("copy",169); - charMap.put("ordf",170); - charMap.put("laquo",171); - charMap.put("not",172); - charMap.put("shy",173); - charMap.put("reg",174); - charMap.put("macr",175); - charMap.put("deg",176); - charMap.put("plusmn",177); - charMap.put("sup2",178); - charMap.put("sup3",179); - charMap.put("acute",180); - charMap.put("micro",181); - charMap.put("para",182); - charMap.put("middot",183); - charMap.put("cedil",184); - charMap.put("sup1",185); - charMap.put("ordm",186); - charMap.put("raquo",187); - charMap.put("frac14",188); - charMap.put("frac12",189); - charMap.put("frac34",190); - charMap.put("iquest",191); - charMap.put("Agrave",192); - charMap.put("Aacute",193); - charMap.put("Acirc",194); - charMap.put("Atilde",195); - charMap.put("Auml",196); - charMap.put("Aring",197); - charMap.put("AElig",198); - charMap.put("Ccedil",199); - charMap.put("Egrave",200); - charMap.put("Eacute",201); - charMap.put("Ecirc",202); - charMap.put("Euml",203); - charMap.put("Igrave",204); - charMap.put("Iacute",205); - charMap.put("Icirc",206); - charMap.put("Iuml",207); - charMap.put("ETH",208); - charMap.put("Ntilde",209); - charMap.put("Ograve",210); - charMap.put("Oacute",211); - charMap.put("Ocirc",212); - charMap.put("Otilde",213); - charMap.put("Ouml",214); - charMap.put("times",215); - charMap.put("Oslash",216); - charMap.put("Ugrave",217); - charMap.put("Uacute",218); - charMap.put("Ucirc",219); - charMap.put("Uuml",220); - charMap.put("Yacute",221); - charMap.put("THORN",222); - charMap.put("szlig",223); - charMap.put("agrave",224); - charMap.put("aacute",225); - charMap.put("acirc",226); - charMap.put("atilde",227); - charMap.put("auml",228); - charMap.put("aring",229); - charMap.put("aelig",230); - charMap.put("ccedil",231); - charMap.put("egrave",232); - charMap.put("eacute",233); - charMap.put("ecirc",234); - charMap.put("euml",235); - charMap.put("igrave",236); - charMap.put("iacute",237); - charMap.put("icirc",238); - charMap.put("iuml",239); - charMap.put("eth",240); - charMap.put("ntilde",241); - charMap.put("ograve",242); - charMap.put("oacute",243); - charMap.put("ocirc",244); - charMap.put("otilde",245); - charMap.put("ouml",246); - charMap.put("divide",247); - charMap.put("oslash",248); - charMap.put("ugrave",249); - charMap.put("uacute",250); - charMap.put("ucirc",251); - charMap.put("uuml",252); - charMap.put("yacute",253); - charMap.put("thorn",254); - charMap.put("yuml",255); - charMap.put("OElig",338); - charMap.put("oelig",339); - charMap.put("Scaron",352); - charMap.put("scaron",353); - charMap.put("Yuml",376); - charMap.put("fnof",402); - charMap.put("circ",710); - charMap.put("tilde",732); - charMap.put("Alpha",913); - charMap.put("Beta",914); - charMap.put("Gamma",915); - charMap.put("Delta",916); - charMap.put("Epsilon",917); - charMap.put("Zeta",918); - charMap.put("Eta",919); - charMap.put("Theta",920); - charMap.put("Iota",921); - charMap.put("Kappa",922); - charMap.put("Lambda",923); - charMap.put("Mu",924); - charMap.put("Nu",925); - charMap.put("Xi",926); - charMap.put("Omicron",927); - charMap.put("Pi",928); - charMap.put("Rho",929); - charMap.put("Sigma",931); - charMap.put("Tau",932); - charMap.put("Upsilon",933); - charMap.put("Phi",934); - charMap.put("Chi",935); - charMap.put("Psi",936); - charMap.put("Omega",937); - charMap.put("alpha",945); - charMap.put("beta",946); - charMap.put("gamma",947); - charMap.put("delta",948); - charMap.put("epsilon",949); - charMap.put("zeta",950); - charMap.put("eta",951); - charMap.put("theta",952); - charMap.put("iota",953); - charMap.put("kappa",954); - charMap.put("lambda",955); - charMap.put("mu",956); - charMap.put("nu",957); - charMap.put("xi",958); - charMap.put("omicron",959); - charMap.put("pi",960); - charMap.put("rho",961); - charMap.put("sigmaf",962); - charMap.put("sigma",963); - charMap.put("tau",964); - charMap.put("upsilon",965); - charMap.put("phi",966); - charMap.put("chi",967); - charMap.put("psi",968); - charMap.put("omega",969); - charMap.put("thetasym",977); - charMap.put("upsih",978); - charMap.put("piv",982); - charMap.put("ensp",8194); - charMap.put("emsp",8195); - charMap.put("thinsp",8201); - charMap.put("zwnj",8204); - charMap.put("zwj",8205); - charMap.put("lrm",8206); - charMap.put("rlm",8207); - charMap.put("ndash",8211); - charMap.put("mdash",8212); - charMap.put("lsquo",8216); - charMap.put("rsquo",8217); - charMap.put("sbquo",8218); - charMap.put("ldquo",8220); - charMap.put("rdquo",8221); - charMap.put("bdquo",8222); - charMap.put("dagger",8224); - charMap.put("Dagger",8225); - charMap.put("bull",8226); - charMap.put("hellip",8230); - charMap.put("permil",8240); - charMap.put("prime",8242); - charMap.put("Prime",8243); - charMap.put("lsaquo",8249); - charMap.put("rsaquo",8250); - charMap.put("oline",8254); - charMap.put("frasl",8260); - charMap.put("euro",8364); - charMap.put("image",8465); - charMap.put("weierp",8472); - charMap.put("real",8476); - charMap.put("trade",8482); - charMap.put("alefsym",8501); - charMap.put("larr",8592); - charMap.put("uarr",8593); - charMap.put("rarr",8594); - charMap.put("darr",8595); - charMap.put("harr",8596); - charMap.put("crarr",8629); - charMap.put("lArr",8656); - charMap.put("uArr",8657); - charMap.put("rArr",8658); - charMap.put("dArr",8659); - charMap.put("hArr",8660); - charMap.put("forall",8704); - charMap.put("part",8706); - charMap.put("exist",8707); - charMap.put("empty",8709); - charMap.put("nabla",8711); - charMap.put("isin",8712); - charMap.put("notin",8713); - charMap.put("ni",8715); - charMap.put("prod",8719); - charMap.put("sum",8721); - charMap.put("minus",8722); - charMap.put("lowast",8727); - charMap.put("radic",8730); - charMap.put("prop",8733); - charMap.put("infin",8734); - charMap.put("ang",8736); - charMap.put("and",8743); - charMap.put("or",8744); - charMap.put("cap",8745); - charMap.put("cup",8746); - charMap.put("int",8747); - charMap.put("there4",8756); - charMap.put("sim",8764); - charMap.put("cong",8773); - charMap.put("asymp",8776); - charMap.put("ne",8800); - charMap.put("equiv",8801); - charMap.put("le",8804); - charMap.put("ge",8805); - charMap.put("sub",8834); - charMap.put("sup",8835); - charMap.put("nsub",8836); - charMap.put("sube",8838); - charMap.put("supe",8839); - charMap.put("oplus",8853); - charMap.put("otimes",8855); - charMap.put("perp",8869); - charMap.put("sdot",8901); - charMap.put("lceil",8968); - charMap.put("rceil",8969); - charMap.put("lfloor",8970); - charMap.put("rfloor",8971); - charMap.put("lang",9001); - charMap.put("rang",9002); - charMap.put("loz",9674); - charMap.put("spades",9824); - charMap.put("clubs",9827); - charMap.put("hearts",9829); - charMap.put("diams",9830); - - for( Entry es: charMap.entrySet()) { - if(es.getValue()>=160); // save small space... note that no longer has amp, etc. - intMap.put(es.getValue(), es.getKey()); - } - } - -} diff --git a/rosetta/src/main/java/com/att/rosetta/env/RosettaDF.java b/rosetta/src/main/java/com/att/rosetta/env/RosettaDF.java deleted file mode 100644 index 6dac5fd..0000000 --- a/rosetta/src/main/java/com/att/rosetta/env/RosettaDF.java +++ /dev/null @@ -1,266 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta.env; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; - -import javax.xml.bind.JAXBException; -import javax.xml.namespace.QName; -import javax.xml.validation.Schema; - -import com.att.inno.env.APIException; -import com.att.inno.env.BaseDataFactory; -import com.att.inno.env.Data; -import com.att.inno.env.Data.TYPE; -import com.att.inno.env.DataFactory; -import com.att.inno.env.Env; -import com.att.inno.env.TimeTaken; -import com.att.inno.env.Trans; -import com.att.inno.env.jaxb.JAXBmar; -import com.att.inno.env.jaxb.JAXBumar; -import com.att.rosetta.InJson; -import com.att.rosetta.InXML; -import com.att.rosetta.JaxInfo; -import com.att.rosetta.Marshal; -import com.att.rosetta.Out; -import com.att.rosetta.OutJson; -import com.att.rosetta.OutRaw; -import com.att.rosetta.OutXML; -import com.att.rosetta.Parse; -import com.att.rosetta.ParseException; -import com.att.rosetta.marshal.DocMarshal; - -public class RosettaDF extends BaseDataFactory implements DataFactory { - - static InJson inJSON = new InJson(); - InXML inXML; - - static OutJson outJSON = new OutJson(); - OutXML outXML; - static OutRaw outRAW = new OutRaw(); - - // Temporary until we write JAXB impl... - JAXBmar jaxMar; - JAXBumar jaxUmar; - - private Parse defaultIn; - private Out defaultOut; - private RosettaEnv env; - private TYPE inType; - private TYPE outType; - private int defOption; - Marshal marshal = null; - - - /** - * Private constructor to setup Type specific data manipulators - * @param schema - * @param rootNs - * @param cls - * @throws SecurityException - * @throws NoSuchFieldException - * @throws ClassNotFoundException - * @throws ParseException - * @throws JAXBException - */ - // package on purpose - RosettaDF(RosettaEnv env, Schema schema, String rootNs, Class cls) throws APIException { - this.env = env; - try { - // Note: rootNs can be null, in order to derive content from Class. - JaxInfo ji = rootNs==null?JaxInfo.build(cls):JaxInfo.build(cls,rootNs); - // Note: JAXBmar sets qname to null if not exists - jaxMar = new JAXBmar(rootNs==null?null:new QName("xmlns",rootNs),cls); - // Note: JAXBumar sets schema to null if not exists - jaxUmar = new JAXBumar(schema, cls); - - defaultIn = inXML = new InXML(ji); - defaultOut = outXML = new OutXML(ji); - inType=outType=Data.TYPE.XML; - defOption = 0; - } catch (Exception e) { - throw new APIException(e); - } - } - - - // @Override - public RosettaData newData() { - RosettaData data = new RosettaData(env, this) - .in(inType) - .out(outType) - .option(defOption); - return data; - } - - // @Override - public RosettaData newData(Env trans) { - RosettaData data = new RosettaData(trans, this) - .in(inType) - .out(outType) - .option(defOption); - return data; - } - - @SuppressWarnings("unchecked") - // @Override - public Class getTypeClass() { - return (Class)jaxMar.getMarshalClass(); - } - - public RosettaDF in(Data.TYPE type) { - inType = type; - defaultIn=getIn(type==Data.TYPE.DEFAULT?Data.TYPE.JSON:type); - return this; - } - - /** - * If exists, first option is "Pretty", second is "Fragment" - * - * @param options - * @return - */ - public RosettaDF out(Data.TYPE type) { - outType = type; - defaultOut = getOut(type==Data.TYPE.DEFAULT?Data.TYPE.JSON:type); - return this; - } - - public Parse getIn(Data.TYPE type) { - switch(type) { - case DEFAULT: - return defaultIn; - case JSON: - return inJSON; - case XML: - return inXML; - default: - return defaultIn; - } - } - - public Out getOut(Data.TYPE type) { - switch(type) { - case DEFAULT: - return defaultOut; - case JSON: - return outJSON; - case XML: - return outXML; - case RAW: - return outRAW; - default: - return defaultOut; - } - } - - public int logType(com.att.inno.env.Data.TYPE ot) { - switch(ot) { - case JSON: - return Env.JSON; - default: - return Env.XML; - } - } - - - public RosettaEnv getEnv() { - return env; - } - - - public Data.TYPE getInType() { - return inType; - } - - public Data.TYPE getOutType() { - return outType; - } - - public RosettaDF option(int option) { - defOption = option; - - return this; - } - - /** - * Assigning Root Marshal Object - * - * Will wrap with DocMarshal Object if not already - * - * @param marshal - * @return - */ - public RosettaDF rootMarshal(Marshal marshal) { - if(marshal instanceof DocMarshal) { - this.marshal = marshal; - } else { - this.marshal = DocMarshal.root(marshal); - } - return this; - } - - public void direct(Trans trans, T t, OutputStream os, boolean ... options) throws APIException, IOException { - Out out = getOut(outType); - TimeTaken tt = trans.start(out.logName(),logType(outType)); // determine from Out.. without dependency on Env? - try { - if(marshal==null) { // Unknown marshaller... do working XML marshal/extraction - StringWriter sw = new StringWriter(); - jaxMar.marshal(trans.debug(), t, sw, options); - out.extract(new StringReader(sw.toString()), new OutputStreamWriter(os), inXML,options); - } else { - out.extract(t, new OutputStreamWriter(os), marshal,options); - } - } catch (Exception e) { - throw new APIException(e); - } finally { - tt.done(); - } - } - - public void direct(Trans trans, T t, Writer writer, boolean ... options) throws APIException, IOException { - Out out = getOut(outType); - TimeTaken tt = trans.start(out.logName(),logType(outType)); // determine from Out.. without dependency on Env? - try { - if(marshal==null) { // Unknown marshaller... do working XML marshal/extraction - StringWriter sw = new StringWriter(); - jaxMar.marshal(trans.debug(), t, sw, options); - out.extract(new StringReader(sw.toString()), writer, inXML,options); - } else { - out.extract(t, writer, marshal,options); - } - } catch (Exception e) { - throw new APIException(e); - } finally { - tt.done(); - } - } - - -} diff --git a/rosetta/src/main/java/com/att/rosetta/env/RosettaData.java b/rosetta/src/main/java/com/att/rosetta/env/RosettaData.java deleted file mode 100644 index 9b2b508..0000000 --- a/rosetta/src/main/java/com/att/rosetta/env/RosettaData.java +++ /dev/null @@ -1,313 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta.env; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; - -import com.att.inno.env.APIException; -import com.att.inno.env.Data; -import com.att.inno.env.Env; -import com.att.inno.env.TimeTaken; -import com.att.rosetta.Out; -import com.att.rosetta.Parse; -import com.att.rosetta.Saved; - -public class RosettaData implements Data{ - private Env trans; - private RosettaDF df; - private Saved saved; - private TYPE inType, outType; - // Note: This is an array of boolean in order to pass into other methods - private boolean options[] = new boolean[] {false, false}; - // Temp Storage of XML. Only when we must use JAXB to read in Objects - private String xml,json; - - // package on purpose - RosettaData(Env env, RosettaDF rosettaDF) { - df = rosettaDF; - saved = new Saved(); // Note: Saved constructs storage as needed... - trans = env; - inType = df.getInType(); - outType = df.getOutType(); // take defaults - } - -// // @Override - public RosettaData in(TYPE rosettaType) { - inType = rosettaType; - return this; - } - -// // @Override - public RosettaData out(TYPE rosettaType) { - outType = rosettaType; - return this; - } - -// // @Override - public RosettaData load(Reader rdr) throws APIException { - Parse in = df.getIn(inType); - TimeTaken tt = in.start(trans); - try { - saved.extract(rdr, (Writer)null, in); - xml=json=null; - } catch (Exception e) { - throw new APIException(e); - } finally { - tt.done(); - } - return this; - } - - // @Override - public RosettaData load(InputStream is) throws APIException { - Parse in = df.getIn(inType); - TimeTaken tt = in.start(trans); - try { - saved.extract(new InputStreamReader(is), (Writer)null, in); - xml=json=null; - } catch (Exception e) { - throw new APIException(e); - } finally { - tt.done(); - } - return this; - } - - // @Override - public RosettaData load(String str) throws APIException { - Parse in = df.getIn(inType); - TimeTaken tt = in.start(trans); - try { - saved.extract(new StringReader(str), (Writer)null, in); - switch(inType) { - case XML: - xml = str; - break; - case JSON: - json = str; - break; - default: - - } - } catch (Exception e) { - throw new APIException(e); - } finally { - tt.done(); - } - return this; - } - - // @Override - public RosettaData load(T t) throws APIException { - Parse in = df.getIn(inType); - TimeTaken tt = in.start(trans); - try { - if(df.marshal==null) { // Unknown marshaller... do working XML marshal/extraction - StringWriter sw = new StringWriter(); - df.jaxMar.marshal(trans.debug(), t, sw, options); - saved.extract(new StringReader(xml = sw.toString()), (Writer)null, df.inXML); - } else { - saved.extract(t, (Writer)null, df.marshal); - } - } catch (Exception e) { - throw new APIException(e); - } finally { - tt.done(); - } - return this; - } - - public Saved getEvents() { - return saved; - } - - // @Override - public T asObject() throws APIException { - Out out = df.getOut(TYPE.XML); - TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? - try { - //TODO Replace JAXB with Direct Object method!!! - StringWriter sw = new StringWriter(); - out.extract(null, sw, saved); - return df.jaxUmar.unmarshal(trans.debug(), sw.toString()); - } catch (Exception e) { - throw new APIException(e); - } finally { - tt.done(); - } - } - - // @Override - public String asString() throws APIException { - Out out = df.getOut(outType); - TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? - try { - if(outType==TYPE.XML) { - if(xml==null) { - StringWriter sw = new StringWriter(); - out.extract(null, sw, saved, options); - xml = sw.toString(); - } - return xml; - } else { // is JSON - if(json==null) { - StringWriter sw = new StringWriter(); - out.extract(null, sw, saved, options); - json = sw.toString(); - } - return json; - } - } catch (Exception e) { - throw new APIException(e); - } finally { - tt.done(); - } - } - - - // @Override - public RosettaData to(OutputStream os) throws APIException, IOException { - Out out = df.getOut(outType); - TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? - try { - if(outType==TYPE.XML && xml!=null) { - os.write(xml.getBytes()); - } else if(outType==TYPE.JSON && json!=null) { - os.write(json.getBytes()); - } else { - out.extract(null, os, saved, options); - } - } catch (Exception e) { - throw new APIException(e); - } finally { - tt.done(); - } - return this; - } - - // @Override - public RosettaData to(Writer writer) throws APIException, IOException { - Out out = df.getOut(outType); - TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? - try { - if(outType==TYPE.XML && xml!=null) { - writer.append(xml); - } else if(outType==TYPE.JSON && json!=null) { - writer.append(json); - } else { - out.extract(null, writer, saved, options); - } - } catch (Exception e) { - throw new APIException(e); - } finally { - tt.done(); - } - return this; - } - - // @Override - public Class getTypeClass() { - return df.getTypeClass(); - } - - private static final boolean[] emptyOption = new boolean[0]; - - public void direct(InputStream is, OutputStream os) throws APIException, IOException { - direct(is,os,emptyOption); - } - - public void direct(Reader reader, Writer writer, boolean ... options) throws APIException, IOException { - Parse in = df.getIn(inType); - Out out = df.getOut(outType); - TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? - try { - out.extract(reader, writer, in,options); - } catch (Exception e) { - throw new APIException(e); - } finally { - tt.done(); - } - } - - public void direct(T t, Writer writer, boolean ... options) throws APIException, IOException { - Out out = df.getOut(outType); - TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? - try { - if(df.marshal==null) { // Unknown marshaller... do working XML marshal/extraction - StringWriter sw = new StringWriter(); - df.jaxMar.marshal(trans.debug(), t, sw, options); - out.extract(new StringReader(xml = sw.toString()), writer, df.inXML,options); - } else { - out.extract(t, writer, df.marshal,options); - } - } catch (Exception e) { - throw new APIException(e); - } finally { - tt.done(); - } - } - - public void direct(T t, OutputStream os, boolean ... options) throws APIException, IOException { - Out out = df.getOut(outType); - TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? - try { - if(df.marshal==null) { // Unknown marshaller... do working XML marshal/extraction - if(outType.equals(TYPE.XML)) { - df.jaxMar.marshal(trans.debug(), t, os, options); - } else { - StringWriter sw = new StringWriter(); - df.jaxMar.marshal(trans.debug(), t, sw, options); - out.extract(new StringReader(xml = sw.toString()), new OutputStreamWriter(os), df.inXML,options); - } - } else { - out.extract(t, new OutputStreamWriter(os), df.marshal,options); - } - - } catch (Exception e) { - throw new APIException(e); - } finally { - tt.done(); - } - } - - - public void direct(InputStream is, OutputStream os, boolean ... options) throws APIException, IOException { - direct(new InputStreamReader(is),new OutputStreamWriter(os), options); - } - - // // @Override - public RosettaData option(int option) { - options[0] = (option&Data.PRETTY)==Data.PRETTY; - options[1] = (option&Data.FRAGMENT)==Data.FRAGMENT; - return this; - } - -} diff --git a/rosetta/src/main/java/com/att/rosetta/env/RosettaEnv.java b/rosetta/src/main/java/com/att/rosetta/env/RosettaEnv.java deleted file mode 100644 index 42877af..0000000 --- a/rosetta/src/main/java/com/att/rosetta/env/RosettaEnv.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta.env; - -import java.applet.Applet; -import java.util.Properties; - -import javax.xml.namespace.QName; -import javax.xml.validation.Schema; - -import com.att.inno.env.APIException; - -/** - * An essential Implementation of Env, which will fully function, without any sort - * of configuration. - * - * Use as a basis for Group level Env, just overriding where needed. - * - */ -public class RosettaEnv extends com.att.inno.env.impl.BasicEnv { - - public RosettaEnv() { - super(); - } - - public RosettaEnv(Applet applet, String... tags) { - super(applet, tags); - } - - public RosettaEnv(String[] args) { - super(args); - } - - public RosettaEnv(String tag, String[] args) { - super(tag, args); - } - - public RosettaEnv(String tag, Properties props) { - super(tag, props); - } - - public RosettaEnv(Properties props) { - super(props); - } - - @SuppressWarnings("unchecked") - @Override - public RosettaDF newDataFactory(Class... classes) throws APIException { - return new RosettaDF(this, null, null, (Class)classes[0]); - } - - @SuppressWarnings("unchecked") - @Override - public RosettaDF newDataFactory(Schema schema, Class... classes) throws APIException { - return new RosettaDF(this, schema, null, (Class)classes[0]); - } - - @SuppressWarnings("unchecked") - @Override - public RosettaDF newDataFactory(QName qName, Class ... classes) throws APIException { - return new RosettaDF(this, null, qName.getNamespaceURI(),(Class)classes[0]); - } - - @SuppressWarnings("unchecked") - @Override - public RosettaDF newDataFactory(Schema schema, QName qName, Class ... classes) throws APIException { - return new RosettaDF(this, schema,qName.getNamespaceURI(),(Class)classes[0]); - } -} diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/DataWriter.java b/rosetta/src/main/java/com/att/rosetta/marshal/DataWriter.java deleted file mode 100644 index f5b13d8..0000000 --- a/rosetta/src/main/java/com/att/rosetta/marshal/DataWriter.java +++ /dev/null @@ -1,139 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta.marshal; - -import javax.xml.datatype.XMLGregorianCalendar; - -import com.att.inno.env.util.Chrono; - -/** - * We make these objects instead of static functions so they can be passed into - * FieldArray. - * - * - * @param - */ -public abstract class DataWriter { - public abstract boolean write(T t, StringBuilder sb); - - public final static DataWriter STRING = new DataWriter() { - @Override - public boolean write(String s, StringBuilder sb) { - sb.append(s); - return true; - } - }; - - public final static DataWriter INTEGER = new DataWriter() { - @Override - public boolean write(Integer i, StringBuilder sb) { - sb.append(i); - return false; - } - }; - - public final static DataWriter LONG = new DataWriter() { - @Override - public boolean write(Long t, StringBuilder sb) { - sb.append(t); - return false; - } - }; - - public final static DataWriter BYTE = new DataWriter() { - @Override - public boolean write(Byte t, StringBuilder sb) { - sb.append(t); - return false; - } - }; - - public final static DataWriter CHAR = new DataWriter() { - @Override - public boolean write(Character t, StringBuilder sb) { - sb.append(t); - return true; - } - }; - - public final static DataWriter BOOL = new DataWriter() { - @Override - public boolean write(Boolean t, StringBuilder sb) { - sb.append(t); - return true; - } - }; - - - /* - public final static DataWriter BYTE_ARRAY = new DataWriter() { - @Override - public boolean write(byte[] ba, StringBuilder sb) { - ByteArrayInputStream bais = new ByteArrayInputStream(ba); - StringBuilderOutputStream sbos = new StringBuilderOutputStream(sb); -// try { - //TODO find Base64 -// Symm.base64noSplit().encode(bais, sbos); -// } catch (IOException e) { -// // leave blank -// } - return true; - } - - }; - */ - - public final static DataWriter DATE = new DataWriter() { - @Override - public boolean write(XMLGregorianCalendar t, StringBuilder sb) { - sb.append(Chrono.dateOnlyStamp(t)); - return true; - } - }; - - public final static DataWriter DATE_TIME = new DataWriter() { - @Override - public boolean write(XMLGregorianCalendar t, StringBuilder sb) { - sb.append(Chrono.dateTime(t)); - return true; - } - }; - - private static final char[] chars="0123456789ABCDEF".toCharArray(); - public final static DataWriter HEX_BINARY = new DataWriter() { - @Override - public boolean write(byte[] ba, StringBuilder sb) { - // FYI, doing this because don't want intermediate - // String in "HexString" or the processing in - // "String.format" - //sb.append("0x"); - for(int i=0;i>4)]); - sb.append(chars[b&0xF]); - } - return true; - } - }; - -} diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/DocMarshal.java b/rosetta/src/main/java/com/att/rosetta/marshal/DocMarshal.java deleted file mode 100644 index 555f419..0000000 --- a/rosetta/src/main/java/com/att/rosetta/marshal/DocMarshal.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta.marshal; - -import java.util.Iterator; - -import com.att.rosetta.Ladder; -import com.att.rosetta.Marshal; -import com.att.rosetta.ParseException; -import com.att.rosetta.Parsed; - -public class DocMarshal extends Marshal { - private Marshal root; - - public DocMarshal(Marshal root) { - this.root = root; - } - - @Override - public Parsed parse(T t, Parsed parsed) throws ParseException { - Ladder> ladder = parsed.state.ladder; - Iterator iter = ladder.peek(); - if(iter==null) { - ladder.push(PENDING_ITERATOR); - parsed.event = START_DOC; - } else if (DONE_ITERATOR.equals(iter)) { - } else { - ladder.ascend(); // look at field info - Iterator currFieldIter = ladder.peek(); - if(!DONE_ITERATOR.equals(currFieldIter)){ - parsed = root.parse(t, parsed); - } - ladder.descend(); - if(DONE_ITERATOR.equals(currFieldIter) || parsed.event==NONE) { - parsed.event = END_DOC; - ladder.push(DONE_ITERATOR); - } - } - return parsed; // if unchanged, then it will end process - - } - - public static final Iterator PENDING_ITERATOR = new Iterator() { - @Override - public boolean hasNext() { - return false; - } - - @Override - public Void next() { - return null; - } - - @Override - public void remove() { - } - }; - - public static DocMarshal root(Marshal m) { - return (DocMarshal)new DocMarshal(m); - } - -} diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/FieldArray.java b/rosetta/src/main/java/com/att/rosetta/marshal/FieldArray.java deleted file mode 100644 index 6a300dd..0000000 --- a/rosetta/src/main/java/com/att/rosetta/marshal/FieldArray.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta.marshal; - -import java.util.Iterator; -import java.util.List; - -import com.att.rosetta.Ladder; -import com.att.rosetta.Marshal; -import com.att.rosetta.ParseException; -import com.att.rosetta.Parsed; - - -public abstract class FieldArray extends Marshal { - private DataWriter dataWriter; - private String name; - - public FieldArray(String name, DataWriter dw) { - this.name = name; - dataWriter = dw; - } - - @SuppressWarnings("unchecked") - @Override - public Parsed parse(T t, Parsed parsed) throws ParseException { - Ladder> ladder = parsed.state.ladder; - Iterator iter = ladder.peek(); - if(iter==null) { - List list = data(t); - if(list.isEmpty() && parsed.state.smallest) { - ladder.push(DONE_ITERATOR); - } else { - ladder.push(new ListIterator(list)); - parsed.event = START_ARRAY; - parsed.name = name; - } - } else if (DONE_ITERATOR.equals(iter)) { - } else { - ladder.ascend(); // look at field info - Iterator memIter = ladder.peek(); - ListIterator mems = (ListIterator)iter; - S mem; - if(memIter==null) { - mem=mems.next(); - } else if(!DONE_ITERATOR.equals(memIter)) { - mem=mems.peek(); - } else if(iter.hasNext()) { - mem=null; - ladder.push(null); - } else { - mem=null; - } - - if(mem!=null) { - parsed.isString=dataWriter.write(mem, parsed.sb); - parsed.event = NEXT; - } - ladder.descend(); - if(mem==null) { - if(iter.hasNext()) { - parsed.event = NEXT; - } else { - parsed.event = END_ARRAY; - ladder.push(DONE_ITERATOR); - } - } - } - return parsed; // if unchanged, then it will end process - } - - protected abstract List data(T t); - -} diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/FieldBlob.java b/rosetta/src/main/java/com/att/rosetta/marshal/FieldBlob.java deleted file mode 100644 index 5c569e6..0000000 --- a/rosetta/src/main/java/com/att/rosetta/marshal/FieldBlob.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta.marshal; - -public abstract class FieldBlob extends FieldMarshal{ - public FieldBlob(String name) { - super(name); - } - - protected abstract byte[] data(T t); - - @Override - protected boolean data(T t, StringBuilder sb) { - return false; - // unimplemented - //return DataWriter.BYTE_ARRAY.write(data(t),sb); - } - -} diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/FieldDate.java b/rosetta/src/main/java/com/att/rosetta/marshal/FieldDate.java deleted file mode 100644 index b23232c..0000000 --- a/rosetta/src/main/java/com/att/rosetta/marshal/FieldDate.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta.marshal; - -import javax.xml.datatype.XMLGregorianCalendar; - -public abstract class FieldDate extends FieldMarshal { - public FieldDate(String name) { - super(name); - } - - @Override - final protected boolean data(T t, StringBuilder sb) { - return DataWriter.DATE.write(data(t), sb); - } - - protected abstract XMLGregorianCalendar data(T t); -} diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/FieldDateTime.java b/rosetta/src/main/java/com/att/rosetta/marshal/FieldDateTime.java deleted file mode 100644 index 4caf247..0000000 --- a/rosetta/src/main/java/com/att/rosetta/marshal/FieldDateTime.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta.marshal; - -import javax.xml.datatype.XMLGregorianCalendar; - -public abstract class FieldDateTime extends FieldMarshal { - public FieldDateTime(String name) { - super(name); - } - - @Override - final protected boolean data(T t, StringBuilder sb) { - return DataWriter.DATE_TIME.write(data(t), sb); - } - - protected abstract XMLGregorianCalendar data(T t); -} diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/FieldHexBinary.java b/rosetta/src/main/java/com/att/rosetta/marshal/FieldHexBinary.java deleted file mode 100644 index 199e52f..0000000 --- a/rosetta/src/main/java/com/att/rosetta/marshal/FieldHexBinary.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta.marshal; - -public abstract class FieldHexBinary extends FieldMarshal{ - public FieldHexBinary(String name) { - super(name); - } - - protected abstract byte[] data(T t); - - @Override - protected boolean data(T t, StringBuilder sb) { - return DataWriter.HEX_BINARY.write(data(t), sb); - } -} diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/FieldMarshal.java b/rosetta/src/main/java/com/att/rosetta/marshal/FieldMarshal.java deleted file mode 100644 index f0916be..0000000 --- a/rosetta/src/main/java/com/att/rosetta/marshal/FieldMarshal.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta.marshal; - - -import com.att.rosetta.Marshal; -import com.att.rosetta.Parse; -import com.att.rosetta.Parsed; - -public abstract class FieldMarshal extends Marshal { - private String name; - - public FieldMarshal(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - @Override - public Parsed parse(T t, Parsed parsed) { - parsed.state.ladder.push(DONE_ITERATOR); - parsed.event = Parse.NEXT; - parsed.name = name; - parsed.isString = data(t,parsed.sb); - return parsed; - } - - /** - * Write Value to StringBuilder - * Return true if value looks like a String - * false if it is Numeric - * @param t - * @param sb - * @return - */ - protected abstract boolean data(T t, StringBuilder sb); - -} diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/FieldNumeric.java b/rosetta/src/main/java/com/att/rosetta/marshal/FieldNumeric.java deleted file mode 100644 index 595ce63..0000000 --- a/rosetta/src/main/java/com/att/rosetta/marshal/FieldNumeric.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta.marshal; - -public abstract class FieldNumeric extends FieldMarshal { - public FieldNumeric(String name) { - super(name); - } - - @Override - final protected boolean data(T t, StringBuilder sb) { - sb.append(data(t)); - return false; - } - - protected abstract N data(T t); -} diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/FieldString.java b/rosetta/src/main/java/com/att/rosetta/marshal/FieldString.java deleted file mode 100644 index 482c211..0000000 --- a/rosetta/src/main/java/com/att/rosetta/marshal/FieldString.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta.marshal; - -public abstract class FieldString extends FieldMarshal { - public FieldString(String name) { - super(name); - } - - protected abstract String data(T t); - - @Override - final protected boolean data(T t, StringBuilder sb) { - return DataWriter.STRING.write(data(t), sb); - } - -} diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/ListIterator.java b/rosetta/src/main/java/com/att/rosetta/marshal/ListIterator.java deleted file mode 100644 index 9aa75b5..0000000 --- a/rosetta/src/main/java/com/att/rosetta/marshal/ListIterator.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta.marshal; - -import java.util.Iterator; -import java.util.List; - -/** - * Need an Iterator that can peek the current value without changing - * - * @param - */ -final class ListIterator implements Iterator { - private T curr; - private Iterator delg; - public ListIterator(List list) { - curr = null; - delg = list.iterator(); - } - @Override - public boolean hasNext() { - return delg.hasNext(); - } - - @Override - public T next() { - return curr = delg.hasNext()?delg.next():null; - } - - public T peek() { - return curr==null?next():curr; - } - - @Override - public void remove() { - delg.remove(); - } - -} diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/ObjArray.java b/rosetta/src/main/java/com/att/rosetta/marshal/ObjArray.java deleted file mode 100644 index abfb483..0000000 --- a/rosetta/src/main/java/com/att/rosetta/marshal/ObjArray.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta.marshal; - -import java.util.Iterator; -import java.util.List; - -import com.att.rosetta.Ladder; -import com.att.rosetta.Marshal; -import com.att.rosetta.ParseException; -import com.att.rosetta.Parsed; - - -public abstract class ObjArray extends Marshal { - private String name; - private Marshal subMarshaller; - - public ObjArray(String name, Marshal subMarshaller) { - this.name = name; - this.subMarshaller = subMarshaller; - } - - @SuppressWarnings("unchecked") - @Override - public Parsed parse(T t, Parsed parsed) throws ParseException { - Ladder> ladder = parsed.state.ladder; - Iterator iter = ladder.peek(); - if(iter==null) { - List list = data(t); - if(list.isEmpty() && parsed.state.smallest) { - ladder.push(DONE_ITERATOR); - } else { - ladder.push(new ListIterator(list)); - parsed.event = START_ARRAY; - parsed.name = name; - } - } else if (DONE_ITERATOR.equals(iter)) { - } else { - ladder.ascend(); // look at field info - Iterator memIter = ladder.peek(); - ListIterator mems = (ListIterator)iter; - S mem; - if(memIter==null) { - mem=mems.next(); - } else if(!DONE_ITERATOR.equals(memIter)) { - mem=mems.peek(); - } else if(iter.hasNext()) { - mem=null; - ladder.push(null); - } else { - mem=null; - } - - if(mem!=null) - parsed = subMarshaller.parse(mem, parsed); - ladder.descend(); - if(mem==null) { - if(iter.hasNext()) { - parsed.event = NEXT; - } else { - parsed.event = END_ARRAY; - ladder.push(DONE_ITERATOR); - } - } - } - return parsed; // if unchanged, then it will end process - } - - protected abstract List data(T t); - -} diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/ObjMarshal.java b/rosetta/src/main/java/com/att/rosetta/marshal/ObjMarshal.java deleted file mode 100644 index bef128b..0000000 --- a/rosetta/src/main/java/com/att/rosetta/marshal/ObjMarshal.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.rosetta.marshal; - -import java.util.Iterator; - -import com.att.rosetta.Ladder; -import com.att.rosetta.Marshal; -import com.att.rosetta.ParseException; -import com.att.rosetta.Parsed; - -/** - * Object Marshal - * Assumes has Fields and other Objects - * s - * - * @param - */ -public abstract class ObjMarshal extends Marshal { - // Note: Not Using List or ArrayList, because there is no "Peek" concept in their iterator. - private Marshal[] pml; - private int end=0; - - /** - * @param pm - */ - @SuppressWarnings("unchecked") - protected void add(Marshal pm) { - if(pml==null) { - pml = new Marshal[Ladder.DEFAULT_INIT_SIZE]; - } else if(end>pml.length) { - Object temp[] = pml; - pml = new Marshal[pml.length+Ladder.DEFAULT_INIT_SIZE]; - System.arraycopy(temp, 0, pml, 0, pml.length); - } - pml[end]=pm; - ++end; - } - - /* (non-Javadoc) - * @see com.att.rosetta.Parse#parse(java.lang.Object, com.att.rosetta.Parsed) - */ - @SuppressWarnings("unchecked") - @Override - public Parsed parse(T in, Parsed parsed) throws ParseException { - Ladder> ladder = parsed.state.ladder; - Iterator> iter = (Iterator>)ladder.peek(); - if(iter==null) { - if(pml.length>0) { - ladder.push(new FieldsIterator()); - parsed.event = START_OBJ; - } else { - ladder.push(DONE_ITERATOR); - } - } else if (DONE_ITERATOR.equals(iter)) { - } else { - FieldsIterator fields = (FieldsIterator)iter; - ladder.ascend(); // look at field info - Iterator currFieldIter = ladder.peek(); - Marshal marshal; - if(currFieldIter==null) { - marshal=fields.next(); - } else if(!DONE_ITERATOR.equals(currFieldIter)) { - marshal=fields.peek(); - if(marshal==null && fields.hasNext())marshal=fields.next(); - } else if(fields.hasNext()) { - marshal=fields.next(); - ladder.push(null); - } else { - marshal=null; - } - - if(marshal!=null) - parsed = marshal.parse(in, parsed); - ladder.descend(); - if(marshal==null || parsed.event==NONE) { - parsed.event = END_OBJ; - ladder.push(DONE_ITERATOR); - } - } - return parsed; // if unchanged, then it will end process - } - - private class FieldsIterator implements Iterator> { - private int idx = -1; - - @Override - public boolean hasNext() { - return idx next() { - return pml[++idx]; - } - - public Marshal peek() { - return idx<0?null:pml[idx]; - } - - @Override - public void remove() { - pml[idx]=null; - } - - } - -} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/InJson.java b/rosetta/src/main/java/org/onap/aaf/rosetta/InJson.java new file mode 100644 index 0000000..22e72a5 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/InJson.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta; + +import java.io.IOException; +import java.io.Reader; + +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.TimeTaken; +import org.onap.aaf.rosetta.InJson.State; + +public class InJson implements Parse { + public Parsed parse(Reader r, Parsed parsed) throws ParseException { + // First things first, if there's a "leftover" event, process that immediately + State state = (State)parsed.state; + if(state.unsent > 0) { + parsed.event = state.unsent; + state.unsent = 0; + return parsed; + } + + int ch; + char c; + StringBuilder sb = parsed.sb; + boolean inQuotes = false, escaped = false; + boolean go = true; + try { + // Gather data from Reader, looking for special characters when not in Quotes + while(go && (ch=r.read())>=0) { + if(state.braces>=0 || ch==Parse.START_OBJ) { // ignore garbage/whitespace before content + c=(char)ch; + // Character is a quote. + if(c=='"') { + if(inQuotes) { + if(escaped) { // if escaped Quote, add to data. + sb.append(c); + escaped = false; + } else { + inQuotes = false; + } + } else { + parsed.isString=true; + inQuotes = true; + } + } else { // Not a Quote + if(inQuotes) { + if(c=='\\') { + if(escaped) { + sb.append("\\\\"); + escaped = false; + } else { + escaped = true; + } + } else { + sb.append(c); + } + } else { + switch(c) { + case ':': + parsed.dataIsName(); + parsed.isString = false; + break; + case Parse.START_OBJ: + if(state.braces++ == 0) { + parsed.event = START_DOC; + state.unsent = c; + } else { + parsed.event = c; + } + go = false; + break; + case Parse.END_OBJ: + if(--state.braces == 0) { + parsed.event = c; + state.unsent = END_DOC; + } else { + parsed.event = c; + } + go = false; + break; + // These three end the data gathering, and send it along with the event that is ending the data gathering + case Parse.NEXT: + if(parsed.name.startsWith("__")) { + parsed.event = Parse.ATTRIB; + parsed.name = parsed.name.substring(2); + } else { + parsed.event = c; + } + go = false; + break; + case Parse.START_ARRAY: + case Parse.END_ARRAY: + parsed.event = c; + go = false; + break; + + // The Escape Sequence, for Quote marks within Quotes + case '\\': + // Ignore these, unless within quotes, at which point data-gather + case ' ': + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + break; + // Normal data... gather it + default: + sb.append(c); + } + } + } + } + } + return parsed; + } catch (IOException e) { + throw new ParseException(e); + } + } + + public static class State { + public int braces = 0; + public char unsent = 0; + } + +// @Override + public Parsed newParsed() { + return new Parsed(new State()); // no State needed + } + +// @Override + public TimeTaken start(Env env) { + return env.start("Rosetta JSON In", Env.JSON); + } +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/InXML.java b/rosetta/src/main/java/org/onap/aaf/rosetta/InXML.java new file mode 100644 index 0000000..25e91db --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/InXML.java @@ -0,0 +1,487 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta; + +import java.io.IOException; +import java.io.Reader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Stack; + +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.TimeTaken; +import org.onap.aaf.rosetta.InXML.State; + +public class InXML implements Parse { + // package on purpose + JaxInfo jaxInfo; + + public InXML(JaxInfo jaxInfo) { + this.jaxInfo = jaxInfo; + } + + public InXML(Class cls, String ... rootNs) throws SecurityException, NoSuchFieldException, ClassNotFoundException, ParseException { + jaxInfo = JaxInfo.build(cls,rootNs); + } + + + // @Override + public Parsed parse(Reader r, Parsed parsed) throws ParseException { + State state = parsed.state; + + // OK, before anything else, see if there is leftover processing, if so, do it! + if(state.unevaluated!=null) { + DerTag dt = state.unevaluated; + state.unevaluated = null; + if(!state.greatExp.eval(parsed, dt))return parsed; + } + + if(state.hasAttributes()) { + Prop prop = state.pop(); + parsed.event = Parse.ATTRIB; + parsed.name = prop.tag; + parsed.sb.append(prop.value); + parsed.isString=true; + return parsed; + } + int ch; + char c; + boolean inQuotes = false, escaped = false; + + StringBuilder sb = parsed.sb, tempSB = new StringBuilder(); + boolean go = true; + + try { + while(go && (ch=r.read())>=0) { + c = (char)ch; + if(c == '"') { + if(state.greatExp instanceof LeafExpectations) { // within a set of Tags, make a Quote + sb.append(c); + } else { + if(inQuotes) { + if(escaped) { + sb.append('\\'); + sb.append(c); + escaped = false; + } else { + inQuotes = false; + } + } else { + parsed.isString=true; + inQuotes = true; + } + } + } else if(inQuotes) { + sb.append(c); + } else if(c=='&') { + XmlEscape.xmlEscape(sb,r); + } else { + switch(c) { + case '<': + DerTag tag=new DerTag().parse(r, tempSB); + go = state.greatExp.eval(parsed, tag); + break; + default: + // don't add Whitespace to start of SB... saves removing later + if(sb.length()>0) { + sb.append(c); + } else if(!Character.isWhitespace(c)) { + sb.append(c); + } + } + } + } + return parsed; + } catch (IOException e) { + throw new ParseException(e); + } + } + + public static final class DerTag { + public String name; + public boolean isEndTag; + public List props; + private boolean isXmlInfo; + //private String ns; + + public DerTag() { + name=null; + isEndTag = false; + props = null; + isXmlInfo = false; + } + + public DerTag parse(Reader r, StringBuilder sb) throws ParseException { + int ch; + char c; + boolean inQuotes = false, escaped = false; + boolean go = true; + String tag = null; + + try { + if((ch = r.read())<0) throw new ParseException("Reader content ended before complete"); + if(ch=='?') { + isXmlInfo = true; + } + // TODO Check for !-- comments + do { + c=(char)ch; + if(c=='"') { + if(inQuotes) { + if(escaped) { + sb.append(c); + escaped = false; + } else { + inQuotes = false; + } + } else { + inQuotes = true; + } + } else if(inQuotes) { + sb.append(c); + } else { + switch(c) { + case '/': + isEndTag = true; + break; + case ' ': + endField(tag,sb); + tag = null; + break; + case '>': + endField(tag,sb); + go = false; + break; + case '=': + tag = sb.toString(); + sb.setLength(0); + break; +// case ':': +// ns = sb.toString(); +// sb.setLength(0); +// break; + case '?': + if(!isXmlInfo)sb.append(c); + break; + default: + sb.append(c); + } + } + } while(go && (ch=r.read())>=0); + } catch (IOException e) { + throw new ParseException(e); + } + return this; + } + + private void endField(String tag, StringBuilder sb) { + if(name==null) { + name = sb.toString(); + sb.setLength(0); + } else { + String value = sb.toString(); + sb.setLength(0); + if(tag !=null && value != null) { + if(props==null)props = new ArrayList(); + props.add(new Prop(tag,value)); + } + } + } + + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(isEndTag?"End":"Start"); + sb.append(" Tag\n"); + sb.append(" Name: "); + sb.append(name); + if(props!=null) for(Prop p : props) { + sb.append("\n "); + sb.append(p.tag); + sb.append("=\""); + sb.append(p.value); + sb.append('"'); + } + return sb.toString(); + } + } + + private static class ArrayState { + public boolean firstObj = true; + public boolean didNext = false; + } + + public static class State { + public GreatExpectations greatExp; + public DerTag unevaluated; + public Stack arrayInfo; + private List attribs; + private int idx; + public State(JaxInfo ji, DerTag dt) throws ParseException { + greatExp = new RootExpectations(this, ji, null); + unevaluated = null; + attribs = null;; + } + + public boolean hasAttributes() { + return attribs!=null && idx(); + idx = 0; + } + attribs.add(prop); + } + + public Prop pop() { + Prop rv = null; + if(attribs!=null) { + rv = attribs.get(idx++); + if(idx>=attribs.size())attribs = null; + } + return rv; + } + } + + private static abstract class GreatExpectations { + protected JaxInfo ji; + protected GreatExpectations prev; + private Map ns; + + public GreatExpectations(State state, JaxInfo curr, GreatExpectations prev, DerTag derTag) throws ParseException { + this.prev = prev; + ns = null; + ji = getDerived(state, curr,derTag); + } + + public abstract boolean eval(Parsed parsed, DerTag derTag) throws ParseException; + + // Recursively look back for any namespaces + protected Map getNS() { + if(ns!=null)return ns; + if(prev!=null) { + return prev.getNS(); + } + return null; + } + + private void addNS(Prop prop) { + Map existingNS = getNS(); + if(ns==null)ns = new HashMap(); + // First make a copy of previous NSs so that we have everything we need, but can overwrite, if necessary + if(existingNS!=null && ns!=existingNS) { + ns.putAll(ns); + } + ns.put(prop.tag, prop.value); + } + + private JaxInfo getDerived(State state, JaxInfo ji, DerTag derTag) throws ParseException { + if(derTag==null)return ji; + + List props = derTag.props; + + Prop derived = null; + if(props!=null) { + // Load Namespaces (if any) + for(Prop prop : props) { + if(prop.tag.startsWith("xmlns:")) { + addNS(prop); + } + } + for(Prop prop : props) { + if(prop.tag.endsWith(":type")) { + int idx = prop.tag.indexOf(':'); + String potentialNS = "xmlns:"+prop.tag.substring(0,idx); + Map ns = getNS(); + boolean noNamespace = false; + if(ns==null) { + noNamespace = true; + } else { + String nsVal = ns.get(potentialNS); + if(nsVal==null) noNamespace = true; + else { + derived = new Prop(Parsed.EXTENSION_TAG,prop.value); + state.push(derived); + } + } + if(noNamespace) { + throw new ParseException(prop.tag + " utilizes an invalid Namespace prefix"); + } + } else if(!prop.tag.startsWith("xmlns")) { + state.push(prop); + } + } + } + return derived==null?ji:ji.getDerived(derived.value); + } + } + + private static class RootExpectations extends GreatExpectations { + + public RootExpectations(State state, JaxInfo curr, GreatExpectations prev) throws ParseException { + super(state,curr,prev, null); + } + + // @Override + public boolean eval(Parsed parsed, DerTag derTag) throws ParseException { + if(derTag.isXmlInfo) { + parsed.event = START_DOC; + } else if(ji.name.equals(derTag.name)) { + if(derTag.isEndTag) { + parsed.event = END_DOC; + parsed.state.greatExp = prev; + } else { + //parsed.name = derTag.name; + parsed.event = START_OBJ; + parsed.state.greatExp = new ObjectExpectations(parsed.state,ji, this, false, derTag); + } + } + return false; + } + } + + private static class ObjectExpectations extends GreatExpectations { + private boolean printName; + + public ObjectExpectations(State state, JaxInfo curr, GreatExpectations prev, boolean printName, DerTag derTag) throws ParseException { + super(state, curr, prev, derTag); + this.printName=printName; + } + + // @Override + public boolean eval(Parsed parsed, DerTag derTag) throws ParseException { + if(derTag.isEndTag && ji.name.equals(derTag.name)) { + parsed.state.greatExp = prev; + parsed.event = END_OBJ; + if(printName)parsed.name = ji.name; + } else { + //Standard Members + for(JaxInfo memb : ji.members) { + if(memb.name.equals(derTag.name)) { + parsed.name = memb.name; + if(memb.isArray) { + parsed.state.unevaluated = derTag; // evaluate within Array Context + parsed.event = START_ARRAY; + parsed.state.greatExp = new ArrayExpectations(parsed.state,memb,this); + return false; + } else if(memb.isObject()) { + if(derTag.isEndTag) { + throw new ParseException("Unexpected End Tag '); + } else { + parsed.event = START_OBJ; + + parsed.state.greatExp = new ObjectExpectations(parsed.state, memb,this,true,derTag); + return false; + } + } else { // a leaf + if(derTag.isEndTag) { + throw new ParseException("Misplaced End Tag '); + } else { + parsed.state.greatExp = new LeafExpectations(parsed.state,memb, this); + return true; // finish out Leaf without returning + } + } + } + } + + throw new ParseException("Unexpected Tag <" + derTag.name + '>'); + } + return false; + } + } + + private static class LeafExpectations extends GreatExpectations { + public LeafExpectations(State state, JaxInfo curr, GreatExpectations prev) throws ParseException { + super(state, curr, prev, null); + } + + // @Override + public boolean eval(Parsed parsed, DerTag derTag) throws ParseException { + if(ji.name.equals(derTag.name) && derTag.isEndTag) { + parsed.event = NEXT; + parsed.isString = ji.isString; + parsed.state.greatExp = prev; + } else { + throw new ParseException("Expected '); + } + return false; + } + } + + private static class ArrayExpectations extends GreatExpectations { + public ArrayExpectations(State state, JaxInfo ji, GreatExpectations prev) throws ParseException { + super(state, ji, prev,null); + if(state.arrayInfo==null)state.arrayInfo=new Stack(); + state.arrayInfo.push(new ArrayState()); + } + // @Override + public boolean eval(Parsed parsed, DerTag derTag) throws ParseException { + if(ji.name.equals(derTag.name) && !derTag.isEndTag) { + if(ji.isObject()) { + if(derTag.isEndTag) { + throw new ParseException("Unexpected End Tag '); + } else { + ArrayState ai = parsed.state.arrayInfo.peek(); + if(ai.firstObj || ai.didNext) { + ai.firstObj = false; + ai.didNext = false; + parsed.event = START_OBJ; + parsed.name=derTag.name; + parsed.state.greatExp = new ObjectExpectations(parsed.state,ji,this,true, derTag); + } else { + ai.didNext = true; + parsed.event = NEXT; + parsed.state.unevaluated = derTag; + } + } + } else { // a leave + if(derTag.isEndTag) { + throw new ParseException("Misplaced End Tag '); + } else { + parsed.state.greatExp = new LeafExpectations(parsed.state, ji, this); + return true; // finish out Leaf without returning + } + } + } else { // Tag now different... Array is done + parsed.state.unevaluated = derTag; + parsed.event=END_ARRAY; + parsed.state.greatExp = prev; + parsed.state.arrayInfo.pop(); + } + return false; + } + } + // @Override + public Parsed newParsed() throws ParseException { + return new Parsed(new State(jaxInfo, null)); + } + + // @Override + public TimeTaken start(Env env) { + return env.start("Rosetta XML In", Env.XML); + } + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/JaxEval.java b/rosetta/src/main/java/org/onap/aaf/rosetta/JaxEval.java new file mode 100644 index 0000000..62e57b8 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/JaxEval.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta; + +public interface JaxEval{ + public abstract JaxEval eval(Parsed p) throws ParseException; +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/JaxInfo.java b/rosetta/src/main/java/org/onap/aaf/rosetta/JaxInfo.java new file mode 100644 index 0000000..8d3d87b --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/JaxInfo.java @@ -0,0 +1,249 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta; + +import java.lang.reflect.Field; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSchema; +import javax.xml.bind.annotation.XmlType; +import javax.xml.datatype.XMLGregorianCalendar; + +public class JaxInfo { + private static final String DEFAULT = "##default"; + public static final int DATA = 0; + public static final int ARRAY = 1; + public static final int OBJECT = 2; + + public final String name; + public final Class clss; + public Map extensions; // Classes, which might be found at runtime, that extend this class. Lazy Instantiation + public final JaxInfo[] members; + public final boolean isArray; + public final boolean isString; + public final boolean required; + public final boolean nillable; + public String ns; + public boolean isObject() {return members!=null;} + + private JaxInfo(String n, String ns, Class c, JaxInfo[] members, boolean string, boolean array, boolean required, boolean nillable) { + name = n; + this.ns = ns; + clss = c; + this.members = members; + this.isString = string; + isArray = array; + this.required = required; + this.nillable = nillable; + extensions = null; + } + + + public int getType() { + if(isArray)return ARRAY; + else if(members!=null)return OBJECT; + return DATA; + } + + public JaxInfo getDerived(String derivedName) { + JaxInfo derived; + // Lazy Instantiation + if(extensions == null) { + extensions = new HashMap(); + derived = null; + } else { + derived = extensions.get(derivedName); + } + + if(derived == null) { + //TODO for the moment, Classes are in same package + Package pkg = clss.getPackage(); + try { + Class dc = getClass().getClassLoader().loadClass(pkg.getName()+'.'+Character.toUpperCase(derivedName.charAt(0))+derivedName.substring(1)); + derived = JaxInfo.build(dc, this); // Use this JAXInfo's name so the tags are correct + extensions.put(derivedName, derived); + } catch (Exception e) { + e.printStackTrace(); + } + } + return derived; + } + + public static JaxInfo get(JaxInfo[] fields, String name) { + for(JaxInfo f : fields) { + if(name.equals(f.name)) return f; + } + return null; + } + + /** + * Build up JAXB Information (recursively) + * + * @param cls + * @param rootNns + * @return + * @throws SecurityException + * @throws NoSuchFieldException + * @throws ClassNotFoundException + * @throws ParseException + */ + public static JaxInfo build(Class cls, JaxInfo parent) throws NoSuchFieldException, ClassNotFoundException, ParseException { + return new JaxInfo(parent.name,parent.ns, cls,buildFields(cls,parent.ns),parent.isString, parent.isArray,parent.required,parent.nillable); + } + /** + * Build up JAXB Information (recursively) + * + * @param cls + * @param rootNns + * @return + * @throws SecurityException + * @throws NoSuchFieldException + * @throws ClassNotFoundException + * @throws ParseException + */ + public static JaxInfo build(Class cls, String ... rootNns) throws SecurityException, NoSuchFieldException, ClassNotFoundException, ParseException { + String defaultNS; + if(rootNns.length>0 && rootNns[0]!=null) { + defaultNS = rootNns[0]; + } else { + Package pkg = cls.getPackage(); + XmlSchema xs = pkg.getAnnotation(XmlSchema.class); + defaultNS = xs==null?"":xs.namespace(); + } + String name; + if(rootNns.length>1) { + name = rootNns[1]; + } else { + XmlRootElement xre = cls.getAnnotation(XmlRootElement.class); + if(xre!=null) { + name = xre.name(); + } else { + XmlType xt = cls.getAnnotation(XmlType.class); + if(xt!=null) { + name=xt.name(); + } else { + throw new ParseException("Need a JAXB Object with XmlRootElement, or stipulate in parms"); + } + } + } + + return new JaxInfo(name,defaultNS, cls,buildFields(cls,defaultNS),false,false,false,false); + } + + // Build up the name and members of this particular class + // This is recursive, if a member is a JAXB Object as well. + private static JaxInfo[] buildFields(Class clazz, String defaultNS) throws SecurityException, NoSuchFieldException, ClassNotFoundException { + ArrayList fields = null; // allow for lazy instantiation, because many structures won't have XmlType + Class cls = clazz; + // Build up Method names from JAXB Annotations + XmlType xt; + while((xt = cls.getAnnotation(XmlType.class))!=null) { + if(fields==null)fields = new ArrayList(); + for(String field : xt.propOrder()) { + if("".equals(field)) break; // odd bug. "" returned when no fields exist, rather than empty array + Field rf = cls.getDeclaredField(field); + Class ft = rf.getType(); + + boolean required = false; + boolean nillable = false; + String xmlName = field; + String namespace = defaultNS; + + XmlElement xe = rf.getAnnotation(XmlElement.class); + if(xe!=null) { + xmlName=xe.name(); + required = xe.required(); + nillable = false; + if(DEFAULT.equals(xmlName)) { + xmlName = field; + } + namespace = xe.namespace(); + if(DEFAULT.equals(namespace)) { + namespace = defaultNS; + } + } + // If object is a List, then it is possible multiple, per XML/JAXB evaluation + if(ft.isAssignableFrom(List.class)) { + Type t = rf.getGenericType(); + String classname = t.toString(); + int start = classname.indexOf('<'); + int end = classname.indexOf('>'); + Class genClass = Class.forName(classname.substring(start+1, end)); + xe = genClass.getAnnotation(XmlElement.class); + if(xe!=null && !DEFAULT.equals(xe.namespace())) { + namespace = xe.namespace(); + } + // add recursed recursed member, marked as array + fields.add(new JaxInfo(xmlName,namespace,genClass,buildFields(genClass,namespace), genClass.equals(String.class),true,required,nillable)); + } else { + boolean isString = ft.equals(String.class) || ft.equals(XMLGregorianCalendar.class); + // add recursed member + fields.add(new JaxInfo(xmlName,namespace,ft,buildFields(ft,namespace),isString,false,required,nillable)); + } + } + cls = cls.getSuperclass(); + }; + if(fields!=null) { + JaxInfo[] rv = new JaxInfo[fields.size()]; + fields.toArray(rv); + return rv; + } else { + return null; + } + } + + + public StringBuilder dump(StringBuilder sb, int idx) { + for(int i=0;i + */ +public class JaxSet { + private static Map,JaxSet> jsets = new HashMap,JaxSet>(); + private Map> members; + + private JaxSet(Class cls) { + members = new TreeMap>(); + XmlType xmltype = cls.getAnnotation(XmlType.class); + Class paramType[] = new Class[] {String.class}; + for(String str : xmltype.propOrder()) { + try { + String setName = "set" + Character.toUpperCase(str.charAt(0)) + str.subSequence(1, str.length()); + Method meth = cls.getMethod(setName,paramType ); + if(meth!=null) { + members.put(str, new Setter(meth) { + public void set(T o, Object t) throws ParseException { + try { + this.meth.invoke(o, t); + } catch (Exception e) { + throw new ParseException(e); + } + } + }); + } + } catch (Exception e) { + // oops + } + } + } + + public static abstract class Setter { + protected final Method meth; + public Setter(Method meth) { + this.meth = meth; + } + public abstract void set(O o, Object obj) throws ParseException; + } + + public static JaxSet get(Class cls) { + synchronized(jsets) { + @SuppressWarnings("unchecked") + JaxSet js = (JaxSet)jsets.get(cls); + if(js == null) { + jsets.put(cls, js = new JaxSet(cls)); + } + return js; + } + } + + public Setter get(String key) { + return members.get(key); + } +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/Ladder.java b/rosetta/src/main/java/org/onap/aaf/rosetta/Ladder.java new file mode 100644 index 0000000..2a08723 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/Ladder.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta; + + +/** + * A Ladder is a Stack like Storage Class, but where you can ascend and descend while + * the elements exists. + * + * Like an extension ladder, you can make taller as you go + * + * + */ +public class Ladder { + public static final int DEFAULT_INIT_SIZE=8; + private final int init_size; + private int rung; // as in ladder + private Object[] struts; + + public Ladder() { + rung=0; + init_size = DEFAULT_INIT_SIZE; + struts=new Object[init_size]; + } + + public Ladder(int initSize) { + rung=0; + init_size = initSize; + struts=new Object[init_size]; + } + + public void bottom() { + rung = 0; + } + + public void top() { + rung = struts.length-1; + while(rung>0 && struts[rung]==null)--rung; + } + + public int howHigh() { + return rung; + } + + public void jumpTo(int rung) { + if(rung>=struts.length) { + Object[] temp = new Object[init_size*((rung/init_size)+1)]; + System.arraycopy(struts, 0, temp, 0, struts.length); + struts = temp; + } + this.rung = rung; + } + + public int height() { + return struts.length; + } + + public void cutTo(int rungs) { + Object[] temp = new Object[rungs]; + System.arraycopy(struts, 0, temp, 0, Math.min(rungs, struts.length)); + struts = temp; + } + + public void ascend() { + ++rung; + if(rung>=struts.length) { + Object[] temp = new Object[struts.length+init_size]; + System.arraycopy(struts, 0, temp, 0, struts.length); + struts = temp; + } + } + + public void descend() { + --rung; + } + + @SuppressWarnings("unchecked") + public T peek() { + return (T)struts[rung]; + } + + public void push(T t) { + struts[rung]=t; + } + + @SuppressWarnings("unchecked") + public T pop() { + T t = (T)struts[rung]; + struts[rung]=null; + return t; + } + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/Marshal.java b/rosetta/src/main/java/org/onap/aaf/rosetta/Marshal.java new file mode 100644 index 0000000..80e3490 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/Marshal.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta; + +import java.util.Iterator; + +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.TimeTaken; + +public abstract class Marshal implements Parse { + + /* (non-Javadoc) + * @see com.att.rosetta.Parse#newParsed() + */ + @Override + public Parsed newParsed() throws ParseException { + return new Parsed(new State()); + } + + @Override + public TimeTaken start(Env env) { + //TODO is a way to mark not-JSON? + return env.start("Rosetta Marshal", Env.JSON); + }; + + public static class State { + // Note: Need a STATEFUL stack... one that will remain stateful until marked as finished + // "finished" is know by Iterators with no more to do/null + // Thus the concept of "Ladder", which one ascends and decends + public Ladder> ladder = new Ladder>(); + public boolean smallest = true; + } + + public static final Iterator DONE_ITERATOR = new Iterator() { + @Override + public boolean hasNext() { + return false; + } + + @Override + public Void next() { + return null; + } + + @Override + public void remove() { + } + }; + + /** + * Typical definition of Done is when Iterator in Ladder is "DONE_ITERATOR" + * + * It is important, however, that the "Ladder Rung" is set to the right level. + * + * @param state + * @return + */ + public boolean amFinished(State state) { + return DONE_ITERATOR.equals(state.ladder.peek()); + } + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/Nulls.java b/rosetta/src/main/java/org/onap/aaf/rosetta/Nulls.java new file mode 100644 index 0000000..1b76130 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/Nulls.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; + +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.TimeTaken; + +public class Nulls { + public static final Parse IN = new Parse() { + + // @Override + public Parsed parse(Reader r, Parsed parsed)throws ParseException { + parsed.event = Parse.END_DOC; + return parsed; + } + + // @Override + public Parsed newParsed() { + Parsed parsed = new Parsed(); + parsed.event = Parse.END_DOC; + return parsed; + } + + // @Override + public TimeTaken start(Env env) { + return env.start("IN", Env.SUB); + } + + }; + + public static final Out OUT = new Out() { + + // @Override + public void extract(IN in, Writer writer, Parse parse, boolean ... options)throws IOException, ParseException { + } + @Override + public String logName() { + return "Rosetta NULL"; + } + + + }; +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/Out.java b/rosetta/src/main/java/org/onap/aaf/rosetta/Out.java new file mode 100644 index 0000000..6ef8f21 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/Out.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; + +public abstract class Out { + public abstract void extract(IN in, Writer writer, Parse parse, boolean ... options) throws IOException, ParseException; + + public void extract(IN in, OutputStream os, Parse parse, boolean ... options) throws IOException, ParseException { + Writer w = new OutputStreamWriter(os); + try { + extract(in, w, parse, options); + } finally { + w.flush(); + } + } + + public abstract String logName(); + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/OutJax.java b/rosetta/src/main/java/org/onap/aaf/rosetta/OutJax.java new file mode 100644 index 0000000..ebd2390 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/OutJax.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta; + +import java.io.IOException; +import java.io.Writer; + +public class OutJax extends Out { + private JaxEval jaxEval; + + public OutJax(JaxEval je) { + this.jaxEval = je; + } + + @Override + public void extract(IN in, Writer writer, Parse parse, boolean... options) throws IOException, ParseException { + Parsed p = parse.newParsed(); + JaxEval je = this.jaxEval; + while((p = parse.parse(in,p.reuse())).valid()) { + if(je==null)throw new ParseException("Incomplete content"); + je = je.eval(p); + } + + } + + @Override + public String logName() { + return "Rosetta JAX"; + } + + + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/OutJson.java b/rosetta/src/main/java/org/onap/aaf/rosetta/OutJson.java new file mode 100644 index 0000000..3b5b2f8 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/OutJson.java @@ -0,0 +1,233 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta; + +import java.io.IOException; +import java.io.Writer; +import java.util.Stack; + +import org.onap.aaf.inno.env.util.IndentPrintWriter; + +public class OutJson extends Out { + + @Override + public void extract(IN in, Writer writer, Parse prs, boolean ... options) throws IOException, ParseException { + Parsed p = prs.newParsed(); + IndentPrintWriter ipw; + if(options.length>0 && options[0]) { // is Pretty + ipw = writer instanceof IndentPrintWriter?(IndentPrintWriter)writer:new IndentPrintWriter(writer); + writer = ipw; + } else { + ipw = null; + } + + // If it's a fragment, print first Object Name. If root Object, skip first name + Stack jsonLevel = new Stack(); + jsonLevel.push(new LevelStack(options.length>1 && options[1])); + boolean print = true, hadData=false; + char afterName=0, beforeName=0, maybe = 0, prev=0; + + int count = 0; + while((p = prs.parse(in,p.reuse())).valid()) { + ++count; + switch(p.event) { + case 1: + continue; + case 2: + if(count==2) { // it's empty, write open/close on it's own + writer.append('{'); + writer.append('}'); + } + writer.flush(); + return; + case '{': + afterName = '{'; + if(jsonLevel.peek().printObjectName) { + print = true; + } else { // don't print names on first + print=false; + } + maybe=jsonLevel.peek().listItem(); + jsonLevel.push(new LevelStack(true)); + break; + case '}': + if(p.hasData()) { // if we have data, we print that, so may need to prepend a comma. + maybe = jsonLevel.peek().listItem(); + } else { // No data means just print, + p.name = ""; // XML tags come through with names, but no data + } + print = true; + jsonLevel.pop(); + afterName = p.event; + break; + case '[': + afterName = p.event; + if((prev==',' && !hadData) || prev==']')maybe=','; + else maybe = jsonLevel.peek().listItem(); + + jsonLevel.push(new LevelStack(false)); + print=true; + break; + case ']': + afterName = p.event; + if(p.hasData()) { + if(prev==',' && !hadData)maybe=','; + else maybe = jsonLevel.peek().listItem(); + } else { + p.name = ""; // XML tags come through with names, but no data + } + jsonLevel.pop(); + + print = true; + break; + case 3: + case ',': + if(!p.hasData()) { + p.isString=false; + print=false; + } else { + maybe=jsonLevel.peek().listItem(); + print = true; + } + break; + default: + print = true; + } + + if(maybe!=0) { + if(ipw==null)writer.append(maybe); + else ipw.println(maybe); + maybe = 0; + } + + if(beforeName!=0) { + if(ipw==null)writer.append(beforeName); + else ipw.println(beforeName); + beforeName = 0; + } + if(print) { + if(p.hasName()) { + writer.append('"'); + if(p.event==3)writer.append("__"); + writer.append(p.name); + writer.append("\":"); + } + if(p.hasData()) { + if(p.isString) { + writer.append('"'); + escapedWrite(writer, p.sb); + writer.append('"'); + } else if(p.sb.length()>0) { + writer.append(p.sb); + } + } + } + if(afterName!=0) { + if(ipw==null)writer.append(afterName); + else { + switch(afterName) { + case '{': + ipw.println(afterName); + ipw.inc(); + break; + case '}': + ipw.dec(); + ipw.println(); + ipw.print(afterName); + break; + case ']': + if(prev=='}' || prev==',')ipw.println(); + ipw.dec(); + ipw.print(afterName); + break; + + case ',': + ipw.println(afterName); + break; + default: + ipw.print(afterName); + } + } + afterName = 0; + } + + if(ipw!=null) { + switch(p.event) { + case '[': + ipw.inc(); + ipw.println(); + break; + } + } + prev = p.event; + hadData = p.hasData(); + + } + writer.flush(); + } + + private void escapedWrite(Writer writer, StringBuilder sb) throws IOException { + char c; + for(int i=0;i void extract(IN in, Writer writer, Parse prs, boolean ... options) throws IOException, ParseException { + Parsed p = prs.newParsed(); + + while((p = prs.parse(in,p.reuse())).valid()) { + writer.append(p.toString()); + writer.append('\n'); + } + } + + @Override + public String logName() { + return "Rosetta RAW"; + } + + + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/OutXML.java b/rosetta/src/main/java/org/onap/aaf/rosetta/OutXML.java new file mode 100644 index 0000000..328b8f7 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/OutXML.java @@ -0,0 +1,226 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta; + +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Stack; + +import org.onap.aaf.inno.env.util.IndentPrintWriter; +import org.onap.aaf.inno.env.util.StringBuilderWriter; + +public class OutXML extends Out{ + private static final String XMLNS_XSI = "xmlns:xsi"; + public static final String XML_INFO = ""; + public static final String XML_SCHEMA_INSTANCE = "http://www.w3.org/2001/XMLSchema-instance"; + + private String root; + private List props; + + public OutXML(String root, String ... params) { + this.root = root; + props = new ArrayList(); + for(String p : params) { + String[] tv=p.split("="); + if(tv.length==2) + props.add(new Prop(tv[0],tv[1])); + } + } + + public OutXML(JaxInfo jaxInfo) { + this(jaxInfo.name,genNS(jaxInfo)); + } + + public OutXML(InXML inXML) { + this(inXML.jaxInfo.name,genNS(inXML.jaxInfo)); + } + + private static String[] genNS(JaxInfo jaxInfo) { + return new String[] {"xmlns=" + jaxInfo.ns}; + } + + + @Override + public void extract(IN in, Writer writer, Parse prs, boolean ... options) throws IOException, ParseException { + Parsed p = prs.newParsed(); + Stack stack = new Stack(); + // If it's an IndentPrintWriter, it is pretty printing. + boolean pretty = (options.length>0&&options[0]); + + IndentPrintWriter ipw; + if(pretty) { + if(writer instanceof IndentPrintWriter) { + ipw = (IndentPrintWriter)writer; + } else { + writer = ipw = new IndentPrintWriter(writer); + } + } else { + ipw=null; + } + boolean closeTag = false; + Level level = new Level(null); + while((p = prs.parse(in,p.reuse())).valid()) { + if(!p.hasName() && level.multi!=null) { + p.name=level.multi; + } + if(closeTag && p.event!=Parse.ATTRIB) { + writer.append('>'); + if(pretty)writer.append('\n'); + closeTag = false; + } + switch(p.event) { + case Parse.START_DOC: + if(!(options.length>1&&options[1])) // if not a fragment, print XML Info data + if(pretty)ipw.println(XML_INFO); + else writer.append(XML_INFO); + break; + case Parse.END_DOC: + break; + case Parse.START_OBJ: + stack.push(level); + level = new Level(level); + if(p.hasName()) { + closeTag = tag(writer,level.sbw,pretty,pretty,p.name,null); + } else if(root!=null && stack.size()==1) { // first Object + closeTag = tag(writer,level.sbw,pretty,pretty,root,null); + // Write Root Props + for(Prop prop : props) { + attrib(writer,pretty,prop.tag, prop.value,level); + } + } + if(pretty)ipw.inc(); + break; + case Parse.END_OBJ: + if(p.hasData()) + closeTag = tag(writer,writer,pretty,false,p.name, XmlEscape.convert(p.sb)); + if(pretty)ipw.dec(); + writer.append(level.sbw.getBuffer()); + level = stack.pop(); + break; + case Parse.START_ARRAY: + level.multi = p.name; + break; + case Parse.END_ARRAY: + if(p.hasData()) + closeTag = tag(writer,writer,pretty,false, p.name, XmlEscape.convert(p.sb)); + level.multi=null; + break; + case Parse.ATTRIB: + if(p.hasData()) + attrib(writer,pretty,p.name, XmlEscape.convert(p.sb), level); + break; + case Parse.NEXT: + if(p.hasData()) + closeTag = tag(writer,writer,pretty, false,p.name, XmlEscape.convert(p.sb)); + break; + } + } + writer.append(level.sbw.getBuffer()); + writer.flush(); + } + + private class Level { + public final StringBuilderWriter sbw; + public String multi; + private Level prev; + private Map nses; + + public Level(Level level) { + sbw = new StringBuilderWriter(); + multi = null; + prev = level; + } + + public boolean hasPrinted(String ns, String value, boolean create) { + boolean rv = false; + if(nses==null) { + if(prev!=null)rv = prev.hasPrinted(ns, value, false); + } else { + String v = nses.get(ns); + return value.equals(v); // note: accomodates not finding NS as well + } + + if(create && !rv) { + if(nses == null) nses = new HashMap(); + nses.put(ns, value); + } + return rv; + } + + + + } + + private boolean tag(Writer fore, Writer aft, boolean pretty, boolean returns, String tag, String data) throws IOException { + fore.append('<'); + fore.append(tag); + if(data!=null) { + fore.append('>'); // if no data, it may need some attributes... + fore.append(data); + if(returns)fore.append('\n'); + } + aft.append(""); + if(pretty)aft.append('\n'); + return data==null; + } + + private void attrib(Writer fore, boolean pretty, String tag, String value, Level level) throws IOException { + String realTag = tag.startsWith("__")?tag.substring(2):tag; // remove __ + if(realTag.equals(Parsed.EXTENSION_TAG)) { // Convert Derived name into XML defined Inheritance + fore.append(" xsi:type=\""); + fore.append(value); + fore.append('"'); + if(!level.hasPrinted(XMLNS_XSI, XML_SCHEMA_INSTANCE,true)) { + fore.append(' '); + fore.append(XMLNS_XSI); + fore.append("=\""); + fore.append(XML_SCHEMA_INSTANCE); + fore.append("\""); + } + } else { + if(realTag.startsWith("xmlns:") ) { + if(level.hasPrinted(realTag, value, true)) { + return; + } + } + fore.append(' '); + fore.append(realTag); + fore.append("=\""); + fore.append(value); + fore.append('"'); + } + } + + @Override + public String logName() { + return "Rosetta XML"; + } + + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/Parse.java b/rosetta/src/main/java/org/onap/aaf/rosetta/Parse.java new file mode 100644 index 0000000..175c162 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/Parse.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta; + +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.TimeTaken; + +public interface Parse { + public Parsed parse(IN in, Parsed parsed) throws ParseException; + + // EVENTS + public static final char NONE = 0; + public static final char START_DOC = 1; + public static final char END_DOC = 2; + public static final char ATTRIB = 3; + + public static final char NEXT = ','; + public static final char START_OBJ = '{'; + public static final char END_OBJ = '}'; + public static final char START_ARRAY = '['; + public static final char END_ARRAY = ']'; + + public Parsed newParsed() throws ParseException; + public TimeTaken start(Env env); + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/ParseException.java b/rosetta/src/main/java/org/onap/aaf/rosetta/ParseException.java new file mode 100644 index 0000000..61f96c4 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/ParseException.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta; + +public class ParseException extends Exception { + private static final long serialVersionUID = 7808836939102997012L; + + public ParseException() { + } + + public ParseException(String message) { + super(message); + } + + public ParseException(Throwable cause) { + super(cause); + } + + public ParseException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/Parsed.java b/rosetta/src/main/java/org/onap/aaf/rosetta/Parsed.java new file mode 100644 index 0000000..ef748a3 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/Parsed.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta; + + +public class Parsed { + public static final String EXTENSION_TAG="extension"; + + public boolean isString; + + public StringBuilder sb; + public char event; + public String name; + public S state; + + public Parsed() { + this(null); + } + + // Package on purpose + Parsed(S theState) { + sb = new StringBuilder(); + isString = false; + event = Parse.NONE; + name = ""; + state = theState; + } + + public boolean valid() { + return event!=Parse.NONE; + } + + public Parsed reuse() { + isString=false; + sb.setLength(0); + event = Parse.NONE; + name = ""; + // don't touch T... + return this; + } + + public void dataIsName() { + name = sb.toString(); + sb.setLength(0); + } + + public boolean hasName() { + return name.length()>0; + } + + public boolean hasData() { + return sb.length()>0; + } + + public String toString() { + StringBuilder sb2 = new StringBuilder(); + if(event<40)sb2.append((int)event); + else sb2.append(event); + sb2.append(" - "); + sb2.append(name); + if(sb.length()>0) { + sb2.append(" : "); + if(isString)sb2.append('"'); + sb2.append(sb); + if(isString)sb2.append('"'); + } + return sb2.toString(); + } + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/Prop.java b/rosetta/src/main/java/org/onap/aaf/rosetta/Prop.java new file mode 100644 index 0000000..dda725a --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/Prop.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta; + +class Prop { + public String tag; + public String value; + public Prop(String t, String v) { + tag = t; + value =v; + } + + public Prop(String t_equals_v) { + String[] tv = t_equals_v.split("="); + if(tv.length>1) { + tag = tv[0]; + value = tv[1]; + } + } + + public String toString() { + return tag + '=' + value; + } +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/Saved.java b/rosetta/src/main/java/org/onap/aaf/rosetta/Saved.java new file mode 100644 index 0000000..ae2797e --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/Saved.java @@ -0,0 +1,194 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.util.List; + +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.TimeTaken; +import org.onap.aaf.rosetta.Saved.State; + +/** + * An Out Object that will save off produced Parsed Stream and + * a Parse (In) Object that will reproduce Parsed Stream on demand + * + * + */ +public class Saved extends Out implements Parse{ + private static final String ROSETTA_SAVED = "Rosetta Saved"; + private final static int INIT_SIZE=128; + private Content content[]; + private int idx; + private boolean append = false; + + /** + * Read from Parsed Stream and save + */ + // @Override + public void extract(IN in, Writer ignore, Parse parser, boolean ... options) throws IOException, ParseException { + Parsed p = parser.newParsed(); + if(!append) { + // reuse array if not too big + if(content==null||content.length>INIT_SIZE*3) { + content = new Content[INIT_SIZE]; + idx = -1; + } else do { + content[idx]=null; + } while(--idx>=0); + } + + // Note: idx needs to be -1 on initialization and no appendages + while((p = parser.parse(in,p.reuse())).valid()) { + if(!(append && (p.event==START_DOC || p.event==END_DOC))) { // skip any start/end of document in appendages + if(++idx>=content.length) { + Content temp[] = new Content[content.length*2]; + System.arraycopy(content, 0, temp, 0, idx); + content = temp; + } + content[idx]= new Content(p); + } + } + } + + // @Override + public Parsed parse(Reader ignore, Parsed parsed) throws ParseException { + int i; + if((i=parsed.state.count++)<=idx) + content[i].load(parsed); + else + parsed.event = Parse.NONE; + return parsed; + } + + public Content[] cut(char event, int count) { + append = true; + for(int i=idx;i>=0;--i) { + if(content[i].event==event) count--; + if(count==0) { + Content[] appended = new Content[idx-i+1]; + System.arraycopy(content, i, appended, 0, appended.length); + idx = i-1; + return appended; + } + } + return new Content[0]; + } + + public void paste(Content[] appended) { + if(appended!=null) { + if(idx+appended.length>content.length) { + Content temp[] = new Content[content.length*2]; + System.arraycopy(content, 0, temp, 0, idx); + content = temp; + } + System.arraycopy(appended,0,content,idx+1,appended.length); + idx+=appended.length; + } + this.append = false; + } + + public static class State { + public int count = 0; + } + + public static class Content { + private boolean isString; + private char event; + private String name; + private List props; + private String str; + + public Content(Parsed p) { + isString = p.isString; + event = p.event; + name = p.name; + // avoid copying, because most elements don't have content + // Cannot set to "equals", because sb ends up being cleared (and reused) + str = p.sb.length()==0?null:p.sb.toString(); + } + + public void load(Parsed p) { + p.isString = isString; + p.event = event; + p.name = name; + if(str!=null) + p.sb.append(str); + } + + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(event); + sb.append(" - "); + sb.append(name); + sb.append(": "); + if(isString)sb.append('"'); + sb.append(str); + if(isString)sb.append('"'); + sb.append(' '); + if(props!=null) { + boolean comma = false; + for(Prop prop : props) { + if(comma)sb.append(','); + else comma = true; + sb.append(prop.tag); + sb.append('='); + sb.append(prop.value); + } + } + return sb.toString(); + } + } + + //// @Override + public Parsed newParsed() { + Parsed ps = new Parsed(new State()); + return ps; + } + + /** + * Convenience function + * @param rdr + * @param in + * @throws IOException + * @throws ParseException + */ + public void load(IN in, Parse parser) throws IOException, ParseException { + extract(in,(Writer)null, parser); + } + + + // @Override + public TimeTaken start(Env env) { + return env.start(ROSETTA_SAVED, 0); + } + + @Override + public String logName() { + return ROSETTA_SAVED; + } + + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/XmlEscape.java b/rosetta/src/main/java/org/onap/aaf/rosetta/XmlEscape.java new file mode 100644 index 0000000..8ada632 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/XmlEscape.java @@ -0,0 +1,372 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta; + +import java.io.IOException; +import java.io.Reader; +import java.util.Map.Entry; +import java.util.TreeMap; + +public class XmlEscape { + private XmlEscape() {} + + private static final TreeMap charMap; // see initialization at end + private static final TreeMap intMap; // see initialization at end + + public static void xmlEscape(StringBuilder sb, Reader r) throws ParseException { + try { + int c; + StringBuilder esc = new StringBuilder(); + for(int cnt = 0;cnt<9 /*max*/; ++cnt) { + if((c=r.read())<0)throw new ParseException("Invalid Data: Unfinished Escape Sequence"); + if(c!=';') { + esc.append((char)c); + } else { // evaluate + Integer i = charMap.get(esc.toString()); + if(i==null) { + // leave in nasty XML format for now. + sb.append('&'); + sb.append(esc); + sb.append(';'); + } else { + sb.append((char)i.intValue()); + } + break; + } + } + + + } catch (IOException e) { + throw new ParseException(e); + } + } + + public static void xmlEscape(StringBuilder sb, int chr) { + sb.append('&'); + sb.append(intMap.get(chr)); + sb.append(';'); + } + + public static String convert(StringBuilder insb) { + int idx, ch; + StringBuilder sb=null; + for(idx=0;idx=160 || ch==34 || ch==38 || ch==39 || ch==60 || ch==62) { + sb = new StringBuilder(); + sb.append(insb,0,idx); + break; + } + } + + if(sb==null)return insb.toString(); + + for(int i=idx;i(); + intMap = new TreeMap(); + charMap.put("quot", 34); + charMap.put("amp",38); + charMap.put("apos",39); + charMap.put("lt",60); + charMap.put("gt",62); + charMap.put("nbsp",160); + charMap.put("iexcl",161); + charMap.put("cent",162); + charMap.put("pound",163); + charMap.put("curren",164); + charMap.put("yen",165); + charMap.put("brvbar",166); + charMap.put("sect",167); + charMap.put("uml",168); + charMap.put("copy",169); + charMap.put("ordf",170); + charMap.put("laquo",171); + charMap.put("not",172); + charMap.put("shy",173); + charMap.put("reg",174); + charMap.put("macr",175); + charMap.put("deg",176); + charMap.put("plusmn",177); + charMap.put("sup2",178); + charMap.put("sup3",179); + charMap.put("acute",180); + charMap.put("micro",181); + charMap.put("para",182); + charMap.put("middot",183); + charMap.put("cedil",184); + charMap.put("sup1",185); + charMap.put("ordm",186); + charMap.put("raquo",187); + charMap.put("frac14",188); + charMap.put("frac12",189); + charMap.put("frac34",190); + charMap.put("iquest",191); + charMap.put("Agrave",192); + charMap.put("Aacute",193); + charMap.put("Acirc",194); + charMap.put("Atilde",195); + charMap.put("Auml",196); + charMap.put("Aring",197); + charMap.put("AElig",198); + charMap.put("Ccedil",199); + charMap.put("Egrave",200); + charMap.put("Eacute",201); + charMap.put("Ecirc",202); + charMap.put("Euml",203); + charMap.put("Igrave",204); + charMap.put("Iacute",205); + charMap.put("Icirc",206); + charMap.put("Iuml",207); + charMap.put("ETH",208); + charMap.put("Ntilde",209); + charMap.put("Ograve",210); + charMap.put("Oacute",211); + charMap.put("Ocirc",212); + charMap.put("Otilde",213); + charMap.put("Ouml",214); + charMap.put("times",215); + charMap.put("Oslash",216); + charMap.put("Ugrave",217); + charMap.put("Uacute",218); + charMap.put("Ucirc",219); + charMap.put("Uuml",220); + charMap.put("Yacute",221); + charMap.put("THORN",222); + charMap.put("szlig",223); + charMap.put("agrave",224); + charMap.put("aacute",225); + charMap.put("acirc",226); + charMap.put("atilde",227); + charMap.put("auml",228); + charMap.put("aring",229); + charMap.put("aelig",230); + charMap.put("ccedil",231); + charMap.put("egrave",232); + charMap.put("eacute",233); + charMap.put("ecirc",234); + charMap.put("euml",235); + charMap.put("igrave",236); + charMap.put("iacute",237); + charMap.put("icirc",238); + charMap.put("iuml",239); + charMap.put("eth",240); + charMap.put("ntilde",241); + charMap.put("ograve",242); + charMap.put("oacute",243); + charMap.put("ocirc",244); + charMap.put("otilde",245); + charMap.put("ouml",246); + charMap.put("divide",247); + charMap.put("oslash",248); + charMap.put("ugrave",249); + charMap.put("uacute",250); + charMap.put("ucirc",251); + charMap.put("uuml",252); + charMap.put("yacute",253); + charMap.put("thorn",254); + charMap.put("yuml",255); + charMap.put("OElig",338); + charMap.put("oelig",339); + charMap.put("Scaron",352); + charMap.put("scaron",353); + charMap.put("Yuml",376); + charMap.put("fnof",402); + charMap.put("circ",710); + charMap.put("tilde",732); + charMap.put("Alpha",913); + charMap.put("Beta",914); + charMap.put("Gamma",915); + charMap.put("Delta",916); + charMap.put("Epsilon",917); + charMap.put("Zeta",918); + charMap.put("Eta",919); + charMap.put("Theta",920); + charMap.put("Iota",921); + charMap.put("Kappa",922); + charMap.put("Lambda",923); + charMap.put("Mu",924); + charMap.put("Nu",925); + charMap.put("Xi",926); + charMap.put("Omicron",927); + charMap.put("Pi",928); + charMap.put("Rho",929); + charMap.put("Sigma",931); + charMap.put("Tau",932); + charMap.put("Upsilon",933); + charMap.put("Phi",934); + charMap.put("Chi",935); + charMap.put("Psi",936); + charMap.put("Omega",937); + charMap.put("alpha",945); + charMap.put("beta",946); + charMap.put("gamma",947); + charMap.put("delta",948); + charMap.put("epsilon",949); + charMap.put("zeta",950); + charMap.put("eta",951); + charMap.put("theta",952); + charMap.put("iota",953); + charMap.put("kappa",954); + charMap.put("lambda",955); + charMap.put("mu",956); + charMap.put("nu",957); + charMap.put("xi",958); + charMap.put("omicron",959); + charMap.put("pi",960); + charMap.put("rho",961); + charMap.put("sigmaf",962); + charMap.put("sigma",963); + charMap.put("tau",964); + charMap.put("upsilon",965); + charMap.put("phi",966); + charMap.put("chi",967); + charMap.put("psi",968); + charMap.put("omega",969); + charMap.put("thetasym",977); + charMap.put("upsih",978); + charMap.put("piv",982); + charMap.put("ensp",8194); + charMap.put("emsp",8195); + charMap.put("thinsp",8201); + charMap.put("zwnj",8204); + charMap.put("zwj",8205); + charMap.put("lrm",8206); + charMap.put("rlm",8207); + charMap.put("ndash",8211); + charMap.put("mdash",8212); + charMap.put("lsquo",8216); + charMap.put("rsquo",8217); + charMap.put("sbquo",8218); + charMap.put("ldquo",8220); + charMap.put("rdquo",8221); + charMap.put("bdquo",8222); + charMap.put("dagger",8224); + charMap.put("Dagger",8225); + charMap.put("bull",8226); + charMap.put("hellip",8230); + charMap.put("permil",8240); + charMap.put("prime",8242); + charMap.put("Prime",8243); + charMap.put("lsaquo",8249); + charMap.put("rsaquo",8250); + charMap.put("oline",8254); + charMap.put("frasl",8260); + charMap.put("euro",8364); + charMap.put("image",8465); + charMap.put("weierp",8472); + charMap.put("real",8476); + charMap.put("trade",8482); + charMap.put("alefsym",8501); + charMap.put("larr",8592); + charMap.put("uarr",8593); + charMap.put("rarr",8594); + charMap.put("darr",8595); + charMap.put("harr",8596); + charMap.put("crarr",8629); + charMap.put("lArr",8656); + charMap.put("uArr",8657); + charMap.put("rArr",8658); + charMap.put("dArr",8659); + charMap.put("hArr",8660); + charMap.put("forall",8704); + charMap.put("part",8706); + charMap.put("exist",8707); + charMap.put("empty",8709); + charMap.put("nabla",8711); + charMap.put("isin",8712); + charMap.put("notin",8713); + charMap.put("ni",8715); + charMap.put("prod",8719); + charMap.put("sum",8721); + charMap.put("minus",8722); + charMap.put("lowast",8727); + charMap.put("radic",8730); + charMap.put("prop",8733); + charMap.put("infin",8734); + charMap.put("ang",8736); + charMap.put("and",8743); + charMap.put("or",8744); + charMap.put("cap",8745); + charMap.put("cup",8746); + charMap.put("int",8747); + charMap.put("there4",8756); + charMap.put("sim",8764); + charMap.put("cong",8773); + charMap.put("asymp",8776); + charMap.put("ne",8800); + charMap.put("equiv",8801); + charMap.put("le",8804); + charMap.put("ge",8805); + charMap.put("sub",8834); + charMap.put("sup",8835); + charMap.put("nsub",8836); + charMap.put("sube",8838); + charMap.put("supe",8839); + charMap.put("oplus",8853); + charMap.put("otimes",8855); + charMap.put("perp",8869); + charMap.put("sdot",8901); + charMap.put("lceil",8968); + charMap.put("rceil",8969); + charMap.put("lfloor",8970); + charMap.put("rfloor",8971); + charMap.put("lang",9001); + charMap.put("rang",9002); + charMap.put("loz",9674); + charMap.put("spades",9824); + charMap.put("clubs",9827); + charMap.put("hearts",9829); + charMap.put("diams",9830); + + for( Entry es: charMap.entrySet()) { + if(es.getValue()>=160); // save small space... note that no longer has amp, etc. + intMap.put(es.getValue(), es.getKey()); + } + } + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/env/RosettaDF.java b/rosetta/src/main/java/org/onap/aaf/rosetta/env/RosettaDF.java new file mode 100644 index 0000000..4005e81 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/env/RosettaDF.java @@ -0,0 +1,266 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta.env; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; + +import javax.xml.bind.JAXBException; +import javax.xml.namespace.QName; +import javax.xml.validation.Schema; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.BaseDataFactory; +import org.onap.aaf.inno.env.Data; +import org.onap.aaf.inno.env.DataFactory; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.TimeTaken; +import org.onap.aaf.inno.env.Trans; +import org.onap.aaf.inno.env.Data.TYPE; +import org.onap.aaf.inno.env.jaxb.JAXBmar; +import org.onap.aaf.inno.env.jaxb.JAXBumar; +import org.onap.aaf.rosetta.InJson; +import org.onap.aaf.rosetta.InXML; +import org.onap.aaf.rosetta.JaxInfo; +import org.onap.aaf.rosetta.Marshal; +import org.onap.aaf.rosetta.Out; +import org.onap.aaf.rosetta.OutJson; +import org.onap.aaf.rosetta.OutRaw; +import org.onap.aaf.rosetta.OutXML; +import org.onap.aaf.rosetta.Parse; +import org.onap.aaf.rosetta.ParseException; +import org.onap.aaf.rosetta.marshal.DocMarshal; + +public class RosettaDF extends BaseDataFactory implements DataFactory { + + static InJson inJSON = new InJson(); + InXML inXML; + + static OutJson outJSON = new OutJson(); + OutXML outXML; + static OutRaw outRAW = new OutRaw(); + + // Temporary until we write JAXB impl... + JAXBmar jaxMar; + JAXBumar jaxUmar; + + private Parse defaultIn; + private Out defaultOut; + private RosettaEnv env; + private TYPE inType; + private TYPE outType; + private int defOption; + Marshal marshal = null; + + + /** + * Private constructor to setup Type specific data manipulators + * @param schema + * @param rootNs + * @param cls + * @throws SecurityException + * @throws NoSuchFieldException + * @throws ClassNotFoundException + * @throws ParseException + * @throws JAXBException + */ + // package on purpose + RosettaDF(RosettaEnv env, Schema schema, String rootNs, Class cls) throws APIException { + this.env = env; + try { + // Note: rootNs can be null, in order to derive content from Class. + JaxInfo ji = rootNs==null?JaxInfo.build(cls):JaxInfo.build(cls,rootNs); + // Note: JAXBmar sets qname to null if not exists + jaxMar = new JAXBmar(rootNs==null?null:new QName("xmlns",rootNs),cls); + // Note: JAXBumar sets schema to null if not exists + jaxUmar = new JAXBumar(schema, cls); + + defaultIn = inXML = new InXML(ji); + defaultOut = outXML = new OutXML(ji); + inType=outType=Data.TYPE.XML; + defOption = 0; + } catch (Exception e) { + throw new APIException(e); + } + } + + + // @Override + public RosettaData newData() { + RosettaData data = new RosettaData(env, this) + .in(inType) + .out(outType) + .option(defOption); + return data; + } + + // @Override + public RosettaData newData(Env trans) { + RosettaData data = new RosettaData(trans, this) + .in(inType) + .out(outType) + .option(defOption); + return data; + } + + @SuppressWarnings("unchecked") + // @Override + public Class getTypeClass() { + return (Class)jaxMar.getMarshalClass(); + } + + public RosettaDF in(Data.TYPE type) { + inType = type; + defaultIn=getIn(type==Data.TYPE.DEFAULT?Data.TYPE.JSON:type); + return this; + } + + /** + * If exists, first option is "Pretty", second is "Fragment" + * + * @param options + * @return + */ + public RosettaDF out(Data.TYPE type) { + outType = type; + defaultOut = getOut(type==Data.TYPE.DEFAULT?Data.TYPE.JSON:type); + return this; + } + + public Parse getIn(Data.TYPE type) { + switch(type) { + case DEFAULT: + return defaultIn; + case JSON: + return inJSON; + case XML: + return inXML; + default: + return defaultIn; + } + } + + public Out getOut(Data.TYPE type) { + switch(type) { + case DEFAULT: + return defaultOut; + case JSON: + return outJSON; + case XML: + return outXML; + case RAW: + return outRAW; + default: + return defaultOut; + } + } + + public int logType(org.onap.aaf.inno.env.Data.TYPE ot) { + switch(ot) { + case JSON: + return Env.JSON; + default: + return Env.XML; + } + } + + + public RosettaEnv getEnv() { + return env; + } + + + public Data.TYPE getInType() { + return inType; + } + + public Data.TYPE getOutType() { + return outType; + } + + public RosettaDF option(int option) { + defOption = option; + + return this; + } + + /** + * Assigning Root Marshal Object + * + * Will wrap with DocMarshal Object if not already + * + * @param marshal + * @return + */ + public RosettaDF rootMarshal(Marshal marshal) { + if(marshal instanceof DocMarshal) { + this.marshal = marshal; + } else { + this.marshal = DocMarshal.root(marshal); + } + return this; + } + + public void direct(Trans trans, T t, OutputStream os, boolean ... options) throws APIException, IOException { + Out out = getOut(outType); + TimeTaken tt = trans.start(out.logName(),logType(outType)); // determine from Out.. without dependency on Env? + try { + if(marshal==null) { // Unknown marshaller... do working XML marshal/extraction + StringWriter sw = new StringWriter(); + jaxMar.marshal(trans.debug(), t, sw, options); + out.extract(new StringReader(sw.toString()), new OutputStreamWriter(os), inXML,options); + } else { + out.extract(t, new OutputStreamWriter(os), marshal,options); + } + } catch (Exception e) { + throw new APIException(e); + } finally { + tt.done(); + } + } + + public void direct(Trans trans, T t, Writer writer, boolean ... options) throws APIException, IOException { + Out out = getOut(outType); + TimeTaken tt = trans.start(out.logName(),logType(outType)); // determine from Out.. without dependency on Env? + try { + if(marshal==null) { // Unknown marshaller... do working XML marshal/extraction + StringWriter sw = new StringWriter(); + jaxMar.marshal(trans.debug(), t, sw, options); + out.extract(new StringReader(sw.toString()), writer, inXML,options); + } else { + out.extract(t, writer, marshal,options); + } + } catch (Exception e) { + throw new APIException(e); + } finally { + tt.done(); + } + } + + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/env/RosettaData.java b/rosetta/src/main/java/org/onap/aaf/rosetta/env/RosettaData.java new file mode 100644 index 0000000..55c4b29 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/env/RosettaData.java @@ -0,0 +1,313 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta.env; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.Data; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.TimeTaken; +import org.onap.aaf.rosetta.Out; +import org.onap.aaf.rosetta.Parse; +import org.onap.aaf.rosetta.Saved; + +public class RosettaData implements Data{ + private Env trans; + private RosettaDF df; + private Saved saved; + private TYPE inType, outType; + // Note: This is an array of boolean in order to pass into other methods + private boolean options[] = new boolean[] {false, false}; + // Temp Storage of XML. Only when we must use JAXB to read in Objects + private String xml,json; + + // package on purpose + RosettaData(Env env, RosettaDF rosettaDF) { + df = rosettaDF; + saved = new Saved(); // Note: Saved constructs storage as needed... + trans = env; + inType = df.getInType(); + outType = df.getOutType(); // take defaults + } + +// // @Override + public RosettaData in(TYPE rosettaType) { + inType = rosettaType; + return this; + } + +// // @Override + public RosettaData out(TYPE rosettaType) { + outType = rosettaType; + return this; + } + +// // @Override + public RosettaData load(Reader rdr) throws APIException { + Parse in = df.getIn(inType); + TimeTaken tt = in.start(trans); + try { + saved.extract(rdr, (Writer)null, in); + xml=json=null; + } catch (Exception e) { + throw new APIException(e); + } finally { + tt.done(); + } + return this; + } + + // @Override + public RosettaData load(InputStream is) throws APIException { + Parse in = df.getIn(inType); + TimeTaken tt = in.start(trans); + try { + saved.extract(new InputStreamReader(is), (Writer)null, in); + xml=json=null; + } catch (Exception e) { + throw new APIException(e); + } finally { + tt.done(); + } + return this; + } + + // @Override + public RosettaData load(String str) throws APIException { + Parse in = df.getIn(inType); + TimeTaken tt = in.start(trans); + try { + saved.extract(new StringReader(str), (Writer)null, in); + switch(inType) { + case XML: + xml = str; + break; + case JSON: + json = str; + break; + default: + + } + } catch (Exception e) { + throw new APIException(e); + } finally { + tt.done(); + } + return this; + } + + // @Override + public RosettaData load(T t) throws APIException { + Parse in = df.getIn(inType); + TimeTaken tt = in.start(trans); + try { + if(df.marshal==null) { // Unknown marshaller... do working XML marshal/extraction + StringWriter sw = new StringWriter(); + df.jaxMar.marshal(trans.debug(), t, sw, options); + saved.extract(new StringReader(xml = sw.toString()), (Writer)null, df.inXML); + } else { + saved.extract(t, (Writer)null, df.marshal); + } + } catch (Exception e) { + throw new APIException(e); + } finally { + tt.done(); + } + return this; + } + + public Saved getEvents() { + return saved; + } + + // @Override + public T asObject() throws APIException { + Out out = df.getOut(TYPE.XML); + TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? + try { + //TODO Replace JAXB with Direct Object method!!! + StringWriter sw = new StringWriter(); + out.extract(null, sw, saved); + return df.jaxUmar.unmarshal(trans.debug(), sw.toString()); + } catch (Exception e) { + throw new APIException(e); + } finally { + tt.done(); + } + } + + // @Override + public String asString() throws APIException { + Out out = df.getOut(outType); + TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? + try { + if(outType==TYPE.XML) { + if(xml==null) { + StringWriter sw = new StringWriter(); + out.extract(null, sw, saved, options); + xml = sw.toString(); + } + return xml; + } else { // is JSON + if(json==null) { + StringWriter sw = new StringWriter(); + out.extract(null, sw, saved, options); + json = sw.toString(); + } + return json; + } + } catch (Exception e) { + throw new APIException(e); + } finally { + tt.done(); + } + } + + + // @Override + public RosettaData to(OutputStream os) throws APIException, IOException { + Out out = df.getOut(outType); + TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? + try { + if(outType==TYPE.XML && xml!=null) { + os.write(xml.getBytes()); + } else if(outType==TYPE.JSON && json!=null) { + os.write(json.getBytes()); + } else { + out.extract(null, os, saved, options); + } + } catch (Exception e) { + throw new APIException(e); + } finally { + tt.done(); + } + return this; + } + + // @Override + public RosettaData to(Writer writer) throws APIException, IOException { + Out out = df.getOut(outType); + TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? + try { + if(outType==TYPE.XML && xml!=null) { + writer.append(xml); + } else if(outType==TYPE.JSON && json!=null) { + writer.append(json); + } else { + out.extract(null, writer, saved, options); + } + } catch (Exception e) { + throw new APIException(e); + } finally { + tt.done(); + } + return this; + } + + // @Override + public Class getTypeClass() { + return df.getTypeClass(); + } + + private static final boolean[] emptyOption = new boolean[0]; + + public void direct(InputStream is, OutputStream os) throws APIException, IOException { + direct(is,os,emptyOption); + } + + public void direct(Reader reader, Writer writer, boolean ... options) throws APIException, IOException { + Parse in = df.getIn(inType); + Out out = df.getOut(outType); + TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? + try { + out.extract(reader, writer, in,options); + } catch (Exception e) { + throw new APIException(e); + } finally { + tt.done(); + } + } + + public void direct(T t, Writer writer, boolean ... options) throws APIException, IOException { + Out out = df.getOut(outType); + TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? + try { + if(df.marshal==null) { // Unknown marshaller... do working XML marshal/extraction + StringWriter sw = new StringWriter(); + df.jaxMar.marshal(trans.debug(), t, sw, options); + out.extract(new StringReader(xml = sw.toString()), writer, df.inXML,options); + } else { + out.extract(t, writer, df.marshal,options); + } + } catch (Exception e) { + throw new APIException(e); + } finally { + tt.done(); + } + } + + public void direct(T t, OutputStream os, boolean ... options) throws APIException, IOException { + Out out = df.getOut(outType); + TimeTaken tt = trans.start(out.logName(),df.logType(outType)); // determine from Out.. without dependency on Env? + try { + if(df.marshal==null) { // Unknown marshaller... do working XML marshal/extraction + if(outType.equals(TYPE.XML)) { + df.jaxMar.marshal(trans.debug(), t, os, options); + } else { + StringWriter sw = new StringWriter(); + df.jaxMar.marshal(trans.debug(), t, sw, options); + out.extract(new StringReader(xml = sw.toString()), new OutputStreamWriter(os), df.inXML,options); + } + } else { + out.extract(t, new OutputStreamWriter(os), df.marshal,options); + } + + } catch (Exception e) { + throw new APIException(e); + } finally { + tt.done(); + } + } + + + public void direct(InputStream is, OutputStream os, boolean ... options) throws APIException, IOException { + direct(new InputStreamReader(is),new OutputStreamWriter(os), options); + } + + // // @Override + public RosettaData option(int option) { + options[0] = (option&Data.PRETTY)==Data.PRETTY; + options[1] = (option&Data.FRAGMENT)==Data.FRAGMENT; + return this; + } + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/env/RosettaEnv.java b/rosetta/src/main/java/org/onap/aaf/rosetta/env/RosettaEnv.java new file mode 100644 index 0000000..8138d47 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/env/RosettaEnv.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta.env; + +import java.applet.Applet; +import java.util.Properties; + +import javax.xml.namespace.QName; +import javax.xml.validation.Schema; + +import org.onap.aaf.inno.env.APIException; + +/** + * An essential Implementation of Env, which will fully function, without any sort + * of configuration. + * + * Use as a basis for Group level Env, just overriding where needed. + * + */ +public class RosettaEnv extends org.onap.aaf.inno.env.impl.BasicEnv { + + public RosettaEnv() { + super(); + } + + public RosettaEnv(Applet applet, String... tags) { + super(applet, tags); + } + + public RosettaEnv(String[] args) { + super(args); + } + + public RosettaEnv(String tag, String[] args) { + super(tag, args); + } + + public RosettaEnv(String tag, Properties props) { + super(tag, props); + } + + public RosettaEnv(Properties props) { + super(props); + } + + @SuppressWarnings("unchecked") + @Override + public RosettaDF newDataFactory(Class... classes) throws APIException { + return new RosettaDF(this, null, null, (Class)classes[0]); + } + + @SuppressWarnings("unchecked") + @Override + public RosettaDF newDataFactory(Schema schema, Class... classes) throws APIException { + return new RosettaDF(this, schema, null, (Class)classes[0]); + } + + @SuppressWarnings("unchecked") + @Override + public RosettaDF newDataFactory(QName qName, Class ... classes) throws APIException { + return new RosettaDF(this, null, qName.getNamespaceURI(),(Class)classes[0]); + } + + @SuppressWarnings("unchecked") + @Override + public RosettaDF newDataFactory(Schema schema, QName qName, Class ... classes) throws APIException { + return new RosettaDF(this, schema,qName.getNamespaceURI(),(Class)classes[0]); + } +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/DataWriter.java b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/DataWriter.java new file mode 100644 index 0000000..14a1e24 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/DataWriter.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta.marshal; + +import javax.xml.datatype.XMLGregorianCalendar; + +import org.onap.aaf.inno.env.util.Chrono; + +/** + * We make these objects instead of static functions so they can be passed into + * FieldArray. + * + * + * @param + */ +public abstract class DataWriter { + public abstract boolean write(T t, StringBuilder sb); + + public final static DataWriter STRING = new DataWriter() { + @Override + public boolean write(String s, StringBuilder sb) { + sb.append(s); + return true; + } + }; + + public final static DataWriter INTEGER = new DataWriter() { + @Override + public boolean write(Integer i, StringBuilder sb) { + sb.append(i); + return false; + } + }; + + public final static DataWriter LONG = new DataWriter() { + @Override + public boolean write(Long t, StringBuilder sb) { + sb.append(t); + return false; + } + }; + + public final static DataWriter BYTE = new DataWriter() { + @Override + public boolean write(Byte t, StringBuilder sb) { + sb.append(t); + return false; + } + }; + + public final static DataWriter CHAR = new DataWriter() { + @Override + public boolean write(Character t, StringBuilder sb) { + sb.append(t); + return true; + } + }; + + public final static DataWriter BOOL = new DataWriter() { + @Override + public boolean write(Boolean t, StringBuilder sb) { + sb.append(t); + return true; + } + }; + + + /* + public final static DataWriter BYTE_ARRAY = new DataWriter() { + @Override + public boolean write(byte[] ba, StringBuilder sb) { + ByteArrayInputStream bais = new ByteArrayInputStream(ba); + StringBuilderOutputStream sbos = new StringBuilderOutputStream(sb); +// try { + //TODO find Base64 +// Symm.base64noSplit().encode(bais, sbos); +// } catch (IOException e) { +// // leave blank +// } + return true; + } + + }; + */ + + public final static DataWriter DATE = new DataWriter() { + @Override + public boolean write(XMLGregorianCalendar t, StringBuilder sb) { + sb.append(Chrono.dateOnlyStamp(t)); + return true; + } + }; + + public final static DataWriter DATE_TIME = new DataWriter() { + @Override + public boolean write(XMLGregorianCalendar t, StringBuilder sb) { + sb.append(Chrono.dateTime(t)); + return true; + } + }; + + private static final char[] chars="0123456789ABCDEF".toCharArray(); + public final static DataWriter HEX_BINARY = new DataWriter() { + @Override + public boolean write(byte[] ba, StringBuilder sb) { + // FYI, doing this because don't want intermediate + // String in "HexString" or the processing in + // "String.format" + //sb.append("0x"); + for(int i=0;i>4)]); + sb.append(chars[b&0xF]); + } + return true; + } + }; + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/DocMarshal.java b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/DocMarshal.java new file mode 100644 index 0000000..47ee596 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/DocMarshal.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta.marshal; + +import java.util.Iterator; + +import org.onap.aaf.rosetta.Ladder; +import org.onap.aaf.rosetta.Marshal; +import org.onap.aaf.rosetta.ParseException; +import org.onap.aaf.rosetta.Parsed; + +public class DocMarshal extends Marshal { + private Marshal root; + + public DocMarshal(Marshal root) { + this.root = root; + } + + @Override + public Parsed parse(T t, Parsed parsed) throws ParseException { + Ladder> ladder = parsed.state.ladder; + Iterator iter = ladder.peek(); + if(iter==null) { + ladder.push(PENDING_ITERATOR); + parsed.event = START_DOC; + } else if (DONE_ITERATOR.equals(iter)) { + } else { + ladder.ascend(); // look at field info + Iterator currFieldIter = ladder.peek(); + if(!DONE_ITERATOR.equals(currFieldIter)){ + parsed = root.parse(t, parsed); + } + ladder.descend(); + if(DONE_ITERATOR.equals(currFieldIter) || parsed.event==NONE) { + parsed.event = END_DOC; + ladder.push(DONE_ITERATOR); + } + } + return parsed; // if unchanged, then it will end process + + } + + public static final Iterator PENDING_ITERATOR = new Iterator() { + @Override + public boolean hasNext() { + return false; + } + + @Override + public Void next() { + return null; + } + + @Override + public void remove() { + } + }; + + public static DocMarshal root(Marshal m) { + return (DocMarshal)new DocMarshal(m); + } + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldArray.java b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldArray.java new file mode 100644 index 0000000..5683367 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldArray.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta.marshal; + +import java.util.Iterator; +import java.util.List; + +import org.onap.aaf.rosetta.Ladder; +import org.onap.aaf.rosetta.Marshal; +import org.onap.aaf.rosetta.ParseException; +import org.onap.aaf.rosetta.Parsed; + + +public abstract class FieldArray extends Marshal { + private DataWriter dataWriter; + private String name; + + public FieldArray(String name, DataWriter dw) { + this.name = name; + dataWriter = dw; + } + + @SuppressWarnings("unchecked") + @Override + public Parsed parse(T t, Parsed parsed) throws ParseException { + Ladder> ladder = parsed.state.ladder; + Iterator iter = ladder.peek(); + if(iter==null) { + List list = data(t); + if(list.isEmpty() && parsed.state.smallest) { + ladder.push(DONE_ITERATOR); + } else { + ladder.push(new ListIterator(list)); + parsed.event = START_ARRAY; + parsed.name = name; + } + } else if (DONE_ITERATOR.equals(iter)) { + } else { + ladder.ascend(); // look at field info + Iterator memIter = ladder.peek(); + ListIterator mems = (ListIterator)iter; + S mem; + if(memIter==null) { + mem=mems.next(); + } else if(!DONE_ITERATOR.equals(memIter)) { + mem=mems.peek(); + } else if(iter.hasNext()) { + mem=null; + ladder.push(null); + } else { + mem=null; + } + + if(mem!=null) { + parsed.isString=dataWriter.write(mem, parsed.sb); + parsed.event = NEXT; + } + ladder.descend(); + if(mem==null) { + if(iter.hasNext()) { + parsed.event = NEXT; + } else { + parsed.event = END_ARRAY; + ladder.push(DONE_ITERATOR); + } + } + } + return parsed; // if unchanged, then it will end process + } + + protected abstract List data(T t); + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldBlob.java b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldBlob.java new file mode 100644 index 0000000..f8275c9 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldBlob.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta.marshal; + +public abstract class FieldBlob extends FieldMarshal{ + public FieldBlob(String name) { + super(name); + } + + protected abstract byte[] data(T t); + + @Override + protected boolean data(T t, StringBuilder sb) { + return false; + // unimplemented + //return DataWriter.BYTE_ARRAY.write(data(t),sb); + } + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldDate.java b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldDate.java new file mode 100644 index 0000000..799cdb0 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldDate.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta.marshal; + +import javax.xml.datatype.XMLGregorianCalendar; + +public abstract class FieldDate extends FieldMarshal { + public FieldDate(String name) { + super(name); + } + + @Override + final protected boolean data(T t, StringBuilder sb) { + return DataWriter.DATE.write(data(t), sb); + } + + protected abstract XMLGregorianCalendar data(T t); +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldDateTime.java b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldDateTime.java new file mode 100644 index 0000000..bd64748 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldDateTime.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta.marshal; + +import javax.xml.datatype.XMLGregorianCalendar; + +public abstract class FieldDateTime extends FieldMarshal { + public FieldDateTime(String name) { + super(name); + } + + @Override + final protected boolean data(T t, StringBuilder sb) { + return DataWriter.DATE_TIME.write(data(t), sb); + } + + protected abstract XMLGregorianCalendar data(T t); +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldHexBinary.java b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldHexBinary.java new file mode 100644 index 0000000..c765625 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldHexBinary.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta.marshal; + +public abstract class FieldHexBinary extends FieldMarshal{ + public FieldHexBinary(String name) { + super(name); + } + + protected abstract byte[] data(T t); + + @Override + protected boolean data(T t, StringBuilder sb) { + return DataWriter.HEX_BINARY.write(data(t), sb); + } +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldMarshal.java b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldMarshal.java new file mode 100644 index 0000000..44d5aff --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldMarshal.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta.marshal; + + +import org.onap.aaf.rosetta.Marshal; +import org.onap.aaf.rosetta.Parse; +import org.onap.aaf.rosetta.Parsed; + +public abstract class FieldMarshal extends Marshal { + private String name; + + public FieldMarshal(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public Parsed parse(T t, Parsed parsed) { + parsed.state.ladder.push(DONE_ITERATOR); + parsed.event = Parse.NEXT; + parsed.name = name; + parsed.isString = data(t,parsed.sb); + return parsed; + } + + /** + * Write Value to StringBuilder + * Return true if value looks like a String + * false if it is Numeric + * @param t + * @param sb + * @return + */ + protected abstract boolean data(T t, StringBuilder sb); + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldNumeric.java b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldNumeric.java new file mode 100644 index 0000000..493cb8b --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldNumeric.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta.marshal; + +public abstract class FieldNumeric extends FieldMarshal { + public FieldNumeric(String name) { + super(name); + } + + @Override + final protected boolean data(T t, StringBuilder sb) { + sb.append(data(t)); + return false; + } + + protected abstract N data(T t); +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldString.java b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldString.java new file mode 100644 index 0000000..662e5da --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/FieldString.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta.marshal; + +public abstract class FieldString extends FieldMarshal { + public FieldString(String name) { + super(name); + } + + protected abstract String data(T t); + + @Override + final protected boolean data(T t, StringBuilder sb) { + return DataWriter.STRING.write(data(t), sb); + } + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/ListIterator.java b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/ListIterator.java new file mode 100644 index 0000000..204437c --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/ListIterator.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta.marshal; + +import java.util.Iterator; +import java.util.List; + +/** + * Need an Iterator that can peek the current value without changing + * + * @param + */ +final class ListIterator implements Iterator { + private T curr; + private Iterator delg; + public ListIterator(List list) { + curr = null; + delg = list.iterator(); + } + @Override + public boolean hasNext() { + return delg.hasNext(); + } + + @Override + public T next() { + return curr = delg.hasNext()?delg.next():null; + } + + public T peek() { + return curr==null?next():curr; + } + + @Override + public void remove() { + delg.remove(); + } + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/ObjArray.java b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/ObjArray.java new file mode 100644 index 0000000..e935887 --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/ObjArray.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta.marshal; + +import java.util.Iterator; +import java.util.List; + +import org.onap.aaf.rosetta.Ladder; +import org.onap.aaf.rosetta.Marshal; +import org.onap.aaf.rosetta.ParseException; +import org.onap.aaf.rosetta.Parsed; + + +public abstract class ObjArray extends Marshal { + private String name; + private Marshal subMarshaller; + + public ObjArray(String name, Marshal subMarshaller) { + this.name = name; + this.subMarshaller = subMarshaller; + } + + @SuppressWarnings("unchecked") + @Override + public Parsed parse(T t, Parsed parsed) throws ParseException { + Ladder> ladder = parsed.state.ladder; + Iterator iter = ladder.peek(); + if(iter==null) { + List list = data(t); + if(list.isEmpty() && parsed.state.smallest) { + ladder.push(DONE_ITERATOR); + } else { + ladder.push(new ListIterator(list)); + parsed.event = START_ARRAY; + parsed.name = name; + } + } else if (DONE_ITERATOR.equals(iter)) { + } else { + ladder.ascend(); // look at field info + Iterator memIter = ladder.peek(); + ListIterator mems = (ListIterator)iter; + S mem; + if(memIter==null) { + mem=mems.next(); + } else if(!DONE_ITERATOR.equals(memIter)) { + mem=mems.peek(); + } else if(iter.hasNext()) { + mem=null; + ladder.push(null); + } else { + mem=null; + } + + if(mem!=null) + parsed = subMarshaller.parse(mem, parsed); + ladder.descend(); + if(mem==null) { + if(iter.hasNext()) { + parsed.event = NEXT; + } else { + parsed.event = END_ARRAY; + ladder.push(DONE_ITERATOR); + } + } + } + return parsed; // if unchanged, then it will end process + } + + protected abstract List data(T t); + +} diff --git a/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/ObjMarshal.java b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/ObjMarshal.java new file mode 100644 index 0000000..0205eaa --- /dev/null +++ b/rosetta/src/main/java/org/onap/aaf/rosetta/marshal/ObjMarshal.java @@ -0,0 +1,128 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.rosetta.marshal; + +import java.util.Iterator; + +import org.onap.aaf.rosetta.Ladder; +import org.onap.aaf.rosetta.Marshal; +import org.onap.aaf.rosetta.ParseException; +import org.onap.aaf.rosetta.Parsed; + +/** + * Object Marshal + * Assumes has Fields and other Objects + * s + * + * @param + */ +public abstract class ObjMarshal extends Marshal { + // Note: Not Using List or ArrayList, because there is no "Peek" concept in their iterator. + private Marshal[] pml; + private int end=0; + + /** + * @param pm + */ + @SuppressWarnings("unchecked") + protected void add(Marshal pm) { + if(pml==null) { + pml = new Marshal[Ladder.DEFAULT_INIT_SIZE]; + } else if(end>pml.length) { + Object temp[] = pml; + pml = new Marshal[pml.length+Ladder.DEFAULT_INIT_SIZE]; + System.arraycopy(temp, 0, pml, 0, pml.length); + } + pml[end]=pm; + ++end; + } + + /* (non-Javadoc) + * @see com.att.rosetta.Parse#parse(java.lang.Object, com.att.rosetta.Parsed) + */ + @SuppressWarnings("unchecked") + @Override + public Parsed parse(T in, Parsed parsed) throws ParseException { + Ladder> ladder = parsed.state.ladder; + Iterator> iter = (Iterator>)ladder.peek(); + if(iter==null) { + if(pml.length>0) { + ladder.push(new FieldsIterator()); + parsed.event = START_OBJ; + } else { + ladder.push(DONE_ITERATOR); + } + } else if (DONE_ITERATOR.equals(iter)) { + } else { + FieldsIterator fields = (FieldsIterator)iter; + ladder.ascend(); // look at field info + Iterator currFieldIter = ladder.peek(); + Marshal marshal; + if(currFieldIter==null) { + marshal=fields.next(); + } else if(!DONE_ITERATOR.equals(currFieldIter)) { + marshal=fields.peek(); + if(marshal==null && fields.hasNext())marshal=fields.next(); + } else if(fields.hasNext()) { + marshal=fields.next(); + ladder.push(null); + } else { + marshal=null; + } + + if(marshal!=null) + parsed = marshal.parse(in, parsed); + ladder.descend(); + if(marshal==null || parsed.event==NONE) { + parsed.event = END_OBJ; + ladder.push(DONE_ITERATOR); + } + } + return parsed; // if unchanged, then it will end process + } + + private class FieldsIterator implements Iterator> { + private int idx = -1; + + @Override + public boolean hasNext() { + return idx next() { + return pml[++idx]; + } + + public Marshal peek() { + return idx<0?null:pml[idx]; + } + + @Override + public void remove() { + pml[idx]=null; + } + + } + +} diff --git a/rosetta/src/test/java/com/data/test/JU_FromJSON.java b/rosetta/src/test/java/com/data/test/JU_FromJSON.java index 5ad6546..fd13f78 100644 --- a/rosetta/src/test/java/com/data/test/JU_FromJSON.java +++ b/rosetta/src/test/java/com/data/test/JU_FromJSON.java @@ -26,20 +26,19 @@ import java.io.Reader; import java.io.StringReader; import org.junit.Test; - -import com.att.inno.env.Env; -import com.att.inno.env.LogTarget; -import com.att.inno.env.TimeTaken; -import com.att.inno.env.Trans; -import com.att.inno.env.impl.EnvFactory; -import com.att.inno.env.jaxb.JAXBmar; -import com.att.inno.env.util.IndentPrintWriter; -import com.att.inno.env.util.StringBuilderWriter; -import com.att.rosetta.InJson; -import com.att.rosetta.Out; -import com.att.rosetta.OutJson; -import com.att.rosetta.OutRaw; -import com.att.rosetta.OutXML; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.LogTarget; +import org.onap.aaf.inno.env.TimeTaken; +import org.onap.aaf.inno.env.Trans; +import org.onap.aaf.inno.env.impl.EnvFactory; +import org.onap.aaf.inno.env.jaxb.JAXBmar; +import org.onap.aaf.inno.env.util.IndentPrintWriter; +import org.onap.aaf.inno.env.util.StringBuilderWriter; +import org.onap.aaf.rosetta.InJson; +import org.onap.aaf.rosetta.Out; +import org.onap.aaf.rosetta.OutJson; +import org.onap.aaf.rosetta.OutRaw; +import org.onap.aaf.rosetta.OutXML; import junit.framework.Assert; import s.xsd.LargerData; diff --git a/rosetta/src/test/java/com/data/test/JU_FromXML.java b/rosetta/src/test/java/com/data/test/JU_FromXML.java index 62db4f9..97209ff 100644 --- a/rosetta/src/test/java/com/data/test/JU_FromXML.java +++ b/rosetta/src/test/java/com/data/test/JU_FromXML.java @@ -26,21 +26,20 @@ import java.io.Reader; import java.io.StringReader; import org.junit.Test; - -import com.att.inno.env.Env; -import com.att.inno.env.LogTarget; -import com.att.inno.env.TimeTaken; -import com.att.inno.env.Trans; -import com.att.inno.env.Trans.Metric; -import com.att.inno.env.impl.EnvFactory; -import com.att.inno.env.jaxb.JAXBmar; -import com.att.inno.env.jaxb.JAXBumar; -import com.att.inno.env.util.StringBuilderWriter; -import com.att.rosetta.InXML; -import com.att.rosetta.Out; -import com.att.rosetta.OutJson; -import com.att.rosetta.OutRaw; -import com.att.rosetta.OutXML; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.LogTarget; +import org.onap.aaf.inno.env.TimeTaken; +import org.onap.aaf.inno.env.Trans; +import org.onap.aaf.inno.env.Trans.Metric; +import org.onap.aaf.inno.env.impl.EnvFactory; +import org.onap.aaf.inno.env.jaxb.JAXBmar; +import org.onap.aaf.inno.env.jaxb.JAXBumar; +import org.onap.aaf.inno.env.util.StringBuilderWriter; +import org.onap.aaf.rosetta.InXML; +import org.onap.aaf.rosetta.Out; +import org.onap.aaf.rosetta.OutJson; +import org.onap.aaf.rosetta.OutRaw; +import org.onap.aaf.rosetta.OutXML; import s.xsd.LargerData; diff --git a/rosetta/src/test/java/com/data/test/JU_JSON.java b/rosetta/src/test/java/com/data/test/JU_JSON.java index 7840573..ffaf429 100644 --- a/rosetta/src/test/java/com/data/test/JU_JSON.java +++ b/rosetta/src/test/java/com/data/test/JU_JSON.java @@ -28,13 +28,12 @@ import java.io.StringReader; import java.io.StringWriter; import org.junit.Test; - -import com.att.rosetta.InJson; -import com.att.rosetta.Out; -import com.att.rosetta.OutJson; -import com.att.rosetta.OutRaw; -import com.att.rosetta.Parse; -import com.att.rosetta.ParseException; +import org.onap.aaf.rosetta.InJson; +import org.onap.aaf.rosetta.Out; +import org.onap.aaf.rosetta.OutJson; +import org.onap.aaf.rosetta.OutRaw; +import org.onap.aaf.rosetta.Parse; +import org.onap.aaf.rosetta.ParseException; import junit.framework.Assert; diff --git a/rosetta/src/test/java/com/data/test/JU_Ladder.java b/rosetta/src/test/java/com/data/test/JU_Ladder.java index 5f19ed8..77165b8 100644 --- a/rosetta/src/test/java/com/data/test/JU_Ladder.java +++ b/rosetta/src/test/java/com/data/test/JU_Ladder.java @@ -25,9 +25,9 @@ package com.data.test; import static org.junit.Assert.assertEquals; import org.junit.Test; -import static org.junit.Assert.*; +import org.onap.aaf.rosetta.Ladder; -import com.att.rosetta.Ladder; +import static org.junit.Assert.*; public class JU_Ladder { diff --git a/rosetta/src/test/java/com/data/test/JU_Nulls.java b/rosetta/src/test/java/com/data/test/JU_Nulls.java index af18a2f..c70725d 100644 --- a/rosetta/src/test/java/com/data/test/JU_Nulls.java +++ b/rosetta/src/test/java/com/data/test/JU_Nulls.java @@ -24,11 +24,10 @@ package com.data.test; import org.junit.AfterClass; import org.junit.Test; - -import com.att.inno.env.Data; -import com.att.rosetta.env.RosettaDF; -import com.att.rosetta.env.RosettaData; -import com.att.rosetta.env.RosettaEnv; +import org.onap.aaf.inno.env.Data; +import org.onap.aaf.rosetta.env.RosettaDF; +import org.onap.aaf.rosetta.env.RosettaData; +import org.onap.aaf.rosetta.env.RosettaEnv; import junit.framework.Assert; import s.xsd.LargerData; diff --git a/rosetta/src/test/java/com/data/test/JU_RosettaDF.java b/rosetta/src/test/java/com/data/test/JU_RosettaDF.java index 7915a60..5c26afe 100644 --- a/rosetta/src/test/java/com/data/test/JU_RosettaDF.java +++ b/rosetta/src/test/java/com/data/test/JU_RosettaDF.java @@ -26,17 +26,16 @@ import java.io.StringReader; import org.junit.Assert; import org.junit.Test; - -import com.att.inno.env.Data; -import com.att.inno.env.Data.TYPE; -import com.att.inno.env.TimeTaken; -import com.att.inno.env.Trans; -import com.att.inno.env.impl.EnvFactory; -import com.att.inno.env.jaxb.JAXBmar; -import com.att.inno.env.util.StringBuilderWriter; -import com.att.rosetta.env.RosettaDF; -import com.att.rosetta.env.RosettaData; -import com.att.rosetta.env.RosettaEnv; +import org.onap.aaf.inno.env.Data; +import org.onap.aaf.inno.env.TimeTaken; +import org.onap.aaf.inno.env.Trans; +import org.onap.aaf.inno.env.Data.TYPE; +import org.onap.aaf.inno.env.impl.EnvFactory; +import org.onap.aaf.inno.env.jaxb.JAXBmar; +import org.onap.aaf.inno.env.util.StringBuilderWriter; +import org.onap.aaf.rosetta.env.RosettaDF; +import org.onap.aaf.rosetta.env.RosettaData; +import org.onap.aaf.rosetta.env.RosettaEnv; import s.xsd.LargerData; import s.xsd.Multi; diff --git a/rosetta/src/test/java/com/data/test/JU_Saved.java b/rosetta/src/test/java/com/data/test/JU_Saved.java index 6314b72..1d43f88 100644 --- a/rosetta/src/test/java/com/data/test/JU_Saved.java +++ b/rosetta/src/test/java/com/data/test/JU_Saved.java @@ -26,16 +26,15 @@ import java.io.Reader; import java.io.StringReader; import org.junit.Test; - -import com.att.inno.env.TimeTaken; -import com.att.inno.env.Trans; -import com.att.inno.env.impl.EnvFactory; -import com.att.inno.env.util.StringBuilderWriter; -import com.att.rosetta.InJson; -import com.att.rosetta.JaxInfo; -import com.att.rosetta.OutJson; -import com.att.rosetta.OutXML; -import com.att.rosetta.Saved; +import org.onap.aaf.inno.env.TimeTaken; +import org.onap.aaf.inno.env.Trans; +import org.onap.aaf.inno.env.impl.EnvFactory; +import org.onap.aaf.inno.env.util.StringBuilderWriter; +import org.onap.aaf.rosetta.InJson; +import org.onap.aaf.rosetta.JaxInfo; +import org.onap.aaf.rosetta.OutJson; +import org.onap.aaf.rosetta.OutXML; +import org.onap.aaf.rosetta.Saved; import s.xsd.LargerData; diff --git a/rosetta/src/test/java/com/data/test/JU_Stream2Obj.java b/rosetta/src/test/java/com/data/test/JU_Stream2Obj.java index b5a6c9d..4ca3328 100644 --- a/rosetta/src/test/java/com/data/test/JU_Stream2Obj.java +++ b/rosetta/src/test/java/com/data/test/JU_Stream2Obj.java @@ -28,20 +28,19 @@ import java.io.StringReader; import java.io.StringWriter; import org.junit.Test; - -import com.att.inno.env.APIException; -import com.att.inno.env.Data; -import com.att.inno.env.DataFactory; -import com.att.inno.env.EnvJAXB; -import com.att.inno.env.impl.BasicEnv; -import com.att.rosetta.InJson; -import com.att.rosetta.InXML; -import com.att.rosetta.Out; -import com.att.rosetta.OutJson; -import com.att.rosetta.OutRaw; -import com.att.rosetta.OutXML; -import com.att.rosetta.Parse; -import com.att.rosetta.ParseException; +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.Data; +import org.onap.aaf.inno.env.DataFactory; +import org.onap.aaf.inno.env.EnvJAXB; +import org.onap.aaf.inno.env.impl.BasicEnv; +import org.onap.aaf.rosetta.InJson; +import org.onap.aaf.rosetta.InXML; +import org.onap.aaf.rosetta.Out; +import org.onap.aaf.rosetta.OutJson; +import org.onap.aaf.rosetta.OutRaw; +import org.onap.aaf.rosetta.OutXML; +import org.onap.aaf.rosetta.Parse; +import org.onap.aaf.rosetta.ParseException; import inherit.DerivedA; import inherit.Root; diff --git a/rosetta/src/test/java/com/data/test/JU_Struct.java b/rosetta/src/test/java/com/data/test/JU_Struct.java index 66c83c0..cb65f24 100644 --- a/rosetta/src/test/java/com/data/test/JU_Struct.java +++ b/rosetta/src/test/java/com/data/test/JU_Struct.java @@ -23,8 +23,7 @@ package com.data.test; import org.junit.Test; - -import com.att.rosetta.JaxInfo; +import org.onap.aaf.rosetta.JaxInfo; import s.xsd.LargerData; diff --git a/rosetta/src/test/java/com/data/test/JU_Types.java b/rosetta/src/test/java/com/data/test/JU_Types.java index d34815f..3fef743 100644 --- a/rosetta/src/test/java/com/data/test/JU_Types.java +++ b/rosetta/src/test/java/com/data/test/JU_Types.java @@ -28,23 +28,23 @@ import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.namespace.QName; import org.junit.Test; +import org.onap.aaf.inno.env.Data; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.Trans; +import org.onap.aaf.inno.env.Data.TYPE; +import org.onap.aaf.inno.env.Trans.Metric; +import org.onap.aaf.inno.env.jaxb.JAXBmar; +import org.onap.aaf.inno.env.jaxb.JAXBumar; +import org.onap.aaf.inno.env.util.Chrono; +import org.onap.aaf.inno.env.util.StringBuilderWriter; +import org.onap.aaf.rosetta.OutJson; +import org.onap.aaf.rosetta.OutRaw; +import org.onap.aaf.rosetta.OutXML; +import org.onap.aaf.rosetta.env.RosettaDF; +import org.onap.aaf.rosetta.env.RosettaData; +import org.onap.aaf.rosetta.env.RosettaEnv; +import org.onap.aaf.rosetta.marshal.DocMarshal; -import com.att.inno.env.Data; -import com.att.inno.env.Data.TYPE; -import com.att.inno.env.Env; -import com.att.inno.env.Trans; -import com.att.inno.env.Trans.Metric; -import com.att.inno.env.jaxb.JAXBmar; -import com.att.inno.env.jaxb.JAXBumar; -import com.att.inno.env.util.Chrono; -import com.att.inno.env.util.StringBuilderWriter; -import com.att.rosetta.OutJson; -import com.att.rosetta.OutRaw; -import com.att.rosetta.OutXML; -import com.att.rosetta.env.RosettaDF; -import com.att.rosetta.env.RosettaData; -import com.att.rosetta.env.RosettaEnv; -import com.att.rosetta.marshal.DocMarshal; import com.data.test.obj.MultiMarshal; import com.data.test.obj.SingleMarshal; diff --git a/rosetta/src/test/java/com/data/test/OutDump.java b/rosetta/src/test/java/com/data/test/OutDump.java index 6e9d0fb..b4f477f 100644 --- a/rosetta/src/test/java/com/data/test/OutDump.java +++ b/rosetta/src/test/java/com/data/test/OutDump.java @@ -25,11 +25,11 @@ package com.data.test; import java.io.IOException; import java.io.Writer; -import com.att.inno.env.util.IndentPrintWriter; -import com.att.rosetta.Out; -import com.att.rosetta.Parse; -import com.att.rosetta.ParseException; -import com.att.rosetta.Parsed; +import org.onap.aaf.inno.env.util.IndentPrintWriter; +import org.onap.aaf.rosetta.Out; +import org.onap.aaf.rosetta.Parse; +import org.onap.aaf.rosetta.ParseException; +import org.onap.aaf.rosetta.Parsed; public class OutDump extends Out{ diff --git a/rosetta/src/test/java/com/data/test/Report.java b/rosetta/src/test/java/com/data/test/Report.java index 9a970dc..7179245 100644 --- a/rosetta/src/test/java/com/data/test/Report.java +++ b/rosetta/src/test/java/com/data/test/Report.java @@ -25,8 +25,8 @@ package com.data.test; import java.io.IOException; import java.io.Writer; -import com.att.inno.env.Trans; -import com.att.inno.env.Trans.Metric; +import org.onap.aaf.inno.env.Trans; +import org.onap.aaf.inno.env.Trans.Metric; public class Report { float total; diff --git a/rosetta/src/test/java/com/data/test/obj/MultiMarshal.java b/rosetta/src/test/java/com/data/test/obj/MultiMarshal.java index ca105b3..31e4f43 100644 --- a/rosetta/src/test/java/com/data/test/obj/MultiMarshal.java +++ b/rosetta/src/test/java/com/data/test/obj/MultiMarshal.java @@ -24,8 +24,8 @@ package com.data.test.obj; import java.util.List; -import com.att.rosetta.marshal.ObjArray; -import com.att.rosetta.marshal.ObjMarshal; +import org.onap.aaf.rosetta.marshal.ObjArray; +import org.onap.aaf.rosetta.marshal.ObjMarshal; import types.xsd.Multi; import types.xsd.Multi.Single; diff --git a/rosetta/src/test/java/com/data/test/obj/SingleMarshal.java b/rosetta/src/test/java/com/data/test/obj/SingleMarshal.java index b1ac110..d524516 100644 --- a/rosetta/src/test/java/com/data/test/obj/SingleMarshal.java +++ b/rosetta/src/test/java/com/data/test/obj/SingleMarshal.java @@ -26,14 +26,14 @@ import java.util.List; import javax.xml.datatype.XMLGregorianCalendar; -import com.att.rosetta.marshal.DataWriter; -import com.att.rosetta.marshal.FieldArray; -import com.att.rosetta.marshal.FieldDate; -import com.att.rosetta.marshal.FieldDateTime; -import com.att.rosetta.marshal.FieldHexBinary; -import com.att.rosetta.marshal.FieldNumeric; -import com.att.rosetta.marshal.FieldString; -import com.att.rosetta.marshal.ObjMarshal; +import org.onap.aaf.rosetta.marshal.DataWriter; +import org.onap.aaf.rosetta.marshal.FieldArray; +import org.onap.aaf.rosetta.marshal.FieldDate; +import org.onap.aaf.rosetta.marshal.FieldDateTime; +import org.onap.aaf.rosetta.marshal.FieldHexBinary; +import org.onap.aaf.rosetta.marshal.FieldNumeric; +import org.onap.aaf.rosetta.marshal.FieldString; +import org.onap.aaf.rosetta.marshal.ObjMarshal; import types.xsd.Multi.Single; diff --git a/xgen/pom.xml b/xgen/pom.xml index 1ead38c..ce495d2 100644 --- a/xgen/pom.xml +++ b/xgen/pom.xml @@ -23,7 +23,7 @@ - com.att.inno + org.onap.aaf.inno parent 1.0.0-SNAPSHOT .. @@ -63,7 +63,7 @@ - com.att.inno + org.onap.aaf.inno env ${project.version} diff --git a/xgen/src/main/java/com/att/xgen/Back.java b/xgen/src/main/java/com/att/xgen/Back.java deleted file mode 100644 index 154ba88..0000000 --- a/xgen/src/main/java/com/att/xgen/Back.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.xgen; - -public class Back { - public String str; - public boolean dec; - public boolean cr; - - public Back(String string, boolean decrement, boolean newline) { - str = string; - dec = decrement; - cr = newline; - } -} diff --git a/xgen/src/main/java/com/att/xgen/Cache.java b/xgen/src/main/java/com/att/xgen/Cache.java deleted file mode 100644 index 6c887cc..0000000 --- a/xgen/src/main/java/com/att/xgen/Cache.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.xgen; - - -public interface Cache> { - public void dynamic(G hgen, Code code); - - public static class Null> implements Cache { - @Override - public void dynamic(N hgen, Code code) {} // NO_OP, no matter what type - - @SuppressWarnings("rawtypes") - private static Null singleton = new Null(); - public static Null singleton() { return singleton;} - } - -} diff --git a/xgen/src/main/java/com/att/xgen/CacheGen.java b/xgen/src/main/java/com/att/xgen/CacheGen.java deleted file mode 100644 index 371cf87..0000000 --- a/xgen/src/main/java/com/att/xgen/CacheGen.java +++ /dev/null @@ -1,132 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.xgen; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.ArrayList; - -import com.att.inno.env.APIException; -import com.att.inno.env.Env; -import com.att.inno.env.Trans; -import com.att.xgen.html.State; -import com.att.xgen.html.Thematic; - - -public abstract class CacheGen> { - public static final int NO_FLAGS = 0x0; - public final static int PRETTY = 0x1; - public final static int XML = 0x2; - public final static int HTML4 = 0x4; - public final static int HTML5 = 0x8; - - - private ArrayList> sections = new ArrayList>(); - private int flags; - private final Thematic thematic; - - public CacheGen(int flags, Code code) throws APIException, IOException { - this.flags = flags; - final XGenBuff buff = new XGenBuff(flags,this); - // Run to gather Strings and Code Class Segments - buff.run(new Cache() { - @Override - public void dynamic(G hgen, Code code) { - sections.add(buff.newSection()); - sections.add(new Dynamic(hgen.getIndent(),code)); - } - },code); - sections.add(buff.newSection()); - - // If Code implements thematic, set for later - thematic = code instanceof Thematic?(Thematic)code:null; - - } - - public abstract G create(int htmlStyle, Writer w); - - public void replay(State state, Trans trans, OutputStream os, String theme) throws IOException, APIException { - replay(state, trans, new OutputStreamWriter(os), theme); - } - - public void replay(State state, Trans trans,Writer w, String theme) throws IOException, APIException { - if(thematic!=null) { - theme = thematic.themeResolve(theme); - } - /* Theme - trans.setTheme(theme); - int htmlStyle = state.htmlVer(theme); - */ - - XGenBuff buff = new XGenBuff(flags,this); - - // forward - int indent = 0; - Section s; - int i=0; - @SuppressWarnings("unchecked") - Section[] reverse = new Section[sections.size()]; - for(Section section : sections) { - s = section.use(state, trans, buff); // note, doesn't change cached, only dynamic, which is created for thread - int tempIndent = s.getIndent(); - s.setIndent(indent); - s.forward(w); - s.setIndent(tempIndent); - indent = tempIndent; - reverse[i++]=s; - } - - for(--i;i>=0;--i) { - reverse[i].back(w); - } - w.flush(); - } - - private class Dynamic extends Section { - private Code code; - - public Dynamic(int indent, Code code) { - this.code = code; - this.indent = indent; - } - - @SuppressWarnings("unchecked") - public Section use(State state, Trans trans, XGenBuff buff) throws APIException, IOException { - // Clone Dynamic to make Thread Safe - Dynamic d = new Dynamic(indent,code); - buff.setIndent(indent); - if(code instanceof DynamicCode) { - buff.run(state,trans,Cache.Null.singleton(), (DynamicCode)code); - } else { - buff.run((Cache)Cache.Null.singleton(), code); - } - Section s = buff.newSection(); - d.indent = s.indent; - d.forward = s.forward; - d.backward = s.backward; - return d; - } - } -} diff --git a/xgen/src/main/java/com/att/xgen/Code.java b/xgen/src/main/java/com/att/xgen/Code.java deleted file mode 100644 index 70d0c74..0000000 --- a/xgen/src/main/java/com/att/xgen/Code.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.xgen; - -import java.io.IOException; - -import com.att.inno.env.APIException; - -public interface Code> { - public void code(Cache cache, G xgen) throws APIException, IOException; -} diff --git a/xgen/src/main/java/com/att/xgen/DynamicCode.java b/xgen/src/main/java/com/att/xgen/DynamicCode.java deleted file mode 100644 index f1cc4c4..0000000 --- a/xgen/src/main/java/com/att/xgen/DynamicCode.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.xgen; - -import java.io.IOException; - -import com.att.inno.env.APIException; -import com.att.inno.env.Env; -import com.att.inno.env.Trans; -import com.att.xgen.html.State; - -/** - * Special Code Interface to gain access to Transaction - * and State information - * - */ -public abstract class DynamicCode, AS extends State, TRANS extends Trans> implements Code { - public abstract void code(AS state, TRANS trans, Cache cache, G xgen) throws APIException, IOException; - - // We expect not to have this section of the code engaged at any time - public void code(Cache cache, G xgen) throws APIException, IOException { - code(null, null,cache,xgen); - } -} diff --git a/xgen/src/main/java/com/att/xgen/Mark.java b/xgen/src/main/java/com/att/xgen/Mark.java deleted file mode 100644 index 4b148d2..0000000 --- a/xgen/src/main/java/com/att/xgen/Mark.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.xgen; - -public class Mark { - // package on purpose - int spot = 0; - public String comment; - - public Mark() { - comment = null; - } - - public Mark(String string) { - comment = string; - } - - public void spot(int spot) { - this.spot = spot; - } -} diff --git a/xgen/src/main/java/com/att/xgen/Section.java b/xgen/src/main/java/com/att/xgen/Section.java deleted file mode 100644 index 1b16986..0000000 --- a/xgen/src/main/java/com/att/xgen/Section.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.xgen; - -import java.io.IOException; -import java.io.Writer; - -import com.att.inno.env.APIException; -import com.att.inno.env.Env; -import com.att.inno.env.Trans; -import com.att.xgen.html.State; - -public class Section> { - protected int indent; - protected String forward; - protected String backward; - - // Default is to use the set Strings (static) - public Section use(State state, Trans trans, XGenBuff buff) throws APIException, IOException { - return this; - } - - public int getIndent() { - return indent; - } - - public void setIndent(int indent) { - this.indent = indent; - } - - public void forward(Writer w) throws IOException { - w.write(forward); - } - - public void back(Writer w) throws IOException { - w.write(backward); - } - - public String toString() { - return forward; - } -} diff --git a/xgen/src/main/java/com/att/xgen/XGen.java b/xgen/src/main/java/com/att/xgen/XGen.java deleted file mode 100644 index fe6acba..0000000 --- a/xgen/src/main/java/com/att/xgen/XGen.java +++ /dev/null @@ -1,297 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.xgen; - -import java.io.PrintWriter; -import java.io.Writer; -import java.util.Stack; - -import com.att.inno.env.util.IndentPrintWriter; -import com.att.inno.env.util.StringBuilderWriter; - -public class XGen> { - - public static int COMMENT_COLUMN = 40; - private StringBuilder backSB = new StringBuilder(); - private Stack backStack = new Stack(); - - protected XGen(Writer w) { - forward = new IndentPrintWriter(w); - } - - public int pushBack(Back b) { - int rv = backStack.size(); - backStack.push(b); - return rv; - } - - public boolean pretty = false; - protected IndentPrintWriter forward; - - public IndentPrintWriter getWriter() { - return forward; - } - - protected PrintWriter back = new PrintWriter( - new StringBuilderWriter(backSB)); - - @SuppressWarnings("unchecked") - public RT pretty() { - pretty = true; - return (RT) this; - } - - protected void prettyln(PrintWriter pw) { - if(pretty)pw.println(); - } - - public RT leaf(Mark mark, String tag, String ... args) { - mark.spot = backStack.size(); - return leaf(tag, args); - } - - @SuppressWarnings("unchecked") - public RT leaf(String tag, String ... attrs) { - forward.append('<'); - forward.append(tag); - addAttrs(attrs); - forward.append('>'); - back.append("'); - backStack.push(new Back(backSB.toString(), false, true)); - backSB.setLength(0); - return (RT)this; - } - - public RT incr(String tag, String ... args) { - return incr(null, tag, false, args); - } - - public RT incr(String tag, boolean oneLine, String ... args) { - return incr(null, tag, oneLine, args); - } - - public RT incr(Mark mark) { - return incr(mark,mark.comment, false, new String[0]); - } - - public RT incr(Mark mark, String tag, String ... attrs) { - return incr(mark, tag, false, attrs); - } - - @SuppressWarnings("unchecked") - public RT incr(Mark mark, String tag, boolean oneLine, String ... attrs) { - forward.append('<'); - forward.append(tag); - addAttrs(attrs); - forward.append('>'); - - back.append("'); - - if(pretty) { - if(mark!=null && mark.comment!=null) { - int fi = forward.getIndent()*IndentPrintWriter.INDENT; - for(int i = fi+backSB.length();i<=COMMENT_COLUMN;++i) { - back.append(' '); - } - back.append(""); - - forward.toCol(COMMENT_COLUMN); - forward.append(""); - } - forward.inc(); - if(!oneLine) { - forward.println(); - } - back.println(); - } - if(mark!=null)mark.spot = backStack.size(); - backStack.push(new Back(backSB.toString(),true, false)); - backSB.setLength(0); - return (RT)this; - } - - @SuppressWarnings("unchecked") - public RT tagOnly(String tag, String ... attrs) { - forward.append('<'); - forward.append(tag); - addAttrs(attrs); - forward.append(" />"); - if(pretty) { - forward.println(); - } - return (RT)this; - } - - @SuppressWarnings("unchecked") - public RT text(String txt) { - forward.append(txt); - return (RT)this; - } - - @SuppressWarnings("unchecked") - public RT xml(String txt) { - for(int i=0; i': - forward.append(">"); - break; - case '&': - forward.append("&"); - break; - default: - forward.append(c); - } - } - return (RT)this; - } - - - @SuppressWarnings("unchecked") - public RT textCR(int tabs, String txt) { - for(int i=0;i0) { - forward.append(' '); - String[] split = attr.split("=",2); - switch(split.length) { - case 0: - break; - case 1: - forward.append(split[0]); -// forward.append("=\"\""); - break; - default: - forward.append(split[0]); - forward.append("=\""); - forward.append(split[1]); - forward.append('"'); - break; - } - } - } - } - } - - @SuppressWarnings("unchecked") - public RT comment(String string) { - if(pretty) { - forward.print(""); - } - return (RT)this; - } - - public void setIndent(int indent) { - forward.setIndent(indent); - forward.toIndent(); - } - - public int getIndent() { - return forward.getIndent(); - } - -} diff --git a/xgen/src/main/java/com/att/xgen/XGenBuff.java b/xgen/src/main/java/com/att/xgen/XGenBuff.java deleted file mode 100644 index bf63e19..0000000 --- a/xgen/src/main/java/com/att/xgen/XGenBuff.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.xgen; - -import java.io.IOException; - -import com.att.inno.env.APIException; -import com.att.inno.env.Env; -import com.att.inno.env.Trans; -import com.att.inno.env.util.StringBuilderWriter; -import com.att.xgen.html.State; - -public class XGenBuff> { - private G xgen; - private StringBuilder sb; - // private String forward, backward; - - public XGenBuff(int flags, CacheGen cg) { - sb = new StringBuilder(); - xgen = cg.create(flags, new StringBuilderWriter(sb)); - } - - /** - * Normal case of building up Cached HTML without transaction info - * - * @param cache - * @param code - * @throws APIException - * @throws IOException - */ - public void run(Cache cache, Code code) throws APIException, IOException { - code.code(cache, xgen); - } - - /** - * Special Case where code is dynamic, so give access to State and Trans info - * - * @param state - * @param trans - * @param cache - * @param code - * @throws APIException - * @throws IOException - */ - @SuppressWarnings({ "unchecked", "rawtypes" }) - public void run(State state, Trans trans, Cache cache, DynamicCode code) throws APIException, IOException { - code.code(state, trans, cache, xgen); - } - - public int getIndent() { - return xgen.getIndent(); - } - - public void setIndent(int indent) { - xgen.setIndent(indent); - } - - public Section newSection() { - Section s = new Section(); - s.indent = xgen.getIndent(); - s.forward = sb.toString(); - sb.setLength(0); - s.backward = sb.toString(); - sb.setLength(0); - return s; - } -} diff --git a/xgen/src/main/java/com/att/xgen/html/HTML4Gen.java b/xgen/src/main/java/com/att/xgen/html/HTML4Gen.java deleted file mode 100644 index 88cae0a..0000000 --- a/xgen/src/main/java/com/att/xgen/html/HTML4Gen.java +++ /dev/null @@ -1,144 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.xgen.html; - -import java.io.Writer; - -import com.att.xgen.Mark; - -public class HTML4Gen extends HTMLGen { - private final static String DOCTYPE = - /* - ""; - ""; - */ - ""; - - public HTML4Gen(Writer w) { - super(w); - } - - @Override - public HTMLGen html(String ... attrib) { - forward.println(DOCTYPE); - return incr("html","xmlns=http://www.w3.org/1999/xhtml","xml:lang=en","lang=en"); - - } - - @Override - public Mark head() { - Mark head = new Mark("head"); - incr(head); - return head; - } - - @Override - public Mark body(String ... attrs) { - Mark body = new Mark("body"); - incr(body,"body",attrs); - return body; - } - - @Override - public HTML4Gen charset(String charset) { - forward.append(""); - prettyln(forward); - return this; - } - - @Override - public Mark header(String ... attribs) { - String[] a = new String[attribs.length+1]; - a[0]="header"; - System.arraycopy(attribs, 0, a, 1, attribs.length); - return divID(a); - } - - @Override - public Mark footer(String ... attribs) { - String[] a = new String[attribs.length+1]; - a[0]="footer"; - System.arraycopy(attribs, 0, a, 1, attribs.length); - return divID(a); - } - - @Override - public Mark section(String ... attribs) { - String[] a = new String[attribs.length+1]; - a[0]="section"; - System.arraycopy(attribs, 0, a, 1, attribs.length); - return divID(a); - } - - @Override - public Mark article(String ... attribs) { - String[] a = new String[attribs.length+1]; - a[0]="attrib"; - System.arraycopy(attribs, 0, a, 1, attribs.length); - return divID(a); - } - - @Override - public Mark aside(String ... attribs) { - String[] a = new String[attribs.length+1]; - a[0]="aside"; - System.arraycopy(attribs, 0, a, 1, attribs.length); - return divID(a); - } - - @Override - public Mark nav(String ... attribs) { - String[] a = new String[attribs.length+1]; - a[0]="nav"; - System.arraycopy(attribs, 0, a, 1, attribs.length); - return divID(a); - } - -// @Override -// protected void importCSS(Imports imports) { -// if(imports.css.size()==1) { -// cssInline(imports.css.get(0)); -// } else { -// text(""); -// prettyln(forward); -// } -// } - -} diff --git a/xgen/src/main/java/com/att/xgen/html/HTML5Gen.java b/xgen/src/main/java/com/att/xgen/html/HTML5Gen.java deleted file mode 100644 index 217a764..0000000 --- a/xgen/src/main/java/com/att/xgen/html/HTML5Gen.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.xgen.html; - -import java.io.Writer; - -import com.att.xgen.Mark; - -public class HTML5Gen extends HTMLGen { - public HTML5Gen(Writer w) { - super(w); - } - - @Override - public HTMLGen html(String ... attrib) { - //forward.println(""); - incr("html",attrib); - return this; - } - - @Override - public Mark head() { - Mark head = new Mark("head"); - incr(head).directive("meta","charset=utf-8"); - return head; - } - - @Override - public Mark body(String ... attrs) { - Mark body = new Mark("body"); - incr(body,"body",attrs); - //chromeFrame(); - return body; - } - - @Override - public HTML5Gen charset(String charset) { - forward.append(""); - prettyln(forward); - return this; - } - - @Override - public Mark header(String ... attribs) { - Mark mark = new Mark("header"); - incr(mark, mark.comment, attribs); - return mark; - } - - @Override - public Mark footer(String ... attribs) { - Mark mark = new Mark("footer"); - incr(mark, mark.comment, attribs); - return mark; - } - - @Override - public Mark section(String ... attribs) { - Mark mark = new Mark("section"); - incr(mark, mark.comment,attribs); - return mark; - } - - @Override - public Mark article(String ... attribs) { - Mark mark = new Mark("article"); - incr(mark, mark.comment,attribs); - return mark; - } - - @Override - public Mark aside(String ... attribs) { - Mark mark = new Mark("aside"); - incr(mark, mark.comment,attribs); - return mark; - } - - @Override - public Mark nav(String ... attribs) { - Mark mark = new Mark("nav"); - incr(mark, mark.comment,attribs); - return mark; - } - - -// @Override -// protected void importCSS(Imports imports) { -// if(imports.css.size() == 1) { -// cssInline(imports.css.get(0)); -// } else { -// for(String str : imports.css) { -// forward.print(""); -// } -// } -// } -// - - /* - public void chromeFrame() { - this.textCR(0,""); - } - */ - -} diff --git a/xgen/src/main/java/com/att/xgen/html/HTMLCacheGen.java b/xgen/src/main/java/com/att/xgen/html/HTMLCacheGen.java deleted file mode 100644 index a53370a..0000000 --- a/xgen/src/main/java/com/att/xgen/html/HTMLCacheGen.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.xgen.html; - -import java.io.IOException; -import java.io.Writer; - -import com.att.inno.env.APIException; -import com.att.xgen.CacheGen; -import com.att.xgen.Code; - -public class HTMLCacheGen extends CacheGen { - protected int flags; - - public HTMLCacheGen(int flags, Code code) throws APIException,IOException { - super(flags, code); - this.flags = flags; - } - - @Override - public HTMLGen create(int htmlStyle, Writer w) { - HTMLGen hg; - switch(htmlStyle&(CacheGen.HTML4|CacheGen.HTML5)) { - case CacheGen.HTML4: - hg = new HTML4Gen(w); - break; - case CacheGen.HTML5: - default: - hg = new HTML5Gen(w); - break; - - } - hg.pretty = (htmlStyle&CacheGen.PRETTY)>0; - return hg; - } - - protected HTMLGen clone(Writer w) { - return create(flags,w); - } -} diff --git a/xgen/src/main/java/com/att/xgen/html/HTMLGen.java b/xgen/src/main/java/com/att/xgen/html/HTMLGen.java deleted file mode 100644 index 3827884..0000000 --- a/xgen/src/main/java/com/att/xgen/html/HTMLGen.java +++ /dev/null @@ -1,241 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.xgen.html; - -import java.io.Writer; - -import com.att.xgen.Mark; -import com.att.xgen.XGen; - -public abstract class HTMLGen extends XGen { - public static final String A = "a"; - public static final String P = "p"; - public static final String LI = "li"; - public static final String OL = "ol"; - public static final String UL = "ul"; - - - public static final String TABLE = "table"; - public static final String THEAD = "thead"; - public static final String TBODY = "tbody"; - public static final String TR = "tr"; - public static final String TH = "th"; - public static final String TD = "td"; - - public static final String TITLE = "title"; - public static final String H1 = "h1"; - public static final String H2 = "h2"; - public static final String H3 = "h3"; - public static final String H4 = "h4"; - public static final String H5 = "h5"; - - - - // --------------------------- HTML Version Specific ----------------------- - public abstract HTMLGen html(String ... attributes); - public abstract HTMLGen charset(String charset); - public abstract Mark head(); - public abstract Mark body(String ... attribs); - - - // HTML 5 has simplified sectioning - public abstract Mark header(String ... attribs); - public abstract Mark footer(String ... attribs); - public abstract Mark section(String ... attribs); - public abstract Mark article(String ... attribs); - public abstract Mark aside(String ... attribs); - public abstract Mark nav(String ... attribs); - - // --------------------------- HTML Version Specific ----------------------- - - public HTMLGen imports(Imports imports) { - //this.imports=imports; - for(String str : imports.css) { - forward.print(""); - } - - for(String str : imports.js) { - forward.print(""); - } - return this; - } - - public HTMLGen jsVars(String ... attrs) { - forward.println(""); - return this; - } - - public HTMLGen(Writer w) { - super(w); - } - - /** - * Use "directive" to handle non-ended HTML tags like and - * @param tag - * @param attrs - * @return - */ - public HTMLGen directive(String tag, String ... attrs) { - forward.append('<'); - forward.append(tag); - addAttrs(attrs); - forward.append('>'); - if(pretty) { - forward.println(); - } - return this; - } - - public Mark divID(String ... attrs) { - Mark div; - if(attrs.length>0) { - div = new Mark(attrs[0]); - attrs[0]="id="+attrs[0]; - } else { - div = new Mark(); - } - incr(div, "div", attrs); - return div; - } - - public HTMLGen img(String ... attrs) { - return tagOnly("img", attrs); - } - - /** - * Input Cheesecake... creates a Label and Field in the form of Table Rows. - * Make sure you create a table first, ie. incr(HTMLGen.TABLE); - * - * Setting Required to "true" will add required Attribute to both Label and Field. In HTML5, "required" in the input will - * validate there is data in the fields before submitting. "required" does nothing for label, but allows for - * easy CSS coding... "label[required] { ... }", so that colors can be changed - * - * @param id - * @param label - * @param required - * @param attrs - * @return - */ - public HTMLGen input(String id, String label, boolean required, String ... attrs) { - Mark mtr = new Mark(TR); - Mark mtd = new Mark(TD); - incr(mtr); - incr(mtd); - incr("label",true, "for="+id,required?"required":null).text(label).end(); - end(mtd); - String nattrs[] = new String[attrs.length+(required?3:2)]; - nattrs[0]="id="+id; - nattrs[1]="name="+id; - System.arraycopy(attrs, 0, nattrs, 2, attrs.length); - if(required) { - nattrs[nattrs.length-1]="required"; - } - incr(mtd); - tagOnly("input",nattrs); - end(mtr); - return this; - } - - // Common tags that do not have standard endings. These are here to help people who don't know to pick directive - public HTMLGen br() { - forward.append("
"); - if(pretty) { - forward.println(); - } - return this; - } - - public HTMLGen p(String ... text) { - forward.append("

"); - for(String s : text) { - forward.append(s); - } - if(pretty) { - forward.println(); - } - return this; - } - - public HTMLGen hr() { - forward.append("


"); - if(pretty) { - forward.println(); - } - return this; - } - - public JSGen js(Mark mark) { - return new JSGen(mark, this); - } - - public JSGen js() { - return js(null); - } -// -// protected void cssInline(String filename) { -// File file = new File(imports.webDir,filename); -// try { -// String line; -// BufferedReader br = new BufferedReader(new FileReader(file)); -// try { -// forward.print(""); -// prettyln(forward); -// br.close(); -// } -// } catch (IOException e) { -// e.printStackTrace(); -// // Can't read, suffice to import normally? -// // for now, just skip -// } -// } - -} diff --git a/xgen/src/main/java/com/att/xgen/html/Imports.java b/xgen/src/main/java/com/att/xgen/html/Imports.java deleted file mode 100644 index 941fe5f..0000000 --- a/xgen/src/main/java/com/att/xgen/html/Imports.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.xgen.html; - -import java.util.ArrayList; -import java.util.List; - -public class Imports implements Thematic{ - List css,js; - public final int backdots; -// public final File webDir; - private String theme; - - public Imports(int backdots) { -// this.webDir = webDir; - - css = new ArrayList(); - js = new ArrayList(); - this.backdots = backdots; - theme = ""; - } - - public Imports css(String str) { - css.add(str); - return this; - } - - public Imports js(String str) { - js.add(str); - return this; - } - - public Imports theme(String str) { - theme = str==null?"":str; - return this; - } - - /** - * Pass in a possible Theme. If it is "" or null, it will resolve to default Theme set in Imports - * - * @param theTheme - * @return - */ - @Override - public String themePath(String theTheme) { - StringBuilder src = dots(new StringBuilder()); - if(theTheme==null||theTheme.length()==0) { - src.append(theme); - if(theme.length()>0)src.append('/'); - } else { - src.append(theTheme); - src.append('/'); - } - - return src.toString(); - } - - /** - * Pass in a possible Theme. If it is "" or null, it will resolve to default Theme set in Imports - * - * @param theTheme - * @return - */ - @Override - public String themeResolve(String theTheme) { - return (theTheme==null||theTheme.length()==0) - ?theme - :theTheme; - } - - public StringBuilder dots(StringBuilder src) { - for(int i=0;i0) ipw.print(' '); - ipw.print(el); - } - } - ipw.println(); - } else { - ipw.print(line.trim()); - } - } - } finally { - htmlGen.setIndent(indent); - try { - br.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - return this; - } - - public JSGen pst(String ... lines) { - return pst(null, lines); - } - - public JSGen pst(Mark jm, String ... lines) { - if(lines.length>0) ipw.append(lines[0]); - ipw.append('('); - for(int i=1;i0)ipw.println(); - ipw.print(lines[i]); - } - ipw.setIndent(current); - ipw.append(';'); - if(htmlGen.pretty)ipw.println(); - return this; - } - - public JSGen text(String text) { - ipw.append(text); - if(htmlGen.pretty)ipw.println(); - return this; - } - - public JSGen function(String name, String ... params) { - return function(null, name, params); - } - - public JSGen jqfunc(Mark mark, String name, String ... params) { - pst(mark,"$").function(name, params); - return this; - } - - public JSGen function(Mark jm, String name, String ... params) { - ipw.print("function "); - ipw.print(name); - ipw.print('('); - for(int i=0;i0)ipw.println(); - ipw.print(lines[i]); - } - ipw.setIndent(current); - ipw.print('{'); - if(htmlGen.pretty) { - ipw.println(); - ipw.inc(); - } - int spot = htmlGen.pushBack(new Back("}",true,true)); - if(jm!=null)jm.spot(spot); - return this; - - } - - - public JSGen comment(String ... lines) { - if(htmlGen.pretty) { - for(int i=0;i { -} diff --git a/xgen/src/main/java/com/att/xgen/html/Thematic.java b/xgen/src/main/java/com/att/xgen/html/Thematic.java deleted file mode 100644 index 865be9b..0000000 --- a/xgen/src/main/java/com/att/xgen/html/Thematic.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.xgen.html; - -public interface Thematic { - String themePath(String theTheme); - String themeResolve(String theTheme); -} diff --git a/xgen/src/main/java/com/att/xgen/xml/XMLCacheGen.java b/xgen/src/main/java/com/att/xgen/xml/XMLCacheGen.java deleted file mode 100644 index 0e00a41..0000000 --- a/xgen/src/main/java/com/att/xgen/xml/XMLCacheGen.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.xgen.xml; - -import java.io.IOException; -import java.io.Writer; - -import com.att.inno.env.APIException; -import com.att.xgen.CacheGen; -import com.att.xgen.Code; - -public class XMLCacheGen extends CacheGen { - - public XMLCacheGen(int flags, Code code) throws APIException, - IOException { - super(flags, code); - } - - @Override - public XMLGen create(int style, Writer w) { - XMLGen xg = new XMLGen(w); - xg.pretty = (style & PRETTY)==PRETTY; - return xg; - } - -} diff --git a/xgen/src/main/java/com/att/xgen/xml/XMLGen.java b/xgen/src/main/java/com/att/xgen/xml/XMLGen.java deleted file mode 100644 index ac9d689..0000000 --- a/xgen/src/main/java/com/att/xgen/xml/XMLGen.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START==================================================== - * * org.onap.aaf - * * =========================================================================== - * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * * =========================================================================== - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * ============LICENSE_END==================================================== - * * - * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * * - ******************************************************************************/ -package com.att.xgen.xml; - -import java.io.Writer; - -import com.att.xgen.XGen;; - -public class XMLGen extends XGen { - private final String XML_TAG; - - public XMLGen(Writer w) { - this(w,"UTF-8"); - } - - public XMLGen(Writer w, String encoding) { - super(w); - XML_TAG=""; - } - - public XMLGen xml() { - forward.println(XML_TAG); - return this; - } -} diff --git a/xgen/src/main/java/org/onap/aaf/xgen/Back.java b/xgen/src/main/java/org/onap/aaf/xgen/Back.java new file mode 100644 index 0000000..0c9f592 --- /dev/null +++ b/xgen/src/main/java/org/onap/aaf/xgen/Back.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.xgen; + +public class Back { + public String str; + public boolean dec; + public boolean cr; + + public Back(String string, boolean decrement, boolean newline) { + str = string; + dec = decrement; + cr = newline; + } +} diff --git a/xgen/src/main/java/org/onap/aaf/xgen/Cache.java b/xgen/src/main/java/org/onap/aaf/xgen/Cache.java new file mode 100644 index 0000000..7f75703 --- /dev/null +++ b/xgen/src/main/java/org/onap/aaf/xgen/Cache.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.xgen; + + +public interface Cache> { + public void dynamic(G hgen, Code code); + + public static class Null> implements Cache { + @Override + public void dynamic(N hgen, Code code) {} // NO_OP, no matter what type + + @SuppressWarnings("rawtypes") + private static Null singleton = new Null(); + public static Null singleton() { return singleton;} + } + +} diff --git a/xgen/src/main/java/org/onap/aaf/xgen/CacheGen.java b/xgen/src/main/java/org/onap/aaf/xgen/CacheGen.java new file mode 100644 index 0000000..3a8957a --- /dev/null +++ b/xgen/src/main/java/org/onap/aaf/xgen/CacheGen.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.xgen; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.ArrayList; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.Trans; +import org.onap.aaf.xgen.html.State; +import org.onap.aaf.xgen.html.Thematic; + + +public abstract class CacheGen> { + public static final int NO_FLAGS = 0x0; + public final static int PRETTY = 0x1; + public final static int XML = 0x2; + public final static int HTML4 = 0x4; + public final static int HTML5 = 0x8; + + + private ArrayList> sections = new ArrayList>(); + private int flags; + private final Thematic thematic; + + public CacheGen(int flags, Code code) throws APIException, IOException { + this.flags = flags; + final XGenBuff buff = new XGenBuff(flags,this); + // Run to gather Strings and Code Class Segments + buff.run(new Cache() { + @Override + public void dynamic(G hgen, Code code) { + sections.add(buff.newSection()); + sections.add(new Dynamic(hgen.getIndent(),code)); + } + },code); + sections.add(buff.newSection()); + + // If Code implements thematic, set for later + thematic = code instanceof Thematic?(Thematic)code:null; + + } + + public abstract G create(int htmlStyle, Writer w); + + public void replay(State state, Trans trans, OutputStream os, String theme) throws IOException, APIException { + replay(state, trans, new OutputStreamWriter(os), theme); + } + + public void replay(State state, Trans trans,Writer w, String theme) throws IOException, APIException { + if(thematic!=null) { + theme = thematic.themeResolve(theme); + } + /* Theme + trans.setTheme(theme); + int htmlStyle = state.htmlVer(theme); + */ + + XGenBuff buff = new XGenBuff(flags,this); + + // forward + int indent = 0; + Section s; + int i=0; + @SuppressWarnings("unchecked") + Section[] reverse = new Section[sections.size()]; + for(Section section : sections) { + s = section.use(state, trans, buff); // note, doesn't change cached, only dynamic, which is created for thread + int tempIndent = s.getIndent(); + s.setIndent(indent); + s.forward(w); + s.setIndent(tempIndent); + indent = tempIndent; + reverse[i++]=s; + } + + for(--i;i>=0;--i) { + reverse[i].back(w); + } + w.flush(); + } + + private class Dynamic extends Section { + private Code code; + + public Dynamic(int indent, Code code) { + this.code = code; + this.indent = indent; + } + + @SuppressWarnings("unchecked") + public Section use(State state, Trans trans, XGenBuff buff) throws APIException, IOException { + // Clone Dynamic to make Thread Safe + Dynamic d = new Dynamic(indent,code); + buff.setIndent(indent); + if(code instanceof DynamicCode) { + buff.run(state,trans,Cache.Null.singleton(), (DynamicCode)code); + } else { + buff.run((Cache)Cache.Null.singleton(), code); + } + Section s = buff.newSection(); + d.indent = s.indent; + d.forward = s.forward; + d.backward = s.backward; + return d; + } + } +} diff --git a/xgen/src/main/java/org/onap/aaf/xgen/Code.java b/xgen/src/main/java/org/onap/aaf/xgen/Code.java new file mode 100644 index 0000000..163a9dd --- /dev/null +++ b/xgen/src/main/java/org/onap/aaf/xgen/Code.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.xgen; + +import java.io.IOException; + +import org.onap.aaf.inno.env.APIException; + +public interface Code> { + public void code(Cache cache, G xgen) throws APIException, IOException; +} diff --git a/xgen/src/main/java/org/onap/aaf/xgen/DynamicCode.java b/xgen/src/main/java/org/onap/aaf/xgen/DynamicCode.java new file mode 100644 index 0000000..4e44032 --- /dev/null +++ b/xgen/src/main/java/org/onap/aaf/xgen/DynamicCode.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.xgen; + +import java.io.IOException; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.Trans; +import org.onap.aaf.xgen.html.State; + +/** + * Special Code Interface to gain access to Transaction + * and State information + * + */ +public abstract class DynamicCode, AS extends State, TRANS extends Trans> implements Code { + public abstract void code(AS state, TRANS trans, Cache cache, G xgen) throws APIException, IOException; + + // We expect not to have this section of the code engaged at any time + public void code(Cache cache, G xgen) throws APIException, IOException { + code(null, null,cache,xgen); + } +} diff --git a/xgen/src/main/java/org/onap/aaf/xgen/Mark.java b/xgen/src/main/java/org/onap/aaf/xgen/Mark.java new file mode 100644 index 0000000..4872139 --- /dev/null +++ b/xgen/src/main/java/org/onap/aaf/xgen/Mark.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.xgen; + +public class Mark { + // package on purpose + int spot = 0; + public String comment; + + public Mark() { + comment = null; + } + + public Mark(String string) { + comment = string; + } + + public void spot(int spot) { + this.spot = spot; + } +} diff --git a/xgen/src/main/java/org/onap/aaf/xgen/Section.java b/xgen/src/main/java/org/onap/aaf/xgen/Section.java new file mode 100644 index 0000000..3851090 --- /dev/null +++ b/xgen/src/main/java/org/onap/aaf/xgen/Section.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.xgen; + +import java.io.IOException; +import java.io.Writer; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.Trans; +import org.onap.aaf.xgen.html.State; + +public class Section> { + protected int indent; + protected String forward; + protected String backward; + + // Default is to use the set Strings (static) + public Section use(State state, Trans trans, XGenBuff buff) throws APIException, IOException { + return this; + } + + public int getIndent() { + return indent; + } + + public void setIndent(int indent) { + this.indent = indent; + } + + public void forward(Writer w) throws IOException { + w.write(forward); + } + + public void back(Writer w) throws IOException { + w.write(backward); + } + + public String toString() { + return forward; + } +} diff --git a/xgen/src/main/java/org/onap/aaf/xgen/XGen.java b/xgen/src/main/java/org/onap/aaf/xgen/XGen.java new file mode 100644 index 0000000..089c62a --- /dev/null +++ b/xgen/src/main/java/org/onap/aaf/xgen/XGen.java @@ -0,0 +1,297 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.xgen; + +import java.io.PrintWriter; +import java.io.Writer; +import java.util.Stack; + +import org.onap.aaf.inno.env.util.IndentPrintWriter; +import org.onap.aaf.inno.env.util.StringBuilderWriter; + +public class XGen> { + + public static int COMMENT_COLUMN = 40; + private StringBuilder backSB = new StringBuilder(); + private Stack backStack = new Stack(); + + protected XGen(Writer w) { + forward = new IndentPrintWriter(w); + } + + public int pushBack(Back b) { + int rv = backStack.size(); + backStack.push(b); + return rv; + } + + public boolean pretty = false; + protected IndentPrintWriter forward; + + public IndentPrintWriter getWriter() { + return forward; + } + + protected PrintWriter back = new PrintWriter( + new StringBuilderWriter(backSB)); + + @SuppressWarnings("unchecked") + public RT pretty() { + pretty = true; + return (RT) this; + } + + protected void prettyln(PrintWriter pw) { + if(pretty)pw.println(); + } + + public RT leaf(Mark mark, String tag, String ... args) { + mark.spot = backStack.size(); + return leaf(tag, args); + } + + @SuppressWarnings("unchecked") + public RT leaf(String tag, String ... attrs) { + forward.append('<'); + forward.append(tag); + addAttrs(attrs); + forward.append('>'); + back.append("'); + backStack.push(new Back(backSB.toString(), false, true)); + backSB.setLength(0); + return (RT)this; + } + + public RT incr(String tag, String ... args) { + return incr(null, tag, false, args); + } + + public RT incr(String tag, boolean oneLine, String ... args) { + return incr(null, tag, oneLine, args); + } + + public RT incr(Mark mark) { + return incr(mark,mark.comment, false, new String[0]); + } + + public RT incr(Mark mark, String tag, String ... attrs) { + return incr(mark, tag, false, attrs); + } + + @SuppressWarnings("unchecked") + public RT incr(Mark mark, String tag, boolean oneLine, String ... attrs) { + forward.append('<'); + forward.append(tag); + addAttrs(attrs); + forward.append('>'); + + back.append("'); + + if(pretty) { + if(mark!=null && mark.comment!=null) { + int fi = forward.getIndent()*IndentPrintWriter.INDENT; + for(int i = fi+backSB.length();i<=COMMENT_COLUMN;++i) { + back.append(' '); + } + back.append(""); + + forward.toCol(COMMENT_COLUMN); + forward.append(""); + } + forward.inc(); + if(!oneLine) { + forward.println(); + } + back.println(); + } + if(mark!=null)mark.spot = backStack.size(); + backStack.push(new Back(backSB.toString(),true, false)); + backSB.setLength(0); + return (RT)this; + } + + @SuppressWarnings("unchecked") + public RT tagOnly(String tag, String ... attrs) { + forward.append('<'); + forward.append(tag); + addAttrs(attrs); + forward.append(" />"); + if(pretty) { + forward.println(); + } + return (RT)this; + } + + @SuppressWarnings("unchecked") + public RT text(String txt) { + forward.append(txt); + return (RT)this; + } + + @SuppressWarnings("unchecked") + public RT xml(String txt) { + for(int i=0; i': + forward.append(">"); + break; + case '&': + forward.append("&"); + break; + default: + forward.append(c); + } + } + return (RT)this; + } + + + @SuppressWarnings("unchecked") + public RT textCR(int tabs, String txt) { + for(int i=0;i0) { + forward.append(' '); + String[] split = attr.split("=",2); + switch(split.length) { + case 0: + break; + case 1: + forward.append(split[0]); +// forward.append("=\"\""); + break; + default: + forward.append(split[0]); + forward.append("=\""); + forward.append(split[1]); + forward.append('"'); + break; + } + } + } + } + } + + @SuppressWarnings("unchecked") + public RT comment(String string) { + if(pretty) { + forward.print(""); + } + return (RT)this; + } + + public void setIndent(int indent) { + forward.setIndent(indent); + forward.toIndent(); + } + + public int getIndent() { + return forward.getIndent(); + } + +} diff --git a/xgen/src/main/java/org/onap/aaf/xgen/XGenBuff.java b/xgen/src/main/java/org/onap/aaf/xgen/XGenBuff.java new file mode 100644 index 0000000..5da2ab3 --- /dev/null +++ b/xgen/src/main/java/org/onap/aaf/xgen/XGenBuff.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.xgen; + +import java.io.IOException; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.inno.env.Env; +import org.onap.aaf.inno.env.Trans; +import org.onap.aaf.inno.env.util.StringBuilderWriter; +import org.onap.aaf.xgen.html.State; + +public class XGenBuff> { + private G xgen; + private StringBuilder sb; + // private String forward, backward; + + public XGenBuff(int flags, CacheGen cg) { + sb = new StringBuilder(); + xgen = cg.create(flags, new StringBuilderWriter(sb)); + } + + /** + * Normal case of building up Cached HTML without transaction info + * + * @param cache + * @param code + * @throws APIException + * @throws IOException + */ + public void run(Cache cache, Code code) throws APIException, IOException { + code.code(cache, xgen); + } + + /** + * Special Case where code is dynamic, so give access to State and Trans info + * + * @param state + * @param trans + * @param cache + * @param code + * @throws APIException + * @throws IOException + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void run(State state, Trans trans, Cache cache, DynamicCode code) throws APIException, IOException { + code.code(state, trans, cache, xgen); + } + + public int getIndent() { + return xgen.getIndent(); + } + + public void setIndent(int indent) { + xgen.setIndent(indent); + } + + public Section newSection() { + Section s = new Section(); + s.indent = xgen.getIndent(); + s.forward = sb.toString(); + sb.setLength(0); + s.backward = sb.toString(); + sb.setLength(0); + return s; + } +} diff --git a/xgen/src/main/java/org/onap/aaf/xgen/html/HTML4Gen.java b/xgen/src/main/java/org/onap/aaf/xgen/html/HTML4Gen.java new file mode 100644 index 0000000..d858148 --- /dev/null +++ b/xgen/src/main/java/org/onap/aaf/xgen/html/HTML4Gen.java @@ -0,0 +1,144 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.xgen.html; + +import java.io.Writer; + +import org.onap.aaf.xgen.Mark; + +public class HTML4Gen extends HTMLGen { + private final static String DOCTYPE = + /* + ""; + ""; + */ + ""; + + public HTML4Gen(Writer w) { + super(w); + } + + @Override + public HTMLGen html(String ... attrib) { + forward.println(DOCTYPE); + return incr("html","xmlns=http://www.w3.org/1999/xhtml","xml:lang=en","lang=en"); + + } + + @Override + public Mark head() { + Mark head = new Mark("head"); + incr(head); + return head; + } + + @Override + public Mark body(String ... attrs) { + Mark body = new Mark("body"); + incr(body,"body",attrs); + return body; + } + + @Override + public HTML4Gen charset(String charset) { + forward.append(""); + prettyln(forward); + return this; + } + + @Override + public Mark header(String ... attribs) { + String[] a = new String[attribs.length+1]; + a[0]="header"; + System.arraycopy(attribs, 0, a, 1, attribs.length); + return divID(a); + } + + @Override + public Mark footer(String ... attribs) { + String[] a = new String[attribs.length+1]; + a[0]="footer"; + System.arraycopy(attribs, 0, a, 1, attribs.length); + return divID(a); + } + + @Override + public Mark section(String ... attribs) { + String[] a = new String[attribs.length+1]; + a[0]="section"; + System.arraycopy(attribs, 0, a, 1, attribs.length); + return divID(a); + } + + @Override + public Mark article(String ... attribs) { + String[] a = new String[attribs.length+1]; + a[0]="attrib"; + System.arraycopy(attribs, 0, a, 1, attribs.length); + return divID(a); + } + + @Override + public Mark aside(String ... attribs) { + String[] a = new String[attribs.length+1]; + a[0]="aside"; + System.arraycopy(attribs, 0, a, 1, attribs.length); + return divID(a); + } + + @Override + public Mark nav(String ... attribs) { + String[] a = new String[attribs.length+1]; + a[0]="nav"; + System.arraycopy(attribs, 0, a, 1, attribs.length); + return divID(a); + } + +// @Override +// protected void importCSS(Imports imports) { +// if(imports.css.size()==1) { +// cssInline(imports.css.get(0)); +// } else { +// text(""); +// prettyln(forward); +// } +// } + +} diff --git a/xgen/src/main/java/org/onap/aaf/xgen/html/HTML5Gen.java b/xgen/src/main/java/org/onap/aaf/xgen/html/HTML5Gen.java new file mode 100644 index 0000000..9fec999 --- /dev/null +++ b/xgen/src/main/java/org/onap/aaf/xgen/html/HTML5Gen.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.xgen.html; + +import java.io.Writer; + +import org.onap.aaf.xgen.Mark; + +public class HTML5Gen extends HTMLGen { + public HTML5Gen(Writer w) { + super(w); + } + + @Override + public HTMLGen html(String ... attrib) { + //forward.println(""); + incr("html",attrib); + return this; + } + + @Override + public Mark head() { + Mark head = new Mark("head"); + incr(head).directive("meta","charset=utf-8"); + return head; + } + + @Override + public Mark body(String ... attrs) { + Mark body = new Mark("body"); + incr(body,"body",attrs); + //chromeFrame(); + return body; + } + + @Override + public HTML5Gen charset(String charset) { + forward.append(""); + prettyln(forward); + return this; + } + + @Override + public Mark header(String ... attribs) { + Mark mark = new Mark("header"); + incr(mark, mark.comment, attribs); + return mark; + } + + @Override + public Mark footer(String ... attribs) { + Mark mark = new Mark("footer"); + incr(mark, mark.comment, attribs); + return mark; + } + + @Override + public Mark section(String ... attribs) { + Mark mark = new Mark("section"); + incr(mark, mark.comment,attribs); + return mark; + } + + @Override + public Mark article(String ... attribs) { + Mark mark = new Mark("article"); + incr(mark, mark.comment,attribs); + return mark; + } + + @Override + public Mark aside(String ... attribs) { + Mark mark = new Mark("aside"); + incr(mark, mark.comment,attribs); + return mark; + } + + @Override + public Mark nav(String ... attribs) { + Mark mark = new Mark("nav"); + incr(mark, mark.comment,attribs); + return mark; + } + + +// @Override +// protected void importCSS(Imports imports) { +// if(imports.css.size() == 1) { +// cssInline(imports.css.get(0)); +// } else { +// for(String str : imports.css) { +// forward.print(""); +// } +// } +// } +// + + /* + public void chromeFrame() { + this.textCR(0,""); + } + */ + +} diff --git a/xgen/src/main/java/org/onap/aaf/xgen/html/HTMLCacheGen.java b/xgen/src/main/java/org/onap/aaf/xgen/html/HTMLCacheGen.java new file mode 100644 index 0000000..e541a16 --- /dev/null +++ b/xgen/src/main/java/org/onap/aaf/xgen/html/HTMLCacheGen.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.xgen.html; + +import java.io.IOException; +import java.io.Writer; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.xgen.CacheGen; +import org.onap.aaf.xgen.Code; + +public class HTMLCacheGen extends CacheGen { + protected int flags; + + public HTMLCacheGen(int flags, Code code) throws APIException,IOException { + super(flags, code); + this.flags = flags; + } + + @Override + public HTMLGen create(int htmlStyle, Writer w) { + HTMLGen hg; + switch(htmlStyle&(CacheGen.HTML4|CacheGen.HTML5)) { + case CacheGen.HTML4: + hg = new HTML4Gen(w); + break; + case CacheGen.HTML5: + default: + hg = new HTML5Gen(w); + break; + + } + hg.pretty = (htmlStyle&CacheGen.PRETTY)>0; + return hg; + } + + protected HTMLGen clone(Writer w) { + return create(flags,w); + } +} diff --git a/xgen/src/main/java/org/onap/aaf/xgen/html/HTMLGen.java b/xgen/src/main/java/org/onap/aaf/xgen/html/HTMLGen.java new file mode 100644 index 0000000..1f4bffd --- /dev/null +++ b/xgen/src/main/java/org/onap/aaf/xgen/html/HTMLGen.java @@ -0,0 +1,241 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.xgen.html; + +import java.io.Writer; + +import org.onap.aaf.xgen.Mark; +import org.onap.aaf.xgen.XGen; + +public abstract class HTMLGen extends XGen { + public static final String A = "a"; + public static final String P = "p"; + public static final String LI = "li"; + public static final String OL = "ol"; + public static final String UL = "ul"; + + + public static final String TABLE = "table"; + public static final String THEAD = "thead"; + public static final String TBODY = "tbody"; + public static final String TR = "tr"; + public static final String TH = "th"; + public static final String TD = "td"; + + public static final String TITLE = "title"; + public static final String H1 = "h1"; + public static final String H2 = "h2"; + public static final String H3 = "h3"; + public static final String H4 = "h4"; + public static final String H5 = "h5"; + + + + // --------------------------- HTML Version Specific ----------------------- + public abstract HTMLGen html(String ... attributes); + public abstract HTMLGen charset(String charset); + public abstract Mark head(); + public abstract Mark body(String ... attribs); + + + // HTML 5 has simplified sectioning + public abstract Mark header(String ... attribs); + public abstract Mark footer(String ... attribs); + public abstract Mark section(String ... attribs); + public abstract Mark article(String ... attribs); + public abstract Mark aside(String ... attribs); + public abstract Mark nav(String ... attribs); + + // --------------------------- HTML Version Specific ----------------------- + + public HTMLGen imports(Imports imports) { + //this.imports=imports; + for(String str : imports.css) { + forward.print(""); + } + + for(String str : imports.js) { + forward.print(""); + } + return this; + } + + public HTMLGen jsVars(String ... attrs) { + forward.println(""); + return this; + } + + public HTMLGen(Writer w) { + super(w); + } + + /** + * Use "directive" to handle non-ended HTML tags like and + * @param tag + * @param attrs + * @return + */ + public HTMLGen directive(String tag, String ... attrs) { + forward.append('<'); + forward.append(tag); + addAttrs(attrs); + forward.append('>'); + if(pretty) { + forward.println(); + } + return this; + } + + public Mark divID(String ... attrs) { + Mark div; + if(attrs.length>0) { + div = new Mark(attrs[0]); + attrs[0]="id="+attrs[0]; + } else { + div = new Mark(); + } + incr(div, "div", attrs); + return div; + } + + public HTMLGen img(String ... attrs) { + return tagOnly("img", attrs); + } + + /** + * Input Cheesecake... creates a Label and Field in the form of Table Rows. + * Make sure you create a table first, ie. incr(HTMLGen.TABLE); + * + * Setting Required to "true" will add required Attribute to both Label and Field. In HTML5, "required" in the input will + * validate there is data in the fields before submitting. "required" does nothing for label, but allows for + * easy CSS coding... "label[required] { ... }", so that colors can be changed + * + * @param id + * @param label + * @param required + * @param attrs + * @return + */ + public HTMLGen input(String id, String label, boolean required, String ... attrs) { + Mark mtr = new Mark(TR); + Mark mtd = new Mark(TD); + incr(mtr); + incr(mtd); + incr("label",true, "for="+id,required?"required":null).text(label).end(); + end(mtd); + String nattrs[] = new String[attrs.length+(required?3:2)]; + nattrs[0]="id="+id; + nattrs[1]="name="+id; + System.arraycopy(attrs, 0, nattrs, 2, attrs.length); + if(required) { + nattrs[nattrs.length-1]="required"; + } + incr(mtd); + tagOnly("input",nattrs); + end(mtr); + return this; + } + + // Common tags that do not have standard endings. These are here to help people who don't know to pick directive + public HTMLGen br() { + forward.append("
"); + if(pretty) { + forward.println(); + } + return this; + } + + public HTMLGen p(String ... text) { + forward.append("

"); + for(String s : text) { + forward.append(s); + } + if(pretty) { + forward.println(); + } + return this; + } + + public HTMLGen hr() { + forward.append("


"); + if(pretty) { + forward.println(); + } + return this; + } + + public JSGen js(Mark mark) { + return new JSGen(mark, this); + } + + public JSGen js() { + return js(null); + } +// +// protected void cssInline(String filename) { +// File file = new File(imports.webDir,filename); +// try { +// String line; +// BufferedReader br = new BufferedReader(new FileReader(file)); +// try { +// forward.print(""); +// prettyln(forward); +// br.close(); +// } +// } catch (IOException e) { +// e.printStackTrace(); +// // Can't read, suffice to import normally? +// // for now, just skip +// } +// } + +} diff --git a/xgen/src/main/java/org/onap/aaf/xgen/html/Imports.java b/xgen/src/main/java/org/onap/aaf/xgen/html/Imports.java new file mode 100644 index 0000000..65aa2c8 --- /dev/null +++ b/xgen/src/main/java/org/onap/aaf/xgen/html/Imports.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.xgen.html; + +import java.util.ArrayList; +import java.util.List; + +public class Imports implements Thematic{ + List css,js; + public final int backdots; +// public final File webDir; + private String theme; + + public Imports(int backdots) { +// this.webDir = webDir; + + css = new ArrayList(); + js = new ArrayList(); + this.backdots = backdots; + theme = ""; + } + + public Imports css(String str) { + css.add(str); + return this; + } + + public Imports js(String str) { + js.add(str); + return this; + } + + public Imports theme(String str) { + theme = str==null?"":str; + return this; + } + + /** + * Pass in a possible Theme. If it is "" or null, it will resolve to default Theme set in Imports + * + * @param theTheme + * @return + */ + @Override + public String themePath(String theTheme) { + StringBuilder src = dots(new StringBuilder()); + if(theTheme==null||theTheme.length()==0) { + src.append(theme); + if(theme.length()>0)src.append('/'); + } else { + src.append(theTheme); + src.append('/'); + } + + return src.toString(); + } + + /** + * Pass in a possible Theme. If it is "" or null, it will resolve to default Theme set in Imports + * + * @param theTheme + * @return + */ + @Override + public String themeResolve(String theTheme) { + return (theTheme==null||theTheme.length()==0) + ?theme + :theTheme; + } + + public StringBuilder dots(StringBuilder src) { + for(int i=0;i0) ipw.print(' '); + ipw.print(el); + } + } + ipw.println(); + } else { + ipw.print(line.trim()); + } + } + } finally { + htmlGen.setIndent(indent); + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return this; + } + + public JSGen pst(String ... lines) { + return pst(null, lines); + } + + public JSGen pst(Mark jm, String ... lines) { + if(lines.length>0) ipw.append(lines[0]); + ipw.append('('); + for(int i=1;i0)ipw.println(); + ipw.print(lines[i]); + } + ipw.setIndent(current); + ipw.append(';'); + if(htmlGen.pretty)ipw.println(); + return this; + } + + public JSGen text(String text) { + ipw.append(text); + if(htmlGen.pretty)ipw.println(); + return this; + } + + public JSGen function(String name, String ... params) { + return function(null, name, params); + } + + public JSGen jqfunc(Mark mark, String name, String ... params) { + pst(mark,"$").function(name, params); + return this; + } + + public JSGen function(Mark jm, String name, String ... params) { + ipw.print("function "); + ipw.print(name); + ipw.print('('); + for(int i=0;i0)ipw.println(); + ipw.print(lines[i]); + } + ipw.setIndent(current); + ipw.print('{'); + if(htmlGen.pretty) { + ipw.println(); + ipw.inc(); + } + int spot = htmlGen.pushBack(new Back("}",true,true)); + if(jm!=null)jm.spot(spot); + return this; + + } + + + public JSGen comment(String ... lines) { + if(htmlGen.pretty) { + for(int i=0;i { +} diff --git a/xgen/src/main/java/org/onap/aaf/xgen/html/Thematic.java b/xgen/src/main/java/org/onap/aaf/xgen/html/Thematic.java new file mode 100644 index 0000000..01281cb --- /dev/null +++ b/xgen/src/main/java/org/onap/aaf/xgen/html/Thematic.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.xgen.html; + +public interface Thematic { + String themePath(String theTheme); + String themeResolve(String theTheme); +} diff --git a/xgen/src/main/java/org/onap/aaf/xgen/xml/XMLCacheGen.java b/xgen/src/main/java/org/onap/aaf/xgen/xml/XMLCacheGen.java new file mode 100644 index 0000000..066e67a --- /dev/null +++ b/xgen/src/main/java/org/onap/aaf/xgen/xml/XMLCacheGen.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.xgen.xml; + +import java.io.IOException; +import java.io.Writer; + +import org.onap.aaf.inno.env.APIException; +import org.onap.aaf.xgen.CacheGen; +import org.onap.aaf.xgen.Code; + +public class XMLCacheGen extends CacheGen { + + public XMLCacheGen(int flags, Code code) throws APIException, + IOException { + super(flags, code); + } + + @Override + public XMLGen create(int style, Writer w) { + XMLGen xg = new XMLGen(w); + xg.pretty = (style & PRETTY)==PRETTY; + return xg; + } + +} diff --git a/xgen/src/main/java/org/onap/aaf/xgen/xml/XMLGen.java b/xgen/src/main/java/org/onap/aaf/xgen/xml/XMLGen.java new file mode 100644 index 0000000..0707e89 --- /dev/null +++ b/xgen/src/main/java/org/onap/aaf/xgen/xml/XMLGen.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.aaf.xgen.xml; + +import java.io.Writer; + +import org.onap.aaf.xgen.XGen;; + +public class XMLGen extends XGen { + private final String XML_TAG; + + public XMLGen(Writer w) { + this(w,"UTF-8"); + } + + public XMLGen(Writer w, String encoding) { + super(w); + XML_TAG=""; + } + + public XMLGen xml() { + forward.println(XML_TAG); + return this; + } +} -- cgit 1.2.3-korg