/** * Converts the collected mapping information into {@link IMapper} instances. * * @throws MIOException In case of an error. */ private void _buildMapping() throws MIOException { for (Entry<String, Mapping> entry : _mappings.entrySet()) { Mapping mapping = entry.getValue(); String predicate = entry.getKey(); switch (mapping.kind) { case NAME: _handler.handleName(predicate, _toArray(mapping.scope), mapping.type, false); break; case OCCURRENCE: _handler.handleOccurrence(predicate, _toArray(mapping.scope), mapping.type, false); break; case TYPE_INSTANCE: _handler.handleInstanceOf(predicate, _toArray(mapping.scope)); break; case ASSOCIATION: { _handler.handleAssociation( predicate, mapping.subject, mapping.object, _toArray(mapping.scope), mapping.type); break; } default: throw new MIOException("Invalid mapping for <" + entry.getKey() + ">"); } } }
/* (non-Javadoc) * @see com.semagia.mio.rdf.IMappingReader#read() */ @Override public void read(final Source source) throws IOException, MIOException { // TODO: check for characterstream / bytestream _parser.setRDFHandler(new RDFStatementHandler()); final InputStream stream = new BufferedInputStream(new URL(source.getIRI()).openStream()); _handler.start(); try { _parser.parse(stream, source.getBaseIRI()); } catch (OpenRDFException ex) { if (ex.getCause() instanceof MIOException) { throw (MIOException) ex.getCause(); } if (ex instanceof RDFParseException) { throw new MIOParseException( ex, ((RDFParseException) ex).getLineNumber(), ((RDFParseException) ex).getColumnNumber()); } throw new MIOException(ex); } finally { if (stream != null) { stream.close(); } } _buildMapping(); _handler.end(); _mappings.clear(); }