Your SlideShare is downloading. ×
0
XML-Free Programming : Java Serverand Client Development Without <>Stephen Chin                     Arun GuptaChief Agile ...
Meet the Presenters           Stephen Chin                              Arun Gupta                                     Com...
Our Plan>   Quick (Humorous) History of Angle Brackets>   XML-Free Programming    1.   Configuration Lives with the Code  ...
Exhibit A – Angle Bracket Sighting in Virginia, 1922Source: Library of Congress, Prints and Photographs Collection – Publi...
Exhibit B - Bermuda Tri-Angle BracketsSource: NOAA National Ocean Service – CC licensedhttp://www.flickr.com/photos/usocea...
Exhibit C – Tim Bray, Co-Founder of XMLSource: Linux.comhttp://www.linux.com/archive/feature/133149                       ...
History of XML>   Based on Standard Generalized Markup Language (SGML)>   Created by a W3C working group of eleven members...
XML Design Goals (a.k.a. problems with SGML)1.    Usable Over the Internet2.    Support a Wide Variety of Applications3.  ...
Design Goals Per Application                               Publishing   Configuration   Data Transfer   ProgrammingUsable ...
Tenet 1Configuration Lives with theCode                               10
Letting Go of XML is Hard!     This is not intended as a replacement for Springs XML format.                              ...
Java EE 6 Annotations>   @Stateless>   @Path>   @WebServlet>   @Inject>   @Named>   @Entity                        12
But There is Hope!     You can have a Groovy DSL … it is as short as can be.                                       Dierk K...
Canoo Web Test Comparison                    XML                                        Groovy Builder<project default="te...
Tenet 2Data Transfer Models theDomain                           15
JavaScript Object Notation (JSON)>   Matches Relational/Object-Oriented Structures>   Easy to Read and Write>   Simple to ...
JSON Syntax in a Slide                         Images courtesy: http://www.json.org/                                      ...
JAX-RS Sample@Stateless                                             @GET@Path("sezzion")                                  ...
Tenet 3Design ProgrammingLanguages for Humans                       19
Counter Example – o:XML>   Created By Martin Klang in 2002>   Object Oriented Language>   Features:       Poymorphism    ...
String Replacement in o:XML vs. Java<?xml-stylesheethref="../xsl/default.xsl" type="text/xsl"?>       class Replace {<prog...
String Replacement in o:XML<?xml-stylesheethref="../xsl/default.xsl" type="text/xsl"?><program>  <o:function name="ex:repl...
Equivalent Javaclass Replace {  public String replace(String input, String from, String to) {    StringBuilder result = ne...
Simple Javaclass Replace {  public String replace(String input, String from, String to) {    return input.replaceAll(from,...
JavaFX 2.0>   Powerful graphics, animation, and media capabilities>   Deploys in the browser or on desktop>   Includes bui...
Hello JavaOne (Java Version)public class HelloJavaOne extends Application {  public static void main(String[] args) {    l...
Hello JavaOne (Builder Version)public void start(Stage primaryStage) {  primaryStage.setTitle("Hello JavaOne");  primarySt...
Hello JavaOne (GroovyFX Version)GroovyFX.start { primaryStage ->  def sg = new SceneGraphBuilder()  sg.stage(    title: He...
Hello JavaOne (ScalaFX Version)object HelloJavaOne extends JFXApp {  stage = new Stage {    title = "Hello JavaFX"    widt...
Hello JavaOne (Visage Version)Stage {  title: "Hello JavaOne"  width: 400  height: 250  scene: Scene {    fill: BLUE    co...
JavaOne Speakers Application>   End-to-end application with no XML coding>   Server written using JavaEE 6 annotations>   ...
Finished Application                       32
Support the Freedom From XML Petition      </>http://steveonjava.com/freedom-from-xml/Provide Non-XML Alternatives For:> D...
Stephen Chin            Arun Guptasteveonjava@gmail.com   arun.p.gupta@oracle.comtweet: @steveonjava     tweet: @arungupta...
Upcoming SlideShare
Loading in...5
×

XML-Free Programming : Java Server and Client Development without &lt;>

1,229

Published on

XML-Free Programming : Java Server and Client Development without <> at JavaOne 2011

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,229
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "XML-Free Programming : Java Server and Client Development without &lt;>"

  1. 1. XML-Free Programming : Java Serverand Client Development Without <>Stephen Chin Arun GuptaChief Agile Methodologist, GXS Oracle Corporationsteveonjava@gmail.com arun.p.gupta@oracle.comtweet: @steveonjava tweet: @arungupta
  2. 2. Meet the Presenters Stephen Chin Arun Gupta Community Guy Family Man Motorcyclist Marathoner
  3. 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. 4. Exhibit A – Angle Bracket Sighting in Virginia, 1922Source: Library of Congress, Prints and Photographs Collection – Public Domainhttp://www.flickr.com/photos/pingnews/434444310/ 4
  5. 5. Exhibit B - Bermuda Tri-Angle BracketsSource: NOAA National Ocean Service – CC licensedhttp://www.flickr.com/photos/usoceangov/4276194691/sizes/o/in/photostream/ 5
  6. 6. Exhibit C – Tim Bray, Co-Founder of XMLSource: Linux.comhttp://www.linux.com/archive/feature/133149 6
  7. 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. 8. XML Design Goals (a.k.a. problems with SGML)1. Usable Over the Internet2. Support a Wide Variety of Applications3. Compatible with SGML4. Easy to Write Programs to Process XML Documents5. Minimum Number of Optional Features6. Documents Should be Human-Legible and Reasonably Clear7. Design Should be Prepared Quickly8. Design Should be Formal and Concise9. Documents Should be Easy to Create10. Terseness in Markup is of Minimal Importance 8
  9. 9. Design Goals Per Application Publishing Configuration Data Transfer ProgrammingUsable Over Internet Important N/A Important N/AWide Variety of Applications Acceptable Negative N/A N/ACompatible With SGML Important Negative Negative NegativeComputer Processable Important Important Important ImportantNo Optional Features Important Important Important ImportantHuman-Legible Important Important Acceptable ImportantDesign Completed Quickly Important N/A N/A N/AFormal and Concise Spec Important Important Important N/AEasy to Create Documents Important Important N/A ImportantMarkup Can be Verbose Negative Negative Negative Negative 9
  10. 10. Tenet 1Configuration Lives with theCode 10
  11. 11. Letting Go of XML is Hard! This is not intended as a replacement for Springs XML format. Rod Johnson on Spring’s Annotations-based Configuration “A Java configuration option for Spring,” 11/28/06 11
  12. 12. Java EE 6 Annotations> @Stateless> @Path> @WebServlet> @Inject> @Named> @Entity 12
  13. 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
  14. 14. Canoo Web Test Comparison XML Groovy Builder<project default="test"> class SimpleTest extends WebtestCase { <target name="test"> void testWebtestOnGoogle() { <webtest webtest("Google WebTest Search") { name="Google WebTest Search"> invoke "http://www.google.com/ncr" <invoke url="http://www.google.com/ncr" /> verifyTitle "Google" <verifyTitle text="Google" /> setInputField name: "q", value: "WebTest" <setInputField name="q" value="WebTest" /> clickButton "Im Feeling Lucky" <clickButton label="Im Feeling Lucky" /> verifyTitle "Canoo WebTest" <verifyTitle text="Canoo WebTest" /> } </webtest> } </target> }</project> 14
  15. 15. Tenet 2Data Transfer Models theDomain 15
  16. 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. 17. JSON Syntax in a Slide Images courtesy: http://www.json.org/ 17
  18. 18. JAX-RS Sample@Stateless @GET@Path("sezzion") @Produces({"application/json", "application/xml"})public class SezzionFacadeREST extends public List<Sezzion> findAll() {AbstractFacade<Sezzion> { return super.findAll(); @PersistenceContext } private EntityManager em; @GET@POST @Path("{from}/{to}")@Consumes({"application/json", "application/xml"}) @Produces({"application/xml", "application/json"}) public void create(Sezzion entity) { public List<Sezzion> findRange(@PathParam("from") Integer super.create(entity); from, @PathParam("to") Integer to) { } return super.findRange(new int[]{from, to}); } 18
  19. 19. Tenet 3Design ProgrammingLanguages for Humans 19
  20. 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. 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
  22. 22. String Replacement in o:XML<?xml-stylesheethref="../xsl/default.xsl" type="text/xsl"?><program> <o:function name="ex:replace"> <o:param name="input" type="String"/> <o:param name="from" type="String"/> <o:param name="to" type="String"/> <o:do> <o:variable name="result"/> <o:while test="contains($input, $from)"> <o:set result="concat($result, substring-before($input, $from), $to)"/> <o:set input="substring-after($input, $from)"/> </o:while> <o:return select="concat($result, $input)"/> </o:do> </o:function></program> 22
  23. 23. Equivalent Javaclass 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
  24. 24. Simple Javaclass Replace { public String replace(String input, String from, String to) { return input.replaceAll(from, to) }} 24
  25. 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. 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
  27. 27. Hello JavaOne (Builder Version)public void start(Stage primaryStage) { primaryStage.setTitle("Hello JavaOne"); primaryStage.setScene(SceneBuilder.create() .width(400) .height(250) .fill(Color.ALICEBLUE) .root( GroupBuilder.create().children( TextBuilder.create() .x(105) .y(120) .text("Hello JavaOne") .font(new Font(30)) .build() ).build() ) .build()); primaryStage.show();} 27
  28. 28. Hello JavaOne (GroovyFX Version)GroovyFX.start { primaryStage -> def sg = new SceneGraphBuilder() sg.stage( title: Hello JavaOne, show: true) { scene( fill: aliceblue, width: 400, height: 250) { text( x: 105, y: 120, text: "Hello JavaOne" font: "30pt") } }} 28
  29. 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. 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. 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
  32. 32. Finished Application 32
  33. 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
  34. 34. Stephen Chin Arun Guptasteveonjava@gmail.com arun.p.gupta@oracle.comtweet: @steveonjava tweet: @arungupta 34
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×