com.togethersoft.openapi.rwi
Interface RwiNode


public interface RwiNode
extends RwiContainer

Nodes can contain members and other nodes called subnodes. Examples of nodes are classes, interfaces, use cases, states.
Members keep node's data and usually represent member-like elements. Examples of members are operations and attributes for a class.

members methods returns an enumeration of node's members:


 RwiMemberEnumeration members = someRwiNode.members();
 while (members.hasMoreElements()){
    RwiMember nextMember = members.nextRwiMember();
    if (RwiShapeType.OPERATION.equals(nextMember.getProperty(RwiProperty.SHAPE_TYPE))){
       System.out.println("Node "+someNode.getProperty(RwiProperty.NAME)+" contains operation: "+nextMember.getProperty(RwiProperty.NAME));
    } else if (RwiShapeType.ATTRIBUTE.equals(nextMember.getProperty(RwiProperty.SHAPE_TYPE))){
       System.out.println("Node "+someNode.getProperty(RwiProperty.NAME)+" contains attribute: "+nextMember.getProperty(RwiProperty.NAME));
    }
 }
To distinguish classes and interfaces from other objects represented by RwiNodes, properties RwiProperty.SHAPE_TYPE and RwiProperty.INTERFACE are used:

 if (RwiShapeType.CLASS.equals(someRwiNode.getProperty(RwiProperty.SHAPE_TYPE))){
   if (someRwiNode.hasProperty(RwiProperty.INTERFACE)){
      ... //it is an interface
   } else {
      ... //it is a class
   }
 }
Note that both classes and interfaces have the the same value of the SHAPE_TYPE property, but only interfaces have INTERFACE property.

The method createMemberByPattern can be used to create new members in this node using certain pattern. For example, if this RwiNode represents a class/interface, a new attribute/operation can be created using the RwiPattern.DEFAULT_ATTRIBUTE/ RwiPattern.DEFAULT_OPERATION patterns respectively.

The method createSubnodeByPattern can be used to create a new inner class/interface in this RwiNode (if it represents a class/interface).

Author:
TogetherSoft

Method Summary
 booleancanCreateMember(String shapeType)
           Checks whether it is possible to create a new member with the specified value of RwiProperty.SHAPE_TYPE property.
 booleancanCreateMemberByPattern(String patternName)
           Checks whether it is possible to create a new member using the specified pattern.
 booleancanCreateSubnode(String shapeType)
           Checks whether it is possible to create a new subnode with the specified value of RwiProperty.SHAPE_TYPE property.
 booleancanCreateSubnodeByPattern(String patternName)
           Checks whether it is possible to create a new subnode using the specified pattern.
 RwiMembercreateMember(String shapeType)
           Creates a new member with the specified value of RwiProperty.SHAPE_TYPE property.
 RwiMembercreateMemberByPattern(String patternName)
           Creates a new member using the specified pattern.
 RwiNodecreateSubnode(String shapeType)
           Creates a new subnode with the specified value of RwiProperty.SHAPE_TYPE property.
 RwiNodecreateSubnodeByPattern(String patternName)
           Creates a new subnode using the specified pattern.
 RwiNodegetContainingNode()
           Returns a containing node for this inner node.
 RwiMemberEnumerationmembers()
           Returns an enumeration of all the members this node has.
 RwiNodeEnumerationsubnodes()
           Returns an enumeration of all the subnodes this node has.

Methods inherited from interface com.togethersoft.openapi.rwi.RwiContainer
canPaste, elements, getContainingPackage, paste

Methods inherited from interface com.togethersoft.openapi.rwi.RwiElement
accept, canCreateIncomingLink, canCreateOutgoingLink, canCreateOutgoingLink, canCreateOutgoingLinkByPattern, canCut, canDelete, codeElements, copy, createOutgoingLink, createOutgoingLinkByPattern, cut, delete, getCodeElement, getTimeStamp, getUniqueName, isDeleted, outgoingLinks

Methods inherited from interface com.togethersoft.openapi.rwi.RwiPropertyMap
addProperty, canAddProperty, canSetProperty, canSetProperty, getProperty, hasProperty, isPropertyReadable, isPropertyWritable, properties, properties, setProperty, setProperty

Method Detail

canCreateMember

public boolean canCreateMember(String shapeType)
Checks whether it is possible to create a new member with the specified value of RwiProperty.SHAPE_TYPE property.
Parameters:
shapeType - the string value which needs to be assigned to the member's SHAPE_TYPE property. Cannot be null.
Returns: true if it is possible to create a new member, false otherwise
See Also:
RwiProperty.SHAPE_TYPE

