You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by me...@apache.org on 2007/03/21 00:32:09 UTC

svn commit: r520657 - in /incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org: ./ apache/ apache/tuscany/ apache/tuscany/demo/ apache/tuscany/demo/app/

Author: meerajk
Date: Tue Mar 20 16:32:08 2007
New Revision: 520657

URL: http://svn.apache.org/viewvc?view=rev&rev=520657
Log:
Added the demo app.

Added:
    incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/
    incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/
    incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/tuscany/
    incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/tuscany/demo/
    incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/tuscany/demo/app/
    incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorForm.java   (with props)
    incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorHandler.java   (with props)

Added: incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorForm.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorForm.java?view=auto&rev=520657
==============================================================================
--- incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorForm.java (added)
+++ incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorForm.java Tue Mar 20 16:32:08 2007
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.demo.app;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tuscany.spi.host.ServletHost;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * @version $Revision$ $Date$
+ */
+@SuppressWarnings("serial")
+public class CalculatorForm extends HttpServlet {
+
+    /**
+     * Injects the servlet host and path mapping.
+     * 
+     * @param servletHost Servlet host to use.
+     * @param path Path mapping for the servlet.
+     */
+    public CalculatorForm(@Reference(name = "servletHost") ServletHost servletHost) {
+        servletHost.registerMapping("calculatorForm", this);
+    }
+    
+    /**
+     * Processes the request.
+     * 
+     * @param req Servlet request.
+     * @param res Servlet response.
+     * @throws ServletException Servlet exception.
+     * @throws IOException IO Exception.
+     */
+    protected void process(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+        
+        PrintWriter writer = res.getWriter();
+        writer.println("<form name='' method='post' action='calculate'>");
+        writer.println("<input name='op1' type='text' size='10'>");
+        writer.println("<br/>");
+        writer.println("<input name='op2' type='text' size='10'>");
+        writer.println("<br/>");
+        writer.println("<input type='submit' value='Add'/>");
+        writer.println("</form>");
+        writer.flush();
+        writer.close();
+        
+    }
+    
+    /**
+     * Handles get requests.
+     */
+    @Override
+    protected final void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+        process(req, res);
+    }
+
+    /**
+     * Handles post request.
+     */
+    @Override
+    protected final void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+        process(req, res);
+    }
+
+}

Propchange: incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorForm.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorForm.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorHandler.java?view=auto&rev=520657
==============================================================================
--- incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorHandler.java (added)
+++ incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorHandler.java Tue Mar 20 16:32:08 2007
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.demo.app;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tuscany.spi.host.ServletHost;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+import calculator.CalculatorService;
+
+/**
+ * @version $Revision$ $Date$
+ */
+@SuppressWarnings("serial")
+public class CalculatorHandler extends HttpServlet {
+    
+    // Calculator service
+    private CalculatorService calculatorService;
+
+    /**
+     * Injects the servlet host and path mapping.
+     * 
+     * @param servletHost Servlet host to use.
+     * @param path Path mapping for the servlet.
+     */
+    public CalculatorHandler(@Reference(name = "servletHost") ServletHost servletHost,
+                             @Reference(name = "servletHost") CalculatorService calculatorService) {
+        servletHost.registerMapping("calculate", this);
+        this.calculatorService = calculatorService;
+    }
+    
+    /**
+     * Processes the request.
+     * 
+     * @param req Servlet request.
+     * @param res Servlet response.
+     * @throws ServletException Servlet exception.
+     * @throws IOException IO Exception.
+     */
+    protected void process(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+        
+        double op1 = Double.parseDouble(req.getParameter("op1"));
+        double op2 = Double.parseDouble(req.getParameter("op2"));
+        double result = calculatorService.add(op1, op2);
+        
+        PrintWriter writer = res.getWriter();
+        writer.println("Result: " + result);
+        writer.flush();
+        writer.close();
+    }
+    
+    /**
+     * Handles get requests.
+     */
+    @Override
+    protected final void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+        process(req, res);
+    }
+
+    /**
+     * Handles post request.
+     */
+    @Override
+    protected final void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+        process(req, res);
+    }
+
+}

Propchange: incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/distribution/sca/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org