Search in sources :

Example 1 with CMAnyElement

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

the class DOMContentBuilderImpl method visitCMAnyElement.

public void visitCMAnyElement(CMAnyElement anyElement) {
    // ingnore buildPolicy for ANY elements... only create elements if
    // absolutely needed
    // 
    int forcedMin = alwaysVisit ? 1 : 0;
    int min = Math.max(anyElement.getMinOccur(), forcedMin);
    alwaysVisit = false;
    String uri = anyElement.getNamespaceURI();
    // $NON-NLS-1$
    String targetNSProperty = "http://org.eclipse.wst/cm/properties/targetNamespaceURI";
    // $NON-NLS-1$
    CMDocument parentCMDocument = (CMDocument) anyElement.getProperty("CMDocument");
    CMElementDeclaration ed = null;
    // //$NON-NLS-1$
    if (parentCMDocument != null) {
        if (// $NON-NLS-1$
        uri == null || uri.startsWith("##") || uri.equals(parentCMDocument.getProperty(targetNSProperty))) {
            ed = getSuitableElement(getParentCMElementDeclaration(), parentCMDocument);
        }
    }
    if (// $NON-NLS-1$
    ed == null && externalCMDocumentSupport != null && uri != null && !uri.startsWith("##") && currentParent instanceof Element) {
        CMDocument externalCMDocument = externalCMDocumentSupport.getCMDocument((Element) currentParent, uri);
        if (externalCMDocument != null) {
            ed = getSuitableElement(null, externalCMDocument);
        }
    }
    for (int i = 1; i <= min; i++) {
        if (ed != null) {
            visitCMElementDeclaration(ed);
        } else {
            // $NON-NLS-1$
            Element element = document.createElement("ANY-ELEMENT");
            linkNode(element);
        }
    }
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMAnyElement(org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement) Element(org.w3c.dom.Element)

Example 2 with CMAnyElement

use of org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement 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

CMAnyElement (org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement)2 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)1 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)1 CMGroupImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMGroupImpl)1 CMNamedNodeMapImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl)1 CMNodeListImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNodeListImpl)1 Element (org.w3c.dom.Element)1