BPEL STRUCTURAL ACTIVITY PARSER Balaji Palasamudram Ramesh

advertisement
BPEL STRUCTURAL ACTIVITY PARSER
Balaji Palasamudram Ramesh
B.E., K.S. Institute of Technology, India, 2006
PROJECT
Submitted in partial satisfaction of
the requirements for the degree of
MASTER OF SCIENCE
in
COMPUTER SCIENCE
at
CALIFORNIA STATE UNIVERSITY, SACRAMENTO
SPRING
2010
BPEL STRUCTURAL ACTIVITY PARSER
A Project
by
Balaji Palasamudram Ramesh
Approved by:
__________________________________, Committee Chair
Dr. Jinsong Ouyang
__________________________________, Second Reader
Dr. Ying Jin
____________________________
Date
ii
Student: Balaji Palasamudram Ramesh
I certify that this student has met the requirements for format contained in the University format
manual, and that this project is suitable for shelving in the Library and credit is to be awarded for
the Project.
__________________________, Graduate Coordinator
Dr. Cui Zhang
Department of Compute Science
iii
________________
Date
Abstract
of
BPEL STRUCTURAL ACTIVITY PARSER
by
Balaji Palasamudram Ramesh
BPEL stands for Business Process Execution Language; it is a standard executable
language for specifying interactions with web-services. “BPEL is [1] essentially a
workflow graph that describes interactions between various web services, dependencies
among tasks, rules and different paths between them, conditions when tasks gets initiated
and moves to the next step.” By combining several web services BPEL can create a new
business model with its own interface to end users. The logic and flow of control [1]
between the participating web services are described by XML grammar defined by
BPEL, which is later executed by a BPEL engine. According to Miguel (2005) [2], like
any other programming language, BPEL has three basic components namely,
•
Data types
•
Programming logic
•
Input/Output
iv
In BPEL the data types are defined by XSD (XML Schema Definition) files – which
specifies the order of tags in XML document, indicates fields that are mandatory, and
defines the data types of the fields. The logic implemented by BPEL defines the
programming logic. The input/output are the web services defined in WSDL.
BPEL is [3] essentially a graph of conditions and activities and they are represented in
terms of state diagram where each state is an activity. Thus at any given instance of time
the business process shall be in a state or an activity. When the business process interacts
with a web service the state of the process changes based on the conditions defined in the
state diagram. The conditions can be ‘ifelse’, ‘while’, ‘repeatUntil’, ‘foreach’ and nested
loops.
This project takes the BPEL file from the destination location as the input and parsers the
file using XML-DOM and creates a table that stores the information of the BPEL flow.
The table contains information of the web services with which the BPEL interacts, the
activity name, the operation being performed at the current state, input and output
message, condition, current state and possible next states.
_______________________, Committee Chair
Dr. Jinsong Ouyang
_______________________
Date
v
DEDICATION
Dedicated to
My FATHER, MOTHER and SISTER for many sacrifices, their support and encouragement to
earn my Master’s degree.
vi
ACKNOWLEDGMENTS
At the very onset, I would like to place on record gratefulness to all those people who helped me
in making this project a reality. Apart from the shear hard work and effort of the students, the
enlightenment from our very experienced teachers also play a paramount role because it is they
who guide us in the right direction.
I am thankful to Dr. Jinsong Ouyang, my Masters Project Advisor for providing an opportunity to
work for this project, for his valuable suggestions and technical guidance, without whose help this
project would have been an unrealized dream.
I am also thankful to Dr. Ying Jin, my second reader, for her valuable time to review the project
and provide valuable suggestions.
I gracefully acknowledge the help lent out to me by all teaching and non-teaching staff members
of the Department of Computer Science at all difficult times.
I would like to take this opportunity to thank my Family and my Friends for listening to me at all
times.
vii
TABLE OF CONTENTS
Page
Dedication ....................................................................................................................................... vi
Acknowledgments.......................................................................................................................... vii
List of Tables ................................................................................................................................... x
List of Figures ................................................................................................................................. xi
Chapter
1. INTRODUCTION ....................................................................................................................... 1
2. LITERATRURE SURVERY....................................................................................................... 3
2.1 XML - XSD .................................................................................................................. 3
2.2 Web Services ................................................................................................................ 6
2.3 BPEL........................................................................................................................... 12
2.3.1 Building a Business Process ......................................................................... 14
2.4 XML - DOM ............................................................................................................... 20
3. STATEMENT OF PROBLEM .................................................................................................. 23
3.1 Overview ..................................................................................................................... 23
3.2 Problem Definition ..................................................................................................... 23
4. DESIGNING .............................................................................................................................. 28
4.1 Overall System Design ............................................................................................... 28
4.2 Design of the BPEL_FLOW Table ............................................................................. 30
4.2.1 Parsing Sequence Node ................................................................................. 31
4.2.2 Parsing ‘if’ Structured Activity ..................................................................... 34
4.2.3 Parsing ‘while’ Structured Activity .............................................................. 35
viii
4.2.4 Parsing ‘repeatUntil’ Structured Activity ..................................................... 36
4.2.5 Parsing ‘forEach’ Structured Activity ........................................................... 37
5. SOFTWARE AND HARDWARE DETAILS ........................................................................... 38
5.1 Overview ..................................................................................................................... 38
5.2 Software Setup ............................................................................................................ 38
5.2.1 Java Development Kit (JDK) ........................................................................ 38
5.2.2 NetBeans ....................................................................................................... 39
5.2.3 MySQL ......................................................................................................... 40
5.2.4 MySQL Connector/J ..................................................................................... 40
5.3 Hardware Requirements and Specifications ............................................................... 43
6. IMPLEMENTATION DETAILS .............................................................................................. 44
6.1 Creating Table BPEL_FLOW..................................................................................... 44
6.2 Database Server Connection ....................................................................................... 45
6.3 Parsing BPEL File ...................................................................................................... 46
6.3.1 Working of seqFun() ..................................................................................... 48
6.3.2 Working of getCondition()............................................................................ 50
6.3.3 Working of ifSeq() ........................................................................................ 53
6.3.4 Working of whileSeq().................................................................................. 56
6.3.5 Working of forEachSeq() .............................................................................. 59
6.3.6 Working of rptSeq() ...................................................................................... 60
6.3.7 Working of webservice() .............................................................................. 61
7. RESULTS .................................................................................................................................. 62
Bibliography .................................................................................................................................. 66
ix
LIST OF TABLES
Page
1.
Table 4.1 BPEL_FLOW Table Design ............................................................................... 30
x
LIST OF FIGURES
Page
1.
Figure 2.1 Structure of WSDL .............................................................................................. 7
2.
Figure 2.2 Tree Structure of DOM...................................................................................... 21
3.
Figure 3.1 Data Structure Format to Maintain Information of Structural Activities .......... 25
4.
Figure 3.2 Data Structure Format to Maintain Information of <if> Activity...................... 27
5.
Figure 4.1 High End Architecture of the BPEL Parser System .......................................... 29
6.
Figure 4.2 Data Flow Diagram of Parser ............................................................................ 33
7.
Figure 4.3 Data Flow Diagram to Parse ‘if’ Activity.......................................................... 34
8.
Figure 4.4 Data Flow Diagram to Parse ‘while’ Activity ................................................... 35
9.
Figure 4.5 Data Flow Diagram to Parse ‘repeatUntil’ Activity .......................................... 36
10.
Figure 4.6 Data Flow Diagram to Parse ‘forEach’ Activity ............................................... 37
11.
Figure 5.1 Adding JDBC Driver to NetBeans IDE ............................................................. 42
12.
Figure 5.2 Establishing a New Database Connection ......................................................... 43
13.
Figure 7.1 Design View of BPEL Input File....................................................................... 62
14.
Figure 7.2 Representation of Figure 7.1 as Table Row Entries .......................................... 63
xi
1
Chapter 1
INTRODUCTION
“Business Process Execution Language – BPEL is [4] an XML based language used to
build a business process, which consists of logical steps also called as activities”. “BPEL
[1] deals explicitly with the functional aspects of business processes”. In BPEL all the
messages that are exchanged i.e., the message returned and passed from business process
are all defined in XML. The data types of all the variables used in the business process
are defined within the XML schema document and the data type of the messages are
declared in WSDL files, which also defines the services it provides.
One of the motivation factors for the development of a BPEL engine was the challenge to
integrate various applications. Inter and intra enterprise integration are the key business
problems. BPEL serves as an excellent glue to integrate services also called as partner
service integration [1]. BPEL is essentially a workflow graph. “A workflow [1] is about
interactions between various partner services, dependencies among tasks, rules and routes
between them, conditions when tasks get initiated and moves to the next step or roles
back”. Each of the activity within BPEL is like a function call in a programming
language.
“The XML Document Object Model (DOM) is [5] a standard object model for XML. It
defines a standard methodology to manipulate and access XML documents”. It treats the
XML document as a tree structure with elements, attributes, text, and comments as nodes
2
of a tree; in general the entire document is treated as nodes. XML DOM provides APIs to
traverse XML files, access, insert and to delete nodes [5].
The BPEL parser uses XML DOM in-order to traverse the XML file and to extract the
information about what the partner roles are. It also gets the information about the partner
link, the activity name, operation that will be invoked, input messages that are sent as
parameter to the operation, the output message of an operation, and conditions that
determine the flow of execution of the operation.
The next process is to convert the above extracted information into customized formats.
A unique id called activity sequence is defined for each activity/operation in the
workflow graph. In addition to this, the ids of the next activity sequence for the current
activity under execution are determined based on the conditions. For example, if the
activity under execution is an ‘if’ activity sequence then there are two possible work flow
paths, one when the condition is satisfied and the other work flow is when the condition
fails. The next activity for the ‘if’ activity sequence is the activity ids of the first activity
encountered in the two workflow paths. Finally, all the information is stored in the
database.
3
Chapter 2
LITERATURE SURVEY
2.1 XML - XSD
“XML is also called [6] as eXtensible Markup Language, is a specification to store
information and also describes the structure of the information”. Just like any HTML,
XML is also a markup language but it does not define a tag of its own. On the contrary it
allows the developer to define their own tags as needed but adhering to the rules of XML
specification. XML [6] is designed keeping in mind how to store and carry information
rather than how to display information as compared to HTML. The advantage of having
XML is that it can be used to share the data between incongruent systems.
XML documents are self-explanatory; the tags describe what kind of data it contains. A
typical XML looks like,
<? xml version = “1.0”?>
<Contact>
<Name>
<LName lang=”eng”>Ramesh</LName>
<FName lang=”eng”>Balaji</FName>
</Name>
<Address> CSUS, Sacramento </Address>
<Phone> 123-456-6789 </Phone>
</Contact>
4
XML always starts with a declaration which specifies the version of the XML. Followed
by it is the XML data document <Contact> which is also called the root node. All the
elements enclosed within </Contact> are the children of <Contact>. The <Name>
element has 2 children’s – <FName> and <LName>. In the above example the element
<FName> contains an attribute called “lang” which tells the language of the value.
Finally all the elements in XML document end with an associated closing tag.
XSD [6]: XML are customized markup language and therefore it is necessary to adhere to
the rules of XML specification. The specification for XML defines what a valid XML
document can contain and this is defined using a schema language called XML Schema
also named as XML Schema Definition (XSD). XSD is also written in XML and it allows
the user to define elements, element data types, support namespace and allows defining
global and local elements.
The basic structure of an XML schema [7] is as shown below where <schema> is the root
element.
<?xml version=”1.0”?>
<xsd: schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xml.netbeans.org/schema/Contact"
xmlns:tns="http://xml.netbeans.org/schema/Contact" …>
<!-- simple type declaration -->
<!—complex type element declaration -->
</xsd:schema>
5
The attributes of the schema element is the declaration. The declaration
‘xmlns:xsd="http://www.w3.org/2001/XMLSchema’ means [7] all the elements, data
types defined in the XML Schema document comes from w3.org. The term namespace
defines that all the elements, attributes names defined in this document are unique. So if a
developer combines several XML Schemas which also contains same element and
attribute names they are differentiated by a namespace. Here ‘tns’ represent the
namespace for XML schema Contact.xsd.
Within XSD, elements are declared. An XML element can be classified as two basic
types [7]: a simple type or a complex type. A simple type element is a leaf node that
contains only text and the text can be of any primate data type defined by XML schema
definition e.g. integer, string or even customise data type. A simple type XML element
looks like
<xsd:element name="Name" type="xsd:string"/>
In the above example, ‘Name’ is the element name where the datatype is of type ‘string’.
Simple type elements can be combined to define a complex type, which in-turn can be
used as a customised data type for the simple type XML elements.
<xsd:complexType name="PhoneType">
<xsd:sequence>
<xsd:element name="Home" type="xsd:string"/>
<xsd:element name="Work" type="xsd:string"/>
6
<xsd:element name="Cell" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
The complex element ‘PhoneType’ can be defined as a datatype for simple type elements.
2.2 Web Services
“Web services are [8] distributed software components that interact and provide
information to applications. They do this by means of an application oriented interface.”
In other words the web service applications are encapsulated, loosely coupled Web
components that can bind dynamically to each other. “The information in web service is
[8] represented in XML language, so that it is easy to parse and process the information
as needed rather than formatting it for display.” A web service is [8] like an interface or
an abstract class; it gives the details of the functions and interfaces, but hides the
implementation details. Thus, it allows the client and the server - which provides the
service, to interact regardless of the platform or the language the function is written.
Hence, a web service offers both platform independent and distributed environment [8].
“In terms of BPEL, the term ‘Web service’ means [2] something with which we can
interact.” For example we can have a web service with which we can interact to request a
course material or we can file for travel reimbursement, etc. In general web services can
be used to serve any purpose.
7
The key technologies used by Web services are:
•
XML [8] (eXtensible Markup Language) – for data exchange and data
formatting.
•
SOAP [8] (Simple Object Access Protocol) – an XML based protocol that
specifies the structure of the message envelope and describes how a
service has to process the information being passed in the message.
•
“WSDL [8] (Web Services Description Language) – typically used to
describe web services. It is an XML language which describes the
attributes, interface and other properties of a Web Service.”
Figure 2.1: Structure of WSDL
The structure of WSDL [9] as shown in Figure 2.1 [10] can be represented in XML as
follows. All the information is enclosed within the <definition> root node.
8
<definition >
<types>
<!—Declaration of datatype used by the webservice -->
</types>
<message>
<!-- Input and Output messages exchanged during the execution of
the operation -->
</message>
<portType>
<!-- Defines the operations that can be invoked
and messages exchanged during the service -->
</portType>
<binding>
<!-- Defines the protocol used to transmit the message -->
</binding>
<service>
<!-- Define the location of the service -->
</service>
</definition>
9
WSDL Type [9]:
The element <type> contains the definition of data types that shall be later used by the
web services to define the message types. The definition of the data types refers to the
XML Schema, as WSDL does not define by its own.
<types>
<xsd:schema targetNamespace="http://j2ee.netbeans.org/wsdl/Contact">
<xsd:import namespace="http://xml.netbeans.org/schema/Contact"
schemaLocation="Contact.xsd"/>
</xsd:schema>
</types>
The above snippet defines the location from which the schema is been imported.
WSDL Message [2]:
WSDL message specifies what type of data the message must contain when the operation
is invoked. The data type of a message can be either an XSD of simple or a complex type.
<message name="GetPhoneReply">
<part name="Phone" type="ns:Phone"/>
</message>
10
In the above example, the message “GetPhoneReply” has a single part “Phone” which is
a complex type as defined in XSD Schema. ‘Part’ here references to the entity that is
been exchanged. There can be multiple message definition in a WSDL.
WSDL Port Type [2]:
“WSDL Port Type represents the definition of the web service” [2]. The PortType
specifies the abstract interface of the service without specifying the implementation of the
operation. It defines the operation along with input and output messages that are required
for an operation to be performed.
<portType name=" ContactPortType”>
<operation name=" GetPhone ">
<input name=" InputNamePhone " message=
" tns:GetNameRequest "/>
<output name = "OutputPhone" message="tns:GetPhoneReply"/>
</operation>
</portType>
The output message is optional based on whether it is a ‘one-way’ or ‘request-response’
message.
11
WSDL Port Type Binding [2]:
The type of communication protocol used by the web service is defined by WSDL
binding. The way of speaking is defined by Port type whereas to who you are speaking
on the other end is specified by binding. It also describes the format of the message that is
exchanged between operations. The implementation of the web service is specified by the
binding in a WSDL. The communication protocol can be SOAP, JMS or direct call.
<binding name=" ContactBinding " type="tns: tns:ContactPortType ">
<soap:binding style="rpc" transport="http://…"/>
<operation name=" GetPhone ">
<soap:operation/>
<input name=" InputNamePhone ">
<soap:body use="encoded" namespace="…"/>
</input>
<output name="OutputPhone" >
<soap:body use="encoded" namespace="…”/>
</output>
</operation>
</binding>
In the above binding example, the element “binding” has two attributes “name” which
defines the name of the bind, and the “type” points to the port of the bind. The element
12
‘soap’ defines the style in which messages are transmitted and the transport protocol used
to transmit the message. The ‘operation’ element defines the operation that the port
unleashes to the outside world.
WSDL Services [9]:
The element <service> defines the location where the service shall be made available and
this is indicated by element <port>. The element <port> tells where to find the portType
via binding.
<service name="ContactService">
<port name="ContactPort" binding="tns:ContactBinding">
<soap:address
location="http://localhost:18181/ContactService/ContactPort"/>
</port>
</service>
2.3 BPEL
There has always been a requirement to join applications and business systems to build a
business model. Conventional approach [1] is to integrate the involved logic in a common
application to meet business requirements such as the CRM or ERP. One of the major
concern with this approach is that, each time an application is developed, tested and
deployed there is a need for integration and process change to be performed which results
13
in complexity as well as cost in-efficiency. In order to address these concerns several
software products emerged – one among them is BEPL – WS, so that business system
can be more efficiently altered, optimized and managed. Now both BPEL and Web
services offers a standardized integration language and an interface [1].
The word BPEL stands for Business Process Execution Language. BPEL emerged from a
society which includes IBM, Microsoft, and BEA Systems. It replaces both Microsoft’s
XLANG language and IBM’s Web Services Work Flow Language (WSFL). BPEL is [1]
essentially a workflow graph that describes interactions between various web services,
dependencies among tasks, rules and different paths between them, conditions when tasks
gets initiated and moves to the next step. BPEL serves as a glue to bind Web services to
build a business solution. By combining several web services, BPEL can create a new
business model with its own interface to end users. The logic, flow of control between the
participating web services are described by XML grammar defined by BPEL which is
later executed by a BPEL engine [1].
Using BPEL, one can write programs that invoke web services to fetch the travelling
details such as cost and time of departure; use another web service to book tickets and
cancel tickets. If suppose a new public web service which forecasts the weather is made
available over internet then that can be used to integrate with the existing BPEL process
to send a message about the predicted weather condition on the day of travel.
14
A BPEL program can be extended as and when new web services come up (in the
internet) and also by connecting to other web service clients. In order to achieve this,
WSDL defines a <binding> element. Binding [2] tells with whom you are speaking at the
other end? What is the protocol used to communicate? In addition the message format
that is been exchanged. Simple Object Access Protocol (SOAP) [2] is a common
communication protocol used to communicate among web services.
Web services are an excellent technology but as an individual, it can’t be implemented in
a business model. Proprietary language such as WSFL and XLANG used to implement
web services also does not bring improvement to the development of web services.
Therefore, BPEL that is the combination of all these proprietary language binds web
services to build a business process. [1]
Typically, BPEL is implemented [2] at the server side and it gets initiated when a user
sends a request to the server to provide a service. Once, the request is received by the
BPEL server a new BPEL process is initiated between the client and the server and it
continues to provide the service until all the activities have been performed by
communicating with other web services.
2.3.1 Building a Business Process
BPEL describes the business model is of two different ways [11]. In an executable
process, the exact details of the business process are specified whereas in an abstract
business process only the signature and the message transmitted is specified. A BPEL
15
process [11] tells how the web services have to be invoked and the invocation can either
be sequential or in parallel order. The invocation of the web services depends not only on
the user input but also on the return value of the previous invocation. BPEL allows
declaring and assigning of variables, defining loops and conditions, etc. Thus, one can
define a complex business process by combining all the supported constructs in an
algorithm way. Essentially a business process is a graph of activities, which can be
expressed in terms of state transition diagram.
“A BPEL process consists of steps; [11] each step is called an activity.” An activity can
either be a simple or complex activity. A primitive activity performs basic tasks.
According to Juric [11] some of the activities include,
•
<assign>, assigns values to variables.
•
<invoke>, used to invoke web services.
•
<receive>, makes the business process to stop until a message arrives.
•
<reply>, returns a message from the process to the operation/client that
initiated the communication.
•
<throw>, to signal an inner fault or an exception.
•
<wait>, used to specify wait condition for some time.
•
<exit>, to stop the execution of a process.
To build a business process BPEL offers structural activities which nests above primitive
activities. Some of the most commonly uses structural activities are, [11]
•
<sequence>, used to nest series of activities.
16
•
<if>, executes an activity if the condition turns true.
•
<while>, iterates one or more activities till the Boolean expression at the
start of the iteration is satisfied.
•
<repeat until>, iterates one or more activities till the Boolean expression at
the end of iteration is satisfied.
•
<for each>, for defining loops.
•
<flow>, nests activities that runs parallel.
•
<scope>, is a collection of activities that does not interfere with the
variables, activities defined in other scopes.
In-order to understand how the business process are described with BPEL, consider a
business process for rental car. A customer invokes a business process to reserve a car by
specifying the car type, zip code of the location where the client wishes to pick the car,
and dates during which he/she wishes to rent the car. Assuming a web service exist which
checks the availability of the requested car for the specified dates then the BPEL business
process performs the check by invoking the corresponding web service. Then the BPEL
process checks for the price of the car with two car rental companies – for example,
Enterprise and Hertz. Assuming both rental companies provide a web service through
which such checks can be performed. Finally, the BPEL process selects the car with
lower price and returns the cost as well as the rental office location.
To create a business process it is necessary to get familiarized with the web services that
are involved in the process, once familiarized BPEL process and the involved web
17
services can be linked by declaring partnerLinkTypes within the WSDL of an associated
web services and these partnerLinkTypes are later referenced by the BPEL process
[2],[11].
1. Defining partner link types [11]
A partner link type identifies the roles enacted between BPEL and the participating web
services during execution time [4]. “Partner link type can have [11] one or two roles and
for each role we must specify the portType it uses.”
A single role is used when the communication is always performed in a one way and in
same direction, usually for synchronous operations that has only one portType. Two roles
are declared if a call back is also involved usually for asynchronous operation which has
two portTypes defined. Below snippet shows the partner link type defined in WSDL file
for the WSDL port type defined in Chapter 2.2
<plnk:partnerLinkType name="ContactPartner">
<plnk:role name="ContactPortTypeRole" portType="tns:ContactPortType"/>
</plnk:partnerLinkType>
The reference of the above partner link type defined in Contact WSDL file is done in
BPEL files as below,
<partnerLinks>
<partnerLink name="Contact"
18
xmlns:tns="http://j2ee.netbeans.org/wsdl/Contact"
partnerLinkType="tns:ContactPartner" partnerRole="ContactPortTypeRole"/>
</partnerLinks>
2. Creating business process [11]
The structure [11] of the BPEL process as follows,
<process name="Contact" ... (define namespace) … >
<partnerLinks>
<!-- Declaration of partner links -->
</partnerLinks>
<variables>
<!-- Declaration of variables -->
</variables>
<sequence>
<!-- BPEL main body -->
</sequence>
</process>
It is necessary to first declare namespaces for the involved WSDL and for the BPEL
activity tags. Next is to define partner links that identifies the roles enacted between
BPEL and the participating web services during execution time as mentioned in Step 1.
Next is to declare variables [11] used in BPEL processes; which are used to store,
19
reformat and alter messages. Variables are needed for every message exchange between
the participating partners.
Each variable [11] is associated with a data type and the data type can, be of WSDL
message type or it can use XML schema of simple type.
<variables>
<variable name="Phone" xmlns:tns="http://j2ee.netbeans.org/wsdl/Contact"
messageType="tns:GetPhoneReply"/>
</variables>
The above snippet uses WSDL message type defined in WSDL message of section 2.2.
After the declaration of the variables, next is the BPEL main body, which is enclosed
within a <sequence> tag [11]. Each activity within a <sequence> tag specifies the order
in which web services are invoked and these activities are built using the primitive or
structural activities explained above. A sample snippet is as shown below,
<sequence>
<invoke name="GetPhone" partnerLink="Contact" operation="GetPhone"
xmlns:tns="http://j2ee.netbeans.org/wsdl/Contact"
portType="tns:ContactPortType" inputVariable="Name"
outputVariable="Phone"/>
</sequence>
20
2.4 XML – DOM
DOM stands for Document Object Model [12] is an Application Programming Interface
(API) that models an XML document as a tree of nodes and controls on how to
manipulate and access the tree nodes. DOM is a read and write API and hence supports
parsing, manipulating and creating new XML documents [13]. API’s of DOM are
available in many programming languages such as Java, VB.net, C++, etc hence it is
called as language neutral interface [5].
DOM [13] treats an XML document as a tree of nodes where each node can have any
number of children nodes but each node is associated with only one single parent except
for the topmost or the starting node called as the root node. A node without children is
called a leaf node. The structure of the DOM is equivalent to tree data structure.
Let’s consider a sample XML document
<Contact>
<Name>
<LName>Ramesh</LName>
<FName>Balaji</FName>
</Name>
<Address> CSUS, Sacramento </Address>
<Phone> 123-456-6789 </Phone>
</Contact>
21
Figure 2.2 shows DOM equivalent representation of above XML document,
ContactBook
Name
LName
FName
Ramesh
Balaji
Address
Phone
CSUS,
Sacramento
123-456-6789
Figure 2.2: Tree Structure of DOM
DOM [13] offers several build in functions to traverse the XML tree, but before we can
perform any task on a XML tree, the XML document has to be uploaded into XML DOM
object. As the application under development is build on java platform java provides
functions to access, manipulate and build XML file using DOM. In-order to upload an
XML file java offers DocumentBuilderFactory.newInstance() factory method to generate
an object of type ‘DocumentBuilderFactory’, using the object create an instance of
abstract ‘DocumentBuilder’ class. Java offers parser() method of ‘DocumentBuilder’ to
read, write and manipulate the XML document. Once a document of
org.w3c.dom.Document object is created, then parsing of this document involves
utilizing proper functions offered by DOM to parse XML files.
22
In DOM all the elements of the tree are considered to be of type NODE. Java DOM
offers twelve different node types, some of the commonly used node types and their
associated values are [13],
ELEMENT_NODE
=
1
ATTRIBUTE_NODE
=
2
DOCUMENT_NODE
=
9
Some of the common node property functions and node list functions used in the project
are [13],
getNodeName() – Name of the function is self-explanatory, fetches the name of the node.
getNodeValue() – Fetches the associated value of the node.
getNodeType() – Returns the equivalent integer value of the node type.
getAttributeNode() – Returns the attribute node by name.
getElementByTagName() – Returns a list of node for the given name.
getLength() – Returns the number of nodes in the node list.
23
Chapter 3
STATEMENT OF PROBLEM
3.1 Overview
A ‘sequence’ node can house either a primitive or a structural activity in other words a
‘sequence’ node can house ‘if’, ‘while’, ‘repeatUntil’ and ‘forEach’ looping structural
activities. Each of these looping structural activities can be combined resulting into
nested loop structure. A nested loop is a loop with in a loop i.e. an inner loop within the
body of an outer loop. Nested loop works with the first pass of the outer loop triggering
the inner loop, which executes to completion. Then the second pass of the outer loop
triggers the inner loop again. The process continues until the outer loop completes its
iteration.
3.2 Problem Definition
One of the greatest challenge while parsing the looping structural activities is to find the
possible next activity to be executed if the condition of the loop is true as well as what
would be the next activity to be executed if the condition of the loop is false. The
problem becomes much more complicated while parsing the nested loop structures, i.e.,
what is the next activity to be executed after the completion of the inner loop. Moreover,
this depends on whether the inner loop is the last instruction within the outer loop or if
there are more instructions to be performed after the inner loop execution. In addition to
all these it is also necessary for the parser to have an intelligence to say what is the last
24
instruction of an outer loop in a nested loop structure, if suppose the inner loop structure
is the last instruction of an outer loop structure. In order to explain the problem consider
the following BPEL program snippet
<while name = “outerWhile” ... >
<condition> ... </condition>
<sequence>
<invoke name = ... />
<while name = “innerWhile” ... />
<condition> ... /condition>
<sequence>
<invoke name = ... />
<reply name = ... />
</sequence>
</while>
</sequence>
</while>
In the above code, ‘reply’ is the last instruction for the ‘innerWhile’ loop but it is not the
same for the ‘outerWhile’ loop; on the contrary, the ‘innerWhile’ is the last instruction
for the ‘outerWhile’ loop. In order to achieve this, parser should have the intelligence or
the memory to say what is the next instruction to be executed after ‘reply’, and what is
the next instruction to be executed after ‘innerWhile’. The problem can be further more
extended if the nested loop structure is a ‘repeatUntil’ or ‘forEach’ or ‘if’ or combination
of all these. Since, the flow of the control for each of these looping structures is unique.
25
The solution to all of the above problems is to maintain a history of looping structural
activities, which contains the details of the inner loops encountered. Figure 3.1 shows the
format of the data structure that keeps track of the information of structural activities.
Id Inner child_ child_ child_
child_
if while reptUntil forEach forEach
loop str_ end_ if_
if_
bit bit
bit
bit
CondKey
ID
seq
seq
strLevel endLevel
Figure 3.1: Data Structure Format to Maintain Information of Structural Activities
Definitions of the field are as follows,
child_str_seq
– The sequence key ID of the first instruction in the inner loop
child_end_seq
– The sequence key ID of the last instruction in the inner loop
child_if_strLevel
– If the structural activity is ‘if’, then the starting level number
represents the depth level number from the outer ‘if’ to the first
encountered inner ‘if’.
child_if_endLevel – Ending level number represents the depth level number from the
outer ‘if’ to the last encountered inner ‘if’.
ifBit
– Indicates the inner loop is <if> activity.
whileBit
– Indicates the inner loop is a <while> activity.
reptUntilBit
– Indicates the inner loop is <repeatUntil> activity.
forEachBit
– Indicates the inner loop is <forEach> activity.
forEachCondKey
– <forEach> activity supports optional condition. The field holds
outer the sequence key ID of the optional condition if it exists.
26
Some of the challenges were encountered, while parsing the <if> structural activity. An
‘ifelse’ statement allows a choice to be made between two possible alternatives.
Sometimes a choice needs to be made between more than two possibilities resulting in a
nested ‘ifelse’ within <if> activity or <else> activity or in both activities. One of the
biggest problem to be handled while parsing nested ‘ifelse’ is, what is the next instruction
to be executed after the last instruction of the innermost <if> or innermost <else> if it
exists. Unlike any other structural activity an ‘ifelse’ has two last instructions one within
‘if’ and the other within ‘else’. The above problem can be best explained by the following
BPEL program snippet.
<if name="outerIf" ... />
<condition>...</condition>
<if name="innerIf" ... />
<condition>...</condition>
<invoke name="invoke1" ... />
<else>
<invoke name="invoke2"... />
</else>
</if>
<else>
<invoke name="invoke3" ... />
</else>
</if>
<reply name = .../>
27
In the above snippet ‘reply’ is the next instruction to be executed after ‘invoke1’,
‘invoke2’ and ‘invoke3’ have been executed. Since, the parser parses the file in
sequential order i.e., first all the instructions within <if> activity is parsed and then all the
instructions within <else> is parsed. So the parser must have a memory to say what is the
next instruction to be executed after the last instruction ‘invoke1’ in ‘if’ part of ‘innerIf’,
as well as last instruction ‘invoke2’ in ‘else’ part of ‘innerIf’ to be executed?
The solution to this problem can be answered by stacking all the required information in
a data structure each time an <if> activity is encountered. Figure 3.2 shows the format of
the data structure used to keep track the information of <if> activity.
begin_ifKey lst_ifKey lst_elseKey
Figure 3.2: Data Structure Format to Maintain Information of <if> Activity.
Definitions of the fields are as follows,
begin_ifKey – The sequence number of the first statement within <if> activity
lst_ifkey
– The sequence number of the last statement within <if> activity
lst_elseKey – The sequence number of the last statement within <else>
28
Chapter 4
DESIGNING
Development of parser involves two steps:
1. To create a table schema to store extracted elements in the database.
2. To parse BPEL file and extract elements into the schema database.
4.1 Overall System Design
A BPEL process integrates WSDL to generate business process. WSDL describes web
services. So, the input to build a BPEL process includes WSDL. The data type of the
variables used in BPEL and WSDL are declared in XSD files. BPEL file programmed
using XML language defines the logic of the business process. Thus, the elements in the
BPEL file can be parsed using DOM in java and then augment some more information
and store the details in the database. This project is an extension of the XSD, WSDL
parser [3].
The Figure 4.1 shows the architecture of a BPEL parser process. The process starts with
the connection of a database at the backend. Once the BPEL file is uploaded then the
database is checked whether same service had already been uploaded, if “Yes” then the
process terminates. On “No”, the parser instantiates a XML document of the uploaded
BPEL file, extracts required elements, customizes their values and stores them in a
HashMap data structure where each entry holds all the required information of an
29
activity. After the entire XML document is read, the values in the HashMap are stored
into database and the connection for the database is closed.
Start
Start Database
Extract/Upload
BPEL file
Is file
already
parsed?
False
Parse BPEL.
Store all
required XML
document info
in HashMap
Insert all info
in HashMap
into Database
schema.
True
Stop Database
Stop
Figure 4.1: High End Architecture of the BPEL Parser System
30
4.2 Design of the BPEL_FLOW Table
A BPEL file contains the business logic; each step in the program defines an activity that
explains how a BPEL engine has to interact with the web services. As explained in
Chapter 2.3.1, a business process contains partnerLinks, roles, portType, operations and
message information required to carry an interaction. The parser extracts all these
required information for each step in the BPEL program and stores it in the database in
their respective fields.
Table 4.1 shows the table design for ‘bpel_flow’, which stores all the information
extracted by the parser.
Field
Id
ServiceName
MyRole
PartnerRole
Activity_Name
Current_State
PartnerLink
Operation
InMsgType
OutMsgType
Conditions
Activity_Seq
Next_Activity
Type
SMALLINT (5)
unsigned
VARCHAR(50)
VARCHAR(50)
VARCHAR(50)
VARCHAR(20)
VARCHAR(20)
VARCHAR(50)
VARCHAR(50)
SMALLINT (5)
unsigned
SMALLINT (5)
unsigned
VARCHAR(100)
VARCHAR(6)
VARCHAR(6)
Key
Primary
Null
No
No
No
Yes
No
Yes
Yes
Yes
No
No
Yes
No
No
Table 4.1: BPEL_FLOW Table Design
Extra
Auto Increment
31
The ServiceName and MyRole are the inputs that must be supplied while uploading the
BPEL file. The PartnerRole, PartnerLink, and Operation are extracted by the parser.
Activity_Name can be either primitive or a structured activity and Current_State is the
name of the activity the programmer has provided. The parser also extracts messages
corresponding to each activity and stores it in the table. If a business process is
asynchronous then there is only an input message, for synchronous process both the input
and output messages are present. The table stores the equivalent id of the input and output
message which is stored while parsing the XSD file of the corresponding BPEL file.
Structured activities like ‘if’, ‘while’, ‘repeatUntil’, and ‘forEach’ always contains a
<condition> tag; the field ‘Conditions’ holds value of the <condition> tag after it is
customized as needed. Activity_Seq is the current activity number and Next_Activity is
the activity number of the possible next activities to be executed based on the outcome of
the current activity under execution.
4.2.1 Parsing Sequence Node
Like any other programming language, a BPEL program also defines library files and
declares variables. In a BPEL program, the <import> tag is similar to “import” key word
in Java – it includes the referenced source code/file as part of library; and <variable> tag
which is equivalent to declaration of variables that are referenced in the BPEL program.
After the library files and variables have been declared the logic starts within the
<sequence> tag. The execution of the statements within the <sequence> tag is sequential,
and hence parsing of a file needs to be performed in a sequential order. A <sequence> tag
32
can house either primitive or structural elements and each structural element can house
either one or more primitive or structural elements enclosed within the <sequence> tag.
The skeletal representation of the programming logic is as follows,
<sequence>
<receive name="GetLecture" …/>
<if name="LastLecture" …>
<condition>…</condition>
<sequence name="ifSequence" …>
<receive name="GetAssignment" …/>
…
…
</sequence>
</if>
</sequence>
From the above snippet it is observed that the programming logic always lies within
<sequence> tag. Figure 4.2 shows the data flow diagram of the BPEL structured activity
parser based on the concept that programming logic lies within a <sequence> tag.
33
Figure 4.2: Data Flow Diagram of Parser
34
4.2.2 Parsing ‘if’ Structured Activity
“An ‘if’ activity supports the conditional behavior of a business process instance. The ‘if’
activity consists of a conditional branch defined by ‘if’ and ‘else if’ elements, followed
by an optional ‘else’ activity branch. The conditions on ‘if’ and ‘else if’ branches are
evaluated in the order they appear.”[14]
During program execution, the ‘if’ branch is chosen when the condition for <if> activity
holds true, when the condition fails ‘else’ branch is chosen. An ‘else’ branch is optional.
So, if an ‘else’ branch does not exist for an ‘if’, then it is considered to contain an
‘empty’ activity. [14]
Is activity
<condition>?
Start ifSeq ()
function
True
Call getCondition ()
to customize the
value of <condition>
element
True
Call seqFun (),
function to parse
sequence node
False
Call parser to parse
primitive activity
False
Is activity
<sequence>?
Return current state
number to caller
Figure 4.3: Data Flow Diagram to Parse ‘if’ Activity
35
The ifSeq() is a function to parse ‘if’ or ‘else’ structural activity. The getCondition() is a
function to customize the value of ‘condition’ activity as required. Figure 4.3 shows the
data flow path for ifSeq().
4.2.3 Parsing ‘while’ Structured Activity
A ‘while’ element first evaluates a specific condition, only on true it executes one or
more activities, and the process is repeatedly performed until the condition fails. Figure
4.4 shows the data flow diagram of parsing a ‘while’ structured activity. [14]
Call getCondition ()
to customize the
value of <condition>
element
Start whileSeq ()
function
Call parser to parse
primitive activity
False
Is activity
<sequence>?
True
Call seqFun (),
function to parse
sequence node
Return current state
number to seqFun ()
Figure 4.4: Data Flow Diagram to Parse ‘while’ Activity
36
4.2.4 Parsing ‘repeatUntil’ Structured Activity
“A ‘repeatUntil’ element executes one or more activities as long as the specific condition
is satisfied after the execution of each iteration.”[14] A ‘repeatUntil’ element works
completely opposite to that of a ‘while’ element i.e., ‘repeatUntil’ first executes the
iterative activity and then checks for the condition whereas ‘while’ activity first checks
for the condition and then executes the iterative activities. Figure 4.5 shows the data flow
path of parsing ‘repeatUntil’ activity.
Start rptSeq ()
function
Is activity
<sequence>?
True
Call seqFun (),
function to parse
sequence node
False
Call parser to parse
primitive activity
Call getCondition ()
to customize the
value of <condition>
element
Return current state
number to seqFun ()
Figure 4.5: Data Flow Diagram to Parse ‘repeatUntil’ Activity
Figure 4.5 clearly shows that function getCondition() is called after the iterative activities
is parsed. After parsing <condition> element the current state number is returned to the
seqFun().
37
4.2.5. Parsing ‘forEach’ Structured Activity
“A ‘forEach’ element repeatedly executes its contained scope activity exactly N+1 times,
where ‘N’ equals to the Final Counter Value minus the Start Counter Value” [14]. An
optional ‘Completion condition’ can be specified which executes the enclosed iterative
activity till the condition is satisfied; if and only if the condition expression is equal to or
less than the available number of iterations [14]. Figure 4.6 shows the data flow diagram
of parsing ‘foreach’ activity.
Call getCounter () to
extract the start and
final counter values
Start whileSeq ()
function
Is activity
<condition>?
True
Call getCondition ()
to customize the
value of <condition>
element
True
Call seqFun (),
function to parse
sequence node
False
Call parser to parse
primitive activity
False
Is activity
<sequence>?
Return current state
number to seqFun ()
Figure 4.6: Data Flow Diagram to Parse ‘forEach’ Activity
38
Chapter 5
SOFTWARE AND HARDWARE DETAILS
5.1 Overview
The chapter talks mainly about the software and hardware specification and details
required for the components of the project to run successfully.
5.2 Software Setup
The developed application requires installation of following software components in the
same order in which they are mentioned as below.
•
Java Development Kit (JDK) 6.0 Update 4 or higher
•
NetBeans 6 (IDE) Enterprise pack
•
MySQL 5.1 or higher
•
Connector/J which allows Java to interact with MySQL database.
5.2.1 Java Development Kit (JDK)
JDK [15] is a product of Sun Microsystems and it is one of the most commonly used Java
SDK (Software Development Kit). JDK is an integral part of SDK which allows a
developer to write and run java programs. SDK in addition to JDK supports servers,
debuggers and additional software’s. JDK is an open source code which is available for
free at http://java.sun.com/javase/downloads/index.jsp. To develop a Java application,
JDK includes JRE (Java Runtime Environment) which in-turn supports Java Virtual
39
Machine that provides all the necessary class libraries. “Java SE Development Kit (JDK)
is usually included within Java EE 5 SDK, which supports GlassFish application server
and provides web services, component-model, management, and communications APIs
that are required for implementing an enterprise service-oriented architecture (SOA)”
[16].
5.2.2 NetBeans
NetBeans [15] is an Integrated Development Environment (IDE) that allows a software
developer to develop applications using Java, JavaScript, PHP, Ruby, C/C++ and Groovy
programming language. Like JDK, IDE is also an open source code that has been coded
in Java using NetBeans Platform. The IDE can be downloaded for free at
http://www.netbeans.info/downloads/dev.php.
NetBeans IDE [15] allows a developer to develop applications on top of build-in software
components, called as modules. Typically, a module is a ‘.jar’ file which is similar to a
zip folder, where each ‘.jar’ file consists of a set of java classes all of which together
provides support to perform specific functionality by interacting with the NetBeans API.
Applications build on top of these modules will be converted into ‘.jar’ file by the IDE,
which can be later included in the library list of a new application, under development.
IDE allows modules to be developed independently and hence this provides third party
developers to easily extend the applications that are build on NetBeans platform.
40
A complete SOA application from Web Services to BPEL implementation can be build
using NetBeans IDE. In-order to build BPEL orchestration it is necessary to first build
XSD and WSDL files respectively and these files can be developed easily using
NetBeans IDE.
5.2.3 MySQL
MySQL [15] also called as “My Structured Query Language” is a relation database
management system. MySQL Server is an open source code that can be downloaded for
free at http://dev.mysql.com/downloads/mysql/5.1.html. MySQL code is developed using
C and C++ and is most commonly used database component for many web applications.
To parse the SQL queries the server uses YACC and LEXER analyser. One can write a
SQL query either in a command line tool or in a GUI called MySQL Query browser
which is an integral part of the MySQL suite which also includes MySQL Administrator
and this entire suite can be downloaded for free. The project uses MySQL 5.1 to store the
parsed information.
5.2.4 MySQL Connector/J
MySQL provides connectivity with applications developed in the Java programming
language via a JDBC driver, which is called MySQL Connector/J. To connect to a
database, a database URL is required. URL serves as a unique name to identify a
resource. The structure of a URL [17] used in JDBC is as follows,
41
“jdbc:subprotocol:subname”
In an HTTP URL the keyword ‘http://’ represents the protocol used for communication;
similarly JDBC URL uses ‘jdbc:’ as a keyword and it represents the protocol name used
for communication between the application and MySQL. The sub-protocol indicates the
database name to connect, i.e. ‘mysql’ in this project. ‘subname’ provides information as
to where the MySQL server is running. Along with the URL, the class name of the JDBC
driver is required and for a MySQL Connector/J JDBC driver the class name is
‘com.mysql.jdbc.driver’. [17]
To connect to the database java.sql.DriverManager.getConnection() method is used. The
method accepts three arguments namely the URL, username under whom the database is
to be connected and the password for the username entered. Once all the necessary
arguments are provided the method finds the driver, which is loaded in JVM and then
delegates the work of establishing the connection to the driver [17]. MySQL Connector/J
driver can be downloaded from http://dev.mysql.com/downloads/connector/j/5.1.html.
Following are the steps to be performed in-order to add MySQL Connector/J driver into
NetBeans IDE.
1. Once the ‘mysql-connector-java-5.1.7’ is downloaded extract the “mysqlconnector-java-5.1.7-bin.jar” file from the folder and place it in ‘C:\Program
Files\Java\jdk1.6.0_04\jre\lib’
42
2. Right click on the ‘Drivers’ node found under ‘Database explorer’ in ‘Service’
window to add new JDBC driver from the path as mentioned in step 1. On ‘OK’
IDE creates a new entry called ‘MySQL (Connector/J driver)’ under Drivers node
[18].
Figure 5.1: Adding JDBC Driver to NetBeans IDE
3. To establish a new database connection, right click on ‘MySQL (Connector/J
driver)’ and specify the URL, User name and the password.
43
Figure 5.2: Establishing a New Database Connection
5.3 Hardware Requirements and Specifications
•
1.6 GHz Intel Pentium Dual Core or equivalent
•
1 GB RAM
•
1 GB of free disk space
44
Chapter 6
IMPLEMENTATION DETAILS
6.1 Creating Table BPEL_FLOW
A parser requires a table BPEL_FLOW to be created before it is deployed. The table is
created by executing the query:
CREATE TABLE bpel_flow (
id smallint(5) unsigned NOT NULL auto_increment,
ServiceName varchar(50) NOT NULL,
MyRole varchar(50) NOT NULL,
PartnerRole varchar(512) default NULL,
Activity_Name varchar(50) NOT NULL,
Current_State varchar(50) default NULL,
PartnerLink varchar(50) default NULL,
Operation varchar(50) default NULL,
InMsgType smallint(5) unsigned default NULL,
OutMsgType smallint(5) unsigned default NULL,
Conditions varchar(100) default NULL,
Activity_Seq varchar(6) NOT NULL,
Next_Activity varchar(6) NOT NULL,
PRIMARY KEY (id)
);
45
6.2 Database Server Connection
In order to establish a connection to the database it is necessary to load the database
driver. Once the driver is loaded then a connection string is generated as shown in the
below java snippet, this connection string is used to communicate with the database for
all future database references.
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/bpelparser";
con = DriverManager.getConnection(url, "root", "root");
if(!con.isClosed())
System.out.println("Successfully connected");
else
System.out.println("Connection failed");
The connection to the database can be closed using ‘con.close();’ function. In order to
perform the above activities it is necessary to include the following files,
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.SQLException;
46
6.3 Parsing BPEL file
The following iterative function parses and extracts the contents within a BPEL file.
•
seqFunc() – To parse the contents within the <sequence> element
•
getCondition() – To extract required values in a condition statement.
•
ifSeq() – To parse the contents of <if> element
•
whileSeq() – Parses the <while> element
•
forEachSeq() – To parse the <forEach> element
•
rptSeq() – Parses the contents within <repeatUntil> element
•
webservice() – To parse the primitive activities.
For the parsing to be performed it is first necessary to upload and read the XML file. The
following code reads the XML file using a DOM parser. DOM parser loads the XML file
into the memory and makes an object model of it. This object model can be traversed to
extract the required details.
DocumentBuilderFactory dbFactory =DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbFactory.newDocumentBuilder();
Document doc = docBuilder .parse(pathoffile);
Node root = doc.getFirstChild();
NodeList bpelnodes = root.getChildNodes();
In order to perform the parsing of XML using XML DOM the following files needs to be
included,
47
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.*;
import java.util.*;
The information extracted from each statement/activity in BPEL is stored into global
memory variable ‘seqMap’. Figure 3.1 and Figure 3.2, which is designed to keep track of
the history are implemented as ‘HashMap’ data structure as follows,
private HashMap seqMap = new HashMap();
private HashMap ifelseTbl = new HashMap();
private int seqiifKey = 0;
private HashMap seqTbl = new HashMap();
private int seqTblKey = 0;
Figure 3.1 and Figure 3.2 are implemented as ‘seqTbl’ and ‘ifelseTbl’ respectively.
‘seqTblKey’ is the hash key for ‘seqTbl’ and ‘seqiifKey’ is the hash key for ‘ifelseTbl’ which defines ‘child_if_strLevel’ and ‘child_if_endLevel’ fields in ‘seqTbl’. The values
of each entry in ‘ifelseTbl’ and ‘seqTbl’ are of array list type. A new entry in ‘seqTbl’ is
added only when ‘if’, ‘else’, ‘while’, ‘foreach’ or ‘repeatUntil’ structural activities has
been encountered, since by definition a ‘seqTbl’ is designed to maintain the history of
looping structural activities.
48
6.3.1 Working of seqFun()
The following code has to be executed in-order to extract the elements within the
<sequence> element.
NodeList seqnodes = elem.getChildNodes();
for ( i=0; i<seqnodes.getLength(); i++)
{
Node seqnode = seqnodes.item(i);
int seqType = seqnode.getNodeType();
if(seqType == Node.ELEMENT_NODE)
{
activName = seqnode.getNodeName();
...
}
}
In a BPEL file the programming logic is always enclosed within a <sequence> element.
If a structural activity is composed by more than one primitive activity then the primitive
activities have to be enclosed within <sequence> element. Since seqFun() is a generic
iterative function it is also called by other functions such as whileSeq(), forEachSeq(),
ifSeq() and rptSeq() whenever it encounters a <sequence> element. The variable
‘strName’ holds the information about which structural activities the element <sequence>
is related to; if it identifies to be of any looping structural activities then it is necessary to
update the details of the topmost entry in ‘seqTbl’ based on the ‘activName’ encountered.
49
The below program shows when the ‘activName’ is <while> activity and if ‘strName’ is
either an ‘if’ or ‘else’ or ‘forEach’ or ‘repeatUntil’ or ‘while’ then the fields of ‘seqTbl’
are set to appropriate values based on the activity being parsed i.e., <while> activity in
this scenario, and the rest of the fields of the ‘seqTbl’ are all set to a default value of -1.
if(activName.equals("while"))
{
if(strName.equals("while")||strName.equals("if")||strName.equals("else")||
strName.equals("repeatUntil")|| strName.equals("forEach"))
{
cpySeqTree = (ArrayList)seqTbl.get(seqTblKey);
parentID = (Integer)cpySeqTree.get(seqTbl_parent_ID);
childID = parentID+1;
cpySeqTree.set(seqTbl_child_ID, childID);
cpySeqTree.set(seqTbl_child_strt_seq,(seqKey+1));
cpySeqTree.set(seqTbl_whileBit,0);
cpySeqTree.set(seqTbl_child_lst_seq, -1);
cpySeqTree.set(seqTbl_child_if_strtLevel, -1);
cpySeqTree.set(seqTbl_child_if_endLevel, -1);
cpySeqTree.set(seqTbl_ifBit, -1);
cpySeqTree.set(seqTbl_reptUntilBit, -1);
cpySeqTree.set(seqTbl_forEachBit, -1);
cpySeqTree.set(seqTbl_forEachCondKey, -1);
}
50
activSeq = whileSeq(seqnode,activName,activSeq);
if(strName.equals("while")||strName.equals("if")||strName.equals("else")||
strName.equals("repeatUntil")|| strName.equals("forEach"))
{
cpySeqTree.set(seqTbl_child_lst_seq,seqKey);
}
}
6.3.2 Working of getCondition()
All the looping structural activities define <condition> element. Value within ‘condition’
tag is an expression, which evaluates to a boolean value. To describe ‘condition’, BPEL
supports operators such as ‘=’, ‘!=’, ‘<’, ‘>’, ‘<=’, ‘>=’, ‘substring’, ‘substring-before’,
‘substring-after’, and ‘starts-with’. The function getCondition() is implemented to parse
the value within the <condition> tag and extract the operands and operator in the format
of ‘operandLeft.operator.operandRight’. ‘operandLeft’ and ‘operandRight’ can either be
a value or a variable, if it is a variable then both ‘document’ and ‘field’ name are
extracted and concatenated using a delimiter ‘.’.
For the operators ‘=’, ‘!=’, ‘<’, ‘>’, ‘<=’, ‘>=’ one of the observation done in a BPEL
document is that, the operand and the operator is always separated by a ‘space’ character.
Exploiting the feature, the value within <condition> element are split on ‘space’ character
and the operands and the operators are extracted into ‘condAttribute’ array list as shown
in the below snippet.
String condElem[] = condValue.split(" ")
51
for(int i=0; i<condElem.length; i++)
{
if ( condElem[i].equals("") || condElem[i].equals("(") ||
condElem[i].equals(")") )
continue;
else
condAttribute.add(condElem[i]);
}
Once the left and right operands of an operator are separated, each of the operand is fed
into parseOperand() to customise the value according to the format.
To parse ‘substring’, ‘substring-after’, ‘substring-before’, and ‘starts-with’ it is essential
to know the format how they are defined in BPEL. The format as follows respectively,
•
substring(string, number, number)
•
substring-after(string, string)
•
substring-before(string, string)
•
starts-with (string, string)
In the above string operations the argument ‘string’ can be a nested substring() operation.
Few of the observation done in the above formats are;
•
Always the arguments are enclosed within parenthesis
•
Arguments are always separated by comma.
52
The below snippet uses regular expression to split the <condition> value
String subStringElem[] = cond.split("(?=[,()])");
if(cond.startsWith("substring-before(")|| cond.startsWith("substring-after(")||
cond.startsWith("starts-with("))
{
result =
parseOperand(subStringElem[1].substring(1))+"."+parseOperand(subStringElem[2]
.substring(1));
}
if(cond.startsWith("substring("))
{
result = "substr."+parseOperand(subStringElem[0].substring(10));
if(subStringElem[1].startsWith("number"))
result = result + ".StartPos."+getNumber(subStringElem[1]);
else
result = result + ".StartPos."+subStringElem[1].replace(")", "");
if(subStringElem[2].startsWith("number"))
result = result + ".StartPos."+getNumber(subStringElem[1]);
else
result = result + ".StartPos."+subStringElem[1].replace(")", "");
}
53
6.3.3 Working of ifSeq()
The function ifSeq() is an iterative function which is called whenever <if> or <else>
activity is encountered. An entry within ‘ifelseTbl’ is added only when <if> activity is
encountered.
seqiifKey++;
llevel = seqiifKey;
ifelseTbl.put(seqiifKey, locallevel);
locallevel.add(ifelseTbl_begin_ifKey, ifKey);
locallevel.add(ifelseTbl_lst_ifKey,lastifKey);
locallevel.add(ifelseTbl_lst_elseKey, -1);
A new entry within ‘seqTbl’ is added when either ‘if’ or ‘else’ or any other structural
activities has been encountered. The following code adds an entry into ‘seqTbl’ and the
implementation is same for all other looping structural functions.
seqTblKey++;
seqTblEntryKey = seqTblKey;
seqTree.add(seqTbl_parent_ID, seqTblKey);
seqTree.add(seqTbl_child_ID,-1);
seqTree.add(seqTbl_child_strt_seq,-1);
seqTree.add(seqTbl_child_lst_seq,-1);
seqTree.add(seqTbl_child_if_strtLevel,-1);
54
seqTree.add(seqTbl_child_if_endLevel,-1);
seqTree.add(seqTbl_ifBit,-1);
seqTree.add(seqTbl_whileBit,-1);
seqTree.add(seqTbl_reptUntilBit,-1);
seqTree.add(seqTbl_forEachBit,-1);
seqTree.add(seqTbl_forEachCondKey,-1);
seqTbl.put(seqTblKey, seqTree);
Initially the values are set to default -1 and based on the encountered structural elements
the values are updated. As shown in Figure 4.2 the ifSeq() is called in both <if> or <else>
activity occurrence.
if (ifName.equals("else"))
{
elseBeginKey = seqKey;
elseactivSeq = activSeq;
activSeq = ifSeq(ifnode, ifName, activSeq);
lastelseKey = seqKey;
key = keyValue(seqTblEntryKey, elseBeginKey);
updSeqMap(activSeq, key);
if(elseBeginKey == lastifKey)
{
locallevel.set(ifelseTbl_lst_elseKey, lastelseKey);
updateActiveSeq(activSeq, llevel, seqTblEntryKey);
else
}
55
seqiifKey--;
}
The function updateActiveSeq() corrects the next state of the nested <if> activity only
when ‘else’ does not exist for the nested ‘if’ condition, but if there exists an ‘else’ then it
updates the next state of the last instruction of the nested ‘else’. Finally, it updates the
next state of the last instruction of the nested ‘if’. The process of correction continues
until all the nested ‘ifelse’ have been updated correctly.
‘activSeq’ defines the current state. The ‘elseactivSeq’ is initially set to a default value of
-1, which is also used to identify whether an <else> activity exists for an <if> activity. An
<else> activity starts only after the completion of <if> activity, so ‘elseBeginKey’ is also
the last key in an <if> activity. The function keyValue() is used to determine whether
‘lastifKey’ is indeed the last key in an <if> activity? The function keyValue() is designed
to fetch the state number of an inner loop condition instruction, if it turns to be the last
instruction within an outer loop.
while(startSeqTblKey <= seqTblKey)
{
seqTree = (ArrayList)seqTbl.get(startSeqTblKey);
int beginKey = (Integer)seqTree.get(seqTbl_child_strt_seq);
int lastKey = (Integer)seqTree.get(seqTbl_child_lst_seq);
int whileBit = (Integer)seqTree.get(seqTbl_whileBit);
int fEachBit = (Integer)seqTree.get(seqTbl_forEachBit);
56
if(lastKey == key && whileBit == 0 && fflag ==0)
{
returnKey = beginKey;
wflag = 1;
}
if(lastKey == key && fEachBit == 0 && wflag == 0)
{
returnKey = beginKey;
fflag = 1;
}
startSeqTblKey++;
}
return returnKey;
6.3.4 Working of whileSeq()
The function whileSeq() is an iterative function i.e., when a <while> activity is
encountered within <while> the function is called by itself. Like in ifSeq(), even in
whileSeq() a new entry within ‘seqTbl’ is added when <while> loop structural activities
has been encountered. ‘While’ requires to test the condition every time before entering
into the loop, so it is necessary to store the ‘activeSeq’ (also called as current state
number) of the <condition> activity, which represent the next state for the last instruction
within <while> activity sequence. But as discussed in section 3.2 what if inner loop is the
last instruction for the outer loop. For the parser the last instruction of the inner loop
looks like the last instruction of the outer loop, and as a result assigns the next state of the
last instruction of the inner loop to point to the state number of the outer loop condition,
which is not correct. To rectify this mistake, after all the instructions within <while>
activity is parsed, and just before the exit of the whileSeq() function the below function is
invoked,
57
exitClean(seqTblEntryKey, whileactivSeq, lastKey);
The main idea behind this function is that, if an inner loop exists then all the details
pertaining to the inner loop are entered into ‘seqTbl’ on top of the details pertaining to the
outer loop. So, the idea of the function exitClean() is to extract the details of the inner
loop and cross verify whether the state number of the last instruction in an outer loop
matches with the state number of the last instruction in an inner loop. If so then it updates
the next state of the inner loop condition instruction to point to the state number of the
outer loop condition instruction.
if(parentLastKey == childLastKey)
{
if(childRepBit == 0)
{
updSeqMap(beginActivSeq, childLastKey);
break;
}
if (childWhileBit == 0 or childfEachBit == 0)
{
updSeqMap(beginActivSeq, childSeqKey);
break;
}
if(childIfBit == 0)
58
{
/* this implies an <if> activity was encountered within <while>
activity so there is need to check whether <if> activity contains nested ‘if’ */
if(childStrtLevel == childEndLevel)
{
/* this implies there were no nested ‘if’. So, the next state of
the last instruction within <if> and <else> activities are updated to
the current state number of the ‘while’ condition. */
if(lastElseKey == -1)
{
updSeqMap(beginActivSeq, lastIfKey);
updSeqMap(beginActivSeq, ifKey);
}
else
{
updSeqMap(beginActivSeq, lastElseKey);
updSeqMap(beginActivSeq, lastIfKey);
}
}
else
{
/* this implies that there were nested ‘if’ so it is necessary to
update next state of the last instruction within all nested ‘if’ */
updateActiveSeq(beginActivSeq, childStrtLevel,
seqTblEntryKey);
59
/* Working of the function updateActiveSeq() is explained in
Section 6.3.3 */
}
}
}
6.3.5 Working of forEachSeq()
The implementation of forEachSeq() is very much similar to that of whileSeq() but the
only difference with respect to the working principle of handling the condition in
‘forEach’. ‘forEach’ has a start counter, final counter and an optional condition
instruction as explained in Section 4.2.5 where as ‘while’ has only a condition. In order to
support the optional condition feature, in ‘forEach’ the field ‘forEachCondKey’ within
seqTbl is provided. The field is by default set to -1, this field also tells whether the
condition instruction exists or not.
If the condition instruction exists then it is necessary to update its next state to the state
number of the first instruction encountered outside the ‘forEach’ loop.
if(conditionKey != -1)
{
Value = seqMap.get("" + conditionKey).toString();
String branchvalues[] = Value.split("_");
if(branchvalues[0].equals("completionCondition"))
60
{
branchValue = branchValue+ ";" + activSeq;
seqMap.put("" + conditionKey, branchValue);
}
}
In order to handle nested loop structure, forEachSeq() also calls the same function as
whileSeq() just before the exit of the forEachSeq()
exitClean(seqTblEntryKey, whileactivSeq, lastKey);
6.3.6 Working of rptSeq()
In a repeat until the conditions are tested at the end of the loop, as a result all the
instructions within the iteration are executed at least once. In BPEL, the <condition>
activity for ‘repeatUntil’ is the last instruction to be executed within the loop. The
possible next states of a repeat until condition are the state number of an instruction
immediately followed after the <condition> activity (which is straight forward) and the
state number of the first instruction within the iteration (to define this it is necessary to
remember the state number of the first instruction within the iteration).
int startActivSeq = activSeq;
‘startActivSeq’ contains the state number of the first instruction in the iteration. Handling
inner loops in ‘foreach’ doesn’t involve the complexities as encountered while parsing
‘while’ and ‘forEach’ since the last instruction in repeatUntil is the condition itself;
61
which is not the same as in ‘while’ and ‘forEach’ as a result the function keyValue()
defined in Section 6.3.2 doesn’t check for the ‘reptUntilBit’ value.
6.3.7 Working of webservice()
This function is defined to extract element name, attribute values of an activity. DOM
provides built-in API to extract these items.
webelem.getAttributeNode("partnerLink").getNodeValue();
webelem.getAttributeNode("operation").getNodeValue();
webelem.getAttributeNode("portType").getNodeValue();
webelem.getAttributeNode("variable").getNodeValue();
webelem.getAttributeNode("inputVariable").getNodeValue();
webelem.getAttributeNode("outputVariable").getNodeValue();
The above API’s extracts the values of the attribute ‘partnerLink’, ‘operation’,
‘portType’, ‘variable’, ‘inputVariable’, ‘outputVariable’ respectively, defined within in
each primitive activities.
62
Chapter 7
RESULTS
The input to the BPEL activity parser is a BPEL file. Figure 7.1 shows the design view of
the BPEL input file.
Figure 7.1 Design View of BPEL Input File
63
In the Figure 7.1 the modules ‘LoanProcessor’ and ‘LoanRequestor’ represents the web
services. Each of the icons within the state diagram that interacts with the web services
are instruction statement also called an activity. The source code of each activity includes
partner link, port type that defines the port number where the web services are available,
name of the operation to be invoked and the messages that needs to be transmitted.
The outcome of the parser is a database entry in BPEL_FLOW table. Each row entry
represents the details of an individual activity which provides information about MyRole,
Partner Role, activity name – also called as ‘Current_State’, partnerLink – which
represents the associated web service, name of the operation being invoked, input
variable, output variable, condition of a looping structural activities, current state number
– called as ‘Activity_seq’, and next possible state numbers – called as ‘Next_activity’.
Figure 7.2 shows the representation of the state diagram as in Figure 7.1 in terms of
database row entries.
Figure 7.2: Representation of Figure 7.1 as Table Row Entries.
64
The project has been tested on the WebPonder application. A web-ponder is a Customer
Relationship Management (CRM) system which is developed under the supervision of
Dr. Jinsong Ouyang, Assistant professor of Department of Computer Science, California
State University, Sacramento. Given a working business model, the application can be
used in various business domains. For example, the application can be used for a
corporate company to handle employee reimbursement, for a college to support online
course registration, for an e-commerce business domain to handle e-ticketing for a movie,
soccer game etc. Here the corporate company, college, and e-commerce are business
domains where as the employee reimbursement, online course registration and e-ticketing
are the business models. The business models are represented as BPEL document, which
depends on WSDL and XML Schema documents as explained in Chapter 2.
It is here where the BPEL structural activity parser parses the BPEL document, and
converts the user understandable state chart BPEL document diagram to application
understandable language i.e., representation of each activity interaction within
BPEL_FLOW table. When the application is executed the next service to be executed by
the application is determined based on the next state number and the operation name
corresponding to this number, and these are generated while parsing the BPEL document.
For any conditional operation there can be atmost two possible static states, but during
dynamic execution there can be only one state, which is determined based on the user
input values and the operator within the condition.
65
The test case created was for a college business domain, specific to online course
business model. The business model to create a course in perspective to course provider
role involves the process of first creating a course name, adding the syllabus for that
particular course, adding any number of lecture notes which is terminated based on user
input on whether the current lecture is a last lecture or not, adding assignments, exams
and finally by adding a grade roster. The logic to add assignments and exams follows the
same termination principle as that of adding lecture notes.
The test scenario supported all the operators and functions namely ‘=’, ‘!=’, ‘<’, ‘>’,
‘<=’, ‘>=’, ‘substring’, ‘starts-with’, ‘substring-after’, ‘substring-before’. The test case
for the business model supported structural activities namely ‘sequence’, ‘while’,
‘repeatUntil’, ‘if’, ‘invoke’, ‘receive’. The looping structural activities were nested.
66
BIBLIOGRAPHY
[1] Michael Cobban. ( 2004). “What is BPEL and why is it important to my business?”.
[Online]. Available: http://www.softcare.com/whitepapers/wp_whatis_bpel.php
[2] Antony Miguel. (October, 2005). “WS-BPEL 2.0 Tutorial”. [Online]. Available:
http://www.eclipse.org/tptp/platform/documents/design/choreography_html/tutorials/wsb
pel_tut.html#overview
[3] Mrinalini Kabbur. “Developing a parser for BPEL Documents”. CSUS, Tech. Rep.
August. 2008.
[4] Ben Margolis, Joseph Sharpe. “SOA for the business developer: Concepts, BPEL and
SCA”, May, 2007.
[5] w3schools [Online]. Available: http://www.w3schools.com/dom/default.asp
[6] Kevin Howard Goldberg, “XML: Visual QuickStart Guide”, 2nd edition, December
2008.
[7] w3schools [Online]. Available: http://www.w3schools.com/Schema/default.asp
[8] Latha Srinivasan, Jem Treadwell. (November, 2005). “An Overview of Serviceoriented Architecture, Web services and Grid Computing”. [Online]. Available:
http://h71028.www7.hp.com/ERC/downloads/SOA-Grid-HP-WhitePaper.pdf
[9] Sanjiva Weerawarana, Francisco Curbera, Frank Leymann, Tony Storey, Donald F.
Ferguson, “Web services platform architecture”. March 2005
67
[10] Francisco Curbera. (July, 2001). “Web Services Overview”. [Online]. Available:
https://computation.llnl.gov/casc/workshops/components_2001/viewgraphs/FranciscoCur
bera.pdf
[11] Matjax B. Juric. “A Hands-on Introduction to BPEL”. [Online]. Available:
http://www.oracle.com/technology/pub/articles/matjaz_bpel1.html
[12] Jonathan Robie. (September 2000). “What is the Document Object Model?”
[Online]. Available: http://www.w3.org/TR/2000/WD-DOM-Level-120000929/introduction.html
[13] Elliotte Rusty Harold. (2001, 2002.). “Processing XML with Java” [Online].
Available: http://www.cafeconleche.org/books/xmljava/chapters/index.html
[14] Netbeans.org. [Online]. Available: http://netbeans.org/kb/61/soa/index.html
[15] Wikipedia.org [Online]. Available: http://en.wikipedia.org
[16] Java.sun.com [Online]. Available: http://java.sun.com/javase/downloads/index.jsp
[17] Faisal Khan. “Connection to a MySQL database using Connector/J JDBC Driver”.
[Online]. Available:
http://www.stardeveloper.com/articles/display.html?article=2003090401&page=1
[18] Netbeans.org. [Online]. Available:
http://www.netbeans.org/kb/60/ide/mysql.html#connecting
Download