View Javadoc

1   package org.apache.stratum.messenger;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation or its licensors,
5    * as applicable.
6    *
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  import org.apache.commons.configuration.Configuration;
21  import org.apache.commons.messenger.MessengerManager;
22  import org.apache.stratum.lifecycle.Configurable;
23  import org.apache.stratum.lifecycle.Initializable;
24  
25  /***
26   * This class is the Messenger component.  It is an adaptor that allows the ComponentLoader to startup MessengerManager.  Client
27   * code wishing to use Messenger should ask MessengerManager directly for Messenger instances.
28   *
29   * @author <a href="mailto:eric@dobbse.net">Eric Dobbs</a>
30   * @version $Id: MessengerComponent.java 264191 2005-08-29 18:07:52Z henning $
31   *
32   * @see org.apache.commons.messenger.MessengerManager
33   * @see org.apache.commons.messenger.Messenger
34   */
35  public class MessengerComponent
36          implements Configurable, Initializable
37  {
38      /*** The key for property 'messenger.xml.url' */
39      private static final String MESSENGER_XML_URL = "messenger.xml.url";
40  
41      /*** The location of the Messenger.xml file */
42      private String messengerXmlUrl;
43  
44      /***
45       * Configure MessengerManager.  MessengerManager requires a URL to a Messenger.xml file.  The messenger.properties file should
46       * define one property named 'messenger.xml.url' identifying the location of Messenger.xml.
47       *
48       * @param configuration Configuration object containing the 'messenger.xml.url' property
49       */
50      public void configure(Configuration configuration)
51      {
52          messengerXmlUrl = configuration.getString(MESSENGER_XML_URL);
53      }
54  
55      /***
56       * Initialize the MessengerManager.
57       *
58       * @exception Exception is thrown if the file defined in 'messenger.xml.url' can't be found.  JMSException will be thrown if
59       *            MessengerManager.configure is unhappy with the value from 'messenger.xml.url'
60       */
61      public void initialize()
62              throws Exception
63      {
64          if (messengerXmlUrl == null)
65          {
66              throw new Exception("Can't find property '" + MESSENGER_XML_URL + "' in the properties file");
67          }
68  
69          MessengerManager.configure(messengerXmlUrl);
70      }
71  }