public void testFailOnSecondErrorNodeWithClass() throws Exception {
   unmarshaller.setEventHandler(new CustomErrorValidationEventHandler());
   InputStream stream = ClassLoader.getSystemResourceAsStream(DOUBLE_ERROR_XML);
   XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
   XMLParser xmlParser = xmlPlatform.newXMLParser();
   xmlParser.setNamespaceAware(true);
   Node node = xmlParser.parse(stream);
   try {
     unmarshaller.setSchema(this.schema);
     unmarshaller.unmarshal(node, Employee.class);
   } catch (UnmarshalException ex) {
     assertTrue(true);
     return;
   } catch (UnsupportedOperationException uoe) {
     // XDK does not support setSchema, so just pass in this case
     assertTrue(true);
     return;
   }
   fail("No Exceptions thrown.");
 }
  public void testDeploymentXmlConversion() {
    XMLProjectReader reader = new XMLProjectReader();
    XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
    XMLParser parser = xmlPlatform.newXMLParser();
    InputStream stream =
        ClassLoader.getSystemResourceAsStream(
            "org/eclipse/persistence/testing/oxm/deploymentxml/db-adapter-toplink-mapping-file.xml");
    Project proj = reader.read(new InputStreamReader(stream));

    StringWriter writer = new StringWriter();
    new XMLProjectWriter().write(proj, writer);

    parser.setNamespaceAware(true);
    parser.setWhitespacePreserving(false);
    String schema = XMLProjectReader.SCHEMA_DIR + XMLProjectReader.ECLIPSELINK_SCHEMA;
    parser.setValidationMode(XMLParser.SCHEMA_VALIDATION);
    URL eclipselinkSchemaURL = getClass().getClassLoader().getResource(schema);
    parser.setEntityResolver(
        new EntityResolver() {

          public InputSource resolveEntity(String publicId, String systemId)
              throws SAXException, IOException {
            if (XMLProjectReader.OPM_SCHEMA.equals(systemId)) {
              URL url =
                  getClass()
                      .getClassLoader()
                      .getResource(XMLProjectReader.SCHEMA_DIR + XMLProjectReader.OPM_SCHEMA);
              if (null == url) {
                return null;
              }
              return new InputSource(url.openStream());
            }
            return null;
          }
        });
    parser.setXMLSchema(eclipselinkSchemaURL);
    parser.parse(new StringReader(writer.toString()));
  }
@WebServiceProvider(
    targetNamespace = OPTLOCK_SERVICE_NAMESPACE,
    serviceName = OPTLOCK_SERVICE,
    portName = OPTLOCK_PORT)
@ServiceMode(MESSAGE)
public class OptLockTestSuite extends ProviderHelper implements Provider<SOAPMessage> {

  static final String CREATE_OPTLOCK_TABLE =
      "CREATE TABLE IF NOT EXISTS optlock ("
          + "\nID NUMERIC NOT NULL,"
          + "\nNAME VARCHAR(25),"
          + "\nDESCRIPT VARCHAR(20),"
          + "\nVERSION NUMERIC,"
          + "\nPRIMARY KEY (ID)"
          + "\n)";
  static final String[] POPULATE_OPTLOCK_TABLE =
      new String[] {
        "insert into optlock (ID, NAME, DESCRIPT, VERSION) values (1, 'name', 'this is ver 3', 3)"
      };
  static final String DROP_OPTLOCK_TABLE = "DROP TABLE optlock";

  static final String ENDPOINT_ADDRESS = "http://localhost:9999/" + OPTLOCK_TEST;

  // JUnit test fixtures
  static Connection conn = null;
  static ByteArrayOutputStream DBWS_SERVICE_STREAM = new ByteArrayOutputStream();
  static ByteArrayOutputStream DBWS_SCHEMA_STREAM = new ByteArrayOutputStream();
  static ByteArrayOutputStream DBWS_OR_STREAM = new ByteArrayOutputStream();
  static ByteArrayOutputStream DBWS_OX_STREAM = new ByteArrayOutputStream();
  static ByteArrayOutputStream DBWS_WSDL_STREAM = new ByteArrayOutputStream();
  static XMLComparer comparer = new XMLComparer();
  static XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
  static XMLParser xmlParser = xmlPlatform.newXMLParser();
  static Endpoint endpoint = null;
  static QName portQName = null;
  static Service testService = null;
  static DBWSBuilder builder = new DBWSBuilder();
  static final String username =
      System.getProperty(DATABASE_USERNAME_KEY, DEFAULT_DATABASE_USERNAME);
  static final String password =
      System.getProperty(DATABASE_PASSWORD_KEY, DEFAULT_DATABASE_PASSWORD);
  static final String url = System.getProperty(DATABASE_URL_KEY, DEFAULT_DATABASE_URL);

