Results 1 to 7 of 7

Thread: VAlidating Class names/Id string

  1. #1
    Join Date
    Jan 2007
    Posts
    14

    Default VAlidating Class names/Id string

    Is it possible to have Spring check at compile time that your references to the beans in the config file are correct, and that your config file does not have any typos in class names. ?

    ie that you don't ask the factory for a bean called getBean("MyBean") when you should be using getBean("MyOwnBean")

  2. #2
    Join Date
    Aug 2004
    Location
    Frankfurt/Main, Germany
    Posts
    253

    Default

    Quote Originally Posted by jfrain2007 View Post
    Is it possible to have Spring check at compile time that your references to the beans in the config file are correct, and that your config file does not have any typos in class names. ?
    This is what Spring IDE's BeansConfigValidator is about.

    Torsten

  3. #3
    Join Date
    Jan 2007
    Posts
    14

    Post

    How is this BeansConfigValidator run? manually/automatically?
    Spring IDE does not catch the "badID" I'm using when getting a Bean and also it doesn't spot the invalid class name "BadAdvisor" I use for the Advisor.

    What am I missing?

    Code:
    public class Driver
    {
    	
    	public static void main(String[] args)
    	{
    		ApplicationContext ac = 
    			new FileSystemXmlApplicationContext("applicationcontext.xml");
    		MyBeanInt bean1 = (MyBeanInt) ac.getBean("BadID");
    		bean1.execute();
    		bean1.doit();
    	}
    }
     
    ***********************
     
    public class MyAdvice implements MethodBeforeAdvice
    {
     
    	/**
    	 *
    	 */
     
    	public void before(Method method, Object[] args, Object target)
    			throws Throwable
    	{
    		
    		System.out.println(">>>" + method.getName() + "()");
    	}
     
    }
     
    ********************
     
    public class MyBean implements MyBeanInt
    {
    	public void execute()
    	{
    		System.out.println("execute doing stuff");
    	}
    	
    	public void doit()
    	{
    		System.out.println("doit doing stuff");
    	}
    }
     
    *************************
     
    public interface MyBeanInt
    {
    	public abstract void execute();
     
    	public abstract void doit();
    }
    ***********************
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
     
    <beans>
     
    	<bean 	id="MyBeanProxyWithMethodMatchingPattern" 
    			class="org.springframework.aop.framework.ProxyFactoryBean" >	
    		<property name="target">
    			<ref local="MyTarget">
    			</ref>
    		</property>
    		<property name="interceptorNames">
    			<list>
    				<value>advisor</value>
    			</list>
    		</property>		
    	</bean>	
    	
    	<bean id="MyTarget" class="MyBean" >	
    	</bean>
    	
    	<bean 	id="advice" class="MyAdvice" >
    	</bean>
    	
    	<bean 	id="advisor" 
    			class="org.springframework.aop.support.BadAdvisor" >
    		<property name="advice">
    			<ref local="advice"/>
    		</property>
    		<property name="pointcut">
    			<bean class="org.springframework.aop.support.JdkRegexpMethodPointcut">
    				<property name="pattern">
    					<value>e*</value>
    				</property>
    			</bean>
    		</property>		
    	</bean>
    	
    </beans>

  4. #4
    Join Date
    Jan 2007
    Posts
    14

    Default

    PS: I know the wiki tells me the beans config validator is called by the beans project validator for modified config files but this does not seem to be happening. I have the config file registered with spring.

  5. #5
    Join Date
    Aug 2004
    Location
    Frankfurt/Main, Germany
    Posts
    253

    Default

    Quote Originally Posted by jfrain2007 View Post
    How is this BeansConfigValidator run? manually/automatically?
    BeansConfigValidator leverages Eclipse's Incremental Builder Support. These builders are only executed when a project is compiled / built. This happens automatically ("Project > Build Automatically" is checked) or manually ("Project > Build Automatically" is NOT checked) by selecting one of the "Project > Build XXX" menu items.

    Quote Originally Posted by jfrain2007 View Post
    Spring IDE does not catch the "badID" I'm using when getting a Bean
    Yes, Spring IDE has no clue about your Java code. It's only about BeansConfig XML files.

    Torsten

  6. #6
    Join Date
    Jan 2007
    Posts
    14

    Default

    I guess what I'm trying to get at is what Spring IDE actually helps me with. Assuming a person is using an XML plugin ( I'm using XMLbuddy ) what does Spring IDE actually do for you?
    I was under the impression that it helped do away with silly typos that caused runtime errors.
    What about checking for potential class cast exceptions at compile time? ie where your applicationContext factory is returning an object of type ClassA is there no check done to warn that your making a dodgy type cast to say a ClassB object in your program?

  7. #7
    Join Date
    Aug 2004
    Location
    Frankfurt/Main, Germany
    Posts
    253

    Default

    Quote Originally Posted by jfrain2007 View Post
    I guess what I'm trying to get at is what Spring IDE actually helps me with. Assuming a person is using an XML plugin ( I'm using XMLbuddy ) what does Spring IDE actually do for you?
    Spring IDE'S BeansXmlEditor provides code completion (bean class, properties, parent beans, factory methods, ...) and navigation (go to parent bean, bean class, property method, ...). The BeansConfigValidator validates your bean config files (bean class, properties, bean references, ...). The BeansView provides a treeview of your Spring projects with the beans config files and their beans. The BeansGraph provides....

    For a detailed list of Spring IDE's features please refer to http://springide.org/project/wiki/SpringideFeatures.

    Torsten

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •