Sucessful Test strong type Value Object communication and casting
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/66cc5a3d Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/66cc5a3d Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/66cc5a3d Branch: refs/heads/feature/amf Commit: 66cc5a3daae1ee9f02264e36cb90b197953c96a9 Parents: a2debfa Author: Carlos Rovira <[email protected]> Authored: Wed Sep 6 15:45:14 2017 +0200 Committer: Carlos Rovira <[email protected]> Committed: Thu Sep 7 00:24:03 2017 +0200 ---------------------------------------------------------------------- .../amfsamples/services/ExampleService.java | 12 +++++ .../flex/amfsamples/valueobjects/Product.java | 54 ++++++++++++++++++++ .../RemoteObjectAMFTest/src/main/flex/App.mxml | 13 ++++- .../src/main/flex/valueObjects/Product.as | 53 +++++++++++++++++++ 4 files changed, 131 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66cc5a3d/examples/amf/SampleAmfWebApp/src/main/java/org/apache/flex/amfsamples/services/ExampleService.java ---------------------------------------------------------------------- diff --git a/examples/amf/SampleAmfWebApp/src/main/java/org/apache/flex/amfsamples/services/ExampleService.java b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/flex/amfsamples/services/ExampleService.java index 86d6d52..f9071af 100644 --- a/examples/amf/SampleAmfWebApp/src/main/java/org/apache/flex/amfsamples/services/ExampleService.java +++ b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/flex/amfsamples/services/ExampleService.java @@ -20,6 +20,7 @@ package org.apache.flex.amfsamples.services; import org.apache.flex.amfsamples.valueobjects.ServerCustomType; +import org.apache.flex.amfsamples.valueobjects.Product; import org.springframework.flex.remoting.RemotingDestination; import org.springframework.stereotype.Service; @@ -44,4 +45,15 @@ public class ExampleService { } return customTypes; } + + public Product getSomeProduct() + { + System.out.println("getSomeProduct called"); + + Product product = new Product(); + product.setName("Some product"); + product.setDescription("This product is only a test typed value object to test AMF strong types"); + + return product; + } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66cc5a3d/examples/amf/SampleAmfWebApp/src/main/java/org/apache/flex/amfsamples/valueobjects/Product.java ---------------------------------------------------------------------- diff --git a/examples/amf/SampleAmfWebApp/src/main/java/org/apache/flex/amfsamples/valueobjects/Product.java b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/flex/amfsamples/valueobjects/Product.java new file mode 100644 index 0000000..c77229e --- /dev/null +++ b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/flex/amfsamples/valueobjects/Product.java @@ -0,0 +1,54 @@ +/* + * 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.flex.amfsamples.valueobjects; + +/** + * The server side object used by AMFConnectionTestService. There is a + * corresponding client side object. + */ +public class Product +{ + private String name; + private String description; + + public Product() + { + } + + public String getName() + { + return name; + } + public void setName(String name) + { + this.name = name; + } + + public String getDescription() + { + return description; + } + public void setDescription(String description) + { + this.description = description; + } + + public String toString() + { + return "Product -> name: " + name + ", description: " + description; + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66cc5a3d/examples/flexjs/RemoteObjectAMFTest/src/main/flex/App.mxml ---------------------------------------------------------------------- diff --git a/examples/flexjs/RemoteObjectAMFTest/src/main/flex/App.mxml b/examples/flexjs/RemoteObjectAMFTest/src/main/flex/App.mxml index 116bf8c..117536a 100644 --- a/examples/flexjs/RemoteObjectAMFTest/src/main/flex/App.mxml +++ b/examples/flexjs/RemoteObjectAMFTest/src/main/flex/App.mxml @@ -27,6 +27,7 @@ limitations under the License. import org.apache.flex.net.events.FaultEvent; import org.apache.flex.net.events.ResultEvent; import valueObjects.ClientValueObject; + import valueObjects.Product; protected function sendName():void { @@ -38,7 +39,11 @@ limitations under the License. trace("Result=" + evt.data); if (evt.data is String) received.text = "Received: " + evt.data; - else + else if (evt.data is Product) + { + var product:Product = evt.data as Product; + received.text = "Received: product name is '" + product.name + "' and product description is '" + product.description + "'" ; + } else { var arr:Array = evt.data as Array; list.dataProvider = arr; @@ -55,6 +60,11 @@ limitations under the License. service.send("getObjectArray1", []); } + protected function getSomeProduct():void + { + service.send("getSomeProduct", []); + } + protected function reportChange():void { var vo:ClientValueObject = list.selectedItem as ClientValueObject; @@ -83,6 +93,7 @@ limitations under the License. <js:Label id="received" width="300"/> <js:TextButton text="Get Array of ValueObjects" click="getVOs()"/> <js:List id="list" labelField="id" width="100" height="100" change="reportChange()"/> + <js:TextButton text="Get Some Product" click="getSomeProduct()"/> </js:View> </js:initialView> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66cc5a3d/examples/flexjs/RemoteObjectAMFTest/src/main/flex/valueObjects/Product.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/RemoteObjectAMFTest/src/main/flex/valueObjects/Product.as b/examples/flexjs/RemoteObjectAMFTest/src/main/flex/valueObjects/Product.as new file mode 100644 index 0000000..aa9e75a --- /dev/null +++ b/examples/flexjs/RemoteObjectAMFTest/src/main/flex/valueObjects/Product.as @@ -0,0 +1,53 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 valueObjects +{ + [RemoteClass(alias="org.apache.flex.amfsamples.valueobjects.Product")] + public class Product + { + public function Product() + { + } + + private var _name:String; + + public function get name():String + { + return _name; + } + + public function set name(value:String):void + { + _name = value; + } + + private var _description:String; + + public function get description():String + { + return _description; + } + + public function set description(value:String):void + { + _description = value; + } + + } +}
