org.argouml.uml.reveng.java
Class Modeller

java.lang.Object
  extended byorg.argouml.uml.reveng.java.Modeller

public class Modeller
extends Object

Modeller maps Java source code(parsed/recognised by ANTLR) to UML model elements, it applies some of the semantics in JSR26.


Field Summary
private  boolean arraysAsDatatype
          Arrays will be modelled as unique datatypes.
private  Hashtable attributes
          Arbitrary attributes.
private  Object currentPackage
          The package which the currentClassifier belongs to.
private  String currentPackageName
          Last package name used in addPackage().
private  DiagramInterface diagram
           
private  String fileName
          The name of the file being parsed.
private  Import importSession
          Current import session.
private static Logger LOG
          Logger.
private  Object model
          Current working model.
private  boolean noAssociations
          Only attributes will be generated.
private  ParseState parseState
          Keeps the data that varies during parsing.
private  Stack parseStateStack
          Stack up the state when descending inner classes.
 
Constructor Summary
Modeller(Object m, DiagramInterface diag, Import imp, boolean noAss, boolean arraysAsDT, String fName)
          Create a new modeller.
 
Method Summary
 void addAnonymousClass(String type)
          Called from the parser when an anonymous inner class is found.
 void addAttribute(short modifiers, String typeSpec, String name, String initializer, String javadoc)
          Called from the parser when an attribute is found.
 void addBodyToOperation(Object op, String body)
          Called from the parser to add a method body to an operation.
 void addCall(String method, String obj)
          This method currently does nothing.
 void addClass(String name, short modifiers, String superclassName, Vector interfaces, String javadoc)
          Called from the parser when a class declaration is found.
private  Object addClassifier(Object newClassifier, String name, short modifiers, String javadoc)
          Common code used by addClass and addInterface.
 void addComponent()
          This is a mapping from a Java compilation Unit -> a UML component.
private  void addDocumentationTag(Object modelElement, String sJavaDocs)
          Add the javadocs as a tagged value 'documentation' to the model element.
 void addImport(String name)
          Called from the parser when an import clause is found.
 void addInterface(String name, short modifiers, Vector interfaces, String javadoc)
          Called from the parser when an interface declaration is found.
private  void addJavadocTagContents(Object me, String sTagName, String sTagData)
          Add the contents of a single standard javadoc tag to the model element.
 Object addOperation(short modifiers, String returnType, String name, Vector parameters, String javadoc)
          Called from the parser when an operation is found.
 void addPackage(String name)
          Called from the parser when a package clause is found.
private  void cleanModelElement(Object element)
          This classifier was earlier generated by reference but now it is its time to be parsed so we clean out remnants.
private  Object getAbstraction(Object parent, Object child)
          Find an abstraction<> in the model.
private  Object getAssociationEnd(String name, Object mClassifier)
          Find an associationEnd from the currentClassifier to the type specified.
 Object getAttribute(String key)
           
private  Object getAttribute(String name, String initializer, Object mClassifier)
          Find an attribute in the currentClassifier.
private  String getClassifierName(String name)
          Get the classifier name from a fully specified classifier name.
private  Context getContext(String name)
          Get the context for a classifier name that may or may not be fully qualified.
private  DiagramInterface getDiagram()
          Get the current diagram.
private  Object getGeneralization(Object mPackage, Object parent, Object child)
          Find a generalization in the model.
private  Object getMethod(String name)
          Find an operation in the currentClassifier.
private  Object getOperation(String name)
          Find an operation in the currentClassifier.
private  Object getPackage(String name)
          Find a package in the model.
private  String getPackageName(String name)
          Get the package name from a fully specified classifier name.
private  String getRelativePackageName(String packageName)
          Get the relative package name from a fully qualified package name.
private  Object getStereotype(Object me, String name, String baseClass)
          Find the first suitable stereotype with baseclass for a given object.
private  Object getStereotype(String name)
          Get the stereotype with a specific name.
private  Object getTaggedValue(Object element, String name)
          Return the tagged value with a specific tag.
 void popClassifier()
          Called from the parser when a classifier is completely parsed.
private  Object searchPackageInModel(String name)
          Search recursivly for nested packages in the model.
 void setAttribute(String key, Object value)
           
private  void setOwnerScope(Object feature, short modifiers)
          Set the owner scope for a feature.
private  void setTargetScope(Object mAssociationEnd, short modifiers)
          Set the target scope for an association end.
private  void setVisibility(Object element, short modifiers)
          Set the visibility for a model element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static final Logger LOG
Logger.


model

private Object model
Current working model.


diagram

private DiagramInterface diagram

importSession

private Import importSession
Current import session.


currentPackage

private Object currentPackage
The package which the currentClassifier belongs to.


currentPackageName

private String currentPackageName
Last package name used in addPackage(). It is null for classes wich are not packaged. Used in popClassifier() to create diagram for that packaget.


parseState

private ParseState parseState
Keeps the data that varies during parsing.


parseStateStack

private Stack parseStateStack
Stack up the state when descending inner classes.


noAssociations

private boolean noAssociations
Only attributes will be generated.


arraysAsDatatype

private boolean arraysAsDatatype
Arrays will be modelled as unique datatypes.


fileName

private String fileName
The name of the file being parsed.


attributes

private Hashtable attributes
Arbitrary attributes.

Constructor Detail

Modeller

public Modeller(Object m,
                DiagramInterface diag,
                Import imp,
                boolean noAss,
                boolean arraysAsDT,
                String fName)
Create a new modeller.

Parameters:
diag - the interface to the diagram to add nodes and edges to
imp - The current Import session.
noAss - whether associations are modelled as attributes
arraysAsDT - whether darrays are modelled as dataypes
fName - the current file name
m - The model to work with.
Method Detail

getAttribute

public Object getAttribute(String key)
Parameters:
key - the key of the attribute to get
Returns:
the value of the attribute

setAttribute

public void setAttribute(String key,
                         Object value)
Parameters:
key - the key of the attribute
value - the value for the attribute

getDiagram

private DiagramInterface getDiagram()
Get the current diagram.

Returns:
a interface to the current diagram.

addComponent

public void addComponent()
This is a mapping from a Java compilation Unit -> a UML component. Classes are resident in a component. Imports are relationships between components and other classes / packages.

See JSR 26.

Adding components is a little messy since there are 2 cases:

  1. source file has package statement, will be added several times since lookup in addComponent() only looks in the model since the package namespace is not yet known.
  2. source file has not package statement: component is added to the model namespace. the is no package statement so the lookup will always work.
Therefore in the case of (1), we need to delete duplicate components in the addPackage() method.

In either case we need to add a package since we don't know in advance if there will be a package statement.


addPackage

public void addPackage(String name)
Called from the parser when a package clause is found.

Parameters:
name - The name of the package.

addImport

public void addImport(String name)
Called from the parser when an import clause is found.

Parameters:
name - The name of the import. Can end with a '*'.

addClass

public void addClass(String name,
                     short modifiers,
                     String superclassName,
                     Vector interfaces,
                     String javadoc)
Called from the parser when a class declaration is found.

Parameters:
name - The name of the class.
modifiers - A sequence of class modifiers.
superclassName - Zero or one string with the name of the superclass. Can be fully qualified or just a simple class name.
interfaces - Zero or more strings with the names of implemented interfaces. Can be fully qualified or just a simple interface name.
javadoc - The javadoc comment. null or "" if no comment available.

addAnonymousClass

public void addAnonymousClass(String type)
Called from the parser when an anonymous inner class is found.

Parameters:
type - The type of this anonymous class.

addInterface

public void addInterface(String name,
                         short modifiers,
                         Vector interfaces,
                         String javadoc)
Called from the parser when an interface declaration is found.

Parameters:
name - The name of the interface.
modifiers - A sequence of interface modifiers.
interfaces - Zero or more strings with the names of extended interfaces. Can be fully qualified or just a simple interface name.
javadoc - The javadoc comment. "" if no comment available.

addClassifier

private Object addClassifier(Object newClassifier,
                             String name,
                             short modifiers,
                             String javadoc)
Common code used by addClass and addInterface.

Parameters:
newClassifier - Supply one if none is found in the model.
name - Name of the classifier.
modifiers - String of modifiers.
javadoc - The javadoc comment. null or "" if no comment available.
Returns:
The newly created/found classifier.

popClassifier

public void popClassifier()
Called from the parser when a classifier is completely parsed.


addOperation

public Object addOperation(short modifiers,
                           String returnType,
                           String name,
                           Vector parameters,
                           String javadoc)
Called from the parser when an operation is found.

Parameters:
modifiers - A sequence of operation modifiers.
returnType - The return type of the operation.
name - The name of the operation as a string
parameters - A number of vectors, each representing a parameter.
javadoc - The javadoc comment. null or "" if no comment available.
Returns:
The operation.

addBodyToOperation

public void addBodyToOperation(Object op,
                               String body)
Called from the parser to add a method body to an operation. (An operation will have exactly one Java body.)

Parameters:
op - An operation.
body - A method body.

addAttribute

public void addAttribute(short modifiers,
                         String typeSpec,
                         String name,
                         String initializer,
                         String javadoc)
Called from the parser when an attribute is found.

Parameters:
modifiers - A sequence of attribute modifiers.
typeSpec - The attribute's type.
name - The name of the attribute.
initializer - The initial value of the attribute.
javadoc - The javadoc comment. null or "" if no comment available.

getGeneralization

private Object getGeneralization(Object mPackage,
                                 Object parent,
                                 Object child)
Find a generalization in the model. If it does not exist, a new generalization is created.

Parameters:
mPackage - Look in this package.
parent - The superclass.
child - The subclass.
Returns:
The generalization found or created.

getAbstraction

private Object getAbstraction(Object parent,
                              Object child)
Find an abstraction<> in the model. If it does not exist, a new abstraction is created.

