public void testRead() throws Exception {
    InputStream carStream =
        getClass()
            .getClassLoader()
            .getResourceAsStream("org/eclipse/persistence/testing/oxm/inheritance/car.xml");
    Object car = unmarshaller.unmarshal(carStream);
    assertTrue("Wrong object returned for subclass", car instanceof Car);

    InputStream vehicleStream =
        getClass()
            .getClassLoader()
            .getResourceAsStream("org/eclipse/persistence/testing/oxm/inheritance/vehicle.xml");
    Object vehicle = unmarshaller.unmarshal(vehicleStream);
    assertTrue("Wrong object returned for superclass", vehicle.getClass().equals(Vehicle.class));
  }
 public void testReadMailingAddress() {
   try {
     InputStream inputStream = ClassLoader.getSystemResourceAsStream(XML_RESOURCE_MAILING);
     MailingAddress testObject = (MailingAddress) unmarshaller.unmarshal(inputStream);
   } catch (ClassCastException e) {
     fail();
   }
 }
 public void testReadBillingAddress() {
   try {
     InputStream inputStream = ClassLoader.getSystemResourceAsStream(XML_RESOURCE_BILLING);
     Object testObject = unmarshaller.unmarshal(inputStream);
     fail();
   } catch (XMLMarshalException e) {
     // PASS - an XMLMarshalException should be caught
   }
 }
 @Test
 public void checkWSDL() throws WSDLException {
   DBWS_BUILDER_XML_USERNAME =
       "******"1.0\" encoding=\"UTF-8\"?>"
           + "<dbws-builder xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">"
           + "<properties>"
           + "<property name=\"projectName\">simpletable2</property>"
           + "<property name=\"logLevel\">off</property>"
           + "<property name=\"username\">";
   DBWS_BUILDER_XML_PASSWORD = "******"password\">";
   DBWS_BUILDER_XML_URL = "</property><property name=\"url\">";
   DBWS_BUILDER_XML_DRIVER = "</property><property name=\"driver\">";
   DBWS_BUILDER_XML_PLATFORM = "</property><property name=\"platformClassname\">";
   DBWS_BUILDER_XML_MAIN =
       "</property>"
           + "</properties>"
           + "<table "
           + "schemaPattern=\"%\" "
           + "tableNamePattern=\"simpletable2\" "
           + ">"
           + "<sql "
           + "name=\"findByName\" "
           + "isCollection=\"true\" "
           + "returnType=\"simpletable2Type\" "
           + ">"
           + "<text><![CDATA[select * from SIMPLETABLE2 where NAME like ?]]></text>"
           + "<binding name=\"NAME\" type=\"xsd:string\"/>"
           + "</sql>"
           + "</table>"
           + "</dbws-builder>";
   String username = System.getProperty(DATABASE_USERNAME_KEY, DEFAULT_DATABASE_USERNAME);
   String password = System.getProperty(DATABASE_PASSWORD_KEY, DEFAULT_DATABASE_PASSWORD);
   String url = System.getProperty(DATABASE_URL_KEY, DEFAULT_DATABASE_URL);
   String builderString =
       DBWS_BUILDER_XML_USERNAME
           + username
           + DBWS_BUILDER_XML_PASSWORD
           + password
           + DBWS_BUILDER_XML_URL
           + url
           + DBWS_BUILDER_XML_DRIVER
           + DATABASE_DRIVER
           + DBWS_BUILDER_XML_PLATFORM
           + DATABASE_PLATFORM
           + DBWS_BUILDER_XML_MAIN;
   XMLContext context = new XMLContext(new DBWSBuilderModelProject());
   XMLUnmarshaller unmarshaller = context.createUnmarshaller();
   DBWSBuilderModel builderModel =
       (DBWSBuilderModel) unmarshaller.unmarshal(new StringReader(builderString));
   DBWSBuilder builder = new DBWSBuilder();
   builder.quiet = true;
   // builder.setLogLevel(SessionLog.FINE_LABEL);
   builder.setLogLevel(SessionLog.OFF_LABEL);
   builder.setPlatformClassname(DATABASE_PLATFORM);
   builder.properties = builderModel.properties;
   builder.getProperties().put(SESSIONS_FILENAME_KEY, NO_SESSIONS_FILENAME);
   builder.operations = builderModel.operations;
   builder.setPackager(
       new JSR109WebServicePackager(null, "WebServiceTestPackager", noArchive) {
         @Override
         public void start() {
           // do nothing - don't have to verify existence of 'stageDir' when
           // all the streams are in-memory
         }
       });
   ByteArrayOutputStream dbwsServiceStream = new ByteArrayOutputStream();
   ByteArrayOutputStream wsdlStream = new ByteArrayOutputStream();
   builder.build(
       __nullStream,
       __nullStream,
       dbwsServiceStream,
       __nullStream,
       __nullStream,
       __nullStream,
       __nullStream,
       wsdlStream,
       __nullStream,
       __nullStream,
       __nullStream,
       __nullStream,
       null);
   // verify that the generated WSDL has the correct response type
   // for the nested sql operation 'findByName'
   try {
     StringWriter sw = new StringWriter();
     StreamSource wsdlStreamSource = new StreamSource(new StringReader(wsdlStream.toString()));
     Transformer t =
         TransformerFactory.newInstance()
             .newTransformer(new StreamSource(new StringReader(MATCH_SCHEMA)));
     StreamResult streamResult = new StreamResult(sw);
     t.transform(wsdlStreamSource, streamResult);
     sw.toString();
     SchemaModelProject schemaProject = new SchemaModelProject();
     XMLContext xmlContext2 = new XMLContext(schemaProject);
     unmarshaller = xmlContext2.createUnmarshaller();
     Schema schema = (Schema) unmarshaller.unmarshal(new StringReader(sw.toString()));
     ComplexType findByNameResponseType =
         (ComplexType) schema.getTopLevelComplexTypes().get(FINDBYNAME_RESPONSETYPE);
     Element result = (Element) findByNameResponseType.getSequence().getElements().get(0);
     Element unnamed = (Element) result.getComplexType().getSequence().getElements().get(0);
     assertTrue(
         "wrong refType for " + FINDBYNAME_RESPONSETYPE, TABLE_ALIAS.equals(unnamed.getRef()));
   } catch (Exception e) {
     fail(e.getMessage());
   }
 }
  public XMLDocument load(Source source, String locationURI, Object options) throws IOException {
    // get XMLUnmarshaller once - as we may create a new instance if this helper isDirty=true
    XMLUnmarshaller anXMLUnmarshaller = getXmlUnmarshaller(options);
    Object unmarshalledObject = null;
    if (options == null) {
      try {
        unmarshalledObject = anXMLUnmarshaller.unmarshal(source);
      } catch (XMLMarshalException xmlException) {
        handleXMLMarshalException(xmlException);
      }
    } else {
      try {
        DataObject optionsDataObject = (DataObject) options;
        try {
          SDOType theType = (SDOType) optionsDataObject.get(SDOConstants.TYPE_LOAD_OPTION);
          try {
            if (theType != null) {
              unmarshalledObject = anXMLUnmarshaller.unmarshal(source, theType.getImplClass());
            } else {
              unmarshalledObject = anXMLUnmarshaller.unmarshal(source);
            }
          } catch (XMLMarshalException xmlException) {
            handleXMLMarshalException(xmlException);
          }
        } catch (ClassCastException ccException) {
          throw SDOException.typePropertyMustBeAType(ccException);
        }
      } catch (ClassCastException ccException) {
        throw SDOException.optionsMustBeADataObject(
            ccException, SDOConstants.ORACLE_SDO_URL, SDOConstants.XMLHELPER_LOAD_OPTIONS);
      }
    }

    if (unmarshalledObject instanceof XMLRoot) {
      XMLRoot xmlRoot = (XMLRoot) unmarshalledObject;
      XMLDocument xmlDocument =
          createDocument(
              (DataObject) ((XMLRoot) unmarshalledObject).getObject(),
              ((XMLRoot) unmarshalledObject).getNamespaceURI(),
              ((XMLRoot) unmarshalledObject).getLocalName());
      if (xmlRoot.getEncoding() != null) {
        xmlDocument.setEncoding(xmlRoot.getEncoding());
      }
      if (xmlRoot.getXMLVersion() != null) {
        xmlDocument.setXMLVersion(xmlRoot.getXMLVersion());
      }
      xmlDocument.setSchemaLocation(xmlRoot.getSchemaLocation());
      xmlDocument.setNoNamespaceSchemaLocation(xmlRoot.getNoNamespaceSchemaLocation());
      return xmlDocument;
    } else if (unmarshalledObject instanceof DataObject) {
      DataObject unmarshalledDataObject = (DataObject) unmarshalledObject;
      String localName =
          ((SDOType) ((DataObject) unmarshalledObject).getType())
              .getXmlDescriptor()
              .getDefaultRootElement();
      if (localName == null) {
        localName = ((SDOType) ((DataObject) unmarshalledObject).getType()).getXsdLocalName();
      }
      return createDocument(
          unmarshalledDataObject, unmarshalledDataObject.getType().getURI(), localName);
    } else if (unmarshalledObject instanceof XMLDocument) {
      return (XMLDocument) unmarshalledObject;
    }
    return null;
  }