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.metadata;
19  
20  import org.opensaml.xml.util.DatatypeHelper;
21  import org.opensaml.xml.util.XMLHelper;
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
25  import org.springframework.beans.factory.xml.ParserContext;
26  import org.w3c.dom.Element;
27  
28  /** Base class for metadata providers that reload their metadata. */
29  public abstract class AbstractMetadataProviderBeanDefinitionParser extends BaseMetadataProviderBeanDefinitionParser {
30  
31      /** Class logger. */
32      private final Logger log = LoggerFactory.getLogger(AbstractMetadataProviderBeanDefinitionParser.class);
33  
34      /** {@inheritDoc} */
35      protected void doParse(Element config, ParserContext parserContext, BeanDefinitionBuilder builder) {
36          super.doParse(config, parserContext, builder);
37          
38          builder.setInitMethodName("initialize");
39  
40          String parserPoolRef = getParserPoolRef(config);
41          log.debug("Metadata provider using parser pool: {}", parserPoolRef);
42          builder.addPropertyReference("parserPool", parserPoolRef);
43  
44          boolean failFastInit = getFailFastInitialization(config);
45          log.debug("Metadata provider fail fast initialization enabled: {}", failFastInit);
46          builder.addPropertyValue("failFastInitialization", failFastInit);
47      }
48  
49      /**
50       * Gets the default parser pool reference for the metadata provider.
51       * 
52       * @param config metadata provider configuration element
53       * 
54       * @return parser pool reference
55       */
56      protected String getParserPoolRef(Element config) {
57          String parserPoolRef = null;
58          if (config.hasAttributeNS(null, "parerPoolRef")) {
59              parserPoolRef = DatatypeHelper.safeTrimOrNullString(config.getAttributeNS(null, "parserPoolRef"));
60          }
61  
62          if (parserPoolRef == null) {
63              parserPoolRef = "shibboleth.ParserPool";
64          }
65  
66          return parserPoolRef;
67      }
68      
69      /**
70       * Gets the fail fast initialization requirement for the metadata provider.
71       * 
72       * @param config metadata provider config
73       * 
74       * @return fail fast initialization requirement for the metadata provider
75       */
76      protected boolean getFailFastInitialization(Element config) {
77          boolean failFastInit = true;
78          if (config.hasAttributeNS(null, "failFastInitialization")) {
79              failFastInit = XMLHelper.getAttributeValueAsBoolean(config.getAttributeNodeNS(null,
80                      "failFastInitialization"));
81          }
82  
83          return failFastInit;
84      }
85  }