// TODO create names for anonymous resource
// throw new RuntimeException(
// "Cannot create names for anonymous resources (yet)");
}
URI uri = (URI)uriOrBlankNode;
String rawname;
if(uri != null) {
if(getLocalPart(uri.toString()) != null) {
rawname = getLocalPart(uri.toString());
} else {
rawname = uri.toString();
}
} else {
// generate name! only needed for blank nodes
rawname = "genBean" + System.currentTimeMillis();
}
// remove preceeding 'has'
if(rawname.toLowerCase().startsWith("has") && rawname.length() > 3) {
rawname = rawname.substring(3);
}
// make rawname bean-style
String beanname = toLegalJavaIdentifier(rawname);
// now we have a nice bean name - but is it unique?
if(usedNames.contains(beanname)) {
// TODO check when this happens and deal better with it
if(uri == null) {
throw new IllegalStateException("");
}
// try to use namespace prefix for disambiguation
String namespacePrefix = guessNSPrefix(uri.toString());
String prefixedBeanName = toLegalJavaIdentifier(namespacePrefix + beanname);
if(usedNames.contains(prefixedBeanName)) {
// fallback to plain uri
beanname = toLegalJavaIdentifier(uri.toString());
} else {
beanname = prefixedBeanName;
}
}