Esempio n. 1
0
 /**
  * Creates a new instance of Index Of Model Mappings read from the corresponding file (Used for
  * persistence)
  */
 public static void parseIndexFromFile() {
   // Read file and create the Index
   // check if file exists. If it exists open it and parse it.
   // Else return
   //
   File inFile = new File(Model3dIndex.getIndexPath() + "modelIndex.xml");
   // error state check
   if (inFile.exists()) {
     try {
       Model3dIndex.getListofAllMetaEntries().clear();
       FileReader tmpInReader = new FileReader(inFile);
       WstxInputFactory fin = new WstxInputFactory();
       fin.configureForConvenience();
       fin.setProperty(
           XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); // <-- NEEDED TO GET ATTRIBUTES!
       // input
       XMLStreamReader2 sr = (XMLStreamReader2) fin.createXMLStreamReader(tmpInReader);
       SMInputCursor inputRootElement = SMInputFactory.rootElementCursor(sr);
       inputRootElement.getNext();
       SMInputCursor childInElement = inputRootElement.childCursor();
       String myText = "";
       while (childInElement.getNext() != null) {
         if (!childInElement.getCurrEvent().hasText()
             && childInElement
                 .getLocalName()
                 .toLowerCase()
                 .equals(Model3dIndex.getMetaEntryTag().toLowerCase())) {
           Model3dIndex.getListofAllMetaEntries().add(new Model3dIndexEntry(childInElement));
         }
       }
       tmpInReader.close();
     } catch (Exception e) {
       return;
     }
   } else return;
 }
Esempio n. 2
0
  public void testEmployee() throws Exception {
    System.setProperty("org.metatype.sxc.output.directory", "target/tmp-jaxb");

    JAXBContext ctx = new JAXBContextImpl(new Class[] {Employee.class});

    JAXBElement<Employee> jaxbE =
        (JAXBElement<Employee>)
            ctx.createUnmarshaller()
                .unmarshal(
                    xif.createXMLStreamReader(getResourceAsStream("employee.xml")), Employee.class);
    assertNotNull(jaxbE);
    assertNotNull(jaxbE.getValue());

    Employee e = jaxbE.getValue();
    assertEquals("foo", e.getDivision());
    assertEquals("bar", e.getName());

    Marshaller marshaller = ctx.createMarshaller();
    assertNotNull(marshaller);

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    XMLStreamWriter writer = xof.createXMLStreamWriter(bos);
    try {
      marshaller.marshal(e, writer);
      fail("MarshalException should have been thrown!");
    } catch (MarshalException ex) {
    }

    marshaller.marshal(jaxbE, writer);

    writer.close();
    Document d = readDocument(bos.toByteArray());
    addNamespace("i", "urn:xfire:inheritance");
    assertValid("/i:in0/i:name[text()='bar']", d);
    assertValid("/i:in0/i:division[text()='foo']", d);
  }