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  
21  import org.opensaml.xml.util.DatatypeHelper;
22  
23  import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.attributeDefinition.MappedAttributeDefinition;
24  import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.attributeDefinition.ValueMap;
25  
26  /**
27   * Spring factory bean that produces {@link MappedAttributeDefinition}s.
28   */
29  public class MappedAttributeDefinitionFactoryBean extends BaseAttributeDefinitionFactoryBean {
30  
31      /** The default return value. */
32      private String defaultValue;
33  
34      /** Whether the definition passes thru unmatched values. */
35      private boolean passThru;
36  
37      /** Value maps. */
38      private List<ValueMap> valueMaps;
39  
40      /** {@inheritDoc} */
41      public Class getObjectType() {
42          return MappedAttributeDefinition.class;
43      }
44  
45      /**
46       * Gets the default return value.
47       * 
48       * @return the default return value
49       */
50      public String getDefaultValue() {
51          return defaultValue;
52      }
53  
54      /**
55       * Get whether the definition passes thru unmatched values.
56       * 
57       * @return whether the definition passes thru unmatched values
58       */
59      public boolean isPassThru() {
60          return passThru;
61      }
62  
63      /**
64       * Gets the value maps.
65       * 
66       * @return the value maps.
67       */
68      public List<ValueMap> getValueMaps() {
69          return valueMaps;
70      }
71  
72      /**
73       * Sets the default return value.
74       * 
75       * @param newDefaultValue the default return value
76       */
77      public void setDefaultValue(String newDefaultValue) {
78          defaultValue = DatatypeHelper.safeTrimOrNullString(newDefaultValue);
79      }
80  
81      /**
82       * Sets whether the definition passes thru unmatched values.
83       * 
84       * @param newPassThru whether the definition passes thru unmatched values
85       */
86      public void setPassThru(boolean newPassThru) {
87          passThru = newPassThru;
88      }
89  
90      /**
91       * Sets the value maps.
92       * 
93       * @param newValueMaps the value maps
94       */
95      public void setValueMaps(List<ValueMap> newValueMaps) {
96          valueMaps = newValueMaps;
97      }
98  
99      /** {@inheritDoc} */
100     protected Object createInstance() throws Exception {
101         MappedAttributeDefinition definition = new MappedAttributeDefinition();
102         populateAttributeDefinition(definition);
103 
104         definition.setDefaultValue(defaultValue);
105 
106         definition.setPassThru(passThru);
107 
108         definition.getValueMaps().addAll(valueMaps);
109 
110         return definition;
111     }
112 
113 }