Re: instanceof validation error on checking value obects from server
Jonathan Thompson <[email protected]>
| Newsgroups | gmane.comp.java.openamf.user |
|---|---|
| Message-ID | <[email protected]> |
Troy,
You are the man! I updated all our value objects in our value object
register class and instanceof is returning true for us now. We have a
ValueObject.as class we use to do this; I am posting the code below as a
convenience to others. Our slip up is/was that we were using the same
args that we used in our openamf-config.xml for our
Object.registerClass(). Lesson learned (the hard way).
Thanks,
Jonathan
class ValueObjects
{
// Properties
static private var inst = null;
function ValueObjects()
{
}
static public function getInstance()
{
// Singleton access
if(inst == null)
{
inst = new ValueObjects();
}
return inst;
}
public function registerValueObjects()
{
//
// Add all value objects used in this application here. Each needs
// to be registered as a class for Flash Remoting to successfully
// map incoming objects to AS classes. The same is true for outgoing
// value objects.
//
// registerValueObject("com.flash.classpath.to.ValueObject",
//
com.flash.classpath.to.ValueObject);
//
// In OpenAMF, using the Advanced Gateway, you also have to update
// the openamf-config.xml file and add a custom class mapping
for each
// value object, in the following form:
//
// <custom-class-mapping>
//
<java-class>com.java.classpath.to.ValueObjects</java-class>
//
<custom-class>com.flash.classpath.to.ValueObjects</custom-class>
// </custom-class-mapping>
//
TRACE(Flashout.INFO + "ValueObjects: Registering value objects");
registerValueObject("com.flash.classpath.to.ValueObject",
com.flash.classpath.to.ValueObject);
}
private function registerValueObject(remoteObject, localObject):Void
{
var result:Boolean = Object.registerClass(remoteObject,
localObject);
if(result == false)
{
TRACE(Flashout.ERROR + "ValueObjects::registerValueObject,
Could not register " + remoteObject + " to local object.");
throw new Error("ERROR: ValueObjects::registerValueObject,
Could not register " + remoteObject + " to local object.");
}
else
{
TRACE(Flashout.INFO + "ValueObjects::registerValueObject,
successfully registered " + remoteObject + " to localObject.");
}
}
}
Troy Gardner wrote:
>Please read the OpenAMF/docs/understanding.htm section "Object Mapping" aka
>Class mapping.
>
>
>
>>Here is our Java class:
>>package com.roundbox.oss.om;
>>public class ContentTemplate implements Serializable {
>>
>>
>
>so com.roundbox.oss.om.ContentTemplate
>
>
>
>>and here is our AS2 class:
>>class com.rbx.selfservice.model.vo.ContentTemplate
>>
>>
>
>so com.rbx.selfservice.model.vo.ContentTemplate
>
>
>
>>However, when I attempt to validate the object's class type in Flash
>>like so:
>>
>>TRACE(Flashout.DEBUG + "item instanceof
>>com.rbx.selfservice.model.vo.ContentTemplate: " + (item instanceof
>>com.rbx.selfservice.model.vo.ContentTemplate));
>>
>>
>
>So your AS registerClass should be:
>
>Object.registerClass("com.rbx.selfservice.model.vo.ContentTemplate",
>com.rbx.selfservice.model.vo.ContentTemplate);
>
>NOT
>
>Object.registerClass("com.rbx.selfservice.model.vo.ContentTemplate",
>com.roundbox.oss.om.ContentTemplate);
>
>If you create a new com.roundbox.oss.om.ContentTemplate(); does it show up as
>the instance of correctly?
>
>
>
>>/////////////////////////////////////////
>>// our openamf-config.xml
>>////////////////////////////////////////
>> <invoker>
>> <name>Java</name>
>> <class>org.openamf.invoker.SpringBeanInvoker</class>
>> </invoker>
>>
>>
>
>As mentioned this needs to be either
><invoker>
> <name>Java</name>
> <class>org.openamf.invoker.JavaServiceInvoker</class>
> </invoker>
>
>for Java or
> <invoker>
> <name>Spring</name>
> <class>org.openamf.invoker.SpringBeanInvoker</class>
> </invoker>
>
>if your using Spring. If you are using Spring you'll have to map the concrete
>implementation class being used not the interface.
>
>
>
>> <custom-class-mapping>
>> <java-class>com.roundbox.oss.om.ContentTemplate</java-class>
>> <custom-class>
>> com.rbx.selfservice.model.vo.ContentTemplate
>> </custom-class>
>> </custom-class-mapping>
>>
>>
>
>while it shouldn't make a difference, remove the white space between class>
>tags and com.rbx....etc.
>
>We use class mapping pretty heavily and it works for me.
>
>Troy Gardner -"How you live your seconds, is how you live your days, is how you live your life..."
>
>http://www.troygardner.com -my world
>http://www.troyworks.com - building Rich Internet Applications
>http://www.intrio.com -helping bridge the gap between the humans and machines. Home of the Flickey^(TM)
>
>
>-------------------------------------------------------
>SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
>from IBM. Find simple to follow Roadmaps, straightforward articles,
>informative Webcasts and more! Get everything you need to get up to
>speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
>_______________________________________________
>Openamf-user mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/openamf-user
>
>
>