| |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
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).
| Method Summary | |
boolean | canCreateMember(String shapeType)Checks whether it is possible to create a new member with the specified value of RwiProperty.SHAPE_TYPE property. |
boolean | canCreateMemberByPattern(String patternName)Checks whether it is possible to create a new member using the specified pattern. |
boolean | canCreateSubnode(String shapeType)Checks whether it is possible to create a new subnode with the specified value of RwiProperty.SHAPE_TYPE property. |
boolean | canCreateSubnodeByPattern(String patternName)Checks whether it is possible to create a new subnode using the specified pattern. |
RwiMember | createMember(String shapeType)Creates a new member with the specified value of RwiProperty.SHAPE_TYPE property. |
RwiMember | createMemberByPattern(String patternName)Creates a new member using the specified pattern. |
RwiNode | createSubnode(String shapeType)Creates a new subnode with the specified value of RwiProperty.SHAPE_TYPE property. |
RwiNode | createSubnodeByPattern(String patternName)Creates a new subnode using the specified pattern. |
RwiNode | getContainingNode()Returns a containing node for this inner node. |
RwiMemberEnumeration | members()Returns an enumeration of all the members this node has. |
RwiNodeEnumeration | subnodes()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 |
public boolean canCreateMember(String shapeType)
RwiProperty.SHAPE_TYPE property.SHAPE_TYPE property. Cannot be
null.true if it is possible to create a new member, false otherwisepublic boolean canCreateMemberByPattern(String patternName)
RwiPattern interface.true if it is possible to create a new member, false otherwisepublic boolean canCreateSubnode(String shapeType)
RwiProperty.SHAPE_TYPE property.SHAPE_TYPE property. Cannot be
null.true if it is possible to create a new subnode, false otherwisepublic boolean canCreateSubnodeByPattern(String patternName)
RwiPattern interface.true if it is possible to create a new subnode, false otherwisepublic RwiMember createMember(String shapeType)
RwiProperty.SHAPE_TYPE property.SHAPE_TYPE property. Cannot be
null.public RwiMember createMemberByPattern(String patternName)
RwiPattern interface.Examples:
"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
}
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);
public RwiNode createSubnode(String shapeType)
RwiProperty.SHAPE_TYPE property.SHAPE_TYPE property. Cannot be
null.public RwiNode createSubnodeByPattern(String patternName)
RwiPattern interface.For example:
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
}
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);
}
public RwiNode getContainingNode()
null:
//only for inner nodes
RwiNode superNode = someInnerRwiNode.getContainingNode();
if ( superNode!=null ) {
//ok, work with the containing class/interface
}
public RwiMemberEnumeration 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));
}
}public RwiNodeEnumeration subnodes()
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
}
}
}
| |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||