  static boolean ddlCreate = false;
  static boolean ddlDrop = false;
  static boolean ddlDebug = false;

  @BeforeClass
  public static void setUp() throws WSDLException {
    try {
      conn = buildConnection();
    } catch (Exception e) {
      e.printStackTrace();
    }
    String ddlCreateProp = System.getProperty(DATABASE_DDL_CREATE_KEY, DEFAULT_DATABASE_DDL_CREATE);
    if ("true".equalsIgnoreCase(ddlCreateProp)) {
      ddlCreate = true;
    }
    String ddlDropProp = System.getProperty(DATABASE_DDL_DROP_KEY, DEFAULT_DATABASE_DDL_DROP);
    if ("true".equalsIgnoreCase(ddlDropProp)) {
      ddlDrop = true;
    }
    String ddlDebugProp = System.getProperty(DATABASE_DDL_DEBUG_KEY, DEFAULT_DATABASE_DDL_DEBUG);
    if ("true".equalsIgnoreCase(ddlDebugProp)) {
      ddlDebug = true;
    }
    if (ddlCreate) {
      runDdl(conn, CREATE_OPTLOCK_TABLE, ddlDebug);
      try {
        Statement stmt = conn.createStatement();
        for (int i = 0; i < POPULATE_OPTLOCK_TABLE.length; i++) {
          stmt.addBatch(POPULATE_OPTLOCK_TABLE[i]);
        }
        stmt.executeBatch();
      } catch (SQLException e) {
        if (ddlDebug) {
          e.printStackTrace();
        }
      }
    }
    builder.setProjectName(OPTLOCK_TEST);
    builder.setTargetNamespace(OPTLOCK_NAMESPACE);
    TableOperationModel tModel = new TableOperationModel();
    tModel.setName(OPTLOCK);
    tModel.setTablePattern(OPTLOCK);
    builder.getOperations().add(tModel);
    builder.quiet = true;
    // builder.setLogLevel(SessionLog.FINE_LABEL);
    builder.setLogLevel(SessionLog.OFF_LABEL);
    builder.setDriver(DATABASE_DRIVER);
    builder.setPlatformClassname(DATABASE_PLATFORM);
    builder.getProperties().put(SESSIONS_FILENAME_KEY, NO_SESSIONS_FILENAME);
    builder.setUsername(username);
    builder.setPassword(password);
    builder.setUrl(url);
    builder.setPackager(
        new JSR109WebServicePackager(null, "WebServiceTestPackager", noArchive) {
          @Override
          public void start() {}
        });
    builder.build(
        DBWS_SCHEMA_STREAM,
        __nullStream,
        DBWS_SERVICE_STREAM,
        DBWS_OR_STREAM,
        DBWS_OX_STREAM,
        __nullStream,
        __nullStream,
        DBWS_WSDL_STREAM,
        __nullStream,
        __nullStream,
        __nullStream,
        __nullStream,
        null);
    endpoint = Endpoint.create(new OptLockTestSuite());
    endpoint.publish(ENDPOINT_ADDRESS);
    QName serviceQName = new QName(OPTLOCK_SERVICE_NAMESPACE, OPTLOCK_SERVICE);
    portQName = new QName(OPTLOCK_SERVICE_NAMESPACE, OPTLOCK_PORT);
    testService = Service.create(serviceQName);
    testService.addPort(portQName, SOAP11HTTP_BINDING, ENDPOINT_ADDRESS);
  }

  @AfterClass
  public static void teardown() {
    if (endpoint != null) {
      endpoint.stop();
    }
    if (ddlDrop) {
      runDdl(conn, DROP_OPTLOCK_TABLE, ddlDebug);
    }
  }

  @PreDestroy
  public void destroy() {
    super.destroy();
  }

  @Override
  protected InputStream initXRServiceStream(ClassLoader parentClassLoader, ServletContext sc) {
    return new ByteArrayInputStream(DBWS_SERVICE_STREAM.toByteArray());
  }

