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