[picocontainer-dev] NanoContainer getComponentInstance() ???

"Michael Rimov" <[email protected]>
Newsgroups gmane.comp.java.picocontainer.devel
Organization Centerline Computers, Inc
Message-ID <051501c66554$6fb8ad30$651ea8c0@prosperity>
Hi all,

 

I was surprised to find that the following groovy script didn't work:

 

 

def CUSTOM_OBJECT_KEY = 'SpecializedInstanceKey'

 

pico = builder.container(parent:parent) {

      //..

}

 

def customObject = parent.getComponentInstance(UNIT_OF_WORK_FACTORY_KEY)

if (customObject == null) {

      println("Using Default Unit Of Work Factory")

      customObject = parent.getComponentInstance(OriginalClass)

}

 

pico.registerComponentInstance(CUSTOM_OBJECT_KEY, customObject);

 

 

 

The culprit was the fact that the line:

pico = builder.container(parent:parent)

 

returns a NanoContainer.

 

And NanoContainer doesn't have 

 

getComponentInstance(Object key)

 

 

I'd really like to not have to do in my script:

 

def picoToUse;

if (parent instanceof NanoPicoContainer) {

     picoToUse = ((NanoPicoContainer) parent).getPico();

} else {

      throw new IllegalStateException("Pico returned from container builder
wasn't NanoPicoContainer")

}

 

def customObject = parent.getComponentInstance(UNIT_OF_WORK_FACTORY_KEY)

if (customObject == null) {

      println("Using Default Unit Of Work Factory")

      customObject = parent.getComponentInstance(OriginalClass)

}

 

pico.registerComponentInstance(CUSTOM_OBJECT_KEY, customObject);

 

Since the NanoContainer  Interface allows registration by key of type
Object, couldn't it have a getComponentInstance(Object key) as well?

 

The reason for something like this is that I'm deploying subcomponents
through Deployer and I would like to have the capability to define a
separate DataSource per-component if necessary yet if that custom datasource
doesn't exist, simply utilize the default one defined in the parent
container.

 

Thanks, 

 

 
-Mike
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.