Java Code Examples for javax.xml.stream.XMLStreamReader#getLocalName()

The following examples show how to use javax.xml.stream.XMLStreamReader#getLocalName() . 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: XMLStreamReaderTest.java    From FHIR with Apache License 2.0 6 votes vote down vote up
private static void parseMeta(java.lang.String elementName, XMLStreamReader reader) throws XMLStreamException {
    while (reader.hasNext()) {
        int eventType = reader.next();
        debug(reader);

        switch (eventType) {
        case XMLStreamReader.START_ELEMENT:
            java.lang.String localName = reader.getLocalName();
            System.out.println("localName: " + localName);
            switch (localName) {
            case "versionId":
                parseString("versionId", reader);
                break;
            case "lastUpdated":
                parseInstant("lastUpdated", reader);
                break;
            }
            break;
        case XMLStreamReader.END_ELEMENT:
            if (reader.getLocalName().equals(elementName)) {
                return;
            }
            break;
        }
    }
}
 
Example 2
Source File: TestXmlOutputParser.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an exception suitable to be thrown when and a bad end tag appears. The exception could
 * also be thrown from here but that would result in an extra stack frame, whereas this way, the
 * topmost frame shows the location where the error occurred.
 */
private TestXmlOutputParserException createBadElementException(
    String expected, XMLStreamReader parser) {
  return new TestXmlOutputParserException(
      "Expected end of XML element '"
          + expected
          + "' , but got '"
          + parser.getLocalName()
          + "' at "
          + parser.getLocation().getLineNumber()
          + ":"
          + parser.getLocation().getColumnNumber());
}
 
Example 3
Source File: ExpandDLMethod.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
protected void handlePhoneNumbers(XMLStreamReader reader, EWSMethod.Item responseItem) throws XMLStreamException {
    while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "PhoneNumbers")) {
        reader.next();
        if (XMLStreamUtil.isStartTag(reader)) {
            String tagLocalName = reader.getLocalName();
            if ("Entry".equals(tagLocalName)) {
                String key = getAttributeValue(reader, "Key");
                String value = XMLStreamUtil.getElementText(reader);
                responseItem.put(key, value);
            }
        }
    }
}
 
Example 4
Source File: XmiReader.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
protected static final Range readMultiplicityDotRange(final XMLStreamReader reader) throws XMLStreamException {
    assertName(XmiElementName.MULTIPLICITY_DOT_RANGE, reader);
    Range range = null;
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
            case XMLStreamConstants.START_ELEMENT: {
                if (match(XmiElementName.MULTIPLICITY_RANGE, reader)) {
                    range = assertNotNull(readMultiplicityRange(reader));
                } else {
                    throw new AssertionError(reader.getLocalName());
                    // skipElement(reader);
                }
                break;
            }
            case XMLStreamConstants.END_ELEMENT: {
                assertName(XmiElementName.MULTIPLICITY_DOT_RANGE, reader);
                return assertNotNull(range);
            }
            case XMLStreamConstants.CHARACTERS: {
                // Ignore.
                break;
            }
            default: {
                throw new AssertionError(reader.getEventType());
            }
        }
    }
    throw new AssertionError();
}
 
Example 5
Source File: XMLStreamReaderUtil.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void verifyTag(XMLStreamReader reader, String namespaceURI, String localName) {
    if (!localName.equals(reader.getLocalName()) || !namespaceURI.equals(reader.getNamespaceURI())) {
        throw new XMLStreamReaderException(
            "xmlreader.unexpectedState.tag",
                "{" + namespaceURI + "}" + localName,
                "{" + reader.getNamespaceURI() + "}" + reader.getLocalName());
    }
}
 
