Search in sources :

Example 1 with MetaInfo

use of org.qi4j.api.common.MetaInfo in project qi4j-sdk by Qi4j.

the class EntityAssemblyImpl method newManyAssociationModel.

public ManyAssociationModel newManyAssociationModel(AccessibleObject accessor, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses) {
    Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
    boolean optional = first(filter(isType(Optional.class), annotations)) != null;
    // Constraints for entities in ManyAssociation
    ValueConstraintsModel valueConstraintsModel = constraintsFor(annotations, GenericAssociationInfo.associationTypeOf(accessor), ((Member) accessor).getName(), optional, constraintClasses, accessor);
    ValueConstraintsInstance valueConstraintsInstance = null;
    if (valueConstraintsModel.isConstrained()) {
        valueConstraintsInstance = valueConstraintsModel.newInstance();
    }
    // Constraints for the ManyAssociation itself
    valueConstraintsModel = constraintsFor(annotations, ManyAssociation.class, ((Member) accessor).getName(), optional, constraintClasses, accessor);
    ValueConstraintsInstance manyValueConstraintsInstance = null;
    if (valueConstraintsModel.isConstrained()) {
        manyValueConstraintsInstance = valueConstraintsModel.newInstance();
    }
    MetaInfo metaInfo = manyAssociationDeclarations.metaInfoFor(accessor);
    ManyAssociationModel associationModel = new ManyAssociationModel(accessor, valueConstraintsInstance, manyValueConstraintsInstance, metaInfo);
    return associationModel;
}
Also used : Optional(org.qi4j.api.common.Optional) MetaInfo(org.qi4j.api.common.MetaInfo) ValueConstraintsModel(org.qi4j.runtime.composite.ValueConstraintsModel) ManyAssociationModel(org.qi4j.runtime.association.ManyAssociationModel) ManyAssociation(org.qi4j.api.association.ManyAssociation) ValueConstraintsInstance(org.qi4j.runtime.composite.ValueConstraintsInstance) Member(java.lang.reflect.Member) Annotation(java.lang.annotation.Annotation)

Example 2 with MetaInfo

use of org.qi4j.api.common.MetaInfo in project qi4j-sdk by Qi4j.

the class ImportedServiceAssemblyImpl method addImportedServiceModel.

@SuppressWarnings({ "raw", "unchecked" })
void addImportedServiceModel(List<ImportedServiceModel> serviceModels) {
    try {
        String id = identity;
        if (id == null) {
            id = generateId(serviceModels, serviceType);
        }
        ImportedServiceModel serviceModel = new ImportedServiceModel(serviceType, visibility, serviceProvider, id, importOnStartup, new MetaInfo(metaInfo).withAnnotations(serviceType), new ActivatorsModel(activators), moduleAssembly.name());
        serviceModels.add(serviceModel);
    } catch (Exception e) {
        throw new InvalidApplicationException("Could not register " + serviceType.getName(), e);
    }
}
Also used : ImportedServiceModel(org.qi4j.runtime.service.ImportedServiceModel) ActivatorsModel(org.qi4j.runtime.activation.ActivatorsModel) MetaInfo(org.qi4j.api.common.MetaInfo) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException)

Example 3 with MetaInfo

use of org.qi4j.api.common.MetaInfo in project qi4j-sdk by Qi4j.

the class ValueAssemblyImpl method newManyAssociationModel.

public ManyAssociationModel newManyAssociationModel(AccessibleObject accessor, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses) {
    Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
    boolean optional = first(filter(isType(Optional.class), annotations)) != null;
    // Constraints for entities in ManyAssociation
    ValueConstraintsModel valueConstraintsModel = constraintsFor(annotations, GenericAssociationInfo.associationTypeOf(accessor), ((Member) accessor).getName(), optional, constraintClasses, accessor);
    ValueConstraintsInstance valueConstraintsInstance = null;
    if (valueConstraintsModel.isConstrained()) {
        valueConstraintsInstance = valueConstraintsModel.newInstance();
    }
    // Constraints for the ManyAssociation itself
    valueConstraintsModel = constraintsFor(annotations, ManyAssociation.class, ((Member) accessor).getName(), optional, constraintClasses, accessor);
    ValueConstraintsInstance manyValueConstraintsInstance = null;
    if (valueConstraintsModel.isConstrained()) {
        manyValueConstraintsInstance = valueConstraintsModel.newInstance();
    }
    MetaInfo metaInfo = stateDeclarations.metaInfoFor(accessor);
    ManyAssociationModel associationModel = new ManyAssociationModel(accessor, valueConstraintsInstance, manyValueConstraintsInstance, metaInfo);
    return associationModel;
}
Also used : Optional(org.qi4j.api.common.Optional) MetaInfo(org.qi4j.api.common.MetaInfo) ValueConstraintsModel(org.qi4j.runtime.composite.ValueConstraintsModel) ManyAssociationModel(org.qi4j.runtime.association.ManyAssociationModel) ManyAssociation(org.qi4j.api.association.ManyAssociation) ValueConstraintsInstance(org.qi4j.runtime.composite.ValueConstraintsInstance) Member(java.lang.reflect.Member) Annotation(java.lang.annotation.Annotation)

