[java-identity-provider COMMIT] in /trunk/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/re...

noreply at shibboleth.net noreply at shibboleth.net
Fri Jun 7 00:58:06 EDT 2013


Author: dfisher
Date: Fri Jun  7 00:58:06 2013
New Revision: 4524

URL: http://svn.shibboleth.net/view/java-identity-provider?rev=4524&view=rev
Log:
Refactor Ldap and Rdbms connectors to use java.beans.Introspector for retrieving beans from the Spring bean factory.
Resolves IDP-285.

Modified:
    trunk/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/dc/BaseDataConnectorParser.java
    trunk/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/dc/ldap/LdapDataConnectorParser.java
    trunk/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/dc/rdbms/RdbmsDataConnectorParser.java

Modified: trunk/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/dc/BaseDataConnectorParser.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/dc/BaseDataConnectorParser.java?rev=4524&r1=4523&r2=4524&view=diff
==============================================================================
--- trunk/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/dc/BaseDataConnectorParser.java (original)
+++ trunk/idp-attribute-resolver-spring/src/main/java/net/shibboleth/idp/attribute/resolver/spring/dc/BaseDataConnectorParser.java Fri Jun  7 00:58:06 2013
@@ -17,6 +17,10 @@
 
 package net.shibboleth.idp.attribute.resolver.spring.dc;
 
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.util.List;
@@ -25,6 +29,7 @@
 import javax.annotation.Nullable;
 import javax.xml.namespace.QName;
 
+import net.shibboleth.idp.attribute.resolver.BaseDataConnector;
 import net.shibboleth.idp.attribute.resolver.spring.AttributeResolverNamespaceHandler;
 import net.shibboleth.idp.attribute.resolver.spring.BaseResolverPluginParser;
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
@@ -77,8 +82,7 @@
                 ElementSupport.getChildElements(config, FAILOVER_DATA_CONNECTOR_ELEMENT_NAME);
         if (failoverConnector != null && !failoverConnector.isEmpty()) {
             String connectorId = StringSupport.trimOrNull(failoverConnector.get(0).getAttributeNS(null, "ref"));
-            log.debug("{} setting the following failover data connector dependencies {}",
-                    getLogPrefix(), connectorId);
+            log.debug("{} setting the following failover data connector dependencies {}", getLogPrefix(), connectorId);
             builder.addPropertyValue("failoverDataConnectorId", connectorId);
         }
     }
@@ -88,7 +92,7 @@
      * multiple <beans/> declarations, only the first is returned.
      * 
      * @param config to check for spring beans declaration
-     *
+     * 
      * @return spring beans element
      */
     @Nullable protected Element getSpringBeansElement(@Nullable final Element config) {
@@ -103,7 +107,7 @@
      * Creates a Spring bean factory from the supplied Spring beans element.
      * 
      * @param springBeans to create bean factory from
-     *
+     * 
      * @return bean factory
      */
     @Nonnull protected BeanFactory createBeanFactory(@Nonnull final Element springBeans) {
@@ -125,7 +129,7 @@
      * @param <T> type of bean to return
      * @param beanFactory to get the bean from
      * @param clazz type of the bean to retrieve
-     *
+     * 
      * @return spring bean
      */
     @Nullable protected <T> T getBean(@Nonnull final BeanFactory beanFactory, @Nonnull final Class<T> clazz) {
@@ -137,6 +141,47 @@
             log.debug("no spring bean configured of type {}", clazz);
         }
         return bean;
+    }
+
+    /**
+     * Returns the results of {@link Introspector#getBeanInfo(Class, Class)} for the supplied connector class.
+     * 
+     * @param connectorClass to introspect
+     * 
+     * @return property descriptors or null if an error occurred
+     */
+    @Nullable protected PropertyDescriptor[] getBeanPropertyDescriptors(
+            @Nonnull final Class<? extends BaseDataConnector> connectorClass) {
+        PropertyDescriptor[] descriptors = null;
+        try {
+            final BeanInfo info = Introspector.getBeanInfo(connectorClass, BaseDataConnector.class);
+            descriptors = info.getPropertyDescriptors();
+        } catch (IntrospectionException e) {
+            log.error("could not retrieve bean info for class {}", connectorClass, e);
+        }
+        return descriptors;
+    }
+
+    /**
+     * Gets the property descriptors for the supplied connector class and then retrieves the bean for each descriptor
+     * type. If a bean is found it is added to the supplied builder.
+     * 
+     * @param builder to add property values to
+     * @param beanFactory to retrieve bean configuration from
+     * @param connectorClass to read property descriptors from
+     */

[... 133 lines stripped ...]


More information about the commits mailing list