camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/3] camel git commit: CAMEL-9469: Properties component - Should include component docs
Date Sun, 03 Jan 2016 10:51:50 GMT
CAMEL-9469: Properties component - Should include component docs


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/294bb237
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/294bb237
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/294bb237

Branch: refs/heads/camel-2.16.x
Commit: 294bb237ab7937fea81f9be19f331e8c340092ce
Parents: 0cdce29
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Jan 3 10:41:19 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Jan 3 11:51:33 2016 +0100

----------------------------------------------------------------------
 .../properties/PropertiesComponent.java         |  44 ++++++-
 .../properties/PropertiesEndpoint.java          | 119 +++++++++++++++++++
 2 files changed, 158 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/294bb237/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index 952606c..b0bd45c 100644
--- a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -25,7 +25,7 @@ import java.util.Map;
 import java.util.Properties;
 
 import org.apache.camel.Endpoint;
-import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.impl.UriEndpointComponent;
 import org.apache.camel.util.FilePathResolver;
 import org.apache.camel.util.LRUSoftCache;
 import org.apache.camel.util.ObjectHelper;
@@ -34,10 +34,8 @@ import org.slf4j.LoggerFactory;
 
 /**
  * The <a href="http://camel.apache.org/properties">Properties Component</a>
allows you to use property placeholders when defining Endpoint URIs
- *
- * @version 
  */
-public class PropertiesComponent extends DefaultComponent {
+public class PropertiesComponent extends UriEndpointComponent {
 
     /**
      * The default prefix token.
@@ -108,6 +106,7 @@ public class PropertiesComponent extends DefaultComponent {
     private int systemPropertiesMode = SYSTEM_PROPERTIES_MODE_OVERRIDE;
 
     public PropertiesComponent() {
+        super(PropertiesEndpoint.class);
         // include out of the box functions
         addFunction(new EnvPropertiesFunction());
         addFunction(new SysPropertiesFunction());
@@ -143,7 +142,12 @@ public class PropertiesComponent extends DefaultComponent {
 
         String endpointUri = parseUri(remaining, paths);
         LOG.debug("Endpoint uri parsed as: {}", endpointUri);
-        return getCamelContext().getEndpoint(endpointUri);
+
+        Endpoint delegate = getCamelContext().getEndpoint(endpointUri);
+        PropertiesEndpoint answer = new PropertiesEndpoint(uri, delegate, this);
+
+        setProperties(answer, parameters);
+        return answer;
     }
 
     public String parseUri(String uri) throws Exception {
@@ -214,6 +218,10 @@ public class PropertiesComponent extends DefaultComponent {
         return locations;
     }
 
+    /**
+     * A list of locations to load properties. You can use comma to separate multiple locations.
+     * This option will override any default locations and only use the locations from this
option.
+     */
     public void setLocations(String[] locations) {
         // make sure to trim as people may use new lines when configuring using XML
         // and do this in the setter as Spring/Blueprint resolves placeholders before Camel
is being started
@@ -227,6 +235,10 @@ public class PropertiesComponent extends DefaultComponent {
         this.locations = locations;
     }
 
+    /**
+     * A list of locations to load properties. You can use comma to separate multiple locations.
+     * This option will override any default locations and only use the locations from this
option.
+     */
     public void setLocation(String location) {
         setLocations(location.split(","));
     }
@@ -249,6 +261,9 @@ public class PropertiesComponent extends DefaultComponent {
         return propertiesResolver;
     }
 
+    /**
+     * To use a custom PropertiesResolver
+     */
     public void setPropertiesResolver(PropertiesResolver propertiesResolver) {
         this.propertiesResolver = propertiesResolver;
     }
@@ -257,6 +272,9 @@ public class PropertiesComponent extends DefaultComponent {
         return propertiesParser;
     }
 
+    /**
+     * To use a custom PropertiesParser
+     */
     public void setPropertiesParser(PropertiesParser propertiesParser) {
         this.propertiesParser = propertiesParser;
     }
@@ -265,6 +283,9 @@ public class PropertiesComponent extends DefaultComponent {
         return cache;
     }
 
+    /**
+     * Whether or not to cache loaded properties. The default value is true.
+     */
     public void setCache(boolean cache) {
         this.cache = cache;
     }
@@ -273,6 +294,9 @@ public class PropertiesComponent extends DefaultComponent {
         return propertyPrefix;
     }
 
+    /**
+     * Optional prefix prepended to property names before resolution.
+     */
     public void setPropertyPrefix(String propertyPrefix) {
         this.propertyPrefix = propertyPrefix;
         this.propertyPrefixResolved = propertyPrefix;
@@ -285,6 +309,9 @@ public class PropertiesComponent extends DefaultComponent {
         return propertySuffix;
     }
 
+    /**
+     * Optional suffix appended to property names before resolution.
+     */
     public void setPropertySuffix(String propertySuffix) {
         this.propertySuffix = propertySuffix;
         this.propertySuffixResolved = propertySuffix;
@@ -297,6 +324,10 @@ public class PropertiesComponent extends DefaultComponent {
         return fallbackToUnaugmentedProperty;
     }
 
+    /**
+     * If true, first attempt resolution of property name augmented with propertyPrefix and
propertySuffix
+     * before falling back the plain property name specified. If false, only the augmented
property name is searched.
+     */
     public void setFallbackToUnaugmentedProperty(boolean fallbackToUnaugmentedProperty) {
         this.fallbackToUnaugmentedProperty = fallbackToUnaugmentedProperty;
     }
@@ -305,6 +336,9 @@ public class PropertiesComponent extends DefaultComponent {
         return ignoreMissingLocation;
     }
 
+    /**
+     * Whether to silently ignore if a location cannot be located, such as a properties file
not found.
+     */
     public void setIgnoreMissingLocation(boolean ignoreMissingLocation) {
         this.ignoreMissingLocation = ignoreMissingLocation;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/294bb237/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesEndpoint.java
b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesEndpoint.java
new file mode 100644
index 0000000..e9837a6
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesEndpoint.java
@@ -0,0 +1,119 @@
+/**
+ * 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.properties;
+
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.DelegateEndpoint;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriPath;
+
+/**
+ * The properties component is used for using property placeholders in endpoint uris.
+ */
+@UriEndpoint(scheme = "properties", title = "Properties", syntax = "properties:key", label
= "core,endpoint")
+public class PropertiesEndpoint extends DefaultEndpoint implements DelegateEndpoint {
+
+    private volatile Endpoint endpoint;
+
+    @UriPath
+    @Metadata(required = "true")
+    private String key;
+    @UriParam
+    private String locations;
+    @UriParam
+    private boolean ignoreMissingLocation;
+
+    public PropertiesEndpoint(String endpointUri, Endpoint delegate, Component component)
{
+        super(endpointUri, component);
+        this.endpoint = delegate;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    /**
+     * Property key to use as placeholder
+     */
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String getLocations() {
+        return locations;
+    }
+
+    /**
+     * A list of locations to load properties. You can use comma to separate multiple locations.
+     * This option will override any default locations and only use the locations from this
option.
+     */
+    public void setLocations(String locations) {
+        this.locations = locations;
+    }
+
+    public boolean isIgnoreMissingLocation() {
+        return ignoreMissingLocation;
+    }
+
+    /**
+     * Whether to silently ignore if a location cannot be located, such as a properties file
not found.
+     */
+    public void setIgnoreMissingLocation(boolean ignoreMissingLocation) {
+        this.ignoreMissingLocation = ignoreMissingLocation;
+    }
+
+    @Override
+    public Producer createProducer() throws Exception {
+        return endpoint.createProducer();
+    }
+
+    @Override
+    public Consumer createConsumer(Processor processor) throws Exception {
+        return endpoint.createConsumer(processor);
+    }
+
+    @Override
+    public boolean isSingleton() {
+        return true;
+    }
+
+    @Override
+    public Endpoint getEndpoint() {
+        return endpoint;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        // add the endpoint as a service so Camel can manage the endpoint and enlist the
endpoint in JMX etc.
+        getCamelContext().addService(endpoint);
+        super.doStart();
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+        // noop
+    }
+
+}


Mime
View raw message