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.impl.transformer;
018
019import org.apache.camel.impl.DefaultCamelContext;
020import org.apache.camel.spi.DataType;
021import org.apache.camel.util.StringHelper;
022import org.apache.camel.util.ValueHolder;
023
024/**
025 * Key used in {@link org.apache.camel.spi.TransformerRegistry} in {@link DefaultCamelContext},
026 * to ensure a consistent lookup.
027 */
028public final class TransformerKey extends ValueHolder<String> {
029
030    private String scheme;
031    private DataType from;
032    private DataType to;
033
034    public TransformerKey(String scheme) {
035        super(scheme);
036        StringHelper.notEmpty(scheme, "scheme");
037        this.scheme = scheme;
038    }
039
040    public TransformerKey(DataType from, DataType to) {
041        super(createKeyString(from, to));
042        this.from = from;
043        this.to = to;
044    }
045
046    private static String createKeyString(DataType from, DataType to) {
047        return from + "/" + to;
048    }
049
050    public String getScheme() {
051        return scheme;
052    }
053
054    public DataType getFrom() {
055        return from;
056    }
057
058    public DataType getTo() {
059        return to;
060    }
061
062    @Override
063    public String toString() {
064        return get();
065    }
066
067}