FileDocCategorySizeDatePackage
IDL.javaAPI DocExample30222Tue Dec 08 01:21:00 GMT 1998oisoft.togetherx.scripts.idl

IDL

public class IDL extends Object

Fields Summary
private String
strAllElement
private String
strDiagram
private String
strElement
private String
stereotype
private String
idlCode
private String
stereotypeElement
public static String
postfix
private String[]
idlKeywordstoIDLGrammar
private IDLOptioner
optioner
private Hashtable
cppOperatorNames
private Hashtable
javahashtable
private Hashtable
IDLhashtable
private Hashtable
idlPathes
private static final String
idlCOM
private static final String
idlCORBA
private String
language
private String
idlSpecification
private String
memberName
private String
convertedType
private String
compositionIdlType
private String
outputDirectory
private String
projectPath
private String
parameterModificator
private String
startPositionOnString
private oisoft.togetherx.scriptapi.APIManager
apiManager
private boolean
arrayAttribute
private StringBuffer
outBuff
private StringBuffer
exceptions
protected static String
strEOL
Constructors Summary
public IDL(IDLOptioner optioner)

  //--------------------------------------------------------------------------

  //--------------------------------------------------------------------------
      
    this.optioner = optioner;
  
Methods Summary
private voidaddComponentToOutputBuf(java.lang.String componentType, java.lang.String componentName)

    if ( ! componentType.equals("")){
      outBuff.append( strEOL );
      outBuff.append( startPositionOnString + "// " + componentType + strEOL );
      outBuff.append( strEOL );
    }
    else if ( ! componentName.equals("")) {
      if ( optioner.isCorrectType() ){
        outBuff.append( startPositionOnString + componentName + strEOL );
      }
      else{
        optioner.setCorrectType( true );
      }
    }
  
public voidaddCompositionType(java.lang.String type)

    compositionIdlType += type;
  
private voidconvertJavaToIdlType(java.lang.String type)

    StringTokenizer tokens = new StringTokenizer( type, "[" );
    type = tokens.nextToken();
    int iPoint = type.lastIndexOf(".");
    if ( iPoint >= 0 ){
      type = type.substring( iPoint + 1 );
    }
    convertedType = (String) javahashtable.get( type );
    if ( convertedType == null ){
      StringTokenizer strTokenType = new StringTokenizer( type, "*&[]" );
      convertedType = strTokenType.nextToken();
      optioner.putIncludeFile( convertedType );
    }
  
private voidfillCppOperatorsSpecialNamesTable()

    String[] cppGrammar = { "operator++","operator==","operator--" };
    String[] idlGrammar = { "operatorInc", "operatorEqu", "operatorDec" };
    cppOperatorNames = new Hashtable();
    for ( int i=0; i < cppGrammar.length; i++ ){
      cppOperatorNames.put( cppGrammar[i], idlGrammar[i] );
    }
  
private java.lang.StringfindOperator(java.lang.String operationName)

    int iPos = operationName.indexOf("operator");
    if ( iPos >= 0 ){
      String operatorName = operationName.substring( iPos );
      String convertOperator = (String) cppOperatorNames.get( operatorName );
      operationName = operationName.substring( 0, iPos );
      operationName += ( convertOperator == null ) ? "operator" : convertOperator;
    }
  return operationName;
  
public java.lang.StringgetCompositionType()

    return compositionIdlType;
  
private java.lang.StringgetIdlType()

    if ( convertedType == null ) return "";
    else return convertedType;
  
private java.util.HashtablegetIdlhashtable()

    IDLhashtable = new Hashtable();
    for ( int i=0; i < idlKeywordstoIDLGrammar.length; i++ ){
      IDLhashtable.put( idlKeywordstoIDLGrammar[i][0], idlKeywordstoIDLGrammar[i][1]);
    }
    return IDLhashtable;
  
public java.lang.StringgetMemberName()

    return memberName;
  
private java.lang.StringgetOutputPath(java.lang.String fullPath, java.lang.String idlFileName)

    String outPath = "";
    int position = fullPath.lastIndexOf( File.separator );
    if ( position > 0 ) {
      outPath = fullPath.substring(0, position) + File.separator;
    }
    else {
      apiManager.createMessage("IDL","Path of "+ idlFileName +" class(interfase) is unknown .IDL interface is creating to c:" + File.separator +".", "");
      outPath = "c:" + File.separator;
    }
    return outPath;
  
