Ejemplo n.º 1
0
 /* (non-Javadoc)
  * @see org.openrdf.rio.helpers.RDFHandlerBase#handleStatement(org.openrdf.model.Statement)
  */
 @Override
 public void handleStatement(final Statement stmt) throws RDFHandlerException {
   final String predicate = stmt.getPredicate().stringValue();
   if (!predicate.startsWith("http://psi.ontopia.net/rdf2tm/#")) {
     return;
   }
   final String subject = stmt.getSubject().stringValue();
   if (!(stmt.getObject() instanceof URI)) {
     throw new RDFHandlerException(
         new MIOException("The object of the RDF mapping must be an IRI"));
   }
   final String object = stmt.getObject().stringValue();
   if (RDF2TM.MAPS_TO.equals(predicate)) {
     if (RDF2TM.BASENAME.equals(object)) {
       getMapping(subject).kind = NAME;
     } else if (RDF2TM.OCCURRENCE.equals(object)) {
       getMapping(subject).kind = OCCURRENCE;
     } else if (RDF2TM.INSTANCE_OF.equals(object)) {
       getMapping(subject).kind = TYPE_INSTANCE;
     } else if (RDF2TM.ASSOCIATION.equals(object)) {
       getMapping(subject).kind = ASSOCIATION;
     } else if (RDF2TM.SUBJECT_IDENTIFIER.equals(object)) {
       try {
         _handler.handleSubjectIdentifier(subject);
       } catch (MIOException ex) {
         throw new RDFHandlerException(ex);
       }
     } else if (RDF2TM.SUBJECT_LOCATOR.equals(object)) {
       try {
         _handler.handleSubjectLocator(subject);
       } catch (MIOException ex) {
         throw new RDFHandlerException(ex);
       }
     } else if (RDF2TM.SOURCE_LOCATOR.equals(object)) {
       try {
         _handler.handleItemIdentifier(subject);
       } catch (MIOException ex) {
         throw new RDFHandlerException(ex);
       }
     } else {
       throw new RDFHandlerException(
           new MIOException(
               "Unknown object of a rtm:maps-to mapping. Object: <" + object + ">"));
     }
   } else if (RDF2TM.TYPE.equals(predicate)) {
     getMapping(subject).type = object;
   } else if (RDF2TM.IN_SCOPE.equals(predicate)) {
     Mapping mapping = getMapping(subject);
     if (mapping.scope == null) {
       mapping.scope = new ArrayList<String>();
     }
     mapping.scope.add(object);
   } else if (RDF2TM.SUBJECT_ROLE.equals(predicate)) {
     getMapping(subject).subject = object;
   } else if (RDF2TM.OBJECT_ROLE.equals(predicate)) {
     getMapping(subject).object = object;
   } else {
     throw new RDFHandlerException(new MIOException("Unknown predicate <" + predicate + ">"));
   }
 }