@Override public Model open(Assembler a, Resource root, Mode mode) { Resource rootModel = getUniqueResource(root, BASE_MODEL); if (rootModel == null) { throw new AssemblerException(root, String.format(NO_X_PROVIDED, BASE_MODEL, root)); } Model baseModel = a.openModel(rootModel, mode); Literal modelName = getUniqueLiteral(root, JA.modelName); if (modelName == null) { throw new AssemblerException(root, String.format(NO_X_PROVIDED, JA.modelName, root)); } Literal factoryName = getUniqueLiteral(root, EVALUATOR_FACTORY); if (factoryName == null) { throw new AssemblerException(root, String.format(NO_X_PROVIDED, EVALUATOR_FACTORY, root)); } SecurityEvaluator securityEvaluator = null; try { Class<?> factoryClass = Class.forName(factoryName.getString()); Method method = factoryClass.getMethod("getInstance"); if (!SecurityEvaluator.class.isAssignableFrom(method.getReturnType())) { throw new AssemblerException( root, String.format( "%s (found at %s for %s) getInstance() must return an instance of SecurityEvaluator", factoryName, EVALUATOR_FACTORY, root)); } if (!Modifier.isStatic(method.getModifiers())) { throw new AssemblerException( root, String.format( "%s (found at %s for %s) getInstance() must be a static method", factoryName, EVALUATOR_FACTORY, root)); } securityEvaluator = (SecurityEvaluator) method.invoke(null); } catch (SecurityException e) { throw new AssemblerException( root, String.format(ERROR_FINDING_FACTORY, factoryName, e.getMessage()), e); } catch (IllegalArgumentException e) { throw new AssemblerException( root, String.format(ERROR_FINDING_FACTORY, factoryName, e.getMessage()), e); } catch (ClassNotFoundException e) { throw new AssemblerException( root, String.format( "Class %s (found at %s for %s) could not be loaded", factoryName, EVALUATOR_FACTORY, root)); } catch (NoSuchMethodException e) { throw new AssemblerException( root, String.format( "%s (found at %s for %s) must implement a static getInstance() that returns an instance of SecurityEvaluator", factoryName, EVALUATOR_FACTORY, root)); } catch (IllegalAccessException e) { throw new AssemblerException( root, String.format(ERROR_FINDING_FACTORY, factoryName, e.getMessage()), e); } catch (InvocationTargetException e) { throw new AssemblerException( root, String.format(ERROR_FINDING_FACTORY, factoryName, e.getMessage()), e); } return Factory.getInstance(securityEvaluator, modelName.asLiteral().getString(), baseModel); }