Example 6
Source File: AtomServiceDocumentConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public ServiceDocumentImpl readServiceDokument(final XMLStreamReader reader) throws EntityProviderException {
  AtomInfoImpl atomInfo = new AtomInfoImpl();
  ServiceDocumentImpl serviceDocument = new ServiceDocumentImpl();
  List<Workspace> workspaces = new ArrayList<Workspace>();
  List<ExtensionElement> extElements = new ArrayList<ExtensionElement>();
  CommonAttributesImpl attributes = new CommonAttributesImpl();
  try {
    while (reader.hasNext()
        && !(reader.isEndElement() && Edm.NAMESPACE_APP_2007.equals(reader.getNamespaceURI()) && FormatXml.APP_SERVICE
            .equals(reader.getLocalName()))) {
      reader.next();
      if (reader.isStartElement()) {
        currentHandledStartTagName = reader.getLocalName();
        if (FormatXml.APP_SERVICE.equals(currentHandledStartTagName)) {
          attributes = parseCommonAttribute(reader);
        } else if (FormatXml.APP_WORKSPACE.equals(currentHandledStartTagName)) {
          workspaces.add(parseWorkspace(reader));
        } else {
          ExtensionElementImpl extElement = parseExtensionElement(reader);
          if (extElement != null) {
            extElements.add(extElement);
          }
        }
      }
    }
    if (workspaces.isEmpty()) {
      throw new EntityProviderException(EntityProviderException.INVALID_STATE
          .addContent("Service element must contain at least one workspace element"));
    }
    reader.close();
    atomInfo.setWorkspaces(workspaces).setCommonAttributes(attributes).setExtesionElements(extElements);

    serviceDocument.setAtomInfo(atomInfo);
    serviceDocument.setEntitySetsInfo(atomInfo.getEntitySetsInfo());
    return serviceDocument;
  } catch (XMLStreamException e) {
    throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
        .getSimpleName()), e);
  }
}
 
Example 7
Source File: XMLFormatter.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public StartElementBuffer( XMLStreamReader rd ) {
  prefix = rd.getPrefix();
  namespace = rd.getNamespaceURI();
  localName = rd.getLocalName();
  for ( int i = 0; i < rd.getAttributeCount(); i++ ) {
    attrBuffer.add( new AttrBuffer( rd, i ) );
  }
}
 
Example 8
Source File: XmiReader.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
protected static final Model readModel(final XMLStreamReader reader) throws XMLStreamException {
    assertName(XmiElementName.MODEL, reader);
    final Identifier id = getId(reader);
    final String name = getName(reader, null, XmiAttributeName.NAME);
    List<TaggedValue> taggedValues = EMPTY_TAGGED_VALUE_LIST;
    List<NamespaceOwnedElement> ownedElements = EMPTY_NAMESPACE_OWNED_ELEMENTS;
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
            case XMLStreamConstants.START_ELEMENT: {
                if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) {
                    taggedValues = readTaggedValueGroup(reader);
                } else if (match(XmiElementName.NAMESPACE_DOT_OWNED_ELEMENT, reader)) {
                    ownedElements = readNamespaceOwnedElement(reader);
                } else {
                    throw new AssertionError(reader.getLocalName());
                }
                break;
            }
            case XMLStreamConstants.END_ELEMENT: {
                assertName(XmiElementName.MODEL, reader);
                return new Model(id, name, taggedValues, ownedElements);
            }
            case XMLStreamConstants.CHARACTERS: {
                // Ignore.
                break;
            }
            default: {
                throw new AssertionError(reader.getEventType());
            }
        }
    }
    throw new AssertionError();
}
 
Example 9
Source File: XmiReader.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
protected static final void assertName(final QName name, final XMLStreamReader reader) {
    if (!match(name, reader)) {
        throw new AssertionError(reader.getLocalName());
    }
}
 
Example 10
Source File: XsdComplexType.java    From gs-xsd2bean with Apache License 2.0 4 votes vote down vote up
private void parseSubElements(XMLStreamReader xmlStreamReader, String diagnosticMessage) throws XMLStreamException
{
    XsdSchemaUnmarshaller.getNextByType(xmlStreamReader, XMLStreamConstants.START_ELEMENT, diagnosticMessage);
    int eventType = XMLStreamConstants.START_ELEMENT;
    while(eventType == XMLStreamConstants.START_ELEMENT)
    {
        String elementName = xmlStreamReader.getLocalName();
        if (elementName.equals("sequence"))
        {
            parseSequence(xmlStreamReader, diagnosticMessage);
        }
        else if (elementName.equals("choice"))
        {
            parseChoice(xmlStreamReader, diagnosticMessage);
        }
        else if (elementName.equals("all"))
        {
            parseAll(xmlStreamReader, diagnosticMessage);
        }
        else if (elementName.equals("complexContent"))
        {
            parseComplexContent(xmlStreamReader, diagnosticMessage);
        }
        else if (elementName.equals("simpleContent"))
        {
            parseSimpleContent(xmlStreamReader, diagnosticMessage);
        }
        else if (elementName.equals("attribute"))
        {
            parseAttribute(xmlStreamReader, diagnosticMessage);
        }
        else if (elementName.equals("attributeGroup"))
        {
            parseAttributeGroup(xmlStreamReader, diagnosticMessage);
        }
        else if (elementName.equals("annotation"))
        {
            XsdAnnotation annotation = new XsdAnnotation();
            annotation.parse(xmlStreamReader, diagnosticMessage);
        }
        else
        {
            XsdSchemaUnmarshaller.throwException("unexpected element in complex content: "+elementName, xmlStreamReader, diagnosticMessage);
        }
        eventType = XsdSchemaUnmarshaller.getNextStartOrEnd(xmlStreamReader, diagnosticMessage);
    }
    XsdSchemaUnmarshaller.expectEnd(xmlStreamReader, diagnosticMessage, eventType, "complexType");
}
 
Example 11
Source File: NodeParser.java    From galleon with Apache License 2.0 4 votes vote down vote up
public ElementNode parseNode(XMLStreamReader reader, String nodeName) throws XMLStreamException {
    if (reader.getEventType() != START_ELEMENT) {
        throw new XMLStreamException("Expected START_ELEMENT", reader.getLocation());
    }
    if (!reader.getLocalName().equals(nodeName)) {
        throw new XMLStreamException("Expected <" + nodeName + ">", reader.getLocation());
    }

    ElementNode rootNode = createNodeWithAttributesAndNs(reader, null);
    ElementNode currentNode = rootNode;
    while (reader.hasNext()) {
        int type = reader.next();
        switch (type) {
        case END_ELEMENT:
            currentNode = currentNode.getParent();
            String name = reader.getLocalName();
            //TODO this looks wrong
            if (name.equals(nodeName)) {
                return rootNode;
            }
            break;
        case START_ELEMENT:
            ElementNode childNode = createNodeWithAttributesAndNs(reader, currentNode);
            currentNode.addChild(childNode);
            currentNode = childNode;
            break;
        case COMMENT:
            String comment = reader.getText();
            currentNode.addChild(new CommentNode(comment));
            break;
        case CDATA:
            currentNode.addChild(new CDataNode(reader.getText()));
            break;
        case CHARACTERS:
            if (!reader.isWhiteSpace()) {
                currentNode.addChild(new TextNode(reader.getText()));
            }
            break;
        case PROCESSING_INSTRUCTION:
            ProcessingInstructionNode node = parseProcessingInstruction(reader, currentNode);
            if (node != null) {
                currentNode.addChild(node);
            }

            break;
        default:
            break;
        }
    }

    throw new XMLStreamException("Element was not terminated", reader.getLocation());
}
 
Example 12
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private AssociationSet readAssociationSet(final XMLStreamReader reader)
    throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ASSOCIATION_SET);
  AssociationSet associationSet = new AssociationSet();
  List<AssociationSetEnd> ends = new ArrayList<AssociationSetEnd>();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();

  associationSet.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  String association = reader.getAttributeValue(null, XmlMetadataConstants.EDM_ASSOCIATION);
  if (association != null) {
    associationSet.setAssociation(extractFQName(association));
  } else {
    throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE
        .addContent(XmlMetadataConstants.EDM_ASSOCIATION).addContent(XmlMetadataConstants.EDM_ASSOCIATION_SET));
  }
  associationSet.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext()
      && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_ASSOCIATION_SET.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      currentHandledStartTagName = reader.getLocalName();
      if (XmlMetadataConstants.EDM_ASSOCIATION_END.equals(currentHandledStartTagName)) {
        AssociationSetEnd associationSetEnd = new AssociationSetEnd();
        associationSetEnd.setEntitySet(reader.getAttributeValue(null, XmlMetadataConstants.EDM_ENTITY_SET));
        associationSetEnd.setRole(reader.getAttributeValue(null, XmlMetadataConstants.EDM_ROLE));
        ends.add(associationSetEnd);
      } else {
        annotationElements.add(readAnnotationElement(reader));
      }
    }
  }
  if (ends.size() != 2) {
    throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT
        .addContent("Count of AssociationSet ends should be 2"));
  } else {
    associationSet.setEnd1(ends.get(0)).setEnd2(ends.get(1));
  }
  if (!annotationElements.isEmpty()) {
    associationSet.setAnnotationElements(annotationElements);
  }
  return associationSet;
}
 
Example 13
Source File: MavenSettings.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void parseSettings(final XMLStreamReader reader, MavenSettings mavenSettings) throws XMLStreamException, IOException {
    int eventType;
    while ((eventType = reader.nextTag()) != END_DOCUMENT) {
        switch (eventType) {
            case END_ELEMENT: {
                return;
            }
            case START_ELEMENT: {
                switch (reader.getLocalName()) {
                    case "localRepository": {
                        String localRepository = reader.getElementText();
                        if (localRepository != null && !localRepository.trim().isEmpty()) {
                            mavenSettings.setLocalRepository(Paths.get(localRepository));
                        }
                        break;
                    }
                    case "profiles": {
                        while ((eventType = reader.nextTag()) != END_DOCUMENT) {
                            if (eventType == START_ELEMENT) {
                                switch (reader.getLocalName()) {
                                    case "profile": {
                                        parseProfile(reader, mavenSettings);
                                        break;
                                    }
                                }
                            } else {
                                break;
                            }
                        }
                        break;
                    }
                    case "activeProfiles": {
                        while ((eventType = reader.nextTag()) != END_DOCUMENT) {
                            if (eventType == START_ELEMENT) {
                                switch (reader.getLocalName()) {
                                    case "activeProfile": {
                                        mavenSettings.addActiveProfile(reader.getElementText());
                                        break;
                                    }
                                }
                            } else {
                                break;
                            }

                        }
                        break;
                    }
                    default: {
                        skip(reader);
                    }
                }
                break;
            }
            default: {
                throw new XMLStreamException("Unexpected content", reader.getLocation());
            }
        }
    }
    throw new XMLStreamException("Unexpected end of document", reader.getLocation());
}
 
