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