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.attribute.encoding.provider;
18  
19  import org.opensaml.Configuration;
20  import org.opensaml.common.SAMLObjectBuilder;
21  import org.opensaml.saml1.core.Attribute;
22  
23  import edu.internet2.middleware.shibboleth.common.attribute.encoding.SAML1AttributeEncoder;
24  
25  /**
26   * Base for encoders that produce {@link Attribute}s.
27   */
28  public abstract class AbstractSAML1AttributeEncoder extends AbstractAttributeEncoder<Attribute> implements
29          SAML1AttributeEncoder {
30  
31      /** Attribute factory. */
32      protected final SAMLObjectBuilder<Attribute> attributeBuilder;
33  
34      /** Namespace of attribute. */
35      private String namespace;
36  
37      /** Constructor. */
38      protected AbstractSAML1AttributeEncoder() {
39          attributeBuilder = (SAMLObjectBuilder<Attribute>) Configuration.getBuilderFactory().getBuilder(
40                  Attribute.DEFAULT_ELEMENT_NAME);
41      }
42  
43      /** {@inheritDoc} */
44      public String getNamespace() {
45          return namespace;
46      }
47  
48      /** {@inheritDoc} */
49      public void setNamespace(String newNamespace) {
50          namespace = newNamespace;
51      }
52  
53      /**
54       * Populates the attribute with attribute name and namespace.
55       * 
56       * @param attribute to populate
57       */
58      protected void populateAttribute(Attribute attribute) {
59          attribute.setAttributeName(getAttributeName());
60          attribute.setAttributeNamespace(getNamespace());
61      }
62  }