Author: lresende
Date: Sun Oct 28 01:08:04 2007
New Revision: 589291

URL: http://svn.apache.org/viewvc?rev=589291&view=rev
Log:
Multiple fixes to make the store scenario to work end to end using sca web 
widget

Added:
    
incubator/tuscany/java/sca/modules/implementation-widget/src/test/java/store/ShoppingCartImpl.java
   (with props)
Modified:
    
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetProxyHelper.java
    
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetReferenceServlet.java
    
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java
    
incubator/tuscany/java/sca/modules/implementation-widget/src/test/java/store/CatalogImpl.java
    
incubator/tuscany/java/sca/modules/implementation-widget/src/test/resources/content/store.html
    
incubator/tuscany/java/sca/modules/implementation-widget/src/test/resources/widget.composite

Modified: 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetProxyHelper.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetProxyHelper.java?rev=589291&r1=589290&r2=589291&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetProxyHelper.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetProxyHelper.java
 Sun Oct 28 01:08:04 2007
@@ -28,10 +28,10 @@
 
     static {
         
proxyFileRegistry.put("org.apache.tuscany.sca.binding.feed.impl.AtomBindingImpl",
 "binding-atom.js");
-        
proxyClient.put("org.apache.tuscany.sca.binding.feed.impl.AtomBindingImpl", 
"AtomBindingClient");
+        
proxyClient.put("org.apache.tuscany.sca.binding.feed.impl.AtomBindingImpl", 
"AtomClient");
         
-        
//proxyRegistry.put("org.apache.tuscany.sca.binding.feed.impl.AtomBindingImpl", 
"binding-jsonrpc.js");
-        
//proxyClient.put("org.apache.tuscany.sca.binding.feed.impl.AtomBindingImpl", 
"JSONRPCBindingClient");
+        
proxyFileRegistry.put("org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding", 
"binding-jsonrpc.js");
+        
proxyClient.put("org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding", 
"JSONRpcClient");
     }
     
     protected WidgetProxyHelper() {

Modified: 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetReferenceServlet.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetReferenceServlet.java?rev=589291&r1=589290&r2=589291&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetReferenceServlet.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetReferenceServlet.java
 Sun Oct 28 01:08:04 2007
@@ -102,19 +102,24 @@
     
     protected void writeJavaScriptReferenceFunction (ServletOutputStream os) 
throws IOException {
         
+        os.println("var referenceMap = new Object();");
         for(ComponentReference reference : component.getReferences()) {
             String referenceName = reference.getName();
             Binding binding = reference.getBindings().get(0);
             if( binding != null) {
                 String proxyClient = 
WidgetProxyHelper.getJavaScriptProxyClient(binding.getClass().getName());
                 if(proxyClient != null) {
-                    os.println("proxy[" + referenceName + "]= new " + 
proxyClient + "(\"" + binding.getURI() + "\");");
+                    if(proxyClient.equals("JSONRpcClient")) {
+                        os.println("referenceMap." + referenceName + " = new " 
+ proxyClient + "(\".." + binding.getURI() + "\")." + 
binding.getURI().substring(1) + ";");
+                    } else {
+                        os.println("referenceMap." + referenceName + " = new " 
+ proxyClient + "(\".." + binding.getURI() + "\");");
+                    }
                 }                
             }
         }
         
         os.println("function Reference(name) {");
-        os.println("    return proxy[name];");
+        os.println("    return referenceMap[name];");
         os.println("}");
     }
 

Modified: 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java?rev=589291&r1=589290&r2=589291&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationProvider.java
 Sun Oct 28 01:08:04 2007
@@ -59,7 +59,7 @@
 
         WidgetReferenceServlet widgetServlet = new 
WidgetReferenceServlet(component);
         
-        String uri = component.getURI() + ".js";
+        String uri = component.getURI() + "/" + component.getURI() + ".js";
         servletHost.addServletMapping(uri, widgetServlet);        
     }
 

Modified: 
incubator/tuscany/java/sca/modules/implementation-widget/src/test/java/store/CatalogImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-widget/src/test/java/store/CatalogImpl.java?rev=589291&r1=589290&r2=589291&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-widget/src/test/java/store/CatalogImpl.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/implementation-widget/src/test/java/store/CatalogImpl.java
 Sun Oct 28 01:08:04 2007