Example 14
Source File: XmlMetadataDeserializer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private EdmMetadataAssociationEnd readAssociationEnd(final XMLStreamReader reader, 
    EdmImpl edm) throws EntityProviderException, XMLStreamException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ASSOCIATION_END);

  EdmAssociationEndImpl associationEnd = new EdmAssociationEndImpl();
  EdmAnnotationsImpl annotations = new EdmAnnotationsImpl();
  List<EdmAnnotationElement> annotationElements = new ArrayList<EdmAnnotationElement>();
  associationEnd.setRole(reader.getAttributeValue(null, XmlMetadataConstants.EDM_ROLE));
  associationEnd.setMultiplicity(EdmMultiplicity.fromLiteral(reader.getAttributeValue(null,
      XmlMetadataConstants.EDM_ASSOCIATION_MULTIPLICITY)));
  String type = reader.getAttributeValue(null, XmlMetadataConstants.EDM_TYPE);
  if (type == null) {
    throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE
        .addContent(XmlMetadataConstants.EDM_TYPE).addContent(XmlMetadataConstants.EDM_ASSOCIATION_END));
  }
  associationEnd.setEdm(edm);
  associationEnd.setType(extractFQName(type));
  annotations.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_ASSOCIATION_END.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      currentHandledStartTagName = reader.getLocalName();
      if (XmlMetadataConstants.EDM_ASSOCIATION_ONDELETE.equals(currentHandledStartTagName)) {
        EdmOnDeleteImpl onDelete = new EdmOnDeleteImpl();
        for (int i = 0; i < EdmAction.values().length; i++) {
          if (EdmAction.values()[i].name().equalsIgnoreCase(
              reader.getAttributeValue(null, XmlMetadataConstants.EDM_ONDELETE_ACTION))) {
            onDelete.setAction(EdmAction.values()[i]);
          }
        }
        associationEnd.setOnDelete(onDelete);
      } else {
        annotationElements.add(readAnnotationElement(reader));
      }
    }
  }
  if (!annotationElements.isEmpty()) {
    annotations.setAnnotationElements(annotationElements);
  }
  associationEnd.setAnnotations(annotations);
  return associationEnd;
}
 
Example 15
Source File: RaParser.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
private Activationspec parseActivationspec(XMLStreamReader reader) throws XMLStreamException, ParserException
{
   ArrayList<RequiredConfigProperty> requiredConfigProperty = new ArrayList<RequiredConfigProperty>();
   XsdString activationspecClass = NULL_XSDSTRING;
   ArrayList<ConfigProperty> configProperty = new ArrayList<ConfigProperty>();
   //getting attributes
   String id = reader.getAttributeValue(null, XML.ATTRIBUTE_ID);

   while (reader.hasNext())
   {

      switch (reader.nextTag())
      {
         case END_ELEMENT : {
            if (XML.ELEMENT_ACTIVATIONSPEC.equals(reader.getLocalName()))
            {
               //trimming collections
               requiredConfigProperty.trimToSize();
               configProperty.trimToSize();

               //building and returning object
               return new ActivationSpecImpl(activationspecClass, requiredConfigProperty, configProperty, id);
            }
            else
            {
               switch (reader.getLocalName())
               {
                  case XML.ELEMENT_ACTIVATIONSPEC_CLASS :
                  case XML.ELEMENT_REQUIRED_CONFIG_PROPERTY :
                  case XML.ELEMENT_CONFIG_PROPERTY :
                     break;
                  default :
                     throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
               }
            }
            break;
         }
         case START_ELEMENT : {
            switch (reader.getLocalName())
            {
               case XML.ELEMENT_ACTIVATIONSPEC_CLASS : {
                  activationspecClass = elementAsXsdString(reader);
                  break;
               }
               case XML.ELEMENT_REQUIRED_CONFIG_PROPERTY : {
                  requiredConfigProperty.add(parseRequiredConfigProperty(reader));
                  break;
               }
               case XML.ELEMENT_CONFIG_PROPERTY : {
                  configProperty.add(parseConfigProperty(reader));
                  break;
               }
               default :
                  throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
            }
            break;
         }
      }
   }
   throw new ParserException(bundle.unexpectedEndOfDocument());
}
 
Example 16
Source File: ResultListUtil.java    From mysql_perf_analyzer with Apache License 2.0 4 votes vote down vote up
private static List<BindVariable> parseBinds(String binds, XMLInputFactory inputFactory)
{
	if(binds==null)return null;
	List<BindVariable> vars = new java.util.ArrayList<BindVariable>();
	//<binds><bind name=":1" pos="1" dty="1" dtystr="VARCHAR2(2000)" maxlen="2000" csid="873" len="15">Billing Contact</bind></binds>
	
	java.io.CharArrayReader in = new java.io.CharArrayReader(binds.toCharArray());
	XMLStreamReader reader = null;
	try
	{
		reader = inputFactory.createXMLStreamReader(in);
		while(reader.hasNext())
		{
			//loop till one sql tag is found
			int evtType = reader.next();
			if(evtType!=XMLStreamConstants.START_ELEMENT)continue;
			String tagName = reader.getLocalName();
			if(!"bind".equals(tagName))continue;
			BindVariable var = new BindVariable();
			int attrCount = reader.getAttributeCount();
			for(int i=0;i<attrCount;i++)
			{
				String attrName = reader.getAttributeLocalName(i);
				String attrValue = reader.getAttributeValue(i);
				if("name".equals(attrName))
					var.name = attrValue;
				else if("pos".equals(attrName))
					var.pos = attrValue;
				else if("dtystr".equalsIgnoreCase(attrName))
					var.dtystr = attrValue;
				else if("maxlen".equalsIgnoreCase(attrName))
				{
					var.maxLen = attrValue;
				}else if("len".equalsIgnoreCase(attrName))
				{
					var.len = attrValue;
				}
			}
			var.value = reader.getElementText();
			vars.add(var);
	    }				
	}catch(Exception ex)
	{
		
	}
	finally
	{
		if(reader!=null)try{reader.close(); reader=null;}catch(Exception iex){}
	}

	return vars;
}
 
Example 17
Source File: RaParser.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
private ConfigProperty parseConfigProperty(XMLStreamReader reader) throws XMLStreamException, ParserException
{
   ArrayList<LocalizedXsdString> description = new ArrayList<LocalizedXsdString>();
   XsdString configPropertyType = NULL_XSDSTRING;
   XsdString configPropertyValue = NULL_XSDSTRING;
   Boolean configPropertyIgnore = null;
   XsdString configPropertyName = NULL_XSDSTRING;
   Boolean configPropertySupportsDynamicUpdates = null;
   Boolean configPropertyConfidential = null;
   String ignoreId = null;
   String updatesId = null;
   String confidId = null;

   //getting attributes
   String id = reader.getAttributeValue(null, XML.ATTRIBUTE_ID);

   while (reader.hasNext())
   {
      switch (reader.nextTag())
      {
         case END_ELEMENT : {
            if (XML.ELEMENT_CONFIG_PROPERTY.equals(reader.getLocalName()))
            {
               //trimming collections
               description.trimToSize();

               //building and returning object
               return new ConfigPropertyImpl(description, configPropertyName, configPropertyType,
                                             configPropertyValue, configPropertyIgnore,
                                             configPropertySupportsDynamicUpdates,
                                             configPropertyConfidential, id, false, null,
                                             ignoreId, updatesId, confidId);
            }
            else
            {
               switch (reader.getLocalName())
               {
                  case XML.ELEMENT_DESCRIPTION :
                  case XML.ELEMENT_CONFIG_PROPERTY_NAME :
                  case XML.ELEMENT_CONFIG_PROPERTY_TYPE :
                  case XML.ELEMENT_CONFIG_PROPERTY_VALUE :
                  case XML.ELEMENT_CONFIG_PROPERTY_IGNORE :
                  case XML.ELEMENT_CONFIG_PROPERTY_CONFIDENTIAL :
                  case XML.ELEMENT_CONFIG_PROPERTY_SUPPORT_DYNAMIC_UPDATE :
                     break;
                  default :
                     throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
               }
            }
            break;
         }
         case START_ELEMENT : {
            switch (reader.getLocalName())
            {
               case XML.ELEMENT_DESCRIPTION : {
                  description.add(elementAsLocalizedXsdString(reader));
                  break;
               }
               case XML.ELEMENT_CONFIG_PROPERTY_NAME : {
                  configPropertyName = elementAsXsdString(reader);
                  break;
               }
               case XML.ELEMENT_CONFIG_PROPERTY_TYPE : {
                  configPropertyType = elementAsXsdString(reader);
                  break;
               }
               case XML.ELEMENT_CONFIG_PROPERTY_VALUE : {
                  configPropertyValue = elementAsXsdString(reader);
                  break;
               }
               case XML.ELEMENT_CONFIG_PROPERTY_IGNORE : {
                  ignoreId = reader.getAttributeValue(null, XML.ATTRIBUTE_ID);
                  configPropertyIgnore = elementAsBoolean(reader, null, null);
                  break;
               }
               case XML.ELEMENT_CONFIG_PROPERTY_CONFIDENTIAL : {
                  confidId = reader.getAttributeValue(null, XML.ATTRIBUTE_ID);
                  configPropertyConfidential = elementAsBoolean(reader, null, null);
                  break;
               }
               case XML.ELEMENT_CONFIG_PROPERTY_SUPPORT_DYNAMIC_UPDATE : {
                  updatesId = reader.getAttributeValue(null, XML.ATTRIBUTE_ID);
                  configPropertySupportsDynamicUpdates = elementAsBoolean(reader, null, null);
                  break;
               }
               default :
                  throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
            }
            break;
         }
      }
   }
   throw new ParserException(bundle.unexpectedEndOfDocument());
}
 
Example 18
Source File: ResourceAdapterParser.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Activations parse(XMLStreamReader reader) throws Exception
{

   Activations adapters = null;

   //iterate over tags
   int iterate;
   try
   {
      iterate = reader.nextTag();
   }
   catch (XMLStreamException e)
   {
      //founding a non tag..go on. Normally non-tag found at beginning are comments or DTD declaration
      iterate = reader.nextTag();
   }
   switch (iterate)
   {
      case END_ELEMENT : {
         // should mean we're done, so ignore it.
         break;
      }
      case START_ELEMENT : {

         switch (reader.getLocalName())
         {
            case XML.ELEMENT_RESOURCE_ADAPTERS : {
               adapters = parseResourceAdapters(reader);
               break;
            }
            default :
               throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
         }

         break;
      }
      default :
         throw new IllegalStateException();
   }

   return adapters;

}
 
Example 19
Source File: XsdRestriction.java    From gs-xsd2bean with Apache License 2.0 4 votes vote down vote up
private void parseSubElements(XMLStreamReader xmlStreamReader, String diagnosticMessage) throws XMLStreamException
{
    int eventType = XsdSchemaUnmarshaller.getNextStartOrEnd(xmlStreamReader, diagnosticMessage);
    if (XsdSchemaUnmarshaller.isAtEnd(xmlStreamReader, eventType, "restriction")) return;
    while (eventType == XMLStreamConstants.START_ELEMENT)
    {
        String elementName = xmlStreamReader.getLocalName();
        if (elementName.equals("enumeration"))
        {
            if (this.validators.size() > 0)
            {
                XsdSchemaUnmarshaller.throwException("cannot have both 'enumeration' and validation in restricted simple type", xmlStreamReader, diagnosticMessage);
            }
            this.isEnumeration = true;
            XsdEnumeration enumeration = new XsdEnumeration();
            enumeration.parse(xmlStreamReader, diagnosticMessage);
            this.enumerationList.add(enumeration);
        }
        else if (elementName.equals("pattern"))
        {
            checkForEnumeration(xmlStreamReader, diagnosticMessage,elementName);
            XsdPattern pattern = new XsdPattern();
            pattern.parse(xmlStreamReader, diagnosticMessage);
            this.validators.add(pattern);
        }
        else if (elementName.equals("fractionDigits"))
        {
            checkForEnumeration(xmlStreamReader, diagnosticMessage,elementName);
            XsdFractionDigits fractionDigits = new XsdFractionDigits();
            fractionDigits.parse(xmlStreamReader, diagnosticMessage);
            this.validators.add(fractionDigits);
            this.precision = fractionDigits.value;
        }
        else if (elementName.equals("minInclusive"))
        {
            checkForEnumeration(xmlStreamReader, diagnosticMessage,elementName);
            XsdMinInclusive minInclusive = new XsdMinInclusive();
            minInclusive.parse(xmlStreamReader, diagnosticMessage);
            this.validators.add(minInclusive);
        }
        else if (elementName.equals("maxLength"))
        {
            checkForEnumeration(xmlStreamReader, diagnosticMessage,elementName);
            XsdMaxLength maxLength = new XsdMaxLength();
            maxLength.parse(xmlStreamReader, diagnosticMessage);
            this.validators.add(maxLength);
        }
        else if (elementName.equals("minLength"))
        {
            checkForEnumeration(xmlStreamReader, diagnosticMessage,elementName);
            XsdMinLength minLength = new XsdMinLength();
            minLength.parse(xmlStreamReader, diagnosticMessage);
            this.validators.add(minLength);
        }
        else if (elementName.equals("length"))
        {
            checkForEnumeration(xmlStreamReader, diagnosticMessage,elementName);
            XsdLength length = new XsdLength();
            length.parse(xmlStreamReader, diagnosticMessage);
            this.validators.add(length);
        }
        else if (elementName.equals("totalDigits"))
        {
            checkForEnumeration(xmlStreamReader, diagnosticMessage,elementName);
            XsdTotalDigits totalDigits = new XsdTotalDigits();
            totalDigits.parse(xmlStreamReader, diagnosticMessage);
            this.validators.add(totalDigits);
            this.width= totalDigits.value;
            this.flag="0";
        }
        eventType = XsdSchemaUnmarshaller.getNextStartOrEnd(xmlStreamReader, diagnosticMessage);
    }
    XsdSchemaUnmarshaller.expectEnd(xmlStreamReader, diagnosticMessage, eventType, "restriction");
}
 
Example 20
Source File: RaParser.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
private AdminObject parseAdminObject(XMLStreamReader reader) throws XMLStreamException, ParserException
{
   ArrayList<ConfigProperty> configProperty = new ArrayList<ConfigProperty>();
   XsdString adminobjectInterface = NULL_XSDSTRING;
   XsdString adminobjectClass = NULL_XSDSTRING;

   //getting attributes
   String id = reader.getAttributeValue(null, XML.ATTRIBUTE_ID);

   while (reader.hasNext())
   {
      switch (reader.nextTag())
      {
         case END_ELEMENT : {
            if (XML.ELEMENT_ADMINOBJECT.equals(reader.getLocalName()))
            {
               //trimming collections
               configProperty.trimToSize();

               //building and returning object
               return new AdminObjectImpl(adminobjectInterface, adminobjectClass, configProperty, id);
            }
            else
            {
               switch (reader.getLocalName())
               {
                  case XML.ELEMENT_ADMINOBJECT_CLASS :
                  case XML.ELEMENT_ADMINOBJECT_INTERFACE :
                  case XML.ELEMENT_CONFIG_PROPERTY :
                     break;
                  default :
                     throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
               }
            }
            break;
         }
         case START_ELEMENT : {
            switch (reader.getLocalName())
            {
               case XML.ELEMENT_ADMINOBJECT_CLASS : {
                  adminobjectClass = elementAsXsdString(reader);
                  break;
               }
               case XML.ELEMENT_ADMINOBJECT_INTERFACE : {
                  adminobjectInterface = elementAsXsdString(reader);
                  break;
               }
               case XML.ELEMENT_CONFIG_PROPERTY : {
                  configProperty.add(parseConfigProperty(reader));
                  break;
               }
               default :
                  throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
            }
            break;
         }
      }
   }
   throw new ParserException(bundle.unexpectedEndOfDocument());
}