XDE中模式驱动的设计与开发(三)

http://tech.ddvip.com   2006年11月25日    社区交流

本文详细介绍XDE中模式驱动的设计与开发(三)

  XDE代码模版的形式很像Jsp或者Asp中使用的形式。你如果对Jsp的机制很了解的话,那么你也可以很容易的理解代码模版的机制了。

  在一个代码模版中,代码被分为两个部分,一部分是直接输出的,不经过任何的处理。另外一个部分是在<%和%>这两个标号之间的脚本内容,通过对参数或者其它元素的处理之后再进行输出。如果Jsp或Asp一样,它也是用简单的<%=var%>来进行变量的输出(var是一个变量)。所有<%和%>之间的内容,是使用脚本语言来编写的。现在XDE中的代码模版只支持Javascript语言。

  下面的一个代码模版的例子选自XDE的在线文档,用以在调试的时候打印对象的当前状态。每一个应用了这个代码模版的方法,将会在调用方法前在控制台输出对象的状态,供调试使用。

<%
// assume: myClass is "this" Class with debug operation
function debugStatements(myClass) {
var attributeCollection = myClass.GetAttributeCollection();
var attributeCollection1= Interfaces.queryInterface(attributeCollection, "com.rational.rms.IRMSElementCollection");
var attributeCount = attributeCollection.getCount();
debugStatements = "";
for (i=1; i<=attributeCount; i++) {
var rmsAttribute = attributeCollection1.GetElementAt(i);
var attrName = rmsAttribute.getName();
%>
System.out.println( "<%=attrName%>" );
<%
}
}
//assume: myOperation is debug operation
function debugOperation(myOperation) {
var thisOperation = Interfaces.queryInterface(myOperation, "com.rational.uml70.IUMLOperation");
var thisClass = thisOperation.GetContainer();
var myClass = Interfaces.queryInterface(thisClass, "com.rational.uml70.IUMLClass");
debugStatements(myClass);
}
var myOperation = Interfaces.queryInterface(thisElement, "com.rational.uml70.IUMLOperation");
debugOperation(myOperation);
// end
%>

  在上面的代码模版中,定义了两个方法debugStatements和debugOperation,debugOperation接受当前元素作为参数,并由其得到debugStatements的参数--一个包含了这个方法的对象,并在debugStatements中输出:System.out.println( "<%=attrName%>" );

责编:豆豆技术应用

正在加载评论...