2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.misc.rosetta.marshal;
24 import java.util.Iterator;
25 import java.util.NoSuchElementException;
27 import org.onap.aaf.misc.rosetta.Ladder;
28 import org.onap.aaf.misc.rosetta.Marshal;
29 import org.onap.aaf.misc.rosetta.ParseException;
30 import org.onap.aaf.misc.rosetta.Parsed;
32 public class DocMarshal<T> extends Marshal<T> {
33 private Marshal<T> root;
35 public DocMarshal(Marshal<T> root) {
40 public Parsed<State> parse(T t, Parsed<State> parsed) throws ParseException {
41 Ladder<Iterator<?>> ladder = parsed.state.ladder;
42 Iterator<?> iter = ladder.peek();
44 ladder.push(PENDING_ITERATOR);
45 parsed.event = START_DOC;
46 } else if (DONE_ITERATOR.equals(iter)) {
48 ladder.ascend(); // look at field info
49 Iterator<?> currFieldIter = ladder.peek();
50 if(!DONE_ITERATOR.equals(currFieldIter)){
51 parsed = root.parse(t, parsed);
54 if(DONE_ITERATOR.equals(currFieldIter) || parsed.event==NONE) {
55 parsed.event = END_DOC;
56 ladder.push(DONE_ITERATOR);
59 return parsed; // if unchanged, then it will end process
63 public static final Iterator<Void> PENDING_ITERATOR = new Iterator<Void>() {
65 public boolean hasNext() {
72 throw new NoSuchElementException();
78 public void remove() {
82 public static<T> DocMarshal<T> root(Marshal<T> m) {
83 return (DocMarshal<T>)new DocMarshal<T>(m);