01: /*
02: * $Id: XmppNamespaceHandler.java 10494 2008-01-23 21:09:56Z acooke $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10:
11: package org.mule.transport.xmpp.config;
12:
13: import org.mule.config.spring.handlers.AbstractMuleNamespaceHandler;
14: import org.mule.config.spring.parsers.PreProcessor;
15: import org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration;
16: import org.mule.config.spring.parsers.processors.RequireAttribute;
17: import org.mule.endpoint.URIBuilder;
18: import org.mule.transport.xmpp.XmppConnector;
19: import org.mule.util.StringUtils;
20:
21: import org.w3c.dom.Element;
22:
23: /**
24: * Registers a Bean Definition Parser for handling <code><xmpp:connector></code> elements.
25: */
26: public class XmppNamespaceHandler extends AbstractMuleNamespaceHandler {
27:
28: public static final String RECIPIENT = "recipient";
29: public static final String[] REQUIRED_ADDRESS_ATTRIBUTES = new String[] {
30: RECIPIENT, URIBuilder.USER, URIBuilder.HOST };
31:
32: public void init() {
33: registerStandardTransportEndpoints(XmppConnector.XMPP,
34: REQUIRED_ADDRESS_ATTRIBUTES).addAlias(RECIPIENT,
35: URIBuilder.PATH).registerPreProcessor(
36: new RequireNickname());
37: this .registerConnectorDefinitionParser(XmppConnector.class);
38: }
39:
40: public static class RequireNickname implements PreProcessor {
41:
42: public void preProcess(PropertyConfiguration config,
43: Element element) {
44: String groupChat = element
45: .getAttribute(XmppConnector.XMPP_GROUP_CHAT);
46: if (Boolean.valueOf(groupChat).booleanValue()) {
47: if (StringUtils.isBlank(element
48: .getAttribute(XmppConnector.XMPP_NICKNAME))) {
49: throw new RequireAttribute.RequireAttributeException(
50: "Attribute " + XmppConnector.XMPP_NICKNAME
51: + " must be given if "
52: + XmppConnector.XMPP_GROUP_CHAT
53: + " is true.");
54: }
55: }
56: }
57:
58: }
59:
60: }
|