1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.config.spring.parsers.specific; |
12 | |
|
13 | |
import org.mule.api.context.notification.ComponentMessageNotificationListener; |
14 | |
import org.mule.api.context.notification.ConnectionNotificationListener; |
15 | |
import org.mule.api.context.notification.CustomNotificationListener; |
16 | |
import org.mule.api.context.notification.EndpointMessageNotificationListener; |
17 | |
import org.mule.api.context.notification.ExceptionNotificationListener; |
18 | |
import org.mule.api.context.notification.ManagementNotificationListener; |
19 | |
import org.mule.api.context.notification.ModelNotificationListener; |
20 | |
import org.mule.api.context.notification.MuleContextNotificationListener; |
21 | |
import org.mule.api.context.notification.RegistryNotificationListener; |
22 | |
import org.mule.api.context.notification.RoutingNotificationListener; |
23 | |
import org.mule.api.context.notification.SecurityNotificationListener; |
24 | |
import org.mule.api.context.notification.ServiceNotificationListener; |
25 | |
import org.mule.api.context.notification.TransactionNotificationListener; |
26 | |
import org.mule.config.spring.parsers.PreProcessor; |
27 | |
import org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration; |
28 | |
import org.mule.config.spring.parsers.collection.ChildMapEntryDefinitionParser; |
29 | |
import org.mule.config.spring.parsers.processors.CheckExclusiveAttributes; |
30 | |
import org.mule.config.spring.parsers.processors.CheckRequiredAttributes; |
31 | |
import org.mule.context.notification.ComponentMessageNotification; |
32 | |
import org.mule.context.notification.ConnectionNotification; |
33 | |
import org.mule.context.notification.CustomNotification; |
34 | |
import org.mule.context.notification.EndpointMessageNotification; |
35 | |
import org.mule.context.notification.ExceptionNotification; |
36 | |
import org.mule.context.notification.ManagementNotification; |
37 | |
import org.mule.context.notification.ModelNotification; |
38 | |
import org.mule.context.notification.MuleContextNotification; |
39 | |
import org.mule.context.notification.RegistryNotification; |
40 | |
import org.mule.context.notification.RoutingNotification; |
41 | |
import org.mule.context.notification.SecurityNotification; |
42 | |
import org.mule.context.notification.ServiceNotification; |
43 | |
import org.mule.context.notification.TransactionNotification; |
44 | |
|
45 | |
import java.util.HashMap; |
46 | |
import java.util.Map; |
47 | |
|
48 | |
import org.w3c.dom.Element; |
49 | |
|
50 | |
public class NotificationDefinitionParser extends ChildMapEntryDefinitionParser |
51 | |
{ |
52 | |
|
53 | |
public static final Map EVENT_MAP; |
54 | |
public static final Map INTERFACE_MAP; |
55 | |
public static final String INTERFACE = "interface"; |
56 | |
public static final String INTERFACE_CLASS = "interface-class"; |
57 | |
public static final String EVENT = "event"; |
58 | |
public static final String EVENT_CLASS = "event-class"; |
59 | 0 | public static final String[][] INTERFACE_ATTRIBUTES = |
60 | |
new String[][]{new String[]{INTERFACE}, new String[]{INTERFACE_CLASS}}; |
61 | 0 | public static final String[][] EVENT_ATTRIBUTES = |
62 | |
new String[][]{new String[]{EVENT}, new String[]{EVENT_CLASS}}; |
63 | 0 | public static final String[][] ALL_ATTRIBUTES = |
64 | |
new String[][]{ |
65 | |
new String[]{EVENT}, new String[]{EVENT_CLASS}, |
66 | |
new String[]{INTERFACE}, new String[]{INTERFACE_CLASS}}; |
67 | |
|
68 | |
static |
69 | |
{ |
70 | 0 | EVENT_MAP = new HashMap(); |
71 | 0 | EVENT_MAP.put("CONTEXT", MuleContextNotification.class.getName()); |
72 | 0 | EVENT_MAP.put("MODEL", ModelNotification.class.getName()); |
73 | 0 | EVENT_MAP.put("SERVICE", ServiceNotification.class.getName()); |
74 | 0 | EVENT_MAP.put("SECURITY", SecurityNotification.class.getName()); |
75 | 0 | EVENT_MAP.put("ENDPOINT-MESSAGE", EndpointMessageNotification.class.getName()); |
76 | 0 | EVENT_MAP.put("COMPONENT-MESSAGE", ComponentMessageNotification.class.getName()); |
77 | 0 | EVENT_MAP.put("MANAGEMENT", ManagementNotification.class.getName()); |
78 | 0 | EVENT_MAP.put("CONNECTION", ConnectionNotification.class.getName()); |
79 | 0 | EVENT_MAP.put("REGISTRY", RegistryNotification.class.getName()); |
80 | 0 | EVENT_MAP.put("CUSTOM", CustomNotification.class.getName()); |
81 | 0 | EVENT_MAP.put("EXCEPTION", ExceptionNotification.class.getName()); |
82 | 0 | EVENT_MAP.put("TRANSACTION", TransactionNotification.class.getName()); |
83 | 0 | EVENT_MAP.put("ROUTING", RoutingNotification.class.getName()); |
84 | |
|
85 | 0 | INTERFACE_MAP = new HashMap(); |
86 | 0 | INTERFACE_MAP.put("CONTEXT", MuleContextNotificationListener.class.getName()); |
87 | 0 | INTERFACE_MAP.put("MODEL", ModelNotificationListener.class.getName()); |
88 | 0 | INTERFACE_MAP.put("SERVICE", ServiceNotificationListener.class.getName()); |
89 | 0 | INTERFACE_MAP.put("SECURITY", SecurityNotificationListener.class.getName()); |
90 | 0 | INTERFACE_MAP.put("MANAGEMENT", ManagementNotificationListener.class.getName()); |
91 | 0 | INTERFACE_MAP.put("CONNECTION", ConnectionNotificationListener.class.getName()); |
92 | 0 | INTERFACE_MAP.put("REGISTRY", RegistryNotificationListener.class.getName()); |
93 | 0 | INTERFACE_MAP.put("CUSTOM", CustomNotificationListener.class.getName()); |
94 | 0 | INTERFACE_MAP.put("ENDPOINT-MESSAGE", EndpointMessageNotificationListener.class.getName()); |
95 | 0 | INTERFACE_MAP.put("COMPONENT-MESSAGE", ComponentMessageNotificationListener.class.getName()); |
96 | 0 | INTERFACE_MAP.put("EXCEPTION", ExceptionNotificationListener.class.getName()); |
97 | 0 | INTERFACE_MAP.put("TRANSACTION", TransactionNotificationListener.class.getName()); |
98 | 0 | INTERFACE_MAP.put("ROUTING", RoutingNotificationListener.class.getName()); |
99 | |
|
100 | |
|
101 | 0 | EVENT_MAP.put("MESSAGE", EndpointMessageNotification.class.getName()); |
102 | |
|
103 | 0 | } |
104 | |
|
105 | |
public NotificationDefinitionParser() |
106 | |
{ |
107 | 0 | super("interfaceToType", INTERFACE_CLASS, EVENT_CLASS); |
108 | 0 | addMapping(EVENT, EVENT_MAP); |
109 | 0 | addAlias(EVENT, VALUE); |
110 | 0 | addMapping(INTERFACE, INTERFACE_MAP); |
111 | 0 | addAlias(INTERFACE, KEY); |
112 | 0 | registerPreProcessor(new CheckExclusiveAttributes(INTERFACE_ATTRIBUTES)); |
113 | 0 | registerPreProcessor(new CheckExclusiveAttributes(EVENT_ATTRIBUTES)); |
114 | 0 | registerPreProcessor(new CheckRequiredAttributes(INTERFACE_ATTRIBUTES)); |
115 | 0 | registerPreProcessor(new CheckRequiredAttributes(EVENT_ATTRIBUTES)); |
116 | 0 | registerPreProcessor(new SetDefaults()); |
117 | 0 | } |
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | 0 | private class SetDefaults implements PreProcessor |
123 | |
{ |
124 | |
|
125 | |
public void preProcess(PropertyConfiguration config, Element element) |
126 | |
{ |
127 | 0 | copy(element, INTERFACE, EVENT, EVENT_CLASS); |
128 | 0 | copy(element, EVENT, INTERFACE, INTERFACE_CLASS); |
129 | 0 | } |
130 | |
|
131 | |
private void copy(Element element, String from, String to, String blocker) |
132 | |
{ |
133 | 0 | if (element.hasAttribute(from) && !element.hasAttribute(to) && !element.hasAttribute(blocker)) |
134 | |
{ |
135 | 0 | element.setAttribute(to, element.getAttribute(from)); |
136 | |
} |
137 | 0 | } |
138 | |
|
139 | |
} |
140 | |
|
141 | |
} |