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