* Make the service locator API more flexible.

This commit is contained in:
Heng Sin Low 2010-08-06 15:57:51 +08:00
parent 57c2bde1ad
commit 0f76a4264b
4 changed files with 51 additions and 15 deletions

View File

@ -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 extends IService> T locate(Class<T> type);
<T extends IService> T locate(Class<T> type, String id);
<T extends IService> T locate(Class<T> type, ServiceQuery query);
<T extends IService> T locate(Class<T> type, String id, ServiceQuery query);
<T extends IService> List<T> list(Class<T> type);
<T extends IService> List<T> list(Class<T> type, String id);
<T extends IService> List<T> list(Class<T> type, ServiceQuery query);
<T extends IService> List<T> list(Class<T> type, String id, ServiceQuery query);
}

View File

@ -58,18 +58,34 @@ public class Service {
}
public static <T extends IService> T locate(Class<T> type) {
return locator().locate(type);
return locate(type, type.getName());
}
public static <T extends IService> T locate(Class<T> type, String id) {
return locator().locate(type, id);
}
public static <T extends IService> T locate(Class<T> type, ServiceQuery query) {
return locator().locate(type, query);
return locate(type, type.getName(), query);
}
public static <T extends IService> T locate(Class<T> type, String id, ServiceQuery query) {
return locator().locate(type, id, query);
}
public static <T extends IService> List<T> list(Class<T> type) {
return locator().list(type);
return list(type, type.getName());
}
public static <T extends IService> List<T> list(Class<T> type, String id) {
return locator().list(type, id);
}
public static <T extends IService> List<T> list(Class<T> type, ServiceQuery query) {
return locator().list(type, query);
return locator().list(type, type.getName(), query);
}
public static <T extends IService> List<T> list(Class<T> type, String id, ServiceQuery query) {
return locator().list(type, id, query);
}
}

View File

@ -34,23 +34,43 @@ import org.adempiere.base.ServiceQuery;
public class EquinoxServiceLocator implements IServiceLocator {
public <T extends IService> List<T> list(Class<T> type) {
ExtensionList<T> list = new ExtensionList<T>(type, type.getName());
return list(type, type.getName());
}
@Override
public <T extends IService> List<T> list(Class<T> type, String id) {
ExtensionList<T> list = new ExtensionList<T>(type, id);
return list.asList();
}
public <T extends IService> List<T> list(Class<T> type, ServiceQuery query) {
ExtensionList<T> list = new ExtensionList<T>(type, type.getName(), query);
return list(type, type.getName(), query);
}
@Override
public <T extends IService> List<T> list(Class<T> type, String id,
ServiceQuery query) {
ExtensionList<T> list = new ExtensionList<T>(type, id, query);
return list.asList();
}
public <T extends IService> T locate(Class<T> type) {
ExtensionList<T> list = new ExtensionList<T>(type, type.getName());
return list.first();
return locate(type, type.getName());
}
@Override
public <T extends IService> T locate(Class<T> type, String id) {
ExtensionList<T> list = new ExtensionList<T>(type, id);
return list.first();
}
public <T extends IService> T locate(Class<T> type, ServiceQuery query) {
return locate(type, type.getName(), query);
}
@Override
public <T extends IService> T locate(Class<T> type, String id, ServiceQuery query) {
ExtensionList<T> list = new ExtensionList<T>(type, type.getName(), query);
return list.first();
}
}
}

View File

@ -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;