All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nakedobjects.metamodel.facets.object.value.ValueFacetAnnotation Maven / Gradle / Ivy

There is a newer version: 4.0-beta-1
Show newest version
package org.nakedobjects.metamodel.facets.object.value;

import org.nakedobjects.applib.annotation.Value;
import org.nakedobjects.metamodel.commons.lang.StringUtils;
import org.nakedobjects.metamodel.config.NakedObjectConfiguration;
import org.nakedobjects.metamodel.facets.FacetHolder;
import org.nakedobjects.metamodel.runtimecontext.RuntimeContext;
import org.nakedobjects.metamodel.specloader.SpecificationLoader;


public class ValueFacetAnnotation extends ValueFacetAbstract {

    private static String semanticsProviderName(final Class annotatedClass, final NakedObjectConfiguration configuration) {
        final Value annotation = (Value) annotatedClass.getAnnotation(Value.class);
        final String semanticsProviderName = annotation.semanticsProviderName();
        if (!StringUtils.isEmpty(semanticsProviderName)) {
            return semanticsProviderName;
        }
        return ValueSemanticsProviderUtil.semanticsProviderNameFromConfiguration(annotatedClass, configuration);
    }

    private static Class semanticsProviderClass(final Class annotatedClass) {
        final Value annotation = (Value) annotatedClass.getAnnotation(Value.class);
        return annotation.semanticsProviderClass();
    }

    public ValueFacetAnnotation(
    		final Class annotatedClass, 
    		final FacetHolder holder, 
    		final NakedObjectConfiguration configuration, 
    		final SpecificationLoader specificationLoader, 
    		final RuntimeContext runtimeContext) {
        this(semanticsProviderName(annotatedClass, configuration), semanticsProviderClass(annotatedClass), holder, configuration, specificationLoader, runtimeContext);
    }

    private ValueFacetAnnotation(
            final String candidateSemanticsProviderName,
            final Class candidateSemanticsProviderClass,
            final FacetHolder holder, 
    		final NakedObjectConfiguration configuration, 
    		final SpecificationLoader specificationLoader, 
            final RuntimeContext runtimeContext) {
        super(ValueSemanticsProviderUtil.valueSemanticsProviderOrNull(candidateSemanticsProviderClass,
                candidateSemanticsProviderName), true, holder, configuration, specificationLoader, runtimeContext);
    }

    /**
     * Always valid, even if the specified semanticsProviderName might have been wrong.
     */
    @Override
    public boolean isValid() {
        return true;
    }

}

// Copyright (c) Naked Objects Group Ltd.




© 2015 - 2024 Weber Informatics LLC | Privacy Policy