1 package fr.in2p3.jsaga.engine.descriptors;
2
3 import fr.in2p3.jsaga.adaptor.base.usage.Usage;
4 import fr.in2p3.jsaga.adaptor.data.DataAdaptor;
5 import fr.in2p3.jsaga.adaptor.data.optimise.DataCopy;
6 import fr.in2p3.jsaga.adaptor.data.optimise.DataCopyDelegated;
7 import fr.in2p3.jsaga.adaptor.data.read.DataReaderAdaptor;
8 import fr.in2p3.jsaga.adaptor.data.read.LogicalReader;
9 import fr.in2p3.jsaga.adaptor.data.write.DataWriterAdaptor;
10 import fr.in2p3.jsaga.adaptor.data.write.LogicalWriter;
11 import fr.in2p3.jsaga.engine.schema.config.Protocol;
12 import org.ogf.saga.error.IncorrectURLException;
13 import org.ogf.saga.error.NoSuccessException;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18
19
20
21
22
23
24
25
26
27
28
29
30 public class DataAdaptorDescriptor {
31 private Map m_classes;
32 private Map m_usages;
33 private Map<String,Map> m_defaults;
34 protected Protocol[] m_xml;
35
36 public DataAdaptorDescriptor(Class[] adaptorClasses, SecurityAdaptorDescriptor securityDesc) throws IllegalAccessException, InstantiationException, IncorrectURLException {
37 m_classes = new HashMap();
38 m_usages = new HashMap();
39 m_defaults = new HashMap<String,Map>();
40 m_xml = new Protocol[adaptorClasses.length];
41 for (int i=0; i<adaptorClasses.length; i++) {
42 DataAdaptor adaptor = (DataAdaptor) adaptorClasses[i].newInstance();
43 if (adaptor.getType() == null) {
44 throw new InstantiationException("Bad adaptor: no type defined");
45 }
46
47
48 m_classes.put(adaptor.getType(), adaptorClasses[i]);
49
50
51 Usage usage = adaptor.getUsage();
52 if (usage != null) {
53 m_usages.put(adaptor.getType(), usage);
54 }
55
56
57 m_defaults.put(adaptor.getType(), AdaptorDescriptors.getDefaultsMap(adaptor));
58
59
60 m_xml[i] = toXML(adaptor, securityDesc);
61 }
62 }
63
64 public Class getClass(String scheme) throws NoSuccessException {
65 Class clazz = (Class) m_classes.get(scheme);
66 if (clazz != null) {
67 return clazz;
68 } else {
69 throw new NoSuccessException("Found no data adaptor supporting scheme: "+ scheme);
70 }
71 }
72
73 public Usage getUsage(String scheme) {
74 return (Usage) m_usages.get(scheme);
75 }
76
77 public Map getDefaultsMap(String scheme) {
78 return m_defaults.get(scheme);
79 }
80
81 public Protocol[] getXML() {
82 return m_xml;
83 }
84
85 private static Protocol toXML(DataAdaptor adaptor, SecurityAdaptorDescriptor securityDesc) throws IncorrectURLException {
86 Protocol protocol = new Protocol();
87 protocol.setRead(adaptor instanceof DataReaderAdaptor);
88 protocol.setWrite(adaptor instanceof DataWriterAdaptor);
89 protocol.setThirdparty(adaptor instanceof DataCopy || adaptor instanceof DataCopyDelegated);
90 protocol.setLogical(adaptor instanceof LogicalReader || adaptor instanceof LogicalWriter);
91
92
93 protocol.setType(adaptor.getType());
94 protocol.setImpl(adaptor.getClass().getName());
95 if (adaptor.getSupportedSecurityCredentialClasses() != null) {
96 String[] supportedContextTypes = securityDesc.getSupportedContextTypes(adaptor.getSupportedSecurityCredentialClasses());
97 protocol.setSupportedContextType(supportedContextTypes);
98 }
99 if (adaptor.getUsage() != null) {
100 protocol.setUsage(adaptor.getUsage().toString());
101 }
102 AdaptorDescriptors.setDefaults(protocol, adaptor);
103 return protocol;
104 }
105 }