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.jaxb;
\r
24 import java.io.InputStream;
\r
25 import java.io.Reader;
\r
27 import javax.xml.bind.JAXBException;
\r
28 import javax.xml.validation.Schema;
\r
30 import org.onap.aaf.misc.env.APIException;
\r
31 import org.onap.aaf.misc.env.Env;
\r
32 import org.onap.aaf.misc.env.TimeTaken;
\r
33 import org.onap.aaf.misc.env.old.IOObjectifier;
\r
36 * Allow Extended IO interface usage without muddying up the Stringifier Interface
\r
38 public class JAXBObjectifier<T> implements IOObjectifier<T> {
\r
39 private JAXBumar jumar;
\r
41 public JAXBObjectifier(Schema schema, Class<?>... classes) throws APIException {
\r
43 jumar = new JAXBumar(schema, classes);
\r
44 } catch (JAXBException e) {
\r
45 throw new APIException(e);
\r
49 public JAXBObjectifier(Class<?>... classes) throws APIException {
\r
51 jumar = new JAXBumar(classes);
\r
52 } catch (JAXBException e) {
\r
53 throw new APIException(e);
\r
57 // package on purpose
\r
58 JAXBObjectifier(JAXBumar jumar) {
\r
62 @SuppressWarnings("unchecked")
\r
64 public T objectify(Env env, String input) throws APIException {
\r
65 TimeTaken tt = env.start("JAXB Unmarshal", Env.XML);
\r
67 tt.size(input.length());
\r
68 return (T)jumar.unmarshal(env.debug(), input);
\r
69 } catch (JAXBException e) {
\r
70 throw new APIException(e);
\r
76 @SuppressWarnings("unchecked")
\r
78 public T objectify(Env env, Reader rdr) throws APIException {
\r
79 //TODO create a Reader that Counts?
\r
80 TimeTaken tt = env.start("JAXB Unmarshal", Env.XML);
\r
82 return (T)jumar.unmarshal(env.debug(), rdr);
\r
83 } catch (JAXBException e) {
\r
84 throw new APIException(e);
\r
91 @SuppressWarnings("unchecked")
\r
93 public T objectify(Env env, InputStream is) throws APIException {
\r
94 //TODO create a Reader that Counts?
\r
95 TimeTaken tt = env.start("JAXB Unmarshal", Env.XML);
\r
97 return (T)jumar.unmarshal(env.debug(), is);
\r
98 } catch (JAXBException e) {
\r
99 throw new APIException(e);
\r
106 public void servicePrestart(Env env) throws APIException {
\r
109 public void threadPrestart(Env env) throws APIException {
\r
113 public void refresh(Env env) throws APIException {
\r
117 public void threadDestroy(Env env) throws APIException {
\r
121 public void serviceDestroy(Env env) throws APIException {
\r
125 @SuppressWarnings("unchecked")
\r
126 public T newInstance() throws APIException {
\r
128 return (T)jumar.newInstance();
\r
129 } catch (Exception e) {
\r
130 throw new APIException(e);
\r