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.ref;
018
019import java.util.Map;
020
021import org.apache.camel.Endpoint;
022import org.apache.camel.impl.UriEndpointComponent;
023
024/**
025 * The <a href="http://camel.apache.org/ref.html">Ref Component</a> is for lookup of existing endpoints bound in the {@link org.apache.camel.spi.Registry}.
026 * <p/>
027 * This component uses the <tt>ref:</tt> notation instead of the mostly common <tt>uri:</tt> notation. 
028 */
029public class RefComponent extends UriEndpointComponent {
030
031    public RefComponent() {
032        super(RefEndpoint.class);
033    }
034
035    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
036        // first remove the scheme from the URI
037        int index = uri.indexOf(':');
038        String name = uri;
039        if (index >= 0) {
040            name = uri.substring(index + 1);
041        }
042        if (name.startsWith("//")) {
043            name = name.substring(2);
044        }
045
046        RefEndpoint answer = new RefEndpoint(uri, this);
047        answer.setName(name);
048        setProperties(answer, parameters);
049        return answer;
050    }
051
052}