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