[jboss-cvs] jboss-seam/src/ioc/org/jboss/seam/ioc/spring ...

Gavin King gavin.king at jboss.com
Sun Feb 18 12:17:54 EST 2007


  User: gavin   
  Date: 07/02/18 12:17:54

  Modified:    src/ioc/org/jboss/seam/ioc/spring       
                        SeamComponentPostProcessor.java
                        SeamFactoryBean.java SeamNamespaceHandler.java
                        SeamScope.java SeamScopePostProcessor.java
                        SeamTargetSource.java SpringComponent.java
  Log:
  coding standard
  
  Revision  Changes    Path
  1.2       +18 -9     jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamComponentPostProcessor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamComponentPostProcessor.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamComponentPostProcessor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- SeamComponentPostProcessor.java	17 Feb 2007 03:26:43 -0000	1.1
  +++ SeamComponentPostProcessor.java	18 Feb 2007 17:17:54 -0000	1.2
  @@ -14,7 +14,8 @@
    *
    * @author youngm
    */
  -public class SeamComponentPostProcessor implements BeanPostProcessor, Ordered {
  +public class SeamComponentPostProcessor implements BeanPostProcessor, Ordered 
  +{
   
   	private int order = Ordered.LOWEST_PRECEDENCE;
   
  @@ -22,21 +23,26 @@
   	 * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object,
   	 *      java.lang.String)
   	 */
  -	public Object postProcessAfterInitialization(final Object bean, String beanName) throws BeansException {
  +	public Object postProcessAfterInitialization(final Object bean, String beanName) throws BeansException 
  +   {
   		// Check to see if this bean is a component.
   		Component component = SpringComponent.forSpringBeanName(beanName);
   		// Not a spring component skip.
  -		if (component == null || !(component instanceof SpringComponent)) {
  +		if (component == null || !(component instanceof SpringComponent)) 
  +      {
   			return bean;
   		}
   		// If this bean is a FactoryBean only request the bean from Seam if the component is a FactoryBean as well
   		// The object created by the factory should come along later
  -		if (bean instanceof FactoryBean && !FactoryBean.class.isAssignableFrom(component.getBeanClass())) {
  +		if (bean instanceof FactoryBean && !FactoryBean.class.isAssignableFrom(component.getBeanClass())) 
  +      {
   			return bean;
   		}
   		// Wrap our bean instance in an object factory for the SpringComponent to use
  -		SpringComponent.setObjectFactory(new ObjectFactory() {
  -			public Object getObject() throws BeansException {
  +		SpringComponent.setObjectFactory(new ObjectFactory() 
  +      {
  +			public Object getObject() throws BeansException 
  +         {
   				return bean;
   			}
   		});
  @@ -48,7 +54,8 @@
   	 * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object,
   	 *      java.lang.String)
   	 */
  -	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
  +	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException 
  +   {
   		return bean;
   	}
   
  @@ -57,14 +64,16 @@
   	 *
   	 * @see org.springframework.core.Ordered#getOrder()
   	 */
  -	public int getOrder() {
  +	public int getOrder() 
  +   {
   		return order;
   	}
   
   	/**
   	 * @param order the order to set
   	 */
  -	public void setOrder(int order) {
  +	public void setOrder(int order) 
  +   {
   		this.order = order;
   	}
   }
  
  
  
  1.2       +30 -14    jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamFactoryBean.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamFactoryBean.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamFactoryBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- SeamFactoryBean.java	17 Feb 2007 03:26:43 -0000	1.1
  +++ SeamFactoryBean.java	18 Feb 2007 17:17:54 -0000	1.2
  @@ -40,8 +40,10 @@
        * @see org.springframework.beans.factory.config.AbstractFactoryBean#afterPropertiesSet()
        */
       @Override
  -    public void afterPropertiesSet() throws Exception {
  -        if (name == null) {
  +    public void afterPropertiesSet() throws Exception 
  +    {
  +        if (name == null) 
  +        {
               throw new IllegalArgumentException("name must not be null");
           }
           // If we're creating a proxy then we want this to be a singleton
  @@ -49,7 +51,8 @@
           
           this.targetSource = new SeamTargetSource(name, scope, create);
           
  -        if (proxy) {
  +        if (proxy) 
  +        {
               // Not sure if I should allow people to change these proxy
               // parameters or not. We'll see what issues we get hard coding them.
               ProxyFactory pf = new ProxyFactory();
  @@ -64,10 +67,14 @@
               // to our proxy.
               List<Class> interfaces = new ArrayList<Class>();
               Component component = targetSource.getComponent();
  -            if (component.getInterceptionType() != InterceptionType.NEVER) {
  -                if (component.getType().isSessionBean()) {
  +            if (component.getInterceptionType() != InterceptionType.NEVER) 
  +            {
  +                if (component.getType().isSessionBean()) 
  +                {
                       interfaces.addAll(component.getBusinessInterfaces());
  -                } else {
  +                } 
  +                else 
  +                {
                       interfaces.add(HttpSessionActivationListener.class);
                       interfaces.add(Mutable.class);
                   }
  @@ -86,10 +93,14 @@
        * @see org.springframework.beans.factory.config.AbstractFactoryBean#createInstance()
        */
       @Override
  -    protected Object createInstance() throws Exception {
  -        if (proxy) {
  +    protected Object createInstance() throws Exception 
  +    {
  +        if (proxy) 
  +        {
               return proxyInstance;
  -        } else {
  +        } 
  +        else 
  +        {
               return targetSource.getTarget();
           }
       }
  @@ -101,7 +112,8 @@
        * @see org.springframework.beans.factory.config.AbstractFactoryBean#getObjectType()
        */
       @Override
  -    public Class getObjectType() {
  +    public Class getObjectType() 
  +    {
           return targetSource.getTargetClass();
       }
       
  @@ -110,7 +122,8 @@
        *
        * @param name the name of the component
        */
  -    public void setName(String name) {
  +    public void setName(String name) 
  +    {
           this.name = name;
       }
   
  @@ -119,7 +132,8 @@
        *
        * @param scope the scope of the component
        */
  -    public void setScope(ScopeType scope) {
  +    public void setScope(ScopeType scope) 
  +    {
           this.scope = scope;
       }
       
  @@ -131,7 +145,8 @@
        *
        * @param create do we create an instance if needed
        */
  -    public void setCreate(Boolean create) {
  +    public void setCreate(Boolean create) 
  +    {
           this.create = create;
       }
       
  @@ -141,7 +156,8 @@
        *
        * @param proxy true to proxy the component
        */
  -    public void setProxy(boolean proxy) {
  +    public void setProxy(boolean proxy) 
  +    {
           this.proxy = proxy;
       }
   }
  
  
  
  1.3       +33 -17    jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamNamespaceHandler.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamNamespaceHandler.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamNamespaceHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- SeamNamespaceHandler.java	17 Feb 2007 09:57:44 -0000	1.2
  +++ SeamNamespaceHandler.java	18 Feb 2007 17:17:54 -0000	1.3
  @@ -34,7 +34,8 @@
       /**
        * @see org.springframework.beans.factory.xml.NamespaceHandler#init()
        */
  -    public void init() {
  +    public void init() 
  +    {
           registerBeanDefinitionParser("configure-scopes", new SeamConfigureScopeParser());
           registerBeanDefinitionParser("instance", new SeamInstanceBeanDefinitionParser());
           registerBeanDefinitionDecorator("component", new SeamComponentBeanDefinitionDecorator());
  @@ -82,7 +83,9 @@
       private static class SeamInstanceBeanDefinitionParser 
           extends AbstractSimpleBeanDefinitionParser 
       {        
  -        protected Class getBeanClass(Element element) {
  +       @Override
  +       protected Class getBeanClass(Element element) 
  +       {
               return SeamFactoryBean.class;
           }
       }
  @@ -100,7 +103,8 @@
        *
        * @author youngm
        */
  -    private static class SeamComponentBeanDefinitionDecorator implements BeanDefinitionDecorator {
  +    private static class SeamComponentBeanDefinitionDecorator implements BeanDefinitionDecorator 
  +    {
           private static final String INTERCEPT_ATTR = "intercept";
           private static final String SPRING_NAME_ATTR = "springName";
           private static final String SEAM_NAME_ATTR = "seamName";
  @@ -112,11 +116,14 @@
            *      org.springframework.beans.factory.config.BeanDefinitionHolder,
            *      org.springframework.beans.factory.xml.ParserContext)
            */
  -        public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
  +        public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) 
  +        {
               // Add the Seam Component Post Processor to the bean factory if it doesn't already exist
  -            if (!parserContext.getRegistry().containsBeanDefinition(SEAM_COMPONENT_POST_PROCESSOR_BEAN_NAME)) {
  +            if (!parserContext.getRegistry().containsBeanDefinition(SEAM_COMPONENT_POST_PROCESSOR_BEAN_NAME)) 
  +            {
                   Class cls;
  -                try {
  +                try 
  +                {
                       cls = ClassUtils.forName(SEAM_COMPONENT_POST_PROCESSOR);
                   } catch (ClassNotFoundException e) {
                       throw new IllegalStateException("Unable to load class '" + SEAM_COMPONENT_POST_PROCESSOR
  @@ -129,27 +136,34 @@
               }
               // get the optional beanClass
               String beanClassName = definition.getBeanDefinition().getBeanClassName();
  -            if (node.getAttributes().getNamedItem(BEAN_CLASS_ATTR) != null) {
  +            if (node.getAttributes().getNamedItem(BEAN_CLASS_ATTR) != null) 
  +            {
                   beanClassName = node.getAttributes().getNamedItem(BEAN_CLASS_ATTR).getNodeValue();
               }
               String beanName = definition.getBeanName();
               // get the name of the seam component to create
               String seamName = beanName;
  -            if (node.getAttributes().getNamedItem(SEAM_NAME_ATTR) != null) {
  +            if (node.getAttributes().getNamedItem(SEAM_NAME_ATTR) != null) 
  +            {
                   seamName = node.getAttributes().getNamedItem(SEAM_NAME_ATTR).getNodeValue();
               }
               // get the name of the spring bean to use
               String springName = beanName;
  -            if (node.getAttributes().getNamedItem(SPRING_NAME_ATTR) != null) {
  +            if (node.getAttributes().getNamedItem(SPRING_NAME_ATTR) != null) 
  +            {
                   springName = node.getAttributes().getNamedItem(SPRING_NAME_ATTR).getNodeValue();
               }
               // get the interception type to use
               InterceptionType interceptionType = null;
  -            if (AUTO_INTERCEPTION_TYPE.equals(node.getAttributes().getNamedItem(INTERCEPT_ATTR).getNodeValue())) {
  -                if (definition.getBeanDefinition().isSingleton()) {
  +            if (AUTO_INTERCEPTION_TYPE.equals(node.getAttributes().getNamedItem(INTERCEPT_ATTR).getNodeValue())) 
  +            {
  +                if (definition.getBeanDefinition().isSingleton()) 
  +                {
                       interceptionType = InterceptionType.NEVER;
                   }
  -            } else {
  +            } 
  +            else 
  +            {
                   interceptionType = InterceptionType.valueOf(node.getAttributes().getNamedItem(INTERCEPT_ATTR)
                                                               .getNodeValue());
               }
  @@ -157,14 +171,16 @@
               // get the requested scope
               ScopeType scope = ScopeType.valueOf(node.getAttributes().getNamedItem("scope").getNodeValue());
               if (scope != ScopeType.STATELESS
  -                && !BeanDefinition.SCOPE_PROTOTYPE.equals(definition.getBeanDefinition().getScope())) {
  +                && !BeanDefinition.SCOPE_PROTOTYPE.equals(definition.getBeanDefinition().getScope())) 
  +            {
                   throw new IllegalStateException(
   						"The spring bean scope must be prototype to use a seam scope other than STATELESS.");
               }
               // determine if we want to override any existing seam component definitions
               boolean override = Boolean.parseBoolean(node.getAttributes().getNamedItem("override").getNodeValue());
               
  -            if (!(parserContext.getRegistry() instanceof BeanFactory)) {
  +            if (!(parserContext.getRegistry() instanceof BeanFactory)) 
  +            {
                   throw new RuntimeException("For some reason your registry is not a BeanFactory");
               }
               SpringComponent.addSpringComponent(seamName, springName, beanClassName, scope, (BeanFactory) parserContext
  
  
  
  1.3       +26 -11    jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamScope.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamScope.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamScope.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- SeamScope.java	17 Feb 2007 09:57:44 -0000	1.2
  +++ SeamScope.java	18 Feb 2007 17:17:54 -0000	1.3
  @@ -24,7 +24,8 @@
       
       private ScopeType scope;
       
  -    public SeamScope(ScopeType scope) {
  +    public SeamScope(ScopeType scope) 
  +    {
           this.scope = scope;
       }
       
  @@ -34,12 +35,16 @@
        * @see org.springframework.beans.factory.config.Scope#get(java.lang.String,
        *      org.springframework.beans.factory.ObjectFactory)
        */
  -    public Object get(String name, ObjectFactory objectFactory) {
  -        try {
  +    public Object get(String name, ObjectFactory objectFactory) 
  +    {
  +        try 
  +        {
               SpringComponent.setObjectFactory(objectFactory);
               Component component = SpringComponent.forSpringBeanName(name);
               return Component.getInstance(component.getName(), scope, true);
  -        } finally {
  +        } 
  +        finally 
  +        {
               SpringComponent.setObjectFactory(null);
           }
       }
  @@ -49,7 +54,8 @@
        *
        * @see org.springframework.beans.factory.config.Scope#getConversationId()
        */
  -    public String getConversationId() {
  +    public String getConversationId() 
  +    {
           return null;
       }
       
  @@ -57,7 +63,8 @@
        * @see org.springframework.beans.factory.config.Scope#registerDestructionCallback(java.lang.String,
        *      java.lang.Runnable)
        */
  -    public void registerDestructionCallback(String name, Runnable callback) {
  +    public void registerDestructionCallback(String name, Runnable callback) 
  +    {
           SpringComponent.forSpringBeanName(name).registerDestroyCallback(name, callback);
       }
       
  @@ -72,16 +79,24 @@
           log.debug("destroying: " + name);
           Component component = SpringComponent.forSpringBeanName(name);
           Object bean = null;
  -        if (component != null) {
  +        if (component != null) 
  +        {
               bean = scope.getContext().get(component.getName());
  -            if (bean != null) { // in a portal environment, this is possible
  +            if (bean != null) // in a portal environment, this is possible
  +            {
                   if (Events.exists())
  +                {
                       Events.instance().raiseEvent("org.jboss.seam.preDestroy." + name);
  -                try {
  -                    if (component.hasDestroyMethod()) {
  +                }
  +                try 
  +                {
  +                    if (component.hasDestroyMethod()) 
  +                    {
                           component.callComponentMethod(bean, component.getDestroyMethod());
                       }
  -                } catch (Exception e) {
  +                } 
  +                catch (Exception e) 
  +                {
                       log.warn("Could not destroy component: " + component.getName(), e);
                   }
               }
  
  
  
  1.3       +39 -19    jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamScopePostProcessor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamScopePostProcessor.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamScopePostProcessor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- SeamScopePostProcessor.java	17 Feb 2007 09:57:44 -0000	1.2
  +++ SeamScopePostProcessor.java	18 Feb 2007 17:17:54 -0000	1.3
  @@ -40,8 +40,10 @@
        *
        * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
        */
  -    public void afterPropertiesSet() throws Exception {
  -        if (prefix == null || "".equals(prefix)) {
  +    public void afterPropertiesSet() throws Exception 
  +    {
  +        if (prefix == null || "".equals(prefix)) 
  +        {
               prefix = DEFAULT_SCOPE_PREFIX;
           }
       }
  @@ -54,35 +56,46 @@
       public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) 
           throws BeansException 
       {
  -        for (ScopeType scope : ScopeType.values()) {
  +        for (ScopeType scope : ScopeType.values()) 
  +        {
               // Don't create a scope for Unspecified
  -            if (scope != ScopeType.UNSPECIFIED) {
  +            if (scope != ScopeType.UNSPECIFIED) 
  +            {
                   beanFactory.registerScope(prefix + scope.name(), new SeamScope(scope));
               }
           }
           // Create a mock application context if not available.
           // TODO Reuse
           boolean unmockApplication = false;
  -        if (!Contexts.isApplicationContextActive()) {
  +        if (!Contexts.isApplicationContextActive()) 
  +        {
               Lifecycle.mockApplication();
               unmockApplication = true;
           }
  -        try {
  +        try 
  +        {
               // Iterate through all the beans in the factory
  -            for (String beanName : beanFactory.getBeanDefinitionNames()) {
  +            for (String beanName : beanFactory.getBeanDefinitionNames()) 
  +            {
                   BeanDefinition definition = beanFactory.getBeanDefinition(beanName);
                   ScopeType scope;
  -                if (definition.getScope().startsWith(prefix)) {
  +                if (definition.getScope().startsWith(prefix)) 
  +                {
                       // Will throw an error if the scope is not found.
                       scope = ScopeType.valueOf(definition.getScope().replaceFirst(prefix, "").toUpperCase());
  -                } else {
  -                    if (log.isDebugEnabled()) {
  +                } 
  +                else 
  +                {
  +                    if (log.isDebugEnabled()) 
  +                    {
                           log.debug("No scope could be derived for bean with name: " + beanName);
                       }
                       continue;
                   }
  -                if (scope == ScopeType.UNSPECIFIED) {
  -                    if (log.isDebugEnabled()) {
  +                if (scope == ScopeType.UNSPECIFIED) 
  +                {
  +                    if (log.isDebugEnabled()) 
  +                    {
                           log.debug("Discarding bean with scope UNSPECIFIED.  Spring will throw an error later: "
                                     + beanName);
                                           }
  @@ -90,8 +103,10 @@
                   }
                   // Cannot be a seam component without a specified class seam:component will need to be used for this
                   // bean.
  -                if (definition.getBeanClassName() == null) {
  -                    if (log.isDebugEnabled()) {
  +                if (definition.getBeanClassName() == null) 
  +                {
  +                    if (log.isDebugEnabled()) 
  +                    {
                           log.debug("Unable to create component for bean: " + beanName
                                     + ".  No class defined try seam:component instead.");
                       }
  @@ -100,8 +115,11 @@
                   SpringComponent.addSpringComponent(beanName, beanName, definition.getBeanClassName(), scope, beanFactory, null,
                                                      override);
               }
  -        } finally {
  -            if (unmockApplication) {
  +        } 
  +        finally 
  +        {
  +            if (unmockApplication) 
  +            {
                   Lifecycle.unmockApplication();
               }
           }
  @@ -110,7 +128,8 @@
       /**
        * @param prefix casesensitive the prefix to use to identify seam scopes for spring beans. Default is "seam."
        */
  -    public void setPrefix(String prefix) {
  +    public void setPrefix(String prefix) 
  +    {
           this.prefix = prefix;
       }
       
  @@ -118,7 +137,8 @@
        * @param override set to tell the postprocessor to duplicate any preexisting seam components that may have the same
        *        name as the candidate spring bean. Default: false
        */
  -    public void setOverride(boolean override) {
  +    public void setOverride(boolean override) 
  +    {
           this.override = override;
       }
   }
  
  
  
  1.3       +36 -16    jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamTargetSource.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamTargetSource.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SeamTargetSource.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- SeamTargetSource.java	17 Feb 2007 09:57:44 -0000	1.2
  +++ SeamTargetSource.java	18 Feb 2007 17:17:54 -0000	1.3
  @@ -15,7 +15,8 @@
    * @author youngm
    */
   @SuppressWarnings("serial")
  -public class SeamTargetSource implements TargetSource, Serializable {
  +public class SeamTargetSource implements TargetSource, Serializable 
  +{
   
   	private ScopeType scope;
   
  @@ -28,8 +29,10 @@
   	 * @param scope Name of the scope the component is in: optional
   	 * @param create Whether to create a new instance if one doesn't already exist: optional
   	 */
  -	public SeamTargetSource(String name, ScopeType scope, Boolean create) {
  -		if (name == null || "".equals(name)) {
  +	public SeamTargetSource(String name, ScopeType scope, Boolean create) 
  +   {
  +		if (name == null || "".equals(name)) 
  +      {
   			throw new IllegalArgumentException("Name is required.");
   		}
   		this.name = name;
  @@ -42,14 +45,22 @@
   	 *
   	 * @see org.springframework.aop.TargetSource#getTarget()
   	 */
  -	public Object getTarget() throws Exception {
  -		if (scope == null && create == null) {
  +	public Object getTarget() throws Exception 
  +   {
  +		if (scope == null && create == null) 
  +      {
   			return Component.getInstance(name);
  -		} else if (scope == null) {
  +		} 
  +      else if (scope == null) 
  +      {
   			return Component.getInstance(name, create);
  -		} else if (create == null) {
  +		} 
  +      else if (create == null) 
  +      {
   			return Component.getInstance(name, scope);
  -		} else {
  +		} 
  +      else 
  +      {
   			return Component.getInstance(name, scope, create);
   		}
   	}
  @@ -59,7 +70,8 @@
   	 *
   	 * @see org.springframework.aop.TargetSource#getTargetClass()
   	 */
  -	public Class getTargetClass() {
  +	public Class getTargetClass() 
  +   {
   		return getComponent().getBeanClass();
   	}
   
  @@ -68,22 +80,28 @@
   	 *
   	 * @return component
   	 */
  -	public Component getComponent() {
  +	public Component getComponent() 
  +   {
   		// TODO reuse
   		boolean unmockApplication = false;
  -		if (!Contexts.isApplicationContextActive()) {
  +		if (!Contexts.isApplicationContextActive()) 
  +      {
   			Lifecycle.mockApplication();
   			unmockApplication = true;
   		}
   		try {
   			Component component = Component.forName(name);
  -			if (component == null) {
  +			if (component == null) 
  +         {
   				throw new IllegalStateException("Cannot find targetClass for seam component: " + name
   						+ ".  Make sure Seam is being configured before Spring.");
   			}
   			return component;
  -		} finally {
  -			if (unmockApplication) {
  +		} 
  +      finally 
  +      {
  +			if (unmockApplication) 
  +         {
   				Lifecycle.unmockApplication();
   			}
   		}
  @@ -92,7 +110,8 @@
   	/**
   	 * @see org.springframework.aop.TargetSource#isStatic()
   	 */
  -	public boolean isStatic() {
  +	public boolean isStatic() 
  +   {
   		return false;
   	}
   
  @@ -101,7 +120,8 @@
   	 *
   	 * @see org.springframework.aop.TargetSource#releaseTarget(java.lang.Object)
   	 */
  -	public void releaseTarget(Object target) throws Exception {
  +	public void releaseTarget(Object target) throws Exception 
  +   {
   		// Do Nothing
   	}
   }
  
  
  
  1.3       +83 -37    jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SpringComponent.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SpringComponent.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/ioc/org/jboss/seam/ioc/spring/SpringComponent.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- SpringComponent.java	17 Feb 2007 09:57:44 -0000	1.2
  +++ SpringComponent.java	18 Feb 2007 17:17:54 -0000	1.3
  @@ -29,7 +29,8 @@
    *
    * @author youngm
    */
  -public class SpringComponent extends IoCComponent {
  +public class SpringComponent extends IoCComponent 
  +{
   	private static final String SPRING_COMPONENT_NAME_MAP = "org.jboss.seam.SpringComponentNameMap";
   
   	public static final String DESTRUCTION_CALLBACK_NAME_PREFIX = IoCComponent.class.getName()
  @@ -43,11 +44,13 @@
   
   	private static final ThreadLocal<ObjectFactory> objectFactory = new ThreadLocal<ObjectFactory>();
   
  -	public static ObjectFactory getObjectFactory() {
  +	public static ObjectFactory getObjectFactory() 
  +   {
   		return objectFactory.get();
   	}
   
  -	public static void setObjectFactory(ObjectFactory bean) {
  +	public static void setObjectFactory(ObjectFactory bean) 
  +   {
   		objectFactory.set(bean);
   	}
   
  @@ -63,16 +66,20 @@
   	 * @param override If a seam component already exists should we override it?
   	 */
   	public static void addSpringComponent(String componentName, String springBeanName, String beanClassName,
  -			ScopeType scopeType, BeanFactory beanFactory, InterceptionType interceptorType, boolean override) {
  +			ScopeType scopeType, BeanFactory beanFactory, InterceptionType interceptorType, boolean override) 
  +   {
   		// mock the application context
   		// TODO reuse
   		boolean unmockApplication = false;
  -		if (!Contexts.isApplicationContextActive()) {
  +		if (!Contexts.isApplicationContextActive()) 
  +      {
   			Lifecycle.mockApplication();
   			unmockApplication = true;
   		}
  -		try {
  -			if (!override && Component.forName(componentName) != null) {
  +		try 
  +      {
  +			if (!override && Component.forName(componentName) != null) 
  +         {
   				throw new IllegalStateException("Cannot add spring component to seam with name: " + componentName
   						+ ".  There is already a seam component with that name.");
   			}
  @@ -85,18 +92,25 @@
   					componentName + Initialization.COMPONENT_SUFFIX,
   					new SpringComponent(beanClass, componentName, springBeanName, scopeType, beanFactory,
   							interceptorType));
  -		} catch (ClassNotFoundException e) {
  +		} 
  +      catch (ClassNotFoundException e) 
  +      {
   			throw new FatalBeanException("Error", e);
  -		} finally {
  -			if (unmockApplication) {
  +		} 
  +      finally 
  +      {
  +			if (unmockApplication) 
  +         {
   				Lifecycle.unmockApplication();
   			}
   		}
   	}
   
   	@SuppressWarnings("unchecked")
  -	private static Map<String, String> getSpringComponentNameMap() {
  -		if (Contexts.getApplicationContext().get(SPRING_COMPONENT_NAME_MAP) == null) {
  +	private static Map<String, String> getSpringComponentNameMap() 
  +   {
  +		if (Contexts.getApplicationContext().get(SPRING_COMPONENT_NAME_MAP) == null) 
  +      {
   			Contexts.getApplicationContext().set(SPRING_COMPONENT_NAME_MAP, new HashMap<String, String>());
   		}
   		return (Map<String, String>) Contexts.getApplicationContext().get(SPRING_COMPONENT_NAME_MAP);
  @@ -109,17 +123,23 @@
   	 * @param springBeanName the spring bean name.
   	 * @return the SpringComponent mapped to that spring bean name.
   	 */
  -	public static SpringComponent forSpringBeanName(String springBeanName) {
  +	public static SpringComponent forSpringBeanName(String springBeanName) 
  +   {
   		// TODO reuse
   		boolean unmockApplication = false;
  -		if (!Contexts.isApplicationContextActive()) {
  +		if (!Contexts.isApplicationContextActive()) 
  +      {
   			Lifecycle.mockApplication();
   			unmockApplication = true;
   		}
  -		try {
  +		try 
  +      {
   			return (SpringComponent) Component.forName(getSpringComponentNameMap().get(springBeanName));
  -		} finally {
  -			if (unmockApplication) {
  +		} 
  +      finally 
  +      {
  +			if (unmockApplication) 
  +         {
   				Lifecycle.unmockApplication();
   			}
   		}
  @@ -136,33 +156,43 @@
   	 * @param interception the interception type
   	 */
   	public SpringComponent(Class clazz, String componentName, String springBeanName, ScopeType scope,
  -			BeanFactory factory, InterceptionType interception) {
  +			BeanFactory factory, InterceptionType interception) 
  +   {
   		super(clazz, componentName, scope);
   		this.springBeanName = springBeanName;
   		this.beanfactory = factory;
   		this.interceptionType = interception;
   	}
   
  -	protected String getIoCName() {
  +   @Override
  +	protected String getIoCName() 
  +   {
   		return "Spring";
   	}
   
  -	protected Object instantiateIoCBean() throws Exception {
  +   @Override
  +	protected Object instantiateIoCBean() throws Exception 
  +   {
   		ObjectFactory objectFactory = getObjectFactory();
  -		if (objectFactory == null) {
  +		if (objectFactory == null) 
  +      {
   			return beanfactory.getBean(springBeanName);
   		}
   		setObjectFactory(null);
   		Object bean = objectFactory.getObject();
   		// initialize the bean following Component.instantiateJavaBean()'s
   		// pattern.
  -		if (getInterceptionType() == InterceptionType.NEVER) {
  +		if (getInterceptionType() == InterceptionType.NEVER) 
  +      {
   			// Only call postConstruct if the bean is not stateless otherwise in the case of a singleton it wowuld be
   			// called every time seam request the bean not just when it is created.
  -			if (getScope() != ScopeType.STATELESS) {
  +			if (getScope() != ScopeType.STATELESS) 
  +         {
   				callPostConstructMethod(bean);
   			}
  -		} else if (!(bean instanceof Proxy)) {
  +		} 
  +      else if (!(bean instanceof Proxy)) 
  +      {
   			// Add all of the interfaces of the bean instance into the Seam
   			// proxy bean because spring's proxies add a bunch of interfaces too
   			// that should be accessible.
  @@ -181,7 +211,9 @@
   	 *
   	 * @see org.jboss.seam.Component#instantiateJavaBean()
   	 */
  -	protected Object instantiateJavaBean() throws Exception {
  +   @Override
  +	protected Object instantiateJavaBean() throws Exception 
  +   {
   		return instantiateIoCBean();
   	}
   
  @@ -191,12 +223,15 @@
   	 * @see org.jboss.seam.Component#callDestroyMethod(Object)
   	 */
   	@Override
  -	public void callDestroyMethod(Object instance) {
  +	public void callDestroyMethod(Object instance) 
  +   {
   		super.callDestroyMethod(instance);
   		// Cannot call the callback on a STATELESS bean because we have no way of storing it.
  -		if (getScope() != ScopeType.STATELESS) {
  +		if (getScope() != ScopeType.STATELESS) 
  +      {
   			Runnable callback = (Runnable) getScope().getContext().get(DESTRUCTION_CALLBACK_NAME_PREFIX + getName());
  -			if (callback != null) {
  +			if (callback != null) 
  +         {
   				callback.run();
   			}
   		}
  @@ -208,9 +243,11 @@
   	 * @param name bean name
   	 * @param destroy the destroy to set
   	 */
  -	public void registerDestroyCallback(String name, Runnable destroy) {
  +	public void registerDestroyCallback(String name, Runnable destroy) 
  +   {
   		// Not sure yet how to register a stateless bean's Destruction callback.
  -		if (getScope() != ScopeType.STATELESS) {
  +		if (getScope() != ScopeType.STATELESS) 
  +      {
   			getScope().getContext().set(DESTRUCTION_CALLBACK_NAME_PREFIX + name, destroy);
   		}
   	}
  @@ -221,13 +258,20 @@
   	 * @see org.jboss.seam.Component#inject(java.lang.Object, boolean)
   	 */
   	@Override
  -	public void inject(Object bean, boolean enforceRequired) {
  -		if (bean instanceof Advised) {
  -			try {
  +	public void inject(Object bean, boolean enforceRequired) 
  +   {
  +		if (bean instanceof Advised) 
  +      {
  +			try 
  +         {
   				inject(((Advised) bean).getTargetSource().getTarget(), enforceRequired);
  -			} catch (RuntimeException e) {
  +			} 
  +         catch (RuntimeException e) 
  +         {
   				throw e;
  -			} catch (Exception e) {
  +			} 
  +         catch (Exception e) 
  +         {
   				throw new RuntimeException(e);
   			}
   		}
  @@ -240,8 +284,10 @@
   	 * @see org.jboss.seam.Component#getInterceptionType()
   	 */
   	@Override
  -	public InterceptionType getInterceptionType() {
  -		if (interceptionType == null) {
  +	public InterceptionType getInterceptionType() 
  +   {
  +		if (interceptionType == null) 
  +      {
   			return super.getInterceptionType();
   		}
   		return interceptionType;
  
  
  



More information about the jboss-cvs-commits mailing list