Blog to discuss Midnight Coders products features, ideas and trends in development of Rich Internet Applications

Monday, October 29, 2007

.NET collections and ArrayCollection (WebORB 3.4)

Starting this week I plan to introduce the new features from the upcoming 3.4 release of WebORB for .NET. The first one is support for ActionScript ArrayCollections. The product offers several options:
  1. Serializing ICollection instances as ArrayCollection:

    WebORB can be configured to serialize all instances of System.Collections.ICollection as ArrayCollection. The configuration setting can be found in weborb.config. Set the value to 'no' to enable serialization of ICollection instances as ArrayCollection:
    <legacyCollectionSerialization>no</legacyCollectionSerialization>

  2. Serializing specific collections as ArrayCollection:

    It may be important to map only certain collections to be serialized as ArrayCollection. In that case, set the configuration setting shown above to 'yes' and tag your collections with the following interface:
    Weborb.Types.IWebORBArrayCollection


    The interface does not declare any methods and is recognized by WebORB as a marker interface forcing collection serialization as ArrayCollection.

  3. Using built-in WebORB collections:

    WebORB includes two collection classes serialized as ArrayCollection objects. One of the classes is a standard IList implementation and the other is a generic version:
    Weborb.Types.WebORBArrayCollection : ArrayList

    Weborb.Types.Generic.WebORBArrayCollection<T> : List<T>


  4. Using custom serializer to serialize specific collection classes as ArrayCollection:

    If none of the options listed above work out, you can use a custom serializer to serialize your collection class as ArrayCollection. This is usually the case when you use a code generator or a class library where modifications to the created/provided classes are not possible. Create a serializer class as shown below:
    using System.Collections;
    using Weborb.Writer;

    public class CustomCollectionWriter : ArrayWriter
    {
    public override void write( object obj, IProtocolFormatter writer )
    {
    ArrayList array = new ArrayList( (ICollection) obj );

    writer.BeginWriteNamedObject( "flex.messaging.io.ArrayCollection", 1 );
    writer.WriteFieldName( "source" );
    writer.BeginWriteFieldValue();

    base.write( array.ToArray(), writer );

    writer.EndWriteFieldValue();
    writer.EndWriteNamedObject();
    }
    }


    Register the serializer either in weborb.config or using the API as shown below:

    weborb.config: add the following XML element into the customWriters block. Make sure to modify the namespaces of the custom collection and the serializer types:
    <customWriter>
    <className>com.acme.CustomCollectionType</className>
    <writerClassName>CustomCollectionWriter </writerClassName>
    </customWriter>


    Registering serializer using API: serializer can be registered in the Application_Start event handler in Global.asax:
    Type collectionType = typeof( CustomCollectionType );
    Weborb.Writer.MessageWriter.AddTypeWriter( collectionType, new CustomCollectionWriter() );


  5. Sending ArrayCollection instances to .NET:

    WebORB 3.4 includes configuration settings to support sending ArrayCollection objects to .NET. WebORB can map ArrayCollection to any linear collection type, so the method argument can be any subclass of ICollection.
Until the new version is released, you can download an intermediate build from the Files section of the WebORB interest group (use the latest build there). If you do not have the product installed, make sure to download WebORB distribution from the website first, then upgrade to the latest build.

4 Comments:

Anonymous Anonymous said...

What's the correct way to perform an upgrade? Just run the installer and it automatically does it? What about if you don't have the product installed and you just use a deployed folder for development? Previously I've had to do a manual diff on all the files to see what's changed.

11:32 AM

 
Blogger Mark Piller said...

There are only two files in the nightly build distribution zip. If you already have WebORB installed, replace bin/weborb.dll with the one from the nightly build. Also, replace weborb.config sitting in the root of the virtual directory. If you do not have WebORB installed, download it from the TMC website first, install and then replace the files from the nightly builds located on the discussion forum.

12:00 PM

 
Anonymous Anonymous said...

Hey Mark,
you say that "WebORB 3.4 includes configuration settings to support sending ArrayCollection objects to .NET. WebORB can map ArrayCollection to any linear collection type, so the method argument can be any subclass of ICollection.
"

Where are these settings and can you give me an example of how to use them?

I'm guessing that its something to do with the abstract class mapping?

7:11 AM

 
Anonymous Anonymous said...

Helo Mark i really spent lot of time By trying to send Array collection in weborb 3.4 thank you very much i could find the solution only in your blog thank you

10:13 AM

 

Post a Comment

<< Home