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.CamelContext; 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 CamelContext 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 @Override 058 public String getLabel() { 059 return "Rest " + getId(); 060 } 061 062 // Properties 063 // ----------------------------------------------------------------------- 064 065 @Override 066 public List<RestDefinition> getRests() { 067 return rests; 068 } 069 070 /** 071 * The rest services 072 */ 073 @Override 074 public void setRests(List<RestDefinition> rests) { 075 this.rests = rests; 076 } 077 078 public CamelContext getCamelContext() { 079 return camelContext; 080 } 081 082 public void setCamelContext(CamelContext camelContext) { 083 this.camelContext = camelContext; 084 } 085 086 // Fluent API 087 // ------------------------------------------------------------------------- 088 089 /** 090 * Creates a rest DSL 091 */ 092 public RestDefinition rest() { 093 RestDefinition rest = createRest(); 094 return rest(rest); 095 } 096 097 /** 098 * Creates a rest DSL 099 * 100 * @param uri the rest path 101 */ 102 public RestDefinition rest(String uri) { 103 RestDefinition rest = createRest(); 104 rest.setPath(uri); 105 return rest(rest); 106 } 107 108 /** 109 * Adds the {@link org.apache.camel.model.rest.RestsDefinition} 110 */ 111 public RestDefinition rest(RestDefinition rest) { 112 getRests().add(rest); 113 return rest; 114 } 115 116 // Implementation methods 117 // ------------------------------------------------------------------------- 118 protected RestDefinition createRest() { 119 RestDefinition rest = new RestDefinition(); 120 return rest; 121 } 122 123}