public void save(XMLDocument xmlDocument, Result result, Object options) throws IOException {
    if (xmlDocument == null) {
      throw new IllegalArgumentException(
          SDOException.cannotPerformOperationWithNullInputParameter("save", "xmlDocument"));
    }

    if (result instanceof StreamResult) {
      StreamResult streamResult = (StreamResult) result;
      Writer writer = streamResult.getWriter();
      if (null == writer) {
        save(xmlDocument, streamResult.getOutputStream(), options);
      } else {
        save(xmlDocument, writer, options);
      }

    } else {
      // get XMLMarshaller once - as we may create a new instance if this helper isDirty=true
      XMLMarshaller anXMLMarshaller = getXmlMarshaller(options);

      // Ask the SDOXMLDocument if we should include the XML declaration in the resulting XML
      anXMLMarshaller.setFragment(!xmlDocument.isXMLDeclaration());

      anXMLMarshaller.setEncoding(xmlDocument.getEncoding());
      anXMLMarshaller.setSchemaLocation(xmlDocument.getSchemaLocation());
      anXMLMarshaller.setNoNamespaceSchemaLocation(xmlDocument.getNoNamespaceSchemaLocation());
      ((SDOMarshalListener) anXMLMarshaller.getMarshalListener())
          .setMarshalledObject(xmlDocument.getRootObject());
      ((SDOMarshalListener) anXMLMarshaller.getMarshalListener())
          .setMarshalledObjectRootQName(
              new QName(xmlDocument.getRootElementURI(), xmlDocument.getRootElementName()));

      if (result instanceof SAXResult) {
        ContentHandlerRecord marshalRecord = new ContentHandlerRecord();
        marshalRecord.setContentHandler(((SAXResult) result).getHandler());
        marshalRecord.setMarshaller(anXMLMarshaller);
        ((SDOMarshalListener) anXMLMarshaller.getMarshalListener())
            .setRootMarshalRecord(marshalRecord);
        anXMLMarshaller.marshal(xmlDocument, marshalRecord);
      } else if (result instanceof DOMResult) {
        NodeRecord marshalRecord = new NodeRecord();
        marshalRecord.setDOM(((DOMResult) result).getNode());
        marshalRecord.setMarshaller(anXMLMarshaller);
        ((SDOMarshalListener) anXMLMarshaller.getMarshalListener())
            .setRootMarshalRecord(marshalRecord);
        anXMLMarshaller.marshal(xmlDocument, marshalRecord);
      } else {
        StringWriter writer = new StringWriter();
        this.save(xmlDocument, writer, options);
        String xml = writer.toString();
        StreamSource source = new StreamSource(new java.io.StringReader(xml));
        anXMLMarshaller.getTransformer().transform(source, result);
      }
    }
  }
  /**
   * INTERNAL: Saves the DataObject as an XML document with the specified root element. Same as
   * save(createDocument(dataObject, rootElementURI, rootElementName), writer, null);
   *
   * @param dataObject specifies DataObject to be saved
   * @param rootElementURI the Target Namespace URI of the root XML element
   * @param rootElementName the Name of the root XML element
   * @param writer specifies the Writer to write to.
   * @throws IOException for stream exceptions.
   * @throws IllegalArgumentException if the dataObject tree is not closed or has no container.
   */
  private void save(
      DataObject rootObject,
      String rootElementURI,
      String rootElementName,
      Writer writer,
      XMLMarshaller anXMLMarshaller)
      throws XMLMarshalException {
    SDOXMLDocument xmlDocument =
        (SDOXMLDocument) createDocument(rootObject, rootElementURI, rootElementName);

    // Ask the SDOXMLDocument if we should include the XML declaration in the resulting XML
    anXMLMarshaller.setFragment(!xmlDocument.isXMLDeclaration());
    WriterRecord writerRecord;
    if (anXMLMarshaller.isFormattedOutput()) {
      writerRecord = new FormattedWriterRecord();
    } else {
      writerRecord = new WriterRecord();
    }
    writerRecord.setWriter(writer);
    writerRecord.setMarshaller(anXMLMarshaller);

    ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()).setMarshalledObject(rootObject);
    ((SDOMarshalListener) anXMLMarshaller.getMarshalListener())
        .setMarshalledObjectRootQName(new QName(rootElementURI, rootElementName));
    ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()).setRootMarshalRecord(writerRecord);
    anXMLMarshaller.marshal(xmlDocument, writerRecord);
    try {
      writer.flush();
    } catch (IOException ex) {
      throw XMLMarshalException.marshalException(ex);
    }
  }
  private void save(XMLDocument xmlDocument, Writer outputWriter, XMLMarshaller anXMLMarshaller)
      throws IOException {
    if (xmlDocument == null) {
      throw new IllegalArgumentException(
          SDOException.cannotPerformOperationWithNullInputParameter("save", "xmlDocument"));
    }

    // Ask the SDOXMLDocument if we should include the XML declaration in the resulting XML
    anXMLMarshaller.setFragment(!xmlDocument.isXMLDeclaration());

    anXMLMarshaller.setEncoding(xmlDocument.getEncoding());
    anXMLMarshaller.setSchemaLocation(xmlDocument.getSchemaLocation());
    anXMLMarshaller.setNoNamespaceSchemaLocation(xmlDocument.getNoNamespaceSchemaLocation());

    WriterRecord writerRecord;
    if (anXMLMarshaller.isFormattedOutput()) {
      writerRecord = new FormattedWriterRecord();
    } else {
      writerRecord = new WriterRecord();
    }
    writerRecord.setWriter(outputWriter);
    writerRecord.setMarshaller(anXMLMarshaller);

    ((SDOMarshalListener) anXMLMarshaller.getMarshalListener())
        .setMarshalledObject(xmlDocument.getRootObject());
    ((SDOMarshalListener) anXMLMarshaller.getMarshalListener())
        .setMarshalledObjectRootQName(
            new QName(xmlDocument.getRootElementURI(), xmlDocument.getRootElementName()));
    ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()).setRootMarshalRecord(writerRecord);

    anXMLMarshaller.marshal(xmlDocument, writerRecord);
    outputWriter.flush();
  }
  public void marshal(Object object, OutputStream outputStream) throws JAXBException {
    if (object == null || outputStream == null) {
      throw new IllegalArgumentException();
    }
    object = modifyObjectIfNeeded(object);

    try {
      xmlMarshaller.marshal(object, outputStream);
    } catch (Exception e) {
      throw new MarshalException(e);
    }
  }
  public void marshal(Object object, Writer writer) throws JAXBException {
    if (object == null || writer == null) {
      throw new IllegalArgumentException();
    }
    object = modifyObjectIfNeeded(object);

    try {
      xmlMarshaller.marshal(object, writer);
    } catch (Exception e) {
      throw new MarshalException(e);
    }
  }
  public void marshal(Object object, MarshalRecord record) throws JAXBException {
    if (object == null || record == null) {
      throw new IllegalArgumentException();
    }
    object = modifyObjectIfNeeded(object);

    try {
      record.setMarshaller(xmlMarshaller);
      xmlMarshaller.marshal(object, record);
    } catch (Exception e) {
      throw new MarshalException(e);
    }
  }
Пример #7
0
 @Test
 public void echoClob() throws ParseException, SQLException {
   Invocation invocation = new Invocation("echoClob");
   invocation.setParameter("PINPUTCLOB", "This is a Clob test");
   Operation op = xrService.getOperation(invocation.getName());
   Object result = op.invoke(xrService, invocation);
   assertNotNull("result is null", result);
   Document doc = xmlPlatform.createDocument();
   XMLMarshaller marshaller = xrService.getXMLContext().createMarshaller();
   marshaller.marshal(result, doc);
   Document controlDoc = xmlParser.parse(new StringReader(ECHO_CLOB_RESULT));
   assertTrue(
       "control document not same as instance document", comparer.isNodeEqual(controlDoc, doc));
 }
Пример #8
0
 @Test
 public void echoDouble() {
   Invocation invocation = new Invocation("echoDouble");
   invocation.setParameter("PDOUBLE", new Double("314.15926"));
   Operation op = xrService.getOperation(invocation.getName());
   Object result = op.invoke(xrService, invocation);
   assertNotNull("result is null", result);
   Document doc = xmlPlatform.createDocument();
   XMLMarshaller marshaller = xrService.getXMLContext().createMarshaller();
   marshaller.marshal(result, doc);
   Document controlDoc = xmlParser.parse(new StringReader(ECHO_DOUBLE_RESULT));
   assertTrue(
       "control document not same as instance document", comparer.isNodeEqual(controlDoc, doc));
 }
