Return-Path: Delivered-To: apmail-ws-juddi-cvs-archive@www.apache.org Received: (qmail 37227 invoked from network); 10 Apr 2009 00:53:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Apr 2009 00:53:20 -0000 Received: (qmail 36671 invoked by uid 500); 10 Apr 2009 00:53:20 -0000 Delivered-To: apmail-ws-juddi-cvs-archive@ws.apache.org Received: (qmail 36630 invoked by uid 500); 10 Apr 2009 00:53:20 -0000 Mailing-List: contact juddi-cvs-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list juddi-cvs@ws.apache.org Received: (qmail 36620 invoked by uid 99); 10 Apr 2009 00:53:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Apr 2009 00:53:20 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Apr 2009 00:53:18 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2100E2388975; Fri, 10 Apr 2009 00:52:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r763842 - in /webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/util: ./ JAXBMarshaller.java Date: Fri, 10 Apr 2009 00:52:57 -0000 To: juddi-cvs@ws.apache.org From: jfaath@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090410005257.2100E2388975@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jfaath Date: Fri Apr 10 00:52:56 2009 New Revision: 763842 URL: http://svn.apache.org/viewvc?rev=763842&view=rev Log: adding JAXBMarshaller utility to easily move data in and out of JAXBObjects Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/util/ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/util/JAXBMarshaller.java (with props) Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/util/JAXBMarshaller.java URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/util/JAXBMarshaller.java?rev=763842&view=auto ============================================================================== --- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/util/JAXBMarshaller.java (added) +++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/util/JAXBMarshaller.java Fri Apr 10 00:52:56 2009 @@ -0,0 +1,104 @@ +/* + * Copyright 2001-2008 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.util; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; + +import org.apache.log4j.Logger; + +/** + * @author Jeff Faath + */ +public class JAXBMarshaller { + private static Logger logger = Logger.getLogger(JAXBMarshaller.class); + + private static final Map JAXBContexts = new HashMap(); + static { + try { + JAXBContexts.put("org.uddi.api_v3", JAXBContext.newInstance("org.uddi.api_v3")); + JAXBContexts.put("org.uddi.sub_v3", JAXBContext.newInstance("org.uddi.sub_v3")); + } catch (JAXBException e) { + logger.error("Initial entityManagerFactory creation failed:" + e, e); + throw new ExceptionInInitializerError(e); + } + } + + + @SuppressWarnings("unchecked") + public static Object unmarshallFromInputStream(InputStream inputStream, String thePackage) throws JAXBException { + Object obj = null; + if (inputStream != null) { + JAXBContext jc = JAXBContexts.get(thePackage); + Unmarshaller unmarshaller = jc.createUnmarshaller(); + obj = ((JAXBElement)unmarshaller.unmarshal(inputStream)).getValue(); + } + else + logger.error("A null input stream was provided"); + + return obj; + + } + + public static Object unmarshallFromFileResource(String fileName, String thePackage) throws JAXBException, IOException { + Object obj = null; + URL url = Thread.currentThread().getContextClassLoader().getResource(fileName); + if (url==null) { + logger.error("Could not find resource: " + fileName); + } else { + InputStream resourceStream =url.openStream(); + + obj = unmarshallFromInputStream(resourceStream, thePackage); + } + return obj; + } + + public static Object unmarshallFromString(String rawObject, String thePackage) throws JAXBException { + Object obj = null; + if (rawObject != null && rawObject.length() > 0) { + ByteArrayInputStream bais = new ByteArrayInputStream(rawObject.getBytes()); + obj = unmarshallFromInputStream(bais, thePackage); + } + else + logger.error("The raw object provided is null or empty"); + return obj; + } + + public static String marshallToString(Object object, String thePackage) throws JAXBException { + String rawObject = null; + + JAXBContext jc = JAXBContexts.get(thePackage); + Marshaller marshaller = jc.createMarshaller(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + marshaller.marshal(object, baos); + rawObject = baos.toString(); + + return rawObject; + } + +} Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/util/JAXBMarshaller.java ------------------------------------------------------------------------------ svn:mime-type = text/plain --------------------------------------------------------------------- To unsubscribe, e-mail: juddi-cvs-unsubscribe@ws.apache.org For additional commands, e-mail: juddi-cvs-help@ws.apache.org