From 0f76a4264b9ad261a9cc8dcb28145860f053d051 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Fri, 6 Aug 2010 15:57:51 +0800 Subject: [PATCH] * Make the service locator API more flexible. --- .../org/adempiere/base/IServiceLocator.java | 7 ++-- base/src/org/adempiere/base/Service.java | 24 ++++++++++--- .../base/equinox/EquinoxServiceLocator.java | 34 +++++++++++++++---- .../adempiere/base/equinox/ExtensionList.java | 1 - 4 files changed, 51 insertions(+), 15 deletions(-) diff --git a/base/src/org/adempiere/base/IServiceLocator.java b/base/src/org/adempiere/base/IServiceLocator.java index 3d75392dd1..b9ba7a0205 100644 --- a/base/src/org/adempiere/base/IServiceLocator.java +++ b/base/src/org/adempiere/base/IServiceLocator.java @@ -18,9 +18,6 @@ package org.adempiere.base; import java.util.List; -import org.compiere.model.Callout; - - /** * A service locator looks up services. * This is the central authority for adempiere service definition, @@ -33,7 +30,11 @@ import org.compiere.model.Callout; */ public interface IServiceLocator { T locate(Class type); + T locate(Class type, String id); T locate(Class type, ServiceQuery query); + T locate(Class type, String id, ServiceQuery query); List list(Class type); + List list(Class type, String id); List list(Class type, ServiceQuery query); + List list(Class type, String id, ServiceQuery query); } diff --git a/base/src/org/adempiere/base/Service.java b/base/src/org/adempiere/base/Service.java index 763c77b313..ccc6be139b 100644 --- a/base/src/org/adempiere/base/Service.java +++ b/base/src/org/adempiere/base/Service.java @@ -58,18 +58,34 @@ public class Service { } public static T locate(Class type) { - return locator().locate(type); + return locate(type, type.getName()); } + public static T locate(Class type, String id) { + return locator().locate(type, id); + } + public static T locate(Class type, ServiceQuery query) { - return locator().locate(type, query); + return locate(type, type.getName(), query); } + public static T locate(Class type, String id, ServiceQuery query) { + return locator().locate(type, id, query); + } + public static List list(Class type) { - return locator().list(type); + return list(type, type.getName()); } + public static List list(Class type, String id) { + return locator().list(type, id); + } + public static List list(Class type, ServiceQuery query) { - return locator().list(type, query); + return locator().list(type, type.getName(), query); + } + + public static List list(Class type, String id, ServiceQuery query) { + return locator().list(type, id, query); } } diff --git a/base/src/org/adempiere/base/equinox/EquinoxServiceLocator.java b/base/src/org/adempiere/base/equinox/EquinoxServiceLocator.java index fe13648039..78abb0541d 100644 --- a/base/src/org/adempiere/base/equinox/EquinoxServiceLocator.java +++ b/base/src/org/adempiere/base/equinox/EquinoxServiceLocator.java @@ -34,23 +34,43 @@ import org.adempiere.base.ServiceQuery; public class EquinoxServiceLocator implements IServiceLocator { public List list(Class type) { - ExtensionList list = new ExtensionList(type, type.getName()); + return list(type, type.getName()); + } + + @Override + public List list(Class type, String id) { + ExtensionList list = new ExtensionList(type, id); return list.asList(); } public List list(Class type, ServiceQuery query) { - ExtensionList list = new ExtensionList(type, type.getName(), query); + return list(type, type.getName(), query); + } + + @Override + public List list(Class type, String id, + ServiceQuery query) { + ExtensionList list = new ExtensionList(type, id, query); return list.asList(); } - + public T locate(Class type) { - ExtensionList list = new ExtensionList(type, type.getName()); - return list.first(); + return locate(type, type.getName()); } + @Override + public T locate(Class type, String id) { + ExtensionList list = new ExtensionList(type, id); + return list.first(); + } + public T locate(Class type, ServiceQuery query) { + return locate(type, type.getName(), query); + } + + @Override + public T locate(Class type, String id, ServiceQuery query) { ExtensionList list = new ExtensionList(type, type.getName(), query); return list.first(); - } - + } } diff --git a/base/src/org/adempiere/base/equinox/ExtensionList.java b/base/src/org/adempiere/base/equinox/ExtensionList.java index 02a2bebc7e..885c938ddd 100644 --- a/base/src/org/adempiere/base/equinox/ExtensionList.java +++ b/base/src/org/adempiere/base/equinox/ExtensionList.java @@ -22,7 +22,6 @@ import java.util.Iterator; import java.util.List; import org.adempiere.base.ServiceQuery; -import org.compiere.model.Callout; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.Platform;