Search in sources :

Example 1 with NoSuchTransientException

use of org.qi4j.api.composite.NoSuchTransientException 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<AccessibleObject, Property<?>>();
    for (PropertyModel propertyModel : modelModule.model().state().properties()) {
        Property<?> property = new PropertyInstance<Object>(propertyModel.getBuilderInfo(), propertyModel.initialValue(modelModule.module()));
        properties.put(propertyModel.accessor(), property);
    }
    TransientStateInstance state = new TransientStateInstance(properties);
    return new TransientBuilderInstance<T>(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 NoSuchTransientException

use of org.qi4j.api.composite.NoSuchTransientException in project qi4j-sdk by Qi4j.

the class Qi4jObjectFactory method createQi4jComposite.

@SuppressWarnings("unchecked")
private Object createQi4jComposite(Class aClass, boolean isAddToTypes) {
    if (compositeBuilderFactory == null) {
        return null;
    }
    Object obj = null;
    ConstructionException exception = null;
    try {
        obj = compositeBuilderFactory.newTransient(aClass);
    } catch (NoSuchTransientException e) {
        return null;
    } catch (ConstructionException e) {
        exception = e;
    }
    if (isAddToTypes) {
        addToType(aClass, qi4jComposite);
    }
    if (exception != null) {
        throw exception;
    }
    return obj;
}
Also used : NoSuchTransientException(org.qi4j.api.composite.NoSuchTransientException) ConstructionException(org.qi4j.api.common.ConstructionException)

Aggregations

NoSuchTransientException (org.qi4j.api.composite.NoSuchTransientException)2 AccessibleObject (java.lang.reflect.AccessibleObject)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConstructionException (org.qi4j.api.common.ConstructionException)1 Property (org.qi4j.api.property.Property)1 TransientBuilderInstance (org.qi4j.runtime.composite.TransientBuilderInstance)1 TransientModel (org.qi4j.runtime.composite.TransientModel)1 TransientStateInstance (org.qi4j.runtime.composite.TransientStateInstance)1 PropertyInstance (org.qi4j.runtime.property.PropertyInstance)1 PropertyModel (org.qi4j.runtime.property.PropertyModel)1