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