forked from micw/php-java-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContext.java
More file actions
220 lines (185 loc) · 5.64 KB
/
Copy pathContext.java
File metadata and controls
220 lines (185 loc) · 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package php.java.bridge;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Map;
public class Context implements Invocable {
/**
* The engine scope
*/
public static final int ENGINE_SCOPE = 100;
/**
* The global scope
*/
public static final int GLOBAL_SCOPE = 200;
/** Map of the scope of level GLOBAL_SCOPE */
protected Map globalScope;
/** Map of the scope of level ENGINE_SCOPE */
protected Map engineScope;
private Object kont;
/**
* Retrieves the value for getAttribute(String, int) for the
* lowest scope in which it returns a non-null value.
*
* @param name the name of the attribute
* @return the value of the attribute
*/
public Object getAttribute(String name) throws IllegalArgumentException{
if (name == null) {
throw new IllegalArgumentException("name cannot be null");
}
if (engineScope.get(name) != null) {
return engineScope.get(name);
} else if (globalScope.get(name) != null) {
return globalScope.get(name);
} else {
return null;
}
}
/**
* Retrieves the value associated with specified name in the
* specified level of scope. Returns null if no value is
* associated with specified key in specified level of scope.
*
* @param key the name of the attribute
* @param scope the level of scope
* @return the value value associated with the specified name in
* specified level of scope
*/
public Object getAttribute(String name, int scope)
throws IllegalArgumentException{
if (name == null) {
throw new IllegalArgumentException("name cannot be null");
}
switch (scope) {
case ENGINE_SCOPE:
return engineScope.get(name);
case GLOBAL_SCOPE:
return globalScope.get(name);
default:
throw new IllegalArgumentException("invalid scope");
}
}
/**
* Retrieves the lowest value of scopes for which the attribute
* is defined. If there is no associate scope with the given
* attribute (-1) is returned.
*
* @param name the name of attribute
* @return the value of level of scope
*/
public int getAttributesScope(String name) {
if (engineScope.containsKey(name)) {
return ENGINE_SCOPE;
} else if(globalScope.containsKey(name)) {
return GLOBAL_SCOPE;
}
return -1;
}
/**
* Retrieves the Map instance associated with the specified
* level of scope.
*
* @param scope the level of the scope
* @return the Map associated with the specified level of
* scope
*/
public Map getMap(int scope) {
switch (scope) {
case ENGINE_SCOPE:
return engineScope;
case GLOBAL_SCOPE:
return globalScope;
default:
return null;
}
}
/**
* Retrieves an instance of java.io.Writer which can be used by
* scripts to display their output.
*
* @return an instance of java.io.Writer
*/
public Writer getWriter() throws IOException {
// autoflush is ture so that I can see the output immediately
return new PrintWriter(System.out, true);
}
/**
* Removes the specified attribute form the specified level of
* scope.
*
* @param name the name of the attribute
* @param scope the level of scope
* @return value which is removed
* @throws
*/
public Object removeAttribute(String name, int scope)
throws IllegalArgumentException{
if (name == null) {
throw new IllegalArgumentException("name is null");
}
switch (scope) {
case ENGINE_SCOPE:
return engineScope.remove(name);
case GLOBAL_SCOPE:
return globalScope.remove(name);
default:
throw new IllegalArgumentException("invalid scope");
}
}
/**
* Sets an attribute specified by the name in specified level of
* scope.
*
* @param key the name of the attribute
* @param value the value of the attribute
* @param scope the level of the scope
* @return value the value associated with the specified key in
* specified scope
* @throws IllegalArguementException if the name is null scope is
* invlaid
*/
public void setAttribute(String name, Object value, int scope)
throws IllegalArgumentException{
if (name == null) {
throw new IllegalArgumentException("name is null");
}
switch (scope) {
case ENGINE_SCOPE:
engineScope.put(name, value);
break;
case GLOBAL_SCOPE:
globalScope.put(name, value);
break;
default:
throw new IllegalArgumentException("invalid scope");
}
}
/**
* Associates the specified Map with specified level of
* scope.
*
* @param map the Map to be associated with specified
* level of scope
* @param scope the level of scope
*/
public void setMap(Map map, int scope)
throws IllegalArgumentException {
switch (scope) {
case ENGINE_SCOPE:
engineScope = map;
break;
case GLOBAL_SCOPE:
globalScope = map;
break;
default:
throw new IllegalArgumentException("invalid scope");
}
}
/* (non-Javadoc)
* @see php.java.bridge.Invocable#call(php.java.bridge.PhpProcedureProxy)
*/
public boolean call(PhpProcedureProxy kont) {
return false;
}
}