01: package org.jicengine.element.impl;
02:
03: import org.jicengine.element.Element;
04: import org.jicengine.expression.FactoryInvocationParser;
05: import org.jicengine.operation.Context;
06: import org.jicengine.operation.Factory;
07: import org.jicengine.operation.FactoryInvocationOperation;
08: import org.jicengine.operation.MethodInvocationOperation;
09: import org.jicengine.operation.ObjectNotFoundException;
10: import org.jicengine.operation.Operation;
11: import org.jicengine.operation.OperationException;
12: import org.jicengine.operation.StaticValue;
13: import org.jicengine.operation.VariableValueOperation;
14:
15: /**
16: *
17: * @author timo
18: *
19: */
20: public class CdataConverterInvocationOperation implements Operation {
21:
22: private Class targetClass;
23: private String cdata;
24:
25: public CdataConverterInvocationOperation(Class targetClass,
26: String cdata) {
27: this .targetClass = targetClass;
28: this .cdata = cdata;
29: }
30:
31: public boolean needsParameters() {
32: return true;
33: }
34:
35: public boolean needsParameter(String name) {
36: return name.equals(Element.VARIABLE_NAME_CDATA);
37: }
38:
39: public Object execute(Context context) throws OperationException {
40:
41: String contextVariableName = CdataConverterElementCompiler
42: .toContextVariableName(this .targetClass);
43:
44: try {
45: Factory factory = (Factory) context
46: .getObject(contextVariableName);
47:
48: Object result = factory.invoke(new Object[] { this .cdata });
49:
50: return result;
51: } catch (ObjectNotFoundException e) {
52: throw new OperationException("CDATA conversion for class '"
53: + this .targetClass.getName() + "' not available.");
54: }
55:
56: }
57:
58: }
|