当前位置: 首页>>代码示例>>Java>>正文


Java XMLEventReader2类代码示例

本文整理汇总了Java中org.odata4j.stax2.XMLEventReader2的典型用法代码示例。如果您正苦于以下问题:Java XMLEventReader2类的具体用法?Java XMLEventReader2怎么用?Java XMLEventReader2使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


XMLEventReader2类属于org.odata4j.stax2包,在下文中一共展示了XMLEventReader2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseEdmAssociationSet

import org.odata4j.stax2.XMLEventReader2; //导入依赖的package包/类
/**
 * parseEdmAssociationSet.
 * @param reader reader
 * @param associationSetElement associationSetElement
 * @return EdmAssociationSet.Builder
 */
private EdmAssociationSet.Builder parseEdmAssociationSet(
        XMLEventReader2 reader, StartElement2 associationSetElement) {
    String name = associationSetElement.getAttributeByName("Name").getValue();
    String associationName = associationSetElement.getAttributeByName("Association").getValue();

    List<EdmAssociationSetEnd.Builder> ends = new ArrayList<EdmAssociationSetEnd.Builder>();

    while (reader.hasNext()) {
        XMLEvent2 event = reader.nextEvent();

        if (isStartElement(event, EDM2006_END, EDM2007_END, EDM2008_END, EDM2009_END)) {
            ends.add(EdmAssociationSetEnd.newBuilder()
                    .setRoleName(event.asStartElement().getAttributeByName("Role").getValue())
                    .setEntitySetName(event.asStartElement().getAttributeByName("EntitySet").getValue()));
        }

        if (isEndElement(event, associationSetElement.getName())) {
            return EdmAssociationSet.newBuilder().setName(name)
                    .setAssociationName(associationName).setEnds(ends.get(0), ends.get(1));
        }
    }
    throw new UnsupportedOperationException();

}
 
开发者ID:personium,项目名称:personium-core,代码行数:31,代码来源:PersoniumEdmxFormatParser.java

示例2: parseEdmAssociation

import org.odata4j.stax2.XMLEventReader2; //导入依赖的package包/类
/**
 * parseEdmAssociation.
 * @param reader reader
 * @param schemaNamespace schemaNamespace
 * @param schemaAlias schemaAlias
 * @param associationElement associationElement
 * @return EdmAssociation.Builder
 */
private EdmAssociation.Builder parseEdmAssociation(
        XMLEventReader2 reader, String schemaNamespace, String schemaAlias, StartElement2 associationElement) {
    String name = associationElement.getAttributeByName("Name").getValue();

    List<EdmAssociationEnd.Builder> ends = new ArrayList<EdmAssociationEnd.Builder>();

    while (reader.hasNext()) {
        XMLEvent2 event = reader.nextEvent();

        if (isStartElement(event, EDM2006_END, EDM2007_END, EDM2008_END, EDM2009_END)) {
            ends.add(EdmAssociationEnd.newBuilder()
                    .setRole(event.asStartElement().getAttributeByName("Role").getValue())
                    .setTypeName(event.asStartElement().getAttributeByName("Type").getValue())
                    .setMultiplicity(EdmMultiplicity.fromSymbolString(
                            event.asStartElement().getAttributeByName("Multiplicity").getValue())));
        }

        if (isEndElement(event, associationElement.getName())) {
            return EdmAssociation.newBuilder().setNamespace(schemaNamespace).
                    setAlias(schemaAlias).setName(name).setEnds(ends.get(0), ends.get(1));
        }
    }
    throw new UnsupportedOperationException();

}
 
开发者ID:personium,项目名称:personium-core,代码行数:34,代码来源:PersoniumEdmxFormatParser.java

示例3: writeXml

import org.odata4j.stax2.XMLEventReader2; //导入依赖的package包/类
private static void writeXml(boolean includeCurrent, XMLEvent2 currentEvent, XMLEventReader2 xmlReader, XMLWriter2 xmlWriter) {
  if (currentEvent == null || !currentEvent.isStartElement())
    throw new IllegalStateException("currentEvent must be a start element");
  if (includeCurrent)
    writeStartElement(currentEvent.asStartElement(), xmlWriter);
  int level = 0;
  while (true) {
    currentEvent = xmlReader.nextEvent();
    if (currentEvent.isStartElement()) {
      writeStartElement(currentEvent.asStartElement(), xmlWriter);
      level++;
    } else if (currentEvent.isEndElement()) {
      if (level == 0)
        break;
      writeEndElement(currentEvent.asEndElement(), xmlWriter);
      level--;
    } else if (currentEvent.isCharacters()) {
      writeCharacters(currentEvent.asCharacters(), xmlWriter);
    }
  }
  if (includeCurrent)
    writeEndElement(currentEvent.asEndElement(), xmlWriter);
}
 
