All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.juddi.jaxb.PrintJUDDI Maven / Gradle / Ivy

/*
 * Copyright 2001-2009 The Apache Software Foundation.
 * 
 * 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.
 */
package org.apache.juddi.jaxb;

import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;

/**
 * This is for printing jUDDI specific data objects only
 * @author Alex O'Ree
 * @param 
 */
public class PrintJUDDI {

	static JAXBContext jaxbContext = null;
	
	private Marshaller getUDDIMarshaller() throws JAXBException {
		if (jaxbContext==null) {
			jaxbContext=JAXBContext.newInstance("org.apache.juddi.api_v3");
		}
		Marshaller marshaller = jaxbContext.createMarshaller();
		marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
		marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
		marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
		
		return marshaller;
	}
	
	public String print(T UDDIEntity) {
		String xml = "";
		@SuppressWarnings("unchecked")
		Class type = (Class) UDDIEntity.getClass();
		try {
			StringWriter writer = new StringWriter();
			JAXBElement element = new JAXBElement(new QName("",UDDIEntity.getClass().getName()),type,UDDIEntity);
			getUDDIMarshaller().marshal(element,writer);
			xml=writer.toString();
		} catch (JAXBException je) {
			
		}
		return xml;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy