org.citygml4j.xml.io.reader.CityGMLReadException Java Examples
The following examples show how to use
org.citygml4j.xml.io.reader.CityGMLReadException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JAXBSimpleReader.java From citygml4j with Apache License 2.0 | 6 votes |
public synchronized XMLChunk nextChunk() throws CityGMLReadException { XMLChunkImpl next = null; if (iterator || hasNext()) { try { next = new XMLChunkImpl(this, null); while (reader.hasNext()) { next.addEvent(reader); if (next.isComplete()) break; reader.next(); } } catch (XMLStreamException e) { throw new CityGMLReadException("Caused by: ", e); } } if (next == null) throw new NoSuchElementException(); else { iterator = false; return next; } }
Example #2
Source File: AbstractJAXBReader.java From citygml4j with Apache License 2.0 | 6 votes |
public void close() throws CityGMLReadException { try { factory = null; schemaHandler = null; jaxbUnmarshaller = null; elementChecker = null; validationSchemaHandler = null; validationEventHandler = null; filter = null; if (reader != null) { reader.close(); in.close(); } } catch (XMLStreamException | IOException e) { throw new CityGMLReadException("Caused by: ", e); } }
Example #3
Source File: JAXBInputFactory.java From citygml4j with Apache License 2.0 | 6 votes |
public CityGMLReader createCityGMLReader(String systemId, InputStream in) throws CityGMLReadException { try { XMLStreamReader streamReader = xmlInputFactory.createXMLStreamReader(systemId, in); URI baseURI = toURI(systemId != null ? SystemIDResolver.getAbsoluteURI(systemId) : null); switch (featureReadMode) { case SPLIT_PER_COLLECTION_MEMBER: case SPLIT_PER_FEATURE: return new JAXBChunkReader(streamReader, in, this, baseURI); default: return new JAXBSimpleReader(streamReader, in, this, baseURI); } } catch (XMLStreamException e) { throw new CityGMLReadException("Caused by: ", e); } }
Example #4
Source File: JAXBInputFactory.java From citygml4j with Apache License 2.0 | 6 votes |
public CityGMLReader createCityGMLReader(String systemId, InputStream in, String encoding) throws CityGMLReadException { try { XMLStreamReader streamReader = xmlInputFactory.createXMLStreamReader(in, encoding); URI baseURI = toURI(systemId != null ? SystemIDResolver.getAbsoluteURI(systemId) : null); switch (featureReadMode) { case SPLIT_PER_COLLECTION_MEMBER: case SPLIT_PER_FEATURE: return new JAXBChunkReader(streamReader, in, this, baseURI); default: return new JAXBSimpleReader(streamReader, in, this, baseURI); } } catch (XMLStreamException e) { throw new CityGMLReadException("Caused by: ", e); } }
Example #5
Source File: JAXBInputFactory.java From citygml4j with Apache License 2.0 | 6 votes |
public CityGMLReader createCityGMLReader(File file, String encoding) throws CityGMLReadException { try { FileInputStream in = new FileInputStream(file); XMLStreamReader streamReader = xmlInputFactory.createXMLStreamReader(in, encoding); switch (featureReadMode) { case SPLIT_PER_COLLECTION_MEMBER: case SPLIT_PER_FEATURE: return new JAXBChunkReader(streamReader, in, this, file.toURI().normalize()); default: return new JAXBSimpleReader(streamReader, in, this, file.toURI().normalize()); } } catch (XMLStreamException | FileNotFoundException e) { throw new CityGMLReadException("Caused by: ", e); } }
Example #6
Source File: JAXBInputFactory.java From citygml4j with Apache License 2.0 | 6 votes |
public CityGMLReader createCityGMLReader(File file) throws CityGMLReadException { try { FileInputStream in = new FileInputStream(file); XMLStreamReader streamReader = xmlInputFactory.createXMLStreamReader(in); switch (featureReadMode) { case SPLIT_PER_COLLECTION_MEMBER: case SPLIT_PER_FEATURE: return new JAXBChunkReader(streamReader, in, this, file.toURI().normalize()); default: return new JAXBSimpleReader(streamReader, in, this, file.toURI().normalize()); } } catch (XMLStreamException | FileNotFoundException e) { throw new CityGMLReadException("Caused by: ", e); } }
Example #7
Source File: AbstractJAXBReader.java From citygml4j with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public AbstractJAXBReader(XMLStreamReader reader, InputStream in, JAXBInputFactory factory, URI baseURI) throws CityGMLReadException { if ((Boolean)factory.getProperty(CityGMLInputFactory.SUPPORT_CITYGML_VERSION_0_4_0)) reader = new CityGMLNamespaceMapper(reader); this.reader = reader; this.in = in; this.factory = factory; this.baseURI = baseURI; transformerChainFactory = factory.getTransformerChainFactory(); parseSchema = (Boolean)factory.getProperty(CityGMLInputFactory.PARSE_SCHEMA); useValidation = (Boolean)factory.getProperty(CityGMLInputFactory.USE_VALIDATION); boolean failOnMissingADESchema = (Boolean)factory.getProperty(CityGMLInputFactory.FAIL_ON_MISSING_ADE_SCHEMA); schemaHandler = factory.getSchemaHandler(); jaxbUnmarshaller = factory.builder.createJAXBUnmarshaller(schemaHandler); jaxbUnmarshaller.setThrowMissingADESchema(failOnMissingADESchema); jaxbUnmarshaller.setSkipGenericADEContent((Boolean)factory.getProperty(CityGMLInputFactory.SKIP_GENERIC_ADE_CONTENT)); elementChecker = new XMLElementChecker(schemaHandler, (FeatureReadMode)factory.getProperty(CityGMLInputFactory.FEATURE_READ_MODE), (Boolean)factory.getProperty(CityGMLInputFactory.KEEP_INLINE_APPEARANCE), parseSchema, failOnMissingADESchema, (List<QName>)factory.getProperty(CityGMLInputFactory.EXCLUDE_FROM_SPLITTING), (List<QName>)factory.getProperty(CityGMLInputFactory.SPLIT_AT_FEATURE_PROPERTY)); if (useValidation) { validationSchemaHandler = new ValidationSchemaHandler(schemaHandler); validationEventHandler = factory.getValidationEventHandler(); } }
Example #8
Source File: JAXBChunkReader.java From citygml4j with Apache License 2.0 | 5 votes |
public void close() throws CityGMLReadException { super.close(); current = null; iterator = null; chunks.clear(); chunk = null; elementInfos.clear(); elementInfo = null; }
Example #9
Source File: JAXBChunkReader.java From citygml4j with Apache License 2.0 | 5 votes |
public synchronized boolean hasNext() throws CityGMLReadException { if (iterator == null) { try { iterator = (XMLChunkImpl)nextChunk(); } catch (NoSuchElementException e) { // } } return iterator != null; }
Example #10
Source File: Serialization.java From citygml4j with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { SimpleDateFormat df = new SimpleDateFormat("[HH:mm:ss] "); System.out.println(df.format(new Date()) + "setting up citygml4j context and CityGML builder"); CityGMLContext ctx = CityGMLContext.getInstance(); CityGMLBuilder builder = ctx.createCityGMLBuilder(); System.out.println(df.format(new Date()) + "reading CityGML file LOD3_Railway_v200.gml into main memory"); CityGMLInputFactory in = builder.createCityGMLInputFactory(); CityModel cityModel; try (CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD3_Railway_v200.gml"))) { cityModel = (CityModel) reader.nextFeature(); } // serialize the object tree System.out.println(df.format(new Date()) + "serializing in-memory citygml4j object tree to file out.ser"); Files.createDirectories(Paths.get("output")); // create an ObjectOutputStream to serialize the CityModel // make sure to use a BufferedOutputStream for performance reasons // to keep the file size small, consider using a GZIPOutputStream in addition try (ObjectOutputStream stream = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("output/out.ser")))) { stream.writeObject(cityModel); } System.out.println(df.format(new Date()) + "citygml4j object tree successfully serialized"); // let's read the serialized object tree back into main memory System.out.println(df.format(new Date()) + "deserializing out.ser back into main memory"); // create an ObjectInputStream to deserialize the CityModel // again, make sure to use a BufferedInputStream for performance reasons try (ObjectInputStream stream = new ObjectInputStream(new BufferedInputStream(new FileInputStream("output/out.ser")))) { Object o = stream.readObject(); if (o instanceof CityModel) { System.out.println(df.format(new Date()) + "successfully read citygml4j object tree from file out.ser"); cityModel = (CityModel) o; System.out.println(df.format(new Date()) + "Found the following cityObjectMembers in out.ser:"); EnumMap<CityGMLClass, Integer> features = new EnumMap<>(CityGMLClass.class); cityModel.getCityObjectMember().forEach(m -> features.merge(m.getCityObject().getCityGMLClass(), 1, Integer::sum)); features.forEach((key, value) -> System.out.println(key + ": " + value)); } else throw new CityGMLReadException("Failed to deserialize the file out.ser"); } System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished"); }
Example #11
Source File: AdditionalObjectsHandler.java From web-feature-service with Apache License 2.0 | 4 votes |
protected void writeObjects() { if (!shouldRun) return; try { // close writers to flush buffers for (CityModelWriter tempWriter : tempWriters.values()) tempWriter.close(); CityGMLInputFactory in = cityGMLBuilder.createCityGMLInputFactory(); in.setProperty(CityGMLInputFactory.FEATURE_READ_MODE, FeatureReadMode.SPLIT_PER_COLLECTION_MEMBER); startAdditionalObjects(); Attributes dummyAttributes = new AttributesImpl(); String propertyName = "member"; String propertyQName = saxWriter.getPrefix(Constants.WFS_NAMESPACE_URI) + ":" + propertyName; // iterate over temp files and send additional objects to response stream for (Path tempFile : tempFiles.values()) { try (CityGMLReader tempReader = in.createCityGMLReader(tempFile.toFile())) { while (tempReader.hasNext()) { XMLChunk chunk = tempReader.nextChunk(); if ("CityModel".equals(chunk.getTypeName().getLocalPart()) && Modules.isCityGMLModuleNamespace(chunk.getTypeName().getNamespaceURI())) continue; ContentHandler handler; if (transformerChainFactory == null) handler = saxWriter; else { TransformerChain chain = transformerChainFactory.buildChain(); chain.tail().setResult(new SAXResult(saxWriter)); handler = chain.head(); handler.startDocument(); } handler.startElement(Constants.WFS_NAMESPACE_URI, propertyName, propertyQName, dummyAttributes); chunk.send(handler, true); handler.endElement(Constants.WFS_NAMESPACE_URI, propertyName, propertyQName); if (transformerChainFactory != null) handler.endDocument(); } } } } catch (CityGMLWriteException | CityGMLBuilderException | CityGMLReadException | SAXException | TransformerConfigurationException e) { eventDispatcher.triggerSyncEvent(new InterruptEvent("Failed to write additional objects.", LogLevel.ERROR, e, eventChannel, this)); } }
Example #12
Source File: JAXBSimpleReader.java From citygml4j with Apache License 2.0 | 4 votes |
public void close() throws CityGMLReadException { super.close(); elementInfo = null; }
Example #13
Source File: JAXBSimpleReader.java From citygml4j with Apache License 2.0 | 4 votes |
public JAXBSimpleReader(XMLStreamReader reader, InputStream in, JAXBInputFactory factory, URI baseURI) throws CityGMLReadException { super(reader, in, factory, baseURI); jaxbUnmarshaller.setParseSchema(parseSchema); }
Example #14
Source File: JAXBChunkReader.java From citygml4j with Apache License 2.0 | 4 votes |
public XMLChunk nextChunk() throws CityGMLReadException { if (iterator == null) { try { current = null; while (reader.hasNext()) { int event = reader.next(); // keep track of schema documents if (event == XMLStreamConstants.START_ELEMENT && parseSchema) { for (int i = 0; i < reader.getAttributeCount(); i++) { if (reader.getAttributeLocalName(i).equals("schemaLocation")) parseSchema(reader.getAttributeValue(i)); else if (reader.getAttributeLocalName(i).equals("noNamespaceSchemaLocation")) schemaHandler.parseSchema("", reader.getAttributeValue(i)); } } // move to the next CityGML feature in the document // and create a new chunk to initiate parsing if (!isInited) { if (event != XMLStreamConstants.START_ELEMENT) continue; else { elementInfo = elementChecker.getElementInfo(reader.getName()); if (elementInfo != null && elementInfo.isFeature()) { isInited = true; chunks.clear(); chunk = new XMLChunkImpl(this, null); chunk.setFirstElement(reader.getName()); if (isFilteredReader()) chunk.setIsFiltered(!filter.accept(reader.getName())); } else continue; } } // check whether start element is a feature if (event == XMLStreamConstants.START_ELEMENT) { ElementInfo lastElementInfo = elementInfos.push(elementInfo); elementInfo = elementChecker.getElementInfo(reader.getName(), lastElementInfo); if (elementInfo != null && elementInfo.isFeature()) { chunk.removeTrailingCharacters(); chunks.add(chunk); chunk = new XMLChunkImpl(this, chunks.peek()); chunk.setFirstElement(reader.getName()); if (isFilteredReader()) chunk.setIsFiltered(!filter.accept(reader.getName())); if (lastElementInfo != null) setXLink = lastElementInfo.hasXLink(); } } // pop last element info else if (event == XMLStreamConstants.END_ELEMENT) elementInfo = elementInfos.pop(); // add streaming event to the current chunk chunk.addEvent(reader); if (setXLink) setXLink(reader); // if the chunk is complete, return it if (chunk.isComplete()) { current = chunk; if (!chunks.isEmpty()) chunk = chunks.pop(); else { chunk = null; isInited = false; } if (!isFilteredReader() || !current.isFiltered()) break; else current = null; } } } catch (XMLStreamException | SAXException | MissingADESchemaException e) { throw new CityGMLReadException("Caused by: ", e); } if (current == null) throw new NoSuchElementException(); } else current = iterator; iterator = null; return current; }
Example #15
Source File: JAXBChunkReader.java From citygml4j with Apache License 2.0 | 4 votes |
public JAXBChunkReader(XMLStreamReader reader, InputStream in, JAXBInputFactory factory, URI baseURI) throws CityGMLReadException { super(reader, in, factory, baseURI); jaxbUnmarshaller.setParseSchema(false); chunks = new Stack<XMLChunkImpl>(); elementInfos = new Stack<ElementInfo>(); }
Example #16
Source File: CityGMLInputFactory.java From citygml4j with Apache License 2.0 | votes |
public CityGMLReader createCityGMLReader(String systemId, InputStream in, String encoding) throws CityGMLReadException;
Example #17
Source File: CityGMLInputFactory.java From citygml4j with Apache License 2.0 | votes |
public CityGMLReader createCityGMLReader(String systemId, InputStream in) throws CityGMLReadException;
Example #18
Source File: CityGMLInputFactory.java From citygml4j with Apache License 2.0 | votes |
public CityGMLReader createCityGMLReader(File file, String encoding) throws CityGMLReadException;
Example #19
Source File: CityGMLInputFactory.java From citygml4j with Apache License 2.0 | votes |
public CityGMLReader createCityGMLReader(File file) throws CityGMLReadException;