class MDSVVista {
private var ident:Number;
private var nombre:String;
private var descripcion:String;
public function MDSVVista (id:Number,nom:String,desc:String) {
this.ident = id;
this.nombre = nom;
this.descripcion = desc;
trace("Vista Constructor: "+this.nombre+" ("+this.ident+"-"+this.descripcion+")");
}
public function getIdent(Void) : Number {
return this.ident;
}
public function setIdent(id:Number) : Void {
this.ident = ident;
}
public function getNombre(Void) : String {
return this.nombre;
}
public function setNombre(nom:String) : Void {
this.nombre = nom;
}
public function getDescripcion(Void) : String {
return this.descripcion;
}
public function setDescripcion(desc:String) : Void {
this.descripcion = desc;
}
}
and a fla document:
import MDSVVista;
// --- Incluimos las clases para la conexin remota
import mx.remoting.NetServices;
import mx.debug.NetDebug;
// --- Definimos la conexin remota
// Connect to the gateway and create a service object
if (connected == null) {
connected = true;
NetServices.setDefaultGatewayUrl("http://localhost:1331/macromedia/gateway");
var my_conn = NetServices.createGatewayConnection();
var myService = my_conn.getService("flashgateway.samples.MDSVGestorVista", this);
}
// --- Definimos el mapeo de clases (clase java / clase Flash)
Object.registerClass("flashgateway.samples.MDSVVista", MDSVVista);
// --- Creamos un usuario Flash
var id:Number = 13;
var nombre:String = "Vista 13";
var desc:String = "Descripcion 13";
trace("Antes de crear la vista");
var nuevaVista:MDSVVista = new MDSVVista(id,nombre,desc);
trace("Despues de crear la vista");
trace("Id de la vista: "+nuevaVista.getIdent());
}
}
if (errors!="") {
throw new Exception (errors) ;
}
ASTranslator t = new ASTranslator();
return (ASObject)t.toActionScript(vista);
}
}
Sent java class MDSVVista is well retrieved in actionscript but sent actionscript class MDSVVista doesn't. In java side String attributes are ok (traces show right values) but Number attributes shows 0 value when must be 13. What maybe the problem?
I have tested changing java numeric attribute to Number, Double,Long, double and the same problem appears. Besides if I do id:Number = new Number(13) the connection crashes and an error is returned.
Help me, please. This is driving me crazy.
Thanks in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for replying. Now, it's solved. There was an error in:
public function setIdent(id:Number) : Void {
this.ident = ident; // must be id
}
Besides, I have a constructor with parameters (not supported in javabeans, I think). Using an unique constructor without parameter the thing goes right. My doubt now is: How can I serialize a class (not javabean) with a constructor passing parameters? Is it possible with ASTranslator or it only support javabean style? Without using ASTranslator is possible?
Thanks again.
Now, I'm working with Macromedia Flash Remoting.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I got problem mapping Number to Java, my ASObject was a value but the Translated class not.
my code:
the custom java class named Hora2
public class Hora2 {
public Number hora;
public String minuto;
}
The service class named Servico
public class Servidor {
public int registrarBo(ASObject ASbo) {
ASTranslator t = new ASTranslator();
Hora2 h = (Hora2)t.fromActionScript(ASbo);
System.err.println(ASbo.get("hora")); // works
System.err.println(h.hora); // prints null (when Number) or 0.0 (when boolean) or 0 (when int)
return 3;
}
}
My custom flash class named Hora2
class Hora2 {
public var hora:Number;
public var minuto:String;
public function Hora2(h:Number, m:String){
Object.registerClass("Hora2",Hora2)
this.hora = h;
this.minuto = m;
}
}
and when a call the service called myservice
...
var h = new Hora2(12,"23");
var pc:PendingCall = Servio.registrarBo(h);
...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
ASTranslator works with JavaBean-style properties so you need get/set accessors for your object properties. Also, you Java class Hora2 needs to implement java.io.Serializable.
Alon
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello, I hava a class in actionscript 2:
class MDSVVista {
private var ident:Number;
private var nombre:String;
private var descripcion:String;
public function MDSVVista (id:Number,nom:String,desc:String) {
this.ident = id;
this.nombre = nom;
this.descripcion = desc;
trace("Vista Constructor: "+this.nombre+" ("+this.ident+"-"+this.descripcion+")");
}
public function getIdent(Void) : Number {
return this.ident;
}
public function setIdent(id:Number) : Void {
this.ident = ident;
}
public function getNombre(Void) : String {
return this.nombre;
}
public function setNombre(nom:String) : Void {
this.nombre = nom;
}
public function getDescripcion(Void) : String {
return this.descripcion;
}
public function setDescripcion(desc:String) : Void {
this.descripcion = desc;
}
}
and a fla document:
import MDSVVista;
// --- Incluimos las clases para la conexin remota
import mx.remoting.NetServices;
import mx.debug.NetDebug;
// --- Definimos la conexin remota
// Connect to the gateway and create a service object
if (connected == null) {
connected = true;
NetServices.setDefaultGatewayUrl("http://localhost:1331/macromedia/gateway");
var my_conn = NetServices.createGatewayConnection();
var myService = my_conn.getService("flashgateway.samples.MDSVGestorVista", this);
}
// --- Definimos el mapeo de clases (clase java / clase Flash)
Object.registerClass("flashgateway.samples.MDSVVista", MDSVVista);
// --- Creamos un usuario Flash
var id:Number = 13;
var nombre:String = "Vista 13";
var desc:String = "Descripcion 13";
trace("Antes de crear la vista");
var nuevaVista:MDSVVista = new MDSVVista(id,nombre,desc);
trace("Despues de crear la vista");
trace("Id de la vista: "+nuevaVista.getIdent());
myService.mandarVista(nuevaVista);
myService.recibirVista();
function mandarVista_Result(result)
{
trace("Vista mandada (correcto): " + result);
trace(" ------------------ ");
trace(" - recibirVista - ");
// --- llamamos al metodo recibirUsuario de la clase Java definida en el servicio
//myService.recibirVista();
}
// --- Definimos la funcion resultado de recibirUsuario
function recibirVista_Result(result)
{
trace("Vista Recibida (correcto): " + result);
trace("es instanceof MDSVVista? -> " + (result instanceof MDSVVista))
}
// --- Definimos una funcin global para el caso de que ocurra un error
_global.System.onStatus = function(status)
{
trace(" - onStatus:");
trace(" code: " + status.code);
trace(" level: " + status.level);
trace(" type: " + status.type);
trace(" rootcause: " + status.rootcause);
trace(" description: " + status.description);
trace(" details: " + status.details);
}
and tha java class to serialize is:
public class MDSVVista implements Serializable{
private long ident;
private String nombre;
private String descripcion;
public MDSVVista ()
{
}
public MDSVVista (long id,String nom,String desc) {
this.ident = id;
this.nombre = nom;
this.descripcion = desc;
System.out.println("Vista: "+this.nombre+" ("+this.ident+"-"+this.descripcion+")");
}
public long getIdent() {
return this.ident;
}
public void setIdent(long id) {
this.ident = ident;
}
public String getNombre() {
return this.nombre;
}
public void setNombre(String nom) {
this.nombre = nom;
}
public String getDescripcion() {
return this.descripcion;
}
public void setDescripcion(String desc) {
this.descripcion = desc;
}
}
and testing class is:
package flashgateway.samples;
//import java.util.logging.Logger;
import com.carbonfive.flash.ASTranslator;
import flashgateway.io.ASObject;
import java.sql.*;
public class MDSVGestorVista
{
/*private static final Logger log =
Logger.getLogger(MDSVGestorVista.class.getName());*/
private String myDriverString = "oracle.jdbc.driver.OracleDriver";
private String myConnectionString = "jdbc:oracle:thin:@10.95.29.195:1521:FFSSVA";
private String myUsername = "opesndsv";
private String myPassword = "opesndsv";
private Connection conn = null;
private MDSVVista vista;
public void mandarVista(ASObject usuarioAS)
{
ASTranslator t = new ASTranslator();
vista = (MDSVVista)t.fromActionScript(usuarioAS);
System.out.println("VISTA RECOGIDA: " + vista.getNombre()+"( "+vista.getIdent()+" ) - "+vista.getDescripcion());
}
public ASObject recibirVista() throws Exception
{
String errors = "";
//CachedRowSet rowset = new CachedRowSet();
long id;
String nom, desc;
try
{
Class.forName(myDriverString);
conn = DriverManager.getConnection(
myConnectionString, myUsername, myPassword);
} catch (ClassNotFoundException e) {
errors = "Incorrect JDBC Driver\n";
}
if(errors == "") {
try
{
Statement s = conn.createStatement();
String sql = "SELECT id_vista,nombre,descripcion FROM NDSV_VISTAS_WEB "+
"WHERE id_vista=1";
System.out.println("Sentencia SQL= "+sql);
ResultSet rs = s.executeQuery(sql);
while ( rs.next() )
{
id = rs.getLong(1);
nom = rs.getString(2);
desc = rs.getString(3);
vista = new MDSVVista(id,nom,desc);
//System.out.println("Datos consulta SQL: "+nom+"( "+id+" ) - "+desc);
System.out.println("VISTA ENVIADA: "+vista.getNombre()+"( "+vista.getIdent()+" ) - "+vista.getDescripcion());
}
rs.close();
s.close();
} catch(SQLException e) { //catch any SQL errors
errors += e.toString() ;
} finally {
if(conn != null) {
conn.close();
}
}
}
if (errors!="") {
throw new Exception (errors) ;
}
ASTranslator t = new ASTranslator();
return (ASObject)t.toActionScript(vista);
}
}
Sent java class MDSVVista is well retrieved in actionscript but sent actionscript class MDSVVista doesn't. In java side String attributes are ok (traces show right values) but Number attributes shows 0 value when must be 13. What maybe the problem?
I have tested changing java numeric attribute to Number, Double,Long, double and the same problem appears. Besides if I do id:Number = new Number(13) the connection crashes and an error is returned.
Help me, please. This is driving me crazy.
Thanks in advance.
Can you tell me the keys/values of the entries in the ASObject passed to mandarVista()?
If the ident entry has a value of 13, there is an issue with ASTranslator. If it has a value of 0 or null it is an issue with the Remoting gateway.
Which Remoting implementation are you using? Macromedia? OpenAMF?
-alon
Thanks for replying. Now, it's solved. There was an error in:
public function setIdent(id:Number) : Void {
this.ident = ident; // must be id
}
Besides, I have a constructor with parameters (not supported in javabeans, I think). Using an unique constructor without parameter the thing goes right. My doubt now is: How can I serialize a class (not javabean) with a constructor passing parameters? Is it possible with ASTranslator or it only support javabean style? Without using ASTranslator is possible?
Thanks again.
Now, I'm working with Macromedia Flash Remoting.
Hi,
I got problem mapping Number to Java, my ASObject was a value but the Translated class not.
my code:
the custom java class named Hora2
public class Hora2 {
public Number hora;
public String minuto;
}
The service class named Servico
public class Servidor {
public int registrarBo(ASObject ASbo) {
ASTranslator t = new ASTranslator();
Hora2 h = (Hora2)t.fromActionScript(ASbo);
System.err.println(ASbo.get("hora")); // works
System.err.println(h.hora); // prints null (when Number) or 0.0 (when boolean) or 0 (when int)
return 3;
}
}
My custom flash class named Hora2
class Hora2 {
public var hora:Number;
public var minuto:String;
public function Hora2(h:Number, m:String){
Object.registerClass("Hora2",Hora2)
this.hora = h;
this.minuto = m;
}
}
and when a call the service called myservice
...
var h = new Hora2(12,"23");
var pc:PendingCall = Servio.registrarBo(h);
...
You need to take another read of the documentation: http://carbonfive.sourceforge.net/astranslator/api/com/carbonfive/flash/package-summary.html#documentation
ASTranslator works with JavaBean-style properties so you need get/set accessors for your object properties. Also, you Java class Hora2 needs to implement java.io.Serializable.
Alon