View Javadoc

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