cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r157056 - in cocoon/branches/BRANCH_2_1_X/src/blocks/tour: java/org/apache/cocoon/samples/tour/shapes/ samples/flow/java-shapes/
Date Fri, 11 Mar 2005 08:31:33 GMT
Author: bdelacretaz
Date: Fri Mar 11 00:31:30 2005
New Revision: 157056

URL: http://svn.apache.org/viewcvs?view=rev&rev=157056
Log:
shapes sample uses bean-like properties, and use if/else in flowscript instead of switch

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Circle.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Rectangular.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Shape.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Square.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/tour/samples/flow/java-shapes/java-shapes.js

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Circle.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Circle.java?view=diff&r1=157055&r2=157056
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Circle.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Circle.java
Fri Mar 11 00:31:30 2005
@@ -31,11 +31,11 @@
         _r = r;
     }
     
-    public double area() {
+    public double getArea() {
         return 3.14 * _r * _r;
     }
     
-    public double perimeter() {
+    public double getPerimeter() {
         return 2 * 3.14 * _r;
     }
     

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Rectangular.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Rectangular.java?view=diff&r1=157055&r2=157056
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Rectangular.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Rectangular.java
Fri Mar 11 00:31:30 2005
@@ -32,11 +32,11 @@
         return "Rectangular";
     }
 
-    public double area(){
+    public double getArea(){
     	return _h * _b;
     }
     
-    public double perimeter(){
+    public double getPerimeter(){
         return (_h + _b) * 2;
     }
 	    

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Shape.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Shape.java?view=diff&r1=157055&r2=157056
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Shape.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Shape.java
Fri Mar 11 00:31:30 2005
@@ -21,6 +21,6 @@
  */
 public interface Shape {
     String getName();
-    abstract double area();
-    abstract double perimeter();
+    abstract double getArea();
+    abstract double getPerimeter();
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Square.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Square.java?view=diff&r1=157055&r2=157056
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Square.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/tour/java/org/apache/cocoon/samples/tour/shapes/Square.java
Fri Mar 11 00:31:30 2005
@@ -30,11 +30,11 @@
         return "Square";
     }
 
-    public double area() {
+    public double getArea() {
         return _b*_b;
     }
     
-    public double perimeter() {
+    public double getPerimeter() {
         return 4*_b;
     }
     

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/tour/samples/flow/java-shapes/java-shapes.js
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/tour/samples/flow/java-shapes/java-shapes.js?view=diff&r1=157055&r2=157056
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/tour/samples/flow/java-shapes/java-shapes.js (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/tour/samples/flow/java-shapes/java-shapes.js Fri
Mar 11 00:31:30 2005
@@ -16,7 +16,7 @@
 
 // Shape's area and perimeter calculation example.
 
-var calculator = Packages.org.apache.cocoon.samples.supersonic.shapes.Shape;
+var calculator = null;
 
 function public_startShape() {
     var hint = "Calculate shape's area and perimeter using logic in java. ";
@@ -28,26 +28,26 @@
     // send shape-specific view
     cocoon.sendPageAndWait("java-shapes/views/" + shapeId, {"shapeId" : shapeId});
 
+    // get request parameters (of which some are null depending on shape, that's not a problem)
+    var h = parseInt( cocoon.request.get("h") );
+    var b = parseInt( cocoon.request.get("b") );
+    var r = parseInt( cocoon.request.get("r") );
+
     // instantiate appropriate calculator
-    switch (shapeId){
-        case "square":
-            var b      = parseInt( cocoon.request.get("b") );
-            calculator = new Packages.org.apache.cocoon.samples.tour.shapes.Square(b);
-            break;
-        case "rectangular":
-            var h      = parseInt( cocoon.request.get("h") );
-            var b      = parseInt( cocoon.request.get("b") );
-            calculator = new Packages.org.apache.cocoon.samples.tour.shapes.Rectangular(b,h);
-            break;
-        case "circle":
-            var r      = parseInt( cocoon.request.get("r") );
-            calculator = new Packages.org.apache.cocoon.samples.tour.shapes.Circle(r);
-            break;
+    if(shapeId == "square") {
+        calculator = new Packages.org.apache.cocoon.samples.tour.shapes.Square(b);
+    } else if(shapeId=="rectangular") {
+        calculator = new Packages.org.apache.cocoon.samples.tour.shapes.Rectangular(b,h);
+    } else if(shapeId=="circle") {
+        calculator = new Packages.org.apache.cocoon.samples.tour.shapes.Circle(r);
+    } else {
+        throw new java.lang.Exception("No calculator found for shape '" + shapeId + "'");
     }
 
     // compute results
-    var a = calculator.area();
-    var p = calculator.perimeter();
+    // (accessing bean-like properties like "getArea()" using property names like "area")
+    var a = calculator.area;
+    var p = calculator.perimeter;
 
     cocoon.sendPage("java-shapes/views/results", {"area" : a, "perimeter" : p, "shape" :
shapeId} );
-}
\ No newline at end of file
+}



Mime
View raw message