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.component.validator; 018 019import java.util.Map; 020 021import org.apache.camel.Endpoint; 022import org.apache.camel.impl.UriEndpointComponent; 023import org.apache.camel.spi.Metadata; 024 025/** 026 * The <a href="http://camel.apache.org/validation.html">Validator Component</a> is for validating XML against a schema 027 * 028 * @version 029 */ 030public class ValidatorComponent extends UriEndpointComponent { 031 032 @Metadata(label = "advanced", description = "To use a custom LSResourceResolver which depends on a dynamic endpoint resource URI") 033 private ValidatorResourceResolverFactory resourceResolverFactory; 034 035 public ValidatorComponent() { 036 this(ValidatorEndpoint.class); 037 } 038 039 public ValidatorComponent(Class<? extends Endpoint> endpointClass) { 040 super(endpointClass); 041 } 042 043 public ValidatorResourceResolverFactory getResourceResolverFactory() { 044 return resourceResolverFactory; 045 } 046 047 public void setResourceResolverFactory(ValidatorResourceResolverFactory resourceResolverFactory) { 048 this.resourceResolverFactory = resourceResolverFactory; 049 } 050 051 protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { 052 ValidatorEndpoint endpoint = new ValidatorEndpoint(uri, this, remaining); 053 // lookup custom resolver to use 054 ValidatorResourceResolverFactory resolverFactory = resolveAndRemoveReferenceParameter(parameters, "resourceResolverFactory", ValidatorResourceResolverFactory.class); 055 if (resolverFactory == null) { 056 // not in endpoint then use component specific resource resolver factory 057 resolverFactory = getResourceResolverFactory(); 058 } 059 if (resolverFactory == null) { 060 // fallback to use a Camel default resource resolver factory 061 resolverFactory = new DefaultValidatorResourceResolverFactory(); 062 } 063 endpoint.setResourceResolverFactory(resolverFactory); 064 setProperties(endpoint, parameters); 065 return endpoint; 066 } 067 068}