FileDocCategorySizeDatePackage
StructFiller.javaAPI DocExample12754Thu Feb 17 20:00:42 GMT 2000com.togethersoft.modules.genidl

StructFiller

public class StructFiller extends Object
The filler of struct type entities. structs, unions and exceptions are struct type entities.

Fields Summary
public static final int
STRUCT
Modes
public static final int
UNION
public static final int
EXCEPTION
private ScopeProcessor
myScopeProcessor
private com.togethersoft.modules.genidl.idl.ProcessTags
myTagsProcessor
private ConfigLoader
myConfigLoader
private Complainer
myComplainer
private IdlTypeConverter
myTypeConverter
private com.togethersoft.openapi.scriptapi.UML.UMLClassifier
myClassifier
private boolean
isFirst
private boolean
isNested
private String
myIndent
private StringBuffer
myBuffer
private StringBuffer
myModuleBuffer
private com.togethersoft.openapi.scriptapi.UML.UMLClassifier
myWrappingClass
private String
myWrappingClassName
private String
mySwitchTypeSpec
private boolean
isInsideModule
private String
idlModuleName
private String
tempTypes
private int
myMode
Entity switch: is this struct, union or exception filler
private String
myEntityName
Entity name. May differ from classifier name if it matches with a keyword
Constructors Summary
public StructFiller(ScopeProcessor scopeProcessor, com.togethersoft.modules.genidl.idl.ProcessTags tagsProcessor, ConfigLoader configLoader, IdlTypeConverter typeConverter, Complainer complainer)
Constructor.

see
ScopeProcessor
see
idl.ProcessTags
see
IdlTypeConverter
see
Complainer


                      
          
            
            myScopeProcessor = scopeProcessor;
            myTagsProcessor = tagsProcessor;
            myConfigLoader = configLoader;
            myComplainer = complainer;
            myTypeConverter = typeConverter;
            tempTypes = "";
    
Methods Summary
private java.lang.Stringentity()

        switch (myMode) {
            case UNION:
                return "Union";
            case EXCEPTION:
                return "Exception";
        }
        return "Struct";
    
private java.lang.StringgetEntityFile()

        switch (myMode) {
            case UNION:
                return "UNIONS";
            case EXCEPTION:
                return "EXCEPTIONS";
        }
        return "STRUCTS";
    
private java.lang.StringgetEntityName()

        if (myEntityName == null) {
            initEntityName();
        }
        return myEntityName;
    
private java.lang.StringBuffergetGlobalEntityBuffer()

        switch (myMode) {
            case UNION:
                return myScopeProcessor.getGlobalUnionsBuffer();
            case EXCEPTION:
                return myScopeProcessor.getGlobalExceptionsBuffer();
        }
        return myScopeProcessor.getGlobalStructsBuffer();
    
public java.lang.StringBuffergetLocalTypedefs()
Get locally generated typedef declarations.

return
StringBuffer containing newly generated typedefs

        return null; //FIXME
    
private com.togethersoft.openapi.scriptapi.UML.UMLClassifiergetWrappingClass()

        UMLAssociationEnumeration enum = myClassifier.getAssociations();
        UMLAssociation assoc;
        UMLClassifier wrapperClass = null;
        while (enum.hasMoreElements()) {
            assoc = enum.getNextUMLAssociation();
            if (myTagsProcessor.getPropertyValue(assoc, IdlTags.STEREOTYPE).equals(IdlTags.NESTED)) {
                wrapperClass = assoc.getDest();
            }
        }
        return wrapperClass;
    
private voidinitEntityName()

        myEntityName = myClassifier.getName();
        if (IdlKeywords.isKeyword(myEntityName)) {
            myEntityName += "_";
        }
    
private voidinsertEntityHeader(java.lang.StringBuffer buffer)

        String header = "";
        switch (myMode) {
            case STRUCT:
                header = "struct " + getEntityName() + " {\n";
                break;
            case UNION:
                header = "union " + getEntityName() + " switch(" + mySwitchTypeSpec + ") {\n";
                break;
            case EXCEPTION:
                header = "exception " + getEntityName() + " {\n";
                break;
        }
        buffer.append(header);
    
public voidprocess()
Do-it-all.

        myComplainer.produceInheritanceWarnings(myClassifier, entity());
        if (myClassifier.hasProperty(IdlTags.IDLUNIONSELECTOR)) {
            mySwitchTypeSpec = myTagsProcessor.getPropertyValue(myClassifier, IdlTags.IDLUNIONSELECTOR);
        }
        UMLAttributeEnumeration attributes = myClassifier.getAllAttributes();
        idlModuleName = myTagsProcessor.getPropertyValue(myClassifier, IdlTags.IDLMODULE);
        if (idlModuleName != null && !idlModuleName.equals("")) {
            isInsideModule = true;
        }
        insertEntityHeader(myBuffer);
        CaseLabelGenerator labelGenerator = null;
        if (myMode == UNION) {
            try {
                labelGenerator = new CaseLabelGenerator(mySwitchTypeSpec);
            }
            catch(IllegalArgumentException iae) {
                myComplainer.error(entity() + " " + myClassifier.getQualifiedName() + " has invalid switch type, ignored");
                return;
            }
        }
        myWrappingClass = getWrappingClass();
        if (myWrappingClass != null) {
            isNested = true;
            myWrappingClassName = myWrappingClass.getQualifiedName();
        }
        AttributeFiller attributeFiller = new AttributeFiller(myScopeProcessor, myTagsProcessor, myConfigLoader,
            myTypeConverter, myComplainer);
        attributeFiller.setClassifier(myClassifier);
        attributeFiller.setPass(false); // imitate second pass for we need attributes
        attributeFiller.setStruct(true);
        attributeFiller.setLabelGenerator(labelGenerator);
        attributeFiller.setBuffer(myBuffer);
        attributeFiller.setModuleBuffer(myModuleBuffer); // FIXME: make sure one day
        attributeFiller.setIndent(myIndent);
        attributeFiller.process();
        myBuffer.insert(0, attributeFiller.getLocalTypedefs());
        if (!isNested) {
            processStandaloneUnion();
        }
        else {
            processNestedUnion();
        }
    
