writing a new reprentation



writing a representation

A representation can either be serialized and directly atached as a new attribute (not recommed but easy to do), a factory(see below) can be atached that implements an interface a UI can look for (better) or a ServiceUI UIDescriptor can be atached (this became standart).  For a new type of Representation going the third wa means to create a new factory-interface as in (2) and giving this factory a TOOLKIT-object to identify this type of factory without using MarshalledObject.instanceof().

describing the representation.


This is done by creating and filling a UIDescriptor. The role can savely be set to MainUI.ROLE. See the ServiceUI-standart for details about it. The nect argument you see is the identifier for the factory-typoe used. The factory is atached pre-serialized for not having to de-serialize it just to look if it is compactible with a UI. It then looks like this:

 /**
  * Get a UIDescriptor as needed by the serviceui-draft-standart
  */
 public static UIDescriptor getUIDescriptor()
  {
   try
     {
      return(new UIDescriptor(MainUI.ROLE,
                              JComponentFactory.TOOLKIT,
                              getServiceUIProperties(),
                              new MarshalledObject(new Factory()))
                             );
     }
   catch(IOException e)
     {
      e.printStackTrace(Logger.err);
     }
   return(null);
  }



  /**
   * Gets a serviceui-draft-standart-compactible attribute-set of this representation
   */
  static Set getServiceUIProperties()
  {
   HashSet set = new HashSet();
   set.add("javax.swing.JComponent");
   set.add("javax.swing.JPanel");
   set.add("java.awt.Component");

   HashSet retval = new HashSet();
   retval.add(new UIFactoryTypes(set));

   HashMap map = new HashMap();
   map.put("javax.swing", Package.getPackage("javax.swing").getSpecificationVersion());
   RequiredPackages req = new RequiredPackages(map);
   retval.add(req);

   return(retval);
  }


  /**
   * A serializable factory for creating this UI
   */
  public static class Factory implements JComponentFactory, Serializable
  {


   /**
    * Returns a <CODE>JComponent</CODE>.
    */
   public JComponent getJComponent(Object roleObject)
   {
    ServiceItem item = (ServiceItem)roleObject;

    Logger.debug.println("DEBUG: [RemoteDesktopClientSwingRepresentation.factory] getJComponent called");
    try
      {
       CalculatorSwingRepresentation rep = new CalculatorSwingRepresentation( ((CalculatorProxy)item.service) );
       return(rep.getPanel());
      }
    catch(RemoteException ex)
       {return(null);}

   }
  }


The  UIFactoryTypes -object gives an indication abaut the types of object created by the factory. It is can be used by the UI if only a subset of the possible objects for this factory-type are supported. ReqiredPackages gets a list of packages and package-versions that need to be available for the representation to function properly.

deploying the representation.


You can atach the UIDescriptor either as a new attribute in the init()-call in the code of the service (or be returned by the getUIDescriptor-call) or you can write a new service that looks for services who's proxy implements the apropriate service-interface and add the new representation automatically via the administrative-object.