1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
package org.apache.shale.remoting.impl; |
19 | |
|
20 | |
import java.io.Serializable; |
21 | |
import java.util.ArrayList; |
22 | |
import java.util.Iterator; |
23 | |
import java.util.List; |
24 | |
import javax.faces.application.ViewHandler; |
25 | |
import org.apache.shale.remoting.Mapping; |
26 | |
import org.apache.shale.remoting.Mappings; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | 13 | public class MappingsImpl implements Mappings, Serializable { |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
private static final long serialVersionUID = 7761184295213057256L; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 13 | private String extension = ViewHandler.DEFAULT_SUFFIX; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | 13 | private List mappings = new ArrayList(); |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | 13 | private int patternIndex = 0; |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | 13 | private String[] patterns = new String[0]; |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
public void addMapping(Mapping mapping) { |
74 | 15 | if (mapping == null) { |
75 | |
throw new NullPointerException(); |
76 | |
} |
77 | 15 | synchronized (mappings) { |
78 | 15 | if (!mappings.contains(mapping)) { |
79 | 15 | mappings.add(mapping); |
80 | |
} |
81 | 15 | } |
82 | 15 | } |
83 | |
|
84 | |
|
85 | |
|
86 | |
public String getExtension() { |
87 | 18 | return this.extension; |
88 | |
} |
89 | |
|
90 | |
|
91 | |
|
92 | |
public Mapping getMapping(String pattern) { |
93 | 3 | if (pattern == null) { |
94 | |
throw new NullPointerException(); |
95 | |
} |
96 | 3 | synchronized (mappings) { |
97 | 3 | Iterator items = mappings.iterator(); |
98 | 6 | while (items.hasNext()) { |
99 | 6 | Mapping item = (Mapping) items.next(); |
100 | 6 | if (pattern.equals(item.getPattern())) { |
101 | 3 | return item; |
102 | |
} |
103 | 3 | } |
104 | |
return null; |
105 | |
} |
106 | |
} |
107 | |
|
108 | |
|
109 | |
|
110 | |
public List getMappings() { |
111 | 3 | return this.mappings; |
112 | |
} |
113 | |
|
114 | |
|
115 | |
|
116 | |
public int getPatternIndex() { |
117 | 6 | return this.patternIndex; |
118 | |
} |
119 | |
|
120 | |
|
121 | |
|
122 | |
public void setPatternIndex(int patternIndex) { |
123 | 1 | this.patternIndex = patternIndex; |
124 | 1 | } |
125 | |
|
126 | |
|
127 | |
|
128 | |
public String[] getPatterns() { |
129 | 23 | return this.patterns; |
130 | |
} |
131 | |
|
132 | |
|
133 | |
|
134 | |
public void removeMapping(Mapping mapping) { |
135 | |
if (mapping == null) { |
136 | |
throw new NullPointerException(); |
137 | |
} |
138 | |
synchronized (mappings) { |
139 | |
mappings.remove(mapping); |
140 | |
} |
141 | |
} |
142 | |
|
143 | |
|
144 | |
|
145 | |
public void setExtension(String extension) { |
146 | 10 | this.extension = extension; |
147 | 10 | } |
148 | |
|
149 | |
|
150 | |
|
151 | |
public void setPatterns(String[] patterns) { |
152 | 16 | this.patterns = patterns; |
153 | 16 | } |
154 | |
|
155 | |
|
156 | |
} |