You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@tomee.apache.org by bu...@apache.org on 2012/03/08 15:22:09 UTC

svn commit: r807868 - in /websites/staging/openejb/trunk: cgi-bin/ content/ content/examples-trunk/ content/examples-trunk/polling-parent/ content/examples-trunk/polling-parent/polling-client/ content/examples-trunk/polling-parent/polling-client/src/ c...

Author: buildbot
Date: Thu Mar  8 14:22:06 2012
New Revision: 807868

Log:
Staging update by buildbot for openejb

Added:
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/pom.xml   (with props)
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/Client.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/api/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/api/AbstractCommand.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/api/Command.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/BestPollCommand.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/ExitCommand.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/HelpCommand.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/NewPollCommand.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/PollResultCommand.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/PollsCommand.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/QueryAndPostCommand.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/ShowPollCommand.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/VoteCommand.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/util/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/util/CommandManager.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/util/ConfigurableClasspathArchive.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/resources/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/resources/META-INF/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/resources/META-INF/scan.xml   (with props)
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/pom.xml   (with props)
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/main/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/main/java/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/main/java/jug/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/main/java/jug/dao/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/main/java/jug/dao/SubjectDao.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/main/java/jug/dao/VoteDao.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/test/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/test/java/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/test/java/jug/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/test/java/jug/dao/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/test/java/jug/dao/SubjectDaoTest.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/pom.xml   (with props)
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/domain/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/domain/Result.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/domain/Subject.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/domain/Value.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/domain/Vote.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/resources/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/resources/META-INF/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/resources/META-INF/persistence.xml   (with props)
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/pom.xml   (with props)
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/java/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/java/jug/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/java/jug/monitoring/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/java/jug/monitoring/VoteCounter.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/java/jug/rest/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/java/jug/rest/PollingApplication.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/java/jug/rest/SubjectService.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/resources/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/resources/META-INF/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/resources/META-INF/beans.xml   (with props)
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/resources/META-INF/env-entries.properties
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/resources/META-INF/resources.xml
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/webapp/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/webapp/WEB-INF/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/webapp/WEB-INF/env-entries.properties
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/test/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/test/java/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/test/java/jug/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/test/java/jug/rest/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/test/java/jug/rest/SubjectServiceTest.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/test/java/jug/rest/arquillian/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/test/java/jug/rest/arquillian/SubjectServiceTomEETest.java
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/test/resources/
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/test/resources/arquillian.xml   (with props)
    websites/staging/openejb/trunk/content/examples-trunk/polling-parent/pom.xml   (with props)
Modified:
    websites/staging/openejb/trunk/cgi-bin/   (props changed)
    websites/staging/openejb/trunk/content/   (props changed)
    websites/staging/openejb/trunk/content/examples-trunk/index.html
    websites/staging/openejb/trunk/content/examples-trunk/pom.xml

Propchange: websites/staging/openejb/trunk/cgi-bin/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Thu Mar  8 14:22:06 2012
@@ -1 +1 @@
-1298167
+1298403

Propchange: websites/staging/openejb/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Thu Mar  8 14:22:06 2012
@@ -1 +1 @@
-1298167
+1298403

Modified: websites/staging/openejb/trunk/content/examples-trunk/index.html
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/index.html (original)
+++ websites/staging/openejb/trunk/content/examples-trunk/index.html Thu Mar  8 14:22:06 2012
@@ -291,7 +291,8 @@ All the examples show code, but some are
 <li><a href="webapps/ejb-webservice/README.html">webapps/ejb-webservice</a></li>
 <li><a href="webapps/jsf/README.html">webapps/jsf</a></li>
 <li><a href="webapps/moviefun/README.html">webapps/moviefun</a></li>
-<li><a href="helloworld-weblogic/README.html">helloworld-weblogic</a></div></div></li>
+<li><a href="helloworld-weblogic/README.html">helloworld-weblogic</a></li>
+<li><a href="polling-parent/README.html">polling-parent</a></div></div></li>
 </ul>
 
 

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/pom.xml
==============================================================================
Binary file - no diff available.

