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