diff options
Diffstat (limited to 'java/sca')
17 files changed, 194 insertions, 171 deletions
diff --git a/java/sca/samples/photo-gallery/src/main/java/launch/Launch.java b/java/sca/samples/photo-gallery/src/main/java/launch/Launch.java index 858fdb6bf2..e1a96f9309 100644 --- a/java/sca/samples/photo-gallery/src/main/java/launch/Launch.java +++ b/java/sca/samples/photo-gallery/src/main/java/launch/Launch.java @@ -25,7 +25,7 @@ public class Launch { public static void main(String[] args) throws Exception { System.out.println("Starting ..."); SCADomain scaDomain = SCADomain.newInstance("photo-gallery.composite"); - System.out.println("store.composite ready for big business !!!"); + System.out.println("photo.gallery.composite ready for big business !!!"); System.in.read(); System.out.println("Stopping ..."); scaDomain.close(); diff --git a/java/sca/samples/photo-gallery/src/main/java/services/Album.java b/java/sca/samples/photo-gallery/src/main/java/services/Album.java new file mode 100644 index 0000000000..5257d0e703 --- /dev/null +++ b/java/sca/samples/photo-gallery/src/main/java/services/Album.java @@ -0,0 +1,29 @@ +/* + * 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 services; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface Album { + + public String[] getPictures(); + +} diff --git a/java/sca/samples/photo-gallery/src/main/java/services/AlbumImpl.java b/java/sca/samples/photo-gallery/src/main/java/services/AlbumImpl.java new file mode 100644 index 0000000000..dd2b086e29 --- /dev/null +++ b/java/sca/samples/photo-gallery/src/main/java/services/AlbumImpl.java @@ -0,0 +1,95 @@ +/* + * 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 services; + +import java.io.File; +import java.io.FilenameFilter; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Property; + +public class AlbumImpl implements Album { + private String gallery; + private String album; + private String location; + private List<String> pictures = new ArrayList<String>(); + + @Property + public void setGallery(String gallery) { + this.gallery = gallery; + this.location = null; + } + @Property + public void setAlbum(String album) { + this.album = album; + this.location = null; + } + + protected String getLocation() { + if (location == null) { + location = gallery + "/" + album + "/"; + } + return location; + + } + + @Init + public void init() { + try { + URL albumURL = this.getClass().getClassLoader().getResource(getLocation()); + if(albumURL != null) { + File album = new File(albumURL.toURI()); + if (album.isDirectory() && album.exists()) { + String[] listPictures = album.list(new ImageFilter(".jpg")); + for(String image : listPictures) { + image = getLocation() + image; + pictures.add(image); + } + } + } + } catch (Exception e) { + // FIXME: ignore for now + e.printStackTrace(); + } + } + + public String[] getPictures() { + String[] pictureArray = new String[pictures.size()]; + pictures.toArray(pictureArray); + return pictureArray; + } + + /** + * Inner fileFilter class + */ + private class ImageFilter implements FilenameFilter { + String afn; + ImageFilter(String afn) { this.afn = afn; } + public boolean accept(File dir, String name) { + // Strip path information: + String f = new File(name).getName(); + return f.indexOf(afn) != -1; + } + } ///:~ + +} diff --git a/java/sca/samples/photo-gallery/src/main/resources/gallery.html b/java/sca/samples/photo-gallery/src/main/resources/gallery.html new file mode 100644 index 0000000000..2a7b32f6ed --- /dev/null +++ b/java/sca/samples/photo-gallery/src/main/resources/gallery.html @@ -0,0 +1,57 @@ +<!-- + * 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. +--> +<html> +<head> +<title>Photo Gallery</title> + +<script type="text/javascript" src="gallery.js"></script> + +<script language="JavaScript"> + + //@Reference + var album = new Reference("album"); + + var albumItems; + + function album_getResponse(items) { + var albumPictures = ""; + for (var i=0; i<items.length; i++) { + albumPictures += '<img src="' + items[i] + '"> <br>'; + } + document.getElementById('album').innerHTML=albumPictures; + albumItems = items; + } + + + function init() { + album.getPictures(album_getResponse); + } + +</script> + +</head> + +<body onload="init()"> +<h1>Photo Gallery</h1> + <div id="gallery"> + <div id="album" ></div> + <br> + </div> +</body> +</html> diff --git a/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00368.jpg b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00368.jpg Binary files differnew file mode 100644 index 0000000000..9437b321e2 --- /dev/null +++ b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00368.jpg diff --git a/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00369.jpg b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00369.jpg Binary files differnew file mode 100644 index 0000000000..07f37ec505 --- /dev/null +++ b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00369.jpg diff --git a/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00370.jpg b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00370.jpg Binary files differnew file mode 100644 index 0000000000..2193784271 --- /dev/null +++ b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00370.jpg diff --git a/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00371.jpg b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00371.jpg Binary files differnew file mode 100644 index 0000000000..1532ee2c1b --- /dev/null +++ b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00371.jpg diff --git a/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00373.jpg b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00373.jpg Binary files differnew file mode 100644 index 0000000000..17ffd73aec --- /dev/null +++ b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00373.jpg diff --git a/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00375.jpg b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00375.jpg Binary files differnew file mode 100644 index 0000000000..19e9ec37df --- /dev/null +++ b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00375.jpg diff --git a/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00376.jpg b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00376.jpg Binary files differnew file mode 100644 index 0000000000..022416dbce --- /dev/null +++ b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00376.jpg diff --git a/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00377.jpg b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00377.jpg Binary files differnew file mode 100644 index 0000000000..c78a974714 --- /dev/null +++ b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00377.jpg diff --git a/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00378.jpg b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00378.jpg Binary files differnew file mode 100644 index 0000000000..a98070925a --- /dev/null +++ b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00378.jpg diff --git a/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00379.jpg b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00379.jpg Binary files differnew file mode 100644 index 0000000000..dc83889116 --- /dev/null +++ b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00379.jpg diff --git a/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00380.jpg b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00380.jpg Binary files differnew file mode 100644 index 0000000000..0e33548135 --- /dev/null +++ b/java/sca/samples/photo-gallery/src/main/resources/gallery/boston/dsc00380.jpg diff --git a/java/sca/samples/photo-gallery/src/main/resources/photo-gallery.composite b/java/sca/samples/photo-gallery/src/main/resources/photo-gallery.composite index 4f4a9d2e3d..0bb3c4b4db 100644 --- a/java/sca/samples/photo-gallery/src/main/resources/photo-gallery.composite +++ b/java/sca/samples/photo-gallery/src/main/resources/photo-gallery.composite @@ -22,43 +22,26 @@ targetNamespace="http://photo-gallery" name="photo-gallery"> - <component name="Store"> - <t:implementation.widget location="uiservices/store.html"/> + <component name="Gallery"> + <t:implementation.widget location="gallery.html"/> <service name="Widget"> - <t:binding.http uri="/store"/> + <t:binding.http uri="/gallery"/> </service> - <reference name="catalog" target="Catalog"> - <t:binding.jsonrpc/> - </reference> - <reference name="shoppingCart" target="ShoppingCart/Cart"> - <t:binding.atom/> - </reference> - <reference name="shoppingTotal" target="ShoppingCart/Total"> + <reference name="album" target="Album"> <t:binding.jsonrpc/> </reference> </component> - <component name="Catalog"> - <implementation.java class="services.FruitsCatalogImpl"/> - <property name="currencyCode">USD</property> - <service name="Catalog"> + <component name="Album"> + <implementation.java class="services.AlbumImpl"/> + <property name="gallery">gallery</property> + <property name="album">boston</property> + <service name="Album"> <t:binding.jsonrpc/> </service> - <reference name="currencyConverter" target="CurrencyConverter"/> </component> - - <component name="ShoppingCart"> - <implementation.java class="services.ShoppingCartImpl"/> - <service name="Cart"> - <t:binding.atom uri="/ShoppingCart/Cart"/> - </service> - <service name="Total"> - <t:binding.jsonrpc/> - </service> + + <component name="GalleryPictures"> + <t:implementation.resource location="gallery"></t:implementation.resource> </component> - - <component name="CurrencyConverter"> - <implementation.java class="services.CurrencyConverterImpl"/> - </component> - </composite> diff --git a/java/sca/samples/photo-gallery/src/main/resources/uiservices/gallery.html b/java/sca/samples/photo-gallery/src/main/resources/uiservices/gallery.html deleted file mode 100644 index 095570f949..0000000000 --- a/java/sca/samples/photo-gallery/src/main/resources/uiservices/gallery.html +++ /dev/null @@ -1,141 +0,0 @@ -<!-- - * 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. ---> -<html> -<head> -<title>Store</title> - -<script type="text/javascript" src="store.js"></script> - -<script language="JavaScript"> - - //@Reference - var catalog = new Reference("catalog"); - - //@Reference - var shoppingCart = new Reference("shoppingCart"); - - //@Reference - var shoppingTotal = new Reference("shoppingTotal"); - - var catalogItems; - - function catalog_getResponse(items) { - var catalog = ""; - for (var i=0; i<items.length; i++) { - var item = items[i].name + ' - ' + items[i].price; - catalog += '<input name="items" type="checkbox" value="' + - item + '">' + item + ' <br>'; - } - document.getElementById('catalog').innerHTML=catalog; - catalogItems = items; - } - - function shoppingCart_getResponse(feed) { - if (feed != null) { - var entries = feed.getElementsByTagName("entry"); - var list = ""; - for (var i=0; i<entries.length; i++) { - var content = entries[i].getElementsByTagName("content")[0]; - var name = content.getElementsByTagName("name")[0].firstChild.nodeValue; - var price = content.getElementsByTagName("price")[0].firstChild.nodeValue; - list += name + ' - ' + price + ' <br>'; - } - document.getElementById("shoppingCart").innerHTML = list; - - if (entries.length != 0) { - shoppingTotal.getTotal(shoppingTotal_getTotalResponse); - } - } - } - - function shoppingTotal_getTotalResponse(total) { - document.getElementById('total').innerHTML = total; - } - - function shoppingCart_postResponse(entry) { - shoppingCart.get("", shoppingCart_getResponse); - } - - function addToCart() { - var items = document.catalogForm.items; - var j = 0; - for (var i=0; i<items.length; i++) - if (items[i].checked) { - var entry = '<entry xmlns="http://www.w3.org/2005/Atom"><title>item</title><content type="text/xml">' + - '<Item xmlns="http://services/">' + - '<name xmlns="">' + catalogItems[i].name + '</name>' + '<price xmlns="">' + catalogItems[i].price + '</price>' + - '</Item>' + '</content></entry>'; - shoppingCart.post(entry, shoppingCart_postResponse); - items[i].checked = false; - } - } - function checkoutCart() { - document.getElementById('store').innerHTML='<h2>' + - 'Thanks for Shopping With Us!</h2>'+ - '<h2>Your Order</h2>'+ - '<form name="orderForm">'+ - document.getElementById('shoppingCart').innerHTML+ - '<br>'+ - document.getElementById('total').innerHTML+ - '<br>'+ - '<br>'+ - '<input type="submit" value="Continue Shopping">'+ - '</form>'; - shoppingCart.del("", null); - } - function deleteCart() { - shoppingCart.del("", null); - document.getElementById('shoppingCart').innerHTML = ""; - document.getElementById('total').innerHTML = ""; - } - - function init() { - catalog.get(catalog_getResponse); - shoppingCart.get("", shoppingCart_getResponse); - } - -</script> - -</head> - -<body onload="init()"> -<h1>Store</h1> - <div id="store"> - <h2>Catalog</h2> - <form name="catalogForm"> - <div id="catalog" ></div> - <br> - <input type="button" onClick="addToCart()" value="Add to Cart"> - </form> - - <br> - - <h2>Your Shopping Cart</h2> - <form name="shoppingCartForm"> - <div id="shoppingCart"></div> - <br> - <div id="total"></div> - <br> - <input type="button" onClick="checkoutCart()" value="Checkout"> - <input type="button" onClick="deleteCart()" value="Empty"> - <a href="../ShoppingCart/Cart/">(feed)</a> - </form> - </div> -</body> -</html> |