@Override public void initialize(final Module module) throws MethodCallException { final Object delegateObject = module.getDelegateObject(); if (initializerRef == null) { initializerRef = new MethodRef(delegateObject.getClass(), getInitializer()); } initializerRef.execute(module.getDelegateObject()); }
@Override public void validate(final Module module) throws MethodCallException { final Object delegateObject = module.getDelegateObject(); if (validaterRef == null) { validaterRef = new MethodRef(delegateObject.getClass(), getValidater()); } validaterRef.execute(module.getDelegateObject()); }
@Override public void initialize(final Module module) throws MethodCallException { final Object delegateObject = module.getDelegateObject(); if (initializerRef == null) { initializerRef = new MethodRef(delegateObject.getClass(), getInitializer()); } initializerRef.execute(module.getDelegateObject()); }
@Override public void validate(final Module module) throws MethodCallException { final Object delegateObject = module.getDelegateObject(); if (validaterRef == null) { validaterRef = new MethodRef(delegateObject.getClass(), getValidater()); } validaterRef.execute(module.getDelegateObject()); }
final Object delegate = module.getDelegateObject(); if (types != null) { for (final Type t : types) {
@Override public void process(final Module module) { if (log == null || !log.isDebug()) return; log.debug("Executing module: " + module.getDelegateObject()); }
@Override public void process(final Module module) { if (log == null || !log.isDebug()) return; log.debug("Executing module: " + module.getDelegateObject()); }
@Override public void process(final Module module) { if (ops == null) return; // no op service available to inject final Object delegate = module.getDelegateObject(); if (!(delegate instanceof Op)) return; // command is not an op final Op op = (Op) delegate; if (op.ops() != null) return; // op already has an environment op.setEnvironment(ops); }
@Override public void callback(final Module module) throws MethodCallException { final Object delegateObject = module.getDelegateObject(); if (callbackRef == null) { callbackRef = new MethodRef(delegateObject.getClass(), getCallback()); } callbackRef.execute(delegateObject); }
@Override public void callback(final Module module) throws MethodCallException { final Object delegateObject = module.getDelegateObject(); if (callbackRef == null) { callbackRef = new MethodRef(delegateObject.getClass(), getCallback()); } callbackRef.execute(delegateObject); }
if (log.isDebug()) { log.debug("Selected '" + matches.get(0).getRef().getLabel() + "' op: " + m.getDelegateObject().getClass().getName()); if (m.getDelegateObject() instanceof Initializable) { ((Initializable) m.getDelegateObject()).initialize();
@Override public void process(final Module module) { final Object command = module.getDelegateObject(); if (command instanceof IceCommand || command instanceof FireCommand) { // NB: A Monty Python quote which is also a Game of Thrones reference. // That's right -- we did that. cancel("NO SINGING!"); } } }
@Override public void process(final Module module) { if (logService == null || moduleService == null) return; final ModuleItem<?> loggerInput = moduleService.getSingleInput(module, Logger.class); if (loggerInput == null || !loggerInput.isAutoFill()) return; String loggerName = loggerInput.getLabel(); if(loggerName == null || loggerName.isEmpty()) loggerName = module.getDelegateObject().getClass().getSimpleName(); Logger logger = logService.subLogger(loggerName); final String name = loggerInput.getName(); module.setInput(name, logger); module.resolveInput(name); }
@Override public void process(final Module module) { if (logService == null || moduleService == null) return; final ModuleItem<?> loggerInput = moduleService.getSingleInput(module, Logger.class); if (loggerInput == null || !loggerInput.isAutoFill()) return; String loggerName = loggerInput.getLabel(); if(loggerName == null || loggerName.isEmpty()) loggerName = module.getDelegateObject().getClass().getSimpleName(); Logger logger = logService.subLogger(loggerName); final String name = loggerInput.getName(); module.setInput(name, logger); module.resolveInput(name); }
/** * Verifies that the given candidate's module conforms. * <p> * Helper method of {@link #filterMatches(List)}. * </p> */ private boolean moduleConforms(final OpCandidate candidate) { // create module and assign the inputs final Module module = createModule(candidate, candidate.getArgs()); candidate.setModule(module); // make sure the op itself is happy with these arguments final Object op = module.getDelegateObject(); if (op instanceof Contingent) { final Contingent c = (Contingent) op; if (!c.conforms()) { candidate.setStatus(StatusCode.DOES_NOT_CONFORM); return false; } } // found a match! return true; }
private void assertMatches(final String name, Class<?>... opTypes) { final List<OpCandidate> candidates = matcher.findCandidates(ops, OpRef .create(name)); final List<OpCandidate> matches = matcher.filterMatches(candidates); assertEquals(opTypes.length, matches.size()); for (int i = 0; i < opTypes.length; i++) { final Module m = matches.get(i).getModule(); assertSame(opTypes[i], m.getDelegateObject().getClass()); } }
@SuppressWarnings("unchecked") private <T> void assignNamespace(final Module module, final ModuleItem<T> item) { if (module.isInputResolved(item.getName())) return; // if possible, extract the OpEnvironment from the delegate object final Object delegate = module.getDelegateObject(); final OpEnvironment env = delegate instanceof Environmental ? // ((Environmental) delegate).ops() : ops; if (env == null) return; T defaultValue = null; if (Namespace.class.isAssignableFrom(item.getType())) { defaultValue = (T) nsService.create(// (Class<? extends Namespace>) item.getType(), env); } if (defaultValue == null) return; item.setValue(module, defaultValue); module.resolveInput(item.getName()); } }
/** Helper method of {@link #match(OpCandidate)}. */ private Module match(final OpCandidate candidate, final Object[] args) { // check that each parameter is compatible with its argument final int badIndex = typesMatch(candidate, args); if (badIndex >= 0) { final String message = typeClashMessage(candidate, args, badIndex); candidate.setStatus(StatusCode.ARG_TYPES_DO_NOT_MATCH, message); return null; } // create module and assign the inputs final Module module = createModule(candidate, args); candidate.setModule(module); // make sure the op itself is happy with these arguments final Object op = module.getDelegateObject(); if (op instanceof Contingent) { final Contingent c = (Contingent) op; if (!c.conforms()) { candidate.setStatus(StatusCode.DOES_NOT_CONFORM); return null; } } // found a match! return module; }
/** Tests {@link OpService#module(Op, Object...)}. */ @Test public void testModuleByOp() { final DoubleType value = new DoubleType(123.456); final Module module = ops.module(new InfinityOp(), value); assertSame(InfinityOp.class, module.getDelegateObject().getClass()); assertSame(value, module.getInput("arg")); assertFalse(Double.isInfinite(value.get())); module.run(); assertTrue(Double.isInfinite(value.get())); }