[dna-commits] DNA SVN: r398 - in trunk/connectors/dna-connector-federation/src/main: resources/org/jboss/dna/connector/federation and 1 other directory.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Thu Aug 7 11:38:59 EDT 2008


Author: rhauch
Date: 2008-08-07 11:38:59 -0400 (Thu, 07 Aug 2008)
New Revision: 398

Modified:
   trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
   trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederationI18n.java
   trunk/connectors/dna-connector-federation/src/main/resources/org/jboss/dna/connector/federation/FederationI18n.properties
Log:
DNA-115 - Create federation service 
http://jira.jboss.com/jira/browse/DNA-115

Added some exception handling in FederatedRepositorySource to better explain a ClastCastException when looking up objects out of JNDI.

Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java	2008-08-06 19:59:12 UTC (rev 397)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java	2008-08-07 15:38:59 UTC (rev 398)
@@ -525,16 +525,20 @@
     @Override
     protected synchronized RepositoryConnection createConnection() throws RepositorySourceException {
         if (getName() == null) {
-            throw new RepositorySourceException(FederationI18n.propertyIsRequired.text("name"));
+            I18n msg = FederationI18n.propertyIsRequired;
+            throw new RepositorySourceException(getName(), msg.text("name"));
         }
         if (getExecutionContextFactoryJndiName() == null) {
-            throw new RepositorySourceException(FederationI18n.propertyIsRequired.text("execution context factory JNDI name"));
+            I18n msg = FederationI18n.propertyIsRequired;
+            throw new RepositorySourceException(getName(), msg.text("execution context factory JNDI name"));
         }
         if (getSecurityDomain() == null) {
-            throw new RepositorySourceException(FederationI18n.propertyIsRequired.text("security domain"));
+            I18n msg = FederationI18n.propertyIsRequired;
+            throw new RepositorySourceException(getName(), msg.text("security domain"));
         }
         if (getRepositorySourceRegistryJndiName() == null) {
-            throw new RepositorySourceException(FederationI18n.propertyIsRequired.text("repository source registry JNDI name"));
+            I18n msg = FederationI18n.propertyIsRequired;
+            throw new RepositorySourceException(getName(), msg.text("repository source registry JNDI name"));
         }
         // Find the repository ...
         FederatedRepository repository = getRepository();
@@ -569,12 +573,21 @@
             Context jndiContext = getContext();
             if (jndiName != null && jndiName.trim().length() != 0) {
                 // Look for an existing repository in JNDI ...
+                Object object = null;
                 try {
                     if (jndiContext == null) jndiContext = new InitialContext();
-                    repository = (FederatedRepository)jndiContext.lookup(jndiName);
+                    object = jndiContext.lookup(jndiName);
+                    if (object != null) repository = (FederatedRepository)object;
+                } catch (ClassCastException err) {
+                    I18n msg = FederationI18n.objectFoundInJndiWasNotOfExpectedType;
+                    String className = object != null ? object.getClass().getName() : "null";
+                    throw new RepositorySourceException(getName(), msg.text(jndiName,
+                                                                            this.getName(),
+                                                                            FederatedRepository.class.getName(),
+                                                                            className), err);
                 } catch (Throwable err) {
                     I18n msg = FederationI18n.unableToFindFederatedRepositoryInJndi;
-                    throw new RepositorySourceException(msg.text(this.sourceName, jndiName), err);
+                    throw new RepositorySourceException(getName(), msg.text(this.sourceName, jndiName), err);
                 }
             }
 
@@ -595,17 +608,26 @@
         Context context = getContext();
         String jndiName = getExecutionContextFactoryJndiName();
         if (jndiName != null && jndiName.trim().length() != 0) {
+            Object object = null;
             try {
                 if (context == null) context = new InitialContext();
-                factory = (ExecutionContextFactory)context.lookup(jndiName);
+                object = context.lookup(jndiName);
+                if (object != null) factory = (ExecutionContextFactory)object;
+            } catch (ClassCastException err) {
+                I18n msg = FederationI18n.objectFoundInJndiWasNotOfExpectedType;
+                String className = object != null ? object.getClass().getName() : "null";
+                throw new RepositorySourceException(getName(), msg.text(jndiName,
+                                                                        this.getName(),
+                                                                        ExecutionContextFactory.class.getName(),
+                                                                        className), err);
             } catch (Throwable err) {
                 I18n msg = FederationI18n.unableToFindExecutionContextFactoryInJndi;
-                throw new RepositorySourceException(msg.text(this.sourceName, jndiName), err);
+                throw new RepositorySourceException(getName(), msg.text(this.sourceName, jndiName), err);
             }
         }
         if (factory == null) {
             I18n msg = FederationI18n.unableToFindExecutionContextFactoryInJndi;
-            throw new RepositorySourceException(msg.text(this.sourceName, jndiName));
+            throw new RepositorySourceException(getName(), msg.text(this.sourceName, jndiName));
         }
         String securityDomain = getSecurityDomain();
         CallbackHandler handler = createCallbackHandler();
@@ -613,7 +635,7 @@
             return factory.create(securityDomain, handler);
         } catch (LoginException e) {
             I18n msg = FederationI18n.unableToCreateExecutionContext;
-            throw new RepositorySourceException(msg.text(this.sourceName, jndiName, securityDomain), e);
+            throw new RepositorySourceException(getName(), msg.text(this.sourceName, jndiName, securityDomain), e);
         }
     }
 
