OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

sca-j message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: JAVA-1: Sample code for alternative factory lookup approach


Here is the sample code that I mentioned in
http://lists.oasis-open.org/archives/sca-j/200903/msg00219.html

   Simon

- - - - - - - - - - - - - - - - - -

package org.oasisopen.sca.client;

import java.util.Properties;

import org.oasisopen.sca.client.impl.SCAClientFactoryFinderImpl;

public abstract class SCAClientFactory {

     protected static SCAClientFactoryFinder defaultFactoryFinder;

     public static SCAClient newInstance() {
         return newInstance(null, null);
     }

     public static SCAClient newInstance(Properties properties) {
         return newInstance(properties, null);
     }

     public static SCAClient newInstance(ClassLoader classLoader) {
         return newInstance(null, classLoader);
     }

     public static SCAClient newInstance(Properties properties,
                                         ClassLoader classLoader) {
         final SCAClientFactoryFinder finder =
             defaultFactoryFinder != null ? defaultFactoryFinder :
             new SCAClientFactoryFinderImpl();
         final SCAClientFactory factory
             = finder.find(properties, classLoader);
         return factory.createSCAClient();
     }

     protected abstract SCAClient createSCAClient();
}

- - - - - - - - - - - - - - - - - -

package org.oasisopen.sca.client;

public abstract class SCAClientFactoryFinder {

     public SCAClientFactory find(Properties properties,
                                  ClassLoader classLoader);
}

- - - - - - - - - - - - - - - - - -

package org.oasisopen.sca.client.impl;

public class SCAClientFactoryFinderImpl extends SCAClientFactoryFinder {

     private static final String SCA_CLIENT_FACTORY_PROVIDER_KEY =
             SCAClientFactory.class.getName();

     private static final String SCA_CLIENT_FACTORY_PROVIDER_META_INF_SERVICE
             = "META-INF/services/" + SCA_CLIENT_FACTORY_PROVIDER_KEY;

     public SCAClientFactoryFinderImpl() {
     }

     public SCAClientFactory find(Properties properties,
                                  ClassLoader classLoader) {
         if (classLoader == null) {
             classLoader = getThreadContextClassLoader();
         }
         final String factoryImplClassName =
             discoverProviderFactoryImplClass(properties, classLoader);
         final Class<? extends SCAClientFactory> factoryImplClass
             = loadProviderFactoryClass(factoryImplClassName, classLoader);
         final SCAClientFactory factory =
             instantiateSCAClientFactoryClass(factoryImplClass);
         return factory;
     }

     // remaining code is unchanged
     ....
}

- - - - - - - - - - - - - - - - - -




[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]