svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / main / java / org / gvsig / expressionevaluator / impl / function / programming / FileFunction.java @ 44181
History | View | Annotate | Download (1.46 KB)
1 |
package org.gvsig.expressionevaluator.impl.function.programming; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.net.URI; |
5 |
import org.apache.commons.lang3.Range; |
6 |
import org.gvsig.expressionevaluator.ExpressionRuntimeException; |
7 |
import org.gvsig.expressionevaluator.Function; |
8 |
import org.gvsig.expressionevaluator.Interpreter; |
9 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
10 |
|
11 |
public class FileFunction extends AbstractFunction { |
12 |
|
13 |
public static final String NAME = "FILE"; |
14 |
|
15 |
public FileFunction() {
|
16 |
super(Function.GROUP_PROGRAMMING,
|
17 |
NAME, |
18 |
Range.is(1),
|
19 |
null,
|
20 |
null,
|
21 |
null,
|
22 |
"Object",
|
23 |
false
|
24 |
); |
25 |
} |
26 |
|
27 |
@Override
|
28 |
public boolean allowConstantFolding() { |
29 |
return false; |
30 |
} |
31 |
|
32 |
@Override
|
33 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
34 |
Object value;
|
35 |
Object obj = getObject(args, 0); |
36 |
if( obj == null ) { |
37 |
return 0; |
38 |
} |
39 |
if( obj instanceof File ) { |
40 |
return obj;
|
41 |
} else if( obj instanceof CharSequence ) { |
42 |
value = new File(((CharSequence)obj).toString()); |
43 |
} else if( obj instanceof URI ) { |
44 |
value = new File(((URI)obj)); |
45 |
} else {
|
46 |
throw new ExpressionRuntimeException("The "+NAME+" function require a File or a String and a received a '"+obj.getClass().getSimpleName()+"'."); |
47 |
} |
48 |
return value;
|
49 |
} |
50 |
|
51 |
} |