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