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 | |
public class DefaultModelServiceDescriptor extends AbstractServiceDescriptor implements ModelServiceDescriptor |
25 | |
{ |
26 | |
private String modelClass; |
27 | |
private Properties properties; |
28 | |
|
29 | |
public DefaultModelServiceDescriptor(String service, Properties properties) |
30 | |
{ |
31 | 0 | super(service); |
32 | 0 | this.properties = properties; |
33 | 0 | modelClass = removeProperty(MuleProperties.MODEL_CLASS, properties); |
34 | 0 | } |
35 | |
|
36 | |
public Model createModel() throws ServiceException |
37 | |
{ |
38 | 0 | if (modelClass != null) |
39 | |
{ |
40 | |
try |
41 | |
{ |
42 | 0 | Model model = (Model)ClassUtils.instanciateClass(modelClass, ClassUtils.NO_ARGS, getClass()); |
43 | 0 | BeanUtils.populateWithoutFail(model, properties, false); |
44 | 0 | return model; |
45 | |
} |
46 | 0 | catch (Exception e) |
47 | |
{ |
48 | 0 | throw new ServiceException(CoreMessages.failedToCreate(modelClass), e); |
49 | |
} |
50 | |
} |
51 | 0 | else return null; |
52 | |
} |
53 | |
|
54 | |
@SuppressWarnings("unchecked") |
55 | |
public Class<Model> getModelClass() throws ServiceException |
56 | |
{ |
57 | |
try |
58 | |
{ |
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 | |
} |