View Javadoc

1   /*
2    * Licensed to the University Corporation for Advanced Internet Development, 
3    * Inc. (UCAID) under one or more contributor license agreements.  See the 
4    * NOTICE file distributed with this work for additional information regarding
5    * copyright ownership. The UCAID licenses this file to You under the Apache 
6    * License, Version 2.0 (the "License"); you may not use this file except in 
7    * compliance with the License.  You may obtain a copy of the License at
8    *
9    *    http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.attributeDefinition;
19  
20  import java.util.List;
21  import java.util.Locale;
22  import java.util.Map;
23  
24  import edu.internet2.middleware.shibboleth.common.attribute.BaseAttribute;
25  import edu.internet2.middleware.shibboleth.common.attribute.encoding.AttributeEncoder;
26  import edu.internet2.middleware.shibboleth.common.attribute.resolver.AttributeResolutionException;
27  import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.ShibbolethResolutionContext;
28  
29  /**
30   * Wrapper for an {@link AttributeDefinition} within a {@link ShibbolethResolutionContext}. This wrapper ensures that
31   * the definition is resolved only once per context.
32   */
33  public class ContextualAttributeDefinition implements AttributeDefinition {
34  
35      /** Wrapped attribute definition. */
36      private AttributeDefinition definition;
37  
38      /** Cached result of resolving the attribute definition. */
39      private BaseAttribute attribute;
40  
41      /**
42       * Constructor.
43       * 
44       * @param newDefinition attribute definition to wrap
45       */
46      public ContextualAttributeDefinition(AttributeDefinition newDefinition) {
47          definition = newDefinition;
48      }
49  
50      /** {@inheritDoc} */
51      public boolean equals(Object obj) {
52          return definition.equals(obj);
53      }
54  
55      /** {@inheritDoc} */
56      public List<AttributeEncoder> getAttributeEncoders() {
57          return definition.getAttributeEncoders();
58      }
59  
60      /** {@inheritDoc} */
61      public List<String> getDependencyIds() {
62          return definition.getDependencyIds();
63      }
64  
65      /** {@inheritDoc} */
66      public Map<Locale, String> getDisplayDescriptions() {
67          return definition.getDisplayDescriptions();
68      }
69  
70      /** {@inheritDoc} */
71      public Map<Locale, String> getDisplayNames() {
72          return definition.getDisplayNames();
73      }
74  
75      /** {@inheritDoc} */
76      public String getId() {
77          return definition.getId();
78      }
79  
80      /** {@inheritDoc} */
81      public int hashCode() {
82          return definition.hashCode();
83      }
84  
85      /** {@inheritDoc} */
86      public boolean isDependencyOnly() {
87          return definition.isDependencyOnly();
88      }
89  
90      /** {@inheritDoc} */
91      public BaseAttribute resolve(ShibbolethResolutionContext resolutionContext) throws AttributeResolutionException {
92          if (attribute == null) {
93              attribute = definition.resolve(resolutionContext);
94          }
95  
96          return attribute;
97      }
98  
99      /** {@inheritDoc} */
100     public void validate() throws AttributeResolutionException {
101         definition.validate();
102     }
103 }