01: package org.osbl.identity.gui;
02:
03: import org.osbl.identity.model.Identity;
04: import org.osbl.persistence.model.Concrete;
05: import org.osbl.persistence.*;
06: import org.osbl.ServiceProvider;
07: import org.osbl.client.ClientServiceProvider;
08: import org.osbl.plugin.*;
09: import org.conform.AbstractDynamicDomainProvider;
10:
11: import java.util.*;
12:
13: public class IdentityConcreteDomainProvider<C extends Concrete<Identity>>
14: extends AbstractDynamicDomainProvider {
15: Class<C> concreteType;
16: boolean addNull = true;
17:
18: public IdentityConcreteDomainProvider(Class<C> concreteType,
19: boolean addNull) {
20: this .concreteType = concreteType;
21: this .addNull = addNull;
22: }
23:
24: public IdentityConcreteDomainProvider(Class<C> concreteType) {
25: this .concreteType = concreteType;
26: }
27:
28: public IdentityConcreteDomainProvider(String concrete) {
29: setConcrete(concrete);
30: }
31:
32: public void setConcrete(String concrete) {
33: final PluginManager pluginManager = (PluginManager) ClientServiceProvider
34: .getInstance().getService("PluginManager");
35: final ExtensionPoint extensionPoint = new ExtensionPoint(
36: Identity.class.getName() + ".concrete", Concrete.class);
37: final List<Extension> list = pluginManager
38: .getExtensions(extensionPoint);
39:
40: for (Extension extension : list) {
41: Class<C> concreteType = (Class<C>) extension
42: .getImplementation();
43: if (concrete.equals(concreteType.getSimpleName())) {
44: this .concreteType = concreteType;
45: break;
46: }
47: }
48: }
49:
50: protected List createValues() {
51: if (concreteType == null)
52: return Collections.EMPTY_LIST;
53:
54: Persistence persistence = (Persistence) ServiceProvider
55: .getInstance().getService("IdentityPersistence");
56: SimpleQueryCommand queryCommand = (SimpleQueryCommand) persistence
57: .createCommand("list");
58: queryCommand.setType(concreteType);
59: queryCommand.addFetch("general", Fetch.JOIN);
60: List<C> concretes = queryCommand.execute();
61: List<Identity> identities = new ArrayList<Identity>(concretes
62: .size());
63: for (C concrete : concretes) {
64: identities.add(concrete.getGeneral());
65: }
66: if (addNull)
67: identities.add(0, null);
68: return identities;
69: }
70: }
|