Hướng phát triển trong tương lai

Một phần của tài liệu Kiểm chứng đặt tả uml cho tác tử phần mềm (Trang 80 - 93)

Từ những vấn đề tồn tại của khóa luận này, trong tương lai tôi sẽ tiếp tục hướng nghiên cứu này nhằm xây dựng hoàn thiện công cụProtocol Verification Generatorđể đáp ứng mọi yêu cầu. Hướng nghiên cứu gần nhất là phát triển công cụđể PVG để có giải quyết triệt để các giao thức ràng buộc phức tạp như tiền điều kiện, hậu điều kiện, giao thức AnBn, giao thức AnBf(n) trong đó f(n) là một hàm nào đó phụ thuộc vào n, giao thức AnBmCf(n,m)trong đó f(n,m) là hàm phụ thuộc vào nm. Bên cạnh đó, tôi sẽ

nghiên cứu và tìm ra các phương pháp sinh mã aspect ki ểm chứng không chỉ phụ

thuộc vào tài liệu XMI mà còn phụ thuộc vào các ràng buộc điều kiện được đặc tả bởi các dạng dữ liệu khác nhằm tăng tính ứng dụng của công cụ PVG đối với công nghệ

73

Ph lc

Ph lc A: Tài liu XMI mô t biểu đồ trng thái UML

<?xml version = "1.0" encoding = "UTF-8"?>

<XMI xmi.version = "1.1" xmlns:UML="href://org.omg/UML/1.3" timestamp =

"Mon May 18 17:41:3 2009"> <XMI.header> <XMI.documentation> <XMI.owner></XMI.owner> <XMI.contact></XMI.contact> <XMI.exporter>StarUML.XMI-Addin</XMI.exporter> <XMI.exporterVersion>1.0</XMI.exporterVersion> <XMI.notice></XMI.notice> </XMI.documentation>

<XMI.metamodel xmi.name = "UML" xmi.version = "1.3"/> </XMI.header>

<XMI.content>

<UML:Model xmi.id="UMLProject.1"> <UML:Namespace.ownedElement>

<UML:Model xmi.id="UMLModel.2" name="Dummy Model" visibility="public"

isSpecification="false" namespace="UMLProject.1" isRoot="false"

isLeaf="false" isAbstract="false"> <UML:Namespace.ownedElement>

<UML:Model xmi.id="UMLModel.3" name="Model1" visibility="public"

isSpecification="false" namespace="UMLModel.2" isRoot="false"

isLeaf="false" isAbstract="false"> <UML:Namespace.ownedElement>

<UML:StateMachine xmi.id="UMLStateMachine.4"

name="StateMachine1" visibility="public" isSpecification="false"

context="UMLModel.3">

<UML:StateMachine.top>

<UML:CompositeState xmi.id="UMLCompositeState.5" name="TOP"

visibility="public" isSpecification="false"

stateMachine="UMLStateMachine.4" isConcurrent="false"> <UML:CompositeState.subvertex>

<UML:Pseudostate xmi.id="UMLPseudostate.6"

name="Initial" visibility="public" isSpecification="false"

container="UMLCompositeState.5" outgoing="UMLTransition.11"

kind="initial"/>

<UML:SimpleState xmi.id="UMLCompositeState.7"

name="State1" visibility="public" isSpecification="false" (adsbygoogle = window.adsbygoogle || []).push({});

container="UMLCompositeState.5" outgoing="UMLTransition.12"

incoming="UMLTransition.11"/>

<UML:SimpleState xmi.id="UMLCompositeState.8"

name="State2" visibility="public" isSpecification="false"

container="UMLCompositeState.5" outgoing="UMLTransition.13"

incoming="UMLTransition.12 UMLTransition.14"/>

<UML:SimpleState xmi.id="UMLCompositeState.9"

name="State3" visibility="public" isSpecification="false"

container="UMLCompositeState.5" outgoing="UMLTransition.14 UMLTransition.15" incoming="UMLTransition.13"/>

<UML:FinalState xmi.id="UMLFinalState.10"

name="FinalState" visibility="public" isSpecification="false"

container="UMLCompositeState.5" incoming="UMLTransition.15"/> </UML:CompositeState.subvertex>

</UML:CompositeState> </UML:StateMachine.top>

74