canCreateMemberByPattern

public boolean canCreateMemberByPattern(String patternName)
Checks whether it is possible to create a new member using the specified pattern.
Parameters:
patternName - the string with the name of the pattern beeing used. Some pattern names are defined in the RwiPattern interface.
Returns: true if it is possible to create a new member, false otherwise
See Also:
RwiPattern

canCreateSubnode

public boolean canCreateSubnode(String shapeType)
Checks whether it is possible to create a new subnode with the specified value of RwiProperty.SHAPE_TYPE property.
Parameters:
shapeType - the string value which needs to be assigned to the subnode's SHAPE_TYPE property. Cannot be null.
Returns: true if it is possible to create a new subnode, false otherwise
See Also:
RwiProperty.SHAPE_TYPE

canCreateSubnodeByPattern

public boolean canCreateSubnodeByPattern(String patternName)
Checks whether it is possible to create a new subnode using the specified pattern.
Parameters:
patternName - the string with the name of the pattern being used. Some pattern names are defined in the RwiPattern interface.
Returns: true if it is possible to create a new subnode, false otherwise
See Also:
RwiPattern

createMember

public RwiMember createMember(String shapeType)
Creates a new member with the specified value of RwiProperty.SHAPE_TYPE property.
Parameters:
shapeType - the string value which needs to be assigned to the member's SHAPE_TYPE property. Cannot be null.
Returns: a new just created member
See Also:
RwiProperty.SHAPE_TYPE

createMemberByPattern

public RwiMember createMemberByPattern(String patternName)
Creates a new member using the specified pattern.
Parameters:
patternName - the string with the name of the pattern beeing used. Some pattern names are defined in the RwiPattern interface.
Returns: a new just created member

Examples:

  • To create a new attribute "protected String myAttribute" in the someRwiNode (here we omit the calls to canSetProperty for the sake of simplicity):
     if (RwiShapeType.CLASS.equals(someRwiNode.getProperty(RwiProperty.SHAPE_TYPE))){ //is it a class/inerface?
       //creates a private integer attribute when it is used for a class,
       //or public static final integer attribute when it is used for an interface
       RwiMember newAttribute = someRwiNode.createMemberByPattern(RwiPattern.DEFAULT_ATTRIBUTE);
       newAttribute.setProperty(RwiProperty.NAME, "myAttribute");  //setting the name
       newAttribute.setProperty(RwiProperty.TYPE, "String"); //setting the type
       //Now, if someRwiNode represents an interface, it is useless to to try to make the attribute to be protected.
       newAttribute.setProperty(RwiProperty.PROTECTED, true); //setting the access modifier. In case of interface this line will produce no effect!
     }
     
    You can easily assign an initial value ("TogetherSoft", for example) to this attribute:
     if ( newAttribute.canSetProperty(RwiProperty.INITIAL_VALUE, "\"TogetherSoft\"") ){
       newAttribute.setProperty(RwiProperty.INITIAL_VALUE, "\"TogetherSoft\""); //setting the initial value
     }
     
  • To create a new operation
     protected Object myOperation(String name) { return new String(""); }
     
    (here we omit the calls to canSetProperty for the sake of simplicity):
     if (RwiShapeType.CLASS.equals(someRwiNode.getProperty(RwiProperty.SHAPE_TYPE))){ //is it a class/inerface?
       //creates a private operation for a class; public abstract for an interface
       RwiMember newOperation = someRwiNode.createMemberByPattern(RwiPattern.DEFAULT_OPERATION);
       newOperation.setProperty(RwiProperty.NAME, "myOperation");
       newOperation.setProperty(RwiProperty.PROTECTED, true); //useless if someRwiNode is an interface
       newOperation.setProperty(RwiProperty.RETURN_TYPE, "Object");
       newOperation.setProperty(RwiProperty.PARAMETERS_TEXT, "String name");
       newOperation.setProperty(RwiProperty.BODY, "return new String(\"\");"); //useless if someRwiNode is an interface
     }
     
    Please note that if someRwiNode represents an interface, Together will create only this (no body, and the access modifier is public abstract):
     Object myOperation(String name);
     
See Also:
RwiProperty.INITIAL_VALUE, RwiProperty.TYPE, RwiProperty.RETURN_TYPE, RwiProperty.PARAMETERS_TEXT, RwiProperty.BODY, RwiPattern.DEFAULT_ATTRIBUTE, RwiPattern.DEFAULT_OPERATION, RwiPattern.DEFAULT_CONSTRUCTOR

