Hi Dan,
this would likely break a minor thing in JBossWS (I still need to check,
might possibly workaround it by being sure to always use a new
databinding when I need to customize it), but besides that it raises a
question from me: is a DataBinding (JAXBDataBinding here) really meant
to be shared within the whole classloader? I would have imagined it to
be a Bus level thing. Asking as the JAXBDataBinding has multiple
members, including context properties, that one might want to configure
differently for each bus.
Thanks
Alessio

On 05/09/2013 06:11 PM, [email protected] wrote:
> Author: dkulp
> Date: Thu May  9 16:11:59 2013
> New Revision: 1480712
> 
> URL: http://svn.apache.org/r1480712
> Log:
> Cache the JAXBDataBinding class which make client creation a tiny bit faster 
> (after the first one) and can hopefully fix a potential deadlock issue when 
> using spring-dm to start multiple bundles that have jaxws:client entries.
> 
> Modified:
>     
> cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
> 
> Modified: 
> cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
> URL: 
> http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java?rev=1480712&r1=1480711&r2=1480712&view=diff
> ==============================================================================
> --- 
> cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
>  (original)
> +++ 
> cxf/trunk/rt/core/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
>  Thu May  9 16:11:59 2013
> @@ -147,6 +147,7 @@ public class ReflectionServiceFactoryBea
>      public static final String METHOD_ANNOTATIONS = 
> "method.return.annotations";
>      public static final String PARAM_ANNOTATION = "parameter.annotations";
>      private static final Logger LOG = 
> LogUtils.getL7dLogger(ReflectionServiceFactoryBean.class);
> +    private static Class<? extends DataBinding> defaultDatabindingClass;
>  
>      protected String wsdlURL;
>  
> @@ -193,7 +194,6 @@ public class ReflectionServiceFactoryBea
>  
>  
>      protected DataBinding createDefaultDataBinding() {
> -
>          Object obj = null;
>          Class<? extends DataBinding> cls = null;
>  
> @@ -216,10 +216,10 @@ public class ReflectionServiceFactoryBea
>          if (cls == null && getBus() != null) {
>              obj = getBus().getProperty(DataBinding.class.getName());
>          }
> -        if (obj == null) {
> -            obj = "org.apache.cxf.jaxb.JAXBDataBinding";
> -        }
>          try {
> +            if (obj == null && cls == null) {
> +                cls = getJAXBClass();            
> +            }
>              if (obj instanceof String) {
>                  cls = ClassLoaderUtils.loadClass(obj.toString(), getClass(), 
> DataBinding.class);
>              } else if (obj instanceof Class) {
> @@ -236,6 +236,17 @@ public class ReflectionServiceFactoryBea
>              throw new ServiceConstructionException(e);
>          }
>      }
> +    private static synchronized Class<? extends DataBinding> getJAXBClass() 
> throws ClassNotFoundException {
> +        if (defaultDatabindingClass == null) {
> +            defaultDatabindingClass = 
> ClassLoaderUtils.loadClass("org.apache.cxf.jaxb.JAXBDataBinding",
> +                                                                 
> ReflectionServiceFactoryBean.class,
> +                                                                 
> DataBinding.class); 
> +        }
> +        return defaultDatabindingClass;
> +    }
> +
> +
> +
>      public void reset() {
>          if (!dataBindingSet) {
>              setDataBinding(null);
> @@ -266,8 +277,7 @@ public class ReflectionServiceFactoryBea
>              getService().setDataBinding(getDataBinding());
>          }
>  
> -        MethodDispatcher m = getMethodDispatcher();
> -        getService().put(MethodDispatcher.class.getName(), m);
> +        getService().put(MethodDispatcher.class.getName(), 
> getMethodDispatcher());
>          createEndpoints();
>  
>          fillInSchemaCrossreferences();
> @@ -426,8 +436,8 @@ public class ReflectionServiceFactoryBea
>          initializeWSDLOperations();
>  
>          Set<Class<?>> cls = getExtraClass();
> -        for (ServiceInfo si : getService().getServiceInfos()) {
> -            if (cls != null && !cls.isEmpty()) {
> +        if (cls != null && !cls.isEmpty()) {
> +            for (ServiceInfo si : getService().getServiceInfos()) {
>                  si.setProperty(EXTRA_CLASS, cls);
>              }
>          }
> @@ -532,14 +542,12 @@ public class ReflectionServiceFactoryBea
>      }
>  
>      protected void initializeServiceModel() {
> -        String wsdlurl = getWsdlURL();
> -
>          if (isFromWsdl()) {
> -            buildServiceFromWSDL(wsdlurl);
> +            buildServiceFromWSDL(getWsdlURL());
>          } else if (getServiceClass() != null) {
>              buildServiceFromClass();
>          } else {
> -            throw new ServiceConstructionException(new 
> Message("NO_WSDL_NO_SERVICE_CLASS_PROVIDED", LOG, wsdlurl));
> +            throw new ServiceConstructionException(new 
> Message("NO_WSDL_NO_SERVICE_CLASS_PROVIDED", LOG, getWsdlURL()));
>          }
>  
>          if (isValidate()) {
> @@ -613,19 +621,15 @@ public class ReflectionServiceFactoryBea
>  
>      private void validateSchemas(XmlSchemaValidationManager xsdValidator,
>                                   SchemaCollection xmlSchemaCollection) {
> -        final boolean[] anyErrors = new boolean[1];
>          final StringBuilder errorBuilder = new StringBuilder();
> -        anyErrors[0] = false;
>          
> xsdValidator.validateSchemas(xmlSchemaCollection.getXmlSchemaCollection(), 
> new DOMErrorHandler() {
> -
>              public boolean handleError(DOMError error) {
> -                anyErrors[0] = true;
>                  errorBuilder.append(error.getMessage());
>                  LOG.warning(error.getMessage());
>                  return true;
>              }
>          });
> -        if (anyErrors[0]) {
> +        if (errorBuilder.length() > 0) {
>              throw new ServiceConstructionException(new 
> Message("XSD_VALIDATION_ERROR", LOG,
>                                                                 
> errorBuilder.toString()));
>          }
> @@ -785,11 +789,8 @@ public class ReflectionServiceFactoryBea
>          }
>          sendEvent(Event.OPERATIONINFO_IN_MESSAGE_SET, origOp, method, 
> origOp.getInput());
>          // Initialize return type
> -        Class<?> paramType = method.getReturnType();
> -        Type genericType = method.getGenericReturnType();
> -
>          if (o.hasOutput()
> -            && !initializeParameter(o, method, -1, paramType, genericType)) {
> +            && !initializeParameter(o, method, -1, method.getReturnType(), 
> method.getGenericReturnType())) {
>              return false;
>          }
>          if (origOp.hasOutput()) {
> 
> 


-- 
Alessio Soldano
Web Service Lead, JBoss

Reply via email to