  @Override
  protected InputStream initXRSchemaStream(ClassLoader parentClassLoader, ServletContext sc) {
    return new ByteArrayInputStream(DBWS_SCHEMA_STREAM.toByteArray());
  }

  @Override
  protected InputStream initWSDLInputStream(ClassLoader parentClassLoader, ServletContext sc) {
    return new ByteArrayInputStream(DBWS_WSDL_STREAM.toByteArray());
  }

  @PostConstruct
  public void init() {
    super.init(
        new XRDynamicClassLoader(Thread.currentThread().getContextClassLoader()), null, false);
  }

  @Override
  public void logoutSessions() {
    if (xrService.getORSession() != null) {
      ((DatabaseSession) xrService.getORSession()).logout();
    }
    if (xrService.getOXSession() != null) {
      ((DatabaseSession) xrService.getOXSession()).logout();
    }
  }

  @Override
  public void buildSessions() {
    XRDynamicClassLoader xrdecl = new XRDynamicClassLoader(parentClassLoader);
    DatasourceLogin login = new DatabaseLogin();
    login.setUserName(username);
    login.setPassword(password);
    ((DatabaseLogin) login).setConnectionString(url);
    ((DatabaseLogin) login).setDriverClassName(DATABASE_PLATFORM);
    Platform platform = builder.getDatabasePlatform();
    ConversionManager conversionManager = platform.getConversionManager();
    if (conversionManager != null) {
      conversionManager.setLoader(xrdecl);
    }
    login.setDatasourcePlatform(platform);
    ((DatabaseLogin) login).bindAllParameters();
    ((DatabaseLogin) login).setUsesStreamsForBinding(true);

    Project orProject = null;
    if (DBWS_OR_STREAM.size() != 0) {
      MetadataProcessor processor =
          new MetadataProcessor(
              new XRPersistenceUnitInfo(xrdecl),
              new DatabaseSessionImpl(login),
              xrdecl,
              false,
              true,
              false,
              false,
              false,
              null,
              null);
      processor.setMetadataSource(
          new JPAMetadataSource(xrdecl, new StringReader(DBWS_OR_STREAM.toString())));
      PersistenceUnitProcessor.processORMetadata(
          processor, true, PersistenceUnitProcessor.Mode.ALL);
      processor.addNamedQueries();
      orProject = processor.getProject().getProject();
    } else {
      orProject = new Project();
    }
    orProject.setName(builder.getProjectName().concat(OR_PRJ_SUFFIX));
    orProject.setDatasourceLogin(login);
    DatabaseSession databaseSession = orProject.createDatabaseSession();
    if ("off".equalsIgnoreCase(builder.getLogLevel())) {
      databaseSession.dontLogMessages();
    } else {
      databaseSession.setLogLevel(
          AbstractSessionLog.translateStringToLoggingLevel(builder.getLogLevel()));
    }
    xrService.setORSession(databaseSession);
    orProject.convertClassNamesToClasses(xrdecl);

    Project oxProject = null;
    Map<String, OXMMetadataSource> metadataMap = new HashMap<String, OXMMetadataSource>();
    StreamSource xml = new StreamSource(new StringReader(DBWS_OX_STREAM.toString()));
    try {
      JAXBContext jc = JAXBContext.newInstance(XmlBindingsModel.class);
      Unmarshaller unmarshaller = jc.createUnmarshaller();

      JAXBElement<XmlBindingsModel> jaxbElt = unmarshaller.unmarshal(xml, XmlBindingsModel.class);
      XmlBindingsModel model = jaxbElt.getValue();
      for (XmlBindings xmlBindings : model.getBindingsList()) {
        metadataMap.put(xmlBindings.getPackageName(), new OXMMetadataSource(xmlBindings));
      }
    } catch (JAXBException jaxbex) {
      jaxbex.printStackTrace();
    }

    Map<String, Map<String, OXMMetadataSource>> properties =
        new HashMap<String, Map<String, OXMMetadataSource>>();
    properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataMap);
    try {
      org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext jCtx =
          org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory.createContextFromOXM(
              parentClassLoader, properties);
      oxProject = jCtx.getXMLContext().getSession(0).getProject();
    } catch (JAXBException e) {
      e.printStackTrace();
    }
    ((XMLLogin) oxProject.getDatasourceLogin()).setPlatformClassName(DOM_PLATFORM_CLASSNAME);
    ((XMLLogin) oxProject.getDatasourceLogin()).setEqualNamespaceResolvers(false);

