1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 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
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.inno.env.jaxb;
\r
25 import java.io.InputStream;
\r
26 import java.io.Reader;
\r
28 import javax.xml.bind.JAXBException;
\r
29 import javax.xml.validation.Schema;
\r
31 import org.onap.aaf.inno.env.APIException;
\r
32 import org.onap.aaf.inno.env.Env;
\r
33 import org.onap.aaf.inno.env.TimeTaken;
\r
34 import org.onap.aaf.inno.env.old.IOObjectifier;
\r
37 * Allow Extended IO interface usage without muddying up the Stringifier Interface
\r
39 public class JAXBObjectifier<T> implements IOObjectifier<T> {
\r
40 private JAXBumar jumar;
\r
42 public JAXBObjectifier(Schema schema, Class<?>... classes) throws APIException {
\r
44 jumar = new JAXBumar(schema, classes);
\r
45 } catch (JAXBException e) {
\r
46 throw new APIException(e);
\r
50 public JAXBObjectifier(Class<?>... classes) throws APIException {
\r
52 jumar = new JAXBumar(classes);
\r
53 } catch (JAXBException e) {
\r
54 throw new APIException(e);
\r
58 // package on purpose
\r
59 JAXBObjectifier(JAXBumar jumar) {
\r
63 @SuppressWarnings("unchecked")
\r
65 public T objectify(Env env, String input) throws APIException {
\r
66 TimeTaken tt = env.start("JAXB Unmarshal", Env.XML);
\r
68 tt.size(input.length());
\r
69 return (T)jumar.unmarshal(env.debug(), input);
\r
70 } catch (JAXBException e) {
\r
71 throw new APIException(e);
\r
77 @SuppressWarnings("unchecked")
\r
79 public T objectify(Env env, Reader rdr) throws APIException {
\r
80 //TODO create a Reader that Counts?
\r
81 TimeTaken tt = env.start("JAXB Unmarshal", Env.XML);
\r
83 return (T)jumar.unmarshal(env.debug(), rdr);
\r
84 } catch (JAXBException e) {
\r
85 throw new APIException(e);
\r
92 @SuppressWarnings("unchecked")
\r
94 public T objectify(Env env, InputStream is) throws APIException {
\r
95 //TODO create a Reader that Counts?
\r
96 TimeTaken tt = env.start("JAXB Unmarshal", Env.XML);
\r
98 return (T)jumar.unmarshal(env.debug(), is);
\r
99 } catch (JAXBException e) {
\r
100 throw new APIException(e);
\r
107 public void servicePrestart(Env env) throws APIException {
\r
110 public void threadPrestart(Env env) throws APIException {
\r
114 public void refresh(Env env) throws APIException {
\r
118 public void threadDestroy(Env env) throws APIException {
\r
122 public void serviceDestroy(Env env) throws APIException {
\r
126 @SuppressWarnings("unchecked")
\r
127 public T newInstance() throws APIException {
\r
129 return (T)jumar.newInstance();
\r
130 } catch (Exception e) {
\r
131 throw new APIException(e);
\r