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.validator; 018 019import javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlAttribute; 022import javax.xml.bind.annotation.XmlType; 023 024import org.apache.camel.CamelContext; 025import org.apache.camel.Endpoint; 026import org.apache.camel.ExchangePattern; 027import org.apache.camel.impl.validator.ProcessorValidator; 028import org.apache.camel.processor.SendProcessor; 029import org.apache.camel.spi.Metadata; 030import org.apache.camel.spi.Validator; 031 032/** 033 * Represents an endpoint {@link Validator} which leverages camel validator component such as 034 * <a href="http://camel.apache.org/validation.html">Validator Component</a> and 035 * <a href="http://camel.apache.org/bean-validation.html">Bean Validator Component</a> to 036 * perform content validation. A {@link ProcessorValidator} will be created internally 037 * with a {@link SendProcessor} which forwards the message to the validator Endpoint. 038 * 039 * {@see ValidatorDefinition} 040 * {@see Validator} 041 */ 042@Metadata(label = "validation") 043@XmlType(name = "endpointValidator") 044@XmlAccessorType(XmlAccessType.FIELD) 045public class EndpointValidatorDefinition extends ValidatorDefinition { 046 047 @XmlAttribute 048 private String ref; 049 @XmlAttribute 050 private String uri; 051 052 @Override 053 protected Validator doCreateValidator(CamelContext context) throws Exception { 054 Endpoint endpoint = uri != null ? context.getEndpoint(uri) 055 : context.getRegistry().lookupByNameAndType(ref, Endpoint.class); 056 SendProcessor processor = new SendProcessor(endpoint, ExchangePattern.InOut); 057 return new ProcessorValidator(context) 058 .setProcessor(processor) 059 .setType(getType()); 060 } 061 062 public String getRef() { 063 return ref; 064 } 065 066 /** 067 * Set the reference of the Endpoint. 068 * 069 * @param ref reference of the Endpoint 070 */ 071 public void setRef(String ref) { 072 this.ref = ref; 073 } 074 075 public String getUri() { 076 return uri; 077 } 078 079 /** 080 * Set the URI of the Endpoint. 081 * 082 * @param uri URI of the Endpoint 083 */ 084 public void setUri(String uri) { 085 this.uri = uri; 086 } 087 088} 089