Ejemplo n.º 1
0
 /**
  * Gets NXRelations node instance given Jena node.
  *
  * @param jenaNodeInst
  * @return NXRelations node instance
  */
 private Node getNXRelationsNode(com.hp.hpl.jena.graph.Node jenaNodeInst) {
   if (jenaNodeInst == null) {
     return null;
   }
   Node nuxNode = null;
   if (jenaNodeInst.isBlank()) {
     AnonId anonId = jenaNodeInst.getBlankNodeId();
     String id = anonId.getLabelString();
     nuxNode = NodeFactory.createBlank(id);
   } else if (jenaNodeInst.isLiteral()) {
     LiteralLabel label = jenaNodeInst.getLiteral();
     String value = label.getLexicalForm();
     String type = jenaNodeInst.getLiteralDatatypeURI();
     String language = jenaNodeInst.getLiteralLanguage();
     if (type != "") {
       nuxNode = NodeFactory.createTypedLiteral(value, type);
     } else if (language != "") {
       nuxNode = NodeFactory.createLiteral(value, language);
     } else {
       nuxNode = NodeFactory.createLiteral(value);
     }
   } else if (jenaNodeInst.isURI()) {
     String uri = jenaNodeInst.getURI();
     // try to find corresponding prefix
     // TODO AT: maybe take namespaces from relation service?
     for (Map.Entry<String, String> ns : namespaces.entrySet()) {
       String base = ns.getValue();
       if (uri.startsWith(base)) {
         String localName = uri.substring(base.length());
         nuxNode = NodeFactory.createQNameResource(base, localName);
         break;
       }
     }
     if (nuxNode == null) {
       // default to resource
       nuxNode = NodeFactory.createResource(uri);
     }
   } else {
     throw new IllegalArgumentException(
         "Cannot translate non concrete Jena node into NXRelations node");
   }
   return nuxNode;
 }