1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.apache.ws.scout.util; |
18 | |
|
19 | |
import java.util.ArrayList; |
20 | |
import java.util.Arrays; |
21 | |
import java.util.HashMap; |
22 | |
import java.util.Map; |
23 | |
import java.util.StringTokenizer; |
24 | |
|
25 | |
import javax.xml.registry.JAXRException; |
26 | |
import javax.xml.registry.infomodel.ClassificationScheme; |
27 | |
import javax.xml.registry.infomodel.Concept; |
28 | |
|
29 | |
import org.apache.commons.logging.Log; |
30 | |
import org.apache.commons.logging.LogFactory; |
31 | |
import org.apache.ws.scout.registry.infomodel.ClassificationSchemeImpl; |
32 | |
import org.apache.ws.scout.registry.infomodel.ConceptImpl; |
33 | |
import org.apache.ws.scout.registry.infomodel.InternationalStringImpl; |
34 | |
import org.apache.ws.scout.registry.infomodel.KeyImpl; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public class EnumerationHelper |
44 | |
{ |
45 | 0 | private static Log log = LogFactory.getLog(EnumerationHelper.class); |
46 | |
|
47 | |
|
48 | |
private final static String UDDI_ORG_TYPES = "C1ACF26D-9672-4404-9D70-39B756E62AB4"; |
49 | |
private final static String OBJECT_TYPE = "ObjectType"; |
50 | |
private final static String ASSOCIATION_TYPE = "AssociationType"; |
51 | |
private final static String URL_TYPE = "URLType"; |
52 | |
private final static String PHONE_TYPE = "PhoneType"; |
53 | |
private final static String POSTAL_ADDRESS_ATTRIBUTES_STR = "PostalAddressAttributes"; |
54 | 0 | private final static String[] TYPES = {OBJECT_TYPE, ASSOCIATION_TYPE, URL_TYPE, PHONE_TYPE, POSTAL_ADDRESS_ATTRIBUTES_STR}; |
55 | |
|
56 | 0 | private final static String[] OBJECT_TYPES = { |
57 | |
"ExternalLink","Package","ExternalId","Association","Classification","Concept", |
58 | |
"AuditableEvent","User","Organization","CPA","CPP","Service","ServiceBinding","Process","WSDL", |
59 | |
"ExtrinsicObj","Organization","User"}; |
60 | 0 | private final static String[] ASSOCIATION_TYPES = { |
61 | |
"RelatedTo","ExternallyLinks","Contains","Extends","Implements", |
62 | |
"InstanceOf","Supersedes","Uses","HasMember","EquivalentTo","HasChild","HasParent","Replaces", |
63 | |
"ResponsibleFor","SubmitterOf"}; |
64 | 0 | private final static String[] URL_TYPES = { |
65 | |
"HTTP","HTTPS","SMTP","FAX","PHONE","OTHER"}; |
66 | 0 | private final static String[] PHONE_TYPES = { |
67 | |
"Office","Home","Mobile","Beeper","FAX"}; |
68 | 0 | private final static String[] POSTAL_ADDRESS_ATTRIBUTES = { |
69 | |
"StreetNumber","Street","City","State","PostalCode","Country"}; |
70 | |
|
71 | 0 | private final static ArrayList<String> TYPES_LIST = new ArrayList<String>(Arrays.asList(TYPES)); |
72 | 0 | private final static ArrayList<String> OBJECT_TYPES_LIST = new ArrayList<String>(Arrays.asList(OBJECT_TYPES)); |
73 | 0 | private final static ArrayList<String> ASSOCIATION_TYPES_LIST = new ArrayList<String>(Arrays.asList(ASSOCIATION_TYPES)); |
74 | 0 | private final static ArrayList<String> URL_TYPES_LIST = new ArrayList<String>(Arrays.asList(URL_TYPES)); |
75 | 0 | private final static ArrayList<String> PHONE_TYPES_LIST = new ArrayList<String>(Arrays.asList(PHONE_TYPES)); |
76 | 0 | private final static ArrayList<String> POSTAL_ADDRESS_ATTRIBUTES_LIST = new ArrayList<String>(Arrays.asList(POSTAL_ADDRESS_ATTRIBUTES)); |
77 | |
|
78 | 0 | private static Map<String,ArrayList<String>> typesMap = new HashMap<String,ArrayList<String>>(); |
79 | |
static { |
80 | 0 | typesMap.put(OBJECT_TYPE ,OBJECT_TYPES_LIST); |
81 | 0 | typesMap.put(ASSOCIATION_TYPE ,ASSOCIATION_TYPES_LIST); |
82 | 0 | typesMap.put(URL_TYPE , URL_TYPES_LIST); |
83 | 0 | typesMap.put(PHONE_TYPE , PHONE_TYPES_LIST); |
84 | 0 | typesMap.put(POSTAL_ADDRESS_ATTRIBUTES_STR, POSTAL_ADDRESS_ATTRIBUTES_LIST); |
85 | 0 | } |
86 | |
|
87 | |
public static Concept getConceptByPath( String path) |
88 | |
throws IllegalArgumentException, JAXRException |
89 | |
{ |
90 | |
|
91 | 0 | StringTokenizer tokenizer = new StringTokenizer(path,"/"); |
92 | 0 | String firstToken = null; |
93 | 0 | String secondToken = null; |
94 | |
|
95 | 0 | if(tokenizer.hasMoreTokens()) |
96 | |
{ |
97 | 0 | firstToken = tokenizer.nextToken(); |
98 | 0 | if (tokenizer.hasMoreTokens()) { |
99 | 0 | secondToken = tokenizer.nextToken(); |
100 | 0 | if (tokenizer.hasMoreTokens()) { |
101 | 0 | log.warn("Looking for 2 tokens. " + tokenizer.nextToken() + " will be ignored"); |
102 | |
} |
103 | |
} else { |
104 | 0 | throw new IllegalArgumentException("Expected two token separated with a forward slash (/)"); |
105 | |
} |
106 | |
} else { |
107 | 0 | throw new IllegalArgumentException("Expected two token separated with a forward slash (/)"); |
108 | |
} |
109 | 0 | return createConcept(firstToken, secondToken) ; |
110 | |
} |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
private static Concept createConcept(String firstToken, String secondToken) |
120 | |
throws JAXRException, IllegalArgumentException |
121 | |
{ |
122 | 0 | if (!TYPES_LIST.contains(firstToken)) throw new IllegalArgumentException("Expected the path to " + |
123 | |
"start with one of " + TYPES); |
124 | |
|
125 | |
|
126 | 0 | ClassificationScheme cs = new ClassificationSchemeImpl(null); |
127 | 0 | cs.setName(new InternationalStringImpl(firstToken)); |
128 | 0 | cs.setKey(new KeyImpl(firstToken)); |
129 | |
|
130 | 0 | ArrayList<String> conceptStrings = typesMap.get(firstToken); |
131 | 0 | if (!conceptStrings.contains(secondToken)) throw new IllegalArgumentException("Expected the path to " + |
132 | |
"end with one of " + conceptStrings.toArray()); |
133 | |
|
134 | 0 | Concept concept = new ConceptImpl(null); |
135 | 0 | concept.setName(new InternationalStringImpl(secondToken.toLowerCase())); |
136 | 0 | concept.setValue(secondToken); |
137 | 0 | concept.setKey(new KeyImpl(UDDI_ORG_TYPES)); |
138 | 0 | ((ConceptImpl)concept).setScheme(((ClassificationSchemeImpl)cs)); |
139 | 0 | return concept; |
140 | |
} |
141 | |
} |