Knut,
here is my �little� HiveMindTestCase (7 files):
playground.IPing.java:
package playground;
public interface IPing {
String ping();
}
playground.IPingHolder.java:
package playground;
import playground.IPing;
public interface IPingHolder {
IPing getPing();
}
playground.ObjectProviderMock.java:
package playground;
import org.apache.hivemind.Location;
import org.apache.hivemind.internal.Module;
import org.apache.hivemind.service.ObjectProvider;
public class ObjectProviderMock implements ObjectProvider {
public static Class propertyType;
public ObjectProviderMock() {
super();
}
/**
* Interprets the locator as a service id, and passes it to
* [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> Module#getService(String,
Class)}.
*/
public Object provideObject( Module contributingModule, Class propertyType,
String locator, Location location ) {
ObjectProviderMock.propertyType = propertyType;
return new Ping();
}
}
playground.ObjectProviderTest.java:
package playground;
import org.apache.hivemind.Registry;
import org.apache.hivemind.test.HiveMindTestCase;
public class ObjectProviderTest extends HiveMindTestCase {
public void testPingHolderConstructor() throws Exception {
Registry registry = buildFrameworkRegistry( "objectprovidertest.xml" );
IPingHolder service = (IPingHolder) registry.getService(
"playground.PingHolderConstructor", IPingHolder.class );
service.getPing().ping();
assertSame( IPing.class, ObjectProviderMock.propertyType );
}
public void testPingHolderSetter() throws Exception {
Registry registry = buildFrameworkRegistry( "objectprovidertest.xml" );
IPingHolder service = (IPingHolder) registry.getService(
"playground.PingHolderSetter", IPingHolder.class );
service.getPing().ping();
assertSame( IPing.class, ObjectProviderMock.propertyType );
}
}
playground.Ping.java:
package playground;
public class Ping implements IPing {
public Ping() {
super();
}
public String ping() {
return "ping..";
}
}
playground.PingHolder.java:
package playground;
import playground.IPing;
public class PingHolder implements IPingHolder {
private IPing ping;
/**
*/
public PingHolder() {
super();
}
/**
* @param ping
*/
public PingHolder( IPing ping ) {
super();
this.ping = ping;
}
/**
* @see playground.IPingHolder#getPing()
*/
public IPing getPing() {
return ping;
}
/**
* @param ping The ping to set.
*/
public void setPing( IPing ping ) {
this.ping = ping;
}
}
playground.objectprovidertest.xml:
<?xml version="1.0"?>
<module id="playground" version="1.0.0">
<contribution configuration-id="hivemind.ObjectProviders">
<provider prefix="test" service-id="ObjectProviderMock"/>
</contribution>
<service-point id="ObjectProviderMock"
interface="org.apache.hivemind.service.ObjectProvider">
<create-instance class="playground.ObjectProviderMock"/>
</service-point>
<service-point id="Ping" interface="playground.IPing">
<create-instance class="playground.Ping"/>
</service-point>
<service-point id="PingHolderConstructor" interface="playground.IPingHolder">
<invoke-factory>
<construct class="playground.PingHolder">
<object>test:Ping</object>
</construct>
</invoke-factory>
</service-point>
<service-point id="PingHolderSetter" interface="playground.IPingHolder">
<invoke-factory>
<construct class="playground.PingHolder">
<set-object property="ping" value="test:Ping"/>
</construct>
</invoke-factory>
</service-point>
</module>
Stefan
________________________________
Von: Knut Wannheden [mailto:[EMAIL PROTECTED]
Gesendet: So 23.01.2005 12:39
An: [email protected]
Betreff: Re: ObjectProvider.provideObject(..) question/problem
Stefan,
First of all, sorry about the long delay! I don't think the parameter
value always is Object.class, so this is possibly a bug in HiveMind.
Could you please provide more details about where you see this
behaviour? Maybe even A JUnit test :-)
--knut
On Thu, 20 Jan 2005 02:26:41 -0800, Liebig, Stefan
<[EMAIL PROTECTED]> wrote:
> It seems that the propertyType parameter of the
> ObjectProvider.provideObject(..):
>
> /**
> * Invoked by the translator to provide the value.
> * @param contributingModule the module which contributed to the locator
> * @param propertyType the expected type of property
> * @param locator a string that should be meaningful to this provider. It
> is the suffix of
> * the original input value provided to the translator, after the
> selector prefix
> * (used to choose a provider) was stripped.
> * @param location the location of the input value (from which the
> locator was extracted). Used
> * for error reporting, or to set the location of created objects.
> */
> public Object provideObject(
> Module contributingModule,
> Class propertyType, <-------- here
> String locator,
> Location location);
>
> always is Object.class. I thought that this parameter represents the expected
> type, which is
> the one given within the constructor or setter signature. I just tested it
> with constructors injection!
> The ServiceImplementationFactory.createCoreServiceImplementation(..) does
> provide the
> expected type.
>
> UseCase:
> I am writing an object provider which itself asks another registry (not
> Hivemind) for a service. And
> this requires its type because it creates a dynamic proxy which requires the
> expected type.
>
> Can you please verify this!
>
> Stefan
> email: [EMAIL PROTECTED]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]