@@ -29,9 +29,9 @@
 
     @Init
     public void init() {
-        catalog.add("Apple - US$ 2.99f");
-        catalog.add("Orange - US$ 3.55f");
-        catalog.add("Pear - US$ 1.55f");
+        catalog.add("Apple - US$ 2.99");
+        catalog.add("Orange - US$ 3.55");
+        catalog.add("Pear - US$ 1.55");
     }
 
     public String[] get() {

Added: 
incubator/tuscany/java/sca/modules/implementation-widget/src/test/java/store/ShoppingCartImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-widget/src/test/java/store/ShoppingCartImpl.java?rev=589291&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-widget/src/test/java/store/ShoppingCartImpl.java
 (added)
+++ 
incubator/tuscany/java/sca/modules/implementation-widget/src/test/java/store/ShoppingCartImpl.java
 Sun Oct 28 01:08:04 2007
@@ -0,0 +1,106 @@
+/*
+ * 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 store;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.tuscany.sca.binding.feed.collection.Collection;
+import org.apache.tuscany.sca.binding.feed.collection.NotFoundException;
+
+import com.sun.syndication.feed.atom.Content;
+import com.sun.syndication.feed.atom.Entry;
+import com.sun.syndication.feed.atom.Feed;
+import com.sun.syndication.feed.atom.Link;
+
+public class ShoppingCartImpl implements Collection {
+
+    private static Map<String, Entry> cart = new HashMap<String, Entry>();
+
+    public Feed getFeed() {
+        Feed feed = new Feed();
+        feed.setTitle("shopping cart");
+        Content subtitle = new Content();
+        subtitle.setValue("Total : " + getTotal());
+        feed.setSubtitle(subtitle);
+        feed.getEntries().addAll(cart.values());
+        return feed;
+    }
+
+    public Entry get(String id) throws NotFoundException {
+        return cart.get(id);
+    }
+
+    public Entry post(Entry entry) {
+        System.out.println("post" + entry);
+        String id = "cart-" + UUID.randomUUID().toString();
+        entry.setId(id);
+
+        Link link = new Link();
+        link.setRel("edit");
+        link.setHref(id);
+        entry.getOtherLinks().add(link);
+        link = new Link();
+        link.setRel("alternate");
+        link.setHref(id);
+        entry.getAlternateLinks().add(link);
+
+        entry.setCreated(new Date());
+
+        cart.put(id, entry);
+        return entry;
+    }
+
+    public Entry put(String id, Entry entry) throws NotFoundException {
+        entry.setUpdated(new Date());
+        cart.put(id, entry);
+        return entry;
+    }
+
+    public void delete(String id) throws NotFoundException {
+        if (id.equals(""))
+            cart.clear();
+        else
+            cart.remove(id);
+    }
+
+    private String getTotal() {
+        float total = 0;
+        String currencySymbol = "";
+        if (!cart.isEmpty()) {
+            String item = 
((Content)cart.values().iterator().next().getContents().get(0)).getValue();
+            currencySymbol = item.substring(item.indexOf("-") + 2, 
item.indexOf("-") + 3);
+        }
+        for (Entry entry : cart.values()) {
+            String item = ((Content)entry.getContents().get(0)).getValue();
+            
+            int index = item.length()-1;
+            char digit;
+            while ((digit = item.charAt(index)) == '.' || 
Character.isDigit(digit)) {
+                index--;
+            }
+            
+            total += Float.valueOf(item.substring(index));
+        }
+        return currencySymbol + String.valueOf(total);
+    }
+}

Propchange: 
incubator/tuscany/java/sca/modules/implementation-widget/src/test/java/store/ShoppingCartImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/java/sca/modules/implementation-widget/src/test/java/store/ShoppingCartImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
incubator/tuscany/java/sca/modules/implementation-widget/src/test/resources/content/store.html
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-widget/src/test/resources/content/store.html?rev=589291&r1=589290&r2=589291&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-widget/src/test/resources/content/store.html
 (original)
+++ 
incubator/tuscany/java/sca/modules/implementation-widget/src/test/resources/content/store.html
 Sun Oct 28 01:08:04 2007
@@ -20,19 +20,16 @@
 <head>
 <title>Store</TITLE>
 
-<script type="text/javascript" src="binding-atom.js"></script>
-<script type="text/javascript" src="binding-jsonrpc.js"></script>
-
 <!-- one js include per sca component -->
-<script type="text/javascript" src="storeWidgetComponent.js"/>
+<script type="text/javascript" src="storeWidgetComponent.js"></script>
 
 <script language="JavaScript">
 
        //@Reference
-       var catalog = new Reference("catalog"); //(new 
JSONRpcClient("../Catalog")).Catalog;
+       var catalog = new Reference("Catalog");
+       
        //@Reference
-       var shoppingCart = new Reference("shoppingCart"); //new 
AtomClient("../ShoppingCart");
-
+       var shoppingCart = new Reference("ShoppingCart"); 
 
        function catalog_getResponse(items) {
                var catalog = "";

Modified: 
incubator/tuscany/java/sca/modules/implementation-widget/src/test/resources/widget.composite
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-widget/src/test/resources/widget.composite?rev=589291&r1=589290&r2=589291&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-widget/src/test/resources/widget.composite
 (original)
+++ 
incubator/tuscany/java/sca/modules/implementation-widget/src/test/resources/widget.composite
 Sun Oct 28 01:08:04 2007
@@ -28,10 +28,10 @@
         <service name="Widget">
                <tuscany:binding.http/> 
         </service>
-               <!-- reference name="catalog" target="Catalog">
+               <reference name="Catalog" target="Catalog">
                        <tuscany:binding.jsonrpc/>
-                </reference-->
-                <reference name="shoppingCart" target="ShoppingCart">
+                </reference>
+                <reference name="ShoppingCart" target="ShoppingCart">
                        <tuscany:binding.atom uri="/ShoppingCart"/>
                 </reference>
     </component>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to