createSubnode

public RwiNode createSubnode(String shapeType)
Creates a new subnode with the specified value of RwiProperty.SHAPE_TYPE property.
Parameters:
shapeType - the string value which needs to be assigned to the subnode's SHAPE_TYPE property. Cannot be null.
Returns: a new just created subnode
See Also:
RwiProperty.SHAPE_TYPE

createSubnodeByPattern

public RwiNode createSubnodeByPattern(String patternName)
Creates a new subnode using the specified pattern.
Parameters:
patternName - the string with the name of the pattern being used. Some pattern names are defined in the RwiPattern interface.
Returns: a new just created subnode

For example:

  • To create a new protected inner class named "InnerClass" in the someRwiNode you can use the following code:
     if (RwiShapeType.CLASS.equals(someRwiNode.getProperty(RwiProperty.SHAPE_TYPE))){ //is it a class/inerface?
       RwiNode newInnerClass = someRwiNode.createSubnodeByPattern(RwiPattern.DEFAULT_CLASS); //creates a private static class
       newInnerClass.setProperty(RwiProperty.NAME, "InnerClass");
       newInnerClass.setProperty(RwiProperty.STATIC, false);  // we don't need the "static" modifier
       //if someRwiNode represents an interface, the following line is useless, the visibility will remain public
       newInnerClass.setProperty(RwiProperty.PROTECTED, true);  // setting the "protected" modifier
     }
     
  • To create a new protected inner interface named "InnerInterface" in the someRwiNode you can use the following code (the difference is only in the pattern being used):
     if (RwiShapeType.CLASS.equals(someRwiNode.getProperty(RwiProperty.SHAPE_TYPE))){ //is it a class/inerface?
       RwiNode newInnerInterface = someRwiNode.createSubnodeByPattern(RwiPattern.DEFAULT_INTERFACE); //creates a private static interface
       newInnerInterface.setProperty(RwiProperty.NAME, "InnerInterface");
       newInnerInterface.setProperty(RwiProperty.STATIC, false);  // we don't need the "static" modifier
       //if someRwiNode represents an interface, the following line is useless, the visibility will remain public
       newInnerInterface.setProperty(RwiProperty.PROTECTED, true);
     }
     
    See Also:
    RwiPattern.DEFAULT_CLASS, RwiPattern.DEFAULT_INTERFACE

getContainingNode

public RwiNode getContainingNode()
Returns a containing node for this inner node. If this node is not an inner node (like a node representing an inner class/interface), this method will return null:
 //only for inner nodes
 RwiNode superNode = someInnerRwiNode.getContainingNode();
 if ( superNode!=null ) {
   //ok, work with the containing class/interface
 }
 
Returns: a containg node for this inner node

members

public RwiMemberEnumeration members()
Returns an enumeration of all the members this node has. For example:

 RwiMemberEnumeration members = someRwiNode.members();
 while (members.hasMoreElements()){
    RwiMember nextMember = members.nextRwiMember();
    if (RwiShapeType.OPERATION.equals(nextMember.getProperty(RwiProperty.SHAPE_TYPE))){
       System.out.println("Node "+someNode.getProperty(RwiProperty.NAME)+" contains operation: "+nextMember.getProperty(RwiProperty.NAME));
    } else if (RwiShapeType.ATTRIBUTE.equals(nextMember.getProperty(RwiProperty.SHAPE_TYPE))){
       System.out.println("Node "+someNode.getProperty(RwiProperty.NAME)+" contains attribute: "+nextMember.getProperty(RwiProperty.NAME));
    }
 }
Returns: an enumeration of all the members this node has

subnodes

public RwiNodeEnumeration subnodes()
Returns an enumeration of all the subnodes this node has. If this node represents a class/interfaces, this method will return an enumeration of RwiNodes representing inner classes/interfaces:
  RwiNodeEnumeration innerNodes = someRwiNode.subnodes();
  while (innerNodes.hasMoreElements()) {
   RwiNode nextInnerNode = innerNodes.nextRwiNode();
   if ( RwiProperty.CLASS.equals(nextInnerNode.getProperty(RwiProperty.SHAPE_TYPE)) ) { // it is an inner clas/interface
     if ( nextInnerNode.hasProperty(RwiProperty.INTERFACE) ) { //it is an inner interface
     } else  { //it is an inner class
     }
   }
 }
 
Returns: an enumeration of all the subnodes this node has