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.OutputStream;
25 import java.io.StringWriter;
26 import java.io.Writer;
28 import javax.xml.bind.JAXBException;
29 import javax.xml.namespace.QName;
31 import org.onap.aaf.misc.env.APIException;
32 import org.onap.aaf.misc.env.Env;
33 import org.onap.aaf.misc.env.TimeTaken;
34 import org.onap.aaf.misc.env.old.IOStringifier;
36 public class JAXBStringifier<T> implements IOStringifier<T> {
39 public JAXBStringifier(Class<?>... classes) throws APIException {
41 jmar = new JAXBmar(classes);
42 } catch (JAXBException e) {
43 throw new APIException(e);
47 public JAXBStringifier(QName qname, Class<?>... classes)
50 jmar = new JAXBmar(qname, classes);
51 } catch (JAXBException e) {
52 throw new APIException(e);
57 JAXBStringifier(JAXBmar jmar) {
62 public void stringify(Env env, T input, Writer writer, boolean ... options)
64 TimeTaken tt = env.start("JAXB Marshal", Env.XML);
66 jmar.marshal(env.debug(), input, writer, options);
67 } catch (JAXBException e) {
68 throw new APIException(e);
75 public void stringify(Env env, T input, OutputStream os, boolean ... options)
77 // TODO create an OutputStream that Counts?
78 TimeTaken tt = env.start("JAXB Marshal", Env.XML);
80 jmar.marshal(env.debug(), input, os, options);
81 } catch (JAXBException e) {
82 throw new APIException(e);
89 public String stringify(Env env, T input, boolean ... options) throws APIException {
90 TimeTaken tt = env.start("JAXB Marshal", Env.XML);
91 StringWriter sw = new StringWriter();
93 jmar.marshal(env.debug(), input, sw, options);
94 String rv = sw.toString();
97 } catch (JAXBException e) {
99 throw new APIException(e);
106 public void servicePrestart(Env env) throws APIException {
110 public void threadPrestart(Env env) throws APIException {
114 public void refresh(Env env) throws APIException {
118 public void threadDestroy(Env env) throws APIException {
122 public void serviceDestroy(Env env) throws APIException {
126 public JAXBStringifier<T> pretty(boolean pretty) {
132 public JAXBStringifier<T> asFragment(boolean fragment) {
133 jmar.asFragment(fragment);