private void scanConceptsWithReflections() throws ObjectStoreConfigException { logger.debug("Search for concepts with reflections"); Set<URL> classpath = new HashSet<>(); classpath.addAll(ClasspathHelper.forClassLoader()); classpath.addAll(ClasspathHelper.forJavaClassPath()); classpath.addAll(ClasspathHelper.forManifest()); classpath.addAll(ClasspathHelper.forPackage("")); Reflections reflections = new Reflections(new ConfigurationBuilder() .setUrls(classpath) .useParallelExecutor() .filterInputsBy(FilterBuilder.parsePackages("-java, -javax, -sun, -com.sun")) .setScanners(new SubTypesScanner(), new TypeAnnotationsScanner())); Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(Iri.class, true); logger.debug("Search for concepts with reflections resulted in " + annotated.size() + " classes"); for (Class clazz : annotated) { logger.debug("Found concept class: " + clazz.getCanonicalName()); roleMapper.addConcept(clazz); } }
private void recordRole(Class<?> clazz, String uri, boolean concept) throws ObjectStoreConfigException { if (uri == null || uri.length() == 0) { if (clazz.isAnnotation()) { roleMapper.addAnnotation(clazz); } else if (isAnnotationPresent(clazz) || concept) { roleMapper.addConcept(clazz); } else { roleMapper.addBehaviour(clazz); } } else { if (clazz.isAnnotation()) { roleMapper.addAnnotation(clazz, new URIImpl(uri)); } else if (isAnnotationPresent(clazz) || concept) { roleMapper.addConcept(clazz, new URIImpl(uri)); } else { roleMapper.addBehaviour(clazz, new URIImpl(uri)); } } }
private void recordRole(Class<?> clazz, String uri, boolean concept) throws ObjectStoreConfigException { if (uri == null || uri.length() == 0) { if (clazz.isAnnotation()) { roleMapper.addAnnotation(clazz); } else if (isAnnotationPresent(clazz) || concept) { roleMapper.addConcept(clazz); } else { roleMapper.addBehaviour(clazz); } } else { if (clazz.isAnnotation()) { roleMapper.addAnnotation(clazz, new URIImpl(uri)); } else if (isAnnotationPresent(clazz) || concept) { roleMapper.addConcept(clazz, new URIImpl(uri)); } else { roleMapper.addBehaviour(clazz, new URIImpl(uri)); } } }
mapper.addConcept(e.getKey()); } else { for (URI value : e.getValue()) { mapper.addConcept(e.getKey(), value);
mapper.addConcept(e.getKey()); } else { for (URI value : e.getValue()) { mapper.addConcept(e.getKey(), value);
/** * 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; }