1
2
3
4
5
6
7
8
9
10 package org.mule.expression.transformers;
11
12 import org.mule.api.lifecycle.InitialisationException;
13 import org.mule.config.i18n.CoreMessages;
14 import org.mule.transformer.AbstractMessageTransformer;
15 import org.mule.transformer.types.DataTypeFactory;
16
17 import java.util.ArrayList;
18 import java.util.Iterator;
19 import java.util.List;
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 public abstract class AbstractExpressionTransformer extends AbstractMessageTransformer
41 {
42 protected List<ExpressionArgument> arguments;
43
44 public AbstractExpressionTransformer()
45 {
46
47 registerSourceType(DataTypeFactory.OBJECT);
48 setReturnDataType(DataTypeFactory.OBJECT);
49 arguments = new ArrayList<ExpressionArgument>(4);
50 }
51
52 public void addArgument(ExpressionArgument argument)
53 {
54 arguments.add(argument);
55 }
56
57 public boolean removeArgument(ExpressionArgument argument)
58 {
59 return arguments.remove(argument);
60 }
61
62
63
64
65
66
67
68
69 @Override
70 public void initialise() throws InitialisationException
71 {
72 if (arguments == null || arguments.size() == 0)
73 {
74 throw new InitialisationException(CoreMessages.objectIsNull("arguments[]"), this);
75 }
76
77 for (Iterator<ExpressionArgument> iterator = arguments.iterator(); iterator.hasNext();)
78 {
79 ExpressionArgument argument = iterator.next();
80 argument.setMuleContext(muleContext);
81 argument.setExpressionEvaluationClassLoader(Thread.currentThread().getContextClassLoader());
82 try
83 {
84 argument.validate();
85 }
86 catch (Exception e)
87 {
88 throw new InitialisationException(e, this);
89 }
90 }
91 }
92
93 public List<ExpressionArgument> getArguments()
94 {
95 return arguments;
96 }
97
98 public void setArguments(List<ExpressionArgument> arguments)
99 {
100 this.arguments = arguments;
101 }
102 }