@VisibleForTesting public <T extends Entity> T createEntityProxy(EntitySpec<T> spec, T entity) { Set<Class<?>> interfaces = Sets.newLinkedHashSet(); if (spec.getType().isInterface()) { interfaces.add(spec.getType()); } else { log.warn("EntitySpec declared in terms of concrete type "+spec.getType()+"; should be supplied in terms of interface"); interfaces.addAll(Reflections.getAllInterfaces(spec.getType())); } interfaces.addAll(spec.getAdditionalInterfaces()); return createEntityProxy(interfaces, entity); }
/** * Searches for config keys in the type, additional interfaces and the implementation (if specified) */ private Collection<FlagUtils.FlagConfigKeyAndValueRecord> findAllFlagsAndConfigKeys(EntitySpec<? extends Entity> spec, ConfigBag bagFlags) { Set<FlagUtils.FlagConfigKeyAndValueRecord> allKeys = MutableSet.of(); allKeys.addAll(FlagUtils.findAllFlagsAndConfigKeys(null, spec.getType(), bagFlags)); if (spec.getImplementation() != null) { allKeys.addAll(FlagUtils.findAllFlagsAndConfigKeys(null, spec.getImplementation(), bagFlags)); } for (Class<?> iface : spec.getAdditionalInterfaces()) { allKeys.addAll(FlagUtils.findAllFlagsAndConfigKeys(null, iface, bagFlags)); } return allKeys; }
@Override protected EntitySpec<T> copyFrom(EntitySpec<T> otherSpec) { super.copyFrom(otherSpec) .additionalInterfaces(otherSpec.getAdditionalInterfaces()) .policySpecs(otherSpec.getPolicySpecs()) .policies(otherSpec.getPolicies()) .enricherSpecs(otherSpec.getEnricherSpecs()) .enrichers(otherSpec.getEnrichers()) .addInitializers(otherSpec.getInitializers()) .children(copyFromSpecs(otherSpec.getChildren())) .members(otherSpec.getMembers()) .groups(otherSpec.getGroups()) .locationSpecs(otherSpec.getLocationSpecs()) .locations(otherSpec.getLocations()); if (otherSpec.getParent() != null) parent(otherSpec.getParent()); if (otherSpec.getImplementation() != null) impl(otherSpec.getImplementation()); return this; }