0 Replies Latest reply on Jan 20, 2012 12:18 AM by Andy_I

    TypeError: Error #1034 after generating AS classes from Java using Data Centric Development

    Andy_I

      Hello together,

      is it possible to generate Action Script Classes from complex Java Classes with the new Data-centric development in Adobe Flash Builder 4? I tried it couple of days, but I always run in an TypeError: Error #1034: Type Coercion failed: cannot convert Object@e60c149  to valueObjects.ChildObject.

      In case of complex java Objects, I mean objects which contain an Object again. In my example: Object “parent” comprises Object “child” (Aggregation).

       

      By loading object “parent” the object “child” cannot be mapped to the Action Script Class, and  it ends in TypeError: Error #1034. Why is the “child” object not mapped? And what can I do, to solve this issue?

       

      Main Application with Service call:

       

       

      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx"
                     xmlns:services="services.*"
                     minWidth="955" minHeight="600">
          <fx:Script>
              <![CDATA[
                  import mx.rpc.events.ResultEvent;
                  import valueObjects.ParentObject;
      
                  protected function button_clickHandler(event:MouseEvent):void
                  {
                      getMyObjectResult.token = fxService.getMyObject();
                  }
      
                  protected function getMyObjectResult_resultHandler(event:ResultEvent):void
                  {
                      var parentObject:ParentObject = getMyObjectResult.lastResult;        
                      trace(parentObject);
                      trace(parentObject.childObject);
                  }
      
              ]]>
          </fx:Script>
          <fx:Declarations>
              <s:CallResponder id="getMyObjectResult" result="getMyObjectResult_resultHandler(event)"/>
              <services:FxService id="fxService"
                                  fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"
                                  showBusyCursor="true"/>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>
          <s:Button id="button" x="10" y="10" label="getMyObj" click="button_clickHandler(event)"/>
      </s:Application>
      

       

      Here are a part of my generated Classes:

       

      _Super_FxService:

       

       

      [ExcludeClass]
      internal class _Super_FxService extends com.adobe.fiber.services.wrapper.RemoteObjectServiceWrapper
      {
      
          // Constructor
          public function _Super_FxService()
          {
              // initialize service control
              _serviceControl = new mx.rpc.remoting.RemoteObject();
      
              // initialize RemoteClass alias for all entities returned by functions of this service
      
              var operations:Object = new Object();
              var operation:mx.rpc.remoting.Operation;
      
              operation = new mx.rpc.remoting.Operation(null, "getMyObject");
              operation.resultType = valueObjects.ParentObject;
              operations["getMyObject"] = operation;
      
              _serviceControl.operations = operations;
              _serviceControl.convertResultHandler = com.adobe.serializers.utility.TypeUtility.convertResultHandler;
      
      
               preInitializeService();
               model_internal::initialize();
          }
      
          //init initialization routine here, child class to override
          protected function preInitializeService():void
          {
              destination = "FxService";
      
          }
      
      
          /**
            * This method is a generated wrapper used to call the 'getMyObject' operation. It returns an mx.rpc.AsyncToken whose 
            * result property will be populated with the result of the operation when the server response is received. 
            * To use this result from MXML code, define a CallResponder component and assign its token property to this method's return value. 
            * You can then bind to CallResponder.lastResult or listen for the CallResponder.result or fault events.
            *
            * @see mx.rpc.AsyncToken
            * @see mx.rpc.CallResponder 
            *
            * @return an mx.rpc.AsyncToken whose result property will be populated with the result of the operation when the server response is received.
            */
          public function getMyObject() : mx.rpc.AsyncToken
          {
              var _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation("getMyObject");
              var _internal_token:mx.rpc.AsyncToken = _internal_operation.send() ;
              return _internal_token;
          }
      
      }
      
      }
      

       

       

      _Super_ParentObject

       

       

      [ExcludeClass]
      public class _Super_ParentObject extends flash.events.EventDispatcher implements com.adobe.fiber.valueobjects.IValueObject
      {
          model_internal static function initRemoteClassAliasSingle(cz:Class) : void
          {
              try
              {
                  if (flash.net.getClassByAlias("com.fx.model.ParentObject") == null)
                  {
                      flash.net.registerClassAlias("com.fx.model.ParentObject", cz);
                  }
              }
              catch (e:Error)
              {
                  flash.net.registerClassAlias("com.fx.model.ParentObject", cz);
              }
          }
      
          model_internal static function initRemoteClassAliasAllRelated() : void
          {
              valueObjects.ChildObject.initRemoteClassAliasSingleChild();
          }
      
          model_internal var _dminternal_model : _ParentObjectEntityMetadata;
          model_internal var _changedObjects:mx.collections.ArrayCollection = new ArrayCollection();
      
          public function getChangedObjects() : Array
          {
              _changedObjects.addItemAt(this,0);
              return _changedObjects.source;
          }
      
          public function clearChangedObjects() : void
          {
              _changedObjects.removeAll();
          }
      
          /**
           * properties
           */
          private var _internal_childObject : valueObjects.ChildObject;
      
          private static var emptyArray:Array = new Array();
      
      
          /**
           * derived property cache initialization
           */
          model_internal var _cacheInitialized_isValid:Boolean = false;
      
          model_internal var _changeWatcherArray:Array = new Array();
      
          public function _Super_ParentObject()
          {
              _model = new _ParentObjectEntityMetadata(this);
      
              // Bind to own data or source properties for cache invalidation triggering
      
          }
      
          /**
           * data/source property getters
           */
      
          [Bindable(event="propertyChange")]
          public function get childObject() : valueObjects.ChildObject
          {
              return _internal_childObject;
          }
      
          public function clearAssociations() : void
          {
          }
      
          /**
           * data/source property setters
           */
      
          public function set childObject(value:valueObjects.ChildObject) : void
          {
              var oldValue:valueObjects.ChildObject = _internal_childObject;
              if (oldValue !== value)
              {
                  _internal_childObject = value;
                  this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "childObject", oldValue, _internal_childObject));
              }
          }
      ...
      

       

       

      _Super_ChildObject

       

      [ExcludeClass]
      public class _Super_ChildObject extends flash.events.EventDispatcher implements com.adobe.fiber.valueobjects.IValueObject
      {
          model_internal static function initRemoteClassAliasSingle(cz:Class) : void
          {
              try
              {
                  if (flash.net.getClassByAlias("com.fx.model.ChildObject") == null)
                  {
                      flash.net.registerClassAlias("com.fx.model.ChildObject", cz);
                  }
              }
              catch (e:Error)
              {
                  flash.net.registerClassAlias("com.fx.model.ChildObject", cz);
              }
          }
      
          model_internal static function initRemoteClassAliasAllRelated() : void
          {
          }
      
          model_internal var _dminternal_model : _ChildObjectEntityMetadata;
          model_internal var _changedObjects:mx.collections.ArrayCollection = new ArrayCollection();
      
          public function getChangedObjects() : Array
          {
              _changedObjects.addItemAt(this,0);
              return _changedObjects.source;
          }
      
          public function clearChangedObjects() : void
          {
              _changedObjects.removeAll();
          }
      
          /**
           * properties
           */
          private var _internal_f : Number;
          private var _internal_d : Number;
          private var _internal_s : String;
          private var _internal_l : Number;
          private var _internal_i : int;
      
          private static var emptyArray:Array = new Array();
      
          // Change this value according to your application's floating-point precision
          private static var epsilon:Number = 0.0001;
      
          /**
           * derived property cache initialization
           */
          model_internal var _cacheInitialized_isValid:Boolean = false;
      
          model_internal var _changeWatcherArray:Array = new Array();
      
          public function _Super_ChildObject()
          {
              _model = new _ChildObjectEntityMetadata(this);
      
              // Bind to own data or source properties for cache invalidation triggering
      
          }
      
          /**
           * data/source property getters
           */
      
          [Bindable(event="propertyChange")]
          public function get f() : Number
          {
              return _internal_f;
          }
      
          [Bindable(event="propertyChange")]
          public function get d() : Number
          {
              return _internal_d;
          }
      
          [Bindable(event="propertyChange")]
          public function get s() : String
          {
              return _internal_s;
          }
      
          [Bindable(event="propertyChange")]
          public function get l() : Number
          {
              return _internal_l;
          }
      
          [Bindable(event="propertyChange")]
          public function get i() : int
          {
              return _internal_i;
          }
      
          public function clearAssociations() : void
          {
          }
      
          /**
           * data/source property setters
           */
      
          public function set f(value:Number) : void
          {
              var oldValue:Number = _internal_f;
              if (isNaN(_internal_f) == true || Math.abs(oldValue - value) > epsilon)
              {
                  _internal_f = value;
                  this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "f", oldValue, _internal_f));
              }
          }
      
          public function set d(value:Number) : void
          {
              var oldValue:Number = _internal_d;
              if (isNaN(_internal_d) == true || Math.abs(oldValue - value) > epsilon)
              {
                  _internal_d = value;
                  this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "d", oldValue, _internal_d));
              }
          }
      
          public function set s(value:String) : void
          {
              var oldValue:String = _internal_s;
              if (oldValue !== value)
              {
                  _internal_s = value;
                  this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "s", oldValue, _internal_s));
              }
          }
      
          public function set l(value:Number) : void
          {
              var oldValue:Number = _internal_l;
              if (oldValue !== value)
              {
                  _internal_l = value;
                  this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "l", oldValue, _internal_l));
              }
          }
      
          public function set i(value:int) : void
          {
              var oldValue:int = _internal_i;
              if (oldValue !== value)
              {
                  _internal_i = value;
                  this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "i", oldValue, _internal_i));
              }
          }
      

       

       

       

      Could it be that this method is not called? -> initRemoteClassAliasAllRelated()

       

       

      Andy the Java objects look like this:

      Model:

       

      ParentObject:

       

      package com.fx.model;
      
      public class ParentObject {
          private ChildObject childObject;
      
          public ChildObject getChildObject() {
              return childObject;
          }
      
          public void setChildObject(ChildObject childObject) {
              this.childObject = childObject;
          }
      
      }
      

       

      ChildObject:

       

      package com.fx.model;
      
      public class ChildObject {
          private String         s;
          private Integer     i;
          private Long        l;
          private Float         f;
          private Double        d;
      
          public ChildObject(String s, Integer i, Long l, Float f, Double d) {
              super();
              this.s = s;
              this.i = i;
              this.l = l;
              this.f = f;
              this.d = d;
          }
          
          public String getS() {
              return s;
          }
          public void setS(String s) {
              this.s = s;
          }
          public Integer getI() {
              return i;
          }
          public void setI(Integer i) {
              this.i = i;
          }
          public Long getL() {
              return l;
          }
          public void setL(Long l) {
              this.l = l;
          }
          public Float getF() {
              return f;
          }
          public void setF(Float f) {
              this.f = f;
          }
          public Double getD() {
              return d;
          }
          public void setD(Double d) {
              this.d = d;
          }
      }
      

       

       

      Service:

       

      package com.fx.service;
      
      import com.fx.model.ChildObject;
      import com.fx.model.ParentObject;
      
      public class FxService {
      
          public ParentObject getMyObject() {
              ParentObject po = new ParentObject();
              po.setChildObject(new ChildObject("hallo", 1, 100l, 1.2f, 1.22222d));
              return po;
          }
      }
      

       

       

       

       

      Configuration Files:

       

      remoting-config.xml

       

      <?xml version="1.0" encoding="UTF-8"?>
      <service id="remoting-service" 
          class="flex.messaging.services.RemotingService">
      
          <adapters>
              <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
          </adapters>
      
          <default-channels>
              <channel ref="my-amf"/>
          </default-channels>
      
          <destination id="FxService">
              <properties>
                  <source>
                      com.fx.service.FxService
                  </source>
                  <scope>session</scope>
              </properties>
          </destination>
          
      </service>
      

       

       

      web.xml

       

       

      ...
      
      
      <!-- begin rds -->
      
      <servlet>
      
      
      <servlet-name>RDSDispatchServlet</servlet-name>
      
      
      <servlet-class>flex.rds.server.servlet.FrontEndServlet</servlet-class>
      
      
      <init-param>
      
      
      
      <param-name>useAppserverSecurity</param-name>
      
      
      
      <param-value>false</param-value>
      
      
      </init-param>
      
      
      <load-on-startup>10</load-on-startup>
      
      </servlet>
      
      
      
      <servlet-mapping id="RDS_DISPATCH_MAPPING">
      
      
      <servlet-name>RDSDispatchServlet</servlet-name>
      
      
      <url-pattern>/CFIDE/main/ide.cfm</url-pattern>
      
      </servlet-mapping>
      
      <!-- end rds -->
      
      ...
      

       

       

       

      If someone wants to see the whole project, I could send it by e-mail.

       

       

      Please help me to find the issue.

      Many thanks in advance.