AT&T 2.0.19 Code drop, stage 1
[aaf/authz.git] / misc / env / src / main / java / org / onap / aaf / misc / env / Data.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
19  *
20  */
21
22 package org.onap.aaf.misc.env;
23
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;
29 /**
30  * <H1>Data</H1>
31  * <i>Data</i> facilitates lazy marshaling of data with a pre-determined
32  * marshaling mechanism.<p>
33  * 
34  * It stores either Object (defined by Generic {@literal <T>}) or String.<p>  
35  * 
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>
38  * 
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>
41  *
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
44  * particular call.
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. 
47  * 
48  * @author Jonathan
49  *
50  * @param <T>
51  */
52 public interface Data<T> {
53         static enum TYPE {XML,JSON,JAXB,RAW,DEFAULT};
54         // can & with 0xFFFF;
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;
59         
60         // can & with 0xF00000;
61         public static final int PRETTY = 0x100000;
62         public static final int FRAGMENT = 0x200000;
63
64         /**
65          * Respond with the String if it exists, or marshal the String and pass the result back.
66          * 
67          * However, use the Env the Data Object was created with.
68          * 
69          * @return String
70          * @throws APIException
71          */
72         public String asString() throws APIException;
73
74         /**
75          * Respond with the Object of type {@literal <T>} if it exists, or unmarshal from String 
76          * and pass the result back.<p>
77          *
78          * However, use the Env the Data Object was created with.
79          * 
80          * @return T
81          * @throws APIException
82          */
83         public T asObject() throws APIException;
84
85         /**
86          * Set a particular option on an existing Out 
87          * 
88          * if int is negative, it should remove the option
89          * @param option
90          */
91         public Data<T> option(int option);
92
93         public Data<T> to(OutputStream os) throws APIException, IOException;
94         public Data<T> to(Writer writer) throws APIException, IOException;
95         
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;
100         
101         public Data<T> in(TYPE type);
102         public Data<T> out(TYPE type);
103         /**
104          * Return the Class Type supported by this DataObject
105          * 
106          * @return {@literal Class<T>}
107          */
108         public Class<T> getTypeClass();
109
110         public void direct(InputStream input, OutputStream output) throws APIException, IOException;
111
112
113 }