Hi,
Is this the same as inserting an interface into META-INF/services?
Currently, we have been developing by doing the following:
Module A
/src/package1/IEngineHolder (interface)
Module B (depends on Module A)
/src/package4/EngineHolderImpl (implements IEngineHolder)
/META-INF/services/package1.IEngineHolder (text file with path to
EngineHolderImpl inside it)
Module C - uses getLookup().getDefault().lookup (new
Template(IEngineHolder);
Rereading the below post it would seem that use the layer.xml is
quicker? Is this the case?
Any info appreciated.
Regards
Paul
-----Original Message-----
From: Wade Chandler [mailto:
hwadechandler-nb@...]
Sent: 13 May 2008 15:34
To:
dev@...
Subject: Re: [openide-dev] Best way to share object instances between
modules?
--- Sergio Lopes <
knitter.is@...> wrote:
> > Can you attach your layer.xml file? I'll have a look at it. Do you
have a folder defined?
> File is not that big, though I believe you must have better things to
> do than look at my code ;)
Sure, I have a lot to do, but I think once I show you this you'll have
it down, and I won't have to explain the whole thing to you again. You
can start playing around with this stuff and help some others when they
ask ;-).
> These are the two variations I tried following the documentation
> <filesystem>
> <folder name="CatalogEngine">
> <file
name="de-berlios-jfindmyfiles-catalog-CatalogEngine.instance">
> <attr name="instanceClass"
> stringvalue="de.berlios.jfindmyfiles.catalog.CatalogEngine"/>
> </file>
> </folder>
> </filesystem>
>
This should work fine, though you might want to include some uniqueness
in the name such as
<folder name="com-yourdomain-CatalogEngine">
just in case others have modules you want to use which might have a
CatalogEngine of some kind using the same name. You'd know more about
your application and what you are using.
Also note that
<file name="de-berlios-jfindmyfiles-catalog-CatalogEngine.instance"/>
is all you need in this case. The instance attribute stuff is so you
could just have the name be "CatalogEngine" or "CatalogEngineImpl" and
not worry about the .instance. The files with a name ending in .instance
are instantiated. The .instance on the end is a command to NB.
> or
>
> <filesystem>
> <file
name="de-berlios-jfindmyfiles-catalog-CatalogEngine.instance">
> <attr name="instanceClass"
> stringvalue="de.berlios.jfindmyfiles.catalog.CatalogEngine"/>
> </file>
> </filesystem>
>
Now, you can make this work, but it is going to be a big lookup
including "everything" from the system...and I mean more than the
default lookup as the default is based on META-INF/services.
> This is on the layer file of the Catalog module, I'm trying to look
> for the instance on the GUI module.
>
Sure, I think now we need to look at the code where you are creating
your Lookup. It should be like this for the entry above with the folder:
Lookup lu = Lookups.forPath("/CatalogEngine");
CatalogEngine ce = lu.lookup(CatalogEngine.class);
and for the one with no folder:
Lookup lu = Lookups.forPath("/");
CatalogEngine ce = lu.lookup(CatalogEngine.class);
Just be sure and store this Lookup off some where. That way when you
need to use it you can use it without having to recreate the entire
thing over and over. Then as data changes in your folder you can have
different instances etc changed in your lookup without having to create
the whole thing again.
If you want to have the idea of a merged set of CatalogEngines then you
can name your folder CatalogEngines and loop over each one looking to
see if one contains what you are trying to find.
You would use Lookup.lookupResult or lookupAll for this.
Anyways, if this doesn't get you going let me know, but remember what
Tom was telling you about interfaces. With Lookup you can have a folder
or tree with instances inside it and have things implement interfaces so
you can change out the implementation or as I said with CatalogEngine
have multiple ones which you can query...this would work sort of like
the JDBC connection manager or the NB editor and data loader stuff.
Wade
==================
Wade Chandler, CCE
Software Engineer and Developer, Certified Forensic Computer Examiner,
NetBeans Dream Team Member, and NetBeans Board Member
http://www.certified-computer-examiner.comhttp://wiki.netbeans.org/wiki/view/NetBeansDreamTeamhttp://www.netbeans.org______________________________________________________
Reg. Office: VEGA Group PLC, 2 Falcon Way, Shire Park, Welwyn Garden City, Herts AL7 1TW, UK
Registered in England, Number 1393778
______________________________________________________