Propchange: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/Client.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/Client.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/Client.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,67 @@
+package jug.client;
+
+import jline.ConsoleReader;
+import jline.FileNameCompletor;
+import jline.SimpleCompletor;
+import jug.client.command.api.AbstractCommand;
+import jug.client.util.CommandManager;
+import org.apache.xbean.recipe.ObjectRecipe;
+import org.apache.xbean.recipe.Option;
+
+import java.io.OutputStreamWriter;
+import java.util.Map;
+
+public class Client {
+    private static final String PROMPT = System.getProperty("user.name") + " @ jug > ";
+    private static final String EXIT_CMD = "exit";
+
+    private Client() {
+        // no-op
+    }
+
+    public static void main(final String[] args) throws Exception {
+        if (args.length != 1) {
+            System.err.println("Pass the base url as parameter");
+            return;
+        }
+
+        final ConsoleReader reader = new ConsoleReader(System.in, new OutputStreamWriter(System.out));
+        reader.addCompletor(new FileNameCompletor());
+        reader.addCompletor(new SimpleCompletor(CommandManager.keys().toArray(new String[CommandManager.size()])));
+
+        String line;
+        while ((line = reader.readLine(PROMPT)) != null) {
+            if (EXIT_CMD.equals(line)) {
+                break;
+            }
+
+            Class<?> cmdClass = null;
+            for (Map.Entry<String, Class<?>> cmd : CommandManager.getCommands().entrySet()) {
+                if (line.startsWith(cmd.getKey())) {
+                    cmdClass = cmd.getValue();
+                    break;
+                }
+            }
+
+            if (cmdClass != null) {
+                final ObjectRecipe recipe = new ObjectRecipe(cmdClass);
+                recipe.setProperty("url", args[0]);
+                recipe.setProperty("command", line);
+                recipe.setProperty("commands", CommandManager.getCommands());
+
+                recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
+                recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
+                recipe.allow(Option.NAMED_PARAMETERS);
+
+                try {
+                    final AbstractCommand cmdInstance = (AbstractCommand) recipe.create();
+                    cmdInstance.execute(line);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            } else {
+                System.err.println("sorry i don't understand '" + line + "'");
+            }
+        }
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/api/AbstractCommand.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/api/AbstractCommand.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/api/AbstractCommand.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,67 @@
+package jug.client.command.api;
+
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.codehaus.jettison.util.StringIndenter;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+
+public abstract class AbstractCommand {
+    protected String command;
+    protected String url;
+
+    protected WebClient client;
+
+    public void execute(final String cmd) {
+        final Response response = invoke(cmd);
+        if (response == null) {
+            return;
+        }
+
+        System.out.println("Status: " + response.getStatus());
+        try {
+            String json = slurp((InputStream) response.getEntity());
+            System.out.println(format(json));
+        } catch (IOException e) {
+            System.err.println("can't get output: " + e.getMessage());
+        }
+    }
+
+    protected String format(final String json) throws IOException {
+        final StringIndenter formatter = new StringIndenter(json);
+        final Writer outWriter = new StringWriter();
+        IOUtils.copy(new StringReader(formatter.result()), outWriter, 2048);
+        outWriter.close();
+        return outWriter.toString();
+    }
+
+    protected abstract Response invoke(final String cmd);
+
+    public void setCommand(String command) {
+        this.command = command;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+        client = WebClient.create(url).accept(MediaType.APPLICATION_JSON);
+    }
+
+    public static String slurp(final InputStream from) throws IOException {
+        ByteArrayOutputStream to = new ByteArrayOutputStream();
+        byte[] buffer = new byte[1024];
+        int length;
+        while ((length = from.read(buffer)) != -1) {
+            to.write(buffer, 0, length);
+        }
+        to.flush();
+        return new String(to.toByteArray());
+    }
+}
+

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/api/Command.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/api/Command.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/api/Command.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,15 @@
+package jug.client.command.api;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ ElementType.TYPE })
+public @interface Command {
+    String usage() default "";
+    String name() default "";
+    String description() default "";
+}
+

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/BestPollCommand.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/BestPollCommand.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/BestPollCommand.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,14 @@
+package jug.client.command.impl;
+
+import jug.client.command.api.AbstractCommand;
+import jug.client.command.api.Command;
+
+import javax.ws.rs.core.Response;
+
+@Command(name = "best", usage = "best", description = "find best poll")
+public class BestPollCommand extends AbstractCommand {
+    @Override
+    protected Response invoke(String cmd) {
+        return client.path("api/subject/best").get();
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/ExitCommand.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/ExitCommand.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/ExitCommand.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,20 @@
+package jug.client.command.impl;
+
+import jug.client.command.api.AbstractCommand;
+import jug.client.command.api.Command;
+
+import javax.ws.rs.core.Response;
+
+// just to get it in the help
+@Command(name = "exit", usage = "exit", description = "exit from the cli")
+public class ExitCommand extends AbstractCommand {
+    @Override
+    public void execute(String cmd) {
+        throw new UnsupportedOperationException("shouldn't be called directly");
+    }
+
+    @Override
+    protected Response invoke(String cmd) {
+        return null;
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/HelpCommand.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/HelpCommand.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/HelpCommand.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,36 @@
+package jug.client.command.impl;
+
+import jug.client.command.api.AbstractCommand;
+import jug.client.command.api.Command;
+
+import javax.ws.rs.core.Response;
+import java.util.Map;
+
+@Command(name = "help", usage = "help", description = "print this help")
+public class HelpCommand extends AbstractCommand {
+    private Map<String, Class<?>> commands;
+
+    @Override
+    public void execute(final String cmd) {
+        for (Map.Entry<String, Class<?>> command : commands.entrySet()) {
+            try {
+                final Class<?> clazz = command.getValue();
+                final Command annotation = clazz.getAnnotation(Command.class);
+                System.out.println(annotation.name() + ": " + annotation.description());
+                System.out.println("\tUsage: " + annotation.usage());
+            } catch (Exception e) {
+                // ignored = command not available
+            }
+        }
+    }
+
+    @Override
+    protected Response invoke(String cmd) {
+        return null;
+    }
+
+    public void setCommands(Map<String, Class<?>> commands) {
+        this.commands = commands;
+    }
+}
+

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/NewPollCommand.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/NewPollCommand.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/NewPollCommand.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,16 @@
+package jug.client.command.impl;
+
+import jug.client.command.api.Command;
+
+@Command(name = "new-poll", usage = "new-poll [<name>, <question>]", description = "create a new poll")
+public class NewPollCommand extends QueryAndPostCommand {
+    @Override
+    protected String getName() {
+        return "name";
+    }
+
+    @Override
+    protected String getPath() {
+        return "api/subject/create";
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/PollResultCommand.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/PollResultCommand.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/PollResultCommand.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,23 @@
+package jug.client.command.impl;
+
+import jug.client.command.api.AbstractCommand;
+import jug.client.command.api.Command;
+
+import javax.ws.rs.core.Response;
+
+import static jug.client.command.impl.PollResultCommand.RESULT_CMD;
+
+@Command(name = RESULT_CMD, usage = RESULT_CMD + " <name>", description = "result of a poll")
+public class PollResultCommand extends AbstractCommand {
+    public static final String RESULT_CMD = "result";
+
+    @Override
+    protected Response invoke(String cmd) {
+        if (RESULT_CMD.length() + 1 >= cmd.length()) {
+            System.err.println("please specify a poll name");
+            return null;
+        }
+
+        return client.path("api/subject/result/".concat(cmd.substring(RESULT_CMD.length() + 1))).get();
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/PollsCommand.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/PollsCommand.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/PollsCommand.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,14 @@
+package jug.client.command.impl;
+
+import jug.client.command.api.AbstractCommand;
+import jug.client.command.api.Command;
+
+import javax.ws.rs.core.Response;
+
+@Command(name = "polls", usage = "polls", description = "list polls")
+public class PollsCommand extends AbstractCommand {
+    @Override
+    public Response invoke(final String cmd) {
+        return client.path("api/subject/list").get();
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/QueryAndPostCommand.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/QueryAndPostCommand.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/QueryAndPostCommand.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,31 @@
+package jug.client.command.impl;
+
+import jug.client.command.api.AbstractCommand;
+import jug.client.command.api.Command;
+
+import javax.ws.rs.core.Response;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public abstract class QueryAndPostCommand extends AbstractCommand {
+    private static final Pattern PATTERN = Pattern.compile(" \\[(.*),(.*)\\]");
+
+    @Override
+    protected Response invoke(final String cmd) {
+        final Matcher matcher = PATTERN.matcher(cmd.substring(getClass().getAnnotation(Command.class).name().length()));
+        if (!matcher.matches() || matcher.groupCount() != 2) {
+            System.err.println("'" + cmd + "' doesn't match command usage");
+            return null;
+        }
+
+        return client.path(getPath()).query(getName(), matcher.group(1).trim()).post(prePost(matcher.group(2).trim()));
+    }
+
+    protected String prePost(final String post) {
+        return post;
+    }
+
+    protected abstract String getName();
+
+    protected abstract String getPath();
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/ShowPollCommand.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/ShowPollCommand.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/ShowPollCommand.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,23 @@
+package jug.client.command.impl;
+
+import jug.client.command.api.AbstractCommand;
+import jug.client.command.api.Command;
+
+import javax.ws.rs.core.Response;
+
+import static jug.client.command.impl.ShowPollCommand.SHOW_POLL_CMD;
+
+@Command(name = SHOW_POLL_CMD, usage = SHOW_POLL_CMD + " <name>", description = "show a poll")
+public class ShowPollCommand extends AbstractCommand {
+    public static final String SHOW_POLL_CMD = "show-poll";
+
+    @Override
+    protected Response invoke(String cmd) {
+        if (SHOW_POLL_CMD.length() + 1 >= cmd.length()) {
+            System.err.println("please specify a poll name");
+            return null;
+        }
+
+        return client.path("api/subject/find/".concat(cmd.substring(SHOW_POLL_CMD.length() + 1))).get();
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/VoteCommand.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/VoteCommand.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/command/impl/VoteCommand.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,28 @@
+package jug.client.command.impl;
+
+import jug.client.command.api.Command;
+import jug.domain.Value;
+
+@Command(name = "vote", usage = "vote [<subject name>, +1|-1]", description = "vote for a subject")
+public class VoteCommand extends QueryAndPostCommand {
+    @Override
+    protected String getName() {
+        return "subject";
+    }
+
+    @Override
+    protected String getPath() {
+        return "api/subject/vote";
+    }
+
+    @Override
+    protected String prePost(final String post) {
+        if ("+1".equals(post) || "like".equals(post)) {
+            return Value.I_LIKE.name();
+        }
+        if ("-1".equals(post)) {
+            return Value.I_DONT_LIKE.name();
+        }
+        throw new IllegalArgumentException("please use +1 or -1 and not '" + post + "'");
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/util/CommandManager.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/util/CommandManager.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/util/CommandManager.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,58 @@
+package jug.client.util;
+
+import jug.client.command.api.Command;
+import org.apache.xbean.finder.Annotated;
+import org.apache.xbean.finder.AnnotationFinder;
+import org.apache.xbean.finder.IAnnotationFinder;
+import org.apache.xbean.finder.UrlSet;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class CommandManager {
+    private static final Logger LOGGER = Logger.getLogger(CommandManager.class.getName());
+    private static final Map<String, Class<?>> COMMANDS = new TreeMap<String, Class<?>>();
+
+    static {
+        final ClassLoader loader = CommandManager.class.getClassLoader();
+        try {
+            UrlSet urlSet = new UrlSet(loader);
+            urlSet = urlSet.exclude(loader.getParent());
+
+            final IAnnotationFinder finder = new AnnotationFinder(new ConfigurableClasspathArchive(loader, urlSet.getUrls()));
+            for (Annotated<Class<?>> cmd : finder.findMetaAnnotatedClasses(Command.class)) {
+                try {
+                    final Command annotation = cmd.getAnnotation(Command.class);
+                    final String key = annotation.name();
+                    if (!COMMANDS.containsKey(key)) {
+                        COMMANDS.put(key, cmd.get());
+                    } else {
+                        LOGGER.warning("command " + key + " already exists, this one will be ignored ( " + annotation.description() + ")");
+                    }
+                } catch (Exception e) {
+                    // command ignored
+                }
+            }
+        } catch (RuntimeException e) {
+            LOGGER.log(Level.SEVERE, "an error occured while getting commands", e);
+        } catch (IOException e) {
+            LOGGER.log(Level.SEVERE, "can't get commands");
+        }
+    }
+
+    public static Map<String, Class<?>> getCommands() {
+        return COMMANDS;
+    }
+
+    public static int size() {
+        return COMMANDS.size();
+    }
+
+    public static Set<String> keys() {
+        return COMMANDS.keySet();
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/util/ConfigurableClasspathArchive.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/util/ConfigurableClasspathArchive.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/java/jug/client/util/ConfigurableClasspathArchive.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,178 @@
+package jug.client.util;
+
+import org.apache.xbean.finder.archive.Archive;
+import org.apache.xbean.finder.archive.ClassesArchive;
+import org.apache.xbean.finder.archive.ClasspathArchive;
+import org.apache.xbean.finder.archive.CompositeArchive;
+import org.apache.xbean.finder.archive.FilteredArchive;
+import org.apache.xbean.finder.filter.Filter;
+import org.apache.xbean.finder.filter.FilterList;
+import org.apache.xbean.finder.filter.PackageFilter;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class ConfigurableClasspathArchive extends CompositeArchive {
+    private static final SAXParserFactory SAX_FACTORY = SAXParserFactory.newInstance();
+    private static final String SCAN_XML = "META-INF/scan.xml";
+
+    public ConfigurableClasspathArchive(final ClassLoader loader, final Iterable<URL> urls) {
+        super(archive(loader, urls, true));
+    }
+
+    public static List<Archive> archive(final ClassLoader loader, final Iterable<URL> urls, boolean forceDescriptor) {
+        final List<Archive> archives = new ArrayList<Archive>();
+        for (URL location : urls) {
+            try {
+                archives.add(archive(loader, location, true));
+            } catch (Exception e) {
+                // ignored
+            }
+        }
+        return archives;
+    }
+
+    public static Archive archive(final ClassLoader loader, final URL location, boolean forceDescriptor) {
+        try {
+            URL scanXml = loader.getResource(SCAN_XML);
+            if (scanXml == null && !forceDescriptor) {
+                return ClasspathArchive.archive(loader, location);
+            } else if (scanXml == null) {
+                return new ClassesArchive();
+            }
+
+            // read descriptors
+            ScanHandler scan;
+            if (scanXml != null) {
+                scan = read(scanXml);
+            } else {
+                scan = new ScanHandler();
+            }
+
+            final Archive packageArchive = packageArchive(scan.getPackages(), loader, location);
+            final Archive classesArchive = classesArchive(scan.getPackages(), scan.getClasses(), loader);
+
+            if (packageArchive != null && classesArchive != null) {
+                return new CompositeArchive(classesArchive, packageArchive);
+            } else if (packageArchive != null) {
+                return  packageArchive;
+            }
+            return classesArchive;
+        } catch (IOException e) {
+            if (forceDescriptor) {
+                return new ClassesArchive();
+            }
+            return ClasspathArchive.archive(loader, location);
+        }
+    }
+
+    public static Archive packageArchive(final Set<String> packageNames, final ClassLoader loader, final URL url) {
+        if (!packageNames.isEmpty()) {
+            return new FilteredArchive(ClasspathArchive.archive(loader, url), filters(packageNames));
+        }
+        return null;
+    }
+
+    private static Filter filters(final Set<String> packageNames) {
+        final List<Filter> filters = new ArrayList<Filter>();
+        for (String packageName : packageNames) {
+            filters.add(new PackageFilter(packageName));
+        }
+        return new FilterList(filters);
+    }
+
+    public static Archive classesArchive(final Set<String> packages, final Set<String> classnames, final ClassLoader loader) {
+        Class<?>[] classes = new Class<?>[classnames.size()];
+        int i = 0;
+        for (String clazz : classnames) {
+            // skip classes managed by package filtering
+            if (packages != null && clazzInPackage(packages, clazz)) {
+                continue;
+            }
+
+            try {
+                classes[i++] = loader.loadClass(clazz);
+            } catch (ClassNotFoundException e) {
+                // ignored
+            }
+        }
+
+        if (i != classes.length) { // shouldn't occur
+            final Class<?>[] updatedClasses = new Class<?>[i];
+            System.arraycopy(classes, 0, updatedClasses, 0, i);
+            classes = updatedClasses;
+        }
+
+        return new ClassesArchive(classes);
+    }
+
+    private static boolean clazzInPackage(final Collection<String> packagename, final String clazz) {
+        for (String str : packagename) {
+            if (clazz.startsWith(str)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public static ScanHandler read(final URL scanXml) throws IOException {
+        final SAXParser parser;
+        try {
+            synchronized (SAX_FACTORY) {
+                parser = SAX_FACTORY.newSAXParser();
+            }
+            final ScanHandler handler = new ScanHandler();
+            parser.parse(new BufferedInputStream(scanXml.openStream()), handler);
+            return handler;
+        } catch (Exception e) {
+            throw new IOException("can't parse " + scanXml.toExternalForm());
+        }
+    }
+
+    public static final class ScanHandler extends DefaultHandler {
+        private final Set<String> classes = new HashSet<String>();
+        private final Set<String> packages = new HashSet<String>();
+        private Set<String> current = null;
+
+        @Override
+        public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+            if (qName.equals("class")) {
+                current = classes;
+            } else if (qName.equals("package")) {
+                current = packages;
+            }
+        }
+
+        @Override
+        public void characters(char ch[], int start, int length) throws SAXException {
+            if (current != null) {
+                current.add(new String(ch, start, length));
+            }
+        }
+
+        @Override
+        public void endElement(final String uri, final String localName, final String qName) throws SAXException {
+            current = null;
+        }
+
+        public Set<String> getPackages() {
+            return packages;
+        }
+
+        public Set<String> getClasses() {
+            return classes;
+        }
+    }
+}
+

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/resources/META-INF/scan.xml
==============================================================================
Binary file - no diff available.

Propchange: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-client/src/main/resources/META-INF/scan.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/pom.xml
==============================================================================
Binary file - no diff available.

Propchange: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/main/java/jug/dao/SubjectDao.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/main/java/jug/dao/SubjectDao.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/main/java/jug/dao/SubjectDao.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,86 @@
+package jug.dao;
+
+import jug.domain.Subject;
+import jug.domain.Value;
+import jug.domain.Vote;
+
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.Singleton;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import java.util.Collection;
+
+@Singleton
+@Lock(LockType.READ)
+public class SubjectDao {
+    @PersistenceContext
+    private EntityManager em;
+
+    public Subject create(final String name, final String question) {
+        final Subject subject = new Subject();
+        subject.setName(name);
+        subject.setQuestion(question);
+
+        em.persist(subject);
+        return subject;
+    }
+
+    public Subject addVote(final Subject subject, final Vote vote) {
+        final Vote foundVote = retrieve(vote, Vote.class, vote.getId());
+        final Subject subjectToUpdate = retrieve(subject, Subject.class, subject.getId());
+
+        subjectToUpdate.getVotes().add(foundVote);
+        return subjectToUpdate;
+    }
+
+    public Subject findByName(final String name) {
+        return em.createNamedQuery(Subject.FIND_BY_NAME_QUERY, Subject.class)
+                .setParameter("name", name)
+                .getSingleResult();
+    }
+
+    public int subjectLikeVoteNumber(final String subjectName) {
+        return subjectVoteNumber(subjectName, Value.I_LIKE);
+    }
+
+    public int subjectNotLikeVoteNumber(final String subjectName) {
+        return subjectVoteNumber(subjectName, Value.I_DONT_LIKE);
+    }
+
+    private int subjectVoteNumber(final String subjectName, final Value value) {
+        return em.createNamedQuery(Subject.COUNT_VOTE, Number.class)
+                    .setParameter("name", subjectName)
+                    .setParameter("value", value)
+                    .getSingleResult().intValue();
+    }
+
+    private <T> T retrieve(final T object, final Class<T> clazz, long id) {
+        if (em.contains(object)) {
+            return object;
+        }
+
+        final T t = em.find(clazz, id);
+        if (t == null) {
+            throw new IllegalArgumentException(clazz.getSimpleName() + " not found");
+        }
+        return t;
+    }
+
+    public Collection<Subject> findAll() {
+        return em.createNamedQuery(Subject.FIND_ALL, Subject.class).getResultList();
+    }
+
+    public Subject bestSubject() {
+        int bestScore = 0;
+        Subject best = null;
+        for (Subject subject : findAll()) {
+            int currentScore = subject.score();
+            if (best == null || bestScore < currentScore) {
+                bestScore = currentScore;
+                best = subject;
+            }
+        }
+        return best;
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/main/java/jug/dao/VoteDao.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/main/java/jug/dao/VoteDao.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/main/java/jug/dao/VoteDao.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,25 @@
+package jug.dao;
+
+import jug.domain.Value;
+import jug.domain.Vote;
+
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.Singleton;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+@Singleton
+@Lock(LockType.READ)
+public class VoteDao {
+    @PersistenceContext
+    private EntityManager em;
+
+    public Vote create(final Value voteValue) {
+        final Vote vote = new Vote();
+        vote.setValue(voteValue);
+
+        em.persist(vote);
+        return vote;
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/test/java/jug/dao/SubjectDaoTest.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/test/java/jug/dao/SubjectDaoTest.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-core/src/test/java/jug/dao/SubjectDaoTest.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,82 @@
+package jug.dao;
+
+import jug.domain.Subject;
+import jug.domain.Value;
+import jug.domain.Vote;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.inject.Inject;
+import javax.naming.NamingException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class SubjectDaoTest {
+    private static EJBContainer container;
+
+    @Inject
+    private SubjectDao subjectDao;
+
+    @Inject
+    private VoteDao voteDao;
+
+    @BeforeClass
+    public static void start() {
+        container = EJBContainer.createEJBContainer();
+    }
+
+    @Before
+    public void inject() throws NamingException {
+        container.getContext().bind("inject", this);
+    }
+
+    @AfterClass
+    public static void stop() {
+        container.close();
+    }
+
+    @Test
+    public void persistSimpleSubject() {
+        final Subject subject = subjectDao.create("TOMEE_JUG", "What do you think about this JUG?");
+        assertNotNull(subject);
+        assertEquals("TOMEE_JUG", subject.getName());
+    }
+
+    @Test
+    public void playWithVotes() {
+        Subject subject = subjectDao.create("TOMEE_JUG_2", "What do you think about this JUG?");
+
+        final Vote vote = voteDao.create(Value.I_LIKE);
+        subject = subjectDao.addVote(subject, vote);
+        assertEquals(1, subject.getVotes().size());
+
+        final Vote moreVote = voteDao.create(Value.I_LIKE);
+        subject = subjectDao.addVote(subject, moreVote);
+        assertEquals(2, subject.getVotes().size());
+
+        final Vote notLiked = voteDao.create(Value.I_DONT_LIKE);
+        subject = subjectDao.addVote(subject, notLiked);
+        assertEquals(3, subject.getVotes().size());
+
+        final Subject retrievedSubject = subjectDao.findByName("TOMEE_JUG_2");
+        assertNotNull(retrievedSubject);
+        assertNotNull(retrievedSubject.getVotes());
+        assertEquals(3, retrievedSubject.getVotes().size());
+    }
+
+    @Test
+    public void voteNumber() {
+        final Subject subject = subjectDao.create("TOMEE_JUG_3", "What do you think about this JUG?");
+
+        subjectDao.addVote(subject, voteDao.create(Value.I_LIKE));
+        subjectDao.addVote(subject, voteDao.create(Value.I_LIKE));
+        subjectDao.addVote(subject, voteDao.create(Value.I_DONT_LIKE));
+
+        assertEquals(2, subjectDao.subjectLikeVoteNumber("TOMEE_JUG_3"));
+        assertEquals(1, subjectDao.subjectNotLikeVoteNumber("TOMEE_JUG_3"));
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/pom.xml
==============================================================================
Binary file - no diff available.

Propchange: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/domain/Result.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/domain/Result.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/domain/Result.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,50 @@
+package jug.domain;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlRootElement
+@XmlType(propOrder = {
+        "likes",
+        "unlikes",
+        "sum"
+})
+public class Result {
+    private int likes;
+    private int unlikes;
+    private int sum;
+
+    public Result() {
+        // no-op
+    }
+
+    public Result(int likes, int unlikes) {
+        this.likes = likes;
+        this.unlikes = -Math.abs(unlikes);
+        sum = likes + unlikes;
+    }
+
+    public int getLikes() {
+        return likes;
+    }
+
+    public void setLikes(int likes) {
+        this.likes = likes;
+    }
+
+    public int getUnlikes() {
+        return unlikes;
+    }
+
+    public void setUnlikes(int unlikes) {
+        this.unlikes = unlikes;
+    }
+
+    public int getSum() {
+        return sum;
+    }
+
+    public void setSum(int sum) {
+        this.sum = sum;
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/domain/Subject.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/domain/Subject.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/domain/Subject.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,89 @@
+package jug.domain;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToMany;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.ArrayList;
+import java.util.Collection;
+
+@Entity
+@NamedQueries({
+        @NamedQuery(name = Subject.FIND_ALL, query = "select s from Subject s"),
+        @NamedQuery(name = Subject.FIND_BY_NAME_QUERY, query = "select s from Subject s where s.name = :name"),
+        @NamedQuery(name = Subject.COUNT_VOTE, query = "select count(s) from Subject s left join s.votes v where v.value = :value and :name = s.name")
+})
+@XmlRootElement
+public class Subject {
+    public static final String FIND_BY_NAME_QUERY = "Subject.findByName";
+    public static final String COUNT_VOTE = "Subject.countVoteNumber";
+    public static final String FIND_ALL = "Subject.findAll";
+
+    @Id
+    @GeneratedValue
+    private long id;
+
+    private String name;
+
+    private String question;
+
+    @OneToMany(fetch = FetchType.EAGER)
+    private Collection<Vote> votes = new ArrayList<Vote>();
+
+    public Subject() {
+        // no-op
+    }
+
+    public Subject(String name, String question) {
+        this.name = name;
+        this.question = question;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getQuestion() {
+        return question;
+    }
+
+    public void setQuestion(String question) {
+        this.question = question;
+    }
+
+    public Collection<Vote> getVotes() {
+        return votes;
+    }
+
+    public void setVotes(Collection<Vote> votes) {
+        this.votes = votes;
+    }
+
+    public int score() {
+        int s = 0;
+        for (Vote vote : votes) {
+            if (vote.getValue().equals(Value.I_LIKE)) {
+                s++;
+            } else {
+                s--;
+            }
+        }
+        return s;
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/domain/Value.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/domain/Value.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/domain/Value.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,5 @@
+package jug.domain;
+
+public enum Value {
+    I_LIKE, I_DONT_LIKE;
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/domain/Vote.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/domain/Vote.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/java/jug/domain/Vote.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,35 @@
+package jug.domain;
+
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@Entity
+@XmlRootElement
+public class Vote {
+    @Id
+    @GeneratedValue
+    private long id;
+
+    @Enumerated(EnumType.STRING)
+    private Value value;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public Value getValue() {
+        return value;
+    }
+
+    public void setValue(Value value) {
+        this.value = value;
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/resources/META-INF/persistence.xml
==============================================================================
Binary file - no diff available.

Propchange: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-domain/src/main/resources/META-INF/persistence.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/pom.xml
==============================================================================
Binary file - no diff available.

Propchange: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/java/jug/monitoring/VoteCounter.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/java/jug/monitoring/VoteCounter.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/java/jug/monitoring/VoteCounter.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,43 @@
+package jug.monitoring;
+
+import jug.domain.Subject;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.management.Description;
+import javax.management.MBean;
+import javax.management.ManagedAttribute;
+import javax.management.ManagedOperation;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+@MBean
+@ApplicationScoped
+@Description("count the number of vote by subject")
+public class VoteCounter {
+    private final Map<String, Subject> subjects = new ConcurrentHashMap<String, Subject>();
+
+    @ManagedAttribute
+    @Description("number of poll created/updated in this instance")
+    public int getSubjectNumber() {
+        return subjects.size();
+    }
+
+    @ManagedOperation
+    @Description("current score of the specified poll")
+    public String names() {
+        return subjects.keySet().toString();
+    }
+
+    @ManagedOperation
+    @Description("current score of the specified poll")
+    public String score(final String name) {
+        if (subjects.containsKey(name)) {
+            return Integer.toString(subjects.get(name).score());
+        }
+        return "poll not found";
+    }
+
+    public void putSubject(final Subject subject) {
+        subjects.put(subject.getName(), subject);
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/java/jug/rest/PollingApplication.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/java/jug/rest/PollingApplication.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/java/jug/rest/PollingApplication.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,15 @@
+package jug.rest;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+import java.util.HashSet;
+import java.util.Set;
+
+@ApplicationPath("/api")
+public class PollingApplication extends Application {
+    public Set<Class<?>> getClasses() {
+        final Set<Class<?>> classes = new HashSet<Class<?>>();
+        classes.add(SubjectService.class);
+        return classes;
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/java/jug/rest/SubjectService.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/java/jug/rest/SubjectService.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/java/jug/rest/SubjectService.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,96 @@
+package jug.rest;
+
+import jug.dao.SubjectDao;
+import jug.dao.VoteDao;
+import jug.domain.Result;
+import jug.domain.Subject;
+import jug.domain.Value;
+import jug.domain.Vote;
+import jug.monitoring.VoteCounter;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.Singleton;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import java.util.Collection;
+import java.util.List;
+
+@Path("subject")
+@Singleton // an ejb just to be able to test in standalone
+@Lock(LockType.READ)
+@TransactionAttribute(TransactionAttributeType.SUPPORTS)
+@Produces({ MediaType.APPLICATION_JSON })
+public class SubjectService {
+    @Inject
+    private SubjectDao dao;
+
+    @Inject
+    private VoteDao voteDao;
+
+    @Inject
+    private VoteCounter counter;
+
+    @Resource(name = "poll.blacklist")
+    private List<String> blackList;
+
+    @POST
+    @Path("create")
+    public Subject create(final String question, @QueryParam("name") final String name) {
+        if (blackList.contains(name)) {
+            throw new IllegalArgumentException("name blaclisted");
+        }
+
+        final Subject subject = dao.create(name, question);
+
+        counter.putSubject(subject);
+
+        return subject;
+    }
+
+    @GET
+    @Path("list")
+    public Collection<Subject> list() {
+        return dao.findAll();
+    }
+
+    @GET
+    @Path("find/{name}")
+    public Subject findByName(@PathParam("name") final String name) {
+        return dao.findByName(name);
+    }
+
+    @GET
+    @Path("best")
+    public Subject best() {
+        return dao.bestSubject();
+    }
+
+    @GET
+    @Path("result/{name}")
+    public Result result(@PathParam("name") final String name) {
+        return new Result(dao.subjectLikeVoteNumber(name), -dao.subjectNotLikeVoteNumber(name));
+    }
+
+    @POST
+    @Path("vote")
+    public Vote vote(final String input, @QueryParam("subject") final String subjectName) {
+        final Vote vote = voteDao.create(Value.valueOf(input));
+        final Subject subject = dao.findByName(subjectName);
+        dao.addVote(subject, vote);
+
+        counter.putSubject(subject); // update
+
+        return vote;
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/resources/META-INF/beans.xml
==============================================================================
Binary file - no diff available.

Propchange: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/resources/META-INF/beans.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/resources/META-INF/env-entries.properties
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/resources/META-INF/env-entries.properties (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/resources/META-INF/env-entries.properties Thu Mar  8 14:22:06 2012
@@ -0,0 +1 @@
+poll.blacklist=test

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/resources/META-INF/resources.xml
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/resources/META-INF/resources.xml (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/resources/META-INF/resources.xml Thu Mar  8 14:22:06 2012
@@ -0,0 +1,26 @@
+<resources>
+  <Resource id="jdbc/polling" type="javax.sql.DataSource">
+    JdbcDriver org.hsqldb.jdbcDriver
+    JdbcUrl jdbc:hsqldb:mem:polling
+    UserName sa
+    Password
+    JtaManaged true
+  </Resource>
+
+
+  <Resource id="jdbc/polling-non-jta" type="javax.sql.DataSource">
+    JdbcDriver org.hsqldb.jdbcDriver
+    JdbcUrl jdbc:hsqldb:mem:polling
+    UserName sa
+    Password
+    JtaManaged false
+  </Resource>
+
+  <!--
+  <Resource id="middle-server" type="org.apache.openejb.config.sys.JndiProvider">
+    java.naming.factory.initial = org.apache.openejb.client.RemoteInitialContextFactory
+    java.naming.provider.url = failover:ejb://192.168.1.20:4201,ejbd://192.168.1.30:4201
+    # java.naming.provider.url = multicast:ejb://192168120:4201?group=default
+  </Resource>
+  -->
+</resources>

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/webapp/WEB-INF/env-entries.properties
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/webapp/WEB-INF/env-entries.properties (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/main/webapp/WEB-INF/env-entries.properties Thu Mar  8 14:22:06 2012
@@ -0,0 +1 @@
+poll.blacklist=poll

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/test/java/jug/rest/SubjectServiceTest.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/test/java/jug/rest/SubjectServiceTest.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/test/java/jug/rest/SubjectServiceTest.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,50 @@
+package jug.rest;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.openejb.OpenEjbContainer;
+import org.apache.openejb.loader.IO;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.naming.NamingException;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import static org.junit.Assert.assertTrue;
+
+public class SubjectServiceTest {
+    private static EJBContainer container;
+
+    @BeforeClass
+    public static void start() {
+        final Properties properties = new Properties();
+        properties.setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true");
+        properties.setProperty(EJBContainer.APP_NAME, "polling/api");
+        container = EJBContainer.createEJBContainer(properties);
+    }
+
+    @Before
+    public void inject() throws NamingException {
+        container.getContext().bind("inject", this);
+    }
+
+    @AfterClass
+    public static void stop() {
+        container.close();
+    }
+
+    @Test
+    public void createVote() throws IOException {
+        final Response response = WebClient.create("http://localhost:4204/polling/")
+                                    .path("api/subject/create")
+                                    .accept("application/json")
+                                    .query("name", "TOMEE_JUG_JSON")
+                                    .post("was it cool?");
+        assertTrue(IO.slurp((InputStream) response.getEntity()).contains("TOMEE_JUG_JSON"));
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/test/java/jug/rest/arquillian/SubjectServiceTomEETest.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/test/java/jug/rest/arquillian/SubjectServiceTomEETest.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/test/java/jug/rest/arquillian/SubjectServiceTomEETest.java Thu Mar  8 14:22:06 2012
@@ -0,0 +1,48 @@
+package jug.rest.arquillian;
+
+import jug.dao.SubjectDao;
+import jug.domain.Subject;
+import jug.monitoring.VoteCounter;
+import jug.rest.SubjectService;
+import org.apache.commons.io.IOUtils;
+import org.apache.ziplock.JarLocation;
+import org.apache.ziplock.WebModule;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.RunAsClient;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.BufferedInputStream;
+import java.net.URL;
+
+import static org.junit.Assert.assertTrue;
+
+@RunAsClient
+@RunWith(Arquillian.class)
+public class SubjectServiceTomEETest {
+    @Deployment
+    public static WebArchive archive() {
+        return new WebModule(SubjectServiceTomEETest.class).getArchive()
+                .addClass(VoteCounter.class)
+                .addPackage(Subject.class.getPackage()) // domain
+                .addAsWebInfResource(new ClassLoaderAsset("META-INF/persistence.xml"), "persistence.xml")
+                .addAsWebInfResource(new ClassLoaderAsset("META-INF/env-entries.properties"), "env-entries.properties")
+                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
+                .addPackage(SubjectDao.class.getPackage()) // core
+                .addPackage(SubjectService.class.getPackage()) // front
+                .addAsLibrary(JarLocation.jarLocation(IOUtils.class)) // helper for client test
+                .addAsLibrary(JarLocation.jarLocation(Test.class)); // junit
+    }
+
+    @Test
+    public void checkThereIsSomeOutput() throws Exception {
+        final String base = "http://localhost:" + System.getProperty("tomee.http.port");
+        final URL url = new URL(base + "/SubjectServiceTomEETest/api/subject/list");
+        final String output = IOUtils.toString(new BufferedInputStream(url.openStream()));
+        assertTrue(output.contains("subject"));
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/test/resources/arquillian.xml
==============================================================================
Binary file - no diff available.

Propchange: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/polling-web/src/test/resources/arquillian.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/pom.xml
==============================================================================
Binary file - no diff available.

Propchange: websites/staging/openejb/trunk/content/examples-trunk/polling-parent/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Modified: websites/staging/openejb/trunk/content/examples-trunk/pom.xml
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/pom.xml (original)
+++ websites/staging/openejb/trunk/content/examples-trunk/pom.xml Thu Mar  8 14:22:06 2012
@@ -17,7 +17,7 @@
     limitations under the License.
 -->
 <!--test 2-->
-<!-- $Rev: 1297652 $ $Date: 2012-03-06 19:00:27 +0000 (Tue, 06 Mar 2012) $ -->
+<!-- $Rev: 1298403 $ $Date: 2012-03-08 14:21:28 +0000 (Thu, 08 Mar 2012) $ -->
 
 <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>
@@ -68,6 +68,7 @@
     <module>movies-complete-meta</module>
     <module>movies-complete</module>
     <module>persistence-fragment</module>
+    <module>polling-parent</module>
     <module>quartz-app</module>
     <module>reload-persistence-unit-properties</module>
     <module>rest-on-ejb</module>