Return-Path: Delivered-To: apmail-incubator-cxf-commits-archive@locus.apache.org Received: (qmail 51073 invoked from network); 3 Aug 2007 09:04:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Aug 2007 09:04:57 -0000 Received: (qmail 5568 invoked by uid 500); 3 Aug 2007 09:04:56 -0000 Delivered-To: apmail-incubator-cxf-commits-archive@incubator.apache.org Received: (qmail 5442 invoked by uid 500); 3 Aug 2007 09:04:56 -0000 Mailing-List: contact cxf-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cxf-dev@incubator.apache.org Delivered-To: mailing list cxf-commits@incubator.apache.org Received: (qmail 5433 invoked by uid 99); 3 Aug 2007 09:04:56 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Aug 2007 02:04:56 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Aug 2007 09:04:35 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 670A11A981A; Fri, 3 Aug 2007 02:04:32 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r562394 - /incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java Date: Fri, 03 Aug 2007 09:04:32 -0000 To: cxf-commits@incubator.apache.org From: ema@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070803090432.670A11A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ema Date: Fri Aug 3 02:04:31 2007 New Revision: 562394 URL: http://svn.apache.org/viewvc?view=rev&rev=562394 Log: When the schema is complex and big size , JAXBContextInitializer can not load all the classes that jaxb needed . Added method in JAXBDataBinging to load extra ObjectFactory class Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java?view=diff&rev=562394&r1=562393&r2=562394 ============================================================================== --- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java (original) +++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java Fri Aug 3 02:04:31 2007 @@ -34,6 +34,7 @@ import java.util.Map; import java.util.ResourceBundle; import java.util.Set; +import java.util.regex.Pattern; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; @@ -169,16 +170,37 @@ initializer.walk(); } - try { - String tns = service.getName().getNamespaceURI(); + + String tns = service.getName().getNamespaceURI(); + JAXBContext ctx = null; + try { if (service.getServiceInfos().size() > 0) { tns = service.getServiceInfos().get(0).getInterface().getName().getNamespaceURI(); } - setContext(createJAXBContext(contextClasses, tns)); + ctx = createJAXBContext(contextClasses, tns); } catch (JAXBException e1) { - throw new ServiceConstructionException(e1); + //load jaxb needed class and try to create jaxb context for more times + boolean added = addJaxbObjectFactory(e1); + while (ctx == null && added) { + try { + synchronized (JAXBCONTEXT_CACHE) { + ctx = JAXBContext.newInstance(contextClasses.toArray(new Class[contextClasses.size()]) + , null); + JAXBCONTEXT_CACHE.put(contextClasses, ctx); + } + } catch (JAXBException e) { + e1 = e; + added = addJaxbObjectFactory(e1); + } + } + if (ctx == null) { + throw new ServiceConstructionException(e1); + } } + setContext(ctx); + + for (ServiceInfo serviceInfo : service.getServiceInfos()) { XmlSchemaCollection col = (XmlSchemaCollection)serviceInfo .getProperty(WSDLServiceBuilder.WSDL_SCHEMA_LIST); @@ -367,4 +389,36 @@ } } } + + + //Now we can not add all the classes that Jaxb needed into JaxbContext, especially when + //an ObjectFactroy is pointed by an jaxb @XmlElementDecl annotation + //added this workaround method to load the jaxb needed OjbectFactory class + public boolean addJaxbObjectFactory(JAXBException e1) { + boolean added = false; + java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream(); + java.io.PrintStream pout = new java.io.PrintStream(bout); + e1.printStackTrace(pout); + String str = new String(bout.toByteArray()); + Pattern pattern = Pattern.compile("(?<=There's\\sno\\sObjectFactory\\swith\\san\\s" + + "@XmlElementDecl\\sfor\\sthe\\selement\\s\\{)\\S*(?=\\})"); + java.util.regex.Matcher matcher = pattern.matcher(str); + while (matcher.find()) { + String pkgName = JAXBUtils.namespaceURIToPackage(matcher.group()); + try { + Class clz = getClass().getClassLoader().loadClass(pkgName + "." + "ObjectFactory"); + + if (!contextClasses.contains(clz)) { + contextClasses.add(clz); + added = true; + } + } catch (ClassNotFoundException e) { + //do nothing + } + + } + return added; + } + + }