This project has retired. For details please refer to its Attic page.
Builders xref
View Javadoc
1   /*
2    * Copyright 2001-2013 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  package org.apache.juddi.webconsole.hub.builders;
18  
19  import java.text.DateFormat;
20  import java.text.SimpleDateFormat;
21  import java.util.ArrayList;
22  import java.util.Date;
23  import java.util.GregorianCalendar;
24  import java.util.HashMap;
25  import java.util.Iterator;
26  import java.util.List;
27  import java.util.Map;
28  import java.util.concurrent.atomic.AtomicReference;
29  import java.util.regex.Matcher;
30  import java.util.regex.Pattern;
31  import javax.servlet.http.HttpSession;
32  import javax.xml.datatype.DatatypeFactory;
33  import org.apache.juddi.webconsole.PostBackConstants;
34  import org.apache.juddi.webconsole.hub.UddiHub;
35  import org.apache.juddi.webconsole.resources.ResourceLoader;
36  import org.uddi.api_v3.*;
37  import org.uddi.sub_v3.Subscription;
38  import org.uddi.sub_v3.SubscriptionFilter;
39  
40  /**
41   * This class provides functions for building UDDI entities from Http request
42   * parameters
43   *
44   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
45   */
46  public class Builders {
47  
48          /**
49           * important - regex to separate postback names from indexes, do not
50           * remove or alter
51           */
52          static final Pattern p = Pattern.compile("[a-zA-Z]");
53  
54          /**
55           * Returns a new map, filtering the original map by key string starts
56           * with
57           *
58           * @param map
59           * @param pattern
60           * @return filtered map
61           */
62          public static Map MapFilter(Map map, String pattern) {
63                  Map ret = new HashMap();
64                  Iterator it = map.keySet().iterator();
65                  while (it.hasNext()) {
66                          String key = (String) it.next();
67                          if (key.startsWith(pattern)) {
68                                  ret.put(key, map.get(key));
69                          }
70                  }
71                  return ret;
72          }
73  
74          /**
75           * Prefix should be contactXName
76           *
77           * @param map
78           * @param prefix
79           * @return list
80           */
81          public static List<PersonName> BuildContactPersonNames(Map map, String prefix, String cte, String locale) {
82                  List<PersonName> ret = new ArrayList();
83                  Iterator it = map.keySet().iterator();
84                  List<String> processedIndexes = new ArrayList<String>();
85                  while (it.hasNext()) {
86                          String key = (String) it.next();
87                          String filteredkey = key.replace(prefix, "");
88                          Matcher match = p.matcher(filteredkey);
89                          if (match.find()) {
90                                  String index = filteredkey.substring(0, match.start());
91                                  if (!processedIndexes.contains(index)) {
92                                          PersonName pn = new PersonName();
93                                          String[] t = (String[]) map.get(prefix + index + PostBackConstants.LANG);
94                                          if (t[0] == null || t[0].equalsIgnoreCase(cte)) {
95                                                  pn.setLang(null);
96                                          } else {
97                                                  pn.setLang(t[0]);
98                                          }
99                                          t = (String[]) map.get(prefix + index + PostBackConstants.VALUE);
100                                         pn.setValue(t[0]);
101                                         ret.add(pn);
102                                         processedIndexes.add(index);
103                                 }
104                         } else {
105                                 throw new IllegalArgumentException(ResourceLoader.GetResource(locale, "errors.invaliddata"));
106                         }
107                 }
108                 return ret;
109         }
110 
111         /**
112          * overview docs
113          *
114          * @param map
115          * @param prefix
116          * @param cte
117          * @return list
118          */
119         public static List<OverviewDoc> BuildOverviewDocs(Map map, String prefix, String cte, String locale) {
120                 List<OverviewDoc> ret = new ArrayList<OverviewDoc>();
121                 Iterator it = map.keySet().iterator();
122                 List<String> processedIndexes = new ArrayList<String>();
123                 while (it.hasNext()) {
124                         String key = (String) it.next();
125                         String filteredkey = key.replace(prefix, "");
126                         Matcher match = p.matcher(filteredkey);
127                         if (match.find()) {
128                                 String index = filteredkey.substring(0, match.start());
129                                 if (!processedIndexes.contains(index)) {
130                                         OverviewDoc pn = new OverviewDoc();
131                                         pn.setOverviewURL(new OverviewURL());
132                                         String[] t = (String[]) map.get(prefix + index + PostBackConstants.VALUE);
133                                         pn.getOverviewURL().setValue(t[0]);
134                                         t = (String[]) map.get(prefix + index + PostBackConstants.TYPE);
135                                         pn.getOverviewURL().setUseType(t[0]);
136                                         pn.getDescription().addAll(BuildDescription(MapFilter(map, prefix + index + PostBackConstants.DESCRIPTION), prefix + index + PostBackConstants.DESCRIPTION, cte, locale));
137                                         ret.add(pn);
138                                         processedIndexes.add(index);
139                                 }
140                         } else {
141                                 throw new IllegalArgumentException(ResourceLoader.GetResource(locale, "errors.invaliddata"));
142                         }
143                 }
144                 return ret;
145         }
146 
147         /**
148          * phone numbers
149          *
150          * @param map
151          * @param prefix
152          * @return list
153          */
154         public static List<Phone> BuildPhone(Map map, String prefix, String locale) {
155                 List<Phone> ret = new ArrayList();
156                 Iterator it = map.keySet().iterator();
157                 List<String> processedIndexes = new ArrayList<String>();
158                 while (it.hasNext()) {
159                         String key = (String) it.next();
160                         String filteredkey = key.replace(prefix, "");
161                         Matcher match = p.matcher(filteredkey);
162                         if (match.find()) {
163                                 String index = filteredkey.substring(0, match.start());
164                                 if (!processedIndexes.contains(index)) {
165                                         Phone pn = new Phone();
166                                         String[] t = (String[]) map.get(prefix + index + PostBackConstants.TYPE);
167                                         pn.setUseType(t[0]);
168                                         t = (String[]) map.get(prefix + index + PostBackConstants.VALUE);
169                                         pn.setValue(t[0]);
170                                         ret.add(pn);
171                                         processedIndexes.add(index);
172                                 }
173                         } else {
174                                 throw new IllegalArgumentException(ResourceLoader.GetResource(locale, "errors.invaliddata"));
175                         }
176                 }
177                 return ret;
178         }
179 
180         /**
181          * builds a contact
182          *
183          * @param m
184          * @param prefix
185          * @param cte
186          * @return contact
187          */
188         public static Contact BuildSingleContact(Map m, String prefix, String cte, String locale) {
189                 Contact c = new Contact();
190                 String[] t = (String[]) m.get(prefix + PostBackConstants.TYPE);
191                 c.setUseType(t[0]);
192                 c.getPersonName().addAll(BuildContactPersonNames(MapFilter(m, prefix + PostBackConstants.NAME), prefix + PostBackConstants.NAME, cte, locale));
193                 c.getDescription().addAll(BuildDescription(MapFilter(m, prefix + PostBackConstants.DESCRIPTION), prefix + PostBackConstants.DESCRIPTION, cte, locale));
194                 c.getEmail().addAll(BuildEmail(MapFilter(m, prefix + PostBackConstants.EMAIL), prefix + PostBackConstants.EMAIL, locale));
195                 c.getPhone().addAll(BuildPhone(MapFilter(m, prefix + PostBackConstants.PHONE), prefix + PostBackConstants.PHONE, locale));
196                 c.getAddress().addAll(BuildAddress(MapFilter(m, prefix + PostBackConstants.ADDRESS), prefix + PostBackConstants.ADDRESS, cte, locale));
197                 return c;
198         }
199 
200         /**
201          * name elements
202          *
203          * @param map
204          * @param prefix
205          * @param cte
206          * @return list
207          */
208         public static List<Name> BuildNames(Map map, String prefix, String cte, String locale) {
209                 List<Name> ret = new ArrayList();
210                 Iterator it = map.keySet().iterator();
211                 List<String> processedIndexes = new ArrayList<String>();
212                 while (it.hasNext()) {
213                         String key = (String) it.next();
214                         String filteredkey = key.replace(prefix, "");
215                         Matcher match = p.matcher(filteredkey);
216                         if (match.find()) {
217                                 String index = filteredkey.substring(0, match.start());
218                                 if (!processedIndexes.contains(index)) {
219                                         Name pn = new Name();
220                                         String[] t = (String[]) map.get(prefix + index + PostBackConstants.LANG);
221                                         if (t[0].equalsIgnoreCase(cte)) {
222                                                 pn.setLang(null);
223                                         } else {
224                                                 pn.setLang(t[0]);
225                                         }
226                                         t = (String[]) map.get(prefix + index + PostBackConstants.VALUE);
227                                         pn.setValue(t[0]);
228                                         ret.add(pn);
229                                         processedIndexes.add(index);
230                                 }
231                         } else {
232                                 throw new IllegalArgumentException(ResourceLoader.GetResource(locale, "errors.invaliddata"));
233                         }
234                 }
235                 return ret;
236         }
237 
238         /**
239          * builds a compelte category bag
240          *
241          * @param map
242          * @param prefix
243          * @return catbag
244          */
245         public static CategoryBag BuildCatBag(Map map, String prefix, String locale) {
246                 CategoryBag ret = new CategoryBag();
247                 Iterator it = map.keySet().iterator();
248                 List<String> processedIndexes = new ArrayList<String>();
249                 while (it.hasNext()) {
250                         String key = (String) it.next();
251                         String filteredkey = key.replace(prefix, "");
252                         Matcher match = p.matcher(filteredkey);
253                         if (match.find()) {
254                                 String index = filteredkey.substring(0, match.start());
255                                 if (!processedIndexes.contains(index)) {
256                                         KeyedReference pn = new KeyedReference();
257                                         String[] t = (String[]) map.get(prefix + index + PostBackConstants.VALUE);
258                                         pn.setTModelKey(t[0]);
259                                         t = (String[]) map.get(prefix + index + PostBackConstants.KEYNAME);
260                                         pn.setKeyName(t[0]);
261                                         t = (String[]) map.get(prefix + index + PostBackConstants.KEYVALUE);
262                                         pn.setKeyValue(t[0]);
263                                         ret.getKeyedReference().add(pn);
264                                         processedIndexes.add(index);
265                                 }
266                         } else {
267                                 throw new IllegalArgumentException(ResourceLoader.GetResource(locale, "errors.invaliddata"));
268                         }
269                 }
270                 return ret;
271         }
272 
273         /**
274          * identifier bag
275          *
276          * @param map
277          * @param prefix
278          * @param locale
279          * @return identbag
280          */
281         public static IdentifierBag BuildIdentBag(Map map, String prefix, String locale) {
282                 IdentifierBag ret = new IdentifierBag();
283                 ret.getKeyedReference().addAll(BuildKeyedReference(map, prefix, locale));
284                 if (ret.getKeyedReference().isEmpty()) {
285                         return null;
286                 }
287                 return ret;
288         }
289 
290         /**
291          * discovery urls
292          *
293          * @param map
294          * @param prefix
295          * @param locale
296          * @return disco urls
297          */
298         public static DiscoveryURLs BuildDisco(Map map, String prefix, String locale) {
299                 DiscoveryURLs list = new DiscoveryURLs();
300                 Iterator it = map.keySet().iterator();
301                 List<String> processedIndexes = new ArrayList<String>();
302                 while (it.hasNext()) {
303                         String key = (String) it.next();
304                         String filteredkey = key.replace(prefix, "");
305                         Matcher match = p.matcher(filteredkey);
306                         if (match.find()) {
307                                 String index = filteredkey.substring(0, match.start());
308                                 if (!processedIndexes.contains(index)) {
309                                         DiscoveryURL pn = new DiscoveryURL();
310                                         String[] t = (String[]) map.get(prefix + index + PostBackConstants.TYPE);
311                                         pn.setUseType(t[0]);
312                                         t = (String[]) map.get(prefix + index + PostBackConstants.VALUE);
313                                         pn.setValue(t[0]);
314                                         list.getDiscoveryURL().add(pn);
315                                         processedIndexes.add(index);
316                                 }
317                         } else {
318                                 throw new IllegalArgumentException(ResourceLoader.GetResource(locale, "errors.invaliddata"));
319                         }
320                 }
321                 if (list.getDiscoveryURL().isEmpty()) {
322                         return null;
323                 }
324                 return list;
325         }
326 
327         /**
328          * addresses
329          *
330          * @param map
331          * @param prefix
332          * @param cte Localized "Click to edit"
333          * @return list
334          */
335         public static List<Address> BuildAddress(Map map, String prefix, String cte, String locale) {
336                 List<Address> ret = new ArrayList();
337                 Iterator it = map.keySet().iterator();
338                 List<String> processedIndexes = new ArrayList<String>();
339                 while (it.hasNext()) {
340                         String key = (String) it.next();
341                         String filteredkey = key.replace(prefix, "");
342                         Matcher match = p.matcher(filteredkey);
343                         if (match.find()) {
344                                 String index = filteredkey.substring(0, match.start());
345                                 if (!processedIndexes.contains(index)) {
346                                         Address pn = new Address();
347                                         String[] t = (String[]) map.get(prefix + index + PostBackConstants.LANG);
348                                         if (t[0] == null || t[0].equalsIgnoreCase(cte)) {
349                                                 pn.setLang(null);
350                                         } else {
351                                                 pn.setLang(t[0]);
352                                         }
353                                         t = (String[]) map.get(prefix + index + PostBackConstants.TYPE);
354                                         if (t[0] == null || t[0].equalsIgnoreCase(cte)) {
355                                                 pn.setUseType(null);
356                                         } else {
357                                                 pn.setUseType(t[0]);
358                                         }
359                                         t = (String[]) map.get(prefix + index + PostBackConstants.SORTCODE);
360                                         if (t[0] == null || t[0].equalsIgnoreCase(cte)) {
361                                                 pn.setSortCode(null);
362                                         } else {
363                                                 pn.setSortCode(t[0]);
364                                         }
365                                         t = (String[]) map.get(prefix + index + PostBackConstants.KEYNAME);
366                                         if (t[0] == null || t[0].equalsIgnoreCase(cte)) {
367                                                 pn.setTModelKey(null);
368                                         } else {
369                                                 pn.setTModelKey(t[0]);
370                                         }
371                                         pn.getAddressLine().addAll(BuildAddressLine(MapFilter(map, prefix + index + PostBackConstants.ADDRESSLINE), prefix + index + PostBackConstants.ADDRESSLINE, cte,locale));
372                                         ret.add(pn);
373                                         processedIndexes.add(index);
374                                 }
375                         } else {
376                                 throw new IllegalArgumentException(ResourceLoader.GetResource(locale, "errors.invaliddata"));
377                         }
378                 }
379                 return ret;
380         }
381 
382         /**
383          * keyed reference group
384          *
385          * @param map
386          * @param prefix
387          * @return list
388          */
389         public static List<KeyedReferenceGroup> BuildKeyedReferenceGroup(Map map, String prefix, String locale) {
390                 List<KeyedReferenceGroup> ret = new ArrayList<KeyedReferenceGroup>();
391                 Iterator it = map.keySet().iterator();
392                 List<String> processedIndexes = new ArrayList<String>();
393                 while (it.hasNext()) {
394                         String key = (String) it.next();
395                         String filteredkey = key.replace(prefix, "");
396                         Matcher match = p.matcher(filteredkey);
397                         if (match.find()) {
398                                 String index = filteredkey.substring(0, match.start());
399                                 if (!processedIndexes.contains(index)) {
400                                         KeyedReferenceGroup pn = new KeyedReferenceGroup();
401                                         String[] t = (String[]) map.get(prefix + index + PostBackConstants.VALUE);
402                                         if (t != null) {
403                                                 pn.setTModelKey(t[0]);
404                                                 pn.getKeyedReference().addAll(BuildKeyedReference(MapFilter(map, prefix + index + PostBackConstants.KEY_REF), prefix + index + PostBackConstants.KEY_REF, locale));
405                                                 ret.add(pn);
406                                         } else {
407                                                 UddiHub.log.warn("Unexpected null from BuildKeyedReferenceGroup " + filteredkey + " " + prefix + " " + key);
408                                         }
409                                         processedIndexes.add(index);
410                                 }
411                         } else {
412                                 throw new IllegalArgumentException(ResourceLoader.GetResource(locale, "errors.invaliddata"));
413                         }
414                 }
415                 return ret;
416         }
417 
418         /**
419          * contactX
420          *
421          * @param map
422          * @return contacts
423          */
424         public static Contacts BuildContacts(Map map, String cte, String locale) {
425                 Contacts cb = new Contacts();
426                 Map contactdata = MapFilter(map, PostBackConstants.CONTACT_PREFIX);
427                 Iterator it = contactdata.keySet().iterator();
428                 List<String> processedIndexes = new ArrayList<String>();
429                 while (it.hasNext()) {
430                         String key = (String) it.next();
431                         key = key.replace(PostBackConstants.CONTACT_PREFIX, "");
432                         Matcher match = p.matcher(key);
433                         if (match.find()) {
434                                 String index = key.substring(0, match.start());
435                                 if (!processedIndexes.contains(index)) {
436                                         cb.getContact().add(BuildSingleContact(MapFilter(contactdata, PostBackConstants.CONTACT_PREFIX + index), PostBackConstants.CONTACT_PREFIX + index, cte, locale));
437                                         processedIndexes.add(index);
438                                 }
439                         } else {
440                                 throw new IllegalArgumentException(ResourceLoader.GetResource(locale, "errors.invaliddata"));
441                         }
442                 }
443                 if (cb.getContact().isEmpty()) {
444                         return null;
445                 }
446                 return cb;
447         }
448 
449         /**
450          * email
451          *
452          * @param map
453          * @param prefix
454          * @return list
455          */
456         public static List<Email> BuildEmail(Map map, String prefix, String locale) {
457                 List<Email> list = new ArrayList<Email>();
458                 Iterator it = map.keySet().iterator();
459                 List<String> processedIndexes = new ArrayList<String>();
460                 while (it.hasNext()) {
461                         String key = (String) it.next();
462                         String filteredkey = key.replace(prefix, "");
463                         Matcher match = p.matcher(filteredkey);
464                         if (match.find()) {
465                                 String index = filteredkey.substring(0, match.start());
466                                 if (!processedIndexes.contains(index)) {
467                                         Email pn = new Email();
468                                         String[] t = (String[]) map.get(prefix + index + PostBackConstants.TYPE);
469                                         pn.setUseType(t[0]);
470                                         t = (String[]) map.get(prefix + index + PostBackConstants.VALUE);
471                                         pn.setValue(t[0]);
472                                         list.add(pn);
473                                         processedIndexes.add(index);
474                                 }
475                         } else {
476                                 throw new IllegalArgumentException(ResourceLoader.GetResource(locale, "errors.invaliddata"));
477                         }
478                 }
479                 return list;
480         }
481 
482         /**
483          * description
484          *
485          * @param map
486          * @param prefix
487          * @param cte click to edit constant
488          * @param locale
489          * @return list
490          */
491         public static List<Description> BuildDescription(Map map, String prefix, String cte, String locale) {
492                 List<Description> ret = new ArrayList();
493                 Iterator it = map.keySet().iterator();
494                 List<String> processedIndexes = new ArrayList<String>();
495                 while (it.hasNext()) {
496                         String key = (String) it.next();
497                         String filteredkey = key.replace(prefix, "");
498                         Matcher match = p.matcher(filteredkey);
499                         if (match.find()) {
500                                 String index = filteredkey.substring(0, match.start());
501                                 if (!processedIndexes.contains(index)) {
502                                         Description pn = new Description();
503                                         String[] t = (String[]) map.get(prefix + index + PostBackConstants.LANG);
504                                         if (t[0] == null || t[0].equalsIgnoreCase(cte)) {
505                                                 pn.setLang(null);
506                                         } else {
507                                                 pn.setLang(t[0]);
508                                         }
509                                         t = (String[]) map.get(prefix + index + PostBackConstants.VALUE);
510                                         pn.setValue(t[0]);
511                                         ret.add(pn);
512                                         processedIndexes.add(index);
513                                 }
514                         } else {
515                                 throw new IllegalArgumentException(ResourceLoader.GetResource(locale, "errors.invaliddata"));
516                         }
517                 }
518                 return ret;
519         }
520 
521         /**
522          * keyed references
523          *
524          * @param map
525          * @param prefix
526          * @return list
527          */
528         public static List<KeyedReference> BuildKeyedReference(Map map, String prefix, String locale) {
529                 List<KeyedReference> ret = new ArrayList<KeyedReference>();
530                 Iterator it = map.keySet().iterator();
531                 List<String> processedIndexes = new ArrayList<String>();
532                 while (it.hasNext()) {
533                         String key = (String) it.next();
534                         String filteredkey = key.replace(prefix, "");
535                         Matcher match = p.matcher(filteredkey);
536                         if (match.find()) {
537                                 String index = filteredkey.substring(0, match.start());
538                                 if (!processedIndexes.contains(index)) {
539                                         KeyedReference pn = new KeyedReference();
540                                         String[] t = (String[]) map.get(prefix + index + PostBackConstants.VALUE);
541                                         if (t != null) {
542                                                 pn.setTModelKey(t[0]);
543                                                 t = (String[]) map.get(prefix + index + PostBackConstants.KEYNAME);
544                                                 pn.setKeyName(t[0]);
545                                                 t = (String[]) map.get(prefix + index + PostBackConstants.KEYVALUE);
546                                                 pn.setKeyValue(t[0]);
547                                                 ret.add(pn);
548                                         }
549                                         processedIndexes.add(index);
550                                 }
551                         } else {
552                                 throw new IllegalArgumentException(ResourceLoader.GetResource(locale, "errors.invaliddata"));
553                         }
554                 }
555                 return ret;
556         }
557 
558         /**
559          * address lines
560          *
561          * @param map
562          * @param prefix
563          * @param cte localized Click to edit
564          * @param locale
565          * @return list
566          */
567         public static List<AddressLine> BuildAddressLine(Map map, String prefix, String cte, String locale) {
568                 List<AddressLine> ret = new ArrayList();
569                 Iterator it = map.keySet().iterator();
570                 List<String> processedIndexes = new ArrayList<String>();
571                 while (it.hasNext()) {
572                         String key = (String) it.next();
573                         String filteredkey = key.replace(prefix, "");
574                         Matcher match = p.matcher(filteredkey);
575                         if (match.find()) {
576                                 String index = filteredkey.substring(0, match.start());
577                                 if (!processedIndexes.contains(index)) {
578                                         AddressLine pn = new AddressLine();
579                                         String[] t = (String[]) map.get(prefix + index + PostBackConstants.VALUE);
580                                         pn.setValue(t[0]);
581                                         t = (String[]) map.get(prefix + index + PostBackConstants.KEYNAME);
582                                         if (t != null && t.length > 0 && !cte.equalsIgnoreCase(t[0])) {
583                                                 pn.setKeyName(t[0]);
584                                         }
585                                         t = (String[]) map.get(prefix + index + PostBackConstants.KEYVALUE);
586                                         if (t != null && t.length > 0 && !cte.equalsIgnoreCase(t[0])) {
587                                                 pn.setKeyValue(t[0]);
588                                         }
589                                         ret.add(pn);
590                                         processedIndexes.add(index);
591                                 }
592                         } else {
593                                 throw new IllegalArgumentException(ResourceLoader.GetResource(locale, "errors.invaliddata"));
594                         }
595                 }
596                 return ret;
597         }
598 
599         /**
600          * binding templates
601          *
602          * @param map
603          * @param prefix
604          * @param cte click to edit constant
605          * @return list
606          */
607         public static List<BindingTemplate> BuildBindingTemplates(Map map, String prefix, String cte, String locale) {
608                 List<BindingTemplate> ret = new ArrayList();
609                 Iterator it = map.keySet().iterator();
610                 List<String> processedIndexes = new ArrayList<String>();
611                 while (it.hasNext()) {
612                         String key = (String) it.next();
613                         String filteredkey = key.replace(prefix, "");
614                         Matcher match = p.matcher(filteredkey);
615                         if (match.find()) {
616                                 String index = filteredkey.substring(0, match.start());
617                                 if (!processedIndexes.contains(index)) {
618                                         BindingTemplate pn = new BindingTemplate();
619 //bindingTemplate0Value
620                                         String[] t = (String[]) map.get(prefix + index + PostBackConstants.VALUE);
621                                         if (t != null && t.length > 0) {
622                                                 pn.setBindingKey(t[0]);
623                                                 if (pn.getBindingKey().equalsIgnoreCase(ResourceLoader.GetResource(locale, "items.clicktoedit"))) {
624                                                         pn.setBindingKey(null);
625                                                 }
626                                         }
627 
628                                         t = (String[]) map.get(prefix + index + PostBackConstants.HOSTINGREDIRECTOR);
629                                         if (t != null && t.length > 0) {
630                                                 pn.setHostingRedirector(new HostingRedirector());
631                                                 pn.getHostingRedirector().setBindingKey(t[0]);
632                                         }
633                                         AccessPoint ap = new AccessPoint();
634                                         t = (String[]) map.get(prefix + index + PostBackConstants.ACCESSPOINT_TYPE);
635                                         if (t != null && t.length > 0) {
636                                                 ap.setUseType(t[0]);
637                                         }
638                                         t = (String[]) map.get(prefix + index + PostBackConstants.ACCESSPOINT_VALUE);
639                                         if (t != null && t.length > 0) {
640                                                 ap.setValue(t[0]);
641                                         }
642                                         if (ap.getValue() != null) {
643                                                 pn.setAccessPoint(ap);
644                                         }
645                                         pn.getDescription().addAll(BuildDescription(MapFilter(map, prefix + index + PostBackConstants.DESCRIPTION), prefix + index + PostBackConstants.DESCRIPTION, cte, locale));
646                                         CategoryBag cb = new CategoryBag();
647                                         cb.getKeyedReference().addAll(BuildKeyedReference(MapFilter(map, prefix + index + PostBackConstants.CATBAG_KEY_REF), prefix + index + PostBackConstants.CATBAG_KEY_REF, locale));
648                                         cb.getKeyedReferenceGroup().addAll(BuildKeyedReferenceGroup(MapFilter(map, prefix + index + PostBackConstants.CATBAG_KEY_REF_GRP), prefix + index + PostBackConstants.CATBAG_KEY_REF_GRP, locale));
649                                         if (cb.getKeyedReference().isEmpty() && cb.getKeyedReferenceGroup().isEmpty()) {
650                                                 cb = null;
651                                         }
652 
653                                         pn.setCategoryBag(cb);
654                                         pn.setTModelInstanceDetails(BuildTmodelInstanceDetails(MapFilter(map, prefix + index + PostBackConstants.TMODELINSTANCE), prefix + index + PostBackConstants.TMODELINSTANCE, cte, locale));
655 
656                                         ret.add(pn);
657                                         processedIndexes.add(index);
658                                 }
659                         } else {
660                                 throw new IllegalArgumentException(ResourceLoader.GetResource(locale, "errors.invaliddata"));
661                         }
662                 }
663                 return ret;
664         }
665 
666         public static TModelInstanceDetails BuildTmodelInstanceDetails(Map map, String prefix, String cte, String locale) {
667                 TModelInstanceDetails ret = new TModelInstanceDetails();
668 
669                 Iterator it = map.keySet().iterator();
670                 List<String> processedIndexes = new ArrayList<String>();
671                 while (it.hasNext()) {
672                         String key = (String) it.next();
673                         String filteredkey = key.replace(prefix, "");
674                         Matcher match = p.matcher(filteredkey);
675                         if (match.find()) {
676                                 String index = filteredkey.substring(0, match.start());
677                                 if (!processedIndexes.contains(index)) {
678                                         TModelInstanceInfo tmi = new TModelInstanceInfo();
679                                         String[] t = (String[]) map.get(prefix + index + PostBackConstants.KEYNAME);
680                                         if (t != null && t.length > 0) {
681                                                 tmi.setTModelKey(t[0]);
682                                         }
683 
684                                         tmi.setInstanceDetails(BuildInstanceDetails(MapFilter(map, prefix + index + PostBackConstants.INSTANCE), prefix + index + PostBackConstants.INSTANCE, cte, locale));
685 
686                                         tmi.getDescription().addAll(BuildDescription(MapFilter(map, prefix + index + PostBackConstants.INSTANCE + PostBackConstants.DESCRIPTION), prefix + index + PostBackConstants.INSTANCE + PostBackConstants.DESCRIPTION, cte, locale));
687 
688                                         ret.getTModelInstanceInfo().add(tmi);
689                                         processedIndexes.add(index);
690                                 }
691                         } else {
692                                 throw new IllegalArgumentException(ResourceLoader.GetResource(locale, "errors.invaliddata"));
693                         }
694                 }
695                 if (ret.getTModelInstanceInfo().isEmpty()) {
696                         return null;
697                 }
698                 return ret;
699         }
700 
701         private static InstanceDetails BuildInstanceDetails(Map map, String prefix, String cte, String locale) {
702                 InstanceDetails ret = new InstanceDetails();
703                 Iterator it = map.keySet().iterator();
704                 List<String> processedIndexes = new ArrayList<String>();
705                 while (it.hasNext()) {
706                         String key = (String) it.next();
707                         String filteredkey = key.replace(prefix, "");
708                         Matcher match = p.matcher(filteredkey);
709                         if (match.find()) {
710                                 String index = filteredkey.substring(0, match.start());
711                                 if (!processedIndexes.contains(index)) {
712 
713                                         String[] t = (String[]) map.get(prefix + index + PostBackConstants.VALUE);
714                                         //pn.setValue(t[0]);
715                                         if (t != null && t.length > 0) {
716                                                 ret.setInstanceParms(t[0]);
717                                         }
718                                         if (cte.equalsIgnoreCase(ret.getInstanceParms())) {
719                                                 ret.setInstanceParms(null);
720                                         }
721 
722                                         ret.getDescription().addAll(BuildDescription(MapFilter(map, prefix + index + PostBackConstants.INSTANCE + PostBackConstants.DESCRIPTION), prefix + index + PostBackConstants.INSTANCE + PostBackConstants.DESCRIPTION, cte, locale));
723                                         ret.getOverviewDoc().addAll(BuildOverviewDocs(MapFilter(map, prefix + index + PostBackConstants.OVERVIEW), prefix + index + PostBackConstants.OVERVIEW, cte, locale));
724 
725                                         processedIndexes.add(index);
726                                 }
727                         } else {
728                                 throw new IllegalArgumentException(ResourceLoader.GetResource(locale, "errors.invaliddata"));
729                         }
730                 }
731                 if (ret.getInstanceParms() == null
732                      && ret.getDescription().isEmpty()
733                      && ret.getOverviewDoc().isEmpty()) {
734                         return null;
735                 }
736                 return ret;
737         }
738 
739         /**
740          * client subscription api
741          *
742          * @param map
743          * @param outmsg
744          * @param session
745          * @return subscription
746          */
747         public static Subscription BuildClientSubscription(Map map, AtomicReference<String> outmsg, HttpSession session) {
748                 Subscription sub = new Subscription();
749                 if (outmsg == null) {
750                         outmsg = new AtomicReference<String>();
751                 }
752 
753                 try {
754                         String alertType = ((String[]) map.get("alertType"))[0];
755                         if (alertType == null) {
756                                 outmsg.set(ResourceLoader.GetResource(session, "errors.subscription.alerttypeinvalid"));
757                                 return null;
758                         }
759                         if (alertType.equalsIgnoreCase("specificItem")) {
760                                 sub = BuildClientSubscriptionSpecificItem(map, outmsg, (String) session.getAttribute("locale"));
761                         } else if (alertType.equalsIgnoreCase("searchResults")) {
762                                 sub = BuildClientSubscriptionSearchResults(map, outmsg, session);
763                         } else {
764                                 outmsg.set(ResourceLoader.GetResource(session, "errors.subscription.alerttypeinvalid"));
765                                 return null;
766                         }
767                         if (sub == null) {
768                                 return null;
769                         }
770 
771                         String alertTransport = ((String[]) map.get("alertTransport"))[0];
772                         if (alertTransport == null) {
773                         } else {
774                                 if (alertTransport.equalsIgnoreCase("bindingTemplate")) {
775                                         sub.setBindingKey(((String[]) map.get("bindingKey"))[0]);
776                                 } else {
777                                         sub.setBindingKey(null);
778                                 }
779                         }
780                         if (map.get("subkey") != null) {
781                                 String subkey = ((String[]) map.get("subkey"))[0];
782                                 if (subkey != null && !subkey.equalsIgnoreCase(ResourceLoader.GetResource(session, "items.clicktoedit"))) {
783                                         sub.setSubscriptionKey(subkey);
784                                 }
785                         }
786                         //options
787                         sub = BuildSubscriptionOptions(map, sub);
788                         return sub;
789                 } catch (Exception ex) {
790                         outmsg.set(ex.getMessage());
791                         return null;
792                 }
793 
794         }
795 
796         private static Subscription BuildClientSubscriptionSpecificItem(Map map, AtomicReference<String> outmsg, String locale) {
797                 try {
798                         Subscription sub = new Subscription();
799                         String alertCritera = ((String[]) map.get("alertCriteraSingleItem"))[0];
800 
801                         List<String> keys = new ArrayList<String>();
802                         String ItemKey = ((String[]) map.get("itemKey"))[0];
803                         if (ItemKey == null) {
804                                 outmsg.set("no item defined");
805                                 return null;
806                         }
807                         //TODO this is an issue. Unknown if commas can be included within UDDI keys
808                         if (ItemKey.contains(",")) {
809                                 String[] k2 = ItemKey.split(",");
810                                 for (int i = 0; i < k2.length; i++) {
811                                         if (k2[i] == null) {
812                                                 continue;
813                                         }
814                                         if (k2[i].trim().isEmpty()) {
815                                                 continue;
816                                         }
817                                         keys.add(k2[i].trim());
818                                 }
819                         } else {
820                                 keys.add(ItemKey);
821                         }
822 
823                         sub.setSubscriptionFilter(new SubscriptionFilter());
824 
825                         if (alertCritera != null) {
826 
827                                 if (alertCritera.equalsIgnoreCase("binding")) {
828                                         sub.getSubscriptionFilter().setGetBindingDetail(new GetBindingDetail());
829                                         sub.getSubscriptionFilter().getGetBindingDetail().getBindingKey().addAll(keys);
830                                 } else if (alertCritera.equalsIgnoreCase("service")) {
831                                         sub.getSubscriptionFilter().setGetServiceDetail(new GetServiceDetail());
832                                         sub.getSubscriptionFilter().getGetServiceDetail().getServiceKey().addAll(keys);
833                                 } else if (alertCritera.equalsIgnoreCase("business")) {
834                                         sub.getSubscriptionFilter().setGetBusinessDetail(new GetBusinessDetail());
835                                         sub.getSubscriptionFilter().getGetBusinessDetail().getBusinessKey().addAll(keys);
836                                 } else if (alertCritera.equalsIgnoreCase("publisherAssertion")) {
837                                         //unknow if this will work
838                                         sub.getSubscriptionFilter().setGetAssertionStatusReport(new GetAssertionStatusReport());
839                                         sub.getSubscriptionFilter().getGetAssertionStatusReport().setCompletionStatus(CompletionStatus.valueOf(((String[]) map.get("assertionStatus"))[0]));
840                                 } else if (alertCritera.equalsIgnoreCase("relatedBusiness")) {
841                                         outmsg.set(ResourceLoader.GetResource(locale, "errors.subscription.relatedbiz"));
842                                         return null;
843                                 } else if (alertCritera.equalsIgnoreCase("tmodel")) {
844                                         sub.getSubscriptionFilter().setGetTModelDetail(new GetTModelDetail());
845                                         sub.getSubscriptionFilter().getGetTModelDetail().getTModelKey().addAll(keys);
846                                 } else {
847                                         outmsg.set(ResourceLoader.GetResource(locale, "errors.subscription.alertcriteriainvalid"));
848                                         return null;
849                                 }
850                         } else {
851                                 outmsg.set(ResourceLoader.GetResource(locale, "errors.subscription.alertcriteriainvalid"));
852                                 return null;
853                         }
854                         return sub;
855                 } catch (Exception ex) {
856                         UddiHub.log.warn(null, ex);
857                         outmsg.set((ResourceLoader.GetResource(locale, "errors.invaliddata")));
858                         return null;
859                 }
860         }
861 
862         private static Subscription BuildClientSubscriptionSearchResults(Map map, AtomicReference<String> outmsg, HttpSession session) {
863                 try {
864                         Subscription sub = new Subscription();
865                         String alertCritera = ((String[]) map.get("alertCriteraMultipleItem"))[0];
866 
867                         sub.setSubscriptionFilter(new SubscriptionFilter());
868                         Name name = new Name();
869                         name.setValue(((String[]) map.get("searchcontent"))[0]);
870                         name.setLang(((String[]) map.get("searchlang"))[0]);
871                         FindQualifiers fq = new FindQualifiers();
872                         String[] fqs = (String[]) map.get("findqualifier");
873                         if (fqs != null) {
874                                 for (int i = 0; i < fqs.length; i++) {
875                                         fq.getFindQualifier().add(fqs[i]);
876                                 }
877                         }
878                         if (fq.getFindQualifier().isEmpty()) {
879                                 fq = null;
880                         }
881                         if (alertCritera != null) {
882                                 if (alertCritera.equalsIgnoreCase("binding")) {
883                                         //sub.getSubscriptionFilter().setFindBinding(new FindBinding());
884                                         //sub.getSubscriptionFilter().getFindBinding().
885                                 } else if (alertCritera.equalsIgnoreCase("service")) {
886                                         sub.getSubscriptionFilter().setFindService(new FindService());
887                                         sub.getSubscriptionFilter().getFindService().getName().add(name);
888                                         sub.getSubscriptionFilter().getFindService().setFindQualifiers(fq);
889                                 } else if (alertCritera.equalsIgnoreCase("business")) {
890                                         sub.getSubscriptionFilter().setFindBusiness(new FindBusiness());
891                                         sub.getSubscriptionFilter().getFindBusiness().setFindQualifiers(fq);
892                                         sub.getSubscriptionFilter().getFindBusiness().getName().add(name);
893                                         //              sub.getSubscriptionFilter().getGetBusinessDetail().getBusinessKey().addAll(keys);
894                                 } else if (alertCritera.equalsIgnoreCase("publisherAssertion")) {
895                                         //unknow if this will work
896                                         sub.getSubscriptionFilter().setGetAssertionStatusReport(new GetAssertionStatusReport());
897                                         sub.getSubscriptionFilter().getGetAssertionStatusReport().setCompletionStatus(CompletionStatus.valueOf(((String[]) map.get("assertionStatus"))[0]));
898                                 } else if (alertCritera.equalsIgnoreCase("relatedBusiness")) {
899                                         sub.getSubscriptionFilter().setFindRelatedBusinesses(new FindRelatedBusinesses());
900                                         sub.getSubscriptionFilter().getFindRelatedBusinesses().setFindQualifiers(fq);
901                                         sub.getSubscriptionFilter().getFindRelatedBusinesses().setBusinessKey(((String[]) map.get("searchcontent"))[0]);
902                                 } else if (alertCritera.equalsIgnoreCase("tmodel")) {
903                                         sub.getSubscriptionFilter().setFindTModel(new FindTModel());
904                                         sub.getSubscriptionFilter().getFindTModel().setFindQualifiers(fq);
905                                         sub.getSubscriptionFilter().getFindTModel().setName(name);
906                                 } else {
907                                         outmsg.set(ResourceLoader.GetResource(session, "errors.subscription.alertcriteriainvalid"));
908                                         return null;
909                                 }
910                         } else {
911                                 outmsg.set(ResourceLoader.GetResource(session, "errors.subscription.alertcriteriainvalid"));
912                                 return null;
913                         }
914                         return sub;
915                 } catch (Exception ex) {
916                         UddiHub.log.warn(null, ex);
917                         outmsg.set("error parsing");
918                         return null;
919                 }
920         }
921 
922         private static Subscription BuildSubscriptionOptions(Map map, Subscription sub) {
923                 if (sub == null) {
924                         return null;
925                 }
926                 try {
927                         sub.setBrief(Boolean.parseBoolean(((String[]) map.get("brief"))[0]));
928                 } catch (Exception x) {
929                         sub.setBrief(false);
930                 }
931 
932                 try {
933                         sub.setMaxEntities(Integer.parseInt(((String[]) map.get("maxRecords"))[0]));
934                 } catch (Exception x) {
935                         sub.setBrief(false);
936                 }
937 
938                 try {
939                         DatatypeFactory df = DatatypeFactory.newInstance();
940                         DateFormat dformat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss a");
941                         String ds = (String) map.get("expires");
942                         if (ds != null && ds.trim().length() != 0 && !ds.equals("\"\"")) {
943                                 Date parsed = dformat.parse(((String[]) map.get("expires"))[0]);
944                                 GregorianCalendar gcal = new GregorianCalendar();
945                                 gcal.setTime(parsed);
946                                 sub.setExpiresAfter(df.newXMLGregorianCalendar(gcal));
947                         }
948                 } catch (Exception ex) {
949                         UddiHub.log.debug("Unexpected parsing expires error " + ex.getMessage());
950                 }
951 
952                 try {
953                         DatatypeFactory df = DatatypeFactory.newInstance();
954                         DateFormat dformat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss a");
955                         Date parsed = dformat.parse(((String[]) map.get("expires"))[0]);
956 
957                         GregorianCalendar gcal = new GregorianCalendar();
958                         gcal.setTime(parsed);
959                         sub.setExpiresAfter(df.newXMLGregorianCalendar(gcal));
960                 } catch (Exception ex) {
961                         UddiHub.log.debug("Unexpected parsing expires error " + ex.getMessage());
962                 }
963 
964                 try {
965                         long durationInMilliSeconds = 0;
966                         DatatypeFactory df = DatatypeFactory.newInstance();
967                         String interval = ((String[]) map.get("interval"))[0];
968                         String[] tokens = interval.split(":");
969                         durationInMilliSeconds += Integer.parseInt(tokens[0]) * 60 * 60 * 1000;
970                         durationInMilliSeconds += Integer.parseInt(tokens[1]) * 60 * 1000;
971                         durationInMilliSeconds += Integer.parseInt(tokens[2]) * 1000;
972 
973                         sub.setNotificationInterval(df.newDuration(durationInMilliSeconds));
974 
975                 } catch (Exception ex) {
976                         UddiHub.log.debug("Unexpected parsing interval error " + ex.getMessage());
977                 }
978 
979                 try {
980                         long durationInMilliSeconds = 0;
981                         DatatypeFactory df = DatatypeFactory.newInstance();
982                         String interval = (String) map.get("interval");
983                         String[] tokens = interval.split(":");
984                         durationInMilliSeconds += Integer.parseInt(tokens[0]) * 60 * 60 * 1000;
985                         durationInMilliSeconds += Integer.parseInt(tokens[1]) * 60 * 1000;
986                         durationInMilliSeconds += Integer.parseInt(tokens[2]) * 1000;
987 
988                         sub.setNotificationInterval(df.newDuration(durationInMilliSeconds));
989 
990                 } catch (Exception ex) {
991                         UddiHub.log.debug("Unexpected parsing interval error " + ex.getMessage());
992                 }
993 
994                 return sub;
995         }
996 }