You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/08/06 20:22:01 UTC

svn commit: r563213 - in /activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component: ResourceBasedComponent.java validator/ValidatorComponent.java

Author: jstrachan
Date: Mon Aug  6 11:22:00 2007
New Revision: 563213

URL: http://svn.apache.org/viewvc?view=rev&rev=563213
Log:
minor refactor to add a useful base class for components which the endpoint depends on a Resource

Added:
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/ResourceBasedComponent.java   (with props)
Modified:
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/validator/ValidatorComponent.java

Added: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/ResourceBasedComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/ResourceBasedComponent.java?view=auto&rev=563213
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/ResourceBasedComponent.java (added)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/ResourceBasedComponent.java Mon Aug  6 11:22:00 2007
@@ -0,0 +1,54 @@
+/**
+ *
+ * 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.camel.component;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.validator.ValidatorComponent;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.DefaultResourceLoader;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public abstract class ResourceBasedComponent  extends DefaultComponent<Exchange>  {
+    protected static final transient Log log = LogFactory.getLog(ValidatorComponent.class);
+    private ResourceLoader resourceLoader = new DefaultResourceLoader();
+
+    public ResourceLoader getResourceLoader() {
+        return resourceLoader;
+    }
+
+    public void setResourceLoader(ResourceLoader resourceLoader) {
+        this.resourceLoader = resourceLoader;
+    }
+
+    protected Resource resolveMandatoryResource(String uri) {
+        Resource resource = getResourceLoader().getResource(uri);
+        if (resource == null) {
+            throw new IllegalArgumentException("Could not find resource for URI: " + uri + " using: " + getResourceLoader());
+        }
+        else {
+            return resource;
+        }
+
+    }
+}

Propchange: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/ResourceBasedComponent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/validator/ValidatorComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/validator/ValidatorComponent.java?view=diff&rev=563213&r1=563212&r2=563213
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/validator/ValidatorComponent.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/validator/ValidatorComponent.java Mon Aug  6 11:22:00 2007
@@ -23,6 +23,7 @@
 import org.apache.camel.impl.DefaultComponent;
 import org.apache.camel.impl.ProcessorEndpoint;
 import org.apache.camel.component.validator.SpringValidator;
+import org.apache.camel.component.ResourceBasedComponent;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.core.io.ResourceLoader;
@@ -37,18 +38,7 @@
  *
  * @version $Revision: 1.1 $
  */
-public class ValidatorComponent extends DefaultComponent<Exchange> {
-    private static final transient Log log = LogFactory.getLog(ValidatorComponent.class);
-
-    private ResourceLoader resourceLoader = new DefaultResourceLoader();
-
-    public ResourceLoader getResourceLoader() {
-        return resourceLoader;
-    }
-
-    public void setResourceLoader(ResourceLoader resourceLoader) {
-        this.resourceLoader = resourceLoader;
-    }
+public class ValidatorComponent extends ResourceBasedComponent {
 
     protected Endpoint<Exchange> createEndpoint(String uri, String remaining, Map parameters) throws Exception {
         SpringValidator validator = new SpringValidator();
@@ -63,16 +53,5 @@
 
     protected void configureValidator(SpringValidator validator, String uri, String remaining, Map parameters) throws Exception {
         IntrospectionSupport.setProperties(validator, parameters);
-    }
-
-    protected Resource resolveMandatoryResource(String uri) {
-        Resource resource = getResourceLoader().getResource(uri);
-        if (resource == null) {
-            throw new IllegalArgumentException("Could not find resource for URI: " + uri + " using: " + getResourceLoader());
-        }
-        else {
-            return resource;
-        }
-
     }
 }