Search in sources :

Example 1 with AccessibleObject

use of java.lang.reflect.AccessibleObject in project qi4j-sdk by Qi4j.

the class ModuleInstance method newTransientBuilder.

// Implementation of TransientBuilderFactory
@Override
public <T> TransientBuilder<T> newTransientBuilder(Class<T> mixinType) throws NoSuchTransientException {
    NullArgumentException.validateNotNull("mixinType", mixinType);
    ModelModule<TransientModel> modelModule = typeLookup.lookupTransientModel(mixinType);
    if (modelModule == null) {
        throw new NoSuchTransientException(mixinType.getName(), name());
    }
    Map<AccessibleObject, Property<?>> properties = new HashMap<>();
    for (PropertyModel propertyModel : modelModule.model().state().properties()) {
        Property<?> property = new PropertyInstance<>(propertyModel.getBuilderInfo(), propertyModel.initialValue(modelModule.module()));
        properties.put(propertyModel.accessor(), property);
    }
    TransientStateInstance state = new TransientStateInstance(properties);
    return new TransientBuilderInstance<>(modelModule, state, UsesInstance.EMPTY_USES);
}
Also used : NoSuchTransientException(org.qi4j.api.composite.NoSuchTransientException) TransientStateInstance(org.qi4j.runtime.composite.TransientStateInstance) TransientModel(org.qi4j.runtime.composite.TransientModel) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PropertyModel(org.qi4j.runtime.property.PropertyModel) TransientBuilderInstance(org.qi4j.runtime.composite.TransientBuilderInstance) AccessibleObject(java.lang.reflect.AccessibleObject) PropertyInstance(org.qi4j.runtime.property.PropertyInstance) Property(org.qi4j.api.property.Property)

Example 2 with AccessibleObject

use of java.lang.reflect.AccessibleObject in project qi4j-sdk by Qi4j.

the class EntityStateInstance method manyAssociationFor.

@Override
@SuppressWarnings("unchecked")
public <T> ManyAssociation<T> manyAssociationFor(AccessibleObject accessor) {
    Map<AccessibleObject, Object> state = state();
    ManyAssociation<T> manyAssociation = (ManyAssociation<T>) state.get(accessor);
    if (manyAssociation == null) {
        ManyAssociationModel associationModel = stateModel.getManyAssociation(accessor);
        manyAssociation = new ManyAssociationInstance<>(entityState instanceof BuilderEntityState ? associationModel.getBuilderInfo() : associationModel, entityFunction, entityState.manyAssociationValueOf(associationModel.qualifiedName()));
        state.put(accessor, manyAssociation);
    }
    return manyAssociation;
}
Also used : AccessibleObject(java.lang.reflect.AccessibleObject) AccessibleObject(java.lang.reflect.AccessibleObject) BuilderEntityState(org.qi4j.runtime.unitofwork.BuilderEntityState) ManyAssociationModel(org.qi4j.runtime.association.ManyAssociationModel) ManyAssociation(org.qi4j.api.association.ManyAssociation)

Example 3 with AccessibleObject

use of java.lang.reflect.AccessibleObject in project qi4j-sdk by Qi4j.

the class EntityStateInstance method namedAssociationFor.

@Override
@SuppressWarnings("unchecked")
public <T> NamedAssociation<T> namedAssociationFor(AccessibleObject accessor) {
    Map<AccessibleObject, Object> state = state();
    NamedAssociation<T> namedAssociation = (NamedAssociation<T>) state.get(accessor);
    if (namedAssociation == null) {
        NamedAssociationModel associationModel = stateModel.getNamedAssociation(accessor);
        namedAssociation = new NamedAssociationInstance<>(entityState instanceof BuilderEntityState ? associationModel.getBuilderInfo() : associationModel, entityFunction, entityState.namedAssociationValueOf(associationModel.qualifiedName()));
        state.put(accessor, namedAssociation);
    }
    return namedAssociation;
}
Also used : NamedAssociation(org.qi4j.api.association.NamedAssociation) NamedAssociationModel(org.qi4j.runtime.association.NamedAssociationModel) AccessibleObject(java.lang.reflect.AccessibleObject) AccessibleObject(java.lang.reflect.AccessibleObject) BuilderEntityState(org.qi4j.runtime.unitofwork.BuilderEntityState)

Example 4 with AccessibleObject

use of java.lang.reflect.AccessibleObject in project qi4j-sdk by Qi4j.

the class EntityStateInstance method associationFor.

@Override
@SuppressWarnings("unchecked")
public <T> Association<T> associationFor(AccessibleObject accessor) throws IllegalArgumentException {
    Map<AccessibleObject, Object> state = state();
    Association<T> association = (Association<T>) state.get(accessor);
    if (association == null) {
        final AssociationModel associationModel = stateModel.getAssociation(accessor);
        association = new AssociationInstance<>(entityState instanceof BuilderEntityState ? associationModel.getBuilderInfo() : associationModel, entityFunction, new Property<EntityReference>() {

            @Override
            public EntityReference get() {
                return entityState.associationValueOf(associationModel.qualifiedName());
            }

            @Override
            public void set(EntityReference newValue) throws IllegalArgumentException, IllegalStateException {
                entityState.setAssociationValue(associationModel.qualifiedName(), newValue);
            }
        });
        state.put(accessor, association);
    }
    return association;
}
Also used : Association(org.qi4j.api.association.Association) ManyAssociation(org.qi4j.api.association.ManyAssociation) NamedAssociation(org.qi4j.api.association.NamedAssociation) EntityReference(org.qi4j.api.entity.EntityReference) AccessibleObject(java.lang.reflect.AccessibleObject) AccessibleObject(java.lang.reflect.AccessibleObject) BuilderEntityState(org.qi4j.runtime.unitofwork.BuilderEntityState) Property(org.qi4j.api.property.Property) NamedAssociationModel(org.qi4j.runtime.association.NamedAssociationModel) AssociationModel(org.qi4j.runtime.association.AssociationModel) ManyAssociationModel(org.qi4j.runtime.association.ManyAssociationModel)

Example 5 with AccessibleObject

use of java.lang.reflect.AccessibleObject 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

AccessibleObject (java.lang.reflect.AccessibleObject)51 ArrayList (java.util.ArrayList)17 Method (java.lang.reflect.Method)13 Field (java.lang.reflect.Field)9 Annotation (java.lang.annotation.Annotation)7 PropertyModel (org.qi4j.runtime.property.PropertyModel)6 HashSet (java.util.HashSet)5 Property (org.qi4j.api.property.Property)4 BuilderEntityState (org.qi4j.runtime.unitofwork.BuilderEntityState)4 MethodInvocation (org.aopalliance.intercept.MethodInvocation)3 MetaInfo (org.qi4j.api.common.MetaInfo)3 Optional (org.qi4j.api.common.Optional)3 DynamicFinder (com.google.inject.persist.finder.DynamicFinder)2 Finder (com.google.inject.persist.finder.Finder)2 InvocationHandler (java.lang.reflect.InvocationHandler)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashMap (java.util.HashMap)2 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)2 ResourceInjectionTargetMetaData (org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData)2 Module (org.jboss.modules.Module)2