cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ard Schrijvers" <>
Subject RE: Same component instance but multiple roles
Date Thu, 11 Jan 2007 10:05:05 GMT

I do not really understand why you want to implement both DupChecker role and FileDuplicateStore
in one component instance? They do different things, right? If they are very similar, you
could differentiate between the two with parametarization

I am not sure if this helps you out, but I will try to put your story below in an (stupid)
example, and how I would implement it. 

Suppose, I have a directory in which documents are stored every now and then, in a random
folder structure. Now, I would like to have a generator that returns all different files names,
and one that returns all file names. Of course, these two things are very similar, so one
generator todo both things are very well possible. Even loading the directories and files
in the generator is simple. But, suppose, later, you also need an inputmodule, or a source-factory
accessing the same thing. Duplicating the stuff in the generator is not an option, and inefficient.


I am not really sure if the problem above is realistic enough to match your idea/problem,
but, I would create one component that reads all files from the directory structure and puts
them in maps. You use a file monitor, for example org.apache.avalon.excalibur.monitor.Monitor
to check the filesytem, and on change, edit the maps. 

Now, the component above implements an interface that has some methods that you want to use
(some getters). Now, all your other components that want the use the maps of the component
and the methods of the interface, just lookup the interface, and, well, that is about it.
Suppose your interface is called "FileSystemSources", then "FileSystemSourcesImpl" implements
all the traversing through the FS and filling the maps, and has the implemented methods. 

Now, any generator, inputmodule, selector, transformer, etc can just access the interface
methods by adding 

m_filesystemSources = (FileSystemSources) manager.lookup(FileSystemSources.ROLE);

Hope this is a little what you meant...

Regards Ard

Is there a way to have the same component instance implement multiple roles?

In short, I have a component that stores name-value pairs. The component persists the list
of pairs in a file. Some parts of the system need to check for duplicates using the DupChecker
interface like...

public boolean isDuplicate(String arg1,String arg2)

Other parts of the system need to access the component to add a new file of duplicates using
an interface like

public boolean addDupFile(String fileURI)

The components that check for duplicates don't care about how the duplicates are persisted,
so I don't want to expose the functionality to them. For example, I may change it one day
so that the pairs are stored in a database - which should be transparent to the parts of the
system that just want to check for a duplicate. So I want to have DupChecker role and FileDuplicateStore
role both implemented by the same component instance.

How do you do this?

thanks - simon

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message