开发者ID:teiid,项目名称:oreva,代码行数:24,代码来源:StaxUtil.java

示例4: parseCollection

import org.odata4j.stax2.XMLEventReader2; //导入依赖的package包/类
private static AtomCollectionInfo parseCollection(String baseUrl, XMLEventReader2 reader, StartElement2 startElement) {
  String href = getAttributeValueIfExists(startElement, "href");
  String url = urlCombine(baseUrl, href);
  String title = null;
  String accept = null;
  while (reader.hasNext()) {
    XMLEvent2 event = reader.nextEvent();
    if (event.isEndElement() && event.asEndElement().getName().equals(startElement.getName())) {
      return new AtomCollectionInfo(href, url, title, accept);
    } else if (isStartElement(event, ATOM_TITLE)) {
      title = reader.getElementText();
    } else if (isStartElement(event, APP_ACCEPT)) {
      accept = reader.getElementText();
    }
  }
  return new AtomCollectionInfo(href, url, title, accept);
}
 
开发者ID:teiid,项目名称:oreva,代码行数:18,代码来源:AtomServiceDocumentFormatParser.java

示例5: parseFeed

import org.odata4j.stax2.XMLEventReader2; //导入依赖的package包/类
AtomFeed parseFeed(XMLEventReader2 reader, EdmEntitySet entitySet) {

    AtomFeed feed = new AtomFeed();
    List<AtomEntry> rt = new ArrayList<AtomEntry>();

    while (reader.hasNext()) {
      XMLEvent2 event = reader.nextEvent();

      if (isStartElement(event, ATOM_ENTRY)) {
        rt.add(parseEntry(reader, event.asStartElement(), entitySet));
      } else if (isStartElement(event, ATOM_LINK)) {
        if ("next".equals(event.asStartElement().getAttributeByName(new QName2("rel")).getValue())) {
          feed.next = event.asStartElement().getAttributeByName(new QName2("href")).getValue();
        }
      } else if (isEndElement(event, ATOM_FEED)) {
        // return from a sub feed, if we went down the hierarchy
        break;
      }

    }
    feed.entries = Enumerable.create(rt).cast(Entry.class);

    return feed;

  }
 
开发者ID:teiid,项目名称:oreva,代码行数:26,代码来源:AtomFeedFormatParser.java

示例6: innerText

import org.odata4j.stax2.XMLEventReader2; //导入依赖的package包/类
private static String innerText(XMLEventReader2 reader, StartElement2 element) {
  StringWriter sw = new StringWriter();
  XMLEventWriter2 writer = XMLFactoryProvider2.getInstance().newXMLOutputFactory2().createXMLEventWriter(sw);
  while (reader.hasNext()) {

    XMLEvent2 event = reader.nextEvent();
    if (event.isEndElement() && event.asEndElement().getName().equals(element.getName())) {

      return sw.toString();
    } else {
      writer.add(event);
    }

  }
  throw new RuntimeException();
}
 
开发者ID:teiid,项目名称:oreva,代码行数:17,代码来源:AtomFeedFormatParser.java

示例7: parse

import org.odata4j.stax2.XMLEventReader2; //导入依赖的package包/类
/**
 * Parse a complex type from function/action response.
 */
@Override
public OComplexObject parse(Reader reader) {
  XMLEvent2 event;
  XMLEventReader2 xmlReader = StaxUtil.newXMLEventReader(reader);
  
  xmlReader.nextEvent(); // start document;
  event = xmlReader.nextEvent(); // start element
  
  String name = event.asStartElement().getName().getLocalPart();
  Attribute2 typeAttribute = event.asStartElement().getAttributeByName(XmlFormatParser.M_TYPE);
  Attribute2 nullAttribute = event.asStartElement().getAttributeByName(XmlFormatParser.M_NULL);
  boolean isNull = nullAttribute != null && "true".equals(nullAttribute.getValue());
  
  if (isNull) {
    return null;
  }

  System.out.println("the complex type name is:"+name);

  
  Iterable<OProperty<?>> props = AtomFeedFormatParser.parseProperties(xmlReader, event.asStartElement(), settings.metadata, (EdmComplexType) settings.parseType);
  
  return createCT(props, (EdmComplexType) this.settings.parseType);
}
 
开发者ID:teiid,项目名称:oreva,代码行数:28,代码来源:AtomComplexFormatParser.java

示例8: parseEdmEntitySet

import org.odata4j.stax2.XMLEventReader2; //导入依赖的package包/类
private EdmEntitySet.Builder parseEdmEntitySet(XMLEventReader2 reader, String schemaNamespace, StartElement2 entitySetStartElement) {
  List<EdmAnnotation<?>> annotElements = new ArrayList<EdmAnnotation<?>>();
  String name = entitySetStartElement.getAttributeByName("Name").getValue();
  String entityTypeName = getAttributeValueIfExists(entitySetStartElement, "EntityType");
  while (reader.hasNext()) {
    XMLEvent2 event = reader.nextEvent();
    if (event.isStartElement()) {
      EdmAnnotation<?> anElement = getAnnotationElements(event, reader);
      if (anElement != null) {
        annotElements.add(anElement);
      }
    }
    if (isEndElement(event, entitySetStartElement.getName())) {
      return EdmEntitySet.newBuilder()
          .setName(name)
          .setEntityTypeName(entityTypeName)
          .setAnnotations(getAnnotations(entitySetStartElement))
          .setAnnotationElements(annotElements);
    }
  }
  throw new UnsupportedOperationException();
}
 
开发者ID:teiid,项目名称:oreva,代码行数:23,代码来源:EdmxFormatParser.java

示例9: parseEdmAssociationSetEnd

import org.odata4j.stax2.XMLEventReader2; //导入依赖的package包/类
private EdmAssociationSetEnd.Builder parseEdmAssociationSetEnd(XMLEventReader2 reader, StartElement2 endStartElement) {
  List<EdmAnnotation<?>> annotElements = new ArrayList<EdmAnnotation<?>>();
  String role = endStartElement.getAttributeByName("Role").getValue();
  String entitySetName = endStartElement.getAttributeByName("EntitySet").getValue();
  while (reader.hasNext()) {
    XMLEvent2 event = reader.nextEvent();
    if (event.isStartElement()) {
      EdmAnnotation<?> anElement = getAnnotationElements(event, reader);
      if (anElement != null) {
        annotElements.add(anElement);
      }
    }
    if (isEndElement(event, endStartElement.getName())) {
      return EdmAssociationSetEnd.newBuilder().setRoleName(role)
          .setEntitySetName(entitySetName)
          .setAnnotations(getAnnotations(endStartElement))
          .setAnnotationElements(annotElements);
    }
  }
  throw new UnsupportedOperationException();
}
 
开发者ID:teiid,项目名称:oreva,代码行数:22,代码来源:EdmxFormatParser.java

示例10: testInheritance

import org.odata4j.stax2.XMLEventReader2; //导入依赖的package包/类
@Test
public void testInheritance() throws FileNotFoundException, InterruptedException {

  // do the raw xml first...
  XMLEventReader2 reader = StaxUtil.newXMLEventReader(new BufferedReader(
      new InputStreamReader(getClass().getResourceAsStream(edmxFile))));
  EdmDataServices d = new EdmxFormatParser().parseMetadata(reader);
  assertTrue("parsed", d != null);

  checkTypeHierarchy(d);

  // now take the parsed result, back to xml, re-parse, check that...
  StringWriter sw = new StringWriter();
  EdmxFormatWriter.write(d, sw);

  EdmDataServices d2 = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new StringReader(sw.toString())));
  assertTrue("parsed", d2 != null);

  checkTypeHierarchy(d2);
}
 
开发者ID:teiid,项目名称:oreva,代码行数:21,代码来源:EdmxFormatParserTest.java

示例11: testProperty

import org.odata4j.stax2.XMLEventReader2; //导入依赖的package包/类
@Test
public void testProperty() {
  XMLEventReader2 reader = StaxUtil.newXMLEventReader(new BufferedReader(
      new InputStreamReader(getClass().getResourceAsStream("/META-INF/property.xml"))));
  EdmDataServices d = new EdmxFormatParser().parseMetadata(reader);
  assertTrue("parsed", d != null);

  EdmEntityType product = d.findEdmEntitySet("Products").getType();
  EdmProperty property = product.findProperty("Name");
  assertTrue(property != null);
  assertTrue(property.getCollation() != null);
  assertTrue(property.getUnicode() != null);
  assertTrue(property.getFixedLength() != null);

  assertNotNull(property.findAnnotationElement("bla", "MyElement"));
  assertEquals("MyElement", property.findAnnotationElement("bla", "MyElement").getName());
}
 
开发者ID:teiid,项目名称:oreva,代码行数:18,代码来源:EdmxFormatParserTest.java

示例12: testAssociationEnd

import org.odata4j.stax2.XMLEventReader2; //导入依赖的package包/类
@Test
public void testAssociationEnd() {
  XMLEventReader2 reader = StaxUtil.newXMLEventReader(new BufferedReader(
      new InputStreamReader(getClass().getResourceAsStream("/META-INF/associationEnd.xml"))));
  EdmDataServices d = new EdmxFormatParser().parseMetadata(reader);
  assertTrue("parsed", d != null);
  for (EdmAssociation association : d.getAssociations()) {
    if (association.getName().equals("ProductCategory")) {
      if (association.getEnd1().getRole().equals("Category")) {
        assertTrue(association.getEnd1().getOnDeleteAction() != null);
      } else {
        assertTrue(association.getEnd2().getOnDeleteAction() != null);
      }
    }
  }
}
 
开发者ID:teiid,项目名称:oreva,代码行数:17,代码来源:EdmxFormatParserTest.java

示例13: testForRecursion

import org.odata4j.stax2.XMLEventReader2; //导入依赖的package包/类
@Test
public void testForRecursion() {
  XMLEventReader2 reader = StaxUtil.newXMLEventReader(new BufferedReader(
      new InputStreamReader(getClass().getResourceAsStream("/META-INF/annotation.xml"))));
  EdmDataServices d = new EdmxFormatParser().parseMetadata(reader);
  assertTrue("parsed", d != null);

  EdmAnnotationElement<?> annot = (EdmAnnotationElement<?>) d.findSchema("Example").findAnnotationElement(MYNAMESPACE, "AnnotElement");

  assertNotNull(annot);
  assertNotNull(annot.findAnnotationElement(MYNAMESPACE, "testing"));
  assertNotNull(annot.findAnnotationElement(MYNAMESPACE, "another"));

  EdmAnnotationElement<?> annot2 = (EdmAnnotationElement<?>) annot.findAnnotationElement(MYNAMESPACE, "another");
  assertEquals("bar", annot2.findAnnotation(MYNAMESPACE, "foo").getValue());
  assertNotNull(annot2.findAnnotationElement(MYNAMESPACE, "yetanother"));
  assertEquals("yetanother", annot2.findAnnotationElement(MYNAMESPACE, "yetanother").getValue().toString().trim());
  assertEquals("mynamespace", annot2.findAnnotationElement(MYNAMESPACE, "yetanother").getNamespace().getPrefix());
  assertEquals(MYNAMESPACE, annot2.findAnnotationElement(MYNAMESPACE, "yetanother").getNamespace().getUri());
}
 
开发者ID:teiid,项目名称:oreva,代码行数:21,代码来源:EdmxFormatParserTest.java

示例14: issue15

import org.odata4j.stax2.XMLEventReader2; //导入依赖的package包/类
@Test
public void issue15() {

  InputStream xml = getClass().getResourceAsStream(
      "/META-INF/issue15.xml");

  XMLEventReader2 reader = DomXMLFactoryProvider2.getInstance()
      .newXMLInputFactory2()
      .createXMLEventReader(new InputStreamReader(xml));
  reader.nextEvent();
  StartElement2 propertiesElement = reader.nextEvent().asStartElement();
  for (OProperty<?> prop : AtomFeedFormatParser.parseProperties(reader,
      propertiesElement, null, null)) {
    if (prop.getName().equals("update_date")) {
      Assert.assertEquals("2010-11-21T12:21:51.000", prop.getValue()
          .toString());
      return;
    }
  }
  Assert.fail("Expected a property update_date");
}
 
开发者ID:teiid,项目名称:oreva,代码行数:22,代码来源:Issue15Test.java

示例15: parseEdmComplexType

import org.odata4j.stax2.XMLEventReader2; //导入依赖的package包/类
/**
 * parseEdmComplexType.
 * @param reader reader
 * @param schemaNamespace schemaNamespace
 * @param complexTypeElement complexTypeElement
 * @return EdmComplexType.Builder
 */
private EdmComplexType.Builder parseEdmComplexType(
        XMLEventReader2 reader, String schemaNamespace, StartElement2 complexTypeElement) {
    String name = complexTypeElement.getAttributeByName("Name").getValue();
    String isAbstractS = getAttributeValueIfExists(complexTypeElement, "Abstract");
    List<EdmProperty.Builder> edmProperties = new ArrayList<EdmProperty.Builder>();

    while (reader.hasNext()) {
        XMLEvent2 event = reader.nextEvent();

        if (isStartElement(event, EDM2006_PROPERTY, EDM2007_PROPERTY, EDM2008_PROPERTY, EDM2009_PROPERTY)) {
            edmProperties.add(parseEdmProperty(event));
        }

        if (isEndElement(event, complexTypeElement.getName())) {
            EdmComplexType.Builder complexType = EdmComplexType.newBuilder()
                    .setNamespace(schemaNamespace).setName(name).addProperties(edmProperties);
            if (isAbstractS != null) {
                complexType.setIsAbstract("true".equals(isAbstractS));
            }
            return complexType;
        }
    }

    throw new UnsupportedOperationException();

}
 
开发者ID:personium,项目名称:personium-core,代码行数:34,代码来源:PersoniumEdmxFormatParser.java


注:本文中的org.odata4j.stax2.XMLEventReader2类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。