[jboss-cvs] JBossAS SVN: r68678 - in projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted: advDeployment and 17 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jan 8 10:44:08 EST 2008
Author: newtonm
Date: 2008-01-08 10:44:08 -0500 (Tue, 08 Jan 2008)
New Revision: 68678
Added:
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/pom.xml
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/assembly/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/assembly/common.xml
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/assembly/pojo.xml
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/config/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/config/deployer-beans.xml
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/config/pojo-beans.xml
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/config/run.sh
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/client/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/client/Client.java
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/client/ConsoleInput.java
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/client/EmbeddedBootstrap.java
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/client/UserInterface.java
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/resources/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/resources/log4j.properties
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/java/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/java/org/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/java/org/jboss/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/java/org/jboss/example/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/java/org/jboss/example/client/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/java/org/jboss/example/client/ClientTestCase.java
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/java/org/jboss/example/client/ClientTestSuite.java
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/java/org/jboss/example/client/MockUserInterface.java
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/resources/
projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/resources/jboss-beans.xml
Log:
Added first draft of advDeployment example that bootstraps the aspectized deployers.
Added: projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/pom.xml
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/pom.xml (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/pom.xml 2008-01-08 15:44:08 UTC (rev 68678)
@@ -0,0 +1,127 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <groupId>org.jboss.microcontainer.examples</groupId>
+ <artifactId>gettingStarted</artifactId>
+ <version>1.0.0</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.microcontainer.examples</groupId>
+ <artifactId>advDeployment</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0.0</version>
+ <name>Advanced Deployment</name>
+ <description>A simple command line client that uses the aspectized deployers.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-kernel</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-deployers-client-spi</artifactId>
+ <version>2.0.0.Beta6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-deployers-client</artifactId>
+ <version>2.0.0.Beta6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-deployers-core-spi</artifactId>
+ <version>2.0.0.Beta6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-deployers-core</artifactId>
+ <version>2.0.0.Beta6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-deployers-impl</artifactId>
+ <version>2.0.0.Beta6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-deployers-spi</artifactId>
+ <version>2.0.0.Beta6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-deployers-structure-spi</artifactId>
+ <version>2.0.0.Beta6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-deployers-vfs-spi</artifactId>
+ <version>2.0.0.Beta6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-deployers-vfs</artifactId>
+ <version>2.0.0.Beta6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-managed</artifactId>
+ <version>2.0.0.Beta6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-metatype</artifactId>
+ <version>2.0.0.Beta6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ <version>2.0.0.Beta6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer.examples</groupId>
+ <artifactId>humanResourcesService</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <addMavenDescriptor>false</addMavenDescriptor>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly/pojo.xml</descriptor>
+ <!--<descriptor>src/main/assembly/aop.xml</descriptor>
+ <descriptor>src/main/assembly/classloader.xml</descriptor>-->
+ </descriptors>
+ <finalName>${pom.artifactId}</finalName>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>directory-inline</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Added: projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/assembly/common.xml
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/assembly/common.xml (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/assembly/common.xml 2008-01-08 15:44:08 UTC (rev 68678)
@@ -0,0 +1,50 @@
+<component>
+ <fileSets>
+ <fileSet>
+ <directory>target</directory>
+ <outputDirectory/>
+ <includes>
+ <include>*.jar</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+ <files>
+ <file>
+ <source>src/main/config/run.sh</source>
+ <fileMode>0744</fileMode>
+ </file>
+ </files>
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>/lib</outputDirectory>
+ <unpack>false</unpack>
+ <scope>runtime</scope>
+ <!-- Need to explicity include dependencies here until optional dependencies are sorted out. -->
+ <includes>
+ <include>org.jboss.microcontainer:jboss-kernel</include>
+ <include>org.jboss.microcontainer:jboss-dependency</include>
+ <include>org.jboss.microcontainer:jboss-container</include>
+ <include>org.jboss:jboss-common-core</include>
+ <include>jboss:jboss-common-core</include>
+ <include>jboss:jboss-common-logging-spi</include>
+ <include>jboss:jboss-common-logging-log4j</include>
+ <include>log4j:log4j</include>
+ <include>org.jboss:jbossxb</include>
+ <include>apache-xerces:xercesImpl</include>
+ <include>oswego-concurrent:concurrent</include>
+ <include>org.jboss.microcontainer:jboss-deployers-client</include>
+ <include>org.jboss.microcontainer:jboss-deployers-client-spi</include>
+ <include>org.jboss.microcontainer:jboss-deployers-core</include>
+ <include>org.jboss.microcontainer:jboss-deployers-core-spi</include>
+ <include>org.jboss.microcontainer:jboss-deployers-impl</include>
+ <include>org.jboss.microcontainer:jboss-deployers-spi</include>
+ <include>org.jboss.microcontainer:jboss-deployers-structure-spi</include>
+ <include>org.jboss.microcontainer:jboss-deployers-vfs</include>
+ <include>org.jboss.microcontainer:jboss-deployers-vfs-spi</include>
+ <include>org.jboss.microcontainer:jboss-managed</include>
+ <include>org.jboss.microcontainer:jboss-metatype</include>
+ <include>org.jboss:jboss-vfs</include>
+ </includes>
+ </dependencySet>
+ </dependencySets>
+</component>
Added: projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/assembly/pojo.xml
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/assembly/pojo.xml (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/assembly/pojo.xml 2008-01-08 15:44:08 UTC (rev 68678)
@@ -0,0 +1,26 @@
+<assembly>
+ <id>pojo</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <files>
+ <file>
+ <source>src/main/config/deployer-beans.xml</source>
+ <destName>jboss-beans.xml</destName>
+ </file>
+ </files>
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>/lib</outputDirectory>
+ <unpack>false</unpack>
+ <scope>runtime</scope>
+ <includes>
+ <include>org.jboss.microcontainer.examples:humanResourcesService</include>
+ </includes>
+ </dependencySet>
+ </dependencySets>
+ <componentDescriptors>
+ <componentDescriptor>src/main/assembly/common.xml</componentDescriptor>
+ </componentDescriptors>
+</assembly>
Added: projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/config/deployer-beans.xml
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/config/deployer-beans.xml (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/config/deployer-beans.xml 2008-01-08 15:44:08 UTC (rev 68678)
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <!-- The MainDeployer -->
+ <bean name="MainDeployer" class="org.jboss.deployers.plugins.main.MainDeployerImpl">
+ <property name="structuralDeployers"><inject bean="StructuralDeployers"/></property>
+ <property name="deployers"><inject bean="Deployers"/></property>
+ </bean>
+
+ <!-- The holder for deployers that determine structure -->
+ <bean name="StructuralDeployers" class="org.jboss.deployers.vfs.plugins.structure.VFSStructuralDeployersImpl">
+ <property name="structureBuilder">
+ <!-- The consolidator of the structure information -->
+ <bean name="StructureBuilder" class="org.jboss.deployers.vfs.plugins.structure.VFSStructureBuilder"/>
+ </property>
+ <!-- Accept any implementor of structure deployer -->
+ <incallback method="addDeployer"/>
+ <uncallback method="removeDeployer"/>
+ </bean>
+
+ <!-- The holder for deployers that do real deployment -->
+ <bean name="Deployers" class="org.jboss.deployers.plugins.deployers.DeployersImpl">
+ <constructor><parameter><inject bean="jboss.kernel:service=KernelController"/></parameter></constructor>
+ <!-- Accept any implementor of deployer -->
+ <incallback method="addDeployer"/>
+ <uncallback method="removeDeployer"/>
+ </bean>
+
+ <!-- JAR Structure -->
+ <bean name="JARStructure" class="org.jboss.deployers.vfs.plugins.structure.jar.JARStructure">
+ <!-- Unless specified the default list of suffixes is .zip, .ear, .jar, ,.rar, .war, .sar, .har, .aop -->
+ <constructor>
+ <parameter>
+ <set elementClass="java.lang.String">
+ <value>.zip</value>
+ <value>.ear</value>
+ <value>.jar</value>
+ <value>.rar</value>
+ <value>.war</value>
+ <value>.sar</value>
+ <value>.har</value>
+ <value>.aop</value>
+ <value>.deployer</value>
+ <value>.beans</value>
+ </set>
+ </parameter>
+ </constructor>
+ <property name="candidateStructureVisitorFactory">
+ <!-- Any file that is not an ordinary directory is a candidate -->
+ <bean name="JARStructureCandidates" class="org.jboss.deployers.vfs.spi.structure.helpers.DefaultCandidateStructureVisitorFactory">
+ <!-- A filter to exclude some obvious non-subdeployments -->
+ <property name="filter">
+ <bean name="JARFilter" class="org.jboss.virtual.plugins.vfs.helpers.SuffixesExcludeFilter">
+ <constructor><parameter>
+ <list elementClass="java.lang.String">
+ <!-- Exclude class files as subdeployments -->
+ <value>.class</value>
+ </list>
+ </parameter></constructor>
+ </bean>
+ </property>
+ </bean>
+ </property>
+ </bean>
+
+ <!-- File Structure -->
+ <bean name="FileStructure" class="org.jboss.deployers.vfs.plugins.structure.file.FileStructure">
+ <!-- Unless specified the default list of suffixes is -service.xml, -beans.xml, -ds.xml, -aop.xml -->
+ <constructor>
+ <parameter>
+ <set elementClass="java.lang.String">
+ <value>-service.xml</value>
+ <value>-beans.xml</value>
+ <value>-ds.xml</value>
+ <value>-aop.xml</value>
+ </set>
+ </parameter>
+ </constructor>
+ </bean>
+
+ <!-- POJO Deployment -->
+ <bean name="BeanDeployer" class="org.jboss.deployers.vfs.deployer.kernel.BeanDeployer">
+ <property name="type">beans</property>
+ </bean>
+ <bean name="KernelDeploymentDeployer" class="org.jboss.deployers.vfs.deployer.kernel.KernelDeploymentDeployer">
+ <property name="type">beans</property>
+ </bean>
+ <bean name="BeanMetaDataDeployer" class="org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer">
+ <constructor><parameter><inject bean="jboss.kernel:service=Kernel"/></parameter></constructor>
+ <property name="type">beans</property>
+ </bean>
+
+ <!-- Your deployer here! -->
+
+</deployment>
+
Added: projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/config/pojo-beans.xml
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/config/pojo-beans.xml (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/config/pojo-beans.xml 2008-01-08 15:44:08 UTC (rev 68678)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd"
+ xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="HRService" class="org.jboss.example.service.HRManager">
+ <!-- <property name="hiringFreeze">true</property>
+ <property name="salaryStrategy"><inject bean="AgeBasedSalary"/></property> -->
+ </bean>
+
+ <!-- <bean name="AgeBasedSalary" class="org.jboss.example.service.util.AgeBasedSalaryStrategy">
+ <property name="minSalary">1000</property>
+ <property name="maxSalary">80000</property>
+ </bean>
+
+ <bean name="LocationBasedSalary" class="org.jboss.example.service.util.LocationBasedSalaryStrategy">
+ <property name="minSalary">2000</property>
+ <property name="maxSalary">90000</property>
+ </bean> -->
+
+</deployment>
Added: projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/config/run.sh
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/config/run.sh (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/config/run.sh 2008-01-08 15:44:08 UTC (rev 68678)
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+java -Djava.ext.dirs=`pwd`/lib -cp .:advDeployment-1.0.0.jar org.jboss.example.client.Client $1
Property changes on: projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/config/run.sh
___________________________________________________________________
Name: svn:executable
+ *
Added: projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/client/Client.java
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/client/Client.java (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/client/Client.java 2008-01-08 15:44:08 UTC (rev 68678)
@@ -0,0 +1,184 @@
+package org.jboss.example.client;
+
+import java.io.IOException;
+import java.net.URL;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.Set;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.example.service.Address;
+import org.jboss.example.service.Employee;
+import org.jboss.example.service.HRManager;
+import org.jboss.example.service.util.SalaryStrategy;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.registry.KernelBus;
+
+/**
+ * A simple client that starts JBoss Microcontainer and then
+ * uses the command line as a User Interface to pass requests
+ * to the Human Resources service either directly or via the bus.
+ *
+ * @author <a href="mailto:mark.newton at jboss.org">Mark Newton</a>
+ */
+public class Client {
+
+ private boolean useBus = false;
+ private URL url;
+ private UserInterface userInterface;
+ private HRManager manager;
+
+ private EmbeddedBootstrap bootstrap;
+ private Kernel kernel;
+ private KernelController controller;
+ private KernelBus bus;
+
+ private final static String HRSERVICE = "HRService";
+ private final static String EMPLOYEE = "org.jboss.example.service.Employee";
+
+ public static void main(String[] args) throws Exception {
+ if ((args.length == 1 && !args[0].equals("bus")) || args.length > 1) {
+ System.out.println("Usage: ./run.sh [bus]");
+ System.exit(1);
+ }
+
+ Client client = new Client(args.length == 1);
+ client.setUserInterface(new ConsoleInput(client));
+ }
+
+ public Client(final boolean useBus) throws Exception {
+ this.useBus = useBus;
+
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ url = cl.getResource("jboss-beans.xml");
+
+ // Start JBoss Microcontainer
+ bootstrap = new EmbeddedBootstrap();
+ bootstrap.run();
+
+ kernel = bootstrap.getKernel();
+ controller = kernel.getController();
+ bus = kernel.getBus();
+ }
+
+ public void setUserInterface(UserInterface userInterface) {
+ this.userInterface = userInterface;
+ }
+
+ void deploy() {
+ bootstrap.deploy(url);
+ if (!useBus && manager == null) {
+ ControllerContext context = controller.getInstalledContext(HRSERVICE);
+ if (context != null) { manager = (HRManager) context.getTarget(); }
+ }
+ }
+
+ void undeploy() {
+ bootstrap.undeploy(url);
+ }
+
+ private Object invoke(String serviceName, String methodName, Object[] args, String[] types) {
+ Object result = null;
+ try {
+ result = bus.invoke(serviceName, methodName, args, types);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ return result;
+ }
+
+ boolean addEmployee() throws ParseException, NumberFormatException, IllegalArgumentException, IOException {
+ Employee newEmployee = userInterface.getEmployee();
+ Address address = userInterface.getAddress();
+ Date dateOfBirth = userInterface.getDateOfBirth();
+ newEmployee.setAddress(address);
+ newEmployee.setDateOfBirth(dateOfBirth);
+
+ if (useBus)
+ return (Boolean) invoke(HRSERVICE, "addEmployee", new Object[] {newEmployee}, new String[] {EMPLOYEE});
+ else
+ return manager.addEmployee(newEmployee);
+ }
+
+ @SuppressWarnings("unchecked")
+ Set<Employee> listEmployees() {
+ if (useBus)
+ return (Set<Employee>) invoke(HRSERVICE, "getEmployees", new Object[] {}, new String[] {});
+ else
+ return manager.getEmployees();
+ }
+
+ void removeEmployee() throws IllegalArgumentException, IOException {
+ Employee employee = userInterface.getEmployee();
+
+ if (useBus)
+ invoke(HRSERVICE, "removeEmployee", new Object[] {employee}, new String[] {EMPLOYEE});
+ else
+ manager.removeEmployee(employee);
+ }
+
+ Integer getSalary() throws IllegalArgumentException, IOException {
+ Employee employee = userInterface.getEmployee();
+
+ if (useBus)
+ return(Integer) invoke(HRSERVICE, "getSalary", new Object[] {employee}, new String[] {EMPLOYEE});
+ else
+ return manager.getSalary(employee);
+ }
+
+ void setSalary() throws NumberFormatException, IllegalArgumentException, IOException {
+ Employee employee = userInterface.getEmployee();
+ Integer salary = userInterface.getSalary();
+
+ Employee actualEmployee;
+ if (useBus) {
+ actualEmployee = (Employee) invoke(HRSERVICE, "getEmployee", new Object[] {employee.getFirstName(), employee.getLastName()}, new String[] {"java.lang.String","java.lang.String"});
+ invoke(HRSERVICE, "setSalary", new Object[] {actualEmployee, salary}, new String[] {EMPLOYEE, "java.lang.Integer"});
+ } else {
+ actualEmployee = manager.getEmployee(employee.getFirstName(), employee.getLastName());
+ manager.setSalary(actualEmployee, salary);
+ }
+ }
+
+ boolean toggleHiringFreeze() {
+ boolean hiringFreeze;
+ if (useBus) {
+ hiringFreeze = (Boolean) invoke(HRSERVICE, "isHiringFreeze", new Object[] {}, new String[] {});
+ invoke(HRSERVICE, "setHiringFreeze", new Object[] {!hiringFreeze}, new String[] {"boolean"});
+ } else {
+ hiringFreeze = manager.isHiringFreeze();
+ manager.setHiringFreeze(!hiringFreeze);
+ }
+ return !hiringFreeze;
+ }
+
+ @SuppressWarnings("unchecked")
+ String printStatus() {
+ boolean hiringFreeze;
+ int totalEmployees;
+ SalaryStrategy salaryStrategy;
+
+ if (useBus) {
+ hiringFreeze = (Boolean) invoke(HRSERVICE, "isHiringFreeze", new Object[] {}, new String[] {});
+ Set<Employee> employees = (Set<Employee>) invoke(HRSERVICE, "getEmployees", new Object[] {}, new String[] {});
+ totalEmployees = employees.size();
+ salaryStrategy = (SalaryStrategy) invoke(HRSERVICE, "getSalaryStrategy", new Object[] {}, new String[] {});
+ } else {
+ hiringFreeze = manager.isHiringFreeze();
+ totalEmployees = manager.getEmployees().size();
+ salaryStrategy = manager.getSalaryStrategy();
+ }
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Total number of employees: " + totalEmployees);
+ buffer.append("\nHiring Freeze: " + hiringFreeze);
+ buffer.append("\nSalary Strategy: ");
+ if (salaryStrategy == null) {
+ buffer.append("None");
+ } else {
+ buffer.append(salaryStrategy.toString());
+ }
+ return buffer.toString();
+ }
+}
Added: projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/client/ConsoleInput.java
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/client/ConsoleInput.java (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/client/ConsoleInput.java 2008-01-08 15:44:08 UTC (rev 68678)
@@ -0,0 +1,133 @@
+package org.jboss.example.client;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.jboss.example.service.Address;
+import org.jboss.example.service.Employee;
+
+/**
+ * A simple Text User Interface (TUI) so a user can access
+ * the Human Resources service from the command line.
+ *
+ * @author <a href="mailto:mark.newton at jboss.org">Mark Newton</a>
+ */
+public class ConsoleInput implements UserInterface {
+
+ private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+
+ public ConsoleInput(final Client client) {
+ System.out.println(getMenu());
+
+ Thread eventThread = new Thread(new Runnable() {
+ private boolean initialDeployment = false;
+ private boolean quit = false;
+
+ public void run() {
+
+ while (!quit) {
+
+ System.out.print(">");
+
+ try {
+ String input = in.readLine();
+ if (input.length() != 1) {
+ System.out.println("Please enter a valid option.");
+ continue;
+ }
+
+ char option = input.charAt(0);
+ if (initialDeployment == false &&
+ (option == 'u' || option == 'a' || option == 'l' || option == 'r' ||
+ option == 'g' || option == 's' || option == 't' || option == 'p')) {
+ System.out.println("Service has not been deployed yet.");
+ continue;
+ }
+
+ switch (option) {
+ case 'd': client.deploy(); initialDeployment = true; break;
+ case 'u': client.undeploy(); break;
+ case 'a': System.out.println("Added employee: " + client.addEmployee()); break;
+ case 'l': System.out.println("Employees: " + client.listEmployees()); break;
+ case 'r': client.removeEmployee(); break;
+ case 'g': System.out.println("Salary: " + client.getSalary()); break;
+ case 's': client.setSalary(); break;
+ case 't': System.out.println("Hiring Freeze: " + client.toggleHiringFreeze()); break;
+ case 'm': System.out.println(getMenu()); break;
+ case 'p': System.out.println(client.printStatus()); break;
+ case 'q': quit = true; break;
+ default: System.out.println("Invalid option."); break;
+ }
+ } catch (ParseException e) {
+ System.out.println(e.getMessage());
+ } catch (NumberFormatException e) {
+ System.out.println("Invalid integer " + e.getMessage());
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ });
+
+ eventThread.start();
+ }
+
+ private String getMenu() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("-----------------------------------\n");
+ buffer.append("Menu:\n");
+ buffer.append("\n");
+ buffer.append("d) Deploy Human Resources service\n");
+ buffer.append("u) Undeploy Human Resources service\n");
+ buffer.append("\n");
+ buffer.append("a) Add employee\n");
+ buffer.append("l) List employees\n");
+ buffer.append("r) Remove employee\n");
+ buffer.append("g) Get a salary\n");
+ buffer.append("s) Set a salary\n");
+ buffer.append("t) Toggle hiring freeze\n");
+ buffer.append("\n");
+ buffer.append("m) Display menu\n");
+ buffer.append("p) Print service status\n");
+ buffer.append("q) Quit");
+ return buffer.toString();
+ }
+
+ public Employee getEmployee() throws IllegalArgumentException, IOException {
+
+ System.out.println("Please enter the employee's name [firstName lastName]:");
+ String name = in.readLine();
+ String[] names = name.split("\\s");
+ if (names.length != 2) { throw new IllegalArgumentException("Employees must have a first and last name."); }
+ return new Employee(names[0], names[1]);
+ }
+
+ public Address getAddress() throws NumberFormatException, IllegalArgumentException, IOException {
+
+ System.out.println("Please enter the employee's address [number,street,city]:");
+ String address = in.readLine();
+ String[] lines = address.split(",");
+ if (lines.length != 3) { throw new IllegalArgumentException("Addresses must contain a number, street and city."); }
+ return new Address(Integer.parseInt(lines[0]), lines[1], lines[2]);
+ }
+
+ public Date getDateOfBirth() throws ParseException, IOException {
+
+ System.out.println("Please enter the employee's date of birth [dd/MM/yyyy]:");
+ String date = in.readLine();
+ return new SimpleDateFormat("dd/MM/yyyy").parse(date);
+ }
+
+ public Integer getSalary() throws NumberFormatException, IOException {
+
+ System.out.println("Please enter the employee's new salary [integer]: ");
+ String salary = in.readLine();
+ return Integer.valueOf(salary);
+ }
+}
Added: projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/client/EmbeddedBootstrap.java
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/client/EmbeddedBootstrap.java (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/client/EmbeddedBootstrap.java 2008-01-08 15:44:08 UTC (rev 68678)
@@ -0,0 +1,59 @@
+package org.jboss.example.client;
+
+import java.net.URL;
+
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
+
+/**
+ * Add a BasicXMLDeployer to the BasicBootstrap so that we can parse
+ * XML descriptors for the beans (*-beans.xml).
+ *
+ * @author <a href="mailto:mark.newton at jboss.org">Mark Newton</a>
+ */
+public class EmbeddedBootstrap extends BasicBootstrap {
+
+ protected BasicXMLDeployer deployer;
+
+ public EmbeddedBootstrap() throws Exception {
+ super();
+ }
+
+ public void bootstrap() throws Throwable {
+ super.bootstrap();
+ deployer = new BasicXMLDeployer(getKernel());
+ Runtime.getRuntime().addShutdownHook(new Shutdown());
+ }
+
+ public void deploy(URL url) {
+ try {
+ // Workaround the fact that the BasicXMLDeployer does not handle redeployment correctly
+ if (deployer.getDeploymentNames().contains(url.toString())) {
+ System.out.println("Service is already deployed.");
+ return;
+ }
+ deployer.deploy(url);
+ } catch (Throwable t) {
+ log.warn("Error during deployment: " + url, t);
+ }
+ }
+
+ public void undeploy(URL url) {
+ if (!deployer.getDeploymentNames().contains(url.toString())) {
+ System.out.println("Service is already undeployed.");
+ return;
+ }
+ try {
+ deployer.undeploy(url);
+ } catch (Throwable t) {
+ log.warn("Error during undeployment: " + url, t);
+ }
+ }
+
+ protected class Shutdown extends Thread {
+ public void run() {
+ log.info("Shutting down");
+ deployer.shutdown();
+ }
+ }
+}
\ No newline at end of file
Added: projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/client/UserInterface.java
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/client/UserInterface.java (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/java/org/jboss/example/client/UserInterface.java 2008-01-08 15:44:08 UTC (rev 68678)
@@ -0,0 +1,21 @@
+package org.jboss.example.client;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.Date;
+
+import org.jboss.example.service.Address;
+import org.jboss.example.service.Employee;
+
+/**
+ * Allow different implementations of a user interface to be used.
+ * i.e. command line, Swing or even a mock for testing purposes.
+ *
+ * @author <a href="mailto:mark.newton at jboss.org">Mark Newton</a>
+ */
+public interface UserInterface {
+ Employee getEmployee() throws IOException;
+ Address getAddress() throws IOException;
+ Date getDateOfBirth() throws ParseException, IOException;
+ Integer getSalary() throws IOException;
+}
Added: projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/resources/log4j.properties
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/resources/log4j.properties (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/main/resources/log4j.properties 2008-01-08 15:44:08 UTC (rev 68678)
@@ -0,0 +1,7 @@
+log4j.rootLogger=DEBUG, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+
+# Pattern to output the caller's file name and line number.
+log4j.appender.stdout.layout.ConversionPattern=Client %5p [%d{dd-MM-yyyy HH:mm:ss}] %c{1} - %m%n
Added: projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/java/org/jboss/example/client/ClientTestCase.java
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/java/org/jboss/example/client/ClientTestCase.java (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/java/org/jboss/example/client/ClientTestCase.java 2008-01-08 15:44:08 UTC (rev 68678)
@@ -0,0 +1,51 @@
+package org.jboss.example.client;
+
+import junit.framework.TestCase;
+
+/**
+ * Use a mock User Interface to pass values into the client
+ * and check that the Human Resources service is called correctly.
+ *
+ * @author <a href="mailto:mark.newton at jboss.org">Mark Newton</a>
+ */
+public class ClientTestCase extends TestCase
+{
+ public ClientTestCase(String name) {
+ super(name);
+ }
+
+ public void testClientWithoutBus() throws Exception {
+ Client client = new Client(false);
+ assertNotNull(client);
+ runTests(client);
+ }
+
+ public void testClientWithBus() throws Exception {
+ Client client = new Client(true);
+ assertNotNull(client);
+ runTests(client);
+ }
+
+ private void runTests(Client client) throws Exception {
+ client.setUserInterface(new MockUserInterface());
+
+ client.deploy();
+
+ assertEquals(true, client.toggleHiringFreeze());
+ assertEquals(false, client.addEmployee());
+ assertEquals(0, client.listEmployees().size());
+
+ assertEquals(false, client.toggleHiringFreeze());
+ assertEquals(true, client.addEmployee());
+ assertEquals(1, client.listEmployees().size());
+ assertEquals((Integer) 10000, client.getSalary());
+
+ client.setSalary();
+ assertEquals((Integer) 50000, client.getSalary());
+
+ client.removeEmployee();
+ assertEquals(0, client.listEmployees().size());
+
+ client.undeploy();
+ }
+}
Added: projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/java/org/jboss/example/client/ClientTestSuite.java
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/java/org/jboss/example/client/ClientTestSuite.java (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/java/org/jboss/example/client/ClientTestSuite.java 2008-01-08 15:44:08 UTC (rev 68678)
@@ -0,0 +1,25 @@
+package org.jboss.example.client;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * Allow all Client tests to be run.
+ *
+ * @author <a href="mailto:mark.newton at jboss.org">Mark Newton</a>
+ */
+public class ClientTestSuite extends TestSuite
+{
+ public static void main(String[] args) {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Client Tests");
+
+ suite.addTestSuite(ClientTestCase.class);
+
+ return suite;
+ }
+}
Added: projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/java/org/jboss/example/client/MockUserInterface.java
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/java/org/jboss/example/client/MockUserInterface.java (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/java/org/jboss/example/client/MockUserInterface.java 2008-01-08 15:44:08 UTC (rev 68678)
@@ -0,0 +1,39 @@
+package org.jboss.example.client;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.Calendar;
+import java.util.Date;
+
+import org.jboss.example.service.Address;
+import org.jboss.example.service.Employee;
+
+/**
+ * A mock user interface to simulate values being passed in by a user.
+ *
+ * @author <a href="mailto:mark.newton at jboss.org">Mark Newton</a>
+ */
+public class MockUserInterface implements UserInterface {
+
+ public Address getAddress() throws IOException {
+ return new Address(5, "Oxford St", "London");
+ }
+
+ public Date getDateOfBirth() throws ParseException, IOException {
+ Calendar age = Calendar.getInstance();
+ int year = age.get(Calendar.YEAR);
+ int month = age.get(Calendar.MONTH);
+ int day = age.get(Calendar.DAY_OF_MONTH);
+
+ age.set(year - 43, month, day);
+ return age.getTime();
+ }
+
+ public Employee getEmployee() throws IOException {
+ return new Employee("David", "Hasselhof");
+ }
+
+ public Integer getSalary() throws IOException {
+ return new Integer("50000");
+ }
+}
Added: projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/resources/jboss-beans.xml
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/resources/jboss-beans.xml (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/gettingStarted/advDeployment/src/test/resources/jboss-beans.xml 2008-01-08 15:44:08 UTC (rev 68678)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd"
+ xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="HRService" class="org.jboss.example.service.HRManager"/>
+
+</deployment>
More information about the jboss-cvs-commits
mailing list