Parameters:
parent - The superclass.
child - The subclass.
Returns:
The abstraction found or created.

getPackage

private Object getPackage(String name)
Find a package in the model. If it does not exist, a new package is created.

Parameters:
name - The name of the package.
Returns:
The package found or created.

searchPackageInModel

private Object searchPackageInModel(String name)
Search recursivly for nested packages in the model. So if you pass a package org.argouml.kernel , this method searches for a package kernel, that is owned by a package argouml, which is owned by a package org. This method is required to nest the parsed packages.

Parameters:
name - The fully qualified package name of the package we are searching for.
Returns:
The found package or null, if it is not in the model.

getOperation

private Object getOperation(String name)
Find an operation in the currentClassifier. If the operation is not found, a new is created.

Parameters:
name - The name of the operation.
Returns:
The operation found or created.

getMethod

private Object getMethod(String name)
Find an operation in the currentClassifier. If the operation is not found, a new is created.

Parameters:
name - The name of the method.
Returns:
The method found or created.

getAttribute

private Object getAttribute(String name,
                            String initializer,
                            Object mClassifier)
Find an attribute in the currentClassifier. If the attribute is not found, a new one is created.

Parameters:
name - The name of the attribute.
initializer - The initializer code.
mClassifier - The type, used when checking for existing association.
Returns:
The attribute found or created.

getAssociationEnd

private Object getAssociationEnd(String name,
                                 Object mClassifier)
Find an associationEnd from the currentClassifier to the type specified. If not found, a new is created.

Parameters:
name - The name of the attribute.
mClassifier - Where the association ends.
Returns:
The attribute found or created.

getStereotype

private Object getStereotype(String name)
Get the stereotype with a specific name.

Parameters:
name - The name of the stereotype.
Returns:
The stereotype.

getStereotype

private Object getStereotype(Object me,
                             String name,
                             String baseClass)
Find the first suitable stereotype with baseclass for a given object.

Parameters:
me -
name -
baseClass -
Returns:
the stereotype if found
Throws:
IllegalArgumentException - if the desired stereotypes for the modelelement and baseclass was not found. No stereotype is created.

getTaggedValue

private Object getTaggedValue(Object element,
                              String name)
Return the tagged value with a specific tag.

Parameters:
element - The tagged value belongs to this.
name - The tag.
Returns:
The found tag. A new is created if not found.

cleanModelElement

private void cleanModelElement(Object element)
This classifier was earlier generated by reference but now it is its time to be parsed so we clean out remnants.

Parameters:
element - that they are removed from

getPackageName

private String getPackageName(String name)
Get the package name from a fully specified classifier name.

Parameters:
name - A fully specified classifier name.
Returns:
The package name.

getRelativePackageName

private String getRelativePackageName(String packageName)
Get the relative package name from a fully qualified package name. So if the parameter is 'org.argouml.kernel' the method is supposed to return 'kernel' (the package kernel is in package 'org.argouml').

Parameters:
packageName - A fully qualified package name.
Returns:
The relative package name.

getClassifierName

private String getClassifierName(String name)
Get the classifier name from a fully specified classifier name.

Parameters:
name - A fully specified classifier name.
Returns:
The classifier name.

setVisibility

private void setVisibility(Object element,
                           short modifiers)
Set the visibility for a model element.

Parameters:
element - The model element.
modifiers - A sequence of modifiers which may contain 'private', 'protected' or 'public'.

setOwnerScope

private void setOwnerScope(Object feature,
                           short modifiers)
Set the owner scope for a feature.

Parameters:
feature - The feature.
modifiers - A sequence of modifiers which may contain 'static'.

setTargetScope

private void setTargetScope(Object mAssociationEnd,
                            short modifiers)
Set the target scope for an association end.

Parameters:
mAssociationEnd - The end.
modifiers - A sequence of modifiers which may contain 'static'.

getContext

private Context getContext(String name)
Get the context for a classifier name that may or may not be fully qualified.

Parameters:
name - The classifier name.

addJavadocTagContents

private void addJavadocTagContents(Object me,
                                   String sTagName,
                                   String sTagData)
Add the contents of a single standard javadoc tag to the model element. Usually this will be added as a tagged value. This is called from addDocumentationTag(java.lang.Object, java.lang.String) only.

Parameters:
me - the model element to add to
sTagName - the name of the javadoc tag
sTagData - the contents of the javadoc tag

addDocumentationTag

private void addDocumentationTag(Object modelElement,
                                 String sJavaDocs)
Add the javadocs as a tagged value 'documentation' to the model element. All comment delimiters are removed prior to adding the comment. Added 2001-10-05 STEFFEN ZSCHALER.

Parameters:
modelElement - the model element to which to add the documentation
sJavaDocs - the documentation comment to add ("" or null if no java docs)

addCall

public void addCall(String method,
                    String obj)
This method currently does nothing.

Once we start reverse engineering interactions, this is used.

Parameters:
method - The method name called.
obj - The object it is called in.


ArgoUML © 1996-2004 (20050222)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook