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.env;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.io.OutputStream;
27 import java.io.Reader;
28 import java.io.Writer;
31 * <i>Data</i> facilitates lazy marshaling of data with a pre-determined
32 * marshaling mechanism.<p>
34 * It stores either Object (defined by Generic {@literal <T>}) or String.<p>
36 * On asking for Object of type {@literal <T>}, it will respond with the object
37 * if it exists, or unmarshal the string and pass the result back.<p>
39 * On asking for String, it will respond with the String
40 * if it exists, or marshal the String and pass the result back.<p>
42 * the "options" available on several functions control the output of this particular call. When
43 * blank, they will default to the DataFactory defaults. When present, they override this
45 * The available options are "pretty" (for XML and JSON) and "fragment" (XML only concept), which drops
46 * the "<?xml ...?>" header so you can create larger XML documents from the output.
52 public interface Data<T> {
53 static enum TYPE {XML,JSON,JAXB,RAW,DEFAULT};
55 // public static final int XML = 0x1;
56 // public static final int JSON = 0x2;
57 // public static final int JAXB = 0x4;
58 // public static final int RAW = 0x1000;
60 // can & with 0xF00000;
61 public static final int PRETTY = 0x100000;
62 public static final int FRAGMENT = 0x200000;
65 * Respond with the String if it exists, or marshal the String and pass the result back.
67 * However, use the Env the Data Object was created with.
70 * @throws APIException
72 public String asString() throws APIException;
75 * Respond with the Object of type {@literal <T>} if it exists, or unmarshal from String
76 * and pass the result back.<p>
78 * However, use the Env the Data Object was created with.
81 * @throws APIException
83 public T asObject() throws APIException;
86 * Set a particular option on an existing Out
88 * if int is negative, it should remove the option
91 public Data<T> option(int option);
93 public Data<T> to(OutputStream os) throws APIException, IOException;
94 public Data<T> to(Writer writer) throws APIException, IOException;
96 public Data<T> load(T t) throws APIException;
97 public Data<T> load(String str) throws APIException;
98 public Data<T> load(InputStream is) throws APIException;
99 public Data<T> load(Reader rdr) throws APIException;
101 public Data<T> in(TYPE type);
102 public Data<T> out(TYPE type);
104 * Return the Class Type supported by this DataObject
106 * @return {@literal Class<T>}
108 public Class<T> getTypeClass();
110 public void direct(InputStream input, OutputStream output) throws APIException, IOException;