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.config.attribute.resolver.attributeDefinition;
18  
19  import java.util.List;
20  import java.util.Locale;
21  import java.util.Map;
22  
23  import org.opensaml.xml.util.DatatypeHelper;
24  
25  import edu.internet2.middleware.shibboleth.common.attribute.encoding.AttributeEncoder;
26  import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.attributeDefinition.BaseAttributeDefinition;
27  import edu.internet2.middleware.shibboleth.common.config.attribute.resolver.AbstractResolutionPluginFactoryBean;
28  
29  /**
30   * Base Spring factory bean that produces attribute definitions.
31   */
32  public abstract class BaseAttributeDefinitionFactoryBean extends AbstractResolutionPluginFactoryBean {
33  
34      /** Attribute ID of the source attribute. */
35      private String sourceAttributeId;
36  
37      /** Whether attributes produced by the definition should be released outside the resolver. */
38      private boolean dependencyOnly;
39  
40      /** Encoders for the attributes. */
41      private List<AttributeEncoder> attributeEncoders;
42  
43      /** Localized human intelligible attribute name. */
44      private Map<Locale, String> displayNames;
45  
46      /** Localized human readable description of attribute. */
47      private Map<Locale, String> displayDescriptions;
48  
49      /**
50       * Gets the encoders for the attributes.
51       * 
52       * @return encoders for the attributes
53       */
54      public List<AttributeEncoder> getAttributeEncoders() {
55          return attributeEncoders;
56      }
57  
58      /**
59       * Gets the localized human readable description of attribute.
60       * 
61       * @return human readable description of attribute
62       */
63      public Map<Locale, String> getDisplayDescriptions() {
64          return displayDescriptions;
65      }
66  
67      /**
68       * Gets the localized human readable name of the attribute.
69       * 
70       * @return human readable name of the attribute
71       */
72      public Map<Locale, String> getDisplayNames() {
73          return displayNames;
74      }
75  
76      /**
77       * Gets the ID of the attribute that serves as the source of information for the attribute definition.
78       * 
79       * @return ID of the attribute that serves as the source of information for the attribute definition
80       */
81      public String getSourceAttributeId() {
82          return sourceAttributeId;
83      }
84  
85      /**
86       * Gets whether attributes produced by the definition should be released outside the resolver.
87       * 
88       * @return whether attributes produced by the definition should be released outside the resolver
89       */
90      public boolean isDependencyOnly() {
91          return dependencyOnly;
92      }
93  
94      /**
95       * Populates the attribute definition with information from this factory.
96       * 
97       * @param definition attribute definition to populate
98       */
99      protected void populateAttributeDefinition(BaseAttributeDefinition definition) {
100         definition.setDependencyOnly(isDependencyOnly());
101 
102         if (getDisplayNames() != null) {
103             definition.getDisplayNames().putAll(getDisplayNames());
104         }
105 
106         if (getDisplayDescriptions() != null) {
107             definition.getDisplayDescriptions().putAll(getDisplayDescriptions());
108         }
109 
110         if (getDependencyIds() != null) {
111             definition.getDependencyIds().addAll(getDependencyIds());
112         }
113 
114         if (getAttributeEncoders() != null) {
115             definition.getAttributeEncoders().addAll(getAttributeEncoders());
116         }
117 
118         definition.setId(getPluginId());
119         definition.setSourceAttributeID(getSourceAttributeId());
120     }
121 
122     /**
123      * Sets the encoders for the attributes.
124      * 
125      * @param encoders encoders for the attributes
126      */
127     public void setAttributeEncoders(List<AttributeEncoder> encoders) {
128         attributeEncoders = encoders;
129     }
130 
131     /**
132      * Sets whether attributes produced by the definition should be released outside the resolver.
133      * 
134      * @param isDependencyOnly whether attributes produced by the definition should be released outside the resolver
135      */
136     public void setDependencyOnly(boolean isDependencyOnly) {
137         dependencyOnly = isDependencyOnly;
138     }
139 
140     /**
141      * Sets the human readable description of attribute.
142      * 
143      * @param descriptions human readable descriptions of attribute
144      */
145     public void setDisplayDescriptions(Map<Locale, String> descriptions) {
146         displayDescriptions = descriptions;
147     }
148 
149     /**
150      * Sets the human readable name of the attribute.
151      * 
152      * @param names human readable names of the attribute
153      */
154     public void setDisplayNames(Map<Locale, String> names) {
155         displayNames = names;
156     }
157 
158     /**
159      * Sets the ID of the attribute that serves as the source of information for the attribute definition.
160      * 
161      * @param id ID of the attribute that serves as the source of information for the attribute definition
162      */
163     public void setSourceAttributeId(String id) {
164         sourceAttributeId = DatatypeHelper.safeTrimOrNullString(id);
165     }
166 }