<UML:StateMachine.transitions>

<UML:Transition xmi.id="UMLTransition.11" name="void init()" visibility="public" isSpecification="false"

stateMachine="UMLStateMachine.4" source="UMLPseudostate.6"

target="UMLCompositeState.7"/>

<UML:Transition xmi.id="UMLTransition.12" name="void start(int a, int b)" visibility="public" isSpecification="false"

stateMachine="UMLStateMachine.4" source="UMLCompositeState.7"

target="UMLCompositeState.8">

<UML:Transition.guard>

<UML:Guard xmi.id="X.16" transition="UMLTransition.12"> <UML:Guard.expression>

<UML:BooleanExpression xmi.id="X.17" body="a &gt;= b"/>

</UML:Guard.expression> </UML:Guard>

</UML:Transition.guard> </UML:Transition>

<UML:Transition xmi.id="UMLTransition.13" name="void stop()" visibility="public" isSpecification="false"

stateMachine="UMLStateMachine.4" source="UMLCompositeState.8"

target="UMLCompositeState.9"/>

<UML:Transition xmi.id="UMLTransition.14" name="void start()" visibility="public" isSpecification="false" (adsbygoogle = window.adsbygoogle || []).push({});

stateMachine="UMLStateMachine.4" source="UMLCompositeState.9"

target="UMLCompositeState.8"/>

<UML:Transition xmi.id="UMLTransition.15" name="void destroy()" visibility="public" isSpecification="false"

stateMachine="UMLStateMachine.4" source="UMLCompositeState.9"

target="UMLFinalState.10"/> </UML:StateMachine.transitions> </UML:StateMachine> </UML:Namespace.ownedElement> </UML:Model> </UML:Namespace.ownedElement> </UML:Model> </UML:Namespace.ownedElement> </UML:Model> </XMI.content> </XMI>

75

Ph lc B: Tài liu XMI mô t biểu đồ trình t UML

<?xml version = "1.0" encoding = "UTF-8"?>

<XMI xmi.version = "1.1" xmlns:UML="href://org.omg/UML/1.3" timestamp =

"Mon May 18 17:44:49 2009"> <XMI.header> <XMI.documentation> <XMI.owner></XMI.owner> <XMI.contact></XMI.contact> <XMI.exporter>StarUML.XMI-Addin</XMI.exporter> <XMI.exporterVersion>1.0</XMI.exporterVersion> <XMI.notice></XMI.notice> </XMI.documentation>

<XMI.metamodel xmi.name = "UML" xmi.version = "1.3"/> </XMI.header>

<XMI.content>

<UML:Model xmi.id="UMLProject.1"> <UML:Namespace.ownedElement>

<UML:Model xmi.id="UMLModel.2" name="Model1" visibility="public"

isSpecification="false" namespace="UMLProject.1" isRoot="false"

isLeaf="false" isAbstract="false"> <UML:Namespace.ownedElement>

<UML:Collaboration xmi.id="UMLCollaborationInstanceSet.3"

name="CollaborationInstanceSet1" visibility="public"

isSpecification="false">

<UML:Collaboration.interaction>

<UML:Interaction xmi.id="UMLInteractionInstanceSet.4"

name="InteractionInstanceSet1" visibility="public" isSpecification="false"

context="UMLCollaborationInstanceSet.3"> <UML:Interaction.message>

<UML:Message xmi.id="UMLStimulus.5" name="debit"

visibility="public" isSpecification="false" sender="UMLObject.15"

receiver="UMLObject.15" interaction="UMLInteractionInstanceSet.4"> <UML:Message.action>

<UML:CallAction xmi.id="UMLCallAction.6" name=""

visibility="public" isSpecification="false" isAsynchronous="false"

stimulus="UMLStimulus.5"/>

</UML:Message.action> </UML:Message> (adsbygoogle = window.adsbygoogle || []).push({});

<UML:Message xmi.id="UMLStimulus.7" name="getBalance"

visibility="public" isSpecification="false" sender="UMLObject.15"

receiver="UMLObject.16" interaction="UMLInteractionInstanceSet.4"> <UML:Message.action>

<UML:CallAction xmi.id="UMLCallAction.8" name=""

visibility="public" isSpecification="false" isAsynchronous="false"

stimulus="UMLStimulus.7"/>

