So I think I can say I understand what Seam does now.  I don't necessarily 
agree with it, though.  I do understand that the installed attribute can't just 
simply override the annotation on that class, otherwise something like 

  | <core:jbpm/>
  |  wouldn't work, because "installed" would still be false.  

On a related note, I did a little testing to see if I was reading the source 
code right.  The results are a little odd, I think:


  | <?xml version="1.0" encoding="UTF-8"?>
  | <components xmlns="http://jboss.com/products/seam/components";
  |     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  |     xsi:schemaLocation="http://jboss.com/products/seam/components 
http://jboss.com/products/seam/components-2.0.xsd";>
  | 
  |     <!-- A standard @Name-annotated component: -->
  |     <component name="foo" scope="session" startup="true"> <!-- scope etc 
attributes ignored... -->
  |             <property name="title">A Foo</property> <!-- ...but property 
configurations are not... -->
  |     </component>
  |     <component name="foo" installed="false">
  |             <property name="description">installed by default</property> 
<!-- ...even when installed="false" -->
  |     </component>
  |     
  |     <!-- Not @Name-annotated: -->
  |     <component name="bar" class="eg.AbstractExampleComponent$Bar" 
scope="session" startup="true"> <!-- scope etc attributes not ignored -->
  |             <property name="title">A Bar</property> <!-- properties not 
ignored, either, of course -->
  |     </component>
  |     <component name="bar">
  |             <property name="description">not annotated as a 
component</property> <!-- (ever) -->
  |     </component>
  | 
  |     <!-- @Name-annotated, but also @Install(false): -->
  |     <component class="eg.AbstractExampleComponent$Baz" scope="session" 
startup="true"> <!-- scope etc attributes not ignored -->
  |             <property name="title">A Baz</property>
  |             <property name="description">a non-installed 
component</property>
  |     </component>
  | 
  | </components>
  | 


  | package eg;
  | 
  | import org.jboss.seam.ScopeType;
  | import org.jboss.seam.annotations.Install;
  | import org.jboss.seam.annotations.Name;
  | import org.jboss.seam.annotations.Scope;
  | 
  | 
  | public class AbstractExampleComponent {
  | 
  |     private String description;
  |     private String title;
  |     
  |     public String getDescription() {
  |             return description;
  |     }
  |     public void setDescription(String name) {
  |             this.description = name;
  |     }
  |     public String getTitle() {
  |             return title;
  |     }
  |     public void setTitle(String title) {
  |             this.title = title;
  |     }
  |     
  |     @Name("foo")
  |     @Scope(ScopeType.CONVERSATION)
  |     public static class Foo extends AbstractExampleComponent {}
  |     
  |     @Scope(ScopeType.CONVERSATION)
  |     public static class Bar extends AbstractExampleComponent {}
  | 
  |     @Name("baz")
  |     @Install(false)
  |     @Scope(ScopeType.CONVERSATION)
  |     public static class Baz extends AbstractExampleComponent {}
  | 
  | }
  | 


  | package eg;
  | 
  | import org.jboss.seam.Component;
  | import org.jboss.seam.ScopeType;
  | import org.jboss.seam.Seam;
  | import org.jboss.seam.mock.SeamTest;
  | import org.testng.annotations.Test;
  | 
  | import eg.AbstractExampleComponent.Bar;
  | import eg.AbstractExampleComponent.Baz;
  | import eg.AbstractExampleComponent.Foo;
  | 
  | public class InitializationTest extends SeamTest{
  | 
  |     @Override
  |     protected void startJbossEmbeddedIfNecessary() throws Exception {
  |     }
  |     
  |     @Test
  |     public void foo() throws Exception {
  |             new ComponentTest() {
  | 
  |                     @Override
  |                     protected void testComponents() throws Exception {
  |                             Foo foo = (Foo) Component.getInstance("foo");
  |                             assert foo.getTitle().equals("A Foo");
  |                             assert foo.getDescription().equals("installed 
by default");
  |                             Component component = 
Seam.componentForName("foo");
  |                             assert component.getScope() == 
ScopeType.CONVERSATION; //xml override not used
  |                             assert component.isStartup() == false; //same
  |                     }
  |                     
  |             }.run();
  |     }
  |     
  |     @Test
  |     public void bar() throws Exception {
  |             new ComponentTest() {
  |                     
  |                     @Override
  |                     protected void testComponents() throws Exception {
  |                             Bar bar = (Bar) Component.getInstance("bar");
  |                             assert bar.getTitle().equals("A Bar");
  |                             assert bar.getDescription().equals("not 
annotated as a component");
  |                             Component component = 
Seam.componentForName("bar");
  |                             assert component.getScope() == 
ScopeType.SESSION;
  |                             assert component.isStartup() == true;
  |                     }
  |                     
  |             }.run();
  |     }
  |     @Test
  |     public void baz() throws Exception {
  |             new ComponentTest() {
  |                     
  |                     @Override
  |                     protected void testComponents() throws Exception {
  |                             Baz baz = (Baz) Component.getInstance("baz");
  |                             assert baz.getTitle().equals("A Baz");
  |                             assert baz.getDescription().equals("a 
non-installed component");
  |                             Component component = 
Seam.componentForName("baz");
  |                             assert component.getScope() == 
ScopeType.SESSION;
  |                             assert component.isStartup() == true;
  |                     }
  |                     
  |             }.run();
  |     }
  |     
  | }
  | 

(The test passes)

The biggest oddity to me is that for installed components, you can't override 
*any* annotations, not just "@Install".  Another oddity is that for 
install="false" elements, properties are still picked up and used.  

It smells buggy.  Or at least not-thought-through.
Is this the way things are supposed to be?

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4095900#4095900

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4095900
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to