/** * Serialize a class hierarchy into a protocol buffer object. * * @param classHierarchy * @return * @deprecated in 0.12. Use AvroClassHierarchySerializer instead */ public static ClassHierarchyProto.Node serialize(final ClassHierarchy classHierarchy) { return serializeNode(classHierarchy.getNamespace()); }
@Override public void registerLegacyConstructor(final String s, final String... args) throws BindException { final ClassNode<?> cn = (ClassNode<?>) namespace.getNode(s); final ClassNode<?>[] cnArgs = new ClassNode[args.length]; for (int i = 0; i < args.length; i++) { cnArgs[i] = (ClassNode<?>) namespace.getNode(args[i]); } registerLegacyConstructor(cn, cnArgs); }
public <T> void bindImplementation(final ClassNode<T> n, final ClassNode<? extends T> m) throws BindException { if (namespace.isImplementation(n, m)) { boundImpls.put(n, m); } else { throw new IllegalArgumentException("Class" + m + " does not extend " + n); } }
@SuppressWarnings("unchecked") private <T> void addConfiguration(final ClassHierarchy ns, final ConfigurationBuilderImpl builder) throws BindException { namespace = namespace.merge(ns); if (namespace instanceof ClassHierarchyImpl || builder.namespace instanceof ClassHierarchyImpl) { if (namespace instanceof ClassHierarchyImpl && builder.namespace instanceof ClassHierarchyImpl) {
@SuppressWarnings("unchecked") @Override public <U> U getInstance(final String clazz) throws InjectionException, NameResolutionException { return (U) getInstance(namespace.getNode(clazz)); }
/** * Serialize the ClassHierarchy into the AvroNode. * @param ch ClassHierarchy to serialize * @return a Avro node having class hierarchy */ public AvroNode toAvro(final ClassHierarchy ch) { return newAvroNode(ch.getNamespace()); }
@SuppressWarnings("unchecked") @Override public void bindSetEntry(final String iface, final Node impl) throws BindException { boundSetEntries.put((NamedParameterNode<Set<?>>) namespace.getNode(iface), impl); }
/** * serialize a class hierarchy into a file. * * @param file * @param classHierarchy * @throws IOException * @deprecated in 0.12. Use AvroClassHierarchySerializer instead */ public static void serialize(final File file, final ClassHierarchy classHierarchy) throws IOException { final ClassHierarchyProto.Node node = serializeNode(classHierarchy.getNamespace()); try (final FileOutputStream output = new FileOutputStream(file)) { try (final DataOutputStream dos = new DataOutputStream(output)) { node.writeTo(dos); } } }
@Override public <T> void bind(final String key, final String value) throws BindException { final Node n = namespace.getNode(key); if (n instanceof NamedParameterNode) { bindParameter((NamedParameterNode<?>) n, value); } else if (n instanceof ClassNode) { final Node m = namespace.getNode(value); bind((ClassNode<?>) n, (ClassNode<?>) m); } else { throw new IllegalStateException("getNode() returned " + n + " which is neither a ClassNode nor a NamedParameterNode"); } }
/** * Produce a Graphviz DOT string for a given TANG configuration. * * @param config TANG configuration object. * @param showImpl If true, plot IS-A edges for know implementations. * @param showLegend If true, add legend to the plot. * @return configuration graph represented as a string in Graphviz DOT format. */ public static String getGraphvizString(final Configuration config, final boolean showImpl, final boolean showLegend) { final GraphvizConfigVisitor visitor = new GraphvizConfigVisitor(config, showImpl, showLegend); final Node root = config.getClassHierarchy().getNamespace(); Walk.preorder(visitor, visitor, root); return visitor.toString(); }
@Override public InjectionPlan<?> getInjectionPlan(final String name) throws NameResolutionException { return getInjectionPlan(namespace.getNode(name)); }
for (final Node n : ch.getNamespace().getChildren()) { if (!this.namespace.contains(n.getFullName())) { if (n instanceof NamedParameter) {
@SuppressWarnings("unchecked") @Override public void bindSetEntry(final String iface, final String impl) throws BindException { boundSetEntries.put((NamedParameterNode<Set<?>>) namespace.getNode(iface), impl); }
for (final Node n : ch.getNamespace().getChildren()) { if (!this.namespace.contains(n.getFullName())) { if (n instanceof NamedParameter) {
@Override public boolean isParameterSet(final String name) throws NameResolutionException { final InjectionPlan<?> p = getInjectionPlan(namespace.getNode(name)); return p.isInjectable(); }
@Override public String classPrettyDescriptionString(final String fullName) throws NameResolutionException { final NamedParameterNode<?> param = (NamedParameterNode<?>) namespace .getNode(fullName); return param.getDocumentation() + "\n" + param.getFullName(); }
@Override public boolean isInjectable(final String name) throws NameResolutionException { return getInjectionPlan(namespace.getNode(name)).isInjectable(); }
@SuppressWarnings("unchecked") @Override public void bindList(final String iface, final List implList) { final NamedParameterNode<List<?>> ifaceNode = (NamedParameterNode<List<?>>) namespace.getNode(iface); // Check parsability of list items for (final Object item : implList) { if (item instanceof String) { final JavaClassHierarchy javanamespace = (ClassHierarchyImpl) namespace; try { // Just for parsability checking. javanamespace.parse(ifaceNode, (String) item); } catch (final ParseException e) { throw new IllegalStateException("Could not parse " + item + " which was passed to " + iface, e); } } } boundLists.put(ifaceNode, implList); }
public Set<NamedParameterNode<?>> getBoundNamedParameters() { final Configuration c = this.builder.b.build(); final Set<NamedParameterNode<?>> nps = new MonotonicSet<>(); nps.addAll(c.getNamedParameters()); for (final Class<?> np : this.builder.freeParams.keySet()) { try { nps.add((NamedParameterNode<?>) builder.b.getClassHierarchy().getNode(ReflectionUtilities.getFullName(np))); } catch (final NameResolutionException e) { throw new IllegalStateException(e); } } return nps; }
@Override public String classPrettyDefaultString(final String longName) throws NameResolutionException { final NamedParameterNode<?> param = (NamedParameterNode<?>) namespace .getNode(longName); return param.getSimpleArgName() + "=" + join(",", param.getDefaultInstanceAsStrings()); }