    prepareDescriptors(oxProject, orProject, xrdecl);
    ProjectHelper.fixOROXAccessors(orProject, oxProject);
    xrService.setORSession(databaseSession);
    xrService.setXMLContext(new XMLContext(oxProject));
    xrService.setOXSession(xrService.getXMLContext().getSession(0));
  }

  static final String THE_INSTANCE =
      "<optlockType>"
          + "<id>1</id>"
          + "<name>name</name>"
          + "<descript>this is ver 2</descript>"
          + "<version>1</version>"
          + "</optlockType>";

  static final String REQUEST_MSG =
      "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\" "
          + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
          + "<env:Header/>"
          + "<env:Body>"
          + "<srvc:update_OptlockType xmlns:srvc=\""
          + OPTLOCK_SERVICE_NAMESPACE
          + "\" "
          + "xmlns=\""
          + OPTLOCK_NAMESPACE
          + "\">"
          + "<srvc:theInstance>"
          + THE_INSTANCE
          + "</srvc:theInstance>"
          + "</srvc:update_OptlockType>"
          + "</env:Body>"
          + "</env:Envelope>";

  @Test
  public void updateinstanceTest()
      throws SOAPException, IOException, SAXException, ParserConfigurationException,
          TransformerException {
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage request = factory.createMessage();
    SOAPPart part = request.getSOAPPart();
    DOMSource domSource =
        new DOMSource(getDocumentBuilder().parse(new InputSource(new StringReader(REQUEST_MSG))));
    part.setContent(domSource);
    Dispatch<SOAPMessage> dispatch =
        testService.createDispatch(portQName, SOAPMessage.class, Service.Mode.MESSAGE);
    try {
      dispatch.invoke(request);
    } catch (SOAPFaultException sfe) {
      assertTrue("incorrect SOAPFaultException", sfe.getMessage().contains("EclipseLink-5010"));
    }
  }
}
Example #4
0
/**
 * <b>INTERNAL</b>: provides useful constants, SQL Column &lt;-&gt; to XML name mapping and a few
 * other misc. features
 *
 * @author Mike Norman - [email protected]
 * @since EclipseLink 1.x
 */
@SuppressWarnings("serial")
public class Util {
  public static final XMLPlatform XML_PLATFORM = XMLPlatformFactory.getInstance().getXMLPlatform();
  public static final Document TEMP_DOC = XML_PLATFORM.createDocument();
  public static final int OPAQUE = 2007;
  public static final String DEFAULT_ATTACHMENT_MIMETYPE = "application/octet-stream";
  public static final String WEB_INF_DIR = "WEB-INF/";
  public static final String WSDL_DIR = "wsdl/";
  public static final String[] META_INF_PATHS = {"META-INF/", "/META-INF/"};
  public static final String DBWS_SERVICE_XML = "eclipselink-dbws.xml";
  public static final String DBWS_OR_LABEL = "dbws-or";
  public static final String DBWS_OX_LABEL = "dbws-ox";
  public static final String DBWS_OR_XML = "eclipselink-" + DBWS_OR_LABEL + ".xml";
  public static final String DBWS_OX_XML = "eclipselink-" + DBWS_OX_LABEL + ".xml";
  public static final String DBWS_SCHEMA_XML = "eclipselink-dbws-schema.xsd";
  public static final String DBWS_WSDL = "eclipselink-dbws.wsdl";
  public static final String DBWS_SESSIONS_XML = "eclipselink-dbws-sessions.xml";
  public static final String DBWS_OR_SESSION_NAME_SUFFIX = DBWS_OR_LABEL + "-session";
  public static final String DBWS_OX_SESSION_NAME_SUFFIX = DBWS_OX_LABEL + "-session";
  public static final String TARGET_NAMESPACE_PREFIX = "ns1";
  public static final String SERVICE_NAMESPACE_PREFIX = "srvc";
  public static final String SERVICE_SUFFIX = "Service";
  public static final String ALL_QUERYNAME = "findAll";
  public static final String PK_QUERYNAME = "findByPrimaryKey";
  public static final String XMLTYPE_STR = "XMLTYPE";
  public static final String DOT_STR = ".";
  public static final String UNDERSCORE_STR = "_";
  public static final String TYPE_STR = "Type";
  public static final String COLLECTION_WRAPPER_STR = "CollectionWrapper";
  public static final String DASH_STR = "-";
  public static final String EMPTY_STR = "";
  public static final char COLON_CHAR = ':';
  public static final char SLASH_CHAR = '/';