</UML:Message.action> </UML:Message>

<UML:Message xmi.id="UMLStimulus.9" name="queryB"

visibility="public" isSpecification="false" sender="UMLObject.16"

receiver="UMLObject.16" interaction="UMLInteractionInstanceSet.4"> <UML:Message.action>

<UML:CallAction xmi.id="UMLCallAction.10" name=""

visibility="public" isSpecification="false" isAsynchronous="false"

stimulus="UMLStimulus.9"/>

</UML:Message.action> </UML:Message>

<UML:Message xmi.id="UMLStimulus.11" name="setBalance"

visibility="public" isSpecification="false" sender="UMLObject.15"

76

<UML:Message.action>

<UML:CallAction xmi.id="UMLCallAction.12" name=""

visibility="public" isSpecification="false" isAsynchronous="false"

stimulus="UMLStimulus.11"/>

</UML:Message.action> </UML:Message>

<UML:Message xmi.id="UMLStimulus.13" name="updateB"

visibility="public" isSpecification="false" sender="UMLObject.16"

receiver="UMLObject.16" interaction="UMLInteractionInstanceSet.4"> <UML:Message.action>

<UML:CallAction xmi.id="UMLCallAction.14" name=""

visibility="public" isSpecification="false" isAsynchronous="false"

stimulus="UMLStimulus.13"/> </UML:Message.action> </UML:Message> </UML:Interaction.message> </UML:Interaction> </UML:Collaboration.interaction> <UML:Namespace.ownedElement>

<UML:ClassifierRole xmi.id="UMLObject.15" name="Account"

visibility="public" isSpecification="false" message2="UMLStimulus.5 UMLStimulus.7 UMLStimulus.11" message1="UMLStimulus.5" isRoot="false" (adsbygoogle = window.adsbygoogle || []).push({});

isLeaf="false" isAbstract="false">

<UML:ClassifierRole.multiplicity> <UML:Multiplicity xmi.id="X.25"> <UML:Multiplicity.range>

<UML:MultiplicityRange xmi.id="X.26" lower="1"

upper="1" multiplicity="X.25"/>

</UML:Multiplicity.range> </UML:Multiplicity>

</UML:ClassifierRole.multiplicity> </UML:ClassifierRole>

<UML:ClassifierRole xmi.id="UMLObject.16" name="DBManager"

visibility="public" isSpecification="false" message2="UMLStimulus.9 UMLStimulus.13" message1="UMLStimulus.7 UMLStimulus.9 UMLStimulus.11 UMLStimulus.13" isRoot="false" isLeaf="false" isAbstract="false"> <UML:ClassifierRole.multiplicity>

<UML:Multiplicity xmi.id="X.27"> <UML:Multiplicity.range>

<UML:MultiplicityRange xmi.id="X.28" lower="1"

upper="1" multiplicity="X.27"/> </UML:Multiplicity.range> </UML:Multiplicity> </UML:ClassifierRole.multiplicity> </UML:ClassifierRole> </UML:Namespace.ownedElement> </UML:Collaboration> </UML:Namespace.ownedElement> </UML:Model> </UML:Namespace.ownedElement> </UML:Model>

<UML:TaggedValue xmi.id="X.17" tag="return" value="void"

modelElement="UMLStimulus.5"/>

<UML:TaggedValue xmi.id="X.18" tag="return" value="int"

modelElement="UMLStimulus.7"/>

<UML:TaggedValue xmi.id="X.19" tag="arguments" value="String str"

modelElement="UMLStimulus.9"/>

<UML:TaggedValue xmi.id="X.20" tag="return" value="int"

77

<UML:TaggedValue xmi.id="X.21" tag="arguments" value="int ba"

modelElement="UMLStimulus.11"/>

<UML:TaggedValue xmi.id="X.22" tag="return" value="void"

modelElement="UMLStimulus.11"/>

<UML:TaggedValue xmi.id="X.23" tag="arguments" value="String str"

modelElement="UMLStimulus.13"/>

<UML:TaggedValue xmi.id="X.24" tag="return" value="void"

modelElement="UMLStimulus.13"/> </XMI.content>

78

Ph lc C: Agent Customer (Customer.java)

