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 protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { 044 ValidatorEndpoint endpoint = new ValidatorEndpoint(uri, this, remaining); 045 // lookup custom resolver to use 046 ValidatorResourceResolverFactory resolverFactory = resolveAndRemoveReferenceParameter(parameters, "resourceResolverFactory", ValidatorResourceResolverFactory.class); 047 if (resolverFactory == null) { 048 // not in endpoint then use component specific resource resolver factory 049 resolverFactory = getResourceResolverFactory(); 050 } 051 if (resolverFactory == null) { 052 // fallback to use a Camel default resource resolver factory 053 resolverFactory = new DefaultValidatorResourceResolverFactory(); 054 } 055 endpoint.setResourceResolverFactory(resolverFactory); 056 setProperties(endpoint, parameters); 057 return endpoint; 058 } 059 060 public ValidatorResourceResolverFactory getResourceResolverFactory() { 061 return resourceResolverFactory; 062 } 063 064 /** 065 * To use a custom LSResourceResolver which depends on a dynamic endpoint resource URI 066 */ 067 public void setResourceResolverFactory(ValidatorResourceResolverFactory resourceResolverFactory) { 068 this.resourceResolverFactory = resourceResolverFactory; 069 } 070 071}