Пример #9
0
 @Test
 public void echoRowId() throws ParseException {
   Invocation invocation = new Invocation("echoRowId");
   invocation.setParameter("PROWID", "'AAADL1AABAAACTEAAE'");
   Operation op = xrService.getOperation(invocation.getName());
   Object result = op.invoke(xrService, invocation);
   assertNotNull("result is null", result);
   Document doc = xmlPlatform.createDocument();
   XMLMarshaller marshaller = xrService.getXMLContext().createMarshaller();
   marshaller.marshal(((XMLRoot) result).getObject(), doc);
   Document controlDoc = xmlParser.parse(new StringReader(ECHO_ROWID_RESULT));
   assertTrue(
       "control document not same as instance document", comparer.isNodeEqual(controlDoc, doc));
 }
Пример #10
0
 @Test
 public void echoVarchar2() {
   Invocation invocation = new Invocation("echoVarchar2");
   invocation.setParameter("PINPUTVARCHAR", "this is a varchar2 test");
   Operation op = xrService.getOperation(invocation.getName());
   Object result = op.invoke(xrService, invocation);
   assertNotNull("result is null", result);
   Document doc = xmlPlatform.createDocument();
   XMLMarshaller marshaller = xrService.getXMLContext().createMarshaller();
   marshaller.marshal(result, doc);
   Document controlDoc = xmlParser.parse(new StringReader(ECHO_VARCHAR2_RESULT));
   assertTrue(
       "control document not same as instance document", comparer.isNodeEqual(controlDoc, doc));
 }
Пример #11
0
 @Test
 public void echoRaw() throws ParseException {
   Invocation invocation = new Invocation("echoRaw");
   byte[] testBytes = "This is yet another test!".getBytes();
   invocation.setParameter("PRAW", testBytes);
   Operation op = xrService.getOperation(invocation.getName());
   Object result = op.invoke(xrService, invocation);
   assertNotNull("result is null", result);
   Document doc = xmlPlatform.createDocument();
   XMLMarshaller marshaller = xrService.getXMLContext().createMarshaller();
   marshaller.marshal(((XMLRoot) result).getObject(), doc);
   Document controlDoc = xmlParser.parse(new StringReader(ECHO_RAW_RESULT));
   assertTrue(
       "control document not same as instance document", comparer.isNodeEqual(controlDoc, doc));
 }
Пример #12
0
 @Test
 public void echoTimestamp() throws ParseException {
   Invocation invocation = new Invocation("echoTimestamp");
   SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd:hhmmss.SSS");
   invocation.setParameter("PINPUTTS", format.parse("20091204:091923.123"));
   Operation op = xrService.getOperation(invocation.getName());
   Object result = op.invoke(xrService, invocation);
   assertNotNull("result is null", result);
   Document doc = xmlPlatform.createDocument();
   XMLMarshaller marshaller = xrService.getXMLContext().createMarshaller();
   marshaller.marshal(result, doc);
   Document controlDoc = xmlParser.parse(new StringReader(ECHO_TS_RESULT));
   assertTrue(
       "control document not same as instance document", comparer.isNodeEqual(controlDoc, doc));
 }
Пример #13
0
 @Test
 public void echoLong() throws ParseException {
   Invocation invocation = new Invocation("echoLong");
   invocation.setParameter(
       "PLONG", "This is a LONG type test.  A LONG type represents 2GB of character data.");
   Operation op = xrService.getOperation(invocation.getName());
   Object result = op.invoke(xrService, invocation);
   assertNotNull("result is null", result);
   Document doc = xmlPlatform.createDocument();
   XMLMarshaller marshaller = xrService.getXMLContext().createMarshaller();
   marshaller.marshal(((XMLRoot) result).getObject(), doc);
   Document controlDoc = xmlParser.parse(new StringReader(ECHO_LONG_RESULT));
   assertTrue(
       "Expected:\n" + documentToString(controlDoc) + "\nActual:\n" + documentToString(doc),
       comparer.isNodeEqual(controlDoc, doc));
 }
