public AttachmentMarshaller getAttachmentMarshaller() {
   if (xmlMarshaller.getAttachmentMarshaller() == null) {
     return null;
   }
   return ((AttachmentMarshallerAdapter) xmlMarshaller.getAttachmentMarshaller())
       .getAttachmentMarshaller();
 }
 public void setAttachmentMarshaller(AttachmentMarshaller attachmentMarshaller) {
   if (attachmentMarshaller == null) {
     xmlMarshaller.setAttachmentMarshaller(null);
   } else {
     xmlMarshaller.setAttachmentMarshaller(new AttachmentMarshallerAdapter(attachmentMarshaller));
   }
 }
コード例 #3
0
  /**
   * 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);
    }
  }
コード例 #4
0
  public void testWrite() throws Exception {
    Car car = new Car();
    car.numberOfDoors = 2;
    car.milesPerGallon = 30;
    car.model = "Grand Am";
    car.manufacturer = "Pontiac";
    car.topSpeed = 220;

    Document carDocument = marshaller.objectToXML(car);
    Element root =
        (Element) carDocument.getElementsByTagNameNS("mynamespaceuri", "vehicle").item(0);
    Attr elem = root.getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "type");
    String carType = elem.getNodeValue();
    assertTrue(
        "The type field was written incorrectly for the subclass",
        carType.equals("prefix:car-type"));

    Vehicle vehicle = new Vehicle();
    vehicle.model = "Blah Blah";
    vehicle.manufacturer = "Some Place";
    vehicle.topSpeed = 10000;

    Document vehicleDocument = marshaller.objectToXML(vehicle);
    root = (Element) vehicleDocument.getElementsByTagNameNS("mynamespaceuri", "vehicle").item(0);
    elem = root.getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "type");
    String vehicleType = elem.getNodeValue();
    assertTrue(
        "The type field was written incorrectly for the superclass",
        vehicleType.equals("prefix:vehicle-type"));
  }
 /**
  * This constructor initializes various settings on the XML marshaller, and stores the provided
  * JAXBIntrospector instance for usage in marshal() calls.
  *
  * @param newXMLMarshaller
  * @param newIntrospector
  */
 public JAXBMarshaller(XMLMarshaller newXMLMarshaller, JAXBIntrospector newIntrospector) {
   super();
   validationEventHandler = JAXBContext.DEFAULT_VALIDATION_EVENT_HANDER;
   xmlMarshaller = newXMLMarshaller;
   xmlMarshaller.setEncoding("UTF-8");
   xmlMarshaller.setFormattedOutput(false);
   xmlMarshaller.getProperties().put(Constants.JAXB_MARSHALLER, this);
 }
 public void setAdapter(Class javaClass, XmlAdapter adapter) {
   HashMap result = (HashMap) xmlMarshaller.getProperty(XML_JAVATYPE_ADAPTERS);
   if (result == null) {
     result = new HashMap();
     xmlMarshaller.getProperties().put(XML_JAVATYPE_ADAPTERS, result);
   }
   result.put(javaClass, adapter);
 }
コード例 #7
0
 public void serialize(XMLDocument xmlDocument, OutputStream outputStream, Object options)
     throws IOException {
   OutputStreamWriter writer =
       new OutputStreamWriter(outputStream, getXmlMarshaller().getEncoding());
   XMLMarshaller xmlMarshaller = getXmlContext().createMarshaller();
   xmlMarshaller.setMarshalListener(
       new SDOMarshalListener(xmlMarshaller, (SDOTypeHelper) aHelperContext.getTypeHelper()));
   save(xmlDocument, writer, xmlMarshaller);
 }
コード例 #8
0
 public void serialize(XMLDocument xmlDocument, OutputStream outputStream, Object options)
     throws IOException {
   XMLMarshaller xmlMarshaller = getXmlMarshaller();
   XMLAttachmentMarshaller attachmentMarshaller = xmlMarshaller.getAttachmentMarshaller();
   // temporarily null out the attachment marshaller as it should not be used during serialization
   xmlMarshaller.setAttachmentMarshaller(null);
   OutputStreamWriter writer = new OutputStreamWriter(outputStream, xmlMarshaller.getEncoding());
   save(xmlDocument, writer, xmlMarshaller);
   xmlMarshaller.setAttachmentMarshaller(attachmentMarshaller);
 }
コード例 #9
0
 /**
  * Saves the DataObject as an XML document with the specified root element. Same as
  * save(createDocument(dataObject, rootElementURI, rootElementName), outputStream, 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 outputStream specifies the OutputStream to write to.
  * @throws IOException for stream exceptions.
  * @throws IllegalArgumentException if the dataObject tree is not closed or has no container.
  */
 public void save(
     DataObject dataObject,
     String rootElementURI,
     String rootElementName,
     OutputStream outputStream)
     throws XMLMarshalException, IOException {
   XMLMarshaller xmlMarshaller = getXmlMarshaller(null);
   OutputStreamWriter writer = new OutputStreamWriter(outputStream, xmlMarshaller.getEncoding());
   save(dataObject, rootElementURI, rootElementName, writer, xmlMarshaller);
 }
 public void setMarshalCallbacks(java.util.HashMap callbacks) {
   if (callbacks == null || callbacks.isEmpty()) {
     return;
   }
   if (xmlMarshaller.getMarshalListener() == null) {
     xmlMarshaller.setMarshalListener(new JAXBMarshalListener(jaxbContext, this));
   }
   ((JAXBMarshalListener) xmlMarshaller.getMarshalListener())
       .setClassBasedMarshalEvents(callbacks);
 }