private java.lang.StringgetParameterModificator()

    if ( parameterModificator == null ) return "";
    else return parameterModificator;
  
private java.lang.StringgetPropertyValue(oisoft.togetherx.scriptapi.UML.UMLClassifier umlClassifier, java.lang.String propertyName)

		 UMLPropertyEnumeration properties = umlClassifier.getDocProperties();
		 while ( properties.hasMoreElements() ){
			 UMLProperty property  = properties.getNextUMLProperty();
			 String name   = property.getPropertyName();
			 String value  = property.getPropertyValue();
			 if (( name != null ) && ( name.equals(propertyName))) {
				 if ( value != null) return value;
				 else return "";
			 }
		 }
		 return "";
	 
public voididlFabric(oisoft.togetherx.scriptapi.APIManager apiManager, java.lang.String idlSpecification)

    this.apiManager = apiManager;
    this.idlSpecification = idlSpecification;

    UMLPackage rootPackage = apiManager.getUMLModel().getRootPackage();
    if ( rootPackage == null ){
      apiManager.createMessage("IDL", "Project is not loaded.", "");
      return;
    }
		 if ( rootPackage.getLanguage().equals(UMLElement.OCOBOL)){
      apiManager.createMessage("IDL", "Object Cobol not supported by this script.", "");
      return;
    }

    GenericIDLOptioner idlGenericOptioner = new GenericIDLOptioner();
    apiManager.customize(idlGenericOptioner);

    String strMode = idlGenericOptioner.getProcessedElements();

    javahashtable = optioner.getJavaToIdlTable();
    IDLhashtable  = getIdlhashtable();
    idlPathes     = new Hashtable();
    fillCppOperatorsSpecialNamesTable();

    File projectFile = rootPackage.getFile();
    projectPath = projectFile.getAbsolutePath();
    int pos = projectPath.lastIndexOf(File.separator);
    if (pos > 0) {
      projectPath = projectPath.substring(0,pos+1);
    }
    else{
      projectPath = "c:" + File.separator;
    }

    UMLModel model = apiManager.getUMLModel();
    if ( strMode.equals(strAllElement)){
      processingPackages( rootPackage );
    }
    else if ( strMode.equals(strDiagram)){
      UMLPackage umlPackage = model.getCurrentPackage();
      processingContentsClassDiagram( umlPackage );
    }
    else if ( strMode.equals(strElement)){
      UMLPackage umlPackage = model.getCurrentPackage();
      processingSelectedElements(umlPackage);
    }
  
private booleanisProcessingClassifier(oisoft.togetherx.scriptapi.UML.UMLClassifier umlClassifier)

    String name = umlClassifier.getName();
    if ( name.endsWith( postfix )){
       return true;
    }
    else {
      String message = " businessobject class should have "+ postfix +" postfix.";
      apiManager.createMessage("IDL",name + message,"");
      return false;
    }
  
private booleanisPublic(java.lang.String visibility)

    return (visibility.equals(UMLElement.PUBLIC));
  
private voidprocessingArray(java.lang.String convertType, java.lang.String memberType, java.lang.String initialValue)

     int openBrace  = memberType.indexOf("[");
     int closeBrace = memberType.indexOf("]");
		 if (( openBrace >= 0 ) && ( closeBrace >= 0 )){
      arrayAttribute = true;
			 int iCountElements = 0;
			 try{
				 if( openBrace != ( closeBrace - 1 )){
           String countElements = memberType.substring( openBrace+1, closeBrace );
					 Integer integerCountElements = new Integer( iCountElements );
					 iCountElements = integerCountElements.intValue();
				 }
			 }
			 catch(NumberFormatException e){
				 System.out.println("Integer Exception");
				 e.printStackTrace();
			 }
			 if ( initialValue != null ){
         StringTokenizer tokens = new StringTokenizer( initialValue, "," );
				 iCountElements = tokens.countTokens();
       }
       String type = optioner.getArrayDeclaration( iCountElements, convertType, getMemberName());
       setCompositionType( type );
     }
     else arrayAttribute = false;
  
