Package org.apache.hivemind.service.impl

Source Code of org.apache.hivemind.service.impl.BuilderPropertyFacet

// Copyright 2004, 2005 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.apache.hivemind.service.impl;

import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ServiceImplementationFactoryParameters;
import org.apache.hivemind.schema.Translator;
import org.apache.hivemind.util.ConstructorUtils;

/**
* Implementation of {@link org.apache.hivemind.service.impl.BuilderFacet}that stores a value. This
* corresponds to the <set> type elements and all constructor parameter elements. The value is
* not resolved until needed using a specified {@link Translator}.
*
* @author Howard Lewis Ship
*/
public class BuilderPropertyFacet extends BuilderFacet
{
    private String _translatorName;

    private String _literalValue;

    public Object getFacetValue(ServiceImplementationFactoryParameters factoryParameters,
            Class targetType)
    {
        Translator translator = factoryParameters.getInvokingModule()
                .getTranslator(_translatorName);

        return translator.translate(
                factoryParameters.getInvokingModule(),
                targetType,
                _literalValue,
                getLocation());
    }

    public boolean isAssignableToType(ServiceImplementationFactoryParameters factoryParameters,
            Class targetType)
    {
        try
        {
            // TODO should Translator declare an analoguous isAssignableToType method?
            Object facetValue = getFacetValue(factoryParameters, targetType);

            if (facetValue == null)
                return !targetType.isPrimitive();

            return ConstructorUtils.isCompatible(targetType, facetValue.getClass());
        }
        catch (ApplicationRuntimeException e)
        {
            return false;
        }
    }

    /** @since 1.1 */
    public void setTranslator(String translatorName)
    {
        _translatorName = translatorName;
    }

    public void setValue(String value)
    {
        _literalValue = value;
    }

}
TOP

Related Classes of org.apache.hivemind.service.impl.BuilderPropertyFacet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.