Search in sources :

Example 1 with DTDAnyContent

use of org.eclipse.wst.dtd.core.internal.emf.DTDAnyContent in project webtools.sourceediting by eclipse.

the class DTDModelBuilder method finishElementDecl.

// /////////////////////////////////////////////////////////////
// 
// Methods for finishing the import of a DTDElement
// 
// /////////////////////////////////////////////////////////////
public void finishElementDecl(DTDElement dtdElement, ElementDecl ed) {
    dtdElement.setName(ed.getNodeName());
    CMNode cmNode = ed.getContentModelNode();
    if (ed.getComment() != null) {
        dtdElement.setComment(ed.getComment());
    }
    if (ed.getErrorMessage() != null) {
        addErrorMessage(ed.getErrorMessage(), dtdElement);
    }
    if (cmNode instanceof CMBasicNode) {
        CMBasicNode bn = (CMBasicNode) cmNode;
        switch(bn.getType()) {
            case CMNodeType.EMPTY:
                DTDEmptyContent emptyContent = getFactory().createDTDEmptyContent();
                dtdElement.setContent(emptyContent);
                break;
            case CMNodeType.ANY:
                DTDAnyContent anyContent = getFactory().createDTDAnyContent();
                dtdElement.setContent(anyContent);
                break;
            case CMNodeType.PCDATA:
                DTDPCDataContent pcData = getFactory().createDTDPCDataContent();
                dtdElement.setContent(pcData);
        }
    } else if (cmNode instanceof CMReferenceNode) {
        CMReferenceNode rn = (CMReferenceNode) cmNode;
        if (rn.getType() == CMNodeType.ENTITY_REFERENCE) {
            String entityName = rn.getName().trim();
            DTDEntity anEntity = (DTDEntity) dtdUtil.getPEPool().get(entityName);
            if (anEntity != null) {
                // 
                // Create an DTDEntityReference and set its referenced
                // element
                // 
                DTDEntityReferenceContent enRef = getFactory().createDTDEntityReferenceContent();
                enRef.setElementReferencedEntity(anEntity);
                DTDOccurrenceType occurrenceType = DTDOccurrenceType.get(computeMofOccurrence(rn));
                enRef.setOccurrence(occurrenceType);
                dtdElement.setContent(enRef);
            } else {
                // create default content
                DTDEmptyContent emptyContent = getFactory().createDTDEmptyContent();
                dtdElement.setContent(emptyContent);
            }
        } else {
            // 
            // Find the real element for this element references
            // If the real element does not yet exist, create it
            // 
            DTDElement anElement = createOrFindElement(rn.getName(), dtdElement);
            // 
            // Create an DTDElementReference and set its referenced
            // element
            // 
            DTDElementReferenceContent elemRef = getFactory().createDTDElementReferenceContent();
            elemRef.setReferencedElement(anElement);
            DTDOccurrenceType occurrenceType = DTDOccurrenceType.get(computeMofOccurrence(rn));
            elemRef.setOccurrence(occurrenceType);
            // setContent to DTDElementReference
            dtdElement.setContent(elemRef);
        }
    } else if (cmNode instanceof CMGroupNode) {
        CMGroupNode grpNode = (CMGroupNode) cmNode;
        DTDGroupContent groupContent = getFactory().createDTDGroupContent();
        DTDGroupKind groupKind = DTDGroupKind.get(computeMofGroupKind(grpNode.getGroupKind()));
        groupContent.setGroupKind(groupKind);
        DTDOccurrenceType occurrenceType = DTDOccurrenceType.get(computeMofOccurrence(grpNode));
        groupContent.setOccurrence(occurrenceType);
        // just use the locator for the element as the closest guess
        processGroupContent(groupContent, grpNode);
        dtdElement.setContent(groupContent);
    } else if (cmNode == null) {
        // bad thing happened here, just create a pcdata
        DTDEmptyContent emptyContent = getFactory().createDTDEmptyContent();
        dtdElement.setContent(emptyContent);
    }
}
Also used : DTDAnyContent(org.eclipse.wst.dtd.core.internal.emf.DTDAnyContent) DTDGroupContent(org.eclipse.wst.dtd.core.internal.emf.DTDGroupContent) DTDEntityReferenceContent(org.eclipse.wst.dtd.core.internal.emf.DTDEntityReferenceContent) DTDPCDataContent(org.eclipse.wst.dtd.core.internal.emf.DTDPCDataContent) CMReferenceNode(org.eclipse.wst.dtd.core.internal.saxparser.CMReferenceNode) DTDElement(org.eclipse.wst.dtd.core.internal.emf.DTDElement) CMGroupNode(org.eclipse.wst.dtd.core.internal.saxparser.CMGroupNode) DTDEntity(org.eclipse.wst.dtd.core.internal.emf.DTDEntity) DTDOccurrenceType(org.eclipse.wst.dtd.core.internal.emf.DTDOccurrenceType) DTDElementReferenceContent(org.eclipse.wst.dtd.core.internal.emf.DTDElementReferenceContent) DTDGroupKind(org.eclipse.wst.dtd.core.internal.emf.DTDGroupKind) CMNode(org.eclipse.wst.dtd.core.internal.saxparser.CMNode) CMBasicNode(org.eclipse.wst.dtd.core.internal.saxparser.CMBasicNode) DTDEmptyContent(org.eclipse.wst.dtd.core.internal.emf.DTDEmptyContent)

Aggregations

DTDAnyContent (org.eclipse.wst.dtd.core.internal.emf.DTDAnyContent)1 DTDElement (org.eclipse.wst.dtd.core.internal.emf.DTDElement)1 DTDElementReferenceContent (org.eclipse.wst.dtd.core.internal.emf.DTDElementReferenceContent)1 DTDEmptyContent (org.eclipse.wst.dtd.core.internal.emf.DTDEmptyContent)1 DTDEntity (org.eclipse.wst.dtd.core.internal.emf.DTDEntity)1 DTDEntityReferenceContent (org.eclipse.wst.dtd.core.internal.emf.DTDEntityReferenceContent)1 DTDGroupContent (org.eclipse.wst.dtd.core.internal.emf.DTDGroupContent)1 DTDGroupKind (org.eclipse.wst.dtd.core.internal.emf.DTDGroupKind)1 DTDOccurrenceType (org.eclipse.wst.dtd.core.internal.emf.DTDOccurrenceType)1 DTDPCDataContent (org.eclipse.wst.dtd.core.internal.emf.DTDPCDataContent)1 CMBasicNode (org.eclipse.wst.dtd.core.internal.saxparser.CMBasicNode)1 CMGroupNode (org.eclipse.wst.dtd.core.internal.saxparser.CMGroupNode)1 CMNode (org.eclipse.wst.dtd.core.internal.saxparser.CMNode)1 CMReferenceNode (org.eclipse.wst.dtd.core.internal.saxparser.CMReferenceNode)1