Date: 2004-07-12T00:36:27 Editor: 211.29.167.17 <> Wiki: Apache Geronimo Wiki Page: GBeans URL: http://wiki.apache.org/geronimo/GBeans
no comment Change Log: ------------------------------------------------------------------------------ @@ -24,27 +24,32 @@ == Let us Write a GBean == - * They should implements the GBeanLifecycle interface + * A GBean may implement the org.apache.geronimo.gbean.GBeanLifecycle interface. If it implements this interface, then it will receive life-cycle call-backs from the IoC framework. * They can have attributes with getters and setters, There are attributes that are final and I think they are standard .. (What is the list of them) e.g. name, Kernel (they can use to get hold of the system info, have a look at the sample GBeans.) There are ordinary attributes .. have getters and setters * GBeans can have methods .. - * each GBean should have GBEAN_INFO attribute (see exapmles) + * A GBean MUST implement a method having the following signature: {{{ -static { -GBeanInfoFactory infoFactory = new GBeanInfoFactory("AxisGbean", -AxisGbean.class); -//attributes -infoFactory.addAttribute("Name", String.class, true); -infoFactory.addAttribute("kernel", Kernel.class, false); -//operations -infoFactory.addOperation("echo", new Class[]{String.class}); +public static GBeanInfo getGBeanInfo(); +}}} +This method provides meta-data about the attributes, operations and references exposed or used by a GBean. It is standard practice to initialize this meta-data in a static block initializer. The following block depicts such an approach: +{{{ +public static final GBeanInfo GBEAN_INFO; -infoFactory.setConstructor(new String[] {"kernel","Name"}); -GBEAN_INFO = infoFactory.getBeanInfo(); +static { + GBeanInfoFactory infoFactory = new GBeanInfoFactory("AxisGbean", + AxisGbean.class); + infoFactory.addAttribute("name", String.class, true); + infoFactory.addAttribute("kernel", Kernel.class, false); + infoFactory.addOperation("echo", new Class[]{String.class}); + infoFactory.setConstructor(new String[] {"kernel","Name"}); + GBEAN_INFO = infoFactory.getBeanInfo(); } }}} +Attributes and references MUST be compliant wit the following naming conventions: attributes MUST start with a lower case first character; and references must should start with an upper case first character. This simple naming convention should simplify the configuration of a GBean. + * following two are call back methods there are more {{{ public void doStart() throws WaitingException, Exception { @@ -66,7 +71,7 @@ ClassLoader cl = getClass().getClassLoader(); ClassLoader myCl = new URLClassLoader(new URL[0], cl); GBeanMBean gbean = new GBeanMBean(AxisGbean.getGBeanInfo(), myCl); -gbean.setAttribute("Name", "Test"); +gbean.setAttribute("name", "Test"); kernel.loadGBean(name, gbean); Kernel.startGBean(name); @@ -82,7 +87,6 @@ == What is GBean Meta Data? == == What does the GBeanInfo class represent? == -== Does my GBean have to implement GBeanLifecycle? == == Can I configure my GBean using a flat file? == == How do I manage the attributes of my GBean remotely? ==