Coverage Report - org.apache.camel.converter.jaxb.JaxbConverter
 
Classes in this File Line Coverage Branch Coverage Complexity
JaxbConverter
0% 
0% 
0
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.converter.jaxb;
 18  
 
 19  
 import javax.xml.bind.JAXBContext;
 20  
 import javax.xml.bind.JAXBException;
 21  
 import javax.xml.bind.Marshaller;
 22  
 import javax.xml.bind.annotation.XmlRootElement;
 23  
 import javax.xml.bind.util.JAXBSource;
 24  
 import javax.xml.parsers.ParserConfigurationException;
 25  
 
 26  
 import org.w3c.dom.Document;
 27  
 
 28  
 import org.apache.camel.converter.HasAnnotation;
 29  
 import org.apache.camel.converter.jaxp.XmlConverter;
 30  
 
 31  
 /**
 32  
  * @version $Revision: 563665 $
 33  
  */
 34  0
 public class JaxbConverter {
 35  
     private XmlConverter jaxbConverter;
 36  
 
 37  
     public XmlConverter getJaxbConverter() {
 38  0
         if (jaxbConverter == null) {
 39  0
             jaxbConverter = new XmlConverter();
 40  
         }
 41  0
         return jaxbConverter;
 42  
     }
 43  
 
 44  
     public void setJaxbConverter(XmlConverter jaxbConverter) {
 45  0
         this.jaxbConverter = jaxbConverter;
 46  0
     }
 47  
 
 48  
     public static JAXBSource toSource(@HasAnnotation(XmlRootElement.class)Object value) throws JAXBException {
 49  0
         JAXBContext context = createJaxbContext(value);
 50  0
         return new JAXBSource(context, value);
 51  
     }
 52  
 
 53  
     public Document toDocument(@HasAnnotation(XmlRootElement.class)Object value) throws JAXBException, ParserConfigurationException {
 54  0
         JAXBContext context = createJaxbContext(value);
 55  0
         Marshaller marshaller = context.createMarshaller();
 56  
 
 57  0
         Document doc = getJaxbConverter().createDocument();
 58  0
         marshaller.marshal(value, doc);
 59  0
         return doc;
 60  
     }
 61  
 
 62  
     protected static JAXBContext createJaxbContext(Object value) throws JAXBException {
 63  0
         if (value == null) {
 64  0
             throw new IllegalArgumentException("Cannot convert from null value to JAXBSource");
 65  
         }
 66  0
         JAXBContext context = JAXBContext.newInstance(value.getClass());
 67  0
         return context;
 68  
     }
 69  
 
 70  
 //    public void write(OutputStream out, Object value) throws JAXBException {
 71  
 //        JAXBContext context = JAXBContext.newInstance(value.getClass());
 72  
 //        Marshaller marshaller = context.createMarshaller();
 73  
 //        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
 74  
 //        marshaller.marshal(value, out);
 75  
 //    }
 76  
 
 77  
 }