use of org.apache.xerces.impl.xs.XSElementDecl in project intellij-community by JetBrains.
the class XmlConstraintsTest method testXercesGrammar.
public void testXercesGrammar() throws Exception {
XSModel xsModel = getXSModel("test.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());
}
use of org.apache.xerces.impl.xs.XSElementDecl in project intellij-community by JetBrains.
the class XmlConstraintsTest method testXercesForCompletion.
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());
}
use of org.apache.xerces.impl.xs.XSElementDecl in project intellij-community by JetBrains.
the class XSDModelLoader method processParticles.
private void processParticles(XSObject def, LinkedList<PEntry> plist, Map<String, NamespaceDesc> nsdMap, Map<String, TypeDesc> jtMap, TypeDesc td, List<XSModel> models, ArrayList<XSComplexTypeDefinition> toAdd, TypeDesc baseClass) {
final boolean globalMerge = jtMap.containsKey(model.toJavaQualifiedTypeName(def, nsdMap, td.type == TypeDesc.TypeEnum.ENUM));
final HashMap<XSParticle, String> globalChoice = new HashMap<>();
final ArrayList<XSObjectList> choiceList = new ArrayList<>();
final ArrayList<TypeDesc> supers = new ArrayList<>();
if (baseClass != null) {
supers.add(baseClass);
}
while (!plist.isEmpty()) {
final PEntry pentry = plist.removeFirst();
final XSParticle p = pentry.p;
if (p.getTerm() instanceof XSElementDecl) {
final XSElementDecl el = (XSElementDecl) p.getTerm();
if (el.getConstraintType() == XSConstants.VC_FIXED)
continue;
XSTypeDefinition etRoot = el.getTypeDefinition();
XSTypeDefinition et = etRoot;
XSAnnotation ann = el.getAnnotation();
String documentation = parseAnnotationString("Element " + el.getNamespace() + ":" + el.getName() + " documentation", ann != null ? ann.getAnnotationString() : null);
final FieldDesc fd1 = new FieldDesc(FieldDesc.STR, Util.toJavaFieldName(el.getName()), et.getName(), null, "null", !pentry.many && p.getMinOccurs() > 0);
fd1.documentation = documentation;
fd1.tagName = el.getName();
while (et.getBaseType() != null && !"anySimpleType".equals(et.getBaseType().getName()) && !"anyType".equals(et.getBaseType().getName())) {
et = et.getBaseType();
}
if (checkEnumType(etRoot)) {
if (etRoot.getAnonymous()) {
etRoot = makeTypeFromAnonymous(el);
if (toAdd != null)
toAdd.add((XSComplexTypeDefinition) etRoot);
}
fd1.type = toJavaTypeName(etRoot, nsdMap);
fd1.clType = FieldDesc.OBJ;
fd1.contentQualifiedName = model.toJavaQualifiedTypeName(etRoot, nsdMap, true);
// forward decl
if (!jtMap.containsKey(fd1.contentQualifiedName)) {
// logwarn("forward decl: "+et);
TypeDesc ftd = new TypeDesc(etRoot.getName(), etRoot.getNamespace(), fd1.type, TypeDesc.TypeEnum.ENUM);
jtMap.put(fd1.contentQualifiedName, ftd);
}
} else if (checkComplexType(etRoot)) {
if (etRoot.getAnonymous()) {
etRoot = makeTypeFromAnonymous(el);
if (toAdd != null)
toAdd.add((XSComplexTypeDefinition) etRoot);
}
fd1.type = toJavaTypeName(etRoot, nsdMap);
fd1.clType = FieldDesc.OBJ;
fd1.contentQualifiedName = model.toJavaQualifiedTypeName(etRoot, nsdMap, false);
// forward decl
if (jtMap.get(fd1.contentQualifiedName) == null) {
//logwarn("forward decl: "+etRoot);
jtMap.put(fd1.contentQualifiedName, new TypeDesc(etRoot.getName(), etRoot.getNamespace(), fd1.type, TypeDesc.TypeEnum.CLASS));
}
} else if (checkBooleanType(etRoot)) {
fd1.type = "boolean";
fd1.clType = FieldDesc.BOOL;
} else {
if (etRoot instanceof XSComplexTypeDefinition) {
final XSComplexTypeDefinition ct = (XSComplexTypeDefinition) etRoot;
// XXX xerces2.7.1 wierd annotation inheritance bug fix
//ann = (XSAnnotation) (ct.getAnnotations()!=null && ct.getAnnotations().getLength()>0?ct.getAnnotations().item(0):null);
ann = (XSAnnotation) (ct.getAnnotations() != null && ct.getAnnotations().getLength() > 0 ? ct.getAnnotations().item(ct.getAnnotations().getLength() - 1) : null);
documentation = parseAnnotationString("Type " + ct.getNamespace() + ":" + ct.getName() + " documentation", ann != null ? ann.getAnnotationString() : null);
if (documentation != null) {
fd1.documentation = fd1.documentation != null ? fd1.documentation + "\n" + documentation : documentation;
}
}
fd1.simpleTypesString = getSimpleTypesString(etRoot);
// "fully-qualified-classType", "jndi-nameType", "transaction-typeType"
// "java-identifierType", "pathType"
fd1.type = et.getName();
if (fd1.type == null) {
fd1.type = "String";
fd1.def = "null";
fd1.clType = FieldDesc.STR;
// fd1.type = "boolean";
// fd1.def = "false";
// fd1.clType = FieldDesc.BOOL;
} else if (fd1.type.equals("string") || fd1.type.equals("anyURI")) {
fd1.type = "String";
} else if (fd1.type.equals("boolean")) {
fd1.type = "String";
} else if (fd1.type.equals("emptyType")) {
fd1.type = "boolean";
fd1.def = "false";
fd1.clType = FieldDesc.BOOL;
} else if (fd1.type.equals("decimal")) {
fd1.type = "String";
fd1.def = "\"0.0\"";
} else if (fd1.type.equals("QName")) {
fd1.type = "String";
} else if (fd1.type.equals("extensibleType")) {
fd1.type = "Object";
} else {
if (et.getBaseType() != null && ("anySimpleType".equals(et.getBaseType().getName()) || "anyType".equals(et.getBaseType().getName()))) {
fd1.type = "String";
fd1.def = "null";
fd1.clType = FieldDesc.STR;
} else {
fd1.type = "boolean";
fd1.def = "false";
fd1.clType = FieldDesc.BOOL;
}
Util.logwarn("using '" + fd1.type + "' for unknown base type: " + et.getName() + " for " + el);
}
}
if ((pentry.many || p.getMaxOccursUnbounded() || p.getMaxOccurs() > 1) && fd1.clType != FieldDesc.BOOL) {
fd1.elementType = fd1.type;
fd1.elementName = fd1.name;
fd1.type = "List<" + fd1.elementType + ">";
fd1.name = Util.pluralize(fd1.name);
fd1.def = "new ArrayList(0)";
fd1.clType = -fd1.clType;
fd1.comment = "array of " + fd1.elementType;
}
fd1.realIndex = td.fdMap.size();
boolean merge = globalMerge || globalChoice.containsKey(p) && globalChoice.values().contains(fd1.name);
td.duplicates = Util.addToNameMap(td.fdMap, fd1, merge) || td.duplicates;
globalChoice.put(p, fd1.name);
} else if (p.getTerm() instanceof XSModelGroup) {
boolean addToGlobalChoice = false;
boolean many = p.getMaxOccursUnbounded() || p.getMaxOccurs() > 1;
XSObjectList l = ((XSModelGroup) p.getTerm()).getParticles();
if (!many) {
if (((XSModelGroup) p.getTerm()).getCompositor() == XSModelGroup.COMPOSITOR_CHOICE) {
addToGlobalChoice = true;
choiceList.add(l);
} else {
// generate group interface???
XSModelGroup groupDef = (XSModelGroup) p.getTerm();
TypeDesc gtd = processGroup(groupDef, models, jtMap, nsdMap);
if (gtd != null)
supers.add(gtd);
}
}
if (globalChoice.containsKey(p)) {
addToGlobalChoice = true;
}
for (int i = 0; i < l.getLength(); i++) {
final PEntry o = new PEntry((XSParticle) l.item(i), many);
plist.add(o);
if (addToGlobalChoice && !globalChoice.containsKey(o.p)) {
globalChoice.put(o.p, null);
}
}
}
}
int i = 0;
for (Iterator<FieldDesc> it = td.fdMap.values().iterator(); it.hasNext(); i++) {
FieldDesc fd = it.next();
fd.idx = i;
}
for (XSObjectList l : choiceList) {
final ArrayList<XSParticle> clist = new ArrayList<>();
final LinkedList<XSParticle> elist = new LinkedList<>();
for (i = 0; i < l.getLength(); i++) {
elist.add((XSParticle) l.item(i));
}
while (!elist.isEmpty()) {
final XSParticle p = elist.removeFirst();
if (p.getTerm() instanceof XSModelGroup) {
XSObjectList l2 = ((XSModelGroup) p.getTerm()).getParticles();
for (int i2 = 0; i2 < l2.getLength(); i2++) {
elist.addFirst((XSParticle) l2.item(i2));
}
} else if (p.getTerm() instanceof XSElementDecl) {
clist.add(p);
}
}
boolean choiceOpt = true;
FieldDesc[] choice = new FieldDesc[clist.size()];
for (i = 0; i < choice.length; i++) {
XSParticle p = clist.get(i);
XSElementDecl el = (XSElementDecl) p.getTerm();
String s = Util.toJavaFieldName(el.getName());
if (p.getMaxOccursUnbounded() || p.getMaxOccurs() > 1) {
s = Util.pluralize(s);
}
FieldDesc fd = td.fdMap.get(s);
if (fd == null) {
fd = td.fdMap.get(Util.pluralize(s));
if (fd == null) {
Util.logerr("uknown choice element: " + s);
}
}
if (fd != null) {
choice[i] = fd;
choice[i].choice = choice;
if (fd.required)
choiceOpt = false;
}
}
for (i = 0; i < choice.length; i++) {
if (choice[i] != null) {
choice[i].choiceOpt = choiceOpt;
}
}
}
td.supers = supers.toArray(new TypeDesc[supers.size()]);
}
use of org.apache.xerces.impl.xs.XSElementDecl in project intellij-community by JetBrains.
the class XmlConstraintsTest method testXercesIncomplete.
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());
}
Aggregations