|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| package org.apache.xindice.core.meta.inline; |
|
21 |
| |
|
22 |
| import org.apache.commons.logging.Log; |
|
23 |
| import org.apache.commons.logging.LogFactory; |
|
24 |
| import org.apache.xindice.core.FaultCodes; |
|
25 |
| import org.apache.xindice.core.data.Value; |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| public class ResourceTypeReader implements InlineMetaReader { |
|
32 |
| |
|
33 |
| private static final Log log = LogFactory.getLog(ResourceTypeReader.class); |
|
34 |
| |
|
35 |
| public static final Integer XML = new Integer(1); |
|
36 |
| public static final Integer BINARY = new Integer(2); |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
0
| public int getVersion() {
|
|
43 |
0
| return 1;
|
|
44 |
| } |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
34455
| public InlineMetaMap read(Value data) throws InlineMetaException {
|
|
50 |
34455
| if (log.isDebugEnabled()) {
|
|
51 |
0
| log.debug("ResourceTypeReader.read: data length=" + data.getLength());
|
|
52 |
| } |
|
53 |
| |
|
54 |
34455
| if (data.getLength() != 1) {
|
|
55 |
0
| throw new InlineMetaException(FaultCodes.COL_DOCUMENT_MALFORMED,
|
|
56 |
| "Expecting header length of 1"); |
|
57 |
| } |
|
58 |
| |
|
59 |
34455
| Integer type;
|
|
60 |
34455
| type = new Integer(data.byteAt(0));
|
|
61 |
| |
|
62 |
34455
| if (!XML.equals(type) && !BINARY.equals(type)) {
|
|
63 |
1
| throw new InlineMetaException(FaultCodes.COL_DOCUMENT_MALFORMED,
|
|
64 |
| "Unexpected type value: " + type); |
|
65 |
| } |
|
66 |
| |
|
67 |
34454
| ResourceTypeMap resourceTypeMap = new ResourceTypeMap();
|
|
68 |
34454
| resourceTypeMap.put("type", type);
|
|
69 |
34454
| return resourceTypeMap;
|
|
70 |
| } |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| public static class ResourceTypeMap implements InlineMetaMap { |
|
77 |
| |
|
78 |
| private static String[] keys = new String[]{"type"}; |
|
79 |
| |
|
80 |
| private Integer type; |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
0
| public boolean containsKey(String key) {
|
|
86 |
0
| return "type".equals(key);
|
|
87 |
| } |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
36437
| public Object get(String key) throws InlineMetaException {
|
|
93 |
36437
| if ("type".equals(key)) {
|
|
94 |
36437
| return type;
|
|
95 |
| } else { |
|
96 |
0
| throw new InlineMetaException(FaultCodes.GEN_CRITICAL_ERROR,
|
|
97 |
| "ResourceTypeMap does not accept key '" + key + "'"); |
|
98 |
| } |
|
99 |
| } |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
0
| public String[] keys() {
|
|
105 |
0
| return keys;
|
|
106 |
| } |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
36437
| public void put(String key, Object value) throws InlineMetaException {
|
|
112 |
36437
| if ("type".equals(key)) {
|
|
113 |
36437
| if (value instanceof Integer) {
|
|
114 |
36437
| type = (Integer) value;
|
|
115 |
| } else { |
|
116 |
0
| throw new InlineMetaException(FaultCodes.GEN_CRITICAL_ERROR,
|
|
117 |
| "ResourceTypeMap key 'type' requires an Integer value"); |
|
118 |
| } |
|
119 |
| } else { |
|
120 |
0
| throw new InlineMetaException(FaultCodes.GEN_CRITICAL_ERROR,
|
|
121 |
| "ResourceTypeMap does not accept key '" + key + "'"); |
|
122 |
| } |
|
123 |
| } |
|
124 |
| } |
|
125 |
| } |