Presentation is loading. Please wait.

Presentation is loading. Please wait.

Teaching Web Services and XML with the Water Language

Similar presentations


Presentation on theme: "Teaching Web Services and XML with the Water Language"— Presentation transcript:

1 Teaching Web Services and XML with the Water Language
Christopher Fry Clear Methods, Inc. Ed Gehringer and Matt Kendall North Carolina State University The Water Logo is trademark by Clear Methods, Inc.

2 Agenda Teaching Web services Introduction to Water
ConciseXML Things Servers Steam IDE The Water object model The Water Logo is trademark by Clear Methods, Inc.

3 Introduction: Web-services example
A new airline, Web Air, would like to add car rental services to their on-line ticket sales system. The Web Air reservation system operates off of a database of flight information: no knowledge of rental cars. Web Air’s ticket system must obtain rental data from rental car agencies. What problems could Web Air encounter in gaining this information? The Water Logo is trademark by Clear Methods, Inc.

4 Introduction: Web Air Problems
Rental companies may operate on different platforms. Example: Mainframes vs. Linux clusters. Individual rental companies may format rental car information differently. Example: Using RGB values to indicate the color of a car, vs. using a string value. Rental companies may use proprietary formats to store data. Example: A binary format created for an individual company. Access to the data may occur over antiquated or proprietary protocols. Example: Using Solaris remote procedure calls to access the data. The Water Logo is trademark by Clear Methods, Inc.

5 Introduction: Web Services
One way to simplify data sharing is to apply standards to interactions between the systems involved. Web services use a set of standards to simplify machine-to-machine communications. XML for both input and output. Web Air’s ticket system only needs to understand XML. Gets XML data from vendors. The Water Logo is trademark by Clear Methods, Inc.

6 Web Services: Interfaces
Standards require that the interface for each Web service be published. The interface is a contract that specifies the available inputs, the formatting of outputs, and the protocols that the Web service employs to transmit data. The protocols employed by Web services are Internet standards such as HTTP, FTP, and SMTP. These protocols have been tested on very large scales, and operate in existing security paradigms. The Water Logo is trademark by Clear Methods, Inc.

7 Web Services: Interfaces (2)
Since inputs and outputs are well defined, Web Air’s ticket system can: Query rental car Web services using an XML query generated based on the published interface. Receive the XML response from the rental car Web service. Use the known interface to translate the data from each rental car agency into a format that it can use internally. The Water Logo is trademark by Clear Methods, Inc.

8 Teaching Web services Web services are hard to teach. Why?
Implementation is complex SOAP WSDL Which platform? J2EE? .NET? Syntax-to-concept mapping The good (human language capacity) The bad (lousy, non-uniform syntaxes) The ugly (multiple incompatible languages) How do we educate students about Web services, Rather than train them in a specific technology? Concepts are simple, implementation is complex.

9 Why Teach with Water? Supports Web services natively.
So we are teaching the concepts. Can return responses in XML, HTML, or SOAP So we don’t have to spend time on libraries.

10 Agenda Teaching Web services Introduction to Water
ConciseXML Things Servers Steam IDE The Water object model The Water Logo is trademark by Clear Methods, Inc.

11 Introduction to Water Water (http://www.waterlanguage.org) is an open, all-purpose language designed for XML Web services. It provides a simple yet powerful way of writing Web services by supporting XML within its core. The Water Logo is trademark by Clear Methods, Inc.

12 Introduction (2) Without Water, XML is used on the "outside"—programs are needed to convert into and out of XML. Water is a language specifically designed for XML. It allows the option of using XML for everything: presentation, logic, content, modeling, etc. The Water Logo is trademark by Clear Methods, Inc.

13 ConciseXML XML is, by default, a very verbose method of representing data. Water uses an extension of XML, ConciseXML, to reduce the amount of text required to represent data in XML. All XML is valid ConciseXML, because ConciseXML is an extension. Not all ConciseXML is valid XML. The Water Logo is trademark by Clear Methods, Inc.

14 ConciseXML: Tag Shorthand
Closing tags can be notated as </>. XML 1.0: <text>Hello!</text> ConciseXML: <text>Hello!</> The Water Logo is trademark by Clear Methods, Inc.

15 ConciseXML: Positional Arguments
Water uses XML tags to make method calls with XML attributes as parameters. Methods are predefined, there is no need to specify the attributes as key=value pairs. The Water Logo is trademark by Clear Methods, Inc.

16 ConciseXML: Positional Arguments (2)
The key is simply omitted. XML 1.0: <person first="Ed" last="Gehringer"/> ConciseXML: <person "Ed" "Gehringer"/> The Water Logo is trademark by Clear Methods, Inc.

17 ConciseXML: Path Notation
Representing nested logic is complex in XML. ConciseXML simplifies nesting by supporting a dot notation. "abe".<foo color="blue"/>.bar ConciseXML is designed to allow XML to better represent data and logic by removing both verbosity and ambiguity from the language. The Water Logo is trademark by Clear Methods, Inc.

18 ConciseXML: Path Notation (2)
<execute_path> "abe" <foo color="blue"/> bar </execute_path> ConciseXML: "abe".<foo color="blue"/>.bar The Water Logo is trademark by Clear Methods, Inc.

19 Things Like many object oriented languages, everything in Water is an object. The most generic class in Water is a thing. Objects in water have a set of properties, called fields. We can create a thing without fields: <thing/> The Water Logo is trademark by Clear Methods, Inc.

20 Things (2) <thing shape="square" size=10/>
Creates a thing with the fields shape and size. ConciseXML does not require parameter names, but we have provided them here. What happens when we execute the following Water code? <thing "square" 10/> The Water Logo is trademark by Clear Methods, Inc.

21 Things (3) We can use the path notation provided by ConciseXML to select a specific field: <thing x=10 y=14 z=-4 message=<h1>A Point P</> />.z What value does this code fragment return? Notice that the message field in the above thing contains an <h1> object. Also note that the <h1> object’s tag has a body, i.e. it is not an empty tag, unlike the thing objects we have seen so far. This means that Water can support seemingly unstructured content in the body of object tags. -4 The Water Logo is trademark by Clear Methods, Inc.

22 Things (4) Water applies a structure to the content of each tag.
<h1>A large <thing "header"/> object!</>.0 <h1>A large <thing "header"/> object!</>.1 <h1>A large <thing "header"/> object!</>.2 What will each statement return? The Water Logo is trademark by Clear Methods, Inc.

23 Servers Methods are easy to define in Water.
This simple method returns a thing with the specified fields. <defmethod foo> <thing "bar" <thing "foo" "bar"/> <h1>Foo Bar!</> /> </> The Water Logo is trademark by Clear Methods, Inc.

24 Servers: Executing a Method
We can create a server that will execute our method: <server root=foo port=8000/> We can execute this method by visiting The question mark (?) is included because we want to execute <foo>. What happens if we visit without the question mark? The Water Logo is trademark by Clear Methods, Inc.

25 Servers: Parameters We can also provide required parameters in the request. This Water program defines a method <foo> that has a required parameter x. Foo creates a thing with a field value that equals x. What will happen if we execute <defmethod foo x=required> <thing value=x/> </> <server root=foo port=8000/> The Water Logo is trademark by Clear Methods, Inc.

26 Servers: Omitting a Parameter
What if we execute now? What about the message returned by the server reminds us of our previous studies of Web services? <defmethod foo x=required> <thing value=x/> </> <server root=foo port=8000/> The Water Logo is trademark by Clear Methods, Inc.

27 Servers: Calling from Programs
So far, all the services we have called have been invoked from a browser. It is also possible to call a Web service from a program. This code snippet will execute the method <foo> with x="Hello World!“ <set mything= <web "http://localhost:8000/"/> /> <mything x="Hello World!"/> The Water Logo is trademark by Clear Methods, Inc.

28 Servers: Local Invocation
Of course, for local methods such as <foo>, we can also execute: <foo "Hello World!"/> The Water Logo is trademark by Clear Methods, Inc.

29 Steam IDE Water source files can be edited in any text editor, but the Steam IDE is designed to write Water programs. Code is executed by highlighting a statement and pressing the execute button. Once code is executed, its effects remain in the environment until they are changed by a later execution. The Water Logo is trademark by Clear Methods, Inc.

30 Steam IDE (2) <set myvar=<h1>Execution One</> />
The variable myvar is assigned the <h1> object. If at a later time you execute: <echo myvar/> The value of myvar is retained from the previous execution. This retention of the environment allows for rapid, iterative development. The Water Logo is trademark by Clear Methods, Inc.

31 Steam IDE (3) Objects can be inspected by double-clicking on their name in the editing pane. The Water Logo is trademark by Clear Methods, Inc.

32 Agenda Teaching Web services Introduction to Water
ConciseXML Things Servers Steam IDE The Water object model The Water Logo is trademark by Clear Methods, Inc.

33 The Water object model The Water object model is simple, yet extremely powerful. It can be described in four statements. Everything is an object. An object has fields. Each field has a key and a value. The key and value can be any object. The Water Logo is trademark by Clear Methods, Inc.

34 An Object Consider this object:
<thing a= s="This is a string" d=<thing 10 20/> /> How many fields does it have? What are the keys? What are the values? 4 a, s, d 2.7, 343, "This is a string", <thing 10 20/> The Water Logo is trademark by Clear Methods, Inc.

35 Classes & Methods Recall that Web services must publish a well defined interface, or contract, that defines their inputs and outputs. Water contracts are based on class and method definitions. Classes are created using <defclass/> and methods are created using <defmethod/>. The Water Logo is trademark by Clear Methods, Inc.

36 Classes & Methods: Classes
We can easily create a class in Water: <defclass myclass one two/> This expression defines a class called <myclass> that has two fields: one and two. The Water Logo is trademark by Clear Methods, Inc.

37 Classes & Methods: Classes (2)
We can create new instances of <myclass>. What is the only requirement of this myclass contract? <myclass "my first field" "my second field"/> <myclass <thing "0"/> 1/> <myclass <thing 0 1/> null /> The Water Logo is trademark by Clear Methods, Inc.

38 Classes & Methods: Classes (3)
We can further define the contract by supplying each field with a type. <myclass> now expects to receive a number for field one and a string for field two. <defclass myclass one=required=number two=required=string/> The Water Logo is trademark by Clear Methods, Inc.

39 Classes & Methods: Classes (5)
What are the values of one and two for each of the following statements? <myclass/> <myclass 3/> <myclass two="2"/> The Water Logo is trademark by Clear Methods, Inc.

40 Classes & Methods: Classes (6)
So far, we have created instances of classes but we have not saved them. You can store an instance into a variable: <set myvar=<myclass 4 "foo"/> /> The Water Logo is trademark by Clear Methods, Inc.

41 Classes & Methods: Methods
Method definitions are similar to class definitions. <defmethod foo> "bar" </> Method parameters use all of the same contracts as class parameters. <defmethod foo one=required=number two="2"> The Water Logo is trademark by Clear Methods, Inc.

42 Classes & Methods: Methods (2)
The value of the last statement executed in a method is the value returned by the method. Methods can specify their return type: <defmethod foo x=required=string _return_type=string> x.<concat "-bar"/> </> This method concatenates the string supplied for x with the string literal "-bar". The Water Logo is trademark by Clear Methods, Inc.

43 Classes & Methods: Methods (3)
Methods can be declared as members of a class. What is the purpose of _subject in this code? <defclass person first last> <defmethod hire> _subject.<set hired_on=date.<current/> </> The Water Logo is trademark by Clear Methods, Inc.

44 Classes & Methods: Methods (4)
It is also possible to assign methods outside of the class definition. If a method is defined outside of a class, we have the option of assigning it to a class. What class is the method accessible from if we do not explicitly assign it to a class? <defclass person first last/> person.<defmethod hire> _subject.<set hired_on=date.<current/> </> The Water Logo is trademark by Clear Methods, Inc.

45 Classes & Methods: Methods (5)
For example, from what classes could the following method be invoked from? <defmethod describe> _subject.<to_string/>.<concat _subject.<keys/>.<to_string/> /> </> What does this method do? The Water Logo is trademark by Clear Methods, Inc.

46 Classes & Methods: Invoking [1]
In Water, a call is either a method call or a constructor call. The syntax is the same. In the following example, the first line creates a method named foo_method. The second line calls the method with the argument x="test". The method call executes the method implementation and returns the result. <defmethod foo_method x> x </> <foo_method x="test"/> What is the result of the above execution? The Water Logo is trademark by Clear Methods, Inc.

47 Classes & Methods: Invoking (2)
You can also invoke a method on a subject: <defmethod tag_it value> _subject.<set tag=value/> </> thing.<tag_it "You're it!"/> thing.tag The Water Logo is trademark by Clear Methods, Inc.

48 Classes & Methods: Invoking (3)
Or, you can declare a method as a member of a specific class (instead of thing) and invoke it on the owning class and its subclasses: <defclass game> <defmethod tag_it value> _subject.<set tag=value/> </> <set a_game=<game/> /> a_game.<tag_it "Freeze!"/> a_game.tag The Water Logo is trademark by Clear Methods, Inc.

49 Classes & Methods: Creating
Now consider the following example of creating an object instance: <defclass foo_object x/> <foo_object x="test"/> Notice the identical structure between this instance creation and invoking a method without a target. In this example: The first line creates a class object named foo_object. The second line calls the default initialization constructor (the init method) for foo_object with an argument x="test". The constructor call executes the init method, which returns the new instance. The Water Logo is trademark by Clear Methods, Inc.

50 Classes & Methods: Creating (2)
The init method is Water’s version of a constructor. We can override the init method to perform tasks during object creation. What does _new_object contain? The student class maintains a field called peers. student.peers is a <thing/> that is initially empty, it has no fields. When a new student is created, it is added to the peers object as a new field. The key of the field is the value of student.id. The value is the student object itself. Browse to to see the results <defclass student id name> student.<set peers=<thing/> /> <defmethod init> student.peers.<set_field _new_object.id _new_object/> _new_object </> <student 100 "Bob"/> <student 200 "Mary"/> <student 300 "Jack"/> <server root=student/> The Water Logo is trademark by Clear Methods, Inc.

51 Classes & Methods: Creating (3)
We have created new instances using local Water expressions, but remember that we can also create new objects based on URLs. For example, is identical to <student 400 "Tom"/> The Water Logo is trademark by Clear Methods, Inc.

52 Overall score: Java 58, Water 33, Smalltalk 28
Is Water Easy to Learn? Overall score: Java 58, Water 33, Smalltalk 28

53 Is Water Perceived to Be Useful?
Overall score: Java 58, Water 40, Smalltalk 25

54 Summary Web services are rapidly growing in importance.
Water is a good way to learn Web services. It is concise. Small Web services can be written in a few lines of code. One can concentrate on the concepts, not the implementation.


Download ppt "Teaching Web Services and XML with the Water Language"

Similar presentations


Ads by Google