2 * ============LICENSE_START====================================================
\r
4 * ===========================================================================
\r
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
\r
6 * ===========================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END====================================================
\r
22 package org.onap.aaf.misc.env;
\r
24 import java.io.IOException;
\r
25 import java.io.InputStream;
\r
26 import java.io.OutputStream;
\r
27 import java.io.Reader;
\r
28 import java.io.Writer;
\r
31 * <i>Data</i> facilitates lazy marshaling of data with a pre-determined
\r
32 * marshaling mechanism.<p>
\r
34 * It stores either Object (defined by Generic {@literal <T>}) or String.<p>
\r
36 * On asking for Object of type {@literal <T>}, it will respond with the object
\r
37 * if it exists, or unmarshal the string and pass the result back.<p>
\r
39 * On asking for String, it will respond with the String
\r
40 * if it exists, or marshal the String and pass the result back.<p>
\r
42 * the "options" available on several functions control the output of this particular call. When
\r
43 * blank, they will default to the DataFactory defaults. When present, they override this
\r
45 * The available options are "pretty" (for XML and JSON) and "fragment" (XML only concept), which drops
\r
46 * the "<?xml ...?>" header so you can create larger XML documents from the output.
\r
52 public interface Data<T> {
\r
53 static enum TYPE {XML,JSON,JAXB,RAW,DEFAULT};
\r
54 // can & with 0xFFFF;
\r
55 // public static final int XML = 0x1;
\r
56 // public static final int JSON = 0x2;
\r
57 // public static final int JAXB = 0x4;
\r
58 // public static final int RAW = 0x1000;
\r
60 // can & with 0xF00000;
\r
61 public static final int PRETTY = 0x100000;
\r
62 public static final int FRAGMENT = 0x200000;
\r
65 * Respond with the String if it exists, or marshal the String and pass the result back.
\r
67 * However, use the Env the Data Object was created with.
\r
70 * @throws APIException
\r
72 public String asString() throws APIException;
\r
75 * Respond with the Object of type {@literal <T>} if it exists, or unmarshal from String
\r
76 * and pass the result back.<p>
\r
78 * However, use the Env the Data Object was created with.
\r
81 * @throws APIException
\r
83 public T asObject() throws APIException;
\r
86 * Set a particular option on an existing Out
\r
88 * if int is negative, it should remove the option
\r
91 public Data<T> option(int option);
\r
93 public Data<T> to(OutputStream os) throws APIException, IOException;
\r
94 public Data<T> to(Writer writer) throws APIException, IOException;
\r
96 public Data<T> load(T t) throws APIException;
\r
97 public Data<T> load(String str) throws APIException;
\r
98 public Data<T> load(InputStream is) throws APIException;
\r
99 public Data<T> load(Reader rdr) throws APIException;
\r
101 public Data<T> in(TYPE type);
\r
102 public Data<T> out(TYPE type);
\r
104 * Return the Class Type supported by this DataObject
\r
106 * @return {@literal Class<T>}
\r
108 public Class<T> getTypeClass();
\r
110 public void direct(InputStream input, OutputStream output) throws APIException, IOException;
\r