summaryrefslogtreecommitdiffstats
path: root/rosetta/src/main/java/com/att/rosetta/marshal
diff options
context:
space:
mode:
Diffstat (limited to 'rosetta/src/main/java/com/att/rosetta/marshal')
-rw-r--r--rosetta/src/main/java/com/att/rosetta/marshal/DataWriter.java140
-rw-r--r--rosetta/src/main/java/com/att/rosetta/marshal/DocMarshal.java84
-rw-r--r--rosetta/src/main/java/com/att/rosetta/marshal/FieldArray.java94
-rw-r--r--rosetta/src/main/java/com/att/rosetta/marshal/FieldBlob.java40
-rw-r--r--rosetta/src/main/java/com/att/rosetta/marshal/FieldDate.java39
-rw-r--r--rosetta/src/main/java/com/att/rosetta/marshal/FieldDateTime.java39
-rw-r--r--rosetta/src/main/java/com/att/rosetta/marshal/FieldHexBinary.java37
-rw-r--r--rosetta/src/main/java/com/att/rosetta/marshal/FieldMarshal.java61
-rw-r--r--rosetta/src/main/java/com/att/rosetta/marshal/FieldNumeric.java38
-rw-r--r--rosetta/src/main/java/com/att/rosetta/marshal/FieldString.java38
-rw-r--r--rosetta/src/main/java/com/att/rosetta/marshal/ListIterator.java60
-rw-r--r--rosetta/src/main/java/com/att/rosetta/marshal/ObjArray.java92
-rw-r--r--rosetta/src/main/java/com/att/rosetta/marshal/ObjMarshal.java129
13 files changed, 891 insertions, 0 deletions
diff --git a/rosetta/src/main/java/com/att/rosetta/marshal/DataWriter.java b/rosetta/src/main/java/com/att/rosetta/marshal/DataWriter.java
new file mode 100644
index 0000000..8d972d8
--- /dev/null
+++ b/rosetta/src/main/java/com/att/rosetta/marshal/DataWriter.java
@@ -0,0 +1,140 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+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 <T>
+ */
+public abstract class DataWriter<T> {
+ public abstract boolean write(T t, StringBuilder sb);
+
+ public final static DataWriter<String> STRING = new DataWriter<String>() {
+ @Override
+ public boolean write(String s, StringBuilder sb) {
+ sb.append(s);
+ return true;
+ }
+ };
+
+ public final static DataWriter<Integer> INTEGER = new DataWriter<Integer>() {
+ @Override
+ public boolean write(Integer i, StringBuilder sb) {
+ sb.append(i);
+ return false;
+ }
+ };
+
+ public final static DataWriter<Long> LONG = new DataWriter<Long>() {
+ @Override
+ public boolean write(Long t, StringBuilder sb) {
+ sb.append(t);
+ return false;
+ }
+ };
+
+ public final static DataWriter<Byte> BYTE = new DataWriter<Byte>() {
+ @Override
+ public boolean write(Byte t, StringBuilder sb) {
+ sb.append(t);
+ return false;
+ }
+ };
+
+ public final static DataWriter<Character> CHAR = new DataWriter<Character>() {
+ @Override
+ public boolean write(Character t, StringBuilder sb) {
+ sb.append(t);
+ return true;
+ }
+ };
+
+ public final static DataWriter<Boolean> BOOL = new DataWriter<Boolean>() {
+ @Override
+ public boolean write(Boolean t, StringBuilder sb) {
+ sb.append(t);
+ return true;
+ }
+ };
+
+
+ /*
+ public final static DataWriter<byte[]> BYTE_ARRAY = new DataWriter<byte[]>() {
+ @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<XMLGregorianCalendar> DATE = new DataWriter<XMLGregorianCalendar>() {
+ @Override
+ public boolean write(XMLGregorianCalendar t, StringBuilder sb) {
+ sb.append(Chrono.dateOnlyStamp(t));
+ return true;
+ }
+ };
+
+ public final static DataWriter<XMLGregorianCalendar> DATE_TIME = new DataWriter<XMLGregorianCalendar>() {
+ @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<byte[]> HEX_BINARY = new DataWriter<byte[]>() {
+ @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<ba.length;++i) {
+ byte b = ba[i];
+ sb.append(chars[((b&0xF0)>>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
new file mode 100644
index 0000000..27a4364
--- /dev/null
+++ b/rosetta/src/main/java/com/att/rosetta/marshal/DocMarshal.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+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<T> extends Marshal<T> {
+ private Marshal<T> root;
+
+ public DocMarshal(Marshal<T> root) {
+ this.root = root;
+ }
+
+ @Override
+ public Parsed<State> parse(T t, Parsed<State> parsed) throws ParseException {
+ Ladder<Iterator<?>> 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<Void> PENDING_ITERATOR = new Iterator<Void>() {
+ @Override
+ public boolean hasNext() {
+ return false;
+ }
+
+ @Override
+ public Void next() {
+ return null;
+ }
+
+ @Override
+ public void remove() {
+ }
+ };
+
+ public static<T> DocMarshal<T> root(Marshal<T> m) {
+ return (DocMarshal<T>)new DocMarshal<T>(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
new file mode 100644
index 0000000..7931e73
--- /dev/null
+++ b/rosetta/src/main/java/com/att/rosetta/marshal/FieldArray.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+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<T,S> extends Marshal<T> {
+ private DataWriter<S> dataWriter;
+ private String name;
+
+ public FieldArray(String name, DataWriter<S> dw) {
+ this.name = name;
+ dataWriter = dw;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Parsed<State> parse(T t, Parsed<State> parsed) throws ParseException {
+ Ladder<Iterator<?>> ladder = parsed.state.ladder;
+ Iterator<?> iter = ladder.peek();
+ if(iter==null) {
+ List<S> list = data(t);
+ if(list.isEmpty() && parsed.state.smallest) {
+ ladder.push(DONE_ITERATOR);
+ } else {
+ ladder.push(new ListIterator<S>(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<S> mems = (ListIterator<S>)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<S> 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
new file mode 100644
index 0000000..b80cb48
--- /dev/null
+++ b/rosetta/src/main/java/com/att/rosetta/marshal/FieldBlob.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.rosetta.marshal;
+
+public abstract class FieldBlob<T> extends FieldMarshal<T>{
+ 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
new file mode 100644
index 0000000..c2a8c03
--- /dev/null
+++ b/rosetta/src/main/java/com/att/rosetta/marshal/FieldDate.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.rosetta.marshal;
+
+import javax.xml.datatype.XMLGregorianCalendar;
+
+public abstract class FieldDate<T> extends FieldMarshal<T> {
+ 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
new file mode 100644
index 0000000..ce14c7f
--- /dev/null
+++ b/rosetta/src/main/java/com/att/rosetta/marshal/FieldDateTime.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.rosetta.marshal;
+
+import javax.xml.datatype.XMLGregorianCalendar;
+
+public abstract class FieldDateTime<T> extends FieldMarshal<T> {
+ 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
new file mode 100644
index 0000000..125f332
--- /dev/null
+++ b/rosetta/src/main/java/com/att/rosetta/marshal/FieldHexBinary.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.rosetta.marshal;
+
+public abstract class FieldHexBinary<T> extends FieldMarshal<T>{
+ 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
new file mode 100644
index 0000000..63ba3b9
--- /dev/null
+++ b/rosetta/src/main/java/com/att/rosetta/marshal/FieldMarshal.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.rosetta.marshal;
+
+
+import com.att.rosetta.Marshal;
+import com.att.rosetta.Parse;
+import com.att.rosetta.Parsed;
+
+public abstract class FieldMarshal<T> extends Marshal<T> {
+ private String name;
+
+ public FieldMarshal(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Parsed<State> parse(T t, Parsed<State> 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
new file mode 100644
index 0000000..b53f12e
--- /dev/null
+++ b/rosetta/src/main/java/com/att/rosetta/marshal/FieldNumeric.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.rosetta.marshal;
+
+public abstract class FieldNumeric<N,T> extends FieldMarshal<T> {
+ 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
new file mode 100644
index 0000000..6fd3424
--- /dev/null
+++ b/rosetta/src/main/java/com/att/rosetta/marshal/FieldString.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.rosetta.marshal;
+
+public abstract class FieldString<T> extends FieldMarshal<T> {
+ 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
new file mode 100644
index 0000000..b444c68
--- /dev/null
+++ b/rosetta/src/main/java/com/att/rosetta/marshal/ListIterator.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+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 <T>
+ */
+final class ListIterator<T> implements Iterator<T> {
+ private T curr;
+ private Iterator<T> delg;
+ public ListIterator(List<T> 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
new file mode 100644
index 0000000..89e07c5
--- /dev/null
+++ b/rosetta/src/main/java/com/att/rosetta/marshal/ObjArray.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+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<T,S> extends Marshal<T> {
+ private String name;
+ private Marshal<S> subMarshaller;
+
+ public ObjArray(String name, Marshal<S> subMarshaller) {
+ this.name = name;
+ this.subMarshaller = subMarshaller;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Parsed<State> parse(T t, Parsed<State> parsed) throws ParseException {
+ Ladder<Iterator<?>> ladder = parsed.state.ladder;
+ Iterator<?> iter = ladder.peek();
+ if(iter==null) {
+ List<S> list = data(t);
+ if(list.isEmpty() && parsed.state.smallest) {
+ ladder.push(DONE_ITERATOR);
+ } else {
+ ladder.push(new ListIterator<S>(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<S> mems = (ListIterator<S>)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<S> 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
new file mode 100644
index 0000000..981dd78
--- /dev/null
+++ b/rosetta/src/main/java/com/att/rosetta/marshal/ObjMarshal.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+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 <T>
+ */
+public abstract class ObjMarshal<T> extends Marshal<T> {
+ // Note: Not Using List or ArrayList, because there is no "Peek" concept in their iterator.
+ private Marshal<T>[] pml;
+ private int end=0;
+
+ /**
+ * @param pm
+ */
+ @SuppressWarnings("unchecked")
+ protected void add(Marshal<T> 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<State> parse(T in, Parsed<State> parsed) throws ParseException {
+ Ladder<Iterator<?>> ladder = parsed.state.ladder;
+ Iterator<Marshal<T>> iter = (Iterator<Marshal<T>>)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<T> 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<Marshal<T>> {
+ private int idx = -1;
+
+ @Override
+ public boolean hasNext() {
+ return idx<end;
+ }
+
+ @Override
+ public Marshal<T> next() {
+ return pml[++idx];
+ }
+
+ public Marshal<T> peek() {
+ return idx<0?null:pml[idx];
+ }
+
+ @Override
+ public void remove() {
+ pml[idx]=null;
+ }
+
+ }
+
+}