private voidprocessNestedUnion()

        if (myMode == EXCEPTION) {
            System.err.println("processNestedStruct: adding exception: " + myScopeProcessor.getDestFQ(myWrappingClass, false) +
                "::" + getEntityName() + ", " + myScopeProcessor.getFileName(myWrappingClass));
            myScopeProcessor.addException(myScopeProcessor.getDestFQ(myWrappingClass, false) + "::" + getEntityName(),
                myScopeProcessor.getFileName(myWrappingClass));
        }
        if (isFirst) {
            System.err.println("WRAPPING CLASS = " + myWrappingClass.getName());
            myScopeProcessor.addTypeFromClass(myScopeProcessor.getDestFQ(myWrappingClass, false) + "::" + getEntityName(),
                myScopeProcessor.getFileName(myWrappingClass));
            myBuffer.append("};\n"); // close statements
            StringBuffer curValue = myScopeProcessor.getNestedObjectDeclaration(myScopeProcessor.getDestFQ(myWrappingClass,
                false));
            if (curValue == null) {
                curValue = new StringBuffer();
            }
            if (curValue.equals("")) {
                myScopeProcessor.putNestedObjectDeclaration(myScopeProcessor.getDestFQ(myWrappingClass, false), myBuffer);
            }
            else {
                myScopeProcessor.putNestedObjectDeclaration(myScopeProcessor.getDestFQ(myWrappingClass, false),
                    curValue.append(myBuffer));
            }
            myScopeProcessor.putNestedObject(myScopeProcessor.getDestFQ(myWrappingClass, false), myClassifier);
        }
    
private voidprocessStandaloneUnion()

        if (!isFirst) {
            myBuffer.append("};\n");
        }
        if (!isInsideModule) {
            if (isFirst) {
                if (myMode == EXCEPTION) {
                    myScopeProcessor.addTypeFromClass("::" + getEntityName(), getEntityFile()); // "STRUCTS" and so alike
                }
                else {
                    myScopeProcessor.addException("::" + getEntityName(), "EXCEPTIONS");
                }
                return;
            }
            // FIXME: tempTypes?
            myScopeProcessor.checkInnerTypes(tempTypes, "", getEntityFile());
            if (!myScopeProcessor.getIncludes().equals("")) {
                getGlobalEntityBuffer().insert(0, myScopeProcessor.getIncludes());
            }
            getGlobalEntityBuffer().append(myBuffer);
        }
        else {
            // handle union inside module
            if (isFirst) {
                if (myMode == EXCEPTION) {
                    myScopeProcessor.addException(myScopeProcessor.getDestFQ(myClassifier, false),
                        myScopeProcessor.getFileName(myClassifier));
                }
                else {
                    myScopeProcessor.addTypeFromClass(myScopeProcessor.getDestFQ(myClassifier, false),
                        myScopeProcessor.getFileName(myClassifier));
                }
                return;
            }
            // FIXME: tempTypes ?
            myScopeProcessor.checkInnerTypes(tempTypes, myScopeProcessor.getDestFQ(myClassifier, false),
                myScopeProcessor.getFileName(myClassifier));
            myScopeProcessor.prepareToFillFile();
            String fileName = getEntityName();
            StringBuffer outBuff = new StringBuffer();
            if (myConfigLoader.isUseLongFileNames() && idlModuleName.equals("")) {
                String scopeName = myTagsProcessor.processingTag_idlModule(idlModuleName);
                myScopeProcessor.setFileName(scopeName + fileName);
            }
            else {
                if (!idlModuleName.equals("")) {
                    myTagsProcessor.processingTag_idlModule(idlModuleName);
                }
            }
            myScopeProcessor.createIdlFile(myScopeProcessor.getOutputDirectory());
            myModuleBuffer = new StringBuffer();
            //moduleTypedefs = new String(); FIXME: how come it is not used ever?
            if (!idlModuleName.equals("")) {
                myScopeProcessor.fillModuleStatements(outBuff, idlModuleName);
            }
            myModuleBuffer.append(myBuffer);
            if (!myScopeProcessor.getIncludes().equals("")) {
                outBuff.insert(0, myScopeProcessor.getIncludes());
            }
            myScopeProcessor.closeModules(myTagsProcessor.getPosition());
            myTagsProcessor.resetSettings();
            myScopeProcessor.closeIdlFile(myScopeProcessor.getOutputFileWriter(), outBuff, myClassifier,
                myScopeProcessor.getFileName());
        }
    
public voidsetBuffer(java.lang.StringBuffer buffer)
Sets the buffer to put generated declarations into

        myBuffer = buffer;
    
public voidsetClassifier(com.togethersoft.openapi.scriptapi.UML.UMLClassifier classifier)

        myClassifier = classifier;
    
public voidsetIndent(java.lang.String indent)
Sets base indent level

param
indent String of spaces which is prepended to all generated code.

        myIndent = indent;
    
public voidsetMode(int mode)
Sets fill mode.

param
mode one of STRUCT, UNION or EXCEPTION

        myMode = mode;
    
public voidsetModuleBuffer(java.lang.StringBuffer moduleBuffer)
Sets the buffer to hold module-level typedefs

        myModuleBuffer = moduleBuffer;
    
public voidsetPass(boolean istFirst)
Set which pass is going on.

param
isFirst true if this is a first pass, gathering information

        isFirst = istFirst;