View Javadoc

1   /*
2    * $Id: XmppNamespaceHandler.java 10494 2008-01-23 21:09:56Z acooke $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
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  
29      public static final String RECIPIENT = "recipient";
30      public static final String[] REQUIRED_ADDRESS_ATTRIBUTES =
31              new String[]{RECIPIENT, URIBuilder.USER, URIBuilder.HOST};
32  
33      public void init()
34      {
35          registerStandardTransportEndpoints(XmppConnector.XMPP, REQUIRED_ADDRESS_ATTRIBUTES).addAlias(RECIPIENT, URIBuilder.PATH).registerPreProcessor(new RequireNickname());
36          this.registerConnectorDefinitionParser(XmppConnector.class);
37      }
38  
39      public static class RequireNickname implements PreProcessor
40      {
41  
42          public void preProcess(PropertyConfiguration config, Element element)
43          {
44              String groupChat = element.getAttribute(XmppConnector.XMPP_GROUP_CHAT);
45              if (Boolean.valueOf(groupChat).booleanValue())
46              {
47                  if (StringUtils.isBlank(element.getAttribute(XmppConnector.XMPP_NICKNAME)))
48                  {
49                      throw new RequireAttribute.RequireAttributeException("Attribute " +
50                                      XmppConnector.XMPP_NICKNAME + " must be given if " +
51                                      XmppConnector.XMPP_GROUP_CHAT + " is true.");
52                  }
53              }
54          }
55  
56      }
57  
58  }