Axa Assurance Maroc - Insurer Innovation Award 2024
XML-Free Programming : Java Server and Client Development without <>
1. XML-Free Programming : Java Server
and Client Development Without <>
Stephen Chin Arun Gupta
Chief Agile Methodologist, GXS Oracle Corporation
steveonjava@gmail.com arun.p.gupta@oracle.com
tweet: @steveonjava tweet: @arungupta
2. Meet the Presenters
Stephen Chin Arun Gupta
Community Guy
Family Man
Motorcyclist
Marathoner
3. Our Plan
> Quick (Humorous) History of Angle Brackets
> XML-Free Programming
1. Configuration Lives with the Code
2. Data Transfer Models the Domain
3. Design Programming Languages for Humans
> JavaOne Speakers Application <Demo>
3
4. Exhibit A – Angle Bracket Sighting in Virginia, 1922
Source: Library of Congress, Prints and Photographs Collection – Public Domain
http://www.flickr.com/photos/pingnews/434444310/
4
5. Exhibit B - Bermuda Tri-Angle Brackets
Source: NOAA National Ocean Service – CC licensed
http://www.flickr.com/photos/usoceangov/4276194691/sizes/o/in/photostream/
5
6. Exhibit C – Tim Bray, Co-Founder of XML
Source: Linux.com
http://www.linux.com/archive/feature/133149
6
7. History of XML
> Based on Standard Generalized Markup Language (SGML)
> Created by a W3C working group of eleven members
> Version History:
XML 1.0 (1998) – Widely adopted with 5 subsequent revisions
XML 1.1 (2004) – Limited adoption
7
8. XML Design Goals (a.k.a. problems with SGML)
1. Usable Over the Internet
2. Support a Wide Variety of Applications
3. Compatible with SGML
4. Easy to Write Programs to Process XML Documents
5. Minimum Number of Optional Features
6. Documents Should be Human-Legible and Reasonably Clear
7. Design Should be Prepared Quickly
8. Design Should be Formal and Concise
9. Documents Should be Easy to Create
10. Terseness in Markup is of Minimal Importance
8
9. Design Goals Per Application
Publishing Configuration Data Transfer Programming
Usable Over Internet Important N/A Important N/A
Wide Variety of Applications Acceptable Negative N/A N/A
Compatible With SGML Important Negative Negative Negative
Computer Processable Important Important Important Important
No Optional Features Important Important Important Important
Human-Legible Important Important Acceptable Important
Design Completed Quickly Important N/A N/A N/A
Formal and Concise Spec Important Important Important N/A
Easy to Create Documents Important Important N/A Important
Markup Can be Verbose Negative Negative Negative Negative
9
11. Letting Go of XML is Hard!
This is not intended as a replacement for Spring's XML format.
Rod Johnson on Spring’s Annotations-based Configuration
“A Java configuration option for Spring,” 11/28/06
11
13. But There is Hope!
You can have a Groovy DSL … it is as short as can be.
Dierk Koenig on Canoo Web Test
“Interview with Dierk Koenig,” ThirstyHead.com 6/3/2009
13
16. JavaScript Object Notation (JSON)
> Matches Relational/Object-Oriented Structures
> Easy to Read and Write
> Simple to Parse and Generate
> Familiar to Programmers of the C-family of languages:
C, C++, C#, Java, JavaScript, Perl, Python, etc.
> Very Simple Specification
16
17. JSON Syntax in a Slide
Images courtesy: http://www.json.org/
17
20. Counter Example – o:XML
> Created By Martin Klang in 2002
> Object Oriented Language
> Features:
Poymorphism
Function Overloading
Exception Handling Diagram from: http://www.o-xml.org/documentation/o-xml-tool-chain.html
Threads
20
21. String Replacement in o:XML vs. Java
<?xml-stylesheethref="../xsl/default.xsl" type="text/xsl"?> class Replace {
<program> public String replace(String input, String from, String to) {
<o:function name="ex:replace"> StringBuilder result = new StringBuilder();
<o:param name="input" type="String"/> int last = 0;
<o:param name="from" type="String"/> int index = 0;
<o:param name="to" type="String"/> while ((index = input.indexOf(from, last)) != -1) {
<o:do> result.append(input.substring(last, index));
16 Lines
<o:variable name="result"/> 14 Lines
result.append(to);
<o:while test="contains($input, $from)"> last = index + from.length()
461 Characters
<o:set result="concat($result, substring-before($input,
$from), $to)"/>
} 319 Characters
result.append(input.substring(last));
<o:set input="substring-after($input, $from)"/> return result.toString();
</o:while> }
<o:return select="concat($result, $input)"/> }
</o:do>
</o:function>
</program>
21
23. Equivalent Java
class Replace {
public String replace(String input, String from, String to) {
StringBuilder result = new StringBuilder();
int last = 0;
int index = 0;
while ((index = input.indexOf(from, last)) != -1) {
result.append(input.substring(last, index));
result.append(to);
last = index + from.length()
}
result.append(input.substring(last));
return result.toString();
}
}
23
25. JavaFX 2.0
> Powerful graphics, animation, and media capabilities
> Deploys in the browser or on desktop
> Includes builders for declarative construction
> Alternative languages can also be used for simpler UI creation
GroovyFX
ScalaFX
Visage
25
26. Hello JavaOne (Java Version)
public class HelloJavaOne extends Application {
public static void main(String[] args) {
launch(HelloJavaOne.class, args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello JavaOne");
Group root = new Group();
Scene scene = new Scene(root, 400, 250, Color.ALICEBLUE);
Text text = new Text();
text.setX(105);
text.setY(120);
text.setFont(new Font(30));
text.setText("Hello JavaOne");
root.getChildren().add(text);
primaryStage.setScene(scene);
primaryStage.show();
}
}
26
29. Hello JavaOne (ScalaFX Version)
object HelloJavaOne extends JFXApp {
stage = new Stage {
title = "Hello JavaFX"
width = 400
height = 250
scene = new Scene {
fill = BLUE
Text {
x = 105
y = 120
text = "Hello JavaOne"
font = Font(size: 30)
}
}
}
}
29
30. Hello JavaOne (Visage Version)
Stage {
title: "Hello JavaOne"
width: 400
height: 250
scene: Scene {
fill: BLUE
content: Text {
x: 105
y: 120
text: "Hello JavaOne"
font: Font {size: 30pt}
}
}
}
30
31. JavaOne Speakers Application
> End-to-end application with no XML coding
> Server written using JavaEE 6 annotations
> Data transfer uses JSON
> Client written in JavaFX 2.0
31
33. Support the Freedom From XML Petition </>
http://steveonjava.com/freedom-from-xml/
Provide Non-XML Alternatives For:
> Declarative Programming
> Configuration
> Data Transfer
Sign the Petition Today!
33