IdentifierBuilder { public String packageName(ResourceObject object, OntGenerationConfig config) { URI u; try { u = new URI(object.getResourceAsString()); } catch (URISyntaxException e) { return config.getBasePackage(); } if(u.getHost() != null) { String[] splits = u.getHost().toLowerCase().split("\\."); List<String> packageNamePortions = new LinkedList<>(); for (int i = splits.length - 1; i >= 0; i--) { if(!splits[i].isEmpty() && !splits[i].matches("[0-9]+") && !splits[i].contains(":")) { String portion; try { portion = toJavaName(splits[i]); packageNamePortions.add(portion); } catch (IllegalArgumentException ignored) { } } } if(packageNamePortions.size() > 0) { StringBuilder packageName = new StringBuilder(); ListIterator<String> portionIter = packageNamePortions.listIterator(); while(portionIter.hasNext()) { packageName.append(portionIter.next()); if(portionIter.hasNext()) { packageName.append("."); } } if(!config.getBasePackage().isEmpty()) { return config.getBasePackage() + "." + packageName.toString(); } else { return packageName.toString(); } } else { return config.getBasePackage(); } } else { return config.getBasePackage(); } } IdentifierBuilder(ObjectConnection connection); static IdentifierBuilder forObjectRepository(ObjectRepository repository); static IdentifierBuilder forObjectRepository(ObjectConnection connection); String packageName(ResourceObject object, OntGenerationConfig config); String lowercaseIdentifier(ResourceObject resource, OntGenerationConfig config); String capitalizedIdentifier(ResourceObject resource, OntGenerationConfig config); String lowercasePluralIdentifier(ResourceObject resource, OntGenerationConfig config); String capitalizedPluralIdentifier(ResourceObject resource, OntGenerationConfig config);  }
@Test public void testPackageName() throws Exception { IdentifierBuilder builder = IdentifierBuilder.forObjectRepository(anno4j.getObjectRepository()); assertEquals("com.xmlns", builder.packageName(anno4j.createObject(RDFSClazz.class, (Resource) new URIImpl(FOAF.HOMEPAGE)), config)); assertEquals("de.uni_passau.fim", builder.packageName(anno4j.createObject(RDFSClazz.class, (Resource) new URIImpl("http: assertEquals("over.its.finally_", builder.packageName(anno4j.createObject(RDFSClazz.class, (Resource) new URIImpl("http: assertEquals("", builder.packageName(anno4j.createObject(RDFSClazz.class, (Resource) new URIImpl("http: assertEquals("", builder.packageName(anno4j.createObject(RDFSClazz.class, (Resource) new URIImpl("urn:isbn:3827370191")), config)); }