diff options
Diffstat (limited to 'sandbox/lresende/sca-2.x/samples/person-jsonrpc/src')
6 files changed, 312 insertions, 0 deletions
diff --git a/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/java/launch/Launch.java b/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/java/launch/Launch.java new file mode 100644 index 0000000000..5f225462c9 --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/java/launch/Launch.java @@ -0,0 +1,39 @@ +/* + * 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 launch; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.ContributionLocationHelper; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +public class Launch { + public static void main(String[] args) throws Exception { + System.out.println("Starting ..."); + String contribution = ContributionLocationHelper.getContributionLocation(Launch.class); + Node node = NodeFactory.newInstance().createNode("person.composite", new Contribution("test", contribution)); + node.start(); + System.out.println("person.composite ready for big business !!!"); + System.in.read(); + System.out.println("Stopping ..."); + node.stop(); + System.out.println(); + } +} diff --git a/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/java/services/Person.java b/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/java/services/Person.java new file mode 100644 index 0000000000..23df63588f --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/java/services/Person.java @@ -0,0 +1,82 @@ +/* + * 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; + +public class Person implements java.io.Serializable { + + private Integer id; + private String firstName; + private String lastName; + private String longitude; + private String latitude; + private String description; + + public Person() { + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getFirstName() { + return this.firstName; + } + + public String getLastName() { + return this.lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getLongatude() { + return this.longitude; + } + + public void setLongatude(String longatude) { + this.longitude = longatude; + } + + public String getLatitude() { + return this.latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public Integer getID() { + return this.id; + } + + public void setID(Integer id) { + this.id = id; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + +} diff --git a/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/java/services/PersonService.java b/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/java/services/PersonService.java new file mode 100644 index 0000000000..9c547697ce --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/java/services/PersonService.java @@ -0,0 +1,28 @@ +/* + * 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.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface PersonService { + void createPerson(Person person); + Person[] get(); +} diff --git a/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/java/services/PersonServiceImpl.java b/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/java/services/PersonServiceImpl.java new file mode 100644 index 0000000000..7a4e294264 --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/java/services/PersonServiceImpl.java @@ -0,0 +1,40 @@ +/* + * 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.util.ArrayList; +import java.util.List; + +public class PersonServiceImpl implements PersonService { + private List<Person> persons = new ArrayList<Person>(); + + @Override + public void createPerson(Person person) { + System.out.println("adding person " + person.getFirstName()); + persons.add(person); + + } + + public Person[] get() { + Person[] catalogArray = new Person[persons.size()]; + persons.toArray(catalogArray); + return catalogArray; + } +} diff --git a/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/resources/person.composite b/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/resources/person.composite new file mode 100644 index 0000000000..4c4741f71b --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/resources/person.composite @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" + targetNamespace="http://person" + name="person"> + + <component name="widget"> + <tuscany:implementation.widget location="uiservices/widget.html"/> + <service name="Widget"> + <tuscany:binding.http uri="/ui"/> + </service> + <reference name="personService" target="PersonComponent/PersonService"/> + </component> + + <component name="PersonComponent"> + <implementation.java class="services.PersonServiceImpl"/> + <service name="PersonService"> + <tuscany:binding.jsonrpc uri="/PersonService"/> + </service> + </component> +</composite> diff --git a/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/resources/uiservices/widget.html b/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/resources/uiservices/widget.html new file mode 100644 index 0000000000..887ef11bfb --- /dev/null +++ b/sandbox/lresende/sca-2.x/samples/person-jsonrpc/src/main/resources/uiservices/widget.html @@ -0,0 +1,84 @@ +<!-- + * 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="../dojo/dojo.js"></script> +<script type="text/javascript" src="widget.js"></script> + +<script language="JavaScript"> + + //@Reference + var personService = new tuscany.sca.Reference("personService"); + + function personService_getResponse(items,exception) { + if(exception){ + alert(exception.message); + return; + } + var persons = ""; + + for (var i=0; i<items.length; i++) { + var person = items[i].firstName + ' - ' + items[i].lastName; + persons += '<input name="items" type="checkbox" value="' + + item + '">' + item + ' <br>'; + } + document.getElementById('persons').innerHTML=catalog; + } + + function addNewPerson() { + var person = new Object(); + person.id = "001" + person.firstName = "Luciano"; + person.lastName = "R"; + + personService.createPerson(person).addCallback(addPerson_getResponse); + } + + function addPerson_getResponse(something) { + personService.get().addCallback(personService_getResponse); + } + + function init() { + try { + personService.get().addCallback(personService_getResponse); + } + catch(e){ + alert(e); + } + } + +</script> + +</head> + +<body onload="init()"> +<h1>Store</h1> + <div id="application"> + <h2>Persons</h2> + <form name="personsForm"> + <div id="persons" ></div> + <br> + <input type="button" onClick="addNewPerson()" value="Add new person"> + </form> + <br> + </div> +</body> +</html> |