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