[jboss-cvs] JBossAS SVN: r64099 - in branches/Branch_4_2/ejb3/docs/tutorial/service: src/org/jboss/tutorial/service/bean and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jul 17 14:05:23 EDT 2007


Author: bdecoste
Date: 2007-07-17 14:05:23 -0400 (Tue, 17 Jul 2007)
New Revision: 64099

Added:
   branches/Branch_4_2/ejb3/docs/tutorial/service/service-xmbean.xml
   branches/Branch_4_2/ejb3/docs/tutorial/service/src/org/jboss/tutorial/service/bean/XMBeanService.java
   branches/Branch_4_2/ejb3/docs/tutorial/service/src/org/jboss/tutorial/service/bean/XMBeanServiceRemote.java
Modified:
   branches/Branch_4_2/ejb3/docs/tutorial/service/build.xml
   branches/Branch_4_2/ejb3/docs/tutorial/service/service.html
   branches/Branch_4_2/ejb3/docs/tutorial/service/service.wiki
   branches/Branch_4_2/ejb3/docs/tutorial/service/src/org/jboss/tutorial/service/client/Client.java
Log:
[EJBTHREE-809] tutorial for XMBean @Service

Modified: branches/Branch_4_2/ejb3/docs/tutorial/service/build.xml
===================================================================
--- branches/Branch_4_2/ejb3/docs/tutorial/service/build.xml	2007-07-17 17:33:47 UTC (rev 64098)
+++ branches/Branch_4_2/ejb3/docs/tutorial/service/build.xml	2007-07-17 18:05:23 UTC (rev 64099)
@@ -60,6 +60,9 @@
          <fileset dir="${build.classes.dir}">
             <include name="**/*.class"/>
          </fileset>
+      	<fileset dir=".">
+	        <include name="service-xmbean.xml"/>
+	    </fileset>
       </jar>
       <copy file="build/tutorial.jar" todir="${jboss.home}/server/${jboss.server.config}/deploy"/>
    </target>

Added: branches/Branch_4_2/ejb3/docs/tutorial/service/service-xmbean.xml
===================================================================
--- branches/Branch_4_2/ejb3/docs/tutorial/service/service-xmbean.xml	                        (rev 0)
+++ branches/Branch_4_2/ejb3/docs/tutorial/service/service-xmbean.xml	2007-07-17 18:05:23 UTC (rev 64099)
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mbean PUBLIC
+        "-//JBoss//DTD JBOSS XMBEAN 1.0//EN"
+        "http://www.jboss.org/j2ee/dtd/jboss_xmbean_1_0.dtd">
+<mbean>
+
+    <description>EJB3 Service XMBean Example</description>
+    
+    <class>org.jboss.tutorial.service.bean.XMBeanService</class>
+   
+    <!-- Constructors -->
+    <constructor>
+        <description>The default constructor</description>
+        <name>XMBeanService</name>
+    </constructor>
+
+    <!-- Attributes -->
+    
+    <attribute access="read-write" getMethod="getAttribute" setMethod="setAttribute">
+        <description>Test attribute</description>
+        <name>IntAttribute</name>
+        <type>java.lang.Integer</type>
+    </attribute>
+
+    <!-- Operations -->
+    <operation>
+        <description>Say Hello</description>
+        <name>sayHello</name>
+        <return-type>java.lang.String</return-type>
+    </operation>
+</mbean>
+

Modified: branches/Branch_4_2/ejb3/docs/tutorial/service/service.html
===================================================================
--- branches/Branch_4_2/ejb3/docs/tutorial/service/service.html	2007-07-17 17:33:47 UTC (rev 64098)
+++ branches/Branch_4_2/ejb3/docs/tutorial/service/service.html	2007-07-17 18:05:23 UTC (rev 64099)
@@ -107,7 +107,16 @@
    }
 </pre>
 </p><p>
+<h3> Defining Management Interface via XML</h3>
+
+You can deploy a Service bean as an XMBean, where the management attributes and operations are defined
+via xml. Take a look at <a href="src/org/jboss/tutorial/service/bean/XMBeanService.java">XMBeanService.xml</a>. Note
+the @Service annotation specifies an <tt>xmbean</tt> property. Also note there is no @Management annotation.
+Now take a look at  <a href="service-xmbean.xml">service-xmbean.xml</a>. This is the file referenced by the <tt>xmbean</tt>
+property and specifies the bean's management attributes and operations. Note the <tt>class</tt>, <tt>constructor</tt>,
+<tt>attribute</tt>, and <tt>operation</tt> elements. 
 </p><p>
+</p><p>
 <h3>Building</h3>
 
 To build and run the example, make sure you have ejb3.deployer installed in JBoss 4.0.x and have JBoss running. See the reference manual on how to install EJB 3.0.
@@ -143,10 +152,13 @@
 Buildfile: build.xml
 
 run:
+     [java] invoking Service...
      [java] attribute value for singleton obtained via JMX is what we set via remote i/f: 100
      [java] Hello from service One
      [java] Hello from service Two
-
+     [java] invoking XMBean...
+     [java] attribute value for singleton obtained via JMX is what we set via remote i/f: 0
+     [java] Hello from an XMBean
 </pre>
 </p><p>
 The JBoss console should show the following output

Modified: branches/Branch_4_2/ejb3/docs/tutorial/service/service.wiki
===================================================================
--- branches/Branch_4_2/ejb3/docs/tutorial/service/service.wiki	2007-07-17 17:33:47 UTC (rev 64098)
+++ branches/Branch_4_2/ejb3/docs/tutorial/service/service.wiki	2007-07-17 18:05:23 UTC (rev 64099)
@@ -93,7 +93,15 @@
    }
 }}}
 
