FileDocCategorySizeDatePackage
IdlTypeConverter.javaAPI DocExample9923Thu Feb 17 20:00:42 GMT 2000com.togethersoft.modules.genidl

IdlTypeConverter

public class IdlTypeConverter extends Object
Type converter. Used to convert standard language types into ones of the IDL.

Fields Summary
private String
myLanguage
private Hashtable
languageToIdlTable
private String[]
idlTypes
private String[]
cppTypes
private String[]
javaTypes
private String[]
javaToIdlTypes
private String[]
cppToIdlTypes
Constructors Summary
public IdlTypeConverter(String language)
Constructor. Language is mandatory.

param
language one of UMLElement.JAVA, UMLElement.CPP
see
com.togethersoft.openapi.scriptapi.UML.UMLElement

        myLanguage = language;
        createLanguageToIdlTable();
    
Methods Summary
private voidcreateLanguageToIdlTable()

        languageToIdlTable = new Hashtable();
        if (getLanguage().equals(UMLElement.CPP)) {
            for (int i = 0; i < (cppToIdlTypes.length); i++) {
                languageToIdlTable.put(cppToIdlTypes[i][0], cppToIdlTypes[i][1]);
            }
        }
        if (getLanguage().equals(UMLElement.JAVA)) {
            for (int i = 0; i < (javaToIdlTypes.length); i++) {
                languageToIdlTable.put(javaToIdlTypes[i][0], javaToIdlTypes[i][1]);
            }
        }
    
public java.lang.StringgetConvertedType(java.lang.String type)
Is to receive converted type to idlType

        String myType = null;
        if (getLanguage().equals(UMLElement.CPP)) {
            myType = getCppType(type.trim());
        }
        else {
            if (getLanguage().equals(UMLElement.JAVA)) {
                myType = getJavaType(type.trim());
            }
        }
        if (myType != null && languageToIdlTable.containsKey(myType)) {
            return (String)languageToIdlTable.get(myType);
        }
        // if unable convert, it's prolly a referenced type
        return null;
    
public java.lang.StringgetCppType(java.lang.String type)
Check for Standard cpp type. It may be : MPoint int - then return int!!!

        //check at next type such : < scope_name > <Standard type>
        int pointer;
        for (int i = 0; i < cppTypes.length; i++) {
            pointer = -1;
            if (type.length() > cppTypes[i].length()) {
                pointer = type.indexOf(" " + cppTypes[i]);
                if (pointer == -1) {
                    pointer = type.indexOf(cppTypes[i] + " ");
                }
            }
            if (type.equals(cppTypes[i]) || pointer != -1) {
                return cppTypes[i]; // ex: "LALA unsigned char"
            }
        }
        return null;
    
public java.lang.StringgetJavaType(java.lang.String type)
Check for Standard Java type. It may be : MPoint int - then return int!!!

        //check at next type such : < scope_name > <Standard type>
        int pointer;
        for (int i = 0; i < javaTypes.length; i++) {
            pointer = -1;
            if (type.length() > javaTypes[i].length()) {
                pointer = type.indexOf(" " + javaTypes[i]);
                if (pointer == -1) {
                    pointer = type.indexOf(javaTypes[i] + " ");
                }
            }
            if (type.equals(javaTypes[i]) || pointer != -1) {
                return javaTypes[i]; // ex: "KAKA unsigned char"
            }
        }
        return null;
    
public java.lang.StringgetLanguage()

        return myLanguage;
    
public java.lang.StringgetStandardIdlType(java.lang.String atype)
Check for Standard idl type. Is return substring of given type( all decl ) if it's Standard type. Ex: int d, f, t => int NOTE : don't used now... only for deep parsing of the tags

        final String type = atype.trim();
        final int typeLength = type.length();
        //check at next type such : < scope_name > <Standard type>
        for (int i = 0; i < idlTypes.length; i++) {
            if (idlTypes[i].equals(type)) {
                return type;
            }
        }
        // check for sequence , fixed.
        if (type.startsWith("sequence") || type.startsWith("fixed")) {
            int counter = 0;
            for (int i = 4; i < typeLength; i++) {
                if (type.charAt(i) == '<") {
                    counter++;
                }
                if (type.charAt(i) == '>") {
                    counter--;
                    if (counter == 0) {
                        return type.substring(0, i + 1);
                    }
                }
            }
        }
        // check for string or wstring
        if (type.startsWith(IdlType.STRING) || type.startsWith(IdlType.WSTRING)) {
            String idlType = "";
            if (type.startsWith("w")) {
                idlType = type.substring(7, typeLength).trim();
            }
            else {
                idlType = type.substring(6, typeLength).trim();
            }
            if (!idlType.startsWith("<")) {
                return type;
            }
            else {
                // " string<20>"
                int counter = 0;
                for (int i = 6; i < typeLength; i++) {
                    if (type.charAt(i) == '<") {
                        counter++;
                    }
                    if (type.charAt(i) == '>") {
                        counter--;
                        if (counter == 0) {
                            return type.substring(0, i + 1);
                        }
                    }
                }
            }
        }
        return null;
    
public voidsetLanguage(java.lang.String lang)

        myLanguage = lang;