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

sirius.kernel.di.std.PartsAnnotationProcessor Maven / Gradle / Ivy

Go to download

Provides common core classes and the microkernel powering all Sirius applications

There is a newer version: 12.9.1
Show newest version
/*
 * Made with all the love in the world
 * by scireum in Remshalden, Germany
 *
 * Copyright by scireum GmbH
 * http://www.scireum.de - [email protected]
 */

package sirius.kernel.di.std;

import sirius.kernel.di.FieldAnnotationProcessor;
import sirius.kernel.di.MutableGlobalContext;
import sirius.kernel.di.PartCollection;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Collection;

/**
 * Handles the {@link Parts} annotation.
 *
 * @see sirius.kernel.di.FieldAnnotationProcessor
 * @see Parts
 */
@Register
public class PartsAnnotationProcessor implements FieldAnnotationProcessor {
    @Override
    public Class getTrigger() {
        return Parts.class;
    }

    @Override
    public void handle(MutableGlobalContext ctx, Object object, Field field) throws Exception {
        Parts parts = field.getAnnotation(Parts.class);
        if (Collection.class.isAssignableFrom(field.getType())) {
            field.set(object, ctx.getParts(parts.value()));
        } else if (PartCollection.class.isAssignableFrom(field.getType())) {
            field.set(object, ctx.getPartCollection(parts.value()));
        } else {
            throw new IllegalArgumentException(
                    "Only fields of type Collection or PartCollection are allowed whe using @Parts.");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy