use of org.qi4j.api.composite.InvalidCompositeException in project qi4j-sdk by Qi4j.
the class CompositeAssemblyImpl method implementMethod.
protected MixinModel implementMethod(Method method, Iterable<Class<?>> mixinDeclarations) {
MixinModel implementationModel = mixinsModel.mixinFor(method);
if (implementationModel != null) {
return implementationModel;
}
Class mixinClass = findTypedImplementation(method, mixinDeclarations);
if (mixinClass != null) {
return implementMethodWithClass(method, mixinClass);
}
// Check generic implementations
mixinClass = findGenericImplementation(method, mixinDeclarations);
if (mixinClass != null) {
return implementMethodWithClass(method, mixinClass);
}
throw new InvalidCompositeException("No implementation found for method \n " + method.toGenericString() + "\nin\n " + types);
}
use of org.qi4j.api.composite.InvalidCompositeException in project qi4j-sdk by Qi4j.
the class CompositeAssemblyImpl method constraintsFor.
protected ValueConstraintsModel constraintsFor(Iterable<Annotation> constraintAnnotations, Type valueType, String name, boolean optional, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses, AccessibleObject accessor) {
valueType = wrapperClass(valueType);
List<AbstractConstraintModel> constraintModels = new ArrayList<AbstractConstraintModel>();
nextConstraint: for (Annotation constraintAnnotation : filter(translate(type(), hasAnnotation(ConstraintDeclaration.class)), constraintAnnotations)) {
// Check composite declarations first
Class<? extends Annotation> annotationType = constraintAnnotation.annotationType();
for (Class<? extends Constraint<?, ?>> constraint : constraintClasses) {
if (helper.appliesTo(constraint, annotationType, valueType)) {
constraintModels.add(new ConstraintModel(constraintAnnotation, constraint));
continue nextConstraint;
}
}
// Check the annotation itself
Constraints constraints = annotationType.getAnnotation(Constraints.class);
if (constraints != null) {
for (Class<? extends Constraint<?, ?>> constraintClass : constraints.value()) {
if (helper.appliesTo(constraintClass, annotationType, valueType)) {
constraintModels.add(new ConstraintModel(constraintAnnotation, constraintClass));
continue nextConstraint;
}
}
}
// No implementation found!
// Check if if it's a composite constraints
Iterable<Annotation> annotations = iterable(annotationType.getAnnotations());
if (Iterables.matchesAny(translate(type(), hasAnnotation(ConstraintDeclaration.class)), annotations)) {
ValueConstraintsModel valueConstraintsModel = constraintsFor(annotations, valueType, name, optional, constraintClasses, accessor);
CompositeConstraintModel compositeConstraintModel = new CompositeConstraintModel(constraintAnnotation, valueConstraintsModel);
constraintModels.add(compositeConstraintModel);
continue nextConstraint;
}
throw new InvalidCompositeException("Cannot find implementation of constraint @" + annotationType.getSimpleName() + " for " + valueType + " in method " + ((Member) accessor).getName() + " of composite " + types);
}
return new ValueConstraintsModel(constraintModels, name, optional);
}
use of org.qi4j.api.composite.InvalidCompositeException in project qi4j-sdk by Qi4j.
the class CompositeModel method createProxyClass.
@SuppressWarnings("unchecked")
private void createProxyClass() {
Class<?> mainType = first(types);
if (mainType.isInterface()) {
ClassLoader proxyClassloader = mainType.getClassLoader();
Class<?>[] interfaces = Iterables.toArray(Class.class, Iterables.<Class>cast(types));
proxyClass = (Class<? extends Composite>) ProxyGenerator.createProxyClass(proxyClassloader, interfaces);
try {
proxyConstructor = proxyClass.getConstructor(InvocationHandler.class);
} catch (NoSuchMethodException e) {
throw (InvalidCompositeException) new InvalidCompositeException("Could not get proxy constructor").initCause(e);
}
proxyConstructor.setAccessible(true);
} else {
try {
proxyClass = new TransientClassLoader(getClass().getClassLoader()).loadFragmentClass(mainType);
proxyConstructor = (Constructor<? extends Composite>) proxyClass.getConstructors()[0];
} catch (ClassNotFoundException e) {
throw (InvalidCompositeException) new InvalidCompositeException("Could not get proxy constructor").initCause(e);
}
}
}
Aggregations