Пример #14
0
 @Test
 public void fEchoNchar() {
   Invocation invocation = new Invocation("fEchoNchar");
   invocation.setParameter("p_nchar", "N'q'");
   Operation op = xrService.getOperation(invocation.getName());
   Object result = op.invoke(xrService, invocation);
   assertNotNull("result is null", result);
   Document doc = xmlPlatform.createDocument();
   XMLMarshaller marshaller = xrService.getXMLContext().createMarshaller();
   marshaller.marshal(result, doc);
   Document controlDoc = xmlParser.parse(new StringReader(F_ECHO_NCHAR_RESULT));
   assertTrue(
       "control document not same as instance document.  Expected "
           + documentToString(controlDoc)
           + " but was "
           + documentToString(doc),
       comparer.isNodeEqual(controlDoc, doc));
 }
 @SuppressWarnings({"unchecked", "rawtypes"})
 @Test
 public void findAll() {
   Invocation invocation = new Invocation("findAll_inlinebinaryType");
   Operation op = xrService.getOperation(invocation.getName());
   Object result = op.invoke(xrService, invocation);
   assertNotNull("result is null", result);
   XMLMarshaller marshaller = xrService.getXMLContext().createMarshaller();
   Document doc = xmlPlatform.createDocument();
   Element ec = doc.createElement("inlinebinary-collection");
   doc.appendChild(ec);
   for (Object r : (Vector) result) {
     marshaller.marshal(r, ec);
   }
   Document controlDoc = xmlParser.parse(new StringReader(INLINEBINARY_COLLECTION_XML));
   assertTrue(
       "control document not same as instance document", comparer.isNodeEqual(controlDoc, doc));
 }
Пример #16
0
 @Test
 public void echoNumber() {
   Invocation invocation = new Invocation("echoNumber");
   invocation.setParameter("PNUMBER", BigDecimal.valueOf(17));
   Operation op = xrService.getOperation(invocation.getName());
   Object result = op.invoke(xrService, invocation);
   assertNotNull("result is null", result);
   Document doc = xmlPlatform.createDocument();
   XMLMarshaller marshaller = xrService.getXMLContext().createMarshaller();
   marshaller.marshal(result, doc);
   Document controlDoc = xmlParser.parse(new StringReader(ECHO_NUMBER_RESULT));
   assertTrue(
       "Control document not same as instance document.\nExpected:\n"
           + documentToString(controlDoc)
           + "\nActual:\n"
           + documentToString(doc),
       comparer.isNodeEqual(controlDoc, doc));
 }
