public void testXercesIncomplete() throws Exception {
   XSModel xsModel = getXSModel("testIncomplete.xml", "test.xsd");
   XSElementDeclaration elementDeclaration = xsModel.getElementDeclaration("a", "");
   XSComplexTypeDefinition typeDefinition =
       (XSComplexTypeDefinition) elementDeclaration.getTypeDefinition();
   CMBuilder cmBuilder = new CMBuilder(new CMNodeFactory());
   XSCMValidator validator = cmBuilder.getContentModel((XSComplexTypeDecl) typeDefinition, true);
   int[] ints = validator.startContentModel();
   Vector vector = validator.whatCanGoHere(ints);
   XSElementDecl o = (XSElementDecl) vector.get(0);
   assertEquals("b", o.getName());
 }
  public void testXercesForCompletion() throws Exception {
    XSModel xsModel = getXSModel("testCompletion.xml", "test.xsd");
    PsiElement element = myFixture.getFile().findElementAt(getEditor().getCaretModel().getOffset());
    XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);

    assert tag != null;
    XSElementDeclaration elementDeclaration =
        xsModel.getElementDeclaration(tag.getLocalName(), tag.getNamespace());
    XSComplexTypeDefinition typeDefinition =
        (XSComplexTypeDefinition) elementDeclaration.getTypeDefinition();
    CMBuilder cmBuilder = new CMBuilder(new CMNodeFactory());
    XSCMValidator validator = cmBuilder.getContentModel((XSComplexTypeDecl) typeDefinition, true);
    int[] ints = validator.startContentModel();
    Vector vector = validator.whatCanGoHere(ints);
    XSElementDecl o = (XSElementDecl) vector.get(0);
    assertEquals("b", o.getName());
  }
  protected void addUserDefinedSimpleTypes(XSModel schema) {
    XSNamedMap xstypes = schema.getComponents(XSConstants.TYPE_DEFINITION);
    if (xstypes.getLength() == 0) {
      return;
    }

    addNamespace("myType", "http://www.w3.org/XQueryTest/userDefinedTypes");
    UserDefinedCtrLibrary udl =
        new UserDefinedCtrLibrary("http://www.w3.org/XQueryTest/userDefinedTypes");

    for (int i = 0; i < xstypes.getLength(); i++) {
      XSObject xsobject = xstypes.item(i);
      if ("http://www.w3.org/XQueryTest/userDefinedTypes".equals(xsobject.getNamespace())) {
        if (xsobject instanceof XSSimpleTypeDefinition) {
          XSSimpleTypeDefinition typeDef = (XSSimpleTypeDefinition) xsobject;
          if (typeDef.getNumeric()) {
            if (xsobject.getName().equals("floatBased") || xsobject.getName().equals("shoesize")) {
              XercesFloatUserDefined fudt = new XercesFloatUserDefined(xsobject);
              udl.add_type(fudt);

            } else {
              XercesIntegerUserDefined iudt = new XercesIntegerUserDefined(xsobject);
              udl.add_type(iudt);
            }
          } else {
            if (xsobject.getName().equals("QNameBased")) {
              XercesQNameUserDefined qudt = new XercesQNameUserDefined(xsobject);
              udl.add_type(qudt);
            } else {
              XercesUserDefined udt = new XercesUserDefined(typeDef);
              udl.add_type(udt);
            }
          }
        }
      }
    }

    addFunctionLibrary(udl);
  }