RE: FW: creating a component descr dynamicall y

"Guijarro, Julio" <[email protected]>
Newsgroups gmane.comp.java.smartfrog.user
Message-ID <[email protected]>
Hi Stefanos,

To create this example you will need to create several CoponentDescriptions
manually or a better way is to create a text structure with that syntax and
then use the parser to generate the final ComponentDescription for you.


Method 1 :
Similar to our previous discussions but you need to do this in a nested way.
- Create a component description for the basic component that you are using
	Ex. ComponentDescription. sfComponentDescriptionFromStr(
"org/smartfrog/sfcore/workflow/components/doNothing.sf","sf",your_phases,new
Reference("DoNothing"))

  (You can also create a context and then create your own
ComonentDescription all manually.)

- Add your attributes to CompDesc

- Set eager to false if it is a Lazy desc.

-Set parent if any to a another CompDesc

- Repeat for each level.

  

Method 2 (Recommended):  
Create a String with the text to be parsed and then use:

You can use something like:

    /**
      * Utility method that gets Component Description for a String after
applying some parser phases
      *
      * @param String description to parse into ComponentDescription
      * @param String language to select appropriate parser ('sf')
      * @param Vector parser phases to apply. If the vector is null, then
all
      *    the default phases are applied
      * @param Rererence ref reference to resolve in ComponentDescription.
      *        If ref is null the whole result ComponentDescription is
returned.
      *
      * @return process the selected ComponentDescription after compound
      *         description 'phases' are resolved
      *
      * @throws SmartFrogRuntimeException In case of SmartFrog system error
      */
     public static ComponentDescription sfComponentDescriptionFromStr(String
description,  String language, Vector phases) throws SmartFrogException {
         Phases descr = null;
         try {
             descr = (new SFParser("sf")).sfParse(description);
         } catch (Throwable thr) {
             throw new (SmartFrogException) SmartFrogException.forward(thr);
         }
         try {
             if (phases==null) {
                descr = descr.sfResolvePhases();

             } else {
                descr = descr.sfResolvePhases(phases);
             }
         } catch (Throwable thr) {
             throw new (SmartFrogException) SmartFrogException.forward(thr);
         }
         obj = descr.sfAsComponentDescription();

         if (!(obj instanceof ComponentDescription)){
            //throw new SmartFrogResolutionExcep ...
         }
         return (ComponentDescription) obj;
     }


Note that these notes are an indication about how to do it and I haven't
tried to run any of this code. These notes are based for the version in CVS
as today (3 August 2004)

Please, let me know if you have any problem with this.

Regards, 
		Julio Guijarro

> -----Original Message-----
> From: Stefanos Koukoulas [mailto:[email protected]]
> Sent: 27 July 2004 00:14
> To: Guijarro, Julio
> Subject: creating a component descr dynamically
> 
> Hi Julio,
> I'm trying to create the following component
> description dynamically using the SF API:
> 
>    actions extends LAZY {
>       deployGar1 extends Try {
>          action extends LAZY z15_4BaseGarDeployer {
> 	    localFileName ROOT:asianGarFileName;
>          }
>          normal extends LAZY DoNothing { time 10;}
>          abnormal extends LAZY DoNothing { time 10; }
>       }
> 							      deployGar2
> extends Try {
>          action extends LAZY z15_4BaseGarDeployer {
> 	    localFileName ROOT:europeanGarFileName;
>          }
>          normal extends LAZY DoNothing { time 10; }
>          abnormal extends LAZY DoNothing { time 10; }
>       }
>    }
> }
> 
> The problem is that it contains a lot of references
> and inner component descriptions, which I don't know
> how they must be constructed as a sequence of java
> commands.I'd be very grateful if you could help me.


> Thanks a lot,
> Stefanos
> 
> 



-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on
Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
one more big change to announce. We are now OSTG- Open Source Technology
Group. Come see the changes on the new OSTG site. www.ostg.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.