1 /* 2 * Copyright 2001-2009 The Apache Software Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 package org.apache.juddi.jaxb; 16 17 import java.io.StringWriter; 18 import javax.xml.bind.JAXB; 19 20 21 /** 22 * This is for printing UDDI v3 objects from the spec.<br><br> 23 * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a> 24 * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a> 25 * @see javax.xml.bind.JAXB 26 * @param <T> 27 */ 28 public class PrintUDDI<T> { 29 30 /* static JAXBContext jaxbContext = null; 31 32 private Marshaller getUDDIMarshaller() throws JAXBException { 33 if (jaxbContext==null) { 34 jaxbContext=JAXBContext.newInstance("org.uddi.api_v3"); 35 } 36 Marshaller marshaller = jaxbContext.createMarshaller(); 37 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); 38 marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); 39 marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); 40 41 return marshaller; 42 } 43 */ 44 /** 45 * Prints a UDDI entity. 46 * @param UDDIEntity 47 * @return Marshalled XML as a string 48 * @throws IllegalArgumentException 49 */ 50 public String print(T UDDIEntity) { 51 if (UDDIEntity==null) 52 throw new IllegalArgumentException(); 53 StringWriter sw = new StringWriter(); 54 JAXB.marshal(UDDIEntity, sw); 55 return sw.toString(); 56 /*String xml = ""; 57 @SuppressWarnings("unchecked") 58 Class<T> type = (Class<T>) UDDIEntity.getClass(); 59 try { 60 StringWriter writer = new StringWriter(); 61 JAXBElement<T> element = new JAXBElement<T>(new QName("",UDDIEntity.getClass().getName()),type,UDDIEntity); 62 getUDDIMarshaller().marshal(element,writer); 63 xml=writer.toString(); 64 } catch (JAXBException je) { 65 66 } 67 return xml;*/ 68 } 69 70 }