01: package org.osbl.client;
02:
03: import org.osbl.client.ClientServiceProvider;
04:
05: import javax.naming.*;
06: import java.util.ArrayList;
07: import java.util.List;
08:
09: public class DefaultServiceProvider extends ClientServiceProvider {
10: public List<String> getServiceNames() {
11: try {
12: InitialContext ctx = new InitialContext();
13: NamingEnumeration<NameClassPair> namingEnumeration = ctx
14: .list("services/");
15: List<String> names = new ArrayList<String>();
16: while (namingEnumeration.hasMoreElements()) {
17: NameClassPair nameClassPair = namingEnumeration
18: .nextElement();
19: names.add(nameClassPair.getName());
20: }
21: return names;
22: } catch (NamingException e) {
23: throw new RuntimeException(e);
24: }
25: }
26:
27: public Object getService(String name) {
28: try {
29: InitialContext ctx = new InitialContext();
30: return ctx.lookup("services/" + name + "/local");
31: } catch (NamingException e) {
32: throw new RuntimeException(e);
33: }
34: }
35:
36: public <T> T getService(Class<T> type) {
37: return (T) getService(type.getSimpleName());
38: }
39:
40: public void autowireServices(Object bean) {
41: throw new UnsupportedOperationException();
42: }
43: }
|