1
2
3
4
5 package de.mindcrimeilab.xsanalyzer.util;
6
7 import java.util.ArrayList;
8 import java.util.List;
9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12 import org.apache.xerces.xs.StringList;
13 import org.apache.xerces.xs.XSObject;
14 import org.apache.xerces.xs.XSObjectList;
15
16
17
18
19
20
21
22 public class XSListHelper {
23
24 private static final Log logger = LogFactory.getLog("xsAnalyzerApplicationLogger");
25
26 public static List<String> asList(StringList stringList) {
27 return XSListHelper.asList(stringList, ArrayList.class);
28 }
29
30 public static List<String> asList(StringList stringList, Class<? extends List> collectionClazz) {
31 List<String> result;
32 try {
33 result = collectionClazz.newInstance();
34 }
35 catch (InstantiationException e) {
36 XSListHelper.logger.warn("Could not create class " + collectionClazz, e);
37 result = new ArrayList<String>(stringList.getLength());
38 }
39 catch (IllegalAccessException e) {
40 XSListHelper.logger.warn("Could not create class " + collectionClazz, e);
41 result = new ArrayList<String>(stringList.getLength());
42 }
43 for (int i = 0; i < stringList.getLength(); ++i) {
44 result.add(stringList.item(i));
45 }
46 return result;
47 }
48
49 public static List<XSObject> asList(XSObjectList xsobjectList) {
50 return XSListHelper.asList(xsobjectList, ArrayList.class);
51 }
52
53 public static List<XSObject> asList(XSObjectList xsobjectList, Class<? extends List> collectionClazz) {
54 List<XSObject> result;
55 try {
56 result = collectionClazz.newInstance();
57 }
58 catch (InstantiationException e) {
59 XSListHelper.logger.warn("Could not create class " + collectionClazz, e);
60 result = new ArrayList<XSObject>(xsobjectList.getLength());
61 }
62 catch (IllegalAccessException e) {
63 XSListHelper.logger.warn("Could not create class " + collectionClazz, e);
64 result = new ArrayList<XSObject>(xsobjectList.getLength());
65 }
66 for (int i = 0; i < xsobjectList.getLength(); ++i) {
67 result.add(xsobjectList.item(i));
68 }
69 return result;
70 }
71 }