@@ -622,17 +644,26 @@
         Context context = getContext();
         String jndiName = getRepositorySourceRegistryJndiName();
         if (jndiName != null && jndiName.trim().length() != 0) {
+            Object object = null;
             try {
                 if (context == null) context = new InitialContext();
-                factories = (RepositorySourceRegistry)context.lookup(jndiName);
+                object = context.lookup(jndiName);
+                if (object != null) factories = (RepositorySourceRegistry)object;
+            } catch (ClassCastException err) {
+                I18n msg = FederationI18n.objectFoundInJndiWasNotOfExpectedType;
+                String className = object != null ? object.getClass().getName() : "null";
+                throw new RepositorySourceException(getName(), msg.text(jndiName,
+                                                                        this.getName(),
+                                                                        RepositorySourceRegistry.class.getName(),
+                                                                        className), err);
             } catch (Throwable err) {
                 I18n msg = FederationI18n.unableToFindRepositoryConnectionFactoriesInJndi;
-                throw new RepositorySourceException(msg.text(this.sourceName, jndiName), err);
+                throw new RepositorySourceException(getName(), msg.text(this.sourceName, jndiName), err);
             }
         }
         if (factories == null) {
             I18n msg = FederationI18n.noRepositoryConnectionFactories;
-            throw new RepositorySourceException(msg.text(this.repositoryName));
+            throw new RepositorySourceException(getName(), msg.text(this.repositoryName));
         }
         return factories;
     }

Modified: trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederationI18n.java
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederationI18n.java	2008-08-06 19:59:12 UTC (rev 397)
+++ trunk/connectors/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederationI18n.java	2008-08-07 15:38:59 UTC (rev 398)
@@ -38,6 +38,7 @@
     public static I18n unableToFindExecutionContextFactoryInJndi;
     public static I18n unableToCreateExecutionContext;
     public static I18n unableToFindRepositoryConnectionFactoriesInJndi;
+    public static I18n objectFoundInJndiWasNotOfExpectedType;
     public static I18n noRepositoryConnectionFactories;
     public static I18n federatedRepositoryCannotBeFound;
     public static I18n unableToAuthenticateConnectionToFederatedRepository;

Modified: trunk/connectors/dna-connector-federation/src/main/resources/org/jboss/dna/connector/federation/FederationI18n.properties
===================================================================
--- trunk/connectors/dna-connector-federation/src/main/resources/org/jboss/dna/connector/federation/FederationI18n.properties	2008-08-06 19:59:12 UTC (rev 397)
+++ trunk/connectors/dna-connector-federation/src/main/resources/org/jboss/dna/connector/federation/FederationI18n.properties	2008-08-07 15:38:59 UTC (rev 398)
@@ -27,6 +27,7 @@
 unableToFindExecutionContextFactoryInJndi = Unable to find an ExecutionContextFactory instance in JNDI under "{1}" when creating connection to federated source "{0}"
 unableToCreateExecutionContext = Unable to create ExecutionContext for connection to federated source "{0}" when using factory in JNDI under "{1}" and security domain "{2}"
 unableToFindRepositoryConnectionFactoriesInJndi = Unable to find an RepositoryConnectionFactories instance in JNDI under "{1}" when creating connection to federated source "{0}"
+objectFoundInJndiWasNotOfExpectedType = Object in JNDI at {0} found by FederatedRepositorySource {1} was expected to be a {2} but instead was a {2}
 noRepositoryConnectionFactories = No RepositoryConnectionFactories instance was specified directly or indirectly found in JNDI when creating connection to federated source "{0}"
 federatedRepositoryCannotBeFound = The federated repository "{0}" cannot be found
 unableToAuthenticateConnectionToFederatedRepository = Unable to authenticate "{1}" for repository "{0}"




More information about the dna-commits mailing list