  /**
   * Convert a SQL name to a valid XML name. Because not all characters that are valid in a SQL name
   * is valid in an XML name, they need to be escaped using a special format. See the Oracle
   * paper,"SQL/XML candidate base document", for more detail
   *
   * @param name the SQL name
   * @return the escaped valid XML name
   */
  public static String sqlToXmlName(String name) {

    int length = name.length();
    if (length == 0) {
      return name;
    }

    StringBuilder xmlName = new StringBuilder();
    int beginAt = 1;
    char firstChar = name.charAt(0);
    // escape : to _x003A_
    if (firstChar == ':') {
      xmlName.append("_x003A_");
    }
    // escape _ of _x to _x005F_
    else if ((length >= 2) && name.substring(0, 2).equals("_x")) {
      xmlName.append("_x005F_");
    }
    // check to see if it is a valid first character
    else {
      if ((firstChar >= 0xd800) && (firstChar < 0xdc00)) {
        // surrogate
        if (length > 1) {
          xmlName.append(hexEscape((firstChar << 16) | (name.charAt(1) & 0xffff)));
          beginAt = 2;
        } else {
          xmlName.append(hexEscape(firstChar));
        }
      } else if (isFirstNameChar(firstChar)) {
        xmlName.append(firstChar);
      } else {
        xmlName.append(hexEscape(firstChar));
      }
    }

    // check each following character to see if it is a valid NameChar
    char c;
    for (int x = beginAt; x < length; x++) {
      c = name.charAt(x);

      if ((c >= 0xd800) && (c < 0xdc00)) {
        // surrogate
        if ((x + 1) < length) {
          xmlName.append(hexEscape((c << 16) | (name.charAt(x + 1) & 0xffff)));
          x++;
        } else {
          xmlName.append(hexEscape(c));
        }
      } else if (!isNameChar(c)) {
        // escape
        xmlName.append(hexEscape(c));
      } else {
        xmlName.append(c);
      }
    }
    return xmlName.toString();
  }

  /**
   * Convert an escaped XML name back to the original SQL name
   *
   * @param name the escaped XML name
   * @return the original SQL name
   */
  public static String xmlToSqlName(String name) {

    String sqlName = "";
    int length = name.length();
    boolean unescapeMode = false;
    String hexString = null;
    char c;
    // step through each one
    for (int x = 0; x < length; x++) {
      c = name.charAt(x);
      if (unescapeMode) {
        // we are in unescape mode
        if (((c >= 'A') && (c <= 'F')) || ((c >= '0') && (c <= '9'))) {
          // gather the hex string from the escape sequence
          hexString = hexString + c;
        } else if (c == '_') {
          // done with escape mode
          unescapeMode = false;
          if (hexString != null) {
            int i;
            int len;
            if ((len = hexString.length()) > 4) {
              char i1 = (char) (Integer.parseInt(hexString.substring(0, len - 4), 16));
              char i2 = (char) (Integer.parseInt(hexString.substring(len - 4), 16));
              sqlName += i1;
              sqlName += i2;
            } else {
              try {
                i = Integer.parseInt(hexString, 16);
                if (i != 0xffff) {
                  sqlName += (char) i;
                }
              } catch (NumberFormatException nfe) {
                throw new RuntimeException(nfe);
              }
            }
          }
        } else {
          // invalid char in escape sequence! write everything into
          // sqlName as is, or we could throw an exception here
          // in the future
          sqlName += ("_x" + hexString + c);
          unescapeMode = false;
        }
      } else {
        if ((c == '_') && ((x + 1) < length) && (name.charAt(x + 1) == 'x')) {
          // found escape beginning _x
          // go into unescape mode
          unescapeMode = true;
          hexString = "";
          x++;
        } else {
          // just copy src char to destination
          sqlName += c;
        }
      }
    }
    return sqlName;
  }

