summaryrefslogtreecommitdiffstats
path: root/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/service/ServiceProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/service/ServiceProvider.java')
-rw-r--r--sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/service/ServiceProvider.java92
1 files changed, 92 insertions, 0 deletions
diff --git a/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/service/ServiceProvider.java b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/service/ServiceProvider.java
new file mode 100644
index 0000000000..db3b92a238
--- /dev/null
+++ b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/service/ServiceProvider.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.das.service;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.tuscany.das.DASFactory;
+
+import sun.misc.Service;
+
+
+public class ServiceProvider {
+ private static final ServiceProvider instance = new ServiceProvider();
+
+ protected ServiceProvider() {
+
+ }
+
+ public static ServiceProvider getInstance(){
+ return instance;
+ }
+
+ public static DASFactory getDASFactory(){
+ try{
+ Iterator ps = ServiceLoader.providers(DASFactory.class);
+ while(ps.hasNext()){
+ String className = (String) ps.next();
+ DASFactory factory = (DASFactory) Class.forName(className).newInstance();
+ System.out.println( factory.getClass().getName() );
+ return factory;
+ }
+ }catch(Exception e){
+ e.printStackTrace();
+ return null;
+ }
+ return null;
+ }
+
+ public static void Something(){
+ //Second, try to find a service by using the JDK1.3 jar
+ // discovery mechanism. This will allow users to plug a logger
+ // by just placing it in the lib/ directory of the webapp ( or in
+ // CLASSPATH or equivalent ). This is similar with the second
+ // step, except that it uses the (standard?) jdk1.3 location in the jar.
+
+ Iterator ps = Service.providers(DASFactory.class);
+ while(ps.hasNext()){
+ DASFactory factory = (DASFactory) ps.next();
+ System.out.println( factory.getClass().getName());
+ }
+ }
+
+ public static void Anotherthing() throws Exception{
+ //Second, try to find a service by using the JDK1.3 jar
+ // discovery mechanism. This will allow users to plug a logger
+ // by just placing it in the lib/ directory of the webapp ( or in
+ // CLASSPATH or equivalent ). This is similar with the second
+ // step, except that it uses the (standard?) jdk1.3 location in the jar.
+
+ Iterator ps = ServiceLoader.providers(DASFactory.class);
+ while(ps.hasNext()){
+ String className = (String) ps.next();
+ DASFactory factory = (DASFactory) Class.forName(className).newInstance();
+ System.out.println( factory.getClass().getName() );
+ }
+ }
+
+ public static void main(String[] args) throws Exception{
+ //DASFactory factory = ServiceProvider.getInstance().getFactory(Implementation.LDAP);
+ //ServiceProvider.Something();
+ //ServiceProvider.Anotherthing();
+ ServiceProvider.getDASFactory();
+ }
+}