From: Wouter Z. <dra...@us...> - 2004-05-30 22:45:05
|
User: draftdog Date: 04/05/30 15:44:58 Modified: andromda-meta/src/templates MetafacadeLogic.vsl Log: implemented caching operations with arguments, using maps Revision Changes Path 1.11 +80 -5 cartridges/andromda-meta/src/templates/MetafacadeLogic.vsl Index: MetafacadeLogic.vsl =================================================================== RCS file: /cvsroot/andromda/cartridges/andromda-meta/src/templates/MetafacadeLogic.vsl,v retrieving revision 1.10 retrieving revision 1.11 diff -u -w -r1.10 -r1.11 --- MetafacadeLogic.vsl 28 May 2004 03:29:19 -0000 1.10 +++ MetafacadeLogic.vsl 30 May 2004 22:44:57 -0000 1.11 @@ -4,6 +4,9 @@ #set ($packagename = $class.package.fullyQualifiedName) package $packagename; +import java.util.Map; +import java.util.HashMap; + ## calculate metaclass and superclass #if ($class.metaclassDirectDependency) #set ($shieldedMetaclassTypeName = $class.metaclass.fullyQualifiedName) @@ -61,7 +64,7 @@ ## #set ($memberTypeName = $att.type.fullyQualifiedName) #set ($methodName = $att.getterName) -#set ($memberName = "${att.name}${velocityCount}")## postfix with counter to avoid collisions with other members +#set ($memberName = "${att.name}${velocityCount}a")## postfix with counter to avoid collisions with other members #set ($handleMethodName = "handle$str.upperCaseFirstLetter($methodName)") #set ($typedArgumentList = "") #set ($handleMethodPreCondition = "${handleMethodName}${velocityCount}PreCondition()") @@ -100,20 +103,78 @@ // ---------------- real business methods ---------------------- #foreach ( $op in $ops) +#set ($hasArguments = ($op.arguments.isEmpty()==false)) #set ($memberTypeName = $op.type.fullyQualifiedName) #set ($methodName = $op.name) -#set ($memberName = "${methodName}${velocityCount}")## postfix with counter to avoid collisions with other members +#set ($memberName = "${methodName}${velocityCount}o")## postfix with counter to avoid collisions with other members #set ($handleMethodName = "handle$str.upperCaseFirstLetter($methodName)") #set ($typedArgumentList = $op.typedArgumentList) #set ($handleMethodPreCondition = "${handleMethodName}${velocityCount}PreCondition()") #set ($handleMethodPostCondition = "${handleMethodName}${velocityCount}PostCondition()") +#set ($innerClassKey = "$str.upperCaseFirstLetter(${memberName})Key") +#set ($innerClassValue = "$str.upperCaseFirstLetter(${memberName})Value") $op.visibility abstract $memberTypeName ${handleMethodName}($typedArgumentList); - private boolean ${memberName}Set = false; #if ($op.hasReturnType()) +#if ($hasArguments) + private final Map $memberName = new HashMap(4); + + private class $innerClassKey + { +#foreach ($param in $op.arguments) + private $param.type.fullyQualifiedName $param.name; +#end + + public $innerClassKey($typedArgumentList) + { +#foreach ($param in $op.arguments) + this.$param.name = $param.name; +#end + } + + public boolean equals(Object object) + { + if (object instanceof $innerClassKey) + { + $innerClassKey that = ($innerClassKey)object; + return true +#foreach ($param in $op.arguments) + && (this.$param.name == that.$param.name) +#end + ; + } + else + { + return false; + } + } + + /** + * @todo: implement hashCode() + */ + } + + private class $innerClassValue + { + private $memberTypeName value; + + public $innerClassValue($memberTypeName value) + { + this.value = value; + } + + public $memberTypeName getValue() + { + return this.value; + } + } + +#else + private boolean ${memberName}Set = false; private $memberTypeName $memberName; #end +#end private void $handleMethodPreCondition { @@ -126,19 +187,33 @@ public final $memberTypeName ${methodName}($typedArgumentList) { #if($op.hasReturnType()) - // if (${memberName}Set) return $memberName; +#if ($hasArguments) + final Object key = new $innerClassKey($op.argumentNames); + if (${memberName}.containsKey(key)) + return (($innerClassValue)${memberName}.get(key)).getValue(); +#else + if (${memberName}Set) return $memberName; +#end #end ${handleMethodPreCondition}; #if($op.hasReturnType()) +#if ($hasArguments) + ${memberName}.put(key, new $innerClassValue(${handleMethodName}($op.argumentNames))); +#else $memberName = ${handleMethodName}($op.argumentNames); +#end #else ${handleMethodName}($op.argumentNames); #end ${handleMethodPostCondition}; #if($op.hasReturnType()) +#if ($hasArguments) + return (($innerClassValue)${memberName}.get(key)).getValue(); +#else ${memberName}Set = true; return $memberName; #end +#end } #end @@ -153,7 +228,7 @@ ## #set ($memberTypeName = $assocEnd.getterSetterTypeName) #set ($methodName = "get$str.upperCaseFirstLetter($assocEnd.otherEnd.name)") -#set ($memberName = "${methodName}${velocityCount}")## postfix with counter to avoid collisions with other members +#set ($memberName = "${methodName}${velocityCount}r")## postfix with counter to avoid collisions with other members #set ($handleMethodName = "handle$str.upperCaseFirstLetter($methodName)") #set ($typedArgumentList = "") #set ($handleMethodPreCondition = "${handleMethodName}${velocityCount}PreCondition()") |