[jboss-svn-commits] JBoss Common SVN: r3638 - invokablecontainer and 36 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Nov 6 19:35:42 EST 2009
Author: ALRubinger
Date: 2009-11-06 19:35:42 -0500 (Fri, 06 Nov 2009)
New Revision: 3638
Added:
invokablecontainer/
invokablecontainer/trunk/
invokablecontainer/trunk/api/
invokablecontainer/trunk/api/pom.xml
invokablecontainer/trunk/api/src/
invokablecontainer/trunk/api/src/main/
invokablecontainer/trunk/api/src/main/java/
invokablecontainer/trunk/api/src/main/java/org/
invokablecontainer/trunk/api/src/main/java/org/jboss/
invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/
invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/
invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/api/
invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/api/Invocation.java
invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/api/InvocationContext.java
invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/api/InvocationException.java
invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/api/InvokableContainer.java
invokablecontainer/trunk/build/
invokablecontainer/trunk/build/pom.xml
invokablecontainer/trunk/core/
invokablecontainer/trunk/core/pom.xml
invokablecontainer/trunk/core/src/
invokablecontainer/trunk/core/src/main/
invokablecontainer/trunk/core/src/main/java/
invokablecontainer/trunk/core/src/main/java/org/
invokablecontainer/trunk/core/src/main/java/org/jboss/
invokablecontainer/trunk/core/src/main/java/org/jboss/ejb3/
invokablecontainer/trunk/core/src/main/java/org/jboss/ejb3/container/
invokablecontainer/trunk/core/src/main/java/org/jboss/ejb3/container/core/
invokablecontainer/trunk/core/src/main/java/org/jboss/ejb3/container/core/DelegatingContainerBase.java
invokablecontainer/trunk/core/src/main/java/org/jboss/ejb3/container/core/InvocationImpl.java
invokablecontainer/trunk/core/src/test/
invokablecontainer/trunk/core/src/test/java/
invokablecontainer/trunk/core/src/test/java/org/
invokablecontainer/trunk/core/src/test/java/org/jboss/
invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/
invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/
invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/
invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/Addable.java
invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/Calculator.java
invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/DelegatingContainerTestCase.java
invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/InvocationImplTest.java
invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/InvokableContainerTestBase.java
invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/InvokableTestCase.java
invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/OriginalVersionInvocationImpl.java
invokablecontainer/trunk/pom.xml
invokablecontainer/trunk/spi/
invokablecontainer/trunk/spi/pom.xml
invokablecontainer/trunk/spi/src/
invokablecontainer/trunk/spi/src/main/
invokablecontainer/trunk/spi/src/main/java/
invokablecontainer/trunk/spi/src/main/java/org/
invokablecontainer/trunk/spi/src/main/java/org/jboss/
invokablecontainer/trunk/spi/src/main/java/org/jboss/ejb3/
invokablecontainer/trunk/spi/src/main/java/org/jboss/ejb3/container/
invokablecontainer/trunk/spi/src/main/java/org/jboss/ejb3/container/spi/
invokablecontainer/trunk/spi/src/main/java/org/jboss/ejb3/container/spi/DelegatingContainer.java
invokablecontainer/trunk/spi/src/main/java/org/jboss/ejb3/container/spi/DirectServiceContainer.java
Log:
[EJBTHREE-1948] Prototype of Invokable Containers
Property changes on: invokablecontainer/trunk
___________________________________________________________________
Name: svn:ignore
+ target
eclipse-target
target-eclipse
.classpath
.project
.settings
Property changes on: invokablecontainer/trunk/api
___________________________________________________________________
Name: svn:ignore
+ target
eclipse-target
target-eclipse
.classpath
.project
.settings
Added: invokablecontainer/trunk/api/pom.xml
===================================================================
--- invokablecontainer/trunk/api/pom.xml (rev 0)
+++ invokablecontainer/trunk/api/pom.xml 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,41 @@
+<!--
+ vi:ts=2:sw=2:expandtab
+-->
+<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 -->
+ <parent>
+ <groupId>org.jboss.invokablecontainer</groupId>
+ <artifactId>build</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>../build/pom.xml</relativePath>
+ </parent>
+
+ <!-- POM Model Version -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Information -->
+ <artifactId>invokablecontainer-api</artifactId>
+ <packaging>jar</packaging>
+ <name>Invokable Containers API</name>
+ <!--//TODO <url>http://labs.jboss.com/jbossejb3</url> -->
+ <description>Invokable Containers Application Programming Interface</description>
+
+ <!-- Properties -->
+ <properties>
+ </properties>
+
+ <!-- Build Information -->
+ <build>
+
+ <plugins>
+
+ </plugins>
+
+ </build>
+
+ <!-- Dependencies -->
+ <dependencies>
+
+ </dependencies>
+</project>
Added: invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/api/Invocation.java
===================================================================
--- invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/api/Invocation.java (rev 0)
+++ invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/api/Invocation.java 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.container.api;
+
+import java.lang.reflect.Method;
+
+/**
+ * Invocation
+ *
+ * Method invocation upon an EJB. Composes the target method, arguments,
+ * and business interface originally invoked upon by the client into a unified
+ * view.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface Invocation
+{
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the target method requested of the invocation.
+ * @return
+ */
+ Method getTargetMethod();
+
+ /**
+ * Returns the arguments to be passed along to this method invocation
+ * @return
+ */
+ Object[] getArgs();
+
+ /**
+ * TODO
+ * @return
+ */
+ InvocationContext getContext();
+}
Added: invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/api/InvocationContext.java
===================================================================
--- invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/api/InvocationContext.java (rev 0)
+++ invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/api/InvocationContext.java 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.container.api;
+
+/**
+ * InvocationContext
+ *
+ * Contextual properties which may be associated with an {@link Invocation}
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface InvocationContext
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Obtains the context property associated with the specified type
+ *
+ * @param <T>
+ * @param type
+ * @throws IllegalArgumentException If the type is not specified
+ */
+ <T> T getProperty(Class<T> type) throws IllegalArgumentException;
+
+ /**
+ * Sets the specified value as a context property under the specified type,
+ * returning the previous value if one existed, else null
+ *
+ * @param <T>
+ * @param type
+ * @param value
+ * @return
+ * @throws IllegalArgumentException If the type or value is not specified
+ */
+ <T> T setProperty(Class<T> type, T value) throws IllegalArgumentException;
+}
Added: invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/api/InvocationException.java
===================================================================
--- invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/api/InvocationException.java (rev 0)
+++ invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/api/InvocationException.java 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.container.api;
+
+/**
+ * InvocationException
+ *
+ * Represents some exceptional circumstance has occurred while
+ * carrying out an invocation. The underlying problem is
+ * represented in the wrapped cause, which is required at construction.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class InvocationException extends Exception
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 1L;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructors -----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructs a new {@link InvocationException}
+ * @param message
+ * @param cause
+ * @throws IllegalArgumentException If no cause has been specified
+ */
+ public InvocationException(final String message, final Throwable cause)
+ {
+ super(message, cause);
+ // Assert invariants
+ this.assertCauseSpecified();
+ }
+
+ /**
+ * Constructs a new {@link InvocationException}
+ * @param cause
+ * @throws IllegalArgumentException If no cause has been specified
+ */
+ public InvocationException(final Throwable cause)
+ {
+ super(cause);
+ // Assert invariants
+ this.assertCauseSpecified();
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that the cause of this Exception has been specified; typically called
+ * from construction
+ *
+ * @throws IllegalArgumentException If no cause exists
+ */
+ private void assertCauseSpecified()
+ {
+
+ // Assert invariants
+ if (this.getCause() == null)
+ {
+ throw new IllegalArgumentException("Cause must be specified");
+ }
+ }
+
+}
Added: invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/api/InvokableContainer.java
===================================================================
--- invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/api/InvokableContainer.java (rev 0)
+++ invokablecontainer/trunk/api/src/main/java/org/jboss/ejb3/container/api/InvokableContainer.java 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.container.api;
+
+/**
+ * Invokable
+ *
+ * Contract of an endpoint servicing incoming invocations. For instance,
+ * implementations may either handle directly, or
+ * delegate to an underlying bean instance.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface InvokableContainer
+{
+
+ /**
+ * Carries out the specified invocation, returning the result
+ *
+ * @param invocation
+ * @return
+ * @throws InvocationException If the underlying invocation
+ * resulted in some Exception; the true context may be obtained
+ * via {@link InvocationException#getCause()}
+ * @throws IllegalArgumentException If the invocation is not specified
+ */
+ Object invoke(Invocation invocation) throws InvocationException;
+}
Property changes on: invokablecontainer/trunk/build
___________________________________________________________________
Name: svn:ignore
+ target
eclipse-target
target-eclipse
.classpath
.project
.settings
Added: invokablecontainer/trunk/build/pom.xml
===================================================================
--- invokablecontainer/trunk/build/pom.xml (rev 0)
+++ invokablecontainer/trunk/build/pom.xml 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,214 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ vi:ts=2:sw=2:expandtab:
+-->
+<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 -->
+ <parent>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-parent</artifactId>
+ <version>4</version>
+ </parent>
+
+ <!-- Model Version -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Configuration -->
+ <groupId>org.jboss.invokablecontainer</groupId>
+ <artifactId>invokablecontainer-build</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <name>Invokable Containers Build</name>
+ <description>Invokable Containers Build Configuration</description>
+ <packaging>pom</packaging>
+
+ <!-- Properties -->
+ <properties>
+
+ <!-- Versioning -->
+ <version.junit_junit>4.6</version.junit_junit>
+
+ </properties>
+
+ <!-- SCM -->
+ <scm>
+ <connection>scm:svn:http://anonsvn.jboss.org/repos/common/invokablecontainer/trunk</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/common/invokablecontainer/trunk</developerConnection>
+ <url>http://anonsvn.jboss.org/repos/common/invokablecontainer/trunk</url>
+ </scm>
+
+ <!-- Issues
+ //TODO
+ <issueManagement>
+ <system>jira</system>
+ <url>http://jira.jboss.com/jira/browse/SHRINKWRAP</url>
+ </issueManagement> -->
+
+ <!-- Licenses
+ //TODO
+ <licenses>
+ <license>
+ <name>Apache License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ </license>
+ </licenses> -->
+
+ <!-- Build -->
+ <build>
+
+ <plugins>
+
+ <!-- JBoss-specific Packaging -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>jboss-packaging-maven-plugin</artifactId>
+ <version>2.0-beta-1</version>
+ <extensions>true</extensions>
+ </plugin>
+
+ <!-- Compiler -->
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <inherited>true</inherited>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <showDeprecation>false</showDeprecation>
+ <showWarnings>true</showWarnings>
+ <optimize>true</optimize>
+ <compilerVersion>1.6</compilerVersion>
+ <fork>true</fork>
+ <argLine>-Xmx512M</argLine>
+ <executable>${JAVA_HOME}/bin/javac</executable>
+ </configuration>
+ </plugin>
+
+ <!-- Surefire -->
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ <trimStackTrace>false</trimStackTrace>
+ <printSummary>true</printSummary>
+ <includes>
+ <include>**/*TestCase.java</include>
+ <include>**/*TestSuite.java</include>
+ </includes>
+ <forkMode>always</forkMode>
+ <reportFormat>xml</reportFormat>
+ </configuration>
+ </plugin>
+
+ <!-- Maven Release Plugin Configuration -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ <configuration>
+ <tagBase>https://svn.jboss.org/repos/common/shrinkwrap/tags</tagBase>
+ </configuration>
+ </plugin>
+
+ <!-- Enforce Maven Environment -->
+ <plugin>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>enforce-maven-environment</id>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <rules>
+ <requireMavenVersion>
+ <version>[2.0.9,2.1)</version> <!-- Must be Maven 2.0.9 >= x > 2.1 -->
+ </requireMavenVersion>
+ <requireJavaVersion>
+ <version>1.6.0</version> <!-- Must be JDK6 -->
+ </requireJavaVersion>
+ <requireProperty>
+ <property>env.JAVA_HOME</property>
+ <message>"JAVA_HOME needs to be set to compile"</message>
+ </requireProperty>
+ </rules>
+ </configuration>
+ </plugin>
+
+ </plugins>
+
+ </build>
+
+ <!-- Dependency Management -->
+ <dependencyManagement>
+ <dependencies>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${version.junit_junit}</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+ </dependencyManagement>
+
+ <!-- Reporting -->
+ <reporting>
+ <plugins>
+
+ <!-- Cobertura (Code Coverage) -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ <configuration>
+ <formats>
+ <format>html</format>
+ <format>xml</format>
+ </formats>
+ </configuration>
+ </plugin>
+
+ <!-- FindBugs -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <xmlOutput>true</xmlOutput>
+ <findbugsXmlOutputDirectory>target/site</findbugsXmlOutputDirectory>
+ </configuration>
+ </plugin>
+
+ <!-- JavaDoc / APIViz -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.5</version>
+ <configuration>
+ <doclet>org.jboss.apiviz.APIviz</doclet>
+ <docletArtifact>
+ <groupId>org.jboss.apiviz</groupId>
+ <artifactId>apiviz</artifactId>
+ <version>1.3.0.GA</version>
+ </docletArtifact>
+ <useStandardDocletOptions>true</useStandardDocletOptions>
+ <charset>UTF-8</charset>
+ <encoding>UTF-8</encoding>
+ <docencoding>UTF-8</docencoding>
+ <breakiterator>true</breakiterator>
+ <version>true</version>
+ <author>true</author>
+ <keywords>true</keywords>
+ <additionalparam>
+ -sourceclasspath ${project.build.outputDirectory}
+ </additionalparam>
+ </configuration>
+ </plugin>
+
+
+ </plugins>
+ </reporting>
+
+</project>
+
Property changes on: invokablecontainer/trunk/core
___________________________________________________________________
Name: svn:ignore
+ target
eclipse-target
target-eclipse
.classpath
.project
.settings
Added: invokablecontainer/trunk/core/pom.xml
===================================================================
--- invokablecontainer/trunk/core/pom.xml (rev 0)
+++ invokablecontainer/trunk/core/pom.xml 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,58 @@
+<!--
+ vi:ts=2:sw=2:expandtab
+-->
+<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 -->
+ <parent>
+ <groupId>org.jboss.invokablecontainer</groupId>
+ <artifactId>build</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>../build/pom.xml</relativePath>
+ </parent>
+
+ <!-- POM Model Version -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Information -->
+ <artifactId>invokablecontainer-core</artifactId>
+ <packaging>jar</packaging>
+ <name>Invokable Containers Core</name>
+ <!--//TODO <url>http://labs.jboss.com/jbossejb3</url> -->
+ <description>Invokable Containers Core</description>
+
+ <!-- Properties -->
+ <properties>
+
+ <!-- Versioning -->
+ <version.org.jboss.invokablecontainer_invokablecontainer.spi>0.1.0-SNAPSHOT</version.org.jboss.invokablecontainer_invokablecontainer.spi>
+
+ </properties>
+
+ <!-- Build Information -->
+ <build>
+
+ <plugins>
+
+ </plugins>
+
+ </build>
+
+ <!-- Dependencies -->
+ <dependencies>
+
+ <!-- org.jboss.invokablecontainer -->
+ <dependency>
+ <groupId>org.jboss.invokablecontainer</groupId>
+ <artifactId>invokablecontainer-spi</artifactId>
+ <version>${version.org.jboss.invokablecontainer_invokablecontainer.spi}</version>
+ </dependency>
+
+ <!-- JUnit -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ </dependencies>
+</project>
Added: invokablecontainer/trunk/core/src/main/java/org/jboss/ejb3/container/core/DelegatingContainerBase.java
===================================================================
--- invokablecontainer/trunk/core/src/main/java/org/jboss/ejb3/container/core/DelegatingContainerBase.java (rev 0)
+++ invokablecontainer/trunk/core/src/main/java/org/jboss/ejb3/container/core/DelegatingContainerBase.java 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.container.core;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.jboss.ejb3.container.api.Invocation;
+import org.jboss.ejb3.container.api.InvocationException;
+import org.jboss.ejb3.container.spi.DelegatingContainer;
+
+/**
+ * DelegatingContainer
+ *
+ * Invokable container which will delegate incoming
+ * requests to be invoked upon a backing target instance,
+ * chosen by {@link DelegatingContainerBase#getTargetInstance(Invocation)}.
+ * Stateless and thread-safe, though subtypes may not offer this same guarantee.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class DelegatingContainerBase implements DelegatingContainer
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @see org.jboss.ejb3.container.api.InvokableContainer#invoke(org.jboss.ejb3.container.api.Invocation)
+ */
+ @Override
+ public Object invoke(final Invocation invocation) throws InvocationException
+ {
+ // Precondition checks
+ if (invocation == null)
+ {
+ throw new IllegalArgumentException("invocation must be specified");
+ }
+
+ // Determine the target instance
+ final Object target = this.getTargetInstance(invocation);
+
+ // Get the target Method and args
+ final Method targetMethod = invocation.getTargetMethod();
+ final Object[] args = invocation.getArgs();
+
+ // Invoke
+ try
+ {
+ return targetMethod.invoke(target, args);
+ }
+ catch (final IllegalArgumentException e)
+ {
+ throw new InvocationException(e);
+ }
+ catch (final IllegalAccessException e)
+ {
+ throw new InvocationException(e);
+ }
+ // Some problem with invocation
+ catch (final InvocationTargetException e)
+ {
+ // Wrap the cause
+ throw new InvocationException(e.getCause());
+ }
+ // Wrap all other runtime exceptions
+ catch (final RuntimeException re)
+ {
+ throw new InvocationException(re);
+ }
+ }
+
+}
Added: invokablecontainer/trunk/core/src/main/java/org/jboss/ejb3/container/core/InvocationImpl.java
===================================================================
--- invokablecontainer/trunk/core/src/main/java/org/jboss/ejb3/container/core/InvocationImpl.java (rev 0)
+++ invokablecontainer/trunk/core/src/main/java/org/jboss/ejb3/container/core/InvocationImpl.java 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,300 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.container.core;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jboss.ejb3.container.api.Invocation;
+import org.jboss.ejb3.container.api.InvocationContext;
+
+/**
+ * InvocationImpl
+ *
+ * Threadsafe implementation of an {@link Invocation}.
+ *
+ * Serializable such that instances may be sent across the wire; though the target
+ * method is deconstructed into components and shipped as a custom
+ * serialized form.
+ *
+ * Value equality is determined by equal target arguments, method,
+ * and {@link InvocationContext}.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public final class InvocationImpl implements Invocation, Serializable
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = -1L;
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(InvocationImpl.class.getName());
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The arguments to be passed along to the target method
+ */
+ private final Object[] args;
+
+ /**
+ * The target method for the invocation; not serialized directly but
+ * will be reconstructed from declaring class, method name, and param types
+ * during deserialization
+ */
+ private transient Method targetMethod;
+
+ //TODO: InvocationContext impl must be Threadsafe, and allow for atomic operations (putIfAbsent, etc)
+
+ //-------------------------------------------------------------------------------------||
+ // Constructors -----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructs a new instance of this invocation, representing the
+ * specified target method and arguments
+ *
+ * @param targetMethod
+ * @param args
+ * @throws IllegalArgumentException If any of the required arguments are not present
+ */
+ public InvocationImpl(final Method targetMethod, final Object[] args)
+ {
+ // Precondition checks
+ if (targetMethod == null)
+ {
+ throw new IllegalArgumentException("Target method must be specified");
+ }
+ if (args == null)
+ {
+ throw new IllegalArgumentException("Arguments for the target method must be specified");
+ }
+
+ // Set
+ this.targetMethod = targetMethod;
+ this.args = args;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @see org.jboss.ejb3.container.api.Invocation#getArgs()
+ */
+ @Override
+ public Object[] getArgs()
+ {
+ return args;
+ }
+
+ /**
+ * @see org.jboss.ejb3.container.api.Invocation#getContext()
+ */
+ @Override
+ public InvocationContext getContext()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * @see org.jboss.ejb3.container.api.Invocation#getTargetMethod()
+ */
+ @Override
+ public Method getTargetMethod()
+ {
+ return this.targetMethod;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Overridden Implementations ---------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return this.getClass().getSimpleName() + " [args=" + Arrays.toString(args) + ", targetMethod=" + targetMethod
+ + "]";
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(args);
+ result = prime * result + ((targetMethod == null) ? 0 : targetMethod.hashCode());
+ return result;
+ }
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(final Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ InvocationImpl other = (InvocationImpl) obj;
+ if (!Arrays.equals(args, other.args))
+ return false;
+ if (targetMethod == null)
+ {
+ if (other.targetMethod != null)
+ return false;
+ }
+ else if (!targetMethod.equals(other.targetMethod))
+ return false;
+ return true;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Serialization ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Serializes the invocation with a custom form
+ *
+ * @serialData After all non-transient fields are written, we pipe out the target method's declaring class,
+ * method name, and array of parameter types. These are used to reconstitute the target Method, which
+ * is not itself Serializable
+ */
+ private void writeObject(final ObjectOutputStream out) throws IOException
+ {
+ // Default write of non-transient fields
+ out.defaultWriteObject();
+
+ // Write out the target method by decomposing it into Serializable parts
+ final Method targetMethod = this.getTargetMethod();
+ final Class<?> declaringClass = targetMethod.getDeclaringClass();
+ final String name = targetMethod.getName();
+ final Class<?>[] paramTypes = targetMethod.getParameterTypes();
+ out.writeObject(declaringClass);
+ out.writeObject(name);
+ out.writeObject(paramTypes);
+
+ // Log
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer("Serialized: " + this);
+ }
+ }
+
+ /**
+ * Deserializes the invocation according to the custom form
+ * defined by {@link InvocationImpl#writeObject(ObjectOutputStream)}
+ */
+ private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException
+ {
+ // Get default form
+ in.defaultReadObject();
+
+ // Assert invariants
+ if (this.getArgs() == null)
+ {
+ throw new IllegalArgumentException("Deserialization resulted in null arguments to the target method");
+ }
+
+ // Reconstruct the Method by getting the declaring class, method name, and signature
+ final Class<?> declaringClass = (Class<?>) in.readObject();
+ final String methodName = (String) in.readObject();
+ final Class<?>[] paramTypes = (Class<?>[]) in.readObject();
+
+ // Some more assertions
+ if (declaringClass == null)
+ {
+ throw new IllegalArgumentException("Declaring class was not read in during deserialization");
+ }
+ if (methodName == null)
+ {
+ throw new IllegalArgumentException("Target method name was not read in during deserialization");
+ }
+ if (paramTypes == null)
+ {
+ throw new IllegalArgumentException(
+ "Parameter types of the target method were not read in during deserialization");
+ }
+
+ // Obtain the target method
+ final Method targetMethod;
+ try
+ {
+ targetMethod = declaringClass.getMethod(methodName, paramTypes);
+ }
+ catch (final NoSuchMethodException nsme)
+ {
+ throw new RuntimeException("Could not deserialize; no target method \"" + methodName + " found in "
+ + declaringClass.getName() + " with param types " + Arrays.asList(paramTypes));
+ }
+
+ // Set the target method
+ this.setTargetMethod(targetMethod);
+
+ // Log
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer("Deserialized: " + this);
+ }
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @param targetMethod the targetMethod to set
+ */
+ private void setTargetMethod(final Method targetMethod)
+ {
+ assert targetMethod != null : "Target method must be specified";
+ this.targetMethod = targetMethod;
+ }
+
+}
Added: invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/Addable.java
===================================================================
--- invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/Addable.java (rev 0)
+++ invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/Addable.java 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.container.core;
+
+/**
+ * Addable
+ *
+ * Contract of entities capaable of an addition operation.
+ * Should only contain one "add" method, as the tests rely
+ * on this via {@link Class#getMethods()} at index position
+ * 0.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+interface Addable
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Adds the arguments, returning the result
+ *
+ * @param args The integers to add
+ * @return The sum of all arguments
+ */
+ int add(int... args) throws IllegalArgumentException;
+
+}
Added: invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/Calculator.java
===================================================================
--- invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/Calculator.java (rev 0)
+++ invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/Calculator.java 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.container.core;
+
+/**
+ * Calculator
+ *
+ * Simple test calculator
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class Calculator implements Addable
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @see org.jboss.ejb3.container.core.Addable#add(int[])
+ */
+ public int add(int... args) throws IllegalArgumentException
+ {
+ // Add all
+ int sum = 0;
+ for (int arg : args)
+ {
+ sum += arg;
+ }
+ return sum;
+ }
+
+}
Added: invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/DelegatingContainerTestCase.java
===================================================================
--- invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/DelegatingContainerTestCase.java (rev 0)
+++ invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/DelegatingContainerTestCase.java 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,229 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.container.core;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import junit.framework.TestCase;
+
+import org.jboss.ejb3.container.api.Invocation;
+import org.jboss.ejb3.container.api.InvocationException;
+import org.jboss.ejb3.container.api.InvokableContainer;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * DelegatingContainerTestCase
+ *
+ * Tests ensuring the contract of {@link InvokableContainer} holds
+ * when using the {@link DelegatingContainerBase}.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class DelegatingContainerTestCase extends InvokableContainerTestBase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(DelegatingContainerTestCase.class.getName());
+
+ /**
+ * Container to calculate invocations
+ */
+ private static InvokableContainer calcContainer;
+
+ /**
+ * Container to throw exceptions for every invocations
+ */
+ private static InvokableContainer exceptionContainer;
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates the invokable container
+ *
+ * @throws Exception
+ */
+ @BeforeClass
+ public static void createInvokableContainers() throws Exception
+ {
+ calcContainer = new SingletonContainer();
+ log.info("Created and set: " + calcContainer);
+ exceptionContainer = new ThrowsExceptionContainer();
+ log.info("Created and set: " + exceptionContainer);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Tests that an invocation upon a backing target instance succeeds
+ */
+ @Test
+ public void testInvocation()
+ {
+ // Adding 1, 2, and 3 should equal 6
+ this.assertInvocationAddingOneTwoThreeSucceeds(calcContainer, 6);
+ }
+
+ /**
+ * Tests that an invocation resulting in some exception will
+ * be wrapped
+ */
+ @Test
+ public void testException()
+ {
+ // Use the Exception-throwing container
+ final InvokableContainer container = exceptionContainer;
+
+ // Get an invocation
+ final Invocation invocation = this.getInvocationToAddOneTwoThree();
+
+ // Invoke
+ try
+ {
+ container.invoke(invocation);
+ }
+ // Should be encountered
+ catch (final InvocationException ie)
+ {
+ final Throwable cause = ie.getCause();
+ log.log(Level.INFO, "Got expected exception", cause);
+ TestCase.assertTrue("Cause should be " + TestException.class.getName() + "; was: "
+ + cause.getClass().getSimpleName(), cause instanceof TestException);
+ return;
+ }
+
+ // Fail, should have thrown an Exception
+ TestCase.fail("Should have thrown an " + InvocationException.class.getSimpleName() + " wrapping a "
+ + TestException.class.getName());
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Classes ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Simple test container which always uses the same instance to service all requests
+ */
+ private static final class SingletonContainer extends DelegatingContainerBase
+ {
+
+ /**
+ * DelegatingCalculator
+ *
+ * Singleton underlying instance to carry out all invocations
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ private enum DelegatingCalculator implements Addable {
+ // The one instance
+ INSTANCE;
+
+ // Delegate for carrying out operations
+ private static final Addable delegate = new Calculator();
+
+ // Implementation; goes to delegate
+ public int add(int... args) throws IllegalArgumentException
+ {
+ return delegate.add(args);
+ }
+
+ }
+
+ /**
+ * Always uses the same instance to service all invocations
+ *
+ * @see org.jboss.ejb3.container.core.DelegatingContainerBase#getTargetInstance(org.jboss.ejb3.container.api.Invocation)
+ */
+ @Override
+ public Object getTargetInstance(final Invocation invocation)
+ {
+ return DelegatingCalculator.INSTANCE;
+ }
+
+ }
+
+ /**
+ * Invokable container which throws {@link TestException} for all incoming requests
+ */
+ private static final class ThrowsExceptionContainer extends DelegatingContainerBase
+ {
+
+ /**
+ * ExceptionThrower
+ *
+ * Singleton underlying instance to always throw an Exception
+ * when invoked
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ private enum ExceptionThrower implements Addable {
+ // The one instance
+ INSTANCE;
+
+ // Implementation; throws an Exception
+ public int add(int... args) throws IllegalArgumentException
+ {
+ throw new TestException();
+ }
+ }
+
+ /**
+ * Always uses the same instance to service all invocations
+ *
+ * @see org.jboss.ejb3.container.core.DelegatingContainerBase#getTargetInstance(org.jboss.ejb3.container.api.Invocation)
+ */
+ @Override
+ public Object getTargetInstance(final Invocation invocation)
+ {
+ return ExceptionThrower.INSTANCE;
+ }
+
+ }
+
+ /**
+ * TestException
+ *
+ * Thrown from all invocations upon {@link ThrowsExceptionContainer}
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ private static final class TestException extends RuntimeException
+ {
+ private static final long serialVersionUID = 1L;
+ }
+
+}
Added: invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/InvocationImplTest.java
===================================================================
--- invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/InvocationImplTest.java (rev 0)
+++ invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/InvocationImplTest.java 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,356 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.container.core;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+import java.io.ObjectStreamConstants;
+import java.io.ObjectStreamField;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.logging.Logger;
+
+import junit.framework.TestCase;
+
+import org.jboss.ejb3.container.api.Invocation;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * InvocationImplTest
+ *
+ * Tests ensuring the contract of {@link Invocation} holds
+ * when using the {@link InvocationImpl}.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class InvocationImplTest
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(InvocationImplTest.class.getName());
+
+ /**
+ * Original invocation constructed
+ */
+ private static Invocation original;
+
+ /**
+ * Duplicate invocation created via serialization copy
+ */
+ private static Invocation roundtrip;
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates a new Invocation instance and creates a clone
+ * by roundtripping via the JDK serialization mechanism
+ *
+ * @throws Exception
+ */
+ @BeforeClass
+ public static void initialize() throws Exception
+ {
+ // Obtain information needed to construct an Invocation instance
+ final Method targetMethod = Calculator.class.getMethods()[0];
+ final Integer[] args =
+ {1, 2, 3};
+
+ // Create an Invocation
+ original = new InvocationImpl(targetMethod, args);
+ log.info("Created invocation: " + original);
+
+ // Create a roundtrip instance via serialization
+ final ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+ final ObjectOutputStream out = new ObjectOutputStream(byteOut);
+ out.writeObject(original);
+ out.flush();
+ out.close();
+ final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(byteOut.toByteArray()));
+ roundtrip = (Invocation) in.readObject();
+ in.close();
+ log.info("Created a serialized copy of the invocation: " + roundtrip);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that {@link Invocation} instances after a serialization
+ * roundtrip are not equal by reference
+ */
+ @Test
+ public void testEqualityByReferenceToRoundtrip()
+ {
+ TestCase.assertFalse("Roundtrip instance should not be equal to original by reference", original == roundtrip);
+ }
+
+ /**
+ * Ensures that {@link Invocation} instances after a serialization
+ * roundtrip are equal by value
+ */
+ @Test
+ public void testEqualityByValueToRoundtrip()
+ {
+ TestCase.assertTrue("Roundtrip instance should be equal to original by value", original.equals(roundtrip));
+ }
+
+ /**
+ * Ensures that {@link Invocation} instances are equal to themselves
+ */
+ @Test
+ public void testEqualityByValueToSame()
+ {
+ TestCase.assertTrue("Invocation objects must be equal by value to equal references", original.equals(original));
+ }
+
+ /**
+ * Ensures that the hash code of {@link Invocation} instances equal by
+ * value are equal
+ */
+ @Test
+ public void testHashCode()
+ {
+ TestCase.assertTrue("Hash codes of objects equal by value must be equal", original.hashCode() == roundtrip
+ .hashCode());
+ }
+
+ /**
+ * Ensures that the target method, even after invocation serialization roundtrip,
+ * remains intact (correct) and may be invoked upon
+ * @throws Exception
+ */
+ @Test
+ public void testRoundtripValidTargetMethod() throws Exception
+ {
+ final Addable target = new Calculator();
+ final Method targetMethod = roundtrip.getTargetMethod();
+ targetMethod.invoke(target, new int[]
+ {3, 4, 5});
+ final int[] args =
+ {1, 2, 3};
+ final int expected = 6;
+ final int actual = ((Integer) targetMethod.invoke(target, args)).intValue();
+ log.info("Adding " + Arrays.asList(args) + ": expecting " + expected + ", got " + actual);
+ TestCase.assertEquals("Method invocation to roundtrip target method did not succeed as expected", expected,
+ actual);
+ }
+
+ /**
+ * Tests that the {@link InvocationImpl} originally released
+ * is able to be represented into the current form
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testWireProtocolOriginalToCurrent() throws IOException
+ {
+ // Make an Invocation of the form originally released
+ final Invocation originalFormat = new OriginalVersionInvocationImpl(original.getTargetMethod(), original
+ .getArgs());
+
+ // Test that the form originally released may be represented as the current type
+ this.testWireProtocol(originalFormat, original.getClass());
+ }
+
+ /**
+ * Tests that the {@link InvocationImpl} current form
+ * is able to be represented as the type originally released
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testWireProtocolCurrentToOriginal() throws IOException
+ {
+ this.testWireProtocol(original, OriginalVersionInvocationImpl.class);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Ensures that the specified client object may be serialized to the specified type
+ *
+ * @param clientObject The object to be serialzed
+ * @param targetType The type we should be represented as
+ * @throws IOException
+ */
+ private void testWireProtocol(final Invocation clientObject, final Class<? extends Invocation> targetType)
+ throws IOException
+ {
+ // Roundtrip the object, now representing as the target type
+ final Invocation roundtrip = serializeAndDeserialize(clientObject, targetType);
+
+ // The type of the object put through roundtrip serialization must be of the type specified
+ TestCase.assertEquals(targetType, roundtrip.getClass());
+ }
+
+ /**
+ *
+ * @param
+ * @see http://crazybob.org/2006/01/unit-testing-serialization-evolution.html
+ * @see http://crazybob.org/2006/01/unit-testing-serialization-evolution_13.html
+ * @see http://www.theserverside.com/news/thread.tss?thread_id=38398
+ * @author Bob Lee
+ */
+ private static <S extends Invocation> S serializeAndDeserialize(final Invocation o, final Class<S> targetType)
+ throws IOException
+ {
+ final ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ final ObjectOutputStream oout = new SpoofingObjectOutputStream(bout, o.getClass(), targetType);
+ oout.writeObject(o);
+ oout.flush();
+ oout.close();
+ final ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
+ final ObjectInputStream oin = new ObjectInputStream(bin);
+ try
+ {
+ final Object obj = oin.readObject();
+ oin.close();
+ log.info("Original invocation type " + o.getClass().getName() + " now represented as "
+ + obj.getClass().getName());
+ return targetType.cast(obj);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Classes ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * SpoofingObjectOutputStream
+ *
+ * ObjectOutputStream which will replace a class name with one explicitly given
+ *
+ * @see http://crazybob.org/2006/01/unit-testing-serialization-evolution_13.html
+ * @author Bob Lee
+ * @version $Revision: $
+ */
+ static class SpoofingObjectOutputStream extends ObjectOutputStream
+ {
+
+ String oldName;
+
+ String newName;
+
+ public SpoofingObjectOutputStream(OutputStream out, Class<?> oldClass, Class<?> newClass) throws IOException
+ {
+ super(out);
+ this.oldName = oldClass.getName();
+ this.newName = newClass.getName();
+ }
+
+ @Override
+ protected void writeClassDescriptor(ObjectStreamClass descriptor) throws IOException
+ {
+ Class<?> clazz = descriptor.forClass();
+
+ boolean externalizable = Externalizable.class.isAssignableFrom(clazz);
+ boolean serializable = Serializable.class.isAssignableFrom(clazz);
+ boolean hasWriteObjectData = hasWriteObjectMethod(clazz);
+ boolean isEnum = Enum.class.isAssignableFrom(clazz);
+
+ writeUTF(replace(descriptor.getName()));
+ writeLong(descriptor.getSerialVersionUID());
+ byte flags = 0;
+ if (externalizable)
+ {
+ flags |= ObjectStreamConstants.SC_EXTERNALIZABLE;
+ flags |= ObjectStreamConstants.SC_BLOCK_DATA;
+ }
+ else if (serializable)
+ {
+ flags |= ObjectStreamConstants.SC_SERIALIZABLE;
+ }
+ if (hasWriteObjectData)
+ {
+ flags |= ObjectStreamConstants.SC_WRITE_METHOD;
+ }
+ if (isEnum)
+ {
+ flags |= ObjectStreamConstants.SC_ENUM;
+ }
+ writeByte(flags);
+
+ ObjectStreamField[] fields = descriptor.getFields();
+ writeShort(fields.length);
+ for (ObjectStreamField field : fields)
+ {
+ writeByte(field.getTypeCode());
+ writeUTF(field.getName());
+ if (!field.isPrimitive())
+ {
+ writeObject(replace(field.getTypeString()));
+ }
+ }
+ }
+
+ String replace(String className)
+ {
+ if (className.equals(newName))
+ {
+ throw new RuntimeException("Found instance of " + className + "." + " Expected instance of " + oldName
+ + ".");
+ }
+ return className == oldName ? newName : className;
+ }
+
+ boolean hasWriteObjectMethod(Class<?> clazz)
+ {
+ try
+ {
+ Method method = clazz.getDeclaredMethod("writeObject", ObjectOutputStream.class);
+ int modifiers = method.getModifiers();
+ return method.getReturnType() == Void.TYPE && !Modifier.isStatic(modifiers)
+ && Modifier.isPrivate(modifiers);
+ }
+ catch (NoSuchMethodException e)
+ {
+ return false;
+ }
+ }
+ }
+
+}
Added: invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/InvokableContainerTestBase.java
===================================================================
--- invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/InvokableContainerTestBase.java (rev 0)
+++ invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/InvokableContainerTestBase.java 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.container.core;
+
+import java.lang.reflect.Method;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import junit.framework.TestCase;
+
+import org.jboss.ejb3.container.api.Invocation;
+import org.jboss.ejb3.container.api.InvocationException;
+import org.jboss.ejb3.container.api.InvokableContainer;
+import org.jboss.ejb3.container.core.InvocationImpl;
+
+/**
+ * InvokableContainerTestBase
+ *
+ * Base for building tests of {@link InvokableContainer}
+ * Containers.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+abstract class InvokableContainerTestBase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(InvokableContainerTestBase.class.getName());
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Methods ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Tests that an request to the specified container
+ * to service the invocation returned by
+ * {@link InvokableContainerTestBase#getInvocationToAddOneTwoThree()}
+ * succeeds, returning the specified expected result
+ *
+ * @param container
+ * @param expectedResut
+ */
+ void assertInvocationAddingOneTwoThreeSucceeds(final InvokableContainer container, final int expectedResut)
+ {
+ // Get the invocation
+ final Invocation invocation = getInvocationToAddOneTwoThree();
+
+ // Invoke
+ Object obj = null;
+ try
+ {
+ obj = container.invoke(invocation);
+ }
+ catch (final InvocationException ie)
+ {
+ log.log(Level.SEVERE, "Invocation failed", ie);
+ TestCase.fail("Invocation failed: " + ie.getCause().toString());
+ }
+
+ // Assert
+ final int actual = ((Integer) obj).intValue();
+ TestCase.assertEquals("Result of invocation was not as expected", expectedResut, actual);
+
+ }
+
+ /**
+ * Returns an invocation request to an {@link Addable} to
+ * add the integers 1, 2 and 3.
+ */
+ Invocation getInvocationToAddOneTwoThree()
+ {
+ final Class<? extends Addable> invokedInterface = Addable.class;
+ final Method targetMethod = invokedInterface.getMethods()[0];
+ final Object[] args =
+ {new int[]
+ {1, 2, 3}};
+ final Invocation invocation = new InvocationImpl(targetMethod, args);
+ return invocation;
+ }
+
+}
Added: invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/InvokableTestCase.java
===================================================================
--- invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/InvokableTestCase.java (rev 0)
+++ invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/InvokableTestCase.java 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.container.core;
+
+import java.util.logging.Logger;
+
+import org.jboss.ejb3.container.api.Invocation;
+import org.jboss.ejb3.container.api.InvocationException;
+import org.jboss.ejb3.container.api.InvokableContainer;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * InvokableTestCase
+ *
+ * Tests ensuring the contract of {@link InvokableContainer} holds
+ * when using the {@link ServicingContainerBase}.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class InvokableTestCase extends InvokableContainerTestBase
+{
+
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(InvokableTestCase.class.getName());
+
+ /**
+ * Container which will be servicing all invocations for this test
+ */
+ private static InvokableContainer container;
+
+ /**
+ * Constant value which should be returned for all invocations
+ */
+ private static final int ONEHUNDRED = 100;
+
+ //-------------------------------------------------------------------------------------||
+ // Lifecycle --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Creates the invokable container
+ *
+ * @throws Exception
+ */
+ @BeforeClass
+ public static void createInvokableContainer() throws Exception
+ {
+ container = new ReturnsOneHundredContainer();
+ log.info("Created and set: " + container);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Tests ------------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Tests that invocation upon a backing target instance succeeds
+ */
+ @Test
+ public void testInvocation()
+ {
+ // Adding 1, 2, and 3 should equal 100, because we use a direct servicing container which always returns 100
+ this.assertInvocationAddingOneTwoThreeSucceeds(container, ONEHUNDRED);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Internal Helper Classes ------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Simple test container which always returns 100 for all incoming invocations
+ */
+ private static final class ReturnsOneHundredContainer implements InvokableContainer
+ {
+
+ /**
+ * @see org.jboss.ejb3.container.api.InvokableContainer#invoke(org.jboss.ejb3.container.api.Invocation)
+ */
+ @Override
+ public Object invoke(final Invocation invocation) throws InvocationException
+ {
+ final int returnValue = ONEHUNDRED;
+ log.info("Returning " + returnValue + " for " + invocation);
+ return returnValue;
+ }
+
+ }
+
+}
Added: invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/OriginalVersionInvocationImpl.java
===================================================================
--- invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/OriginalVersionInvocationImpl.java (rev 0)
+++ invokablecontainer/trunk/core/src/test/java/org/jboss/ejb3/container/core/OriginalVersionInvocationImpl.java 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,285 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.container.core;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.logging.Logger;
+
+import org.jboss.ejb3.container.api.Invocation;
+import org.jboss.ejb3.container.api.InvocationContext;
+import org.jboss.ejb3.container.core.InvocationImpl;
+
+/**
+ * OriginalVersionInvocationImpl
+ *
+ * A copy of the {@link InvocationImpl} originally released.
+ * Do not change this class; it is used by {@link InvocationImplTest#testWireProtocol()}
+ * to ensure wire compatibility in both directions is preserved
+ * as the class evolves.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public final class OriginalVersionInvocationImpl implements Invocation, Serializable
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = -1L;
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(InvocationImpl.class.getName());
+
+ //-------------------------------------------------------------------------------------||
+ // Instance Members -------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * The arguments to be passed along to the target method
+ */
+ private final Object[] args;
+
+ /**
+ * The target method for the invocation; not serialized directly but
+ * will be reconstructed from declaring class, method name, and param types
+ * during deserialization
+ */
+ private transient Method targetMethod;
+
+ //-------------------------------------------------------------------------------------||
+ // Constructors -----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Constructs a new instance of this invocation, representing the
+ * specified target method and arguments
+ *
+ * @param targetMethod
+ * @param args
+ * @throws IllegalArgumentException If any of the required arguments are not present
+ */
+ public OriginalVersionInvocationImpl(final Method targetMethod, final Object[] args)
+ {
+ // Precondition checks
+ if (targetMethod == null)
+ {
+ throw new IllegalArgumentException("Target method must be specified");
+ }
+ if (args == null)
+ {
+ throw new IllegalArgumentException("Arguments for the target method must be specified");
+ }
+
+ // Set
+ this.targetMethod = targetMethod;
+ this.args = args;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @see org.jboss.ejb3.container.api.Invocation#getArgs()
+ */
+ public Object[] getArgs()
+ {
+ return args;
+ }
+
+ /**
+ * @see org.jboss.ejb3.container.api.Invocation#getContext()
+ */
+ public InvocationContext getContext()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * @see org.jboss.ejb3.container.api.Invocation#getTargetMethod()
+ */
+ public Method getTargetMethod()
+ {
+ return this.targetMethod;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Overridden Implementations ---------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString()
+ {
+ return this.getClass().getSimpleName() + " [args=" + Arrays.toString(args) + ", targetMethod=" + targetMethod
+ + "]";
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(args);
+ result = prime * result + ((targetMethod == null) ? 0 : targetMethod.hashCode());
+ return result;
+ }
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ OriginalVersionInvocationImpl other = (OriginalVersionInvocationImpl) obj;
+ if (!Arrays.equals(args, other.args))
+ return false;
+ if (targetMethod == null)
+ {
+ if (other.targetMethod != null)
+ return false;
+ }
+ else if (!targetMethod.equals(other.targetMethod))
+ return false;
+ return true;
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Serialization ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Serializes the invocation with a custom form
+ *
+ * @serialData After all non-transient fields are written, we pipe out the target method's declaring class,
+ * method name, and array of parameter types. These are used to reconstitute the target Method, which
+ * is not itself Serializable
+ */
+ private void writeObject(final ObjectOutputStream out) throws IOException
+ {
+ // Default write of non-transient fields
+ out.defaultWriteObject();
+
+ // Write out the target method by decomposing it into Serializable parts
+ final Method targetMethod = this.getTargetMethod();
+ final Class<?> declaringClass = targetMethod.getDeclaringClass();
+ final String name = targetMethod.getName();
+ final Class<?>[] paramTypes = targetMethod.getParameterTypes();
+ out.writeObject(declaringClass);
+ out.writeObject(name);
+ out.writeObject(paramTypes);
+
+ // Log
+ log.finer("Serialized: " + this);
+ }
+
+ /**
+ * Deserializes the invocation according to the custom form
+ * defined by {@link InvocationImpl#writeObject(ObjectOutputStream)}
+ */
+ private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException
+ {
+ // Get default form
+ in.defaultReadObject();
+
+ // Assert invariants
+ if (this.getArgs() == null)
+ {
+ throw new IllegalArgumentException("Deserialization resulted in null arguments to the target method");
+ }
+
+ // Reconstruct the Method by getting the declaring class, method name, and signature
+ final Class<?> declaringClass = (Class<?>) in.readObject();
+ final String methodName = (String) in.readObject();
+ final Class<?>[] paramTypes = (Class<?>[]) in.readObject();
+
+ // Some more assertions
+ if (declaringClass == null)
+ {
+ throw new IllegalArgumentException("Declaring class was not read in during deserialization");
+ }
+ if (methodName == null)
+ {
+ throw new IllegalArgumentException("Target method name was not read in during deserialization");
+ }
+ if (paramTypes == null)
+ {
+ throw new IllegalArgumentException(
+ "Parameter types of the target method were not read in during deserialization");
+ }
+
+ // Obtain the target method
+ final Method targetMethod;
+ try
+ {
+ targetMethod = declaringClass.getMethod(methodName, paramTypes);
+ }
+ catch (final NoSuchMethodException nsme)
+ {
+ throw new RuntimeException("Could not deserialize; no target method \"" + methodName + " found in "
+ + declaringClass.getName() + " with param types " + Arrays.asList(paramTypes));
+ }
+
+ // Set the target method
+ this.setTargetMethod(targetMethod);
+
+ // Log
+ log.finer("Deserialized: " + this);
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Accessors / Mutators ---------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * @param targetMethod the targetMethod to set
+ */
+ private void setTargetMethod(final Method targetMethod)
+ {
+ assert targetMethod != null : "Target method must be specified";
+ this.targetMethod = targetMethod;
+ }
+
+}
Added: invokablecontainer/trunk/pom.xml
===================================================================
--- invokablecontainer/trunk/pom.xml (rev 0)
+++ invokablecontainer/trunk/pom.xml 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ vi:ts=2:sw=2:expandtab:
+-->
+<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 -->
+ <parent>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-parent</artifactId>
+ <version>4</version>
+ </parent>
+
+ <!-- Model Information -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Information -->
+ <groupId>org.jboss.invokablecontainer</groupId>
+ <artifactId>invokablecontainer-parent</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <name>Invokable Containers Aggregator</name>
+
+ <!-- Aggregate Modules -->
+ <modules>
+ <module>api</module>
+ <module>build</module>
+ <module>core</module>
+ <module>spi</module>
+ </modules>
+
+</project>
Property changes on: invokablecontainer/trunk/spi
___________________________________________________________________
Name: svn:ignore
+ target
eclipse-target
target-eclipse
.classpath
.project
.settings
Added: invokablecontainer/trunk/spi/pom.xml
===================================================================
--- invokablecontainer/trunk/spi/pom.xml (rev 0)
+++ invokablecontainer/trunk/spi/pom.xml 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,48 @@
+<!--
+ vi:ts=2:sw=2:expandtab
+-->
+<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 -->
+ <parent>
+ <groupId>org.jboss.invokablecontainer</groupId>
+ <artifactId>build</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>../build/pom.xml</relativePath>
+ </parent>
+
+ <!-- POM Model Version -->
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- Artifact Information -->
+ <artifactId>invokablecontainer-spi</artifactId>
+ <packaging>jar</packaging>
+ <name>Invokable Containers SPI</name>
+ <!--//TODO <url>http://labs.jboss.com/jbossejb3</url> -->
+ <description>Invokable Containers Service Provider Interface</description>
+
+ <!-- Properties -->
+ <properties>
+
+ <!-- Versioning -->
+ <version.org.jboss.invokablecontainer_invokablecontainer.api>0.1.0-SNAPSHOT</version.org.jboss.invokablecontainer_invokablecontainer.api>
+
+ </properties>
+
+ <!-- Build Information -->
+ <build>
+
+ </build>
+
+ <!-- Dependencies -->
+ <dependencies>
+
+ <!-- org.jboss.invokablecontainer -->
+ <dependency>
+ <groupId>org.jboss.invokablecontainer</groupId>
+ <artifactId>invokablecontainer-api</artifactId>
+ <version>${version.org.jboss.invokablecontainer_invokablecontainer.api}</version>
+ </dependency>
+
+ </dependencies>
+</project>
Added: invokablecontainer/trunk/spi/src/main/java/org/jboss/ejb3/container/spi/DelegatingContainer.java
===================================================================
--- invokablecontainer/trunk/spi/src/main/java/org/jboss/ejb3/container/spi/DelegatingContainer.java (rev 0)
+++ invokablecontainer/trunk/spi/src/main/java/org/jboss/ejb3/container/spi/DelegatingContainer.java 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.container.spi;
+
+import org.jboss.ejb3.container.api.Invocation;
+import org.jboss.ejb3.container.api.InvokableContainer;
+
+/**
+ * DelegatingContainer
+ *
+ * Contract of an {@link InvokableContainer} which may delegate
+ * incoming {@link Invocation}s to a backing target instance
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface DelegatingContainer extends InvokableContainer
+{
+ /**
+ * Returns the target instance to be used in carrying out the specified invocation
+ *
+ * @param invocation
+ * @return
+ */
+ Object getTargetInstance(final Invocation invocation);
+}
Added: invokablecontainer/trunk/spi/src/main/java/org/jboss/ejb3/container/spi/DirectServiceContainer.java
===================================================================
--- invokablecontainer/trunk/spi/src/main/java/org/jboss/ejb3/container/spi/DirectServiceContainer.java (rev 0)
+++ invokablecontainer/trunk/spi/src/main/java/org/jboss/ejb3/container/spi/DirectServiceContainer.java 2009-11-07 00:35:42 UTC (rev 3638)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.container.spi;
+
+import org.jboss.ejb3.container.api.Invocation;
+import org.jboss.ejb3.container.api.InvocationException;
+import org.jboss.ejb3.container.api.InvokableContainer;
+
+/**
+ * DirectServiceContainer
+ *
+ * Contract of an {@link InvokableContainer} which is capable
+ * of first analyzing the context of an incoming {@link Invocation}
+ * to determine if it would like to service the request directly.
+ * If the invocation is not eligible for direct service, it will be
+ * delegated to the instance returned by
+ * {@link DelegatingContainer#getTargetInstance(Invocation)}
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface DirectServiceContainer extends DelegatingContainer
+{
+ //-------------------------------------------------------------------------------------||
+ // Contracts --------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Determines whether or not this instance should be serviced locally or delegated
+ * to an underlying instance as determined from the result of
+ * {@link DirectServiceContainer#getTargetInstance(Invocation)}
+ *
+ * @param invocation
+ * @return true if we should handle locally, false if an underlying instance should
+ * service the invocation
+ * @throws IllegalArgumentException If the invocation is not specified
+ */
+ boolean canService(final Invocation invocation);
+
+ /**
+ * Services this invocation within this container, returning the result
+ *
+ * @param invocation
+ * @return
+ * @throws InvocationException If an exception occurred during invocation, it
+ * will be wrapped and thrown
+ */
+ Object service(final Invocation invocation) throws InvocationException;
+}
More information about the jboss-svn-commits
mailing list