View Javadoc

1   /*
2    * $Id: ContainerKeyPair.java 7963 2007-08-21 08:53:15Z dirk.olmes $
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.impl.container;
12  
13  /**
14   * <code>ContainerKeyPair</code> is a key strategy that binds a container reference
15   * with a container name. This object isn't used directly by users, but it is used
16   * when the the Mule XML configuration is processed.
17   */
18  public class ContainerKeyPair
19  {
20      private final String containerName;
21      private final Object key;
22      private final boolean required;
23  
24      public ContainerKeyPair(String containerName, Object key)
25      {
26          this.containerName = containerName;
27          this.key = key;
28          this.required = true;
29      }
30  
31      public ContainerKeyPair(String containerName, Object key, boolean required)
32      {
33          this.containerName = containerName;
34          this.key = key;
35          this.required = required;
36      }
37  
38      public String getContainerName()
39      {
40          return containerName;
41      }
42  
43      public Object getKey()
44      {
45          return key;
46      }
47  
48      public boolean isRequired()
49      {
50          return required;
51      }
52  
53      // here we only return the key value as string so that
54      // containers that have no notion of this object can still
55      // look up objects by calling the toString method on this object
56      public String toString()
57      {
58          return key.toString();
59      }
60  
61      public String toFullString()
62      {
63          return "Container Key{key=" + key.toString() + ", container=" + containerName + ", required="
64                 + required + "}";
65      }
66  
67      public boolean equals(Object o)
68      {
69          if (this == o)
70          {
71              return true;
72          }
73          if (o == null || getClass() != o.getClass())
74          {
75              return false;
76          }
77  
78          final ContainerKeyPair that = (ContainerKeyPair) o;
79  
80          if (!containerName.equals(that.containerName))
81          {
82              return false;
83          }
84          if (!key.equals(that.key))
85          {
86              return false;
87          }
88  
89          return true;
90      }
91  
92      public int hashCode()
93      {
94          return 29 * containerName.hashCode() + key.hashCode();
95      }
96  }