2 package edu.internet2.middleware.shibboleth.metadata;
5 * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import org.apache.log4j.Logger;
21 import org.opensaml.saml2.metadata.provider.MetadataProvider;
22 import org.opensaml.saml2.metadata.provider.MetadataProviderException;
23 import org.w3c.dom.Element;
25 public class MetadataProviderFactory {
27 private static Logger log = Logger.getLogger(MetadataProviderFactory.class.getName());
29 public static MetadataProvider loadProvider(Element e) throws MetadataProviderException {
31 String className = e.getAttribute("type");
32 if (className == null || className.equals("")) {
33 log.error("Metadata Provider requires specification of the attribute \"type\".");
34 throw new MetadataProviderException("Failed to initialize Metadata Provider.");
37 Class[] params = {Class.forName("org.w3c.dom.Element"),};
38 return (MetadataProvider) Class.forName(className).getConstructor(params).newInstance(new Object[]{e});
40 } catch (Exception loaderException) {
41 log.error("Failed to load Metadata Provider implementation class: " + loaderException);
42 Throwable cause = loaderException.getCause();
43 while (cause != null) {
44 log.error("caused by: " + cause);
45 cause = cause.getCause();
47 throw new MetadataProviderException("Failed to initialize Metadata Provider.");