/** * Packs the proxies created by the Anno4j instance into a JAR file. * @param commandLine The parsed command line arguments. * @param anno4j The Anno4j instance. * @throws RepositoryException Thrown if an error occurs while querying the repository. * @throws IOException Thrown if an error occurs while writing the JAR file. */ private static void packProxies(CommandLine commandLine, Anno4j anno4j) throws RepositoryException, IOException { ClassFactory factory = anno4j.getObjectRepository().getConnection().getObjectFactory().getResolver().getClassFactory(); JarPacker packer = new JarPacker(new File(getOutputPath(commandLine) + "proxies.jar")); packer.addFile(factory.getOutput()); packer.close(); }
/** * Creates an Anno4j instance that can use the concepts contained in the given JAR file. * @param ontologyJar A JAR file containing concepts. * @param classLoader The class loader to use. * @param persistSchemaAnnotations Whether schema annotations should be scanned. * @return Returns an Anno4j instance. * @throws Exception Thrown on error. */ private static Anno4j getAnno4jWithClassLoader(File ontologyJar, ClassLoader classLoader, boolean persistSchemaAnnotations) throws Exception { Set<URL> clazzes = new HashSet<>(); clazzes.addAll(ClasspathHelper.forManifest(ontologyJar.toURI().toURL())); Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), new IDGeneratorAnno4jURN(), null, persistSchemaAnnotations, clazzes); // Register concepts found in JAR: RoleMapper mapper = anno4j.getObjectRepository().getConnection().getObjectFactory().getResolver().getRoleMapper(); for (final String className : getClassNamesInJar(ontologyJar)) { Class<?> clazz = classLoader.loadClass(className); if(clazz.getAnnotation(Iri.class) != null) { mapper.addConcept(clazz); } } return anno4j; }