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.model.cloud;
018
019import javax.xml.bind.annotation.XmlAccessType;
020import javax.xml.bind.annotation.XmlAccessorType;
021import javax.xml.bind.annotation.XmlAttribute;
022import javax.xml.bind.annotation.XmlRootElement;
023import javax.xml.bind.annotation.XmlTransient;
024
025import org.apache.camel.CamelContext;
026import org.apache.camel.cloud.ServiceFilter;
027import org.apache.camel.spi.Metadata;
028
029@Metadata(label = "routing,cloud,service-filter")
030@XmlRootElement(name = "customServiceFilter")
031@XmlAccessorType(XmlAccessType.FIELD)
032public class CustomServiceCallServiceFilterConfiguration extends ServiceCallServiceFilterConfiguration {
033    @XmlAttribute(name = "ref")
034    private String serviceFilterRef;
035    @XmlTransient
036    private ServiceFilter serviceFilter;
037
038    public CustomServiceCallServiceFilterConfiguration() {
039        this(null);
040    }
041
042    public CustomServiceCallServiceFilterConfiguration(ServiceCallDefinition parent) {
043        super(parent, "custom-service-filter");
044    }
045
046    // *************************************************************************
047    // Properties
048    // *************************************************************************
049
050    public String getServiceFilterRef() {
051        return serviceFilterRef;
052    }
053
054    /**
055     * Reference of a ServiceFilter
056     */
057    public void setServiceFilterRef(String serviceFilterRef) {
058        this.serviceFilterRef = serviceFilterRef;
059    }
060
061    public ServiceFilter getServiceFilter() {
062        return serviceFilter;
063    }
064
065    /**
066     * Set the ServiceFilter
067     */
068    public void setServiceFilter(ServiceFilter serviceFilter) {
069        this.serviceFilter = serviceFilter;
070    }
071
072    // *************************************************************************
073    // Fluent API
074    // *************************************************************************
075
076    /**
077     * Reference of a ServiceFilter
078     */
079    public CustomServiceCallServiceFilterConfiguration serviceFilter(String serviceFilter) {
080        setServiceFilterRef(serviceFilter);
081        return this;
082    }
083
084    /**
085     * Set the ServiceFilter
086     */
087    public CustomServiceCallServiceFilterConfiguration serviceFilter(ServiceFilter serviceFilter) {
088        setServiceFilter(serviceFilter);
089        return this;
090    }
091
092    // *************************************************************************
093    // Factory
094    // *************************************************************************
095
096    @Override
097    public ServiceFilter newInstance(CamelContext camelContext) throws Exception {
098        ServiceFilter answer = serviceFilter;
099        if (serviceFilterRef != null) {
100            answer = camelContext.getRegistry().lookupByNameAndType(serviceFilterRef, ServiceFilter.class);
101        }
102
103        return answer;
104    }
105}