  public static String hexEscape(char c) {
    String outPutString;
    outPutString = Integer.toHexString(c);
    switch (outPutString.length()) {
      case 1:
        outPutString = "_x000" + outPutString.toUpperCase(Locale.US) + "_";
        break;
      case 2:
        outPutString = "_x00" + outPutString.toUpperCase(Locale.US) + "_";
        break;
      case 3:
        outPutString = "_x0" + outPutString.toUpperCase(Locale.US) + "_";
        break;
      case 4:
        outPutString = "_x" + outPutString.toUpperCase(Locale.US) + "_";
        break;
    }
    return outPutString;
  }

  public static String hexEscape(int c) {
    String outPutString;
    outPutString = Integer.toHexString(c);
    switch (outPutString.length()) {
      case 1:
      case 5:
        outPutString = "_x000" + outPutString.toUpperCase(Locale.US) + "_";
        break;
      case 2:
      case 6:
        outPutString = "_x00" + outPutString.toUpperCase(Locale.US) + "_";
        break;
      case 3:
      case 7:
        outPutString = "_x0" + outPutString.toUpperCase(Locale.US) + "_";
        break;
      case 4:
      case 8:
        outPutString = "_x" + outPutString.toUpperCase(Locale.US) + "_";
        break;
    }
    return outPutString;
  }

  /**
   * return true if character can be part of a name
   *
   * @param c - char to be checked
   * @return true/false
   */
  public static boolean isNameChar(char c) {
    // In most cases the character is less than 256, so this check
    // is made fast. For the rest of the characters the check is
    // based on the conformance tests. XML 1.1 has changed the list
    // of chars allowed, and the check is quite simple. So the
    // complete check based on XML 1.0 is not performed.
    boolean res;
    if (c < 256) res = (chartype[c] & (FLETTER | FDIGIT | FMISCNAME)) != 0;
    else {
      // [#x2180-#x2182] | [#x3041-#x3094] | [#x30A1-#x30FA] |
      // [#x3105-#x312C] | [#xAC00-#xD7A3]
      // [#x0E47-#x0E4E]
      if (((c >= 0x2180) && (c <= 0x2182))
          || ((c >= 0x3041) && (c <= 0x3094))
          || ((c >= 0x30A1) && (c <= 0x30FA))
          || ((c >= 0x3105) && (c <= 0x312C))
          || ((c >= 0xAC00) && (c <= 0xD7A3))
          || ((c >= 0x0E47) && (c <= 0x0E4E))) res = true;
      else {
        if ((c == 0x02FF)
            || (c == 0x0346)
            || (c == 0x0362)
            || (c == 0x0487)
            || (c == 0x05A2)
            || (c == 0x05BA)
            || (c == 0x05BE)
            || (c == 0x05C0)
            || (c == 0x05C3)
            || (c == 0x0653)
            || (c == 0x06B8)
            || (c == 0x06B9)
            || (c == 0x06E9)
            || (c == 0x06EE)
            || (c == 0x0904)
            || (c == 0x093B)
            || (c == 0x094E)
            || (c == 0x0955)
            || (c == 0x0964)
            || (c == 0x0984)
            || (c == 0x09C5)
            || (c == 0x09C9)
            || (c == 0x09CE)
            || (c == 0x09D8)
            || (c == 0x09E4)
            || (c == 0x0A03)
            || (c == 0x0A3D)
            || (c == 0x0A46)
            || (c == 0x0A49)
            || (c == 0x0A4E)
            || (c == 0x0A80)
            || (c == 0x0A84)
            || (c == 0x0ABB)
            || (c == 0x0AC6)
            || (c == 0x0ACA)
            || (c == 0x0ACE)
            || (c == 0x0B04)
            || (c == 0x0B3B)
            || (c == 0x0B44)
            || (c == 0x0B4A)
            || (c == 0x0B4E)
            || (c == 0x0B58)
            || (c == 0x0B84)
            || (c == 0x0BC3)
            || (c == 0x0BC9)
            || (c == 0x0BD6)
            || (c == 0x0C0D)
            || (c == 0x0C45)
            || (c == 0x0C49)
            || (c == 0x0C54)
            || (c == 0x0C81)
            || (c == 0x0C84)
            || (c == 0x0CC5)
            || (c == 0x0CC9)
            || (c == 0x0CD4)
            || (c == 0x0CD7)
            || (c == 0x0D04)
            || (c == 0x0D45)
            || (c == 0x0D49)
            || (c == 0x0D4E)
            || (c == 0x0D58)
            || (c == 0x0E3F)
            || (c == 0x0E3B)
            || (c == 0x0E4F)
            || (c == 0x0EBA)
            || (c == 0x0EBE)
            || (c == 0x0ECE)
            || (c == 0x0F1A)
            || (c == 0x0F36)
            || (c == 0x0F38)
            || (c == 0x0F3B)
            || (c == 0x0F3A)
            || (c == 0x0F70)
            || (c == 0x0F85)
            || (c == 0x0F8C)
            || (c == 0x0F96)
            || (c == 0x0F98)
            || (c == 0x0FB0)
            || (c == 0x0FB8)
            || (c == 0x0FBA)
            || (c == 0x20DD)
            || (c == 0x20E2)
            || (c == 0x3030)
            || (c == 0x309B)
            || (c == 0x066A)
            || (c == 0x06FA)
            || (c == 0x0970)
            || (c == 0x09F2)
            || (c == 0x0AF0)
            || (c == 0x0B70)
            || (c == 0x0C65)
            || (c == 0x0CE5)
            || (c == 0x0CF0)
            || (c == 0x0D70)
            || (c == 0x0E5A)
            || (c == 0x0EDA)
            || (c == 0x0F2A)
            || (c == 0x02D2)
            || (c == 0x03FE)
            || (c == 0x065F)
            || (c == 0x0E5C)
            || (c == 0x0C04)) res = false;
        else {
          // Character.isLetter(c) || Character.isDigit(c) || '-' || '-' || '.'
          // is known to be true at this point
          res = true;
        }
      }
    }
    return res;
  }

