|
From: Colin S. <col...@ex...> - 2004-11-02 21:57:00
|
There's probably some cleaner ways to handle this, but off the top of my head I can think of one fairly easy mechanism that should take 10 minutes or less to implement. Sucblass ClasspathXmlApplicationContext to have a Communicator field, and getCommunicator() method to get the value of this. When your variant of ClasspathXmlApplicationContext is created, the Communicator instance could be passed in as a constructor arg (make a new constructor), or as a setter property (you would need to make sure to use the existing constructor with refresh=false, for that approach). To actually get at the Communicator instance inside the context def, the user would just use a custom FactoryBean you define. This factory bean would be ApplicationContextAware, so would have the context given to it. All it would do on the getObject() method, is cast the context to your subclass type, and return the value of the getCommunicator() method. All the user has to do when setting up their context.xml file is remember to add in a one line bean definition for your factory: <bean id="communicator" class="x.y.z.CommunicatorFactoryBean"/> Regards, Colin Venkat Sonnathi wrote: > Hi, > > The subject may sound strange but please bear with me. I am trying to > use Spring to isolate ICE (http://www.zeroc.com) specific depedencies. > I could prototype the client side interaction (Thanks to Jurgen for > pointing me in the right direction), but have come to a block when > trying Server side. > > ICE has a kind of app server called IceBox, it loads different > services from a Config file, it has a feature called > UseSharedCommunicator, which means all the loaded services share the > same ICE runtime instance and calls to other services located in the > same instance are treated as local calls. > > Basically you wrap a ServiceImpl class in ServiceAdapter so that > IceBox can load it, here is an example of the ServiceAdapter for a > ServiceImpl class PrinterI > > public class IceBoxService extends Ice.LocalObjectImpl implements > IceBox.Service { > > private Ice.ObjectAdapter adapter; > > public void start(String s, Communicator communicator, String[] > strings) { > > this.adapter = communicator.createObjectAdapter(s); > Ice.Object object = new PrinterI(communicator); > adapter.add(object, > Ice.Util.stringToIdentity("SimpleFCASearch")); > adapter.activate(); > } > > public void stop() { > adapter.deactivate(); > } > } > > } > > I was planning on writing a generic IceBoxService which takes a > parameter to context.xml file and instantiate a BeanFactory which > loads the ServiceImpls and resolve the services they depend upon. > But, if you observe how the PrinterI is instantiated, the communicator > instance passed to it should be one that is supplied by the IceBox > server (passed in as a parameter to start method). How to make a bean > factory aware of this communicator? > > The following code explains the behaviour I am looking for: > BeanFactory bf = new ClassPathXmlApplicationContext(); > bf.setBean("communicator", communicator); // Setting/passing the > application communicator instance to the Bean > bf.load("context.xml"); // refers to the communicator bean passed in > above statement. > > Thanks for your time and patience. > > --Venkat. > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: > Sybase ASE Linux Express Edition - download now for FREE > LinuxWorld Reader's Choice Award Winner for best database on Linux. > http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer |