001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.component.properties;
018
019import org.apache.camel.Component;
020import org.apache.camel.Consumer;
021import org.apache.camel.DelegateEndpoint;
022import org.apache.camel.Endpoint;
023import org.apache.camel.Processor;
024import org.apache.camel.Producer;
025import org.apache.camel.impl.DefaultEndpoint;
026import org.apache.camel.spi.Metadata;
027import org.apache.camel.spi.UriEndpoint;
028import org.apache.camel.spi.UriParam;
029import org.apache.camel.spi.UriPath;
030
031/**
032 * The properties component is used for using property placeholders in endpoint uris.
033 */
034@UriEndpoint(firstVersion = "2.3.0", scheme = "properties", title = "Properties", syntax = "properties:key", label = "core,endpoint")
035public class PropertiesEndpoint extends DefaultEndpoint implements DelegateEndpoint {
036
037    private volatile Endpoint endpoint;
038
039    @UriPath
040    @Metadata(required = "true")
041    private String key;
042    @UriParam
043    private String locations;
044    @UriParam
045    private boolean ignoreMissingLocation;
046
047    public PropertiesEndpoint(String endpointUri, Endpoint delegate, Component component) {
048        super(endpointUri, component);
049        this.endpoint = delegate;
050    }
051
052    public String getKey() {
053        return key;
054    }
055
056    /**
057     * Property key to use as placeholder
058     */
059    public void setKey(String key) {
060        this.key = key;
061    }
062
063    public String getLocations() {
064        return locations;
065    }
066
067    /**
068     * A list of locations to load properties. You can use comma to separate multiple locations.
069     * This option will override any default locations and only use the locations from this option.
070     */
071    public void setLocations(String locations) {
072        this.locations = locations;
073    }
074
075    public boolean isIgnoreMissingLocation() {
076        return ignoreMissingLocation;
077    }
078
079    /**
080     * Whether to silently ignore if a location cannot be located, such as a properties file not found.
081     */
082    public void setIgnoreMissingLocation(boolean ignoreMissingLocation) {
083        this.ignoreMissingLocation = ignoreMissingLocation;
084    }
085
086    @Override
087    public Producer createProducer() throws Exception {
088        return endpoint.createProducer();
089    }
090
091    @Override
092    public Consumer createConsumer(Processor processor) throws Exception {
093        return endpoint.createConsumer(processor);
094    }
095
096    @Override
097    public boolean isSingleton() {
098        return true;
099    }
100
101    @Override
102    public Endpoint getEndpoint() {
103        return endpoint;
104    }
105
106    @Override
107    protected void doStart() throws Exception {
108        // add the endpoint as a service so Camel can manage the endpoint and enlist the endpoint in JMX etc.
109        getCamelContext().addService(endpoint);
110        super.doStart();
111    }
112
113    @Override
114    protected void doStop() throws Exception {
115        super.doStop();
116        // noop
117    }
118
119}