Please do a partial revert: Re: svn commit: r802567 [1/5] - in /ofbiz/trunk: applications/order/src/org/ofbiz/order/shoppingcart/ applications/product/src/org/ofbiz/shipment/packing/ applications/product/src/org/ofbiz/shipment/verify/ applications/product/src/org/ofbiz/shipment/weigh...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
24 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Please do a partial revert: Re: svn commit: r802567 [1/5] - in /ofbiz/trunk: applications/order/src/org/ofbiz/order/shoppingcart/ applications/product/src/org/ofbiz/shipment/packing/ applications/product/src/org/ofbiz/shipment/verify/ applications/product/src/org/ofbiz/shipment/weigh...

Adam Heath-2
Adrian Crum wrote:

> Adam Heath wrote:
>> However, if there was a central factory, that used the ServiceRegistry
>> pattern, and framework/entity implemented that, getGenericDelegator
>> then called the ServiceRegistry implementation, logging a warning(from
>> perspective of caller) while doing so, and the base factory then
>> loaded the delegator thru ServiceRegistry, then existing code will
>> still work, you'd get a logged warning, and you'd support the new design.
>
> Are you referring to this:
>
> http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider

Yes, using javax.imageio.spi.ServiceRegistry; an example of it's use
is in CachedClassLoader.

java 1.6 has java.util.ServiceLoader, but it's a slightly different api.
Reply | Threaded
Open this post in threaded view
|

Re: Please do a partial revert: Re: svn commit: r802567 [1/5] - in /ofbiz/trunk: applications/order/src/org/ofbiz/order/shoppingcart/ applications/product/src/org/ofbiz/shipment/packing/ applications/product/src/org/ofbiz/shipment/verify/ applications/product/src/org/ofbiz/shipment/weigh...

Adrian Crum
Adam Heath wrote:

> Adrian Crum wrote:
>> Adam Heath wrote:
>>> However, if there was a central factory, that used the ServiceRegistry
>>> pattern, and framework/entity implemented that, getGenericDelegator
>>> then called the ServiceRegistry implementation, logging a warning(from
>>> perspective of caller) while doing so, and the base factory then
>>> loaded the delegator thru ServiceRegistry, then existing code will
>>> still work, you'd get a logged warning, and you'd support the new design.
>> Are you referring to this:
>>
>> http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider
>
> Yes, using javax.imageio.spi.ServiceRegistry; an example of it's use
> is in CachedClassLoader.
>
> java 1.6 has java.util.ServiceLoader, but it's a slightly different api.
>

So, the code:

GenericDelegator delegator = GenericDelegator.getGenericDelegator(String
delegatorName);

would be replaced with something like:

DelegatorFactory factory = (DelegatorFactory)
UtilObject.getServiceProviderByClass(DelegatorFactory.class);
DelegatorInterface delegator = DelegatorFactory
.getGenericDelegator(String delegatorName);

where the method

public static Object UtilObject.getServiceProviderByClass(Class
providerClass);

would use javax.imageio.spi.ServiceRegistry to look up the provider class.

Is that correct?

-Adrian
Reply | Threaded
Open this post in threaded view
|

Re: Please do a partial revert: Re: svn commit: r802567 [1/5] - in /ofbiz/trunk: applications/order/src/org/ofbiz/order/shoppingcart/ applications/product/src/org/ofbiz/shipment/packing/ applications/product/src/org/ofbiz/shipment/verify/ applications/product/src/org/ofbiz/shipment/weigh...

Adam Heath-2
Adrian Crum wrote:

> So, the code:
>
> GenericDelegator delegator = GenericDelegator.getGenericDelegator(String
> delegatorName);
>
> would be replaced with something like:
>
> DelegatorFactory factory = (DelegatorFactory)
> UtilObject.getServiceProviderByClass(DelegatorFactory.class);
> DelegatorInterface delegator = DelegatorFactory
> .getGenericDelegator(String delegatorName);

==
public interface Factory<T> {
        T getInstance(String name);
}
public interface GenericDelegatorFactory implements
Factory<GenericDelegator> {
}
public class GenericDelegatorFactoryImpl implements
GenericDelegatorFactory {
        public GenericDelegator getInstance(String name) {
        }
}
public class UtilObject {
        public static <T> T getImplementation(Factory<T> factory, String name) {

                Iterator<Factory<T>> it = ServiceRegistry.lookupProviders(factory,
loader);
                while (it.hasNext()) {
                        Factory<T> factory = it.next();
                        T instance = factory.getInstance(name);
                        if (instance != null) return instance;
                }
                throw GeneralException("foo");
        }
}
GenericDelegator delegator =
UtilObject.getImplementation(GenericDelegatorFactory.class, name);

src/META-INF/services/org.ofbiz.entity.GenericDelegatorFactory:
org.ofbiz.entity.GenericDelegatorFactoryImpl
==

The above is completely untested.

Reply | Threaded
Open this post in threaded view
|

Re: Please do a partial revert: Re: svn commit: r802567 [1/5] - in /ofbiz/trunk: applications/order/src/org/ofbiz/order/shoppingcart/ applications/product/src/org/ofbiz/shipment/packing/ applications/product/src/org/ofbiz/shipment/verify/ applications/product/src/org/ofbiz/shipment/weigh...

Adrian Crum
Adam Heath wrote:

> Adrian Crum wrote:
>> So, the code:
>>
>> GenericDelegator delegator = GenericDelegator.getGenericDelegator(String
>> delegatorName);
>>
>> would be replaced with something like:
>>
>> DelegatorFactory factory = (DelegatorFactory)
>> UtilObject.getServiceProviderByClass(DelegatorFactory.class);
>> DelegatorInterface delegator = DelegatorFactory
>> .getGenericDelegator(String delegatorName);
>
> ==
> public interface Factory<T> {
> T getInstance(String name);
> }
> public interface GenericDelegatorFactory implements
> Factory<GenericDelegator> {
> }
> public class GenericDelegatorFactoryImpl implements
> GenericDelegatorFactory {
> public GenericDelegator getInstance(String name) {
> }
> }
> public class UtilObject {
> public static <T> T getImplementation(Factory<T> factory, String name) {
>
> Iterator<Factory<T>> it = ServiceRegistry.lookupProviders(factory,
> loader);
> while (it.hasNext()) {
> Factory<T> factory = it.next();
> T instance = factory.getInstance(name);
> if (instance != null) return instance;
> }
> throw GeneralException("foo");
> }
> }
> GenericDelegator delegator =
> UtilObject.getImplementation(GenericDelegatorFactory.class, name);
>
> src/META-INF/services/org.ofbiz.entity.GenericDelegatorFactory:
> org.ofbiz.entity.GenericDelegatorFactoryImpl
> ==
>
> The above is completely untested.

Cool - thanks!

-Adrian

12