Revision: 1625 http://svn.sourceforge.net/spring-rich-c/?rev=1625&view=rev Author: kevinstembridge Date: 2007-01-08 05:01:30 -0800 (Mon, 08 Jan 2007)
Log Message: ----------- Added javadoc, simplified implementation of getViewDescriptor Modified Paths: -------------- trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/BeanFactoryViewDescriptorRegistry.java Modified: trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/BeanFactoryViewDescriptorRegistry.java =================================================================== --- trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/BeanFactoryViewDescriptorRegistry.java 2007-01-08 12:59:53 UTC (rev 1624) +++ trunk/spring-richclient/support/src/main/java/org/springframework/richclient/application/support/BeanFactoryViewDescriptorRegistry.java 2007-01-08 13:01:30 UTC (rev 1625) @@ -17,37 +17,57 @@ import java.util.Map; +import org.springframework.beans.factory.BeanNotOfRequiredTypeException; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.context.support.ApplicationObjectSupport; import org.springframework.richclient.application.ViewDescriptor; import org.springframework.richclient.application.ViewDescriptorRegistry; +import org.springframework.richclient.util.Assert; /** - * Simple <code>ViewRegistry</code> that pulls singleton view definitions out - * of a spring application context. + * A simple [EMAIL PROTECTED] ViewDescriptorRegistry} implementation that pulls singleton view definitions out + * of a spring application context. This class is intended to be managed by a Spring IoC container. + * If being created programatically, be sure to call the + * [EMAIL PROTECTED] #setApplicationContext(org.springframework.context.ApplicationContext)} method. * + * * @author Keith Donald + * @author Kevin Stembridge */ -public class BeanFactoryViewDescriptorRegistry extends ApplicationObjectSupport - implements ViewDescriptorRegistry { +public class BeanFactoryViewDescriptorRegistry extends ApplicationObjectSupport implements ViewDescriptorRegistry { + /** + * [EMAIL PROTECTED] + */ public ViewDescriptor[] getViewDescriptors() { Map beans = getApplicationContext().getBeansOfType(ViewDescriptor.class, false, false); return (ViewDescriptor[])beans.values().toArray(new ViewDescriptor[beans.size()]); } - + /** + * Returns the view descriptor with the given identifier, or null if no such bean definition + * with the given name exists in the current application context. + * + * @param viewName The bean name of the view descriptor that is to be retrieved from the + * underlying application context. Must not be null. + * + * @throws IllegalArgumentException if [EMAIL PROTECTED] viewName} is null. + * @throws BeanNotOfRequiredTypeException if the bean retrieved from the underlying application + * context is not of type [EMAIL PROTECTED] ViewDescriptor}. + * + */ public ViewDescriptor getViewDescriptor(String viewName) { - final Object bean = getApplicationContext().getBean(viewName); + + Assert.required(viewName, "viewName"); + try { - return (ViewDescriptor)bean; + return (ViewDescriptor) getApplicationContext().getBean(viewName, ViewDescriptor.class); } - catch (ClassCastException e) { - ClassCastException exp = new ClassCastException(bean.getClass() + " is not a " + ViewDescriptor.class + - " when looking up '" + viewName + "'"); - exp.setStackTrace(e.getStackTrace()); - throw exp; + catch (NoSuchBeanDefinitionException e) { + return null; } + } -} \ No newline at end of file +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ spring-rich-c-cvs mailing list spring-rich-c-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs