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