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.dataConnector;
18  
19  import java.util.List;
20  import java.util.Map;
21  
22  import javax.xml.namespace.QName;
23  
24  import org.opensaml.xml.util.DatatypeHelper;
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
28  import org.springframework.beans.factory.xml.ParserContext;
29  import org.w3c.dom.Element;
30  
31  import edu.internet2.middleware.shibboleth.common.config.attribute.resolver.AbstractResolutionPlugInBeanDefinitionParser;
32  import edu.internet2.middleware.shibboleth.common.config.attribute.resolver.AttributeResolverNamespaceHandler;
33  
34  /**
35   * Base spring bean definition parser for data connectors. DataConnector implementations should provide a custom
36   * BeanDefinitionParser by extending this class and overriding the
37   * {@link #doParse(String, Element, Map, BeanDefinitionBuilder, ParserContext)} method to parse any additional
38   * attributes or elements it requires. Standard attributes and elements defined by the ResolutionPlugIn and
39   * DataConnector schemas will automatically attempt to be parsed.
40   */
41  public abstract class BaseDataConnectorBeanDefinitionParser extends AbstractResolutionPlugInBeanDefinitionParser {
42  
43      /** Failover data connector attribute name. */
44      public static final QName FAILOVER_DATA_CONNECTOR_ELEMENT_NAME = new QName(
45              AttributeResolverNamespaceHandler.NAMESPACE, "FailoverDataConnector");
46  
47      /** Log4j logger. */
48      private final Logger log = LoggerFactory.getLogger(BaseDataConnectorBeanDefinitionParser.class);
49  
50      /** {@inheritDoc} */
51      protected void doParse(String pluginId, Element pluginConfig, Map<QName, List<Element>> pluginConfigChildren,
52              BeanDefinitionBuilder pluginBuilder, ParserContext parserContext) {
53  
54          List<Element> failoverConnector = pluginConfigChildren.get(FAILOVER_DATA_CONNECTOR_ELEMENT_NAME);
55          if (failoverConnector != null && !failoverConnector.isEmpty()) {
56              String connectorId = DatatypeHelper.safeTrimOrNullString(failoverConnector.get(0).getAttributeNS(null,
57                      "ref"));
58              log.debug("Setting the following failover data connector dependencies for plugin {}: {}", pluginId,
59                      connectorId);
60              pluginBuilder.addPropertyValue("failoverDataConnectorIds", connectorId);
61          }
62      }
63  }