use of org.qi4j.api.composite.CompositeInstance in project qi4j-sdk by Qi4j.
the class NamedAssociationFunction method map.
@Override
public NamedAssociation<T> map(Composite entity) {
try {
Object target = entity;
if (traversedAssociation != null) {
target = traversedAssociation.map(entity).get();
}
if (traversedManyAssociation != null) {
throw new IllegalArgumentException("Cannot traverse ManyAssociations");
}
if (traversedNamedAssociation != null) {
throw new IllegalArgumentException("Cannot traverse NamedAssociations");
}
CompositeInstance handler = (CompositeInstance) Proxy.getInvocationHandler(target);
return ((AssociationStateHolder) handler.state()).namedAssociationFor(accessor);
} catch (IllegalArgumentException e) {
throw e;
} catch (Throwable e) {
throw new IllegalArgumentException(e);
}
}
use of org.qi4j.api.composite.CompositeInstance in project qi4j-sdk by Qi4j.
the class PropertyFunction method map.
@Override
public Property<T> map(Composite entity) {
try {
Object target = entity;
if (traversedProperty != null) {
Property<?> property = traversedProperty.map(entity);
if (property == null) {
return null;
}
target = property.get();
} else if (traversedAssociation != null) {
Association<?> association = traversedAssociation.map(entity);
if (association == null) {
return null;
}
target = association.get();
} else if (traversedManyAssociation != null) {
throw new IllegalArgumentException("Cannot evaluate a ManyAssociation");
} else if (traversedNamedAssociation != null) {
throw new IllegalArgumentException("Cannot evaluate a NamedAssociation");
}
if (target == null) {
return null;
}
CompositeInstance handler = (CompositeInstance) Proxy.getInvocationHandler(target);
return handler.state().propertyFor(accessor);
} catch (IllegalArgumentException e) {
throw e;
} catch (Throwable e) {
throw new IllegalArgumentException(e);
}
}
Aggregations