1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.model; |
12 | |
|
13 | |
import org.mule.api.config.MuleProperties; |
14 | |
import org.mule.api.model.Model; |
15 | |
import org.mule.api.model.ModelServiceDescriptor; |
16 | |
import org.mule.api.registry.AbstractServiceDescriptor; |
17 | |
import org.mule.api.registry.ServiceException; |
18 | |
import org.mule.config.i18n.CoreMessages; |
19 | |
import org.mule.util.BeanUtils; |
20 | |
import org.mule.util.ClassUtils; |
21 | |
|
22 | |
import java.util.Properties; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class DefaultModelServiceDescriptor extends AbstractServiceDescriptor implements ModelServiceDescriptor |
28 | |
{ |
29 | |
private String modelClass; |
30 | |
private Properties properties; |
31 | |
|
32 | |
public DefaultModelServiceDescriptor(String service, Properties properties) |
33 | |
{ |
34 | 0 | super(service); |
35 | 0 | this.properties = properties; |
36 | 0 | modelClass = removeProperty(MuleProperties.MODEL_CLASS, properties); |
37 | 0 | } |
38 | |
|
39 | |
public Model createModel() throws ServiceException |
40 | |
{ |
41 | 0 | if (modelClass != null) |
42 | |
{ |
43 | |
try { |
44 | 0 | Model model = (Model)ClassUtils.instanciateClass(modelClass, ClassUtils.NO_ARGS, getClass()); |
45 | 0 | BeanUtils.populateWithoutFail(model, properties, false); |
46 | 0 | return model; |
47 | |
} |
48 | 0 | catch (Exception e) |
49 | |
{ |
50 | 0 | throw new ServiceException(CoreMessages.failedToCreate(modelClass), e); |
51 | |
} |
52 | |
} |
53 | 0 | else return null; |
54 | |
} |
55 | |
|
56 | |
public Class getModelClass() throws ServiceException |
57 | |
{ |
58 | |
try { |
59 | 0 | return ClassUtils.getClass(modelClass); |
60 | |
} |
61 | 0 | catch (ClassNotFoundException e) |
62 | |
{ |
63 | 0 | throw new ServiceException(CoreMessages.cannotLoadFromClasspath(modelClass), e); |
64 | |
} |
65 | |
} |
66 | |
} |