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