@Override public String apply(Name<?> input) { return Factory.activationKey(input.getClazz(), input.getName()); } }));
@Override protected Optional<NamedComponent<T>> doFindOne() { Set<NamedComponent<T>> components = doFind(); if (components.isEmpty()) { return Optional.absent(); } else if (components.size() == 1) { return Optional.of(components.iterator().next()); } else { StringBuilder sb = new StringBuilder(); sb.append("more than one component is available for query ").append(this).append(".\n") .append(" Please select which one you want with a more specific query,\n") .append(" or by deactivating one of the available components.\n") .append(" Available components:\n"); for (NamedComponent<T> component : components) { sb.append(" - ").append(component).append("\n") .append(" [Activation key: '") .append(activationKey(component.getName().getClazz(), component.getName().getName())) .append("']\n"); } throw UnsatisfiedDependency.on(this).causedBy(sb.toString()).raise(); } } }
private <T> boolean checkActive(Name<T> name) { if (name.getClazz() == String.class && name.getName().startsWith("restx.activation::")) { // can't deactivate activation keys themselves return true; } // check 'cache' for perf reasons - core Factory being immutable the 'cache' never needs to be invalidated if (deactivatedComponents.contains(name)) { return false; } if (activatedComponents.contains(name)) { return true; } // actual check Class<?> aClass = name.getClazz(); while (aClass != null) { if ("false".equals(queryByName(Name.of(String.class, activationKey(aClass, name.getName()))) .findOneAsComponent().or("true"))) { deactivatedComponents.add(name); return false; } aClass = aClass.getSuperclass(); } activatedComponents.add(name); return true; }