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 /** 063 * The rest services 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}