/** * ============LICENSE_START==================================================== * org.onap.aaf * =========================================================================== * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. * =========================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END==================================================== * */ package org.onap.aaf.misc.env.jaxb; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; import java.io.Writer; import javax.xml.bind.JAXBException; import org.onap.aaf.misc.env.APIException; import org.onap.aaf.misc.env.Data; import org.onap.aaf.misc.env.Env; import org.onap.aaf.misc.env.EnvJAXB; import org.onap.aaf.misc.env.old.IOStringifier; import org.onap.aaf.misc.env.old.Objectifier; import org.onap.aaf.misc.env.old.Stringifier; /** *
*
* It stores either Object (defined by Generic {@literal
*
* On asking for Object of type {@literal
*
* On asking for String, it will respond with the String
* if it exists, or marshal the String and pass the result back.
*
* @author Jonathan
*
* @param
*
* Explicitly use a specific Env for logging purposes
*
* @param env
* @return String
* @throws APIException
*/
public String asString(EnvJAXB env) throws APIException {
if (dataAsString!=null) {
return dataAsString;
} else {
return dataAsString = stringifier.stringify(env, dataAsObject);
}
}
/**
* Respond with the String if it exists, or marshal the String and pass the result back.
*
* However, use the Env the Data Object was created with.
*
* @return String
* @throws APIException
*/
// @Override
public String asString() throws APIException {
if (dataAsString!=null) {
return dataAsString;
} else {
return dataAsString = stringifier.stringify(creatingEnv, dataAsObject,options);
}
}
public Data
*
* Explicitly use a specific Env for logging purposes
*
* @param env
* @return T
* @throws APIException
*/
public T asObject(EnvJAXB env) throws APIException {
if (dataAsObject !=null) {
return dataAsObject;
} else {
// Some Java compilers need two statements here
dataAsObject = objectifier.objectify(env, dataAsString);
return dataAsObject;
}
}
/**
* Respond with the Object of type {@literal
*
* However, use the Env the Data Object was created with.
*
* @return T
* @throws APIException
*/
// @Override
public T asObject() throws APIException {
if (dataAsObject !=null) {
return dataAsObject;
} else {
// Some Java compilers need two statements here
dataAsObject = objectifier.objectify(creatingEnv, dataAsString);
return dataAsObject;
}
}
/**
* Return the Class Type supported by this DataObject
*
* @return {@literal Class
* Since toString() must not throw exceptions, the function just catches and prints an
* error, which is probably not the behavior desired.
*
* Therefore, use "asString()" where possible in actual Transactional code.
*
* @see java.lang.Object#toString()
*/
// @Override
public String toString() {
if (dataAsString!=null) {
return dataAsString;
} else {
try {
return dataAsString = stringifier.stringify(creatingEnv, dataAsObject);
} catch (APIException e) {
return "ERROR - Can't Stringify from Object " + e.getLocalizedMessage();
}
}
}
public Data