  /**
   * return true if character can be part of a name
   *
   * @param c - char to be checked
   * @return true/false
   */
  public static boolean isFirstNameChar(char c) {
    // In most cases the character is less than 256, so this check
    // is made fast. For the rest of the characters the check is
    // based on the conformance tests. XML 1.1 has changed the list
    // of chars allowed, and the check is quite simple. So the
    // complete check based on XML 1.0 is not performed.
    boolean res;
    if (c < 256) res = (chartype[c] & (FLETTER | FSTARTNAME)) != 0;
    else {
      // [#x2180-#x2182] | [#x3041-#x3094] | [#x30A1-#x30FA] |
      // [#x3105-#x312C] | [#xAC00-#xD7A3]
      if (((c >= 0x2180) && (c <= 0x2182))
          || (c == 0x3007)
          || ((c >= 0x3021) && (c <= 0x3029))
          || ((c >= 0x3041) && (c <= 0x3094))
          || ((c >= 0x30A1) && (c <= 0x30FA))
          || ((c >= 0x3105) && (c <= 0x312C))
          || ((c >= 0xAC00) && (c <= 0xD7A3))) res = true;
      else {
        if ((c == 0x1101)
            || (c == 0x1104)
            || (c == 0x1108)
            || (c == 0x110A)
            || (c == 0x110D)
            || (c == 0x113B)
            || (c == 0x1141)
            || (c == 0x114D)
            || (c == 0x114F)
            || (c == 0x1151)
            || (c == 0x1156)
            || (c == 0x1162)
            || (c == 0x1164)
            || (c == 0x1166)
            || (c == 0x116B)
            || (c == 0x116F)
            || (c == 0x1174)
            || (c == 0x119F)
            || (c == 0x11AC)
            || (c == 0x11B6)
            || (c == 0x11B9)
            || (c == 0x11BB)
            || (c == 0x11C3)
            || (c == 0x11F1)
            || (c == 0x0132)
            || (c == 0x0133)
            || (c == 0x013F)
            || (c == 0x0140)
            || (c == 0x0149)
            || (c == 0x017F)
            || (c == 0x01C4)
            || (c == 0x01CC)
            || (c == 0x01F1)
            || (c == 0x01F3)
            || (c == 0x0E46)
            || (c == 0x113F)
            || (c == 0x01F6)
            || (c == 0x01F9)
            || (c == 0x0230)
            || (c == 0x03D7)
            || (c == 0x03DD)
            || (c == 0x03E1)
            || (c == 0x040D)
            || (c == 0x0450)
            || (c == 0x045D)
            || (c == 0x04EC)
            || (c == 0x04ED)
            || (c == 0x06B8)
            || (c == 0x06BF)
            || (c == 0x06CF)
            || (c == 0x0E2F)
            || (c == 0x0EAF)
            || (c == 0x0F6A)
            || (c == 0x4CFF)
            || (c == 0x212F)
            || (c == 0x0587)) {
          res = false;
        } else {
          // Character.isLetter(c) || c == '_' is known to be true here
          res = true;
        }
      }
    }
    return res;
  }

