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.dataConnector;
18  
19  import java.util.List;
20  import java.util.Map;
21  
22  import edu.internet2.middleware.shibboleth.common.attribute.BaseAttribute;
23  import edu.internet2.middleware.shibboleth.common.attribute.resolver.AttributeResolutionException;
24  import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.ShibbolethResolutionContext;
25  
26  /**
27   * Wrapper for a {@link DataConnector} within a resolution context. This wrapper ensures that the connector is resolved
28   * only once per context.
29   */
30  public class ContextualDataConnector implements DataConnector {
31  
32      /** Wrapped data connector. */
33      private DataConnector connector;
34  
35      /** Cached result of resolving the data connector. */
36      private Map<String, BaseAttribute> attributes;
37  
38      /**
39       * Constructor.
40       * 
41       * @param newConnector data connector to wrap
42       */
43      public ContextualDataConnector(DataConnector newConnector) {
44          this.connector = newConnector;
45      }
46  
47      /** {@inheritDoc} */
48      public boolean equals(Object obj) {
49          return connector.equals(obj);
50      }
51  
52      /** {@inheritDoc} */
53      public int hashCode() {
54          return connector.hashCode();
55      }
56  
57      /** {@inheritDoc} */
58      public List<String> getDependencyIds() {
59          return connector.getDependencyIds();
60      }
61  
62      /** {@inheritDoc} */
63      public String getFailoverDependencyId() {
64          return connector.getFailoverDependencyId();
65      }
66  
67      /** {@inheritDoc} */
68      public String getId() {
69          return connector.getId();
70      }
71  
72      /** {@inheritDoc} */
73      public Map<String, BaseAttribute> resolve(ShibbolethResolutionContext resolutionContext)
74              throws AttributeResolutionException {
75          if (attributes == null) {
76              attributes = connector.resolve(resolutionContext);
77          }
78  
79          return attributes;
80      }
81  
82      /** {@inheritDoc} */
83      public void validate() throws AttributeResolutionException {
84          connector.validate();
85      }
86  }