001 /** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.camel.component.cxf; 019 020 import org.apache.camel.EndpointResolver; 021 import org.apache.camel.Component; 022 import org.apache.camel.CamelContext; 023 import org.apache.camel.util.ObjectHelper; 024 025 import java.io.IOException; 026 import java.net.URISyntaxException; 027 import java.util.concurrent.Callable; 028 029 /** 030 * An implementation of {@link EndpointResolver} that creates 031 * {@link CxfEndpoint} objects. 032 * 033 * The syntax for a MINA URI looks like: 034 * 035 * <pre><code>mina:</code></pre> 036 * 037 * @version $Revision:520964 $ 038 */ 039 public class CxfEndpointResolver implements EndpointResolver<CxfExchange> { 040 041 public static final String DEFAULT_COMPONENT_NAME = CxfEndpointResolver.class.getName(); 042 043 /** 044 * Finds the {@link CxfComponent} specified by the uri. If the {@link CxfComponent} 045 * object do not exist, it will be created. 046 */ 047 public Component resolveComponent(CamelContext container, String uri) { 048 String[] id = getEndpointId(uri); 049 return resolveCxfComponent(container, id[0]); 050 } 051 052 /** 053 * Finds the {@link CxfEndpoint} specified by the uri. If the {@link CxfEndpoint} or it's associated 054 * {@see QueueComponent} object do not exist, they will be created. 055 */ 056 public CxfEndpoint resolveEndpoint(CamelContext container, String uri) throws IOException, URISyntaxException { 057 String[] urlParts = getEndpointId(uri); 058 CxfComponent component = resolveCxfComponent(container, urlParts[0]); 059 return component.createEndpoint(uri, urlParts); 060 } 061 062 /** 063 * @return an array that looks like: [componentName,endpointName] 064 */ 065 private String[] getEndpointId(String uri) { 066 String rc [] = {CxfEndpointResolver.DEFAULT_COMPONENT_NAME, null}; 067 String splitURI[] = ObjectHelper.splitOnCharacter(uri, ":", 3); 068 if( splitURI[2] != null ) { 069 rc[0] = splitURI[1]; 070 rc[1] = splitURI[2]; 071 } else { 072 rc[1] = splitURI[1]; 073 } 074 return rc; 075 } 076 077 @SuppressWarnings("unchecked") 078 private CxfComponent resolveCxfComponent(final CamelContext context, final String componentName) { 079 Component rc = context.getOrCreateComponent(componentName, new Callable(){ 080 public CxfComponent call() throws Exception { 081 return new CxfComponent(context); 082 }}); 083 return (CxfComponent) rc; 084 } 085 086 087 }