public static void parse(final XMLStreamReader reader, final XmlRpcListener listener) throws XMLStreamException, XmlRpcException { listener.startResponse(); boolean paramDetected = false; boolean faultDetected = false; int type = -1; do { type = reader.nextTag(); if (type == START_ELEMENT) { final String tag = reader.getName().getLocalPart(); if (XmlRpcConstants.FAULT.equals(tag)) { faultDetected = true; FaultHelper.parse(reader, listener); break; } else if (XmlRpcConstants.PARAMS.equals(tag)) { paramDetected = true; ParamHelper.parse(reader, listener); } } else if (type == XMLStreamReader.END_ELEMENT && XmlRpcConstants.RESPONSE.equals(reader.getName().getLocalPart())) { break; } } while (type != END_DOCUMENT); if (paramDetected && faultDetected) { throw new XmlRpcException("Cannot specify both fault and parameters in XML-RPC response."); } listener.endResponse(); }
private static void readModality(ModalityInfoData data, XMLStreamReader xmler) throws XMLStreamException { boolean state = true; while (xmler.hasNext() && state) { switch (xmler.next()) { case XMLStreamConstants.START_ELEMENT: if ("corner".equals(xmler.getName().getLocalPart()) && xmler.getAttributeCount() >= 1) { // $NON-NLS-1$ String name = xmler.getAttributeValue(null, "name"); // $NON-NLS-1$ CornerDisplay corner = getCornerDisplay(name); if (corner != null) { readCorner(data, corner, xmler); } } break; case XMLStreamConstants.END_ELEMENT: if ("modality".equals(xmler.getName().getLocalPart())) { // $NON-NLS-1$ state = false; } break; default: break; } } }
private static Map<String, String> parseAmortizeObject(final XMLStreamReader reader) { Map<String, String> elementMap = new HashMap<>(); /* still at start of amortize object. Need to know when end is reached */ QName parsingElement = reader.getName(); try { parse: while (reader.hasNext()) { int event = reader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: String element = reader.getLocalName(); elementMap.put(element, reader.getElementText()); break; case XMLStreamConstants.END_ELEMENT: if (reader.getName().equals(parsingElement)) { logger.finest("Found the end of the Amortize Object"); break parse; } break; default: break; } } } catch (XMLStreamException e) { logger.log(Level.SEVERE, e.toString(), e); } return elementMap; }
private static String[] parseAccountSecurities(final XMLStreamReader reader) { assert reader.getAttributeCount() == 2; ArrayList<String> securities = new ArrayList<>(); /* still at start of security array. Need to know when end is reached */ QName parsingElement = reader.getName(); try { parse: while (reader.hasNext()) { int event = reader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: securities.add(reader.getElementText()); break; case XMLStreamConstants.END_ELEMENT: if (reader.getName().equals(parsingElement)) { logger.finest("Found the end of the Account Securities"); break parse; } break; default: break; } } } catch (XMLStreamException e) { logger.log(Level.SEVERE, e.toString(), e); } return securities.toArray(new String[securities.size()]); }
private void compareStartElement(XMLStreamReader orig, XMLStreamReader actual) throws Exception { Assert.assertEquals("Start element is not matched", orig.getName(), actual.getName()); int origAttrCount = orig.getAttributeCount(); int actualAttrCount = actual.getAttributeCount(); for (int i = 0; i < origAttrCount; i++) { QName origAttrName = orig.getAttributeName(i); if ((origAttrName.getLocalPart().equals("location")) || (origAttrName.getLocalPart().equals("schemaLocation"))) { // skip this atribute origAttrCount--; } else { Assert.assertEquals( "Attribute " + origAttrName + " not found or value not matching", orig.getAttributeValue(origAttrName.getNamespaceURI(), origAttrName.getLocalPart()), actual.getAttributeValue(origAttrName.getNamespaceURI(), origAttrName.getLocalPart())); } } for (int i = 0; i < actualAttrCount; i++) { QName actualAttrName = actual.getAttributeName(i); if ((actualAttrName.getLocalPart().equals("location")) || (actualAttrName.getLocalPart().equals("schemaLocation"))) { // skip this atribute actualAttrCount--; } } Assert.assertEquals( "Attribute count is not matched for element " + orig.getName(), origAttrCount, actualAttrCount); }
private static void readCorner(ModalityInfoData data, CornerDisplay corner, XMLStreamReader xmler) throws XMLStreamException { TagView[] disElements = data.getCornerInfo(corner).getInfos(); boolean state = true; int index = -1; String format = null; while (xmler.hasNext() && state) { switch (xmler.next()) { case XMLStreamConstants.CHARACTERS: if (index > 0 && index <= 7) { disElements[index - 1] = getTag(xmler.getText(), format); index = -1; // Reset current index and format format = null; } break; case XMLStreamConstants.START_ELEMENT: if ("p".equals(xmler.getName().getLocalPart()) && xmler.getAttributeCount() >= 1) { // $NON-NLS-1$ index = TagUtil.getIntegerTagAttribute(xmler, "index", -1); // $NON-NLS-1$ format = xmler.getAttributeValue(null, "format"); // $NON-NLS-1$ } break; case XMLStreamConstants.END_ELEMENT: if ("corner".equals(xmler.getName().getLocalPart())) { // $NON-NLS-1$ state = false; } break; default: break; } } }
private static void parseExchangeRate(final XMLStreamReader reader) { Map<String, String> elementMap = new HashMap<>(); /* still at start of the exchange rate. Need to know when end is reached */ QName parsingElement = reader.getName(); try { while (reader.hasNext()) { int event = reader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: String element = reader.getLocalName(); elementMap.put(element.intern(), reader.getElementText()); break; case XMLStreamConstants.END_ELEMENT: if (reader.getName().equals(parsingElement)) { logger.finest("Found the end of the exchange rate"); try { String key = elementMap.get("key"); if (key != null && key.length() == 6) { Engine e = EngineFactory.getEngine(EngineFactory.DEFAULT); CurrencyNode cOne = e.getCurrency(key.substring(0, 3)); CurrencyNode cTwo = e.getCurrency(key.substring(3, 6)); // jGnash 1.x would hold onto old exchange rates for deleted commodities if (cOne != null && cTwo != null) { BigDecimal rate = new BigDecimal(elementMap.get("rate")); EngineFactory.getEngine(EngineFactory.DEFAULT) .setExchangeRate(cOne, cTwo, rate); logger.log( Level.FINE, "Set ExchangeRate {0}:{1}", new Object[] {key, rate.toString()}); } } } catch (Exception e) { logger.log(Level.SEVERE, e.toString(), e); } return; } break; default: break; } } } catch (XMLStreamException e) { logger.severe("Error importing exchange rate"); logger.log(Level.SEVERE, e.toString(), e); } }
/** * Forwards the given {@link XMLStreamReader} to the specified element or to the end of the * enclosing element/document if there is no such element. * * @param reader reader to forward, must not be <code>null</code> * @param elementName element to forward to, must not be <code>null</code> * @throws XMLStreamException */ public static boolean skipToElementOnSameLevel(XMLStreamReader reader, QName elementName) throws XMLStreamException { while (reader.isStartElement() && !elementName.equals(reader.getName())) { skipElement(reader); nextElement(reader); } return reader.isStartElement() && elementName.equals(reader.getName()); }
/** * static method to create the object Precondition: If this object is an element, the current or * next start element starts this object and any intervening reader events are ignorable If this * object is not an element, it is a complex type and the reader is at the event just after the * outer start element Postcondition: If this object is an element, the reader is positioned at * its end element If this object is a complex type, the reader is positioned at the end element * of its outer element */ public static ListMethods parse(javax.xml.stream.XMLStreamReader reader) throws java.lang.Exception { ListMethods object = new ListMethods(); int event; java.lang.String nillableValue = null; java.lang.String prefix = ""; java.lang.String namespaceuri = ""; try { while (!reader.isStartElement() && !reader.isEndElement()) reader.next(); nillableValue = reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance", "nil"); if ("true".equals(nillableValue) || "1".equals(nillableValue)) { // Skip the element and report the null value. It cannot have subelements. while (!reader.isEndElement()) reader.next(); return object; } // Note all attributes that were handled. Used to differ normal attributes // from anyAttributes. java.util.Vector handledAttributes = new java.util.Vector(); while (!reader.isEndElement()) { if (reader.isStartElement()) { if (reader.isStartElement()) { // use the QName from the parser as the name for the builder javax.xml.namespace.QName startQname1 = reader.getName(); // We need to wrap the reader so that it produces a fake START_DOCUMENT event // this is needed by the builder classes org.apache.axis2.databinding.utils.NamedStaxOMBuilder builder1 = new org.apache.axis2.databinding.utils.NamedStaxOMBuilder( new org.apache.axis2.util.StreamWrapper(reader), startQname1); object.setListMethods(builder1.getOMElement()); } // End of if for expected property start element else { // A start element we are not expecting indicates an invalid parameter was passed throw new org.apache.axis2.databinding.ADBException( "Unexpected subelement " + reader.getName()); } } else { reader.next(); } } // end of while loop } catch (javax.xml.stream.XMLStreamException e) { throw new java.lang.Exception(e); } return object; }
/** * Returns the text in the required element as a inz. If the name of the reader does not match the * given qName, an exception will be thrown. If the value is not a double, an exception will be * thrown. Post: reader will be unchanged or at {@link XMLStreamConstants #END_ELEMENT} of the * matching element or at {@link XMLStreamConstants #START_ELEMENT} of the next element if * requested. * * @param reader * @param elementName * @param nextElemOnSucces if true the reader will be move to the next element if the operation * was successful. * @return the double value of the required element. * @throws XMLStreamException */ public static int getRequiredElementTextAsInteger( XMLStreamReader reader, QName elementName, boolean nextElemOnSucces) throws XMLStreamException { if (!elementName.equals(reader.getName())) { throw new XMLParsingException( reader, "The current element: " + reader.getName() + " is not expected: " + elementName); } return getElementTextAsInteger(reader); }
private List<SecurityHistoryNode> parseHistoryNodes(final XMLStreamReader reader) { List<SecurityHistoryNode> list = new ArrayList<>(); assert reader.getAttributeCount() == 3; // number of history nodes to parse int count = Integer.parseInt(reader.getAttributeValue(2)); logger.log(Level.FINEST, "Parsing {0} SecurityHistoryNodes", count); Map<String, String> elementMap = new HashMap<>(); QName parsingElement = null; try { while (reader.hasNext() && list.size() < count) { int event = reader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: if (reader.getAttributeCount() > 0 && reader.getAttributeValue(0).equals("SecurityHistoryNode")) { // start of hNode parsingElement = reader.getName(); } else { String element = reader.getLocalName(); elementMap.put(element, reader.getElementText()); } break; case XMLStreamConstants.END_ELEMENT: if (reader.getName().equals(parsingElement)) { // build the security history node; SecurityHistoryNode hNode = new SecurityHistoryNode(); hNode.setDate(decodeDate(elementMap.get("date"))); hNode.setHigh(new BigDecimal(elementMap.get("high"))); hNode.setLow(new BigDecimal(elementMap.get("low"))); hNode.setPrice(new BigDecimal(elementMap.get("price"))); hNode.setVolume(Long.parseLong(elementMap.get("volume"))); elementMap.clear(); list.add(hNode); } break; default: break; } } } catch (XMLStreamException e) { logger.log(Level.SEVERE, e.toString(), e); } return list; }
/** * Reads PageRanges from the XMLStreamReader, reader must be at Start element of PageRangeElement * * @param xmlr the XMLStreamReader to read from * @return the PageRange from the stream. * @throws XMLStreamException if there is an error parsing the stream * @throws ParseException if there is an error in parsing a date * @throws URISyntaxException if the uri is invalid * @throws StorageException */ public static ArrayList<PageRange> readPageRanges(final XMLStreamReader xmlr) throws XMLStreamException, StorageException { int eventType = xmlr.getEventType(); final ArrayList<PageRange> retRanges = new ArrayList<PageRange>(); xmlr.require(XMLStreamConstants.START_ELEMENT, null, BlobConstants.PAGE_RANGE_ELEMENT); // check if there are more events in the input stream while (xmlr.hasNext() && BlobConstants.PAGE_RANGE_ELEMENT.equals(xmlr.getName().toString())) { long startOffset = -1; long endOffset = -1; // Read a Page Range while (xmlr.hasNext()) { eventType = xmlr.next(); final String name = xmlr.getName().toString(); if (eventType == XMLStreamConstants.START_ELEMENT) { if (name.equals(BlobConstants.START_ELEMENT)) { final String sizeString = Utility.readElementFromXMLReader(xmlr, BlobConstants.START_ELEMENT); startOffset = Long.parseLong(sizeString); } else if (name.equals(Constants.END_ELEMENT)) { final String sizeString = Utility.readElementFromXMLReader(xmlr, Constants.END_ELEMENT); endOffset = Long.parseLong(sizeString); } else { throw new StorageException( StorageErrorCodeStrings.INVALID_XML_DOCUMENT, "The response received is invalid or improperly formatted.", Constants.HeaderConstants.HTTP_UNUSED_306, null, null); } } else if (eventType == XMLStreamConstants.END_ELEMENT) { if (startOffset == -1 || endOffset == -1) { throw new StorageException( StorageErrorCodeStrings.INVALID_XML_DOCUMENT, "The response received is invalid or improperly formatted.", Constants.HeaderConstants.HTTP_UNUSED_306, null, null); } final PageRange pageRef = new PageRange(startOffset, endOffset); retRanges.add(pageRef); break; } } eventType = xmlr.next(); } return retRanges; }
private void parseTransaction(final XMLStreamReader reader) { assert reader.getAttributeCount() == 2; Map<String, String> elementMap = new HashMap<>(); /* still at start of the transaction. Need to know when end is reached */ QName parsingElement = reader.getName(); String transactionClass = reader.getAttributeValue(0); String transactionId = reader.getAttributeValue(1); elementMap.put(ID, transactionId); try { while (reader.hasNext()) { int event = reader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: String element = reader.getLocalName(); elementMap.put(element.intern(), reader.getElementText()); break; case XMLStreamConstants.END_ELEMENT: if (reader.getName().equals(parsingElement)) { logger.log(Level.FINEST, "Found the end of a Transaction: {0}", transactionId); try { Transaction transaction = generateTransaction(transactionClass, elementMap); if (transaction != null) { Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT); engine.addTransaction(transaction); logger.finest("Transaction add complete"); } } catch (Exception e) { logger.log(Level.SEVERE, "Error importing transaction id: {0}", transactionId); logger.log(Level.SEVERE, e.toString(), e); throw new RuntimeException(e); } return; } break; default: break; } } } catch (XMLStreamException e) { logger.log(Level.SEVERE, "Error importing transaction id: {0}", transactionId); logger.log(Level.SEVERE, e.toString(), e); } }
/** * Skips to the next element if the reader points the required element. Post: reader will be at * {@link XMLStreamConstants#START_ELEMENT} of the next element. * * @param reader * @param elementName * @throws XMLStreamException */ public static void skipRequiredElement(XMLStreamReader reader, QName elementName) throws XMLStreamException { if (reader.isStartElement() && reader.getName().equals(elementName)) { nextElement(reader); if (reader.isEndElement() && reader.getName().equals(elementName)) { nextElement(reader); } return; } throw new XMLParsingException( reader, "Required element " + elementName + " was not found at given stream position."); }
/** * static method to create the object Precondition: If this object is an element, the current or * next start element starts this object and any intervening reader events are ignorable If this * object is not an element, it is a complex type and the reader is at the event just after the * outer start element Postcondition: If this object is an element, the reader is positioned at * its end element If this object is a complex type, the reader is positioned at the end element * of its outer element */ public static hr.ponge.pfa.axis.core.operations.CreateDocumentReq parse( javax.xml.stream.XMLStreamReader reader) throws java.lang.Exception { hr.ponge.pfa.axis.core.operations.CreateDocumentReq object = new hr.ponge.pfa.axis.core.operations.CreateDocumentReq(); int event; java.lang.String nillableValue = null; java.lang.String prefix = ""; java.lang.String namespaceuri = ""; try { while ((!(reader.isStartElement())) && (!(reader.isEndElement()))) reader.next(); if ((reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance", "type")) != null) { java.lang.String fullTypeName = reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance", "type"); if (fullTypeName != null) { java.lang.String nsPrefix = null; if ((fullTypeName.indexOf(":")) > (-1)) { nsPrefix = fullTypeName.substring(0, fullTypeName.indexOf(":")); } nsPrefix = nsPrefix == null ? "" : nsPrefix; java.lang.String type = fullTypeName.substring(((fullTypeName.indexOf(":")) + 1)); if (!("CreateDocumentReq".equals(type))) { java.lang.String nsUri = reader.getNamespaceContext().getNamespaceURI(nsPrefix); return ((hr.ponge.pfa.axis.core.operations.CreateDocumentReq) (hr.ponge.pfa.axis.ExtensionMapper.getTypeObject(nsUri, type, reader))); } } } java.util.Vector handledAttributes = new java.util.Vector(); reader.next(); while ((!(reader.isStartElement())) && (!(reader.isEndElement()))) reader.next(); if ((reader.isStartElement()) && (new javax.xml.namespace.QName( "http://ponge.hr/pfa/axis/core/operations", "document") .equals(reader.getName()))) { object.setDocument(hr.ponge.pfa.axis.core.Document.Factory.parse(reader)); reader.next(); } else { throw new org.apache.axis2.databinding.ADBException( ("Unexpected subelement " + (reader.getName()))); } while ((!(reader.isStartElement())) && (!(reader.isEndElement()))) reader.next(); if (reader.isStartElement()) throw new org.apache.axis2.databinding.ADBException( ("Unexpected subelement " + (reader.getName()))); } catch (javax.xml.stream.XMLStreamException e) { throw new java.lang.Exception(e); } return object; }
/** * Returns the text in the required element as a double. If the name of the reader does not match * the given qName, an exception will be thrown. If the value is not a double, an exception will * be thrown. Post: reader will be unchanged or at {@link XMLStreamConstants #END_ELEMENT} of the * matching element or at {@link XMLStreamConstants #START_ELEMENT} of the next element if * requested. * * @param reader * @param elementName * @param nextElemOnSucces if true the reader will be move to the next element if the operation * was successful. * @return the double value of the required element. * @throws XMLStreamException */ public static double getRequiredElementTextAsDouble( XMLStreamReader reader, QName elementName, boolean nextElemOnSucces) throws XMLStreamException { if (!elementName.equals(reader.getName())) { throw new XMLParsingException( reader, "The current element: " + reader.getName() + " is not expected: " + elementName); } double result = getElementTextAsDouble(reader, elementName, Double.NaN, nextElemOnSucces); if (Double.isNaN(result)) { throw new XMLParsingException( reader, "The element " + elementName + " does not specify a double value."); } return result; }
public static GetStatus parse(final XMLStreamReader reader) throws Exception { final GetStatus object = new GetStatus(); try { while (!reader.isStartElement() && !reader.isEndElement()) { reader.next(); } while (!reader.isEndElement()) { if (reader.isStartElement()) { if (reader.isStartElement() && new QName("http://remotelabs.eng.uts.edu.au/rigclient/protocol", "getStatus") .equals(reader.getName())) { object.setGetStatus(NullType.Factory.parse(reader)); } else { throw new ADBException("Unexpected subelement " + reader.getLocalName()); } } else { reader.next(); } } } catch (final XMLStreamException e) { throw new Exception(e); } return object; }
private void handleEndElement() throws XMLStreamException { QName qName = staxStreamReader.getName(); try { String pfix = qName.getPrefix(); String rawname = (pfix == null || pfix.length() == 0) ? qName.getLocalPart() : pfix + ':' + qName.getLocalPart(); // fire endElement saxHandler.endElement(qName.getNamespaceURI(), qName.getLocalPart(), rawname); // end namespace bindings int nsCount = staxStreamReader.getNamespaceCount(); for (int i = nsCount - 1; i >= 0; i--) { String prefix = staxStreamReader.getNamespacePrefix(i); if (prefix == null) { // true for default namespace prefix = ""; } saxHandler.endPrefixMapping(prefix); } } catch (SAXException e) { throw new XMLStreamException2(e); } }
public static VDBMetaData unmarshell(InputStream content) throws XMLStreamException { XMLInputFactory inputFactory = XMLType.getXmlInputFactory(); XMLStreamReader reader = inputFactory.createXMLStreamReader(content); try { // elements while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) { Element element = Element.forName(reader.getLocalName()); switch (element) { case VDB: VDBMetaData vdb = new VDBMetaData(); Properties props = getAttributes(reader); vdb.setName(props.getProperty(Element.NAME.getLocalName())); vdb.setVersion(Integer.parseInt(props.getProperty(Element.VERSION.getLocalName()))); parseVDB(reader, vdb); return vdb; default: throw new XMLStreamException( AdminPlugin.Util.gs( "unexpected_element1", reader.getName(), Element.VDB.getLocalName()), reader.getLocation()); } } } finally { try { content.close(); } catch (IOException e) { Logger.getLogger(VDBMetadataParser.class.getName()) .log(Level.FINE, "Exception closing vdb stream", e); } } return null; }
public boolean isCorrect(String word, String... uris) { try { RequestParameters params = new RequestParameters(); params.add("service", "is-correct"); params.add("word", word); params.add("uris", uris); XMLStreamReaderHandle readHandle = new XMLStreamReaderHandle(); // call the service getServices().get(params, readHandle); QName correctName = new QName(XMLConstants.DEFAULT_NS_PREFIX, "correct"); XMLStreamReader streamReader = readHandle.get(); while (streamReader.hasNext()) { int current = streamReader.next(); if (current == XMLStreamReader.START_ELEMENT) { if (correctName.equals(streamReader.getName())) { return "true".equals(streamReader.getElementText()); } } } return false; } catch (XMLStreamException ex) { throw new RuntimeException(ex); } }
/** * Post: reader will be unchanged or on success at {@link XMLStreamConstants #END_ELEMENT} of the * matching element or at {@link XMLStreamConstants #START_ELEMENT} of the next element if * requested. * * @param reader pointing to the current element. * @param elementName of the current element. * @param defaultValue to return if the current name was not the one given or the value could not * be parsed as a integer. * @param nextElemOnSucces if true the reader will be moved to the next tag if the retrieval was * successful. * @return the text of the current element (which should have element name) parsed as a integer. * @throws XMLStreamException from {@link XMLStreamReader#getElementText()}. */ public static int getElementTextAsInteger( XMLStreamReader reader, QName elementName, int defaultValue, boolean nextElemOnSucces) throws XMLStreamException { int value = defaultValue; if (elementName.equals(reader.getName()) && reader.isStartElement()) { String s = reader.getElementText(); if (s != null) { try { value = Integer.parseInt(s); if (nextElemOnSucces) { nextElement(reader); } } catch (NumberFormatException nfe) { LOG.debug( reader.getLocation() + ") Value " + s + " in element: " + elementName + " was not a parsable integer, returning integer value: " + defaultValue); } } } return value; }
private void parseArtifactVersions( final XMLStreamReader reader, final FeaturePackDescription result) throws XMLStreamException { final Set<Artifact> artifactVersions = result.getArtifactVersions(); while (reader.hasNext()) { switch (reader.nextTag()) { case XMLStreamConstants.END_ELEMENT: { return; } case XMLStreamConstants.START_ELEMENT: { final Element element = Element.of(reader.getName()); switch (element) { case ARTIFACT: artifactVersions.add(parseArtifact(reader)); break; default: throw ParsingUtils.unexpectedContent(reader); } break; } default: { throw ParsingUtils.unexpectedContent(reader); } } } throw ParsingUtils.endOfDocument(reader.getLocation()); }
public static PerformPrimitiveControl parse(final XMLStreamReader reader) throws Exception { final PerformPrimitiveControl object = new PerformPrimitiveControl(); try { while (!reader.isStartElement() && !reader.isEndElement()) { reader.next(); } while (!reader.isEndElement()) { if (reader.isStartElement()) { if (reader.isStartElement() && new QName( "http://remotelabs.eng.uts.edu.au/rigclient/protocol", "performPrimitiveControl") .equals(reader.getName())) { object.setPerformPrimitiveControl(PrimitiveControlRequestType.Factory.parse(reader)); } else { throw new ADBException("Unexpected subelement " + reader.getLocalName()); } } else { reader.next(); } } } catch (final XMLStreamException e) { throw new Exception(e); } return object; }
public QName getName() { if (state == STATE_START_DOCUMENT || state == STATE_END_DOCUMENT) { throw new IllegalStateException(); } else { return parent.getName(); } }
/** * Populates the object from the XMLStreamReader * * @param xmlr the XMLStreamReader to read from * @throws XMLStreamException if there is an error parsing the stream * @throws ParseException if there is an error in parsing a date * @throws URISyntaxException if the uri is invalid */ protected static BlobContainerAttributes readBlobContainerAttributes(final XMLStreamReader xmlr) throws XMLStreamException, ParseException, URISyntaxException { int eventType = xmlr.getEventType(); final BlobContainerAttributes attributes = new BlobContainerAttributes(); while (xmlr.hasNext()) { eventType = xmlr.next(); final String name = xmlr.getName().toString(); if (eventType == XMLStreamConstants.START_ELEMENT) { if (name.equals(BlobConstants.PROPERTIES)) { attributes.setProperties(BlobDeserializationHelper.readBlobContainerProperties(xmlr)); xmlr.require(XMLStreamConstants.END_ELEMENT, null, BlobConstants.PROPERTIES); } else if (name.equals(Constants.URL_ELEMENT)) { attributes.setUri(new URI(Utility.readElementFromXMLReader(xmlr, Constants.URL_ELEMENT))); } else if (name.equals(Constants.NAME_ELEMENT)) { attributes.setName(Utility.readElementFromXMLReader(xmlr, Constants.NAME_ELEMENT)); } else if (name.equals(Constants.METADATA_ELEMENT)) { // parse metadata attributes.setMetadata(DeserializationHelper.parseMetadateFromXML(xmlr)); xmlr.require(XMLStreamConstants.END_ELEMENT, null, Constants.METADATA_ELEMENT); } } else if (eventType == XMLStreamConstants.END_ELEMENT && name.equals(BlobConstants.CONTAINER_ELEMENT)) { break; } } return attributes; }
private static void parseFilterList( final XMLStreamReader reader, final MultiplePathFilterBuilder builder) throws XMLStreamException { // xsd:choice while (reader.hasNext()) { switch (reader.nextTag()) { case XMLStreamConstants.END_ELEMENT: { return; } case XMLStreamConstants.START_ELEMENT: { switch (Element.of(reader.getName())) { case INCLUDE: parsePath(reader, true, builder); break; case EXCLUDE: parsePath(reader, false, builder); break; default: throw unexpectedContent(reader); } break; } default: { throw unexpectedContent(reader); } } } throw endOfDocument(reader.getLocation()); }
public static void parseCorrelations( XMLStreamReader input, Contextual<?> ctx, ExecCompilerContext context) throws XMLStreamException, ParserException { while (input.hasNext()) { int type = input.getEventType(); switch (type) { case XMLStreamConstants.START_ELEMENT: ParserUtils.assertStart(input, CORRELATIONS); Contextual<Correlations> corrs = new Contextual<Correlations>(CORRELATIONS, Correlations.class, ctx); ParserUtils.setLocation(input, context.source().srcRef(), corrs); ctx.children().add(corrs); while (input.nextTag() == XMLStreamConstants.START_ELEMENT) { if (CORRELATION.equals(input.getName())) { Instructional<Correlation> corr = new Instructional<Correlation>(CORRELATION, Correlation.class, corrs); ParserUtils.setLocation(input, context.source().srcRef(), corr); corrs.children().add(corr); while (input.nextTag() == XMLStreamConstants.START_ELEMENT) { context.parseContent(input, corr); } } else { context.parseContent(input, corrs); } } break; case XMLStreamConstants.END_ELEMENT: ParserUtils.assertEnd(input, CORRELATIONS); return; } } }
private static ModuleSpec parseDocument( final File root, XMLStreamReader reader, ModuleSpec.Builder specBuilder) throws XMLStreamException { while (reader.hasNext()) { switch (reader.nextTag()) { case XMLStreamConstants.START_DOCUMENT: { parseRootElement(root, reader, specBuilder); return specBuilder.create(); } case XMLStreamConstants.START_ELEMENT: { if (Element.of(reader.getName()) != Element.MODULE) { throw unexpectedContent(reader); } parseModuleContents(root, reader, specBuilder); parseEndDocument(reader); return specBuilder.create(); } default: { throw unexpectedContent(reader); } } } throw endOfDocument(reader.getLocation()); }
private static void parseDependencies( final XMLStreamReader reader, final ModuleSpec.Builder specBuilder) throws XMLStreamException { // xsd:choice while (reader.hasNext()) { switch (reader.nextTag()) { case XMLStreamConstants.END_ELEMENT: { return; } case XMLStreamConstants.START_ELEMENT: { switch (Element.of(reader.getName())) { case MODULE: parseModuleDependency(reader, specBuilder); break; default: throw unexpectedContent(reader); } break; } default: { throw unexpectedContent(reader); } } } throw endOfDocument(reader.getLocation()); }
private static void parseResources( final File root, final XMLStreamReader reader, final ModuleSpec.Builder specBuilder) throws XMLStreamException { // xsd:choice while (reader.hasNext()) { switch (reader.nextTag()) { case XMLStreamConstants.END_ELEMENT: { return; } case XMLStreamConstants.START_ELEMENT: { switch (Element.of(reader.getName())) { case RESOURCE_ROOT: { parseResourceRoot(root, reader, specBuilder); break; } default: throw unexpectedContent(reader); } break; } default: { throw unexpectedContent(reader); } } } throw endOfDocument(reader.getLocation()); }