geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Geronimo Wiki] Update of "GBeansArticle1" by JasonDillon
Date Wed, 16 Nov 2005 20:50:49 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Geronimo Wiki" for change notification.

The following page has been changed by JasonDillon:
http://wiki.apache.org/geronimo/GBeansArticle1

The comment on the change is:
Formatting clean up for code readability

------------------------------------------------------------------------------
  Most simple form of IOC or the Dependency injection is to by system wide known values. For
an instance let us assume this is Web Service that is to deployed inside Axis, do not worry
about Axis but just assume that the Axis will load the following class and call the doit()
method. 
  
  {{{
- public class WS{
+ public class WS {
- 	public WS(MesageContext msgctx){
+     public WS(MesageContext msgctx) {
-         }
- 
+     }
+     
-         public void doit(){
+     public void doit() {
-         }
+     }
  }
- 
  }}}
  
  But Axis has something called !MessageContext that has all the configuration information.
In order to give a reference of !MessageContext to the WS class Axis can say "if you have
a Constructor like XX(!MessageContext) or you have a method like setMessageContext(!MessageContext
msgctx) I will inject the !MessageContext to you".
@@ -82, +81 @@

  {{{
  public class MyGBean implements GBeanLifecycle {
      private final String val;
+     
      static {
          GBeanInfoBuilder infoFactory =  ...
          // attributes
@@ -92, +92 @@

          GBEAN_INFO = infoFactory.getBeanInfo();
      }
  
-      public ConstructorInjectionGbean(String val )     {
+     public ConstructorInjectionGbean(String val ) {
- 	this.val = val;
+         this.val = val;
      }
- ...
+     ...
  }
  }}}
  
@@ -137, +137 @@

          GBEAN_INFO = infoFactory.getBeanInfo();
      }
  
-      public ConstructorInjectionGbean(GBean1 bean1)     {-----------(C)
+     public ConstructorInjectionGbean(GBean1 bean1) {-----------(C)
- 	this.bean1 = bean1;
+         this.bean1 = bean1;
      }
  ...
  }
@@ -192, +192 @@

  Correct way to do it is write G1 like 
  
  {{{
- class G1 implements GBeanLifeCycle{
+ class G1 implements GBeanLifeCycle {
- 	...
+     ...
- private final G2 g2;
+     private final G2 g2;
      
      static {
-         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("G1",
+         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("G1", G1.class);
-                 G1.class);
          infoFactory.addReference("G2",G2.class); --------- (A)
- 	 infoFactory.addConstructor("G2"); ---------------- (B)
+         infoFactory.addConstructor("G2"); ---------------- (B)
-  GBEAN_INFO = infoFactory.getBeanInfo();
+         GBEAN_INFO = infoFactory.getBeanInfo();
      }
+     
      public ConstructorInjectionGbean(G2 g2 )     {
- 	this.g2 = g2;
+         this.g2 = g2;
-    }
+     }
+     
      public void doG1Work(){
- g2.doit();
+         g2.doit();
      }
  }
- 
  }}}
  
  At line (A) defining there is a reference to G2 and at line (B) adding a constructor that
inject the G2 and G1 obtain a reference to the G2. Then   logic is implemented using simple
Java code. 

Mime
View raw message