Mapping an object
Valerian <[email protected]>
| Newsgroups | gmane.comp.java.openamf.user |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I've tried to map an object from as to java and i failed
i can't read any properties of the object
see : java service, monPoint.getNom() returns null
any idea ?
thanks,
valerian
here is my code :
--------------------------------------
AS2 Class :
--------------------------------------
class PointTest {
private static var __reg = Object.registerClass("PointTest",PointTest);
private var _id:Number;
private var _posx:Number;
private var _posy:Number;
private var _nom:String;
private var _toto:String;
public function PointTest()
{
}
// getter / setter
public function setId(n:Number):Void { this._id = n; }
public function getId():Number { return _id; }
public function setPosx(n:Number):Void { this._posx = n; }
public function getPosx():Number { return _posx; }
public function setPosy(n:Number):Void { this._posy = n; }
public function getPosy():Number { return _posy; }
public function setNom(n:String):Void { this._nom = n; }
public function getNom():String { return _nom; }
public function setToto(n:String):Void { this._toto = n; }
public function getToto():String { return _toto; }
}
--------------------------------------
Java Class :
--------------------------------------
package com.test.app;
import java.io.Serializable;
public class PointTest implements Serializable {
private Integer _id;
private Float _posx;
private Float _posy;
private String _nom;
public String _toto="test";
private static final String EMPTY_STRING = "";
public PointTest() {
}
public void setId( Integer nId ) {
_id = nId;
}
public Integer getId() {
return _id;
}
public void setX( Float nX ) {
_posx = nX;
}
public Float getX() {
return _posx;
}
public void setY( Float nY ) {
_posy = nY;
}
public Float getY() {
return _posy;
}
public void setNom( String nNom ) {
_nom = ( nNom == null ) ? EMPTY_STRING : nNom;
}
public String getNom() {
return _nom;
}
public void setToto( String n ) {
_toto = ( n == null ) ? EMPTY_STRING : n;
}
public String getToto() {
return _toto;
}
}
--------------------------------------
AS Code :
--------------------------------------
import PointTest;
// flash remoting
import mx.remoting.Service;
import mx.remoting.PendingCall;
import mx.rpc.RelayResponder;
import mx.rpc.FaultEvent;
import mx.rpc.ResultEvent;
var test:PointTest = new PointTest();
test.setId(10);
test.setPosx(10);
test.setPosy(5);
test.setNom("totot");
test.setToto("testas");
trace("item instanceof PointTest: " + (item instanceof PointTest));
var saveService:Service = new
Service("http://localhost:8080/testapp/gateway",null, "com.test.app.SavePoints",
null,null);
var pc:PendingCall = saveService.setData(test);
pc.responder = new RelayResponder(this,"onSaveOk","onSaveError");
function onSaveOk(r:ResultEvent) {
trace("onSaveOk");
trace(r.result);
}
function onSaveError(f:FaultEvent) {
trace("onSaveError");
trace(f.fault);
}
--------------------------------------
Java Service :
--------------------------------------
package com.test.app;
import java.io.Serializable;
public class SavePoints implements Serializable {
public String setData(PointTest monPoint) {
PointTest testt = monPoint;
System.out.println("******************");
System.out.println(monPoint.getNom());
return "+----"+monPoint.getToto();
}
}
--------------------------------------
openamf-config.xml :
--------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<config>
<amf-serializer>
<force-lower-case-keys>false</force-lower-case-keys>
</amf-serializer>
<!-- Required for DefaultGateway-->
<invoker>
<name>PageableRecordSet</name>
<class>org.openamf.invoker.PageableResultSetServiceInvoker</class>
</invoker>
<invoker>
<name>SessionControl</name>
<class>org.openamf.invoker.SessionControlInvoker</class>
</invoker>
<invoker>
<name>WebService</name>
<class>org.openamf.invoker.WebServiceInvoker</class>
</invoker>
<invoker>
<name>JMX</name>
<class>org.openamf.invoker.JMXServiceInvoker</class>
</invoker>
<invoker>
<name>Java</name>
<class>org.openamf.invoker.JavaServiceInvoker</class>
</invoker>
<pageable-recordset>
<initial-data-row-count>20</initial-data-row-count>
</pageable-recordset>
<custom-class-mapping>
<java-class>com.test.app.PointTest</java-class>
<custom-class>PointTest</custom-class>
</custom-class-mapping>
<!-- Required for AdvancedGateway -->
<!--
This allows you to declare infomation about your services,
instead of having the DefaultGateway guess
-->
<service>
<name>SessionControlService</name>
<invoker-ref>SessionControl</invoker-ref>
<method>
<name>close</name>
<parameter>
<type>*</type>
</parameter>
</method>
</service>
<service>
<name>OpenAMFPageableRecordSet</name>
<invoker-ref>PageableRecordSet</invoker-ref>
<method>
<name>*</name>
<parameter>
<type>*</type>
</parameter>
</method>
</service>
<service>
<name>Directory</name>
<service-location>com.fictis.cartographie.PointTest</service-location>
<invoker-ref>Java</invoker-ref>
<method>
<!-- Operation's are matched by the name and parameters -->
<name>setData</name>
<parameter>
<!--
type can be the the name of the class,
a * for any types,
or a ? any 1 type
-->
<type>*</type>
</parameter>
</method>
</service>
</config>
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf