List of usage examples for javax.xml.stream XMLStreamReader next
public int next() throws XMLStreamException;
From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java
protected static final TaggedValue readTaggedValue(final XMLStreamReader reader) throws XMLStreamException { assertName(XmiElementName.TAGGED_VALUE, reader); final Identifier id = getId(reader); String dataValue = ""; Identifier tagDefinition = null;/*from w ww . j a v a 2s . c om*/ while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { if (match(XmiElementName.TAGGED_VALUE_DOT_DATA_VALUE, reader)) { dataValue = assertNotNull(readTaggedValueData(reader)); } else if (match(XmiElementName.TAGGED_VALUE_DOT_TYPE, reader)) { tagDefinition = assertNotNull(readTaggedValueType(reader)); } else { throw new AssertionError(reader.getLocalName()); } break; } case XMLStreamConstants.END_ELEMENT: { assertName(XmiElementName.TAGGED_VALUE, reader); return new TaggedValue(id, EMPTY_TAGGED_VALUE_LIST, dataValue, tagDefinition); } case XMLStreamConstants.CHARACTERS: { // Ignore. break; } default: { throw new AssertionError(reader.getEventType()); } } } throw new AssertionError(); }
From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java
protected static final String readTaggedValueData(final XMLStreamReader reader) throws XMLStreamException { assertName(XmiElementName.TAGGED_VALUE_DOT_DATA_VALUE, reader); final StringBuilder sb = new StringBuilder(); while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { throw new AssertionError(reader.getLocalName()); }/*from w w w .j av a 2 s . c o m*/ case XMLStreamConstants.END_ELEMENT: { assertName(XmiElementName.TAGGED_VALUE_DOT_DATA_VALUE, reader); return collapseWhitespace(sb.toString()); } case XMLStreamConstants.CHARACTERS: { sb.append(reader.getText()); break; } default: { throw new AssertionError(reader.getEventType()); } } } throw new AssertionError(); }
From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java
protected static final List<TaggedValue> readTaggedValueGroup(final XMLStreamReader reader) { final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>(); try {// w ww .j av a2 s . c om if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) { while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { if ("TaggedValue".equals(reader.getLocalName())) { taggedValues.add(assertNotNull(readTaggedValue(reader))); break; } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.END_ELEMENT: { if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) { return taggedValues; } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.CHARACTERS: { // Ignore. break; } default: { throw new AssertionError(reader.getEventType()); } } } } else { throw new AssertionError(reader.getLocalName()); } } catch (final XMLStreamException e) { LOG.warn(e.getMessage()); } throw new AssertionError(); }
From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java
protected static final Identifier readTaggedValueType(final XMLStreamReader reader) throws XMLStreamException { assertName(XmiElementName.TAGGED_VALUE_DOT_TYPE, reader); Identifier reference = null;/*from www. j a v a2s .co m*/ while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { if (match(XmiElementName.TAG_DEFINITION, reader)) { reference = assertNotNull(readIdentifier(reader)); } else { throw new AssertionError(reader.getLocalName()); } break; } case XMLStreamConstants.END_ELEMENT: { assertName(XmiElementName.TAGGED_VALUE_DOT_TYPE, reader); return assertNotNull(reference); } case XMLStreamConstants.CHARACTERS: { // Ignore. break; } default: { throw new AssertionError(reader.getEventType()); } } } throw new AssertionError(); }
From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java
protected static final Model readXMI(final XMLStreamReader reader) { try {//from ww w .j a v a2s . c o m if ("XMI".equals(reader.getLocalName())) { Model model = null; while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { if ("XMI.header".equals(reader.getLocalName())) { skipElement(reader, false); break; } else if ("XMI.content".equals(reader.getLocalName())) { model = readContent(reader); if (model == null) { throw new IllegalStateException(); } break; } else { throw new XmiRuntimeException("Expecting Foo element, got: " + reader.getLocalName()); } } case XMLStreamConstants.END_ELEMENT: { if ("XMI".equals(reader.getLocalName())) { if (model == null) { throw new IllegalStateException(); } return model; } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.CHARACTERS: { // Ignore. break; } default: { throw new AssertionError(reader.getEventType()); } } } } else { throw new AssertionError(reader.getLocalName()); } } catch (final XMLStreamException e) { LOG.warn(e.getMessage()); } return null; }
From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java
/** * Skips (recursively) over the element in question. Also useful during development. * * @param reader/*from ww w . j a va 2 s . c o m*/ * The StAX {@link XMLStreamReader}. */ protected static final void skipElement(final XMLStreamReader reader, final boolean check) throws XMLStreamException { if (check) { throw new AssertionError(reader.getName()); } final String localName = reader.getLocalName(); while (reader.hasNext()) { reader.next(); switch (reader.getEventType()) { case XMLStreamConstants.START_ELEMENT: { skipElement(reader, check); break; } case XMLStreamConstants.END_ELEMENT: { if (localName.equals(reader.getLocalName())) { return; } else { throw new AssertionError(reader.getLocalName()); } } case XMLStreamConstants.CHARACTERS: { // Ignore. break; } default: { throw new AssertionError(reader.getEventType()); } } } throw new AssertionError(); }
From source file:org.socraticgrid.workbench.ontomodel.service.SyntacticalOntoModelServiceImpl.java
/** * Extracts all the Fact Types used in a process definition. * Each Fact Type is declared as:// w w w . ja v a 2 s . com * * <bpmn2:textAnnotation id="_92807518-95EC-447B-A292-D46C9D5958E9"> * <bpmn2:text>KMRCustom--Diagnosis--code--49320</bpmn2:text> * </bpmn2:textAnnotation> * * In the previous example, Diagnosis is the Fact Type * * @param processXml * @return * @throws XMLStreamException */ private Set<String> getProcessFactTypesFromXml(String processXml) throws XMLStreamException { Set<String> facts = new HashSet<String>(); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = factory.createXMLStreamReader(new ByteArrayInputStream(processXml.getBytes())); boolean parsingTextAnnotation = false; //<bpmn2:text>KMRCustom--Diagnosis--code--49320</bpmn2:text> while (reader.hasNext()) { switch (reader.next()) { case XMLStreamReader.START_ELEMENT: if ("bpmn2".equals(reader.getName().getPrefix()) && "textAnnotation".equals(reader.getName().getLocalPart())) { parsingTextAnnotation = true; } if (parsingTextAnnotation && "bpmn2".equals(reader.getName().getPrefix()) && "text".equals(reader.getName().getLocalPart())) { String text = reader.getElementText(); if (text.startsWith("KMRCustom--")) { String[] parts = text.split("--"); facts.add(parts[1]); } } break; case XMLStreamReader.END_ELEMENT: if ("bpmn2".equals(reader.getName().getPrefix()) && "textAnnotation".equals(reader.getName().getLocalPart())) { parsingTextAnnotation = false; } } } return facts; }
From source file:org.springmodules.remoting.xmlrpc.stax.AbstractStaxXmlRpcParser.java
/** * Creates a new <code>java.util.List</code> from the current element being * read in the specified <code>StreamReader</code>. * //from w w w . j av a 2 s.c o m * @param reader * the <code>StreamReader</code>. * @return the new array of <code>java.util.List</code>s. * @throws XmlRpcInvalidPayloadException * if the element contains an unknown child. Only one "data" element * is allowed inside an "array" element. * @see #parseDataElement(XMLStreamReader) */ protected final XmlRpcArray parseArrayElement(XMLStreamReader reader) throws XMLStreamException { while (reader.hasNext()) { int event = reader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: String localName = reader.getLocalName(); if (XmlRpcElementNames.DATA.equals(localName)) { return parseDataElement(reader); } XmlRpcParsingUtils.handleUnexpectedElementFound(localName); } } // we should not reach this point. return null; }
From source file:org.springmodules.remoting.xmlrpc.stax.AbstractStaxXmlRpcParser.java
/** * Creates a new <code>java.util.List</code> from the current element being * read in the specified <code>StreamReader</code>. * /* w w w . ja v a 2s. c om*/ * @param reader * the <code>StreamReader</code>. * @return the new array of <code>java.util.List</code>s. * @see #parseValueElement(XMLStreamReader) */ protected final XmlRpcArray parseDataElement(XMLStreamReader reader) throws XMLStreamException { XmlRpcArray array = new XmlRpcArray(); while (reader.hasNext()) { int event = reader.next(); String localName = null; switch (event) { case XMLStreamConstants.START_ELEMENT: localName = reader.getLocalName(); if (XmlRpcElementNames.VALUE.equals(localName)) { XmlRpcElement element = parseValueElement(reader); array.add(element); } break; case XMLStreamConstants.END_ELEMENT: localName = reader.getLocalName(); if (XmlRpcElementNames.DATA.equals(localName) || XmlRpcElementNames.ARRAY.equals(localName)) { return array; } } } // we should not reach this point. return null; }
From source file:org.springmodules.remoting.xmlrpc.stax.AbstractStaxXmlRpcParser.java
/** * Creates a new Object from the current element being read in the specified * <code>StreamReader</code>. * /* w w w. j ava 2s . com*/ * @param reader * the <code>StreamReader</code>. * @return the created Object. * @throws XmlRpcInvalidPayloadException * if the element contains an unknown child. * @see #parseValueElement(XMLStreamReader) */ protected final XmlRpcElement parseParameterElement(XMLStreamReader reader) throws XMLStreamException { while (reader.hasNext()) { int event = reader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: String localName = reader.getLocalName(); if (XmlRpcElementNames.VALUE.equals(localName)) { return parseValueElement(reader); } XmlRpcParsingUtils.handleUnexpectedElementFound(localName); } } // we should not reach this point. return null; }