Example 4 with MetaInfo

use of org.qi4j.api.common.MetaInfo in project qi4j-sdk by Qi4j.

the class CompositeAssemblyImpl method buildComposite.

protected void buildComposite(AssemblyHelper helper, StateDeclarations stateDeclarations) {
    this.stateDeclarations = stateDeclarations;
    this.helper = helper;
    for (Class<?> compositeType : types) {
        metaInfo = new MetaInfo(metaInfo).withAnnotations(compositeType);
        addAnnotationsMetaInfo(compositeType, metaInfo);
    }
    immutable = metaInfo.get(Immutable.class) != null;
    propertiesModel = new PropertiesModel();
    stateModel = createStateModel();
    mixinsModel = createMixinsModel();
    compositeMethodsModel = new CompositeMethodsModel(mixinsModel);
    // Implement composite methods
    ArrayList<Type> allTypes = getTypes(this.types);
    Iterable<Class<? extends Constraint<?, ?>>> constraintClasses = constraintDeclarations(getTypes(this.types));
    Iterable<Class<?>> concernClasses = flatten(concerns, concernDeclarations(allTypes));
    Iterable<Class<?>> sideEffectClasses = flatten(sideEffects, sideEffectDeclarations(allTypes));
    Iterable<Class<?>> mixinClasses = flatten(mixins, mixinDeclarations(this.types));
    implementMixinType(types, constraintClasses, concernClasses, sideEffectClasses, mixinClasses);
    // Add state from methods and fields
    addState(constraintClasses);
}
Also used : Annotations.isType(org.qi4j.api.util.Annotations.isType) Type(java.lang.reflect.Type) CompositeMethodsModel(org.qi4j.runtime.composite.CompositeMethodsModel) Constraint(org.qi4j.api.constraint.Constraint) MetaInfo(org.qi4j.api.common.MetaInfo) Classes.wrapperClass(org.qi4j.api.util.Classes.wrapperClass) PropertiesModel(org.qi4j.runtime.property.PropertiesModel)

Example 5 with MetaInfo

use of org.qi4j.api.common.MetaInfo in project qi4j-sdk by Qi4j.

the class CompositeAssemblyImpl method newPropertyModel.

protected PropertyModel newPropertyModel(AccessibleObject accessor, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses) {
    Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
    boolean optional = first(filter(isType(Optional.class), annotations)) != null;
    ValueConstraintsModel valueConstraintsModel = constraintsFor(annotations, GenericPropertyInfo.propertyTypeOf(accessor), ((Member) accessor).getName(), optional, constraintClasses, accessor);
    ValueConstraintsInstance valueConstraintsInstance = null;
    if (valueConstraintsModel.isConstrained()) {
        valueConstraintsInstance = valueConstraintsModel.newInstance();
    }
    MetaInfo metaInfo = stateDeclarations.metaInfoFor(accessor);
    Object initialValue = stateDeclarations.initialValueOf(accessor);
    boolean useDefaults = metaInfo.get(UseDefaults.class) != null || stateDeclarations.useDefaults(accessor);
    boolean immutable = this.immutable || metaInfo.get(Immutable.class) != null;
    PropertyModel propertyModel = new PropertyModel(accessor, immutable, useDefaults, valueConstraintsInstance, metaInfo, initialValue);
    return propertyModel;
}
Also used : Optional(org.qi4j.api.common.Optional) MetaInfo(org.qi4j.api.common.MetaInfo) PropertyModel(org.qi4j.runtime.property.PropertyModel) ValueConstraintsModel(org.qi4j.runtime.composite.ValueConstraintsModel) AccessibleObject(java.lang.reflect.AccessibleObject) ValueConstraintsInstance(org.qi4j.runtime.composite.ValueConstraintsInstance) Annotations.hasAnnotation(org.qi4j.api.util.Annotations.hasAnnotation) Annotation(java.lang.annotation.Annotation)

Aggregations

MetaInfo (org.qi4j.api.common.MetaInfo)15 Annotation (java.lang.annotation.Annotation)9 Optional (org.qi4j.api.common.Optional)9 ValueConstraintsInstance (org.qi4j.runtime.composite.ValueConstraintsInstance)9 ValueConstraintsModel (org.qi4j.runtime.composite.ValueConstraintsModel)9 Member (java.lang.reflect.Member)7 ManyAssociation (org.qi4j.api.association.ManyAssociation)4 NamedAssociation (org.qi4j.api.association.NamedAssociation)4 ManyAssociationModel (org.qi4j.runtime.association.ManyAssociationModel)4 NamedAssociationModel (org.qi4j.runtime.association.NamedAssociationModel)4 AccessibleObject (java.lang.reflect.AccessibleObject)3 InvalidApplicationException (org.qi4j.api.common.InvalidApplicationException)3 PropertyModel (org.qi4j.runtime.property.PropertyModel)3 Type (java.lang.reflect.Type)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Association (org.qi4j.api.association.Association)2 AssociationModel (org.qi4j.runtime.association.AssociationModel)2 CompositeMethodsModel (org.qi4j.runtime.composite.CompositeMethodsModel)2 PropertiesModel (org.qi4j.runtime.property.PropertiesModel)2