FileDocCategorySizeDatePackage
CountMembers.javaAPI DocExample6984Tue Dec 08 01:21:00 GMT 1998oisoft.togetherx.scripts

CountMembers

public class CountMembers extends Object implements Script, ScriptResources

Fields Summary
private UMLPackage
umlRootPackage
private StringBuffer
strBuff
private PrintWriter
outputFile
private static String
strEOL
Constructors Summary
Methods Summary
private voidaddComponentToOutputBuf(java.lang.String strComponentType, java.lang.String strComponentName)

    if (! strComponentType.equals("") ) strBuff.append( strComponentType );
    if (! strComponentName.equals("") ) strBuff.append( strComponentName );
    addLine();
  
private voidaddLine()

    strBuff.append( strEOL );
  
private voidattributesProcessing(UMLAttributeEnumeration umlAttributeEnumeration)

    int iCountAttributes = 0;
    while( umlAttributeEnumeration.hasMoreElements() ){
      UMLAttribute umlAttribute = umlAttributeEnumeration.getNextUMLAttribute();
      iCountAttributes ++;
    }
    // write couunt attributes to output buffer
    String strCount = "" + iCountAttributes;
    addComponentToOutputBuf( "  Number of attributes : ", strCount );
  
private voidclassDiagramContentsProcessing(UMLPackage umlPackage)

    // classes processing
    UMLClassEnumeration umlClassEnum = ((UMLClassDiagram)(umlPackage)).getClasses();
    addLine();
    addLine();
    addComponentToOutputBuf( "", umlPackage.toLongString() );
    if ( umlClassEnum.hasMoreElements() ) {
      addComponentToOutputBuf( "CLASSES :","");
      addLine();
    }
    while( umlClassEnum.hasMoreElements() ){
      UMLClassifier umlClassifier = (UMLClassifier) umlClassEnum.getNextUMLClass();
      classifierProcessing( umlClassifier );
    }
    // interfaces processing
    UMLInterfaceEnumeration umlInterfaceEnum = ((UMLClassDiagram)(umlPackage)).getInterfaces();
    if ( umlInterfaceEnum.hasMoreElements() ) {
      addLine();
      addComponentToOutputBuf( "INTERFACES :","");
    }
    while( umlInterfaceEnum.hasMoreElements() ){
      UMLClassifier umlClassifier = (UMLClassifier) umlInterfaceEnum.getNextUMLInterface();
      classifierProcessing( umlClassifier );
    }
  
private voidclassifierProcessing(UMLClassifier umlClassifier)

    addComponentToOutputBuf( " ",umlClassifier.getName());
    // operations processing
    UMLOperationEnumeration umlOperationEnumeration = umlClassifier.getOperations();
    operationsProcessing( umlOperationEnumeration );
    // attributes processing
    UMLAttributeEnumeration umlAttributeEnumeration = umlClassifier.getAttributes();
    attributesProcessing( umlAttributeEnumeration );
  
public voiddoIt(APIManager apiManager)

    umlRootPackage = apiManager.getUMLModel().getRootPackage();
    if ( umlRootPackage == null ){
      apiManager.createMessage("CountMembers",  "Root package is null ", "Error");
      return;
    }
    try{
      String outputStreamName = apiManager.getOutputStream(".txt");
      if (outputStreamName != null){
        txtFileCreater( outputStreamName );
        modelProcessing( umlRootPackage );
        txtFileClose();
        apiManager.openExternalViewer(outputStreamName);
        System.out.println( "Done" );
      }
    }
    catch( Exception e ){
       e.printStackTrace();
    }
  
public java.lang.StringgetMenuItem()

  //------------------------------------------------------------------------------
     
     return "CountMembers...|T";
  
private voidmodelProcessing(UMLPackage umlPackage)

    classDiagramContentsProcessing( umlPackage );
    UMLClassDiagramEnumeration classDiagrams = umlPackage.getClassDiagrams();
    while ( classDiagrams.hasMoreElements()){
      UMLPackage umlNextPackage = classDiagrams.getNextUMLClassDiagram();
      modelProcessing( umlNextPackage );
  	}
  
private voidoperationsProcessing(UMLOperationEnumeration umlOperationEnumeration)

    int iCountOperation = 0;
    while( umlOperationEnumeration.hasMoreElements() ) {
      UMLOperation umlOperation = umlOperationEnumeration.getNextUMLOperation();
      iCountOperation ++;
    }
    // write couunt operations to output buffer
    String strCount = "" + iCountOperation;
    addComponentToOutputBuf( "  Number of operations : ", strCount );
  
private voidtxtFileClose()

    String strDocumentation = new String( strBuff );
    if (! strDocumentation.equals("")) outputFile.println( strDocumentation );
    outputFile.println ( "" );
    outputFile.println ( "---------- End of document ----------" );
    outputFile.flush ();
    outputFile.close ();
  
private voidtxtFileCreater(java.lang.String strFullName)

    try{
      outputFile = new PrintWriter( new FileWriter( strFullName ));
      outputFile.println ( " --------------------- " );
      outputFile.println ( " Generated by Together " );
      outputFile.println ( " --------------------- " );
    }
    catch (Exception e){
      e.printStackTrace();
    }