Пример #17
0
 @Test
 public void echoBooleanFalse2() {
   Invocation invocation = new Invocation("echoBoolean2");
   invocation.setParameter("P1", 0);
   Operation op = xrService.getOperation(invocation.getName());
   Object result = op.invoke(xrService, invocation);
   assertNotNull("result is null", result);
   Document doc = xmlPlatform.createDocument();
   XMLMarshaller marshaller = xrService.getXMLContext().createMarshaller();
   marshaller.marshal(result, doc);
   Document controlDoc = xmlParser.parse(new StringReader(ECHO_BOOLEAN_RESULT2));
   assertTrue(
       "control document not same as instance document:  expected "
           + documentToString(controlDoc)
           + " but was "
           + documentToString(doc),
       comparer.isNodeEqual(controlDoc, doc));
 }
  private void save(XMLDocument xmlDocument, Writer outputWriter, XMLMarshaller anXMLMarshaller)
      throws IOException {
    if (xmlDocument == null) {
      throw new IllegalArgumentException(
          SDOException.cannotPerformOperationWithNullInputParameter("save", "xmlDocument"));
    }

    // Ask the SDOXMLDocument if we should include the XML declaration in the resulting XML
    anXMLMarshaller.setFragment(!xmlDocument.isXMLDeclaration());

    anXMLMarshaller.setEncoding(xmlDocument.getEncoding());
    anXMLMarshaller.setSchemaLocation(xmlDocument.getSchemaLocation());
    anXMLMarshaller.setNoNamespaceSchemaLocation(xmlDocument.getNoNamespaceSchemaLocation());

    WriterRecord writerRecord;
    if (anXMLMarshaller.isFormattedOutput()) {
      writerRecord = new FormattedWriterRecord();
    } else {
      writerRecord = new WriterRecord();
    }
    writerRecord.setWriter(outputWriter);
    writerRecord.setMarshaller(anXMLMarshaller);

    ((SDOMarshalListener) anXMLMarshaller.getMarshalListener())
        .setMarshalledObject(xmlDocument.getRootObject());
    ((SDOMarshalListener) anXMLMarshaller.getMarshalListener())
        .setMarshalledObjectRootQName(
            new QName(xmlDocument.getRootElementURI(), xmlDocument.getRootElementName()));
    ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()).setRootMarshalRecord(writerRecord);

    try {
      anXMLMarshaller.marshal(xmlDocument, writerRecord);
    } catch (XMLMarshalException xme) {
      if (xme.getErrorCode() == XMLMarshalException.DESCRIPTOR_NOT_FOUND_IN_PROJECT) {
        if (aHelperContext
            != ((SDOType) xmlDocument.getRootObject().getType()).getHelperContext()) {
          throw SDOException.dataObjectNotFromHelperContext();
        }
      }
    }
    outputWriter.flush();
  }
  /**
   * INTERNAL: Saves the DataObject as an XML document with the specified root element. Same as
   * save(createDocument(dataObject, rootElementURI, rootElementName), writer, null);
   *
   * @param dataObject specifies DataObject to be saved
   * @param rootElementURI the Target Namespace URI of the root XML element
   * @param rootElementName the Name of the root XML element
   * @param writer specifies the Writer to write to.
   * @throws IOException for stream exceptions.
   * @throws IllegalArgumentException if the dataObject tree is not closed or has no container.
   */
  private void save(
      DataObject rootObject,
      String rootElementURI,
      String rootElementName,
      Writer writer,
      XMLMarshaller anXMLMarshaller)
      throws XMLMarshalException {
    SDOXMLDocument xmlDocument =
        (SDOXMLDocument) createDocument(rootObject, rootElementURI, rootElementName);

    // Ask the SDOXMLDocument if we should include the XML declaration in the resulting XML
    anXMLMarshaller.setFragment(!xmlDocument.isXMLDeclaration());
    WriterRecord writerRecord;
    if (anXMLMarshaller.isFormattedOutput()) {
      writerRecord = new FormattedWriterRecord();
    } else {
      writerRecord = new WriterRecord();
    }
    writerRecord.setWriter(writer);
    writerRecord.setMarshaller(anXMLMarshaller);

    ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()).setMarshalledObject(rootObject);
    ((SDOMarshalListener) anXMLMarshaller.getMarshalListener())
        .setMarshalledObjectRootQName(new QName(rootElementURI, rootElementName));
    ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()).setRootMarshalRecord(writerRecord);

    try {
      anXMLMarshaller.marshal(xmlDocument, writerRecord);
    } catch (XMLMarshalException xme) {
      if (xme.getErrorCode() == XMLMarshalException.DESCRIPTOR_NOT_FOUND_IN_PROJECT) {
        if (aHelperContext != ((SDOType) rootObject.getType()).getHelperContext()) {
          throw SDOException.dataObjectNotFromHelperContext();
        }
      }
    }

    try {
      writer.flush();
    } catch (IOException ex) {
      throw XMLMarshalException.marshalException(ex);
    }
  }
Пример #20
0
 @Test
 public void selectXMLData() throws ParseException {
   Invocation invocation = new Invocation("selectXMLData");
   Operation op = xrService.getOperation(invocation.getName());
   Object result = null;
   try {
     result = op.invoke(xrService, invocation);
   } catch (NoClassDefFoundError ncdfex) {
     fail(
         "Test failed unexpectedly.  Please make sure that Oracle's XDB and XMLParser jars are on the test classpath.\nException:\n"
             + ncdfex);
   }
   assertNotNull("result is null", result);
   Document doc = xmlPlatform.createDocument();
   XMLMarshaller marshaller = xrService.getXMLContext().createMarshaller();
   marshaller.marshal(((XMLRoot) result).getObject(), doc);
   Document controlDoc = xmlParser.parse(new StringReader(XMLTYPE_XML_2));
   assertTrue(
       "Expected:\n" + documentToString(controlDoc) + "\nActual:\n" + documentToString(doc),
       comparer.isNodeEqual(controlDoc, doc));
 }