Listing 1

<UML:Class name = 'XMI_Parser'
  xmi.id = '1'
  visibility = 'public'
  isSpecification = 'false'
  isRoot = 'false'
  isLeaf = 'false'
  isAbstract = 'false'
  isActive = 'false'>
  <UML:Classifier.feature>
   <UML:Operation
    name='createModelFromFile'
    xmi.id = '2'
    visibility ='public'
     isSpecification ='false'
     ownerScope ='instance'
     isQuery = 'false'
     concurrency ='sequential'
     isRoot = 'false'
     isLeaf = 'false'
     isAbstract = 'false'>
     <UML:BehavioralFeature.parameter>
      <UML:Parameter name = 'fileName'
       kind = 'in'
       xmi.id = '3'
       isSpecification ='false' >
        <UML2:TypedElement.type>
          <UML:DataType
           xmi.idref='4'/>
        </UML2:TypedElement.type>
       </UML:Parameter>
       <UML:Parameter name = 'return'
        kind = 'return'
        xmi.id = '5'
        isSpecification ='false'>
        <UML2:TypedElement.type>
         <UML:Class xmi.idref = '6'/>
        </UML2:TypedElement.type>
       </UML:Parameter>
     </UML:BehavioralFeature.parameter>
   </UML:Operation>
   <UML:Method xmi.id = '7'
    isSpecification='false'
    isQuery = 'false'>
   <UML:Method.body>
    <UML:ProcedureExpression
     xmi.id='8'
     language = 'java'
     body =''/>
   </UML:Method.body>
   <UML:Method.specification>
    <UML:Operation xmi.idref = '9'/>
    </UML:Method.specification>
   </UML:Method>
  </UML:Classifier.feature>
</UML:Class>

Listing 2

<cffunction
	name="XMI_to_model"
	access="public"
	returntype="model"
	hint="reads in an XMI file and
    returns a fully populated model"
	output="no"
>

<cfargument 
	name="filePath"
	type="string"
	required="yes"
	hint="fully qualified path on the
    server containing a valid
    XMI document"
/>

<cffile action="read"
    file="#arguments.filePath#"
    variable="myfile"
/>
<cfscript>
//setup an empty model
var myModel=createObject
   ('component','Model').init();

var xmlDoc = xmlparse(myfile);

//extract the data from the XML
var classes =xmlsearch(xmlDoc,
  "//UML:Class[@xmi.id]"
);
var cLen=arraylen(classes);
var i=1;

//loop over the classes---------------
for(i=1; i lte cLen;i=i+1){
  thisClass = classes[i];
  //add class to model
  myModel.addComponent(
    name=thisClass.XmlAttributes.name
  );
  //see sample3
  myModel=populateProps(
    myModel,
    thisClass,
    xmlDoc
  );
 
  //see sample4
  myModel=populateFuncs(
    myModel,
    thisClass,
    xmlDoc
  );
}
return myModel;
</cfscript>
</cffunction>

Listing 3

<cffunction 
  name="populateProps"
  access="private"
  returntype="model"
  hint="inserts property information
        into a Model object"
  output="no"
>

<cfargument
  name="model"
  type="Model" 
  required="yes"
  hint="the Model to populate"
/>
<cfargument
  name="class"
  type="xml"
  required="yes"
  hint="the xml element representing
        the class containing properties"
/>
<cfargument
  name="xmlDoc"
  type="xml"
  required="yes"
  hint="xml object containing all info
        on the packages being modelled"
/>

<cfscript>
var thisProperty = '';
var propType  ='';
var myModel   = arguments.model;
var thisClass = arguments.class;
var xmlDoc    = arguments.xmlDoc;

var properties =xmlsearch(thisClass,
  'UML:Classifier.feature/UML:Attribute'
);

var len_props=arraylen(properties);
var i =1;

for(i=1;i lte len_props;i=i+1){
  thisProperty =properties[i];

  //this function uses xmi.idref to
  //lookup the name of the CF type
  propType=
  lookupType(thisProperty,xmlDoc);

  //add property to class' model
  myModel.addProperty(
    componentname=
    thisClass.XmlAttributes.name,
 
    name=
    thisProperty.XmlAttributes.name,

    displayname='',
    type='#propType#',
    required='no',
    default='',
    hint='',
  );
  //some of these attributes may be
  //hard to support in the diagram
}
return myModel;
</cfscript>
</cffunction>

Listing 4

<cffunction
  name="populateFuncs"
  access="private"
  returntype="model"
  hint="inserts function information
        into a Model object"
  output="no"
>

<cfargument
  name="model"
  type="Model" 
  required="yes"
  hint="the Model to populate"
/>
<cfargument
  name="class"
  type="xml"
  required="yes"
  hint="the xml element representing
        the class containing properties"
/>
<cfargument
  name="xmlDoc"
  type="xml"
  required="yes"
  hint="xml object containing all info
        on the packages being modelled"
/>

<cfscript>
var methods='';
var thisMethod='';
var len_methods =0;
var returntype='';
var returntypeElement='';

var arguments='';
var thisArg='';
var len_arguments=0;
var thisArgType='';

var i=1;
var j=1;

methods =xmlsearch(thisClass,
  'UML:Classifier.feature/UML:Operation'
);

len_methods = arraylen(methods);

for(i=1;i lte len_methods;i=i+1){
  thisMethod= methods[i];
  returntypeElement=
    xmlsearch(
      thisMethod,
     "UML:BehavioralFeature.parameter
      /UML:Parameter[@kind= 'return']"
    );

  //use a helper method to lookup the
  //related xmi.idref
  returntype=
    lookupType(thisMethod,xmlDoc);

  //add methods to class' model
  myModel.addMethod(
    componentname=
      thisClass.XmlAttributes.name,
    name=
      thisMethod.XmlAttributes.name,
    access='public',
    returnType=returntype,
    roles='',
    hint='',
    output='no',
  );
 
  //get arguments for method
  arguments =
    xmlsearch(
      thisMethod,
     'UML:BehavioralFeature.parameter
      /UML:Parameter'
    );
  //loop over arg list
  len_arguments= arraylen(arguments);
  for(j=1;j lte len_arguments;j=j+1){
    thisArg = arguments[j];
    if(thisArg.XmlAttributes.kind
       neq 'return'
    ){
      thisArgType=
      lookupType(thisArg,xmlDoc);

      //add arg to method
      myModel.addArgument(
        componentname=
          thisClass.XmlAttributes.name,
        methodname=
          thisMethod.XmlAttributes.name,
        name=
          thisArg.XmlAttributes.name,
        ordinality=j,
        type=thisArgType,
        required='no',
        default='',
        hint='',
      );
    }
  }
}
</cfscript>
</cffunction>