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.rest;
018
019import java.util.ArrayList;
020import java.util.List;
021import javax.xml.bind.annotation.XmlAccessType;
022import javax.xml.bind.annotation.XmlAccessorType;
023import javax.xml.bind.annotation.XmlElementRef;
024import javax.xml.bind.annotation.XmlRootElement;
025import javax.xml.bind.annotation.XmlTransient;
026
027import org.apache.camel.model.ModelCamelContext;
028import org.apache.camel.model.OptionalIdentifiedDefinition;
029
030/**
031 * Represents a collection of {@link org.apache.camel.model.rest.RestDefinition REST's}
032 */
033@XmlRootElement(name = "rests")
034@XmlAccessorType(XmlAccessType.FIELD)
035public class RestsDefinition extends OptionalIdentifiedDefinition<RestsDefinition> implements RestContainer {
036    @XmlElementRef
037    private List<RestDefinition> rests = new ArrayList<RestDefinition>();
038    @XmlTransient
039    private ModelCamelContext camelContext;
040
041    public RestsDefinition() {
042    }
043
044    @Override
045    public String toString() {
046        return "Rests: " + rests;
047    }
048
049    @Override
050    public String getShortName() {
051        return "rests";
052    }
053
054    public String getLabel() {
055        return "Rest " + getId();
056    }
057
058    // Properties
059    //-----------------------------------------------------------------------
060
061    public List<RestDefinition> getRests() {
062        return rests;
063    }
064
065    public void setRests(List<RestDefinition> rests) {
066        this.rests = rests;
067    }
068
069    public ModelCamelContext getCamelContext() {
070        return camelContext;
071    }
072
073    public void setCamelContext(ModelCamelContext camelContext) {
074        this.camelContext = camelContext;
075    }
076
077    // Fluent API
078    //-------------------------------------------------------------------------
079
080    /**
081     * Creates a rest DSL
082     */
083    public RestDefinition rest() {
084        RestDefinition rest = createRest();
085        return rest(rest);
086    }
087
088    /**
089     * Creates a rest DSL
090     *
091     * @param uri the rest path
092     */
093    public RestDefinition rest(String uri) {
094        RestDefinition rest = createRest();
095        rest.setPath(uri);
096        return rest(rest);
097    }
098
099    /**
100     * Adds the {@link org.apache.camel.model.rest.RestsDefinition}
101     */
102    public RestDefinition rest(RestDefinition rest) {
103        getRests().add(rest);
104        return rest;
105    }
106
107    // Implementation methods
108    //-------------------------------------------------------------------------
109    protected RestDefinition createRest() {
110        RestDefinition rest = new RestDefinition();
111        return rest;
112    }
113
114}