Search in sources :

Example 1 with CMGroupImpl

use of org.eclipse.wst.xml.core.internal.contentmodel.basic.CMGroupImpl in project webtools.sourceediting by eclipse.

the class InferredGrammarFactory method createCMElementDeclaration.

public CMElementDeclaration createCMElementDeclaration(CMDocument cmDocument, Element element, boolean isLocal) {
    String localName = element.getLocalName();
    CMDocumentImpl cmDocumentImpl = (CMDocumentImpl) cmDocument;
    CMNamedNodeMapImpl elementMap = isLocal ? (CMNamedNodeMapImpl) cmDocumentImpl.getLocalElementPool() : (CMNamedNodeMapImpl) cmDocumentImpl.getElements();
    CMElementDeclarationImpl ed = (CMElementDeclarationImpl) elementMap.getNamedItem(localName);
    if (ed == null) {
        // System.out.println("create ed " + localName);
        ed = new CMElementDeclarationImpl(cmDocument, localName);
        ed.setInferred(true);
        ed.setLocal(isLocal);
        ed.setMaxOccur(1);
        CMGroupImpl group = new CMGroupImpl(new CMNodeListImpl(), CMGroup.CHOICE);
        group.setInferred(true);
        group.setMinOccur(0);
        group.setMaxOccur(-1);
        ed.setContent(group);
        elementMap.put(ed);
    }
    // lookup or create the attributes
    // 
    NamedNodeMap attributeMap = element.getAttributes();
    int attributeMapLength = attributeMap.getLength();
    for (int i = 0; i < attributeMapLength; i++) {
        Attr attr = (Attr) attributeMap.item(i);
        CMAttributeDeclarationImpl ad = (CMAttributeDeclarationImpl) ed.getAttributeMap().getNamedItem(attr.getNodeName());
        if (ad == null) {
            // todo... use an attribute pool to be more efficient?
            ad = new CMAttributeDeclarationImpl(attr.getNodeName(), CMAttributeDeclaration.OPTIONAL);
            ad.setInferred(true);
            ed.getAttributeMap().put(ad);
        }
    }
    return ed;
}
Also used : CMNamedNodeMapImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl) CMAttributeDeclarationImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMAttributeDeclarationImpl) CMNodeListImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNodeListImpl) NamedNodeMap(org.w3c.dom.NamedNodeMap) CMElementDeclarationImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMElementDeclarationImpl) CMDocumentImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMDocumentImpl) Attr(org.w3c.dom.Attr) CMGroupImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMGroupImpl)

Example 2 with CMGroupImpl

use of org.eclipse.wst.xml.core.internal.contentmodel.basic.CMGroupImpl in project webtools.sourceediting by eclipse.

the class InferredGrammarFactory method createCMContent.

public void createCMContent(CMDocument parentCMDocument, CMElementDeclaration parentEd, CMDocument childCMDocument, CMElementDeclaration childEd, boolean isLocal, String uri) {
    // add element to the parent's content
    // consider all content to be of the form (A | B | C)*
    // 
    CMGroupImpl group = (CMGroupImpl) parentEd.getContent();
    CMNodeListImpl groupChildNodeList = (CMNodeListImpl) group.getChildNodes();
    if (parentCMDocument == childCMDocument) {
        if (!groupChildNodeList.contains(childEd)) {
            groupChildNodeList.add(childEd);
        }
        if (isLocal) {
            CMNamedNodeMapImpl localElementMap = (CMNamedNodeMapImpl) parentEd.getLocalElements();
            localElementMap.put(childEd);
        }
    } else {
        CMAnyElement cmAnyElement = lookupOrCreateCMAnyElement((CMDocumentImpl) parentCMDocument, uri);
        if (!groupChildNodeList.contains(cmAnyElement)) {
            groupChildNodeList.add(cmAnyElement);
        }
    }
}
Also used : CMNamedNodeMapImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl) CMNodeListImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNodeListImpl) CMAnyElement(org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement) CMGroupImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMGroupImpl)

Aggregations

CMGroupImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMGroupImpl)2 CMNamedNodeMapImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl)2 CMNodeListImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNodeListImpl)2 CMAnyElement (org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement)1 CMAttributeDeclarationImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMAttributeDeclarationImpl)1 CMDocumentImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMDocumentImpl)1 CMElementDeclarationImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMElementDeclarationImpl)1 Attr (org.w3c.dom.Attr)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1