Search in sources :

Example 1 with DTDEnumerationType

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

the class DTDModelBuilder method createDTDEnumeration.

private DTDEnumerationType createDTDEnumeration(DTDAttribute dtdattr, AttNode attdef, int enumKind) {
    DTDEnumerationType enumeration = getFactory().createDTDEnumerationType();
    DTDEnumGroupKind groupKind = DTDEnumGroupKind.get(enumKind);
    enumeration.setKind(groupKind);
    dtdattr.getDTDElement().getDTDFile().getDTDEnumerationType().add(enumeration);
    // Enumeration values
    Enumeration tokenIter = attdef.elements();
    if (tokenIter != null) {
        while (tokenIter.hasMoreElements()) {
            String val = (String) tokenIter.nextElement();
            EEnumLiteral enumLiteral = createEEnumLiteral();
            // enumLiteral.setXMIDocument(dtdattr.getXMIDocument());
            // MOF2EMF Port
            // enumLiteral.refSetLiteral(val);
            enumLiteral.setName(val);
            // enumLiteral.setNumber(i++);
            enumeration.getEnumLiterals().add(enumLiteral);
        }
    }
    return enumeration;
}
Also used : Enumeration(java.util.Enumeration) DTDEnumerationType(org.eclipse.wst.dtd.core.internal.emf.DTDEnumerationType) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) DTDEnumGroupKind(org.eclipse.wst.dtd.core.internal.emf.DTDEnumGroupKind)

Example 2 with DTDEnumerationType

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

the class DTDAttributeImpl method unparse.

public String unparse() {
    StringBuffer result = new StringBuffer(128);
    result.append(getName());
    StringBuffer value = new StringBuffer();
    switch(getDefaultKind().getValue()) {
        case DTDDefaultKind.IMPLIED:
            // $NON-NLS-1$
            value.append("#IMPLIED");
            break;
        case DTDDefaultKind.REQUIRED:
            // $NON-NLS-1$
            value.append("#REQUIRED");
            break;
        case DTDDefaultKind.FIXED:
            String type = getDTDType().toString();
            if (!(type.equals(DTDType.ID) || type.equals(DTDType.IDREF) || type.equals(DTDType.ENUM_NAME_TOKEN_GROUP) || type.equals(DTDType.IDREFS))) {
                // $NON-NLS-1$ //$NON-NLS-2$
                value.append("#FIXED \"").append(getDefaultValueString()).append("\"");
            }
            break;
        case DTDDefaultKind.NOFIXED:
            String defaultValue = getDefaultValueString();
            if (defaultValue != null)
                // $NON-NLS-1$ //$NON-NLS-2$
                value.append("\"").append(defaultValue).append("\"");
            break;
    }
    // Get the attribute type
    DTDEntity typeEnt = getAttributeTypeReferencedEntity();
    if (typeEnt != null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        result.append(" %" + typeEnt.getName() + "; ").append(value);
    } else {
        DTDType dtdType = getDTDType();
        if (dtdType instanceof DTDBasicType) {
            switch(((DTDBasicType) dtdType).getKind().getValue()) {
                case DTDBasicTypeKind.CDATA:
                    // $NON-NLS-1$
                    result.append(" CDATA ").append(value);
                    break;
                case DTDBasicTypeKind.ID:
                    // $NON-NLS-1$
                    result.append(" ID ").append(value);
                    break;
                case DTDBasicTypeKind.IDREF:
                    // $NON-NLS-1$
                    result.append(" IDREF ").append(value);
                    break;
                case DTDBasicTypeKind.IDREFS:
                    // $NON-NLS-1$
                    result.append(" IDREFS ").append(value);
                    break;
                case DTDBasicTypeKind.ENTITY:
                    // $NON-NLS-1$
                    result.append(" ENTITY ").append(value);
                    break;
                case DTDBasicTypeKind.ENTITIES:
                    // $NON-NLS-1$
                    result.append(" ENTITIES ").append(value);
                    break;
                case DTDBasicTypeKind.NMTOKEN:
                    // $NON-NLS-1$
                    result.append(" NMTOKEN ").append(value);
                    break;
                case DTDBasicTypeKind.NMTOKENS:
                    // $NON-NLS-1$
                    result.append(" NMTOKENS ").append(value);
                    break;
            }
        } else if (dtdType instanceof DTDEnumerationType) {
            // $NON-NLS-1$
            result.append(" ").append(buildEnumString((DTDEnumerationType) dtdType)).append(value);
        }
    }
    return result.toString();
}
Also used : DTDBasicType(org.eclipse.wst.dtd.core.internal.emf.DTDBasicType) DTDEnumerationType(org.eclipse.wst.dtd.core.internal.emf.DTDEnumerationType) DTDType(org.eclipse.wst.dtd.core.internal.emf.DTDType) DTDEntity(org.eclipse.wst.dtd.core.internal.emf.DTDEntity)

Example 3 with DTDEnumerationType

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

the class DTDAttributeImpl method getEnumeratedValues.

public Collection getEnumeratedValues() {
    Collection result = new ArrayList();
    DTDType type = getDTDType();
    if (type instanceof DTDEnumerationType) {
        DTDEnumerationType enumType = (DTDEnumerationType) type;
        Iterator i = enumType.getEnumLiterals().iterator();
        while (i.hasNext()) {
            result.add(((EEnumLiteral) i.next()).toString());
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) DTDEnumerationType(org.eclipse.wst.dtd.core.internal.emf.DTDEnumerationType) Iterator(java.util.Iterator) Collection(java.util.Collection) DTDType(org.eclipse.wst.dtd.core.internal.emf.DTDType)

Example 4 with DTDEnumerationType

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

the class DTDAttributeImpl method createDTDEnumeration.

public DTDEnumerationType createDTDEnumeration(String[] enumValues, int enumKind) {
    DTDEnumerationType enumeration = DTDFactoryImpl.instance().createDTDEnumerationType();
    // enum.setID("Enum_" + ((DTDElement)getMOFDomain()).getName() + "_" +
    // getName());
    DTDEnumGroupKind groupKind = DTDEnumGroupKind.get(enumKind);
    enumeration.setKind(groupKind);
    // Enumeration values
    if (enumValues != null) {
        for (int i = 0; i < enumValues.length; i++) {
            EcorePackage ePackage = (EcorePackage) EPackage.Registry.INSTANCE.getEPackage(EcorePackage.eNS_URI);
            EEnumLiteral enumLiteral = ((EcoreFactory) ePackage.getEFactoryInstance()).createEEnumLiteral();
            // MOF2EMF Port
            // enumLiteral.refSetLiteral(enumValues[i]);
            enumLiteral.setName(enumValues[i]);
            // MOF2EMF Port
            // enumLiteral.refSetLiteral(i);
            enumLiteral.setValue(i);
            enumeration.getEnumLiterals().add(enumLiteral);
        }
    }
    getDTDElement().getDTDFile().getDTDEnumerationType().add(enumeration);
    return enumeration;
}
Also used : DTDEnumerationType(org.eclipse.wst.dtd.core.internal.emf.DTDEnumerationType) EcoreFactory(org.eclipse.emf.ecore.EcoreFactory) EcorePackage(org.eclipse.emf.ecore.EcorePackage) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) DTDEnumGroupKind(org.eclipse.wst.dtd.core.internal.emf.DTDEnumGroupKind)

Example 5 with DTDEnumerationType

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

the class DTDModelBuilder method createDTDEnumeration.

public DTDEnumerationType createDTDEnumeration(DTDAttribute dtdattr, String[] enumValues, int enumKind) {
    DTDEnumerationType enumeration = getFactory().createDTDEnumerationType();
    DTDEnumGroupKind groupKind = DTDEnumGroupKind.get(enumKind);
    enumeration.setKind(groupKind);
    // Enumeration values
    if (enumValues != null) {
        for (int i = 0; i < enumValues.length; i++) {
            EEnumLiteral enumLiteral = createEEnumLiteral();
            // enumVal.setXMIDocument(dtdattr.getXMIDocument());
            // MOF2EMF Port
            // enumLiteral.refSetLiteral(enumValues[i]);
            enumLiteral.setName(enumValues[i]);
            // enumLiteral.setNumber(i);
            enumeration.getEnumLiterals().add(enumLiteral);
        }
    }
    dtdattr.getDTDElement().getDTDFile().getDTDEnumerationType().add(enumeration);
    return enumeration;
}
Also used : DTDEnumerationType(org.eclipse.wst.dtd.core.internal.emf.DTDEnumerationType) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) DTDEnumGroupKind(org.eclipse.wst.dtd.core.internal.emf.DTDEnumGroupKind)

Aggregations

DTDEnumerationType (org.eclipse.wst.dtd.core.internal.emf.DTDEnumerationType)5 EEnumLiteral (org.eclipse.emf.ecore.EEnumLiteral)3 DTDEnumGroupKind (org.eclipse.wst.dtd.core.internal.emf.DTDEnumGroupKind)3 DTDType (org.eclipse.wst.dtd.core.internal.emf.DTDType)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Enumeration (java.util.Enumeration)1 Iterator (java.util.Iterator)1 EcoreFactory (org.eclipse.emf.ecore.EcoreFactory)1 EcorePackage (org.eclipse.emf.ecore.EcorePackage)1 DTDBasicType (org.eclipse.wst.dtd.core.internal.emf.DTDBasicType)1 DTDEntity (org.eclipse.wst.dtd.core.internal.emf.DTDEntity)1