+!! Defining Management Interface via XML
+You can deploy a Service bean as an XMBean, where the management attributes and operations are defined
+via xml. Take a look at [XMBeanService.xml|src/org/jboss/tutorial/service/bean/XMBeanService.java]. Note
+the @Service annotation specifies an {{xmbean}} property. Also note there is no @Management annotation.
+Now take a look at  [service-xmbean.xml|service-xmbean.xml]. This is the file referenced by the {{xmbean}}
+property and specifies the bean's management attributes and operations. Note the {{class}}, {{constructor}},
+{{attribute}}, and {{operation}} elements. 
 
+
 !!Building
 To build and run the example, make sure you have ejb3.deployer installed in JBoss 4.0.x and have JBoss running. See the reference manual on how to install EJB 3.0.
 
@@ -128,10 +136,13 @@
 Buildfile: build.xml
 
 run:
+     [java] invoking Service...
      [java] attribute value for singleton obtained via JMX is what we set via remote i/f: 100
      [java] Hello from service One
      [java] Hello from service Two
-
+     [java] invoking XMBean...
+     [java] attribute value for singleton obtained via JMX is what we set via remote i/f: 0
+     [java] Hello from an XMBean
 }}}
 
 The JBoss console should show the following output

Added: branches/Branch_4_2/ejb3/docs/tutorial/service/src/org/jboss/tutorial/service/bean/XMBeanService.java
===================================================================
--- branches/Branch_4_2/ejb3/docs/tutorial/service/src/org/jboss/tutorial/service/bean/XMBeanService.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/docs/tutorial/service/src/org/jboss/tutorial/service/bean/XMBeanService.java	2007-07-17 18:05:23 UTC (rev 64099)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tutorial.service.bean;
+
+import org.jboss.annotation.ejb.Service;
+
+ at Service(objectName="jboss.ejb3.tutorial:service=XMBeanService", xmbean="resource:service-xmbean.xml")
+public class XMBeanService implements XMBeanServiceRemote
+{
+   int attribute;
+
+   public void setIntAttribute(int attribute)
+   {
+      this.attribute = attribute;
+   }
+
+   public int getIntAttribute()
+   {
+      return this.attribute;
+   }
+
+   public String sayHello()
+   {
+      return "Hello from an XMBean";
+   }
+   
+   public void remoteBusinessMethod()
+   {
+      
+   }
+}

Added: branches/Branch_4_2/ejb3/docs/tutorial/service/src/org/jboss/tutorial/service/bean/XMBeanServiceRemote.java
===================================================================
--- branches/Branch_4_2/ejb3/docs/tutorial/service/src/org/jboss/tutorial/service/bean/XMBeanServiceRemote.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/docs/tutorial/service/src/org/jboss/tutorial/service/bean/XMBeanServiceRemote.java	2007-07-17 18:05:23 UTC (rev 64099)
@@ -0,0 +1,28 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.tutorial.service.bean;
+
+
+public interface XMBeanServiceRemote
+{
+   void remoteBusinessMethod();
+}

Modified: branches/Branch_4_2/ejb3/docs/tutorial/service/src/org/jboss/tutorial/service/client/Client.java
===================================================================
--- branches/Branch_4_2/ejb3/docs/tutorial/service/src/org/jboss/tutorial/service/client/Client.java	2007-07-17 17:33:47 UTC (rev 64098)
+++ branches/Branch_4_2/ejb3/docs/tutorial/service/src/org/jboss/tutorial/service/client/Client.java	2007-07-17 18:05:23 UTC (rev 64099)
@@ -36,7 +36,15 @@
       InitialContext ctx = new InitialContext();
       //Get hold of the MBean server invoker
       RMIAdaptor server = (RMIAdaptor)ctx.lookup("jmx/invoker/RMIAdaptor");
-
+      
+      invokeService(ctx, server);
+      
+      invokeXMBean(ctx, server);
+   }
+   
+   public static void invokeService(InitialContext ctx, RMIAdaptor server) throws Exception
+   {
+      System.out.println("invoking Service...");
       //Set attribute on singleton ServiceOne via remote interface
       ServiceOneRemote serviceOne = (ServiceOneRemote) ctx.lookup("ServiceOne/remote");
       serviceOne.setAttribute(100);
@@ -58,4 +66,20 @@
       String service2Hello = (String)server.invoke(service3, "serviceTwoHello", noArgs, noSig);
       System.out.println(service2Hello);
    }
+   
+   public static void invokeXMBean(InitialContext ctx, RMIAdaptor server) throws Exception
+   {
+      System.out.println("invoking XMBean...");
+      ObjectName service = new ObjectName("jboss.ejb3.tutorial:service=XMBeanService");
+      //Get attribute of singleton XMBeanService via JMX
+      int attr = (Integer)server.getAttribute(service, "IntAttribute");
+      System.out.println("attribute value for singleton obtained via JMX is what we set via remote i/f: " + attr);
+
+      //Call sayHello() on XMBeanService
+      Object[] noArgs = new Object[0];//No arguments
+      String[] noSig = new String[0];//No parameters in signature
+
+      String hello = (String)server.invoke(service, "sayHello", noArgs, noSig);
+      System.out.println(hello);
+   }
 }




More information about the jboss-cvs-commits mailing list