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

com.exadel.aem.toolkit.plugin.sources.AnnotationSourceImpl Maven / Gradle / Ivy

Go to download

Maven plugin for storing AEM (Granite UI) markup created with Exadel Toolbox Authoring Kit

There is a newer version: 2.5.3
Show newest version
/*
 * 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 com.exadel.aem.toolkit.plugin.sources;

import java.lang.annotation.Annotation;

import org.apache.commons.lang3.StringUtils;

import com.exadel.aem.toolkit.api.handlers.Source;
import com.exadel.aem.toolkit.plugin.adapters.AdaptationBase;

/**
 * Implements {@link Source} to expose the metadata that is specific for the underlying annotation
 */
class AnnotationSourceImpl extends AdaptationBase implements Source {
    private final Annotation value;

    /**
     * Initializes a class instance storing a reference to the {@code Annotation} object that serves as the metadata source
     * @param value The referenced {@code Annotation} object
     */
    AnnotationSourceImpl(Annotation value) {
        super(Source.class);
        this.value = value;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getName() {
        return value != null ? value.annotationType().getName() : StringUtils.EMPTY;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean isValid() {
        return value != null;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public  A adaptTo(Class type) {
        if (type == null) {
            return null;
        }
        if (type.isAnnotation() && value != null && type.equals(value.annotationType())) {
            return type.cast(value);
        }
        return super.adaptTo(type);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy