cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r637027 - in /incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring: BusApplicationContext.java ControlledValidationXmlBeanDefinitionReader.java
Date Fri, 14 Mar 2008 09:53:35 GMT
Author: bimargulies
Date: Fri Mar 14 02:53:32 2008
New Revision: 637027

URL: http://svn.apache.org/viewvc?rev=637027&view=rev
Log:
Suppress validation of CXF's spring config files. Add compatible name 
for validation control variable.

Added:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/ControlledValidationXmlBeanDefinitionReader.java
  (with props)
Modified:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContext.java

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContext.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContext.java?rev=637027&r1=637026&r2=637027&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContext.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContext.java
Fri Mar 14 02:53:32 2008
@@ -33,9 +33,11 @@
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.configuration.Configurer;
+import org.springframework.beans.factory.support.DefaultListableBeanFactory;
 import org.springframework.beans.factory.xml.BeansDtdResolver;
 import org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver;
 import org.springframework.beans.factory.xml.PluggableSchemaResolver;
+import org.springframework.beans.factory.xml.ResourceEntityResolver;
 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -193,7 +195,10 @@
         }
         reader.setNamespaceHandlerResolver(nsHandlerResolver);
         
-        String mode = System.getProperty("spring.validation.mode");
+        String mode = System.getProperty("org.apache.cxf.spring.validation.mode");
+        if (mode == null) {
+            mode = System.getProperty("spring.validation.mode");
+        }
         if (null != mode) {
             reader.setValidationModeName(mode);
         }
@@ -206,6 +211,22 @@
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
         reader.setEntityResolver(new BusEntityResolver(new BeansDtdResolver(),
             new PluggableSchemaResolver(cl)));
+    }
+    @Override
+    protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws IOException
{
+            // Create a new XmlBeanDefinitionReader for the given BeanFactory.
+        XmlBeanDefinitionReader beanDefinitionReader = 
+            new ControlledValidationXmlBeanDefinitionReader(beanFactory);
+        
+        // Configure the bean definition reader with this context's
+        // resource loading environment.
+        beanDefinitionReader.setResourceLoader(this);
+        beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));
+
+        // Allow a subclass to provide custom initialization of the reader,
+        // then proceed with actually loading the bean definitions.
+        initBeanDefinitionReader(beanDefinitionReader);
+        loadBeanDefinitions(beanDefinitionReader);
     }
     
 }

Added: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/ControlledValidationXmlBeanDefinitionReader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/ControlledValidationXmlBeanDefinitionReader.java?rev=637027&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/ControlledValidationXmlBeanDefinitionReader.java
(added)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/ControlledValidationXmlBeanDefinitionReader.java
Fri Mar 14 02:53:32 2008
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cxf.bus.spring;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.xml.sax.InputSource;
+
+import org.springframework.beans.factory.BeanDefinitionStoreException;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.core.io.Resource;
+
+/**
+ * This is a mutant version of the bean definition reader
+ * which allows us to avoid validating our internal CXF
+ * configuration files.
+ */
+public class ControlledValidationXmlBeanDefinitionReader extends XmlBeanDefinitionReader
{
+
+    // Spring has no 'getter' for this.
+    private int visibleValidationMode = VALIDATION_AUTO;
+
+    /**
+     * @param beanFactory
+     */
+    public ControlledValidationXmlBeanDefinitionReader(BeanDefinitionRegistry beanFactory)
{
+        super(beanFactory);
+    }
+
+    @Override
+    protected int doLoadBeanDefinitions(InputSource inputSource, 
+                                        Resource resource) throws BeanDefinitionStoreException
{
+        // sadly, the Spring class we are extending has the critical function
+        // getValidationModeForResource
+        // marked private instead of protected, so trickery is called for here.
+        boolean suppressValidation = false;
+        try {
+            URL url = resource.getURL();
+            if (url.getFile().contains("/META-INF/cxf/")) {
+                suppressValidation = true;
+            }
+        } catch (IOException e) {
+            // this space intentionally left blank.
+        }
+        
+        int savedValidation = visibleValidationMode;
+        if (suppressValidation) {
+            setValidationMode(VALIDATION_NONE);
+        }
+        int r = super.doLoadBeanDefinitions(inputSource, resource);
+        setValidationMode(savedValidation);
+        return r;
+    }
+
+    @Override
+    public void setValidationMode(int validationMode) {
+        visibleValidationMode = validationMode;
+        super.setValidationMode(validationMode);
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/ControlledValidationXmlBeanDefinitionReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/ControlledValidationXmlBeanDefinitionReader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message