import jade.core.Agent; import jade.core.AID; import jade.core.behaviours.Behaviour; import jade.lang.acl.ACLMessage; import jade.proto.AchieveREInitiator; import jade.domain.FIPANames; import java.util.Date; import java.util.Vector; (adsbygoogle = window.adsbygoogle || []).push({});

public class Customer extends Agent {

private int nResponders;

static String str = "";

static String request = "true";

protected void setup()

{

// Read name of ShoppingCart as arguments

final Object[] args = getArguments();

if(args != null && args.length > 0) {

nResponders = args.length;

System.out.println("Requesting dummy-action to "+nResponders+" responders.");

// Gui REQUEST

final ACLMessage msg = new ACLMessage(ACLMessage.REQUEST);

msg.addReceiver(new AID((String) args[0], AID.ISLOCALNAME)); msg.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST); // We want to receive a reply in 10 secs

msg.setReplyByDate(new Date(System.currentTimeMillis() + 10000)); msg.setContent(request);

//agreeSuggest(); sendRequest();

// AddBehavior

addBehaviour(new AchieveREInitiator(this, msg) {

protected void handleInform(ACLMessage inform) {

String tmp = inform.getContent(); if(tmp.equals("suggest"))

{

//agreeSuggest(); refuseSuggest();

ACLMessage msg1 = new ACLMessage(ACLMessage.REQUEST); msg1.addReceiver(new AID((String) args[0], AID.ISLOCALNAME)); msg1.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST); // We want to receive a reply in 10 secs

msg1.setReplyByDate(new Date(System.currentTimeMillis() + 10000));

msg1.setContent(request); sendRequest();

addBehaviour(new AchieveREInitiator(myAgent, msg1) {

79

System.out.println("Agent

"+inform.getSender().getName()+" successfully performed the requested action"); (adsbygoogle = window.adsbygoogle || []).push({});

}

protected void handleRefuse(ACLMessage refuse) {

System.out.println("Agent

"+refuse.getSender().getName()+" refused to perform the requested action");

}

protected void handleFailure(ACLMessage failure) {

if (failure.getSender().equals(myAgent.getAMS())) { // FAILURE notification from the JADE runtime: the receiver

// does not exist

System.out.println("Responder does not exist"); }

else {

System.out.println("Agent

"+failure.getSender().getName()+" failed to perform the requested action"); }

}

protected void handleAllResultNotifications(Vector

notifications) {

if (notifications.size() < nResponders) {

// Some responder didn't reply within the specified timeout

System.out.println("Timeout expired: missing "+(nResponders - notifications.size())+" responses");

} } }); // AddBehavior } else {

System.out.println("Agent "+inform.getSender().getName()+" dat hang thanh cong");

}

}

protected void handleRefuse(ACLMessage refuse) {

System.out.println("Agent "+refuse.getSender().getName()+" khong chap nhan");

nResponders--;

}

protected void handleFailure(ACLMessage failure) {

if (failure.getSender().equals(myAgent.getAMS())) {

// FAILURE notification from the JADE runtime: the receiver // does not exist

System.out.println("Agent Giohang khong hoat dong"); } (adsbygoogle = window.adsbygoogle || []).push({});

else {

System.out.println("Agent "+failure.getSender().getName()+" loi trong xu ly yeu cau");

80

}

protected void handleAllResultNotifications(Vector notifications) {

if (notifications.size() < nResponders) {

// Some responder didn't reply within the specified timeout System.out.println("Timeout expired: missing "+(nResponders - notifications.size())+" responses"); } } }); } else {

System.out.println("Khong co Agent ShoppingCart nao fuc vu");

}

}

static void sendRequest()

{

System.out.println("called sendRequest"); }

static void agreeSuggest()

{

System.out.println("agreeSuggest");

request = "true"; }

static void refuseSuggest()

{

System.out.println("refuseSuggest");

request = "false"; }

81

Ph lc D: Agent ShoppingCart (ShoppingCart.java)

import jade.core.Agent; import jade.core.AID; import jade.lang.acl.ACLMessage; import jade.lang.acl.MessageTemplate; import jade.proto.AchieveREResponder; import jade.domain.FIPANames; import jade.domain.FIPAAgentManagement.NotUnderstoodException; import jade.domain.FIPAAgentManagement.RefuseException; import jade.domain.FIPAAgentManagement.FailureException;

public class ShoppingCart extends Agent{

protected void setup()

{

System.out.println("Agent "+getLocalName()+" waiting for requests..."); MessageTemplate template = MessageTemplate.and(

MessageTemplate.MatchProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST), MessageTemplate.MatchPerformative(ACLMessage.REQUEST) );

addBehaviour(new AchieveREResponder(this, template) { (adsbygoogle = window.adsbygoogle || []).push({});

protected ACLMessage prepareResponse(ACLMessage request) throws

NotUnderstoodException, RefuseException {

System.out.println("Agent "+getLocalName()+": REQUEST received from "+request.getSender().getName()+". Action is "+request.getContent());

String strReq = request.getContent();

if(strReq.equals("true")) {

System.out.println("Agent "+getLocalName()+": Agree"); ACLMessage agree = request.createReply();

agree.setPerformative(ACLMessage.AGREE); agree.setContent("ok");

agreeRequest();

return agree;

}

else if (strReq.equals("suggest")) {

System.out.println("Agent "+getLocalName()+": Agree"); ACLMessage agree = request.createReply();

agree.setPerformative(ACLMessage.AGREE); agree.setContent("suggest"); sendSuggest(); return agree; } else { refuseRequest();

System.out.println("Agent "+getLocalName()+": Refuse"); throw new RefuseException("check-failed");

}

82

}

}); }

static void sendSuggest()

{

System.out.println("ShoppingCart gui mot loi de nghi cho Customer");

}

static void agreeRequest()

{

System.out.println("ShoppingCart Chap nhan yeu cau dat hang"); }

static void refuseRequest()

{

System.out.println("ShoppingCart Tu choi dat hang"); }}

83

Ph lc E: Aspect Template (adsbygoogle = window.adsbygoogle || []).push({});

static String aspectTemplate =

"\r\n" +

" pointcut pc_$METHODNAME$($METHOD_ARG$): $ARGS$ call ($METHOD_RETURN$ $METHOD_NAME$($METHOD_ARG_TYPE$));\r\n" + " before($METHOD_ARG$): pc_$METHODNAME$($METHOD_ARG_NAME$) {\r\n" + " if ($PRE-CONDITIONS$){\r\n" + " System.out.print(\"Wrong at: \"+thisJoinPointStaticPart.getSignature());\r\n"+ " System.out.print(\" In file: \"+thisJoinPointStaticPart.getSourceLocation().getFileName());\r\n"+ " System.out.println(\" At line: \"+thisJoinPointStaticPart.getSourceLocation().getLine());\r\n"+ " }}\r\n" + " after($METHOD_ARG$): pc_$METHODNAME$($METHOD_ARG_NAME$) {\r\n" + " state = STATE_$METHOD_STATE_NAME$;\r\n" + " }\r\n";

static String strPointcutEntry =

" pointcut pc_$METHODNAME$($METHOD_ARG$): $ARGS$ call ($METHOD_RETURN$ $METHOD_NAME$($METHOD_ARG_TYPE$)) ;\r\n" + " before($METHOD_ARG$): pc_$METHODNAME$($METHOD_ARG_NAME$) {\r\n" + " Object o = thisJoinPoint.getTarget();\r\n"+ " if (!sm.isBinded(o)) \r\n"+ " sm.newSharedState(o);\r\n"+ " }\r\n" + " after($METHOD_ARG$): pc_$METHODNAME$($METHOD_ARG_NAME$) {\r\n" + " String s = thisJoinPoint.getSignature().toString();\r\n" + " Object o = thisJoinPoint.getTarget();\r\n" +

" log(\"change state: \" + sm.getSharedState(o).getState() + \" ---> \" + s); \r\n" +

" sm.setSharedState(o, s);\r\n" +

" }\r\n";

static String strPointcutExit =

" pointcut pc_$METHODNAME$($METHOD_ARG$): $ARGS$ call ($METHOD_RETURN$ $METHOD_NAME$($METHOD_ARG_TYPE$));\r\n" + " before($METHOD_ARG$): pc_$METHODNAME$($METHOD_ARG_NAME$) {\r\n" + " Object o = thisJoinPoint.getTarget();\r\n" + " if (!sm.isBinded(o))\r\n"+ " sm.bind(o);\r\n" + " String s = thisJoinPoint.getSignature().toString();\r\n"+ " if (! isValidState(o, s)) {\r\n" + " log(\"Invalid change: \" + sm.getSharedState(o).getState() + \" ---> \" + s); \r\n" + " log(thisJoinPoint);\r\n" + " }\r\n"+ " }\r\n" + " after($METHOD_ARG$): pc_$METHODNAME$($METHOD_ARG_NAME$){\r\n" + " String s = thisJoinPoint.getSignature().toString();\r\n" + " Object o = thisJoinPoint.getTarget();\r\n" +

" log(\"change state: \" + sm.getSharedState(o).getState() + \" ---> \" + s); \r\n" +

84

" sm.reset(o);\r\n" +

" }\r\n";

static String strPointcut =

" pointcut pc_$METHODNAME$($METHOD_ARG$): $ARGS$ call ($METHOD_RETURN$ $METHOD_NAME$($METHOD_ARG_TYPE$));\r\n" +

" before ($METHOD_ARG$): pc_$METHODNAME$($METHOD_ARG_NAME$) {\r\n" + " Object o = thisJoinPoint.getTarget();\r\n" + " if (!sm.isBinded(o))\r\n"+ " sm.bind(o);\r\n" + " String s = thisJoinPoint.getSignature().toString();\r\n"+ " if (! isValidState(o, s)) {\r\n" + " log(\"Invalid change: \" + sm.getSharedState(o).getState() + \" ---> \" + s); \r\n" + " log(thisJoinPoint);\r\n" + " }\r\n"+ " }\r\n" + " after($METHOD_ARG$): pc_$METHODNAME$($METHOD_ARG_NAME$) {\r\n" + " String s = thisJoinPoint.getSignature().toString();\r\n" + " Object o = thisJoinPoint.getTarget();\r\n" +

" log(\"change state: \" + sm.getSharedState(o).getState() + \" ---> \" + s); \r\n" +

" sm.setSharedState(o, s);\r\n" +

Tài liu tham kho

[1

[2

[3

[4] A. Colyer, A. Clement, G. Harley and M. Webster. Eclipse AspectJ: Aspect- Oriented Programming with AspectJ and the Eclipse AspectJ Development Tools. Addison Wesley Professional Publisher, 2004.

[5] Anh-Hoang Truong, Thanh-Binh Trinh, Dang Van Hung, Viet-Ha Nguyen, Nguyen Thi Thu Trang, and Pham Dinh Hung. “Checking Interface Interaction Protocols Using Aspect-Oriented Programming”. Africa, November 10-14, 2008.

[6] David Hunter, Kurt Cagle, Chris Dix, Roger Kovack, Jonathan Pinnock, Jeff Rafter. Beginning XML, 4th edition. Wiley Publishing Inc, 2007.

[7] J. D. Gradecki and N. Lesiecki. Mastering AspectJ Aspect-Oriented Programming in Java. Wiley Publishing Inc, 2003.

[8] James Odell, H. Van Dyke Parunak, Bernhard Bauer. Representing Agent Interaction Protocols in UML , 1999.

[9] James Odell, H. Van Dyke Parunak, Bernhard Bauer. Extending UML for Agents, 2000.

[10] M. Wooldridge, N. Jennings, D. Kinny: The Gaia Methodology for Agent- Oriented Analysis and Design. Autonomous Agents and Multi-Agent Systems. 3 (3): (2000). (adsbygoogle = window.adsbygoogle || []).push({});

[11] OMG. Unified Modeling Language. OMG Version 1.5 – 2003.

[12] R. Laddad. AspectJ in Action Practical Aspect-Oriented Programming. Manning Publications Co., 2003.

[13] R. S. Pressman. Software Engineering, A Practitioner’s Approach, 5th edition. Thomas Casson, 2001.

[14] Timothy J. Grose, Gary C. Doney, Stephen A. Brodsky. Mastering XMI: Java Programming with XMI, XML, and UML. Wiley Publishing Inc,2002.

[15] Y. Cheon and A. Perumandla. Specifying and checking method call sequences of Java programs. Software Quality Control, 15(1):7–25, 2007.

Một phần của tài liệu Kiểm chứng đặt tả uml cho tác tử phần mềm (Trang 80 - 93)