public void validatePlan() throws IOException, BindException, InjectionException { final Tang t = Tang.Factory.getTang(); // TODO Use the AvroClassHierarchySerializer final ClassHierarchyProto.Node root; try (final InputStream chin = new FileInputStream(this.ch)) { root = ClassHierarchyProto.Node.parseFrom(chin); } final ClassHierarchy classHierarchy = new ProtocolBufferClassHierarchy(root); final ConfigurationBuilder cb = t.newConfigurationBuilder(classHierarchy); if (!inConfig.canRead()) { throw new IOException("Cannot read input config file: " + inConfig); } ConfigurationFile.addConfiguration(cb, inConfig); if (target != null) { final Injector i = t.newInjector(cb.build()); final InjectionPlan<?> ip = i.getInjectionPlan(target); if (!ip.isInjectable()) { throw new InjectionException(target + " is not injectable: " + ip.toCantInjectString()); } } ConfigurationFile.writeConfigurationFile(cb.build(), outConfig); // Injector i = t.newInjector(cb.build()); // InjectionPlan<?> ip = i.getInjectionPlan(target); // try (final OutputStream ipout = new FileOutputStream(injectionPlan)) { // new ProtocolBufferInjectionPlan().serialize(ip).writeTo(ipout); // } }
/** * Deserialize a class hierarchy from a file. The file can be generated from either Java or C# * * @param file * @return * @throws IOException */ public static ClassHierarchy deserialize(final File file) throws IOException { try (final InputStream stream = new FileInputStream(file)) { final ClassHierarchyProto.Node root = ClassHierarchyProto.Node.parseFrom(stream); return new ProtocolBufferClassHierarchy(root); } }