View Javadoc

1   /*
2    * Copyright [2006] [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.resolver.provider.attributeDefinition;
18  
19  import java.util.List;
20  import java.util.Locale;
21  import java.util.Map;
22  
23  import edu.internet2.middleware.shibboleth.common.attribute.BaseAttribute;
24  import edu.internet2.middleware.shibboleth.common.attribute.encoding.AttributeEncoder;
25  import edu.internet2.middleware.shibboleth.common.attribute.resolver.AttributeResolutionException;
26  import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.ShibbolethResolutionContext;
27  
28  /**
29   * Wrapper for an {@link AttributeDefinition} within a {@link ShibbolethResolutionContext}. This wrapper ensures that
30   * the definition is resolved only once per context.
31   */
32  public class ContextualAttributeDefinition implements AttributeDefinition {
33  
34      /** Wrapped attribute definition. */
35      private AttributeDefinition definition;
36  
37      /** Cached result of resolving the attribute definition. */
38      private BaseAttribute attribute;
39  
40      /**
41       * Constructor.
42       * 
43       * @param newDefinition attribute definition to wrap
44       */
45      public ContextualAttributeDefinition(AttributeDefinition newDefinition) {
46          definition = newDefinition;
47      }
48  
49      /** {@inheritDoc} */
50      public boolean equals(Object obj) {
51          return definition.equals(obj);
52      }
53  
54      /** {@inheritDoc} */
55      public List<AttributeEncoder> getAttributeEncoders() {
56          return definition.getAttributeEncoders();
57      }
58  
59      /** {@inheritDoc} */
60      public List<String> getDependencyIds() {
61          return definition.getDependencyIds();
62      }
63  
64      /** {@inheritDoc} */
65      public Map<Locale, String> getDisplayDescriptions() {
66          return definition.getDisplayDescriptions();
67      }
68  
69      /** {@inheritDoc} */
70      public Map<Locale, String> getDisplayNames() {
71          return definition.getDisplayNames();
72      }
73  
74      /** {@inheritDoc} */
75      public String getId() {
76          return definition.getId();
77      }
78  
79      /** {@inheritDoc} */
80      public int hashCode() {
81          return definition.hashCode();
82      }
83  
84      /** {@inheritDoc} */
85      public boolean isDependencyOnly() {
86          return definition.isDependencyOnly();
87      }
88  
89      /** {@inheritDoc} */
90      public BaseAttribute resolve(ShibbolethResolutionContext resolutionContext) throws AttributeResolutionException {
91          if (attribute == null) {
92              attribute = definition.resolve(resolutionContext);
93          }
94  
95          return attribute;
96      }
97  
98      /** {@inheritDoc} */
99      public void validate() throws AttributeResolutionException {
100         definition.validate();
101     }
102 }