  /** Char type table */
  static final int chartype[] = new int[256];

  static final int FWHITESPACE = 1;
  static final int FDIGIT = 2;
  static final int FLETTER = 4;
  static final int FMISCNAME = 8;
  static final int FSTARTNAME = 16;

  static {
    for (int i = 0; i < 256; i++) {
      char c = (char) i;
      chartype[i] = 0;
      if ((c == 32) || (c == 9) || (c == 13) || (c == 10)) chartype[i] = FWHITESPACE;
      if (Character.isLetter(c)) chartype[i] |= FLETTER;
      if (Character.isDigit(c)) chartype[i] |= FDIGIT;
    }
    chartype['.'] |= FMISCNAME;
    chartype['-'] |= FMISCNAME;
    chartype['_'] |= FMISCNAME | FSTARTNAME;
    chartype[0xb7] |= FMISCNAME; // Extender
  }

  public static Class<?> getClassFromJDBCType(String typeName, DatabasePlatform databasePlatform) {
    Class<?> clz = databasePlatform.getClassTypes().get(typeName);
    if (clz == null) {
      return Object_Class;
    }
    return clz;
  }

  public static final QName SXF_QNAME = new QName("", DEFAULT_SIMPLE_XML_FORMAT_TAG);

  public static final Map<QName, Class<?>> SCHEMA_2_CLASS;

  static {
    SCHEMA_2_CLASS =
        Collections.unmodifiableMap(
            new HashMap<QName, Class<?>>() {
              {
                put(ANY_SIMPLE_TYPE_QNAME, Object_Class);
                put(BASE_64_BINARY_QNAME, APBYTE);
                put(BOOLEAN_QNAME, BOOLEAN);
                put(BYTE_QNAME, BYTE);
                // put(DATE_QNAME, SQLDATE);
                put(DATE_QNAME, CALENDAR);
                // put(DATE_TIME_QNAME, TIMESTAMP);
                put(DATE_TIME_QNAME, CALENDAR);
                put(DECIMAL_QNAME, BIGDECIMAL);
                put(DOUBLE_QNAME, DOUBLE);
                put(DURATION_QNAME, STRING);
                put(FLOAT_QNAME, FLOAT);
                put(G_YEAR_MONTH_QNAME, STRING);
                put(G_YEAR_QNAME, STRING);
                put(G_MONTH_QNAME, STRING);
                put(G_MONTH_DAY_QNAME, STRING);
                put(G_DAY_QNAME, STRING);
                put(HEX_BINARY_QNAME, APBYTE);
                put(INT_QNAME, INTEGER);
                put(INTEGER_QNAME, BIGINTEGER);
                put(LONG_QNAME, LONG);
                put(QNAME_QNAME, QName.class);
                put(SHORT_QNAME, SHORT);
                put(STRING_QNAME, STRING);
                // put(TIME_QNAME, TIME);
                put(TIME_QNAME, CALENDAR);
                put(UNSIGNED_BYTE_QNAME, SHORT);
                put(UNSIGNED_INT_QNAME, LONG);
                put(UNSIGNED_SHORT_QNAME, INTEGER);
              }
            });
  }

  /**
   * Return the type name to be used for a given JDBC type. This will typically be used when setting
   * the SQL type and type name on a stored function/procedure argument. Currently, the only case we
   * need to handle in this manner is oracle.xdb.XMLType - here we may set 2007 (OPAQUE) or 2009
   * (SQLXML).
   *
   * <p>In the future this method may be required to return more types.
   */
  public static String getTypeNameForJDBCType(int jdbcType) {
    String typeName = null;
    switch (jdbcType) {
      case OPAQUE:
      case Types.SQLXML:
        typeName = XMLTYPE_STR;
        break;
      default:
        break;
    }
    return typeName;
  }

  public static int getJDBCTypeForTypeName(String typeName) {
    int typeCode = -1;
    if (typeName.equals(XMLTYPE_STR)) {
      // we currently use oracle.sql.OPAQUE for XMLType
      typeCode = OPAQUE;
    }
    return typeCode;
  }
}
 public NamespaceCollisionTestCases() {
   XMLPlatform platform = XMLPlatformFactory.getInstance().getXMLPlatform();
   parser = platform.newXMLParser();
 }