View Javadoc

1   /*
2    * Copyright [2007] [University Corporation for Advanced Internet Development, Inc.]
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package edu.internet2.middleware.shibboleth.common.attribute.provider;
18  
19  import org.opensaml.xml.util.DatatypeHelper;
20  
21  /**
22   * An attribute value with an associated scope.
23   */
24  public class ScopedAttributeValue {
25  
26      /** Value of the attribute. */
27      private String value;
28  
29      /** Scope of the attribute value. */
30      private String scope;
31  
32      /**
33       * Constructor.
34       * 
35       * @param attributeValue value of the attribute
36       * @param valueScope scope of the value
37       */
38      public ScopedAttributeValue(String attributeValue, String valueScope) {
39          value = DatatypeHelper.safeTrimOrNullString(attributeValue);
40          scope = DatatypeHelper.safeTrimOrNullString(valueScope);
41  
42          if (scope == null || value == null) {
43              throw new IllegalArgumentException("Attribute value and scope may not be null");
44          }
45      }
46  
47      /**
48       * Gets the value of the attribute.
49       * 
50       * @return value of the attribute
51       */
52      public String getValue() {
53          return value;
54      }
55  
56      /**
57       * Gets the scope of the value.
58       * 
59       * @return scope of the value
60       */
61      public String getScope() {
62          return scope;
63      }
64  
65      /** {@inheritDoc} */
66      public String toString() {
67          return value + ":" + scope;
68      }
69  
70      /** {@inheritDoc} */
71      public int hashCode() {
72          int hash = 1;
73          hash = hash * 31 + value.hashCode();
74          hash = hash * 31 + scope.hashCode();
75  
76          return hash;
77      }
78  
79      /** {@inheritDoc} */
80      public boolean equals(Object obj) {
81          if (this == obj) {
82              return true;
83          }
84  
85          if (!(obj instanceof ScopedAttributeValue)) {
86              return false;
87          }
88  
89          ScopedAttributeValue otherValue = (ScopedAttributeValue) obj;
90  
91          return DatatypeHelper.safeEquals(getValue(), otherValue.getValue())
92                  && DatatypeHelper.safeEquals(getScope(), otherValue.getScope());
93      }
94  }