Search in sources :

Example 1 with DTDFactory

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

the class DTDModelBuilder method createOrFindElement.

/**
 * Find the real element that is referenced by the current element
 */
private DTDElement createOrFindElement(String name, Object obj) {
    // DTDElement aElement = getDTDFile().findElement(name);
    DTDElement aElement = (DTDElement) dtdUtil.getElementPool().get(name);
    if (aElement != null) {
        return aElement;
    }
    // $NON-NLS-1$
    String errorMsg = DTDCoreMessages._ERROR_UNDECLARED_ELEMENT_1;
    // $NON-NLS-1$ //$NON-NLS-2$
    errorMsg += "\"" + name + "\"";
    // $NON-NLS-1$
    errorMsg += DTDCoreMessages._UI_ERRORPART_UNDECLARED_ELEMENT_2;
    ErrorMessage dtdError = new ErrorMessage();
    dtdError.setErrorMessage(errorMsg);
    addErrorMessage(dtdError, obj);
    // System.out.println(errorMsg);
    // setDTDErrorMessage(errorMsg);
    getDTDFile().setParseError(true);
    // 
    // Create an empty element for the reference to make it valid
    // 
    DTDFactory factory = getFactory();
    DTDElement dtdelement = factory.createDTDElement();
    dtdelement.setName(name);
    DTDEmptyContent emptyContent = factory.createDTDEmptyContent();
    dtdelement.setContent(emptyContent);
    getDTDFile().getDTDObject().add(dtdelement);
    dtdUtil.getElementPool().put(name, dtdelement);
    return dtdelement;
}
Also used : DTDElement(org.eclipse.wst.dtd.core.internal.emf.DTDElement) ErrorMessage(org.eclipse.wst.dtd.core.internal.saxparser.ErrorMessage) DTDFactory(org.eclipse.wst.dtd.core.internal.emf.DTDFactory) DTDEmptyContent(org.eclipse.wst.dtd.core.internal.emf.DTDEmptyContent)

Example 2 with DTDFactory

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

the class DTDModelBuilder method processGroupContent.

/**
 * Add a new group to the current group
 *
 * @param parent -
 *            the parent node for this group element
 * @param op1Node -
 *            the group e.g. (a,b)
 * @param op2Node -
 *            set only if called by processCM1op e.g. (a,b)+
 */
void processGroupContent(DTDGroupContent parent, CMGroupNode grpNode) {
    Enumeration children = grpNode.getChildren().elements();
    DTDFactory factory = getFactory();
    while (children.hasMoreElements()) {
        CMNode cnode = (CMNode) children.nextElement();
        if (cnode instanceof CMGroupNode) {
            CMGroupNode gNode = (CMGroupNode) cnode;
            DTDGroupContent groupContent = factory.createDTDGroupContent();
            DTDGroupKind groupKind = DTDGroupKind.get(computeMofGroupKind(gNode.getGroupKind()));
            groupContent.setGroupKind(groupKind);
            DTDOccurrenceType occurrenceType = DTDOccurrenceType.get(computeMofOccurrence(gNode));
            groupContent.setOccurrence(occurrenceType);
            parent.getContent().add(groupContent);
            processGroupContent(groupContent, gNode);
        } else if (cnode instanceof CMBasicNode) {
            CMBasicNode n = (CMBasicNode) cnode;
            if (n.getType() == CMNodeType.PCDATA) {
                // Create a DTDPCDataContent for a leaf PCData node
                // 
                DTDPCDataContent pcData = factory.createDTDPCDataContent();
                // Add #PCDATA to the Group, i.e Mixed content model
                parent.getContent().add(pcData);
            }
        } else if (cnode instanceof CMReferenceNode) {
            CMReferenceNode rn = (CMReferenceNode) cnode;
            if (rn.getType() == CMNodeType.ELEMENT_REFERENCE) {
                // System.out.println("CM Element Ref name: " +
                // rn.getName());
                // 
                // Create an DTDElementReference and set its referenced
                // element
                // 
                DTDElementReferenceContent elemRef = factory.createDTDElementReferenceContent();
                // 
                // Find the real element for this element references
                // If the real element does not yet exist, create it
                // 
                DTDElement anElement = createOrFindElement(rn.getName(), elemRef);
                elemRef.setReferencedElement(anElement);
                DTDOccurrenceType occurrenceType = DTDOccurrenceType.get(computeMofOccurrence(rn));
                elemRef.setOccurrence(occurrenceType);
                // Add DTDElementReference to the Group
                parent.getContent().add(elemRef);
            } else // PE Reference
            {
                String entityName = rn.getName().trim();
                // System.out.println("CM PE Ref name: " + entityName);
                DTDEntity anEntity = (DTDEntity) dtdUtil.getPEPool().get(entityName);
                if (anEntity != null) {
                    // 
                    // Create an DTDEntityReference and set its referenced
                    // element
                    // 
                    DTDEntityReferenceContent enRef = factory.createDTDEntityReferenceContent();
                    enRef.setElementReferencedEntity(anEntity);
                    DTDOccurrenceType occurrenceType = DTDOccurrenceType.get(computeMofOccurrence(rn));
                    enRef.setOccurrence(occurrenceType);
                    // Add DTDEntityReference to the Group
                    parent.getContent().add(enRef);
                }
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) 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) DTDOccurrenceType(org.eclipse.wst.dtd.core.internal.emf.DTDOccurrenceType) DTDEntity(org.eclipse.wst.dtd.core.internal.emf.DTDEntity) 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) DTDFactory(org.eclipse.wst.dtd.core.internal.emf.DTDFactory) CMBasicNode(org.eclipse.wst.dtd.core.internal.saxparser.CMBasicNode)

Aggregations

DTDElement (org.eclipse.wst.dtd.core.internal.emf.DTDElement)2 DTDFactory (org.eclipse.wst.dtd.core.internal.emf.DTDFactory)2 Enumeration (java.util.Enumeration)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 ErrorMessage (org.eclipse.wst.dtd.core.internal.saxparser.ErrorMessage)1