Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5AF37D165 for ; Tue, 25 Sep 2012 11:21:37 +0000 (UTC) Received: (qmail 47590 invoked by uid 500); 25 Sep 2012 11:21:37 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 47484 invoked by uid 500); 25 Sep 2012 11:21:36 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 47473 invoked by uid 99); 25 Sep 2012 11:21:36 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Sep 2012 11:21:36 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.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; Tue, 25 Sep 2012 11:21:32 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 87B6723888E4; Tue, 25 Sep 2012 11:20:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1389808 - in /cxf/branches/2.6.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ rt... Date: Tue, 25 Sep 2012 11:20:48 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120925112048.87B6723888E4@eris.apache.org> Author: sergeyb Date: Tue Sep 25 11:20:47 2012 New Revision: 1389808 URL: http://svn.apache.org/viewvc?rev=1389808&view=rev Log: Merged revisions 1389791-1389792 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1389791 | sergeyb | 2012-09-25 11:58:08 +0100 (Tue, 25 Sep 2012) | 1 line [CXF-4519] Adding an option to set type-specific schemas on JAXB providers ........ r1389792 | sergeyb | 2012-09-25 11:58:45 +0100 (Tue, 25 Sep 2012) | 1 line [CXF-4519] Adding an option to set type-specific schemas on JAXB providers, one more commit ........ Modified: cxf/branches/2.6.x-fixes/ (props changed) cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml Propchange: cxf/branches/2.6.x-fixes/ ------------------------------------------------------------------------------ Merged /cxf/trunk:r1389791-1389792 Propchange: cxf/branches/2.6.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=1389808&r1=1389807&r2=1389808&view=diff ============================================================================== --- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java (original) +++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java Tue Sep 25 11:20:47 2012 @@ -111,8 +111,11 @@ public abstract class AbstractJAXBProvid private Map, JAXBContext> classContexts = new HashMap, JAXBContext>(); private MessageContext mc; + private Schema schema; private String catalogLocation; + private Map schemaHandlers; + private String collectionWrapperName; private Map collectionWrapperMap; private List jaxbElementClassNames = Collections.emptyList(); @@ -370,6 +373,11 @@ public abstract class AbstractJAXBProvid return unmarshalAsJaxbElement && type != Response.class; } + @Deprecated + public void setSchemas(List locations) { + setSchemaLocations(locations); + } + public void setSchemaLocations(List locations) { schema = SchemaHandler.createSchema(locations, catalogLocation, getBus()); } @@ -378,7 +386,15 @@ public abstract class AbstractJAXBProvid this.catalogLocation = name; } - public void setSchema(Schema s) { + public void setSchemaHandler(SchemaHandler handler) { + setSchema(handler.getSchema()); + } + + public void setSchemaHandlers(Map handlers) { + schemaHandlers = handlers; + } + + protected void setSchema(Schema s) { schema = s; } @@ -490,8 +506,9 @@ public abstract class AbstractJAXBProvid JAXBContext context = isCollection ? getCollectionContext(cls) : getJAXBContext(cls, genericType); Unmarshaller unmarshaller = context.createUnmarshaller(); - if (schema != null) { - unmarshaller.setSchema(schema); + Schema theSchema = getSchema(cls); + if (theSchema != null) { + unmarshaller.setSchema(theSchema); } if (eventHandler != null) { unmarshaller.setEventHandler(eventHandler); @@ -521,18 +538,21 @@ public abstract class AbstractJAXBProvid if (marshallerListener != null) { marshaller.setListener(marshallerListener); } - validateObjectIfNeeded(marshaller, obj); + validateObjectIfNeeded(marshaller, cls, obj); return marshaller; } - protected void validateObjectIfNeeded(Marshaller marshaller, Object obj) + protected void validateObjectIfNeeded(Marshaller marshaller, Class cls, Object obj) throws JAXBException { - if (validateOutput && schema != null) { - marshaller.setEventHandler(eventHandler); - marshaller.setSchema(schema); - if (validateBeforeWrite) { - marshaller.marshal(obj, new DefaultHandler()); - marshaller.setSchema(null); + if (validateOutput) { + Schema theSchema = getSchema(cls); + if (theSchema != null) { + marshaller.setEventHandler(eventHandler); + marshaller.setSchema(theSchema); + if (validateBeforeWrite) { + marshaller.marshal(obj, new DefaultHandler()); + marshaller.setSchema(null); + } } } } @@ -556,7 +576,21 @@ public abstract class AbstractJAXBProvid } protected Schema getSchema() { - return schema; + return getSchema(null); + } + + protected Schema getSchema(Class cls) { + // deal with the typical default case first + if (schema == null && schemaHandlers == null) { + return null; + } + + if (schema != null) { + return schema; + } else { + SchemaHandler handler = schemaHandlers.get(cls.getName()); + return handler != null ? handler.getSchema() : null; + } } Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=1389808&r1=1389807&r2=1389808&view=diff ============================================================================== --- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java (original) +++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java Tue Sep 25 11:20:47 2012 @@ -66,7 +66,6 @@ import org.apache.cxf.jaxrs.utils.Annota import org.apache.cxf.jaxrs.utils.HttpUtils; import org.apache.cxf.jaxrs.utils.InjectionUtils; import org.apache.cxf.jaxrs.utils.JAXBUtils; -import org.apache.cxf.jaxrs.utils.schemas.SchemaHandler; import org.apache.cxf.message.Attachment; import org.apache.cxf.message.Message; import org.apache.cxf.staxutils.DepthExceededStaxException; @@ -131,14 +130,6 @@ public class JAXBElementProvider exte super.setProduceMediaTypes(types); } - public void setSchemas(List locations) { - super.setSchemaLocations(locations); - } - - public void setSchemaHandler(SchemaHandler handler) { - super.setSchema(handler.getSchema()); - } - public void setMarshallerProperties(Map marshallProperties) { mProperties = marshallProperties; } Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1389808&r1=1389807&r2=1389808&view=diff ============================================================================== --- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java (original) +++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java Tue Sep 25 11:20:47 2012 @@ -847,12 +847,12 @@ public final class ProviderFactory { public void setSchemaLocations(List schemas) { boolean schemasMethodAvailable = false; for (ProviderInfo> r : messageReaders) { - schemasMethodAvailable = injectProviderProperty(r.getProvider(), "setSchemas", + schemasMethodAvailable = injectProviderProperty(r.getProvider(), "setSchemaLocations", List.class, schemas); } if (!schemasMethodAvailable) { for (ProviderInfo> r : jaxbReaders) { - schemasMethodAvailable = injectProviderProperty(r.getProvider(), "setSchemas", + schemasMethodAvailable = injectProviderProperty(r.getProvider(), "setSchemaLocations", List.class, schemas); } } Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java?rev=1389808&r1=1389807&r2=1389808&view=diff ============================================================================== --- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java (original) +++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java Tue Sep 25 11:20:47 2012 @@ -63,7 +63,12 @@ public class SchemaHandler { bus = b; } + @Deprecated public void setSchemas(List locations) { + setSchemaLocations(locations); + } + + public void setSchemaLocations(List locations) { schema = createSchema(locations, catalogLocation, bus == null ? BusFactory.getThreadDefaultBus() : bus); } Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java?rev=1389808&r1=1389807&r2=1389808&view=diff ============================================================================== --- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java (original) +++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java Tue Sep 25 11:20:47 2012 @@ -1169,7 +1169,7 @@ public class JAXBElementProviderTest ext JAXBElementProvider provider = new JAXBElementProvider(); List locations = new ArrayList(); locations.add("classpath:/test.xsd"); - provider.setSchemas(locations); + provider.setSchemaLocations(locations); Schema s = provider.getSchema(); assertNotNull("schema can not be read from classpath", s); } @@ -1181,7 +1181,7 @@ public class JAXBElementProviderTest ext String loc = getClass().getClassLoader().getResource("test.xsd").toURI().getPath(); locations.add("file:" + loc); - provider.setSchemas(locations); + provider.setSchemaLocations(locations); Schema s = provider.getSchema(); assertNotNull("schema can not be read from disk", s); } @@ -1192,7 +1192,7 @@ public class JAXBElementProviderTest ext List locations = new ArrayList(); String loc = getClass().getClassLoader().getResource("book1.xsd").toURI().getPath(); locations.add(loc); - provider.setSchemas(locations); + provider.setSchemaLocations(locations); Schema s = provider.getSchema(); assertNotNull("schema can not be read from disk", s); @@ -1214,7 +1214,7 @@ public class JAXBElementProviderTest ext List locations = new ArrayList(); String loc = getClass().getClassLoader().getResource("test.xsd").toURI().getPath(); locations.add("file:" + loc); - provider.setSchemas(locations); + provider.setSchemaLocations(locations); Schema s = provider.getSchema(); assertNotNull("schema can not be read from disk", s); Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java?rev=1389808&r1=1389807&r2=1389808&view=diff ============================================================================== --- cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java (original) +++ cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java Tue Sep 25 11:20:47 2012 @@ -68,7 +68,6 @@ import org.apache.cxf.jaxrs.utils.Annota import org.apache.cxf.jaxrs.utils.HttpUtils; import org.apache.cxf.jaxrs.utils.InjectionUtils; import org.apache.cxf.jaxrs.utils.JAXBUtils; -import org.apache.cxf.jaxrs.utils.schemas.SchemaHandler; import org.apache.cxf.message.MessageUtils; import org.apache.cxf.staxutils.StaxUtils; import org.apache.cxf.staxutils.W3CDOMStreamWriter; @@ -174,14 +173,6 @@ public class JSONProvider extends Abs super.setProduceMediaTypes(types); } - public void setSchemas(List locations) { - super.setSchemaLocations(locations); - } - - public void setSchemaHandler(SchemaHandler handler) { - super.setSchema(handler.getSchema()); - } - public void setSerializeAsArray(boolean asArray) { this.serializeAsArray = asArray; } Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml?rev=1389808&r1=1389807&r2=1389808&view=diff ============================================================================== --- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml (original) +++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml Tue Sep 25 11:20:47 2012 @@ -265,7 +265,7 @@ http://cxf.apache.org/schemas/core.xsd"> - +