コード例 #11
0
  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();
  }
コード例 #12
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));
 }
コード例 #13
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));
 }
コード例 #14
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));
 }
コード例 #15
0
 /**
  * Serializes an XMLDocument as an XML document into the outputStream. If the DataObject's Type
  * was defined by an XSD, the serialization will follow the XSD. Otherwise the serialization will
  * follow the format as if an XSD were generated as defined by the SDO specification. The
  * OutputStream will be flushed after writing. Does not perform validation to ensure compliance
  * with an XSD.
  *
  * @param xmlDocument specifies XMLDocument to be saved
  * @param outputStream specifies the OutputStream to write to.
  * @param options implementation-specific options.
  * @throws IOException for stream exceptions.
  * @throws IllegalArgumentException if the dataObject tree is not closed or has no container.
  */
 public void save(XMLDocument xmlDocument, OutputStream outputStream, Object options)
     throws IOException {
   if (xmlDocument == null) {
     throw new IllegalArgumentException(
         SDOException.cannotPerformOperationWithNullInputParameter("save", "xmlDocument"));
   }
   XMLMarshaller xmlMarshaller = getXmlMarshaller(options);
   String encoding = xmlMarshaller.getEncoding();
   if (xmlDocument.getEncoding() != null) {
     encoding = xmlDocument.getEncoding();
   }
   OutputStreamWriter writer = new OutputStreamWriter(outputStream, encoding);
   save(xmlDocument, writer, xmlMarshaller);
 }
コード例 #16
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));
 }
コード例 #17
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));
 }
コード例 #18
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));
 }
コード例 #19
0
  public XMLMarshaller getXmlMarshaller() {
    XMLMarshaller marshaller = xmlMarshallerMap.get(Thread.currentThread());

    if (marshaller == null) {
      marshaller = getXmlContext().createMarshaller();
      marshaller.setMarshalListener(
          new SDOMarshalListener(marshaller, (SDOTypeHelper) aHelperContext.getTypeHelper()));
      xmlMarshallerMap.put(Thread.currentThread(), marshaller);
    }

    XMLContext context = getXmlContext();
    if (marshaller.getXMLContext() != context) {
      marshaller.setXMLContext(context);
    }
    return marshaller;
  }
 public XmlAdapter getAdapter(Class javaClass) {
   HashMap result = (HashMap) xmlMarshaller.getProperty(XML_JAVATYPE_ADAPTERS);
   if (result == null) {
     return null;
   }
   return (XmlAdapter) result.get(javaClass);
 }
コード例 #21
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));
 }
コード例 #22
0
 @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));
 }
 public void setEventHandler(ValidationEventHandler newValidationEventHandler)
     throws JAXBException {
   if (null == newValidationEventHandler) {
     validationEventHandler = JAXBContext.DEFAULT_VALIDATION_EVENT_HANDER;
   } else {
     validationEventHandler = newValidationEventHandler;
   }
   xmlMarshaller.setErrorHandler(new JAXBErrorHandler(validationEventHandler));
 }
コード例 #24
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));
 }
コード例 #25
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));
 }
コード例 #26
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));
 }
コード例 #27
0
 private XMLMarshaller getXmlMarshaller(Object options) {
   XMLMarshaller xmlMarshaller = getXmlMarshaller().clone();
   if (null == options) {
     return xmlMarshaller;
   }
   try {
     DataObject optionsDO = (DataObject) options;
     if (optionsDO.isSet(SDOConstants.ATTACHMENT_MARSHALLER_OPTION)) {
       xmlMarshaller.setAttachmentMarshaller(
           (XMLAttachmentMarshaller) optionsDO.get(SDOConstants.ATTACHMENT_MARSHALLER_OPTION));
     }
     xmlMarshaller.setMarshalListener(
         new SDOMarshalListener(xmlMarshaller, (SDOTypeHelper) aHelperContext.getTypeHelper()));
     return xmlMarshaller;
   } catch (ClassCastException ccException) {
     throw SDOException.optionsMustBeADataObject(
         ccException, SDOConstants.ORACLE_SDO_URL, SDOConstants.XMLHELPER_LOAD_OPTIONS);
   }
 }
コード例 #28
0
  /**
   * 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);
    }
  }
 private Object wrapEnumeration(Object object, Class enumerationClass) {
   Class generatedClass = this.getClassToGeneratedClasses().get(enumerationClass.getName());
   if (generatedClass != null && WrappedValue.class.isAssignableFrom(generatedClass)) {
     ClassDescriptor desc =
         xmlMarshaller.getXMLContext().getSession(generatedClass).getDescriptor(generatedClass);
     Object newObject = desc.getInstantiationPolicy().buildNewInstance();
     ((WrappedValue) newObject).setValue(object);
     object = newObject;
   }
   return object;
 }
  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);
    }
  }