private voidprocessingAssociation(oisoft.togetherx.scriptapi.UML.UMLAssociation associations)

    UMLAttribute umlAttribute = associations.getAttribute();
    if ( isPublic ( umlAttribute.getVisibility())){
      String destinationName = umlAttribute.getName();
      processingType( umlAttribute.getTypeExpression(), "" );

      StringTokenizer token = new StringTokenizer( compositionIdlType, " " );
      String destinationType = token.nextToken();
//    optioner.putIncludeFile( destinationType );
      String link = optioner.getAttributeTitle() + destinationType + " " + destinationName + ";";
    // write link data to output buffer
      addComponentToOutputBuf( "", link );
    }
  
private voidprocessingAttributes(oisoft.togetherx.scriptapi.UML.UMLClassifier umlClassifier)

    UMLAttributeEnumeration attributes = umlClassifier.getAttributes();
//    if ( attributes.hasMoreElements() )
//      addComponentToOutputBuf( "Attributes", "" );
    while( attributes.hasMoreElements() ){
      UMLAttribute umlAttribute = attributes.getNextUMLAttribute();
      if ( isPublic ( umlAttribute.getVisibility())){

        //Check for use of IDL keyword
				 String name = (String)IDLhashtable.get(umlAttribute.getName());
        String type = umlAttribute.getTypeExpression();
        String initialValue = umlAttribute.getInitialValue();
        processingType( type, initialValue );
        String attributeDeclaration = umlAttribute.isConst() ? "const " : optioner.getAttributeTitle();
        attributeDeclaration +=  getCompositionType() + " " + name + ";";
        addComponentToOutputBuf( "", attributeDeclaration );
      }
    }
  
private voidprocessingClassifier(oisoft.togetherx.scriptapi.UML.UMLClassifier umlClassifier)

    String idlFileName = umlClassifier.getName();
    if ( getPropertyValue(umlClassifier, stereotype).equals(stereotypeElement )){

      if ( isProcessingClassifier(umlClassifier)) {
        language = umlClassifier.getLanguage();
        optioner.createBaseDataTables();
        outBuff      = new StringBuffer();
        exceptions   = new StringBuffer();

        // Generalization processing
        UMLLinkEnumeration links = umlClassifier.getOutgoingLinksByKind( UMLLink.GENERALIZATION );
        processingParents( links );

         // Implementation processing
        links = umlClassifier.getOutgoingLinksByKind( UMLLink.IMPLEMENTATION );
        processingParents( links );

        String parents = "";
        Enumeration files = optioner.getIncludeFiles().elements();
        while ( files.hasMoreElements()){
           parents += parents.equals("") ? "" : ", ";
           parents += (String) files.nextElement();
         }

        // operations processing
        processingOperations( umlClassifier, idlFileName );

        // attributes processing
        if ( idlSpecification.equals( idlCORBA )) processingAttributes( umlClassifier );

        // links processing
        if ( idlSpecification.equals( idlCORBA )) processingClassifierLinks( umlClassifier );
        optioner.putIdlFile( idlFileName );

        // create IDL file for the current class or interface
        if ( language.equals( UMLElement.JAVA )){
          outputDirectory = projectPath;
        }
        else{
          File curentFile = umlClassifier.getFile();
          String fullPath = curentFile.getAbsolutePath();

          String localPath = "";
          String localPackages = umlClassifier.getQualifiedName();

          if (! localPackages.equals("")) {
            StringTokenizer token = new StringTokenizer( localPackages, ".");
            while ( token.hasMoreElements()) {
              localPath += File.separator + token.nextToken() ;
            }
            int position = fullPath.lastIndexOf( localPath );
            if (position > 0){
              outputDirectory = fullPath.substring(0, position) + File.separator;
            }
            else{
              outputDirectory = getOutputPath(fullPath,idlFileName);
            }
          }
          else{
              outputDirectory = getOutputPath(fullPath,idlFileName);
          }
        }
        if ( optioner.creationIdlFile( language, outputDirectory, idlFileName, parents )){
          idlPathes.put( outputDirectory, outputDirectory);  // adding idls path
          optioner.setPackages( umlClassifier.getQualifiedName() );
          optioner.genereateIdlFileTitle();
          if ( idlSpecification.equals( idlCORBA )){
            String propertyValue = getPropertyValue(umlClassifier, idlCode);
            if (! propertyValue.equals("")){
              processingTag(propertyValue);
            }
          }
          optioner.closeIdlFile( outBuff, exceptions );
        }
      }
    }
  
private voidprocessingClassifierLinks(oisoft.togetherx.scriptapi.UML.UMLClassifier classifier)

    UMLLinkEnumeration links = classifier.getOutgoingLinksByKind( UMLAssociation.ASSOCIATION );
    processingLinks( links, "Association links" );
    links = classifier.getOutgoingLinksByKind( UMLAssociation.AGGREGATION );
    processingLinks( links, "Aggregation links" );
    links = classifier.getOutgoingLinksByKind( UMLAssociation.COMPOSITION );
    processingLinks( links, "Composition links" );
  
private voidprocessingContentsClassDiagram(oisoft.togetherx.scriptapi.UML.UMLPackage umlPackage)

    // class processing
    UMLClassEnumeration classes = ((UMLClassDiagram)(umlPackage)).getClasses();
    while( classes.hasMoreElements() ){
      UMLClassifier classifier = (UMLClassifier) classes.getNextUMLClass();
      processingClassifier( classifier );
    }
    // interfaces processing
    UMLInterfaceEnumeration interfaces = ((UMLClassDiagram)(umlPackage)).getInterfaces();
    while( interfaces.hasMoreElements() ){
      UMLClassifier classifier = (UMLClassifier) interfaces.getNextUMLInterface();
      processingClassifier( classifier );
    }
  
private java.lang.StringprocessingException(oisoft.togetherx.scriptapi.UML.UMLOperation umlOperation)

		 UMLClassifierEnumeration umlExceptions = umlOperation.getThrownExceptions();
		 String exception = "";
		 while( umlExceptions.hasMoreElements() ){
			 UMLClassifier umlException = umlExceptions.getNextUMLClassifier();
			 String exceptionName = umlException.getName();

			 String exceptionType = "";
			 if ( language.equals( UMLElement.CPP )){
				 exceptionType = optioner.getConvertedCppType( exceptionName );
			 }
			 else{
				 exceptionType = (String)javahashtable.get( exceptionName );
			 }
			 if ( exceptionType == null) {
				 if ( exceptionName.endsWith( postfix )){
					 int position = exceptionName.lastIndexOf( postfix );
					 exceptionName = exceptionName.substring(0,position);
				 }
				 else continue;
			 }
			 exception += exception.equals("") ? " raises(" : ", ";
			 exception += exceptionName;
			 exceptions.append( "  exception " + exceptionName + " {" + strEOL );
			 exceptions.append( "  };" + strEOL );
		 }
		 if (! exception.equals("")) exception += ")";
	 return exception;
	 
private voidprocessingLinks(oisoft.togetherx.scriptapi.UML.enums.UMLLinkEnumeration links, java.lang.String linkType)

    // write links title to output buffer
    //if ( links.hasMoreElements() ) addComponentToOutputBuf( linkType, "" );
    while ( links.hasMoreElements() ){
      UMLLink umlLink = links.getNextUMLLink();
      UMLAssociation umlAssociation = ( UMLAssociation )umlLink;
      processingAssociation( umlAssociation );
    }
  
private voidprocessingOperations(oisoft.togetherx.scriptapi.UML.UMLClassifier umlClassifier, java.lang.String idlFileName)

		 UMLOperationEnumeration operations = umlClassifier.getOperations();
		 Hashtable listOperations = new Hashtable();
		 //if ( operations.hasMoreElements()){
			 //addComponentToOutputBuf( "Operations", "" );
//    }
    while( operations.hasMoreElements()){
      UMLOperation umlOperation = operations.getNextUMLOperation();
      if ( isPublic( umlOperation.getVisibility())){
        memberName = findOperator( umlOperation.getName()).trim();
        if (( memberName.equals(idlFileName)) ||
            ( memberName.equals( "~" + idlFileName ))){
          apiManager.createMessage("IDL", "Constructor/destructor "+ idlFileName +" not mapped to IDL.", "");
				 }
				 else{
					 String operationName = memberName;
					 String type = umlOperation.getTypeExpression().trim();
					 if ( type.equals("")) setCompositionType("void");
					 else processingType( type, "" );
					 String operationType = getCompositionType();


					 String strNameClash = findOperator( umlOperation.getName() );
					 String strName = (String)IDLhashtable.get(strNameClash);
					 //Check for use of IDL keyword
					 if (strName == null) strName = strNameClash;
					 //Check if operation has already been defined
					 //No overloading in IDL
					 if (listOperations.containsKey(strName)) {
             apiManager.createMessage("IDL", "Overloaded operation "+ strName +" not mapped to IDL.", "");
					 }
					 else {

						 listOperations.put(strName,strName);
						 String exception = idlSpecification.equals( idlCORBA ) ? processingException( umlOperation ) : "";
						 String parameters    = processingParameters( umlOperation.getParameterList());
						 String operation     = optioner.getOperationDeclaration(operationType, operationName, parameters, exception);

						 // write operations data to output buffer
						 addComponentToOutputBuf( "", operation );
					 }
				 }
			 }
    }
  
private voidprocessingPackages(oisoft.togetherx.scriptapi.UML.UMLPackage umlPackage)

    processingContentsClassDiagram( umlPackage );
    UMLClassDiagramEnumeration classDiagrams = umlPackage.getClassDiagrams();
    while ( classDiagrams.hasMoreElements()){
      UMLPackage classDiagram = classDiagrams.getNextUMLClassDiagram();
      if (! classDiagram.hasProperty("$imported"))  processingPackages( classDiagram );
  	}
  
private java.lang.StringprocessingParameter(java.lang.String parameter)

    String idlParameter = "";
    String memberType = "";
    int finishSpace = parameter.lastIndexOf( " " );
    int startSpace  = parameter.indexOf( " " );
    if (( startSpace > 0 ) && ( startSpace != finishSpace )){
      String type = parameter.substring(0, finishSpace);
      StringTokenizer token = new StringTokenizer(type, " ");
      while ( token.hasMoreElements()) memberType += token.nextToken();
    }
    else {
      int startPosition = (startSpace == finishSpace) ? 0 : startSpace + 1;
      memberType = parameter.substring( startPosition, finishSpace );
    }
    memberName = findOperator( parameter.substring( finishSpace+1 ));
    processingType( memberType, "" );
    return optioner.getParameterModificator(memberName, memberType,arrayAttribute) + getCompositionType() + " " + memberName;
  
private java.lang.StringprocessingParameters(java.lang.String parameters)

    String idlParameters = "";
    StringTokenizer tokens = new StringTokenizer( parameters, "," );
    while ( tokens.hasMoreTokens()){
      String token = tokens.nextToken();
      if (! idlParameters.equals("")) idlParameters += ", ";
      String parameter = processingParameter( token );
      idlParameters   +=  parameter;
    }
    return idlParameters;
  
private voidprocessingParents(oisoft.togetherx.scriptapi.UML.enums.UMLLinkEnumeration links)

    while ( links.hasMoreElements() ){
      UMLLink umlLink = links.getNextUMLLink();
      String linkDestinationName = umlLink.getLinkDestination().getName();
      optioner.putIncludeFile( linkDestinationName );
    }
  
private voidprocessingSelectedElements(oisoft.togetherx.scriptapi.UML.UMLPackage umlPackage)

    UMLElementEnumeration elements = umlPackage.getSelectedElements();
    while( elements.hasMoreElements() ){
      UMLElement element = elements.getNextUMLElement();
      if ( element instanceof UMLClassifier ) {
        processingClassifier( (UMLClassifier) element);
      }
    }
  
private voidprocessingTag(java.lang.String idlCode)

    StringTokenizer token = new StringTokenizer(idlCode, "\n");
    String stringValue = "";
    while ( token.hasMoreElements()) {
     stringValue += startPositionOnString + token.nextToken();
    }
    outBuff.insert(0,stringValue);
  
private voidprocessingType(java.lang.String memberType, java.lang.String initialValue)

    setCompositionType("");
    if ((! memberType.equals("")) && ( memberType != null )){
      StringTokenizer tokens = new StringTokenizer( memberType, optioner.getDelimiters());
      String type = "";
      while ( tokens.hasMoreTokens()){
        String token = tokens.nextToken();
				 if ( language.equals( UMLElement.CPP )){
           optioner.convertCppToIdlType( token );
           type = optioner.getIdlType();
        }
        else {
          convertJavaToIdlType(token);
          type = getIdlType();
        }

        if (! type.equals("")){
          int position = type.lastIndexOf( postfix );
          if ( position > 0 ) type = type.substring(0,position);
          if ( getCompositionType().equals("")) setCompositionType( type );
          else addCompositionType( " " + type );
        }
      }
      processingArray( getCompositionType(), memberType, initialValue );
    }
  
public voidsetCompositionType(java.lang.String type)

    compositionIdlType = type;
  
private voidsetParameterModificator(java.lang.String parameterModificator)

    this.parameterModificator = parameterModificator;