You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2011/07/21 23:42:54 UTC

svn commit: r1149378 [1/5] - in /openejb/trunk/openejb3/examples/webapps: ./ rest-example/ rest-example/src/ rest-example/src/main/ rest-example/src/main/java/ rest-example/src/main/java/org/ rest-example/src/main/java/org/superbiz/ rest-example/src/ma...

Author: rmannibucau
Date: Thu Jul 21 21:42:07 2011
New Revision: 1149378

URL: http://svn.apache.org/viewvc?rev=1149378&view=rev
Log:
adding a beginning for rest-examples (still the view to do and find a better way to initialize data)

Added:
    openejb/trunk/openejb3/examples/webapps/rest-example/
    openejb/trunk/openejb3/examples/webapps/rest-example/init.sh   (with props)
    openejb/trunk/openejb3/examples/webapps/rest-example/pom.xml
    openejb/trunk/openejb3/examples/webapps/rest-example/src/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/CommentDAO.java
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/DAO.java
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/PostDAO.java
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/UserDAO.java
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/Comment.java
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/DatedModel.java
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/Model.java
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/Post.java
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/User.java
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/CommentService.java
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/PostService.java
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/UserService.java
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/resources/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/resources/META-INF/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/resources/META-INF/persistence.xml
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/tomcat/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/tomcat/conf/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/tomcat/conf/logging.properties
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/WEB-INF/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/WEB-INF/web.xml
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/blog.css
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/blog.html
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/blog.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/controllers/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/controllers/post_controller.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/index.html
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/models/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/models/post.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/edit.ejs
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/init.ejs
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/list.ejs
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/show.ejs
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/index.html
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/class/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/class/class.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/controller/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/controller/controller.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/controller/subscribe/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/controller/subscribe/subscribe.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/controller/view/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/controller/view/view.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/dom/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/dom/dom.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/dom/form_params/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/dom/form_params/form_params.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/event/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/event/destroyed/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/event/destroyed/destroyed.html
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/event/destroyed/destroyed.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/event/destroyed/destroyed_menu.html
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/event/event.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/jquery.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/lang/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/lang/json/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/lang/json/json.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/lang/lang.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/lang/openajax/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/lang/openajax/openajax.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/lang/rsplit/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/lang/rsplit/rsplit.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/model/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/model/model.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/view/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/view/ejs/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/view/ejs/ejs.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/jquery/view/view.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/steal/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/steal/dev/
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/steal/dev/dev.js
    openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/steal/steal.js
Modified:
    openejb/trunk/openejb3/examples/webapps/pom.xml

Modified: openejb/trunk/openejb3/examples/webapps/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/pom.xml?rev=1149378&r1=1149377&r2=1149378&view=diff
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/pom.xml (original)
+++ openejb/trunk/openejb3/examples/webapps/pom.xml Thu Jul 21 21:42:07 2011
@@ -34,7 +34,7 @@
     <module>jsf</module>
     <module>struts</module>
     <module>moviefun</module>
-    <!--module>rest-example</module-->
+    <module>rest-example</module>
   </modules>
 
   <!--

Added: openejb/trunk/openejb3/examples/webapps/rest-example/init.sh
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/init.sh?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/init.sh (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/init.sh Thu Jul 21 21:42:07 2011
@@ -0,0 +1,16 @@
+#! /bin/bash
+
+base=http://localhost:1234/rest-example-1.1-SNAPSHOT
+
+for i in {1..3}; do
+	curl -i -H "Accept: application/json" -X PUT "$base/api/user/create?name=Wizard$i&pwd=simplest&&mail=supername$i@supercompany.com"
+done
+
+for i in {1..30}; do
+	curl -i -H "Accept: application/json" -X PUT "$base/api/post/create?title=Title$i&content=Content&userId=$((RANDOM % 3 + 1 ))"
+done
+
+for i in {1..1000}; do
+	curl -i -H "Accept: application/json" -X PUT "$base/api/comment/create?author=Author$i&content=Content$i&postId=$((RANDOM % 30 + 51 ))"
+done
+

Propchange: openejb/trunk/openejb3/examples/webapps/rest-example/init.sh
------------------------------------------------------------------------------
    svn:executable = *

Added: openejb/trunk/openejb3/examples/webapps/rest-example/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/pom.xml?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/pom.xml (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/pom.xml Thu Jul 21 21:42:07 2011
@@ -0,0 +1,151 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<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">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.superbiz</groupId>
+  <artifactId>rest-example</artifactId>
+  <packaging>war</packaging>
+  <version>1.1-SNAPSHOT</version>
+  <name>OpenEJB :: Web Examples :: REST Example</name>
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <openejb.version>4.0.0-SNAPSHOT</openejb.version>
+  </properties>
+  <repositories>
+    <repository>
+      <id>apache-m2-snapshot</id>
+      <name>Apache Snapshot Repository</name>
+      <url>http://repository.apache.org/snapshots</url>
+    </repository>
+    <repository>
+      <id>tomcat-m2-repo</id>
+      <name>Tomcat Dev Repository</name>
+      <url>http://tomcat.apache.org/dev/dist/m2-repository/</url>
+    </repository>
+  </repositories>
+  <pluginRepositories>
+    <pluginRepository>
+      <id>apache-m2-snapshot</id>
+      <name>Apache Snapshot Repository</name>
+      <url>http://repository.apache.org/snapshots</url>
+    </pluginRepository>
+  </pluginRepositories>
+  <build>
+    <defaultGoal>package</defaultGoal>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.3.2</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.openjpa</groupId>
+        <artifactId>openjpa-maven-plugin</artifactId>
+        <version>2.2.0-SNAPSHOT</version>
+        <configuration>
+          <includes>org/superbiz/rest/model/*.class</includes>
+          <addDefaultConstructor>true</addDefaultConstructor>
+          <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
+        </configuration>
+        <executions>
+          <execution>
+            <id>enhancer</id>
+            <phase>process-classes</phase>
+            <goals>
+              <goal>enhance</goal>
+            </goals>
+          </execution>
+        </executions>
+        <dependencies>
+          <dependency>
+            <groupId>org.apache.openjpa</groupId>
+            <artifactId>openjpa</artifactId>
+            <version>2.0.1</version>
+          </dependency>
+        </dependencies>
+      </plugin>
+      <plugin>
+        <artifactId>maven-war-plugin</artifactId>
+        <version>2.1.1</version>
+        <configuration>
+          <packagingExcludes>WEB-INF/web.xml</packagingExcludes>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>com.googlecode.t7mp</groupId>
+        <artifactId>maven-t7-plugin</artifactId>
+        <version>0.9.7</version>
+        <configuration>
+          <tomcatHttpPort>1234</tomcatHttpPort>
+          <tomcatShutdownPort>13245</tomcatShutdownPort>
+          <tomcatVersion>7.0.16</tomcatVersion>
+          <libs>
+            <jarArtifact>
+              <groupId>org.apache.openejb</groupId>
+              <artifactId>openejb-logging</artifactId>
+              <version>${openejb.version}</version>
+            </jarArtifact>
+          </libs>
+          <webapps>
+            <webappArtifact>
+              <groupId>org.apache.openejb</groupId>
+              <artifactId>openejb-tomcat-webapp</artifactId>
+              <version>${openejb.version}</version>
+              <contextPath>openejb</contextPath>
+            </webappArtifact>
+          </webapps>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-core</artifactId>
+      <version>4.0.0-SNAPSHOT</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <!--
+  This section allows you to configure where to publish libraries for sharing.
+  It is not required and may be deleted.  For more information see:
+  http://maven.apache.org/plugins/maven-deploy-plugin/
+  -->
+  <distributionManagement>
+    <repository>
+      <id>local-release-repo</id>
+      <url>file://${project.build.outputDirectory}/repo/</url>
+    </repository>
+    <snapshotRepository>
+      <id>local-snapshot-repo</id>
+      <url>file://${project.build.outputDirectory}/repo/</url>
+    </snapshotRepository>
+  </distributionManagement>
+</project>
\ No newline at end of file

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/CommentDAO.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/CommentDAO.java?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/CommentDAO.java (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/CommentDAO.java Thu Jul 21 21:42:07 2011
@@ -0,0 +1,54 @@
+package org.superbiz.rest.dao;
+
+import org.superbiz.rest.model.Comment;
+import org.superbiz.rest.model.Post;
+
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author Romain Manni-Bucau
+ */
+@Stateless
+public class CommentDAO extends DAO {
+    @EJB private DAO dao;
+
+    public List<Comment> list(long postId) {
+        Post post = dao.find(Post.class, postId);
+        if (post == null) {
+            throw new IllegalArgumentException("post with id " + postId + " not found");
+        }
+        return Collections.unmodifiableList(post.getComments());
+    }
+
+    public Comment create(String author, String content, long postId) {
+        Post post = dao.find(Post.class, postId);
+        if (post == null) {
+            throw new IllegalArgumentException("post with id " + postId + " not found");
+        }
+
+        Comment comment = new Comment();
+        comment.setAuthor(author);
+        comment.setContent(content);
+        dao.create(comment);
+        comment.setPost(post);
+        return comment;
+    }
+
+    public void delete(long id) {
+        dao.delete(Comment.class, id);
+    }
+
+    public Comment update(long id, String author, String content) {
+        Comment comment = dao.find(Comment.class, id);
+        if (comment == null) {
+            throw new IllegalArgumentException("comment with id " + id + " not found");
+        }
+
+        comment.setAuthor(author);
+        comment.setContent(content);
+        return dao.update(comment);
+    }
+}

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/DAO.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/DAO.java?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/DAO.java (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/DAO.java Thu Jul 21 21:42:07 2011
@@ -0,0 +1,69 @@
+/*
+ *     Licensed to the Apache Software Foundation (ASF) under one or more
+ *     contributor license agreements.  See the NOTICE file distributed with
+ *     this work for additional information regarding copyright ownership.
+ *     The ASF licenses this file to You under the Apache License, Version 2.0
+ *     (the "License"); you may not use this file except in compliance with
+ *     the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *     Unless required by applicable law or agreed to in writing, software
+ *     distributed under the License is distributed on an "AS IS" BASIS,
+ *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *     See the License for the specific language governing permissions and
+ *     limitations under the License.
+ */
+package org.superbiz.rest.dao;
+
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+import java.util.List;
+
+/**
+ * Simply maps the entitymanager.
+ * It simplifies refactoring (unitName change) and wraps some logic (limited queries).
+ *
+ * @author Romain Manni-Bucau
+ */
+@Stateless
+public class DAO {
+    @PersistenceContext(unitName = "blog") private EntityManager em;
+
+    public <E> E create(E e) {
+        em.persist(e);
+        return e;
+    }
+
+    public <E> E update(E e) {
+        return em.merge(e);
+    }
+
+    public <E> void delete(Class<E> clazz, long id) {
+        em.remove(em.find(clazz, id));
+    }
+
+    public <E> E find(Class<E> clazz, long id) {
+        return em.find(clazz, id);
+    }
+
+    public <E> List<E> find(Class<E> clazz, String query, int min, int max) {
+        return queryRange(em.createQuery(query), min, max).getResultList();
+    }
+
+    public <E> List<E> namedFind(Class<E> clazz, String query, int min, int max) {
+        return queryRange(em.createNamedQuery(query), min, max).getResultList();
+    }
+
+    private static Query queryRange(Query query, int min, int max) {
+        if (max >= 0) {
+            query.setMaxResults(max);
+        }
+        if (min >= 0) {
+            query.setFirstResult(min);
+        }
+        return query;
+    }
+}

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/PostDAO.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/PostDAO.java?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/PostDAO.java (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/PostDAO.java Thu Jul 21 21:42:07 2011
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.superbiz.rest.dao;
+
+import org.superbiz.rest.model.Post;
+import org.superbiz.rest.model.User;
+
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import java.util.List;
+
+/**
+ * @author Romain Manni-Bucau
+ */
+@Stateless
+public class PostDAO {
+    @EJB private DAO dao;
+
+    public Post create(String title, String content, long userId) {
+        User user = dao.find(User.class, userId);
+        Post post = new Post();
+        post.setTitle(title);
+        post.setContent(content);
+        post.setUser(user);
+        return dao.create(post);
+    }
+
+    public Post find(long id) {
+        return dao.find(Post.class, id);
+    }
+
+    public List<Post> list(int first, int max) {
+        return dao.namedFind(Post.class, "post.list", first, max);
+    }
+
+    public void delete(long id) {
+        dao.delete(Post.class, id);
+    }
+
+    public Post update(long id, long userId, String title, String content) {
+        User user = dao.find(User.class, userId);
+        if (user == null) {
+            throw  new IllegalArgumentException("setUser id " + id + " not found");
+        }
+
+        Post post = dao.find(Post.class, id);
+        if (post == null) {
+            throw  new IllegalArgumentException("post id " + id + " not found");
+        }
+
+        post.setTitle(title);
+        post.setContent(content);
+        post.setUser(user);
+        return dao.update(post);
+    }
+}

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/UserDAO.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/UserDAO.java?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/UserDAO.java (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/UserDAO.java Thu Jul 21 21:42:07 2011
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.superbiz.rest.dao;
+
+import org.superbiz.rest.model.User;
+
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import java.util.List;
+
+/**
+ * @author Romain Manni-Bucau
+ */
+@Stateless
+public class UserDAO {
+    @EJB private DAO dao;
+
+    public User create(String name, String pwd, String mail) {
+        User user = new User();
+        user.setFullname(name);
+        user.setPassword(pwd);
+        user.setEmail(mail);
+        return dao.create(user);
+    }
+
+    public List<User> list(int first, int max) {
+        return dao.namedFind(User.class, "user.list", first, max);
+    }
+
+    public User find(long id) {
+        return dao.find(User.class, id);
+    }
+
+    public void delete(long id) {
+        dao.delete(User.class, id);
+    }
+
+    public User update(long id, String name, String pwd, String mail) {
+        User user = dao.find(User.class, id);
+        if (user == null) {
+            throw  new IllegalArgumentException("setUser id " + id + " not found");
+        }
+
+        user.setFullname(name);
+        user.setPassword(pwd);
+        user.setEmail(mail);
+        return dao.update(user);
+    }
+}

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/Comment.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/Comment.java?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/Comment.java (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/Comment.java Thu Jul 21 21:42:07 2011
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *     contributor license agreements.  See the NOTICE file distributed with
+ *     this work for additional information regarding copyright ownership.
+ *     The ASF licenses this file to You under the Apache License, Version 2.0
+ *     (the "License"); you may not use this file except in compliance with
+ *     the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *     Unless required by applicable law or agreed to in writing, software
+ *     distributed under the License is distributed on an "AS IS" BASIS,
+ *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *     See the License for the specific language governing permissions and
+ *     limitations under the License.
+ */
+
+package org.superbiz.rest.model;
+
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.Lob;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+/**
+ * @author Romain Manni-Bucau
+ */
+@Entity
+@NamedQueries({
+    @NamedQuery(name = "comment.list", query = "select c from Comment c")
+})
+@XmlRootElement(name = "comment")
+public class Comment extends Model {
+    @NotNull @Size(min = 1) private String author;
+    @NotNull @Size(min = 1) @Lob private String content;
+    @ManyToOne @JoinColumn(name = "post_id") @Valid @XmlTransient private Post post;
+
+    public void setAuthor(final String author) {
+        this.author = author;
+    }
+
+    public void setContent(final String content) {
+        this.content = content;
+    }
+
+    public void setPost(Post post) {
+        post.addComment(this);
+        this.post = post;
+    }
+
+    public String getAuthor() {
+        return author;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public Post getPost() {
+        return post;
+    }
+}

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/DatedModel.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/DatedModel.java?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/DatedModel.java (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/DatedModel.java Thu Jul 21 21:42:07 2011
@@ -0,0 +1,25 @@
+package org.superbiz.rest.model;
+
+import javax.persistence.MappedSuperclass;
+import javax.persistence.PrePersist;
+import java.util.Date;
+
+/**
+ * @author Romain Manni-Bucau
+ */
+@MappedSuperclass
+public abstract class DatedModel extends Model {
+    private Date created;
+
+    @PrePersist public void create() {
+        created = new Date();
+    }
+
+    public Date getCreated() {
+        return created;
+    }
+
+    public void setCreated(Date created) {
+        this.created = created;
+    }
+}

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/Model.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/Model.java?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/Model.java (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/Model.java Thu Jul 21 21:42:07 2011
@@ -0,0 +1,27 @@
+package org.superbiz.rest.model;
+
+import javax.persistence.Access;
+import javax.persistence.AccessType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+
+/**
+ * @author Romain Manni-Bucau
+ */
+@MappedSuperclass
+@Access(AccessType.FIELD)
+@XmlAccessorType(XmlAccessType.FIELD)
+public abstract class Model {
+    @Id @GeneratedValue protected long id;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+}

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/Post.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/Post.java?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/Post.java (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/Post.java Thu Jul 21 21:42:07 2011
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *     contributor license agreements.  See the NOTICE file distributed with
+ *     this work for additional information regarding copyright ownership.
+ *     The ASF licenses this file to You under the Apache License, Version 2.0
+ *     (the "License"); you may not use this file except in compliance with
+ *     the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *     Unless required by applicable law or agreed to in writing, software
+ *     distributed under the License is distributed on an "AS IS" BASIS,
+ *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *     See the License for the specific language governing permissions and
+ *     limitations under the License.
+ */
+
+package org.superbiz.rest.model;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Lob;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToMany;
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Romain Manni-Bucau
+ */
+@Entity
+@NamedQueries({
+    @NamedQuery(name = "post.list", query = "select p from Post p")
+})
+@XmlRootElement(name = "post")
+public class Post extends DatedModel {
+    @NotNull @Size(min = 1) private String title;
+    @NotNull @Size(min = 1) @Lob private String content;
+    @ManyToOne @Valid private User user;
+    @OneToMany(mappedBy = "post", fetch = FetchType.EAGER) private List<Comment> comments = new ArrayList<Comment>();
+
+    public void setTitle(final String title) {
+        this.title = title;
+    }
+
+    public void setContent(final String content) {
+        this.content = content;
+    }
+
+    public void setUser(final User user) {
+        this.user = user;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public User getUser() {
+        return user;
+    }
+
+    public List<Comment> getComments() {
+        return comments;
+    }
+
+    public void setComments(List<Comment> comments) {
+        this.comments = comments;
+    }
+
+    public void addComment(final Comment comment) {
+        getComments().add(comment);
+    }
+}

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/User.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/User.java?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/User.java (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/User.java Thu Jul 21 21:42:07 2011
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *     contributor license agreements.  See the NOTICE file distributed with
+ *     this work for additional information regarding copyright ownership.
+ *     The ASF licenses this file to You under the Apache License, Version 2.0
+ *     (the "License"); you may not use this file except in compliance with
+ *     the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *     Unless required by applicable law or agreed to in writing, software
+ *     distributed under the License is distributed on an "AS IS" BASIS,
+ *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *     See the License for the specific language governing permissions and
+ *     limitations under the License.
+ */
+
+package org.superbiz.rest.model;
+
+import javax.persistence.Entity;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * @author Romain Manni-Bucau
+ */
+@Entity
+@NamedQueries({
+    @NamedQuery(name = "user.list", query = "select u from User u")
+})
+@XmlRootElement(name = "user")
+public class User extends Model {
+    @NotNull @Size(min = 3, max = 15) private String fullname;
+    @NotNull @Size(min = 5, max = 15) private String password;
+    @NotNull @Pattern(regexp = ".+@.+\\.[a-z]+") private String email;
+
+    public void setFullname(final String fullname) {
+        this.fullname = fullname;
+    }
+
+    public void setPassword(final String password) {
+        this.password = password;
+    }
+
+    public void setEmail(final String email) {
+        this.email = email;
+    }
+
+    public String getFullname() {
+        return fullname;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public String getEmail() {
+        return email;
+    }
+}

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/CommentService.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/CommentService.java?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/CommentService.java (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/CommentService.java Thu Jul 21 21:42:07 2011
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *     contributor license agreements.  See the NOTICE file distributed with
+ *     this work for additional information regarding copyright ownership.
+ *     The ASF licenses this file to You under the Apache License, Version 2.0
+ *     (the "License"); you may not use this file except in compliance with
+ *     the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *     Unless required by applicable law or agreed to in writing, software
+ *     distributed under the License is distributed on an "AS IS" BASIS,
+ *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *     See the License for the specific language governing permissions and
+ *     limitations under the License.
+ */
+
+package org.superbiz.rest.service;
+
+import org.superbiz.rest.dao.CommentDAO;
+import org.superbiz.rest.model.Comment;
+
+import javax.ejb.EJB;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import java.util.List;
+
+/**
+ * @author Romain Manni-Bucau
+ */
+@Path("/api/comment")
+@Produces({"text/xml", "application/json"})
+public class CommentService {
+    @EJB private CommentDAO commentDao;
+
+    @Path("/create") @PUT public Comment create(@QueryParam("author") String author,
+                                                @QueryParam("content") String content,
+                                                @QueryParam("postId") long postId) {
+        return commentDao.create(author, content, postId);
+    }
+
+    @Path("/list/{postId}") @GET public List<Comment> list(@PathParam("postId") long postId) {
+        return commentDao.list(postId);
+    }
+
+    @Path("/delete/{id}") @DELETE public void delete(@PathParam("id") long id) {
+        commentDao.delete(id);
+    }
+
+    @Path("/update/{id}") @POST public Comment update(@PathParam("id") long id,
+                                                      @QueryParam("author") String author,
+                                                      @QueryParam("content") String content) {
+        return commentDao.update(id, author, content);
+    }
+}

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/PostService.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/PostService.java?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/PostService.java (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/PostService.java Thu Jul 21 21:42:07 2011
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *     contributor license agreements.  See the NOTICE file distributed with
+ *     this work for additional information regarding copyright ownership.
+ *     The ASF licenses this file to You under the Apache License, Version 2.0
+ *     (the "License"); you may not use this file except in compliance with
+ *     the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *     Unless required by applicable law or agreed to in writing, software
+ *     distributed under the License is distributed on an "AS IS" BASIS,
+ *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *     See the License for the specific language governing permissions and
+ *     limitations under the License.
+ */
+package org.superbiz.rest.service;
+
+import org.superbiz.rest.dao.PostDAO;
+import org.superbiz.rest.model.Post;
+
+import javax.ejb.EJB;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import java.util.List;
+
+/**
+ * @author Romain Manni-Bucau
+ */
+@Path("/api/post")
+@Produces({ "text/xml", "application/json" })
+public class PostService {
+    @EJB private PostDAO dao;
+
+    @Path("/create") @PUT public Post create(@QueryParam("title") String title,
+                                        @QueryParam("content") String content,
+                                        @QueryParam("userId") long userId) {
+        return dao.create(title, content, userId);
+    }
+
+    @Path("/list") @GET public List<Post> list(@QueryParam("first") @DefaultValue("0") int first,
+                                          @QueryParam("max") @DefaultValue("20") int max) {
+        return dao.list(first, max);
+    }
+
+    @Path("/show/{id}") @GET public Post show(@PathParam("id") long id) {
+        return dao.find(id);
+    }
+
+    @Path("/delete/{id}") @DELETE public void delete(@PathParam("id") long id) {
+        dao.delete(id);
+    }
+
+    @Path("/update/{id}") @POST public Post update(@PathParam("id") long id,
+                                        @QueryParam("userId") long userId,
+                                        @QueryParam("name") String title,
+                                        @QueryParam("pwd") String content) {
+        return dao.update(id, userId, title, content);
+    }
+}

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/UserService.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/UserService.java?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/UserService.java (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/UserService.java Thu Jul 21 21:42:07 2011
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *     contributor license agreements.  See the NOTICE file distributed with
+ *     this work for additional information regarding copyright ownership.
+ *     The ASF licenses this file to You under the Apache License, Version 2.0
+ *     (the "License"); you may not use this file except in compliance with
+ *     the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *     Unless required by applicable law or agreed to in writing, software
+ *     distributed under the License is distributed on an "AS IS" BASIS,
+ *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *     See the License for the specific language governing permissions and
+ *     limitations under the License.
+ */
+package org.superbiz.rest.service;
+
+import org.superbiz.rest.dao.UserDAO;
+import org.superbiz.rest.model.Post;
+import org.superbiz.rest.model.User;
+
+import javax.ejb.EJB;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import java.util.List;
+
+/**
+ * @author Romain Manni-Bucau
+ */
+@Path("/api/user")
+@Produces({ "text/xml", "application/json" })
+public class UserService {
+    @EJB private UserDAO dao;
+
+    @Path("/create") @PUT public User create(@QueryParam("name") String name,
+                                        @QueryParam("pwd") String pwd,
+                                        @QueryParam("mail") String mail) {
+        return dao.create(name, pwd, mail);
+    }
+
+    @Path("/list") @GET public List<User> list(@QueryParam("first") @DefaultValue("0") int first,
+                                          @QueryParam("max") @DefaultValue("20") int max) {
+        return dao.list(first, max);
+    }
+
+    @Path("/show") @GET public User show(@PathParam("id") long id) {
+        return dao.find(id);
+    }
+
+    @Path("/delete/{id}") @DELETE public void delete(@PathParam("id") long id) {
+        dao.delete(id);
+    }
+
+    @Path("/update/{id}") @POST public User update(@PathParam("id") long id,
+                                        @QueryParam("name") String name,
+                                        @QueryParam("pwd") String pwd,
+                                        @QueryParam("mail") String mail) {
+        return dao.update(id, name, pwd, mail);
+    }
+}

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/resources/META-INF/persistence.xml?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/resources/META-INF/persistence.xml (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/resources/META-INF/persistence.xml Thu Jul 21 21:42:07 2011
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<persistence version="2.0"
+   xmlns="http://java.sun.com/xml/ns/persistence"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
+                       http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
+  <persistence-unit name="blog">
+    <jta-data-source>My DataSource</jta-data-source>
+    <non-jta-data-source>My Unmanaged DataSource</non-jta-data-source>
+    <class>org.superbiz.rest.model.User</class>
+    <class>org.superbiz.rest.model.Post</class>
+    <class>org.superbiz.rest.model.Comment</class>
+    <properties>
+      <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
+    </properties>
+  </persistence-unit>
+</persistence>
\ No newline at end of file

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/tomcat/conf/logging.properties
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/tomcat/conf/logging.properties?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/tomcat/conf/logging.properties (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/tomcat/conf/logging.properties Thu Jul 21 21:42:07 2011
@@ -0,0 +1,22 @@
+#
+# Copyright (C) 2010 Joerg Bellmann <jo...@googlemail.com>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#
+# OpenEJB logs
+#
+log4j.rootLogger = INFO, stdout
+log4j.appender.stdout = org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout = org.apache.openejb.logging.SimpleJULLikeLayout

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/WEB-INF/web.xml?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/WEB-INF/web.xml (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/WEB-INF/web.xml Thu Jul 21 21:42:07 2011
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+     Licensed to the Apache Software Foundation (ASF) under one or more
+     contributor license agreements.  See the NOTICE file distributed with
+     this work for additional information regarding copyright ownership.
+     The ASF licenses this file to You under the Apache License, Version 2.0
+     (the "License"); you may not use this file except in compliance with
+     the License.  You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+  -->
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+         metadata-complete="false"
+         version="2.5">
+
+  <display-name>OpenEJB REST Example</display-name>
+</web-app>

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/blog.css
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/blog.css?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/blog.css (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/blog.css Thu Jul 21 21:42:07 2011
@@ -0,0 +1,2 @@
+body {font-family: verdana}
+td {padding: 3px;}
\ No newline at end of file

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/blog.html
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/blog.html?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/blog.html (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/blog.html Thu Jul 21 21:42:07 2011
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+	"http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+	<head>
+		<title>OpenEJB REST Blog</title>
+	</head>
+	<body>
+	    <h1>Blog</h1>
+		<script type='text/javascript' 
+                src='../steal/steal.js?blog,development'>    
+        </script>
+	</body>
+</html> 

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/blog.js
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/blog.js?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/blog.js (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/blog.js Thu Jul 21 21:42:07 2011
@@ -0,0 +1,17 @@
+steal.plugins(	
+	'jquery/controller',			// a widget factory
+	'jquery/controller/subscribe',	// subscribe to OpenAjax.hub
+	'jquery/view/ejs',				// client side templates
+	'jquery/controller/view',		// lookup views with the controller's name
+	'jquery/model',					// Ajax wrappers
+	'jquery/dom/form_params')		// form data helper
+	
+	.css('blog')	// loads styles
+
+	.resources()					// 3rd party script's (like jQueryUI), in resources folder
+
+	.models('post')						// loads files in models folder 
+
+	.controllers('post')					// loads files in controllers folder
+
+	.views();						// adds views to be added to build
\ No newline at end of file

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/controllers/post_controller.js
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/controllers/post_controller.js?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/controllers/post_controller.js (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/controllers/post_controller.js Thu Jul 21 21:42:07 2011
@@ -0,0 +1,98 @@
+/**
+ * @tag controllers, home
+ * Displays a table of posts.	 Lets the user 
+ * ["Blog.Controllers.Post.prototype.form submit" create], 
+ * ["Blog.Controllers.Post.prototype.&#46;edit click" edit],
+ * or ["Blog.Controllers.Post.prototype.&#46;destroy click" destroy] posts.
+ */
+$.Controller.extend('Blog.Controllers.Post',
+/* @Static */
+{
+	onDocument: true
+},
+/* @Prototype */
+{
+ /**
+ * When the page loads, gets all posts to be displayed.
+ */
+ "{window} load": function(){
+	if(!$("#post").length){
+	 $(document.body).append($('<div/>').attr('id','post'));
+		 Blog.Models.Post.findAll({}, this.callback('list'));
+ 	}
+ },
+ /**
+ * Displays a list of posts and the submit form.
+ * @param {Array} posts An array of Blog.Models.Post objects.
+ */
+ list: function( posts ){
+	$('#post').html(this.view('init', {posts:posts} ));
+ },
+ /**
+ * Responds to the create form being submitted by creating a new Blog.Models.Post.
+ * @param {jQuery} el A jQuery wrapped element.
+ * @param {Event} ev A jQuery event whose default action is prevented.
+ */
+'form submit': function( el, ev ){
+	ev.preventDefault();
+	new Blog.Models.Post(el.formParams()).save();
+},
+/**
+ * Listens for posts being created.	 When a post is created, displays the new post.
+ * @param {String} called The open ajax event that was called.
+ * @param {Event} post The new post.
+ */
+'post.created subscribe': function( called, post ){
+	$("#post tbody").append( this.view("list", {posts:[post]}) );
+	$("#post form input[type!=submit]").val(""); //clear old vals
+},
+ /**
+ * Creates and places the edit interface.
+ * @param {jQuery} el The post's edit link element.
+ */
+'.edit click': function( el ){
+	var post = el.closest('.post').model();
+	post.elements().html(this.view('edit', post));
+},
+ /**
+ * Removes the edit interface.
+ * @param {jQuery} el The post's cancel link element.
+ */
+'.cancel click': function( el ){
+	this.show(el.closest('.post').model());
+},
+ /**
+ * Updates the post from the edit values.
+ */
+'.update click': function( el ){
+	var $post = el.closest('.post'); 
+	$post.model().update($post.formParams());
+},
+ /**
+ * Listens for updated posts.	 When a post is updated, 
+ * update's its display.
+ */
+'post.updated subscribe': function( called, post ){
+	this.show(post);
+},
+ /**
+ * Shows a post's information.
+ */
+show: function( post ){
+	post.elements().html(this.view('show',post));
+},
+ /**
+ *	 Handle's clicking on a post's destroy link.
+ */
+'.destroy click': function( el ){
+	if(confirm("Are you sure you want to destroy?")){
+		el.closest('.post').model().destroy();
+	}
+ },
+ /**
+ *	 Listens for posts being destroyed and removes them from being displayed.
+ */
+"post.destroyed subscribe": function(called, post){
+	post.elements().remove();	 //removes ALL elements
+ }
+});
\ No newline at end of file

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/index.html
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/index.html?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/index.html (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/index.html Thu Jul 21 21:42:07 2011
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+	"http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+	<head>
+		<title>OpenEJB REST Blog</title>
+	</head>
+	<body>
+	    <h1>Blog</h1>
+		<script type='text/javascript' 
+                src='../steal/steal.js?blog,development'>    
+        </script>
+	</body>
+</html> 

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/models/post.js
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/models/post.js?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/models/post.js (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/models/post.js Thu Jul 21 21:42:07 2011
@@ -0,0 +1,82 @@
+/**
+ * @tag models, home
+ * Wraps backend post services.  Enables 
+ * [Blog.Models.Post.static.findAll retrieving],
+ * [Blog.Models.Post.static.update updating],
+ * [Blog.Models.Post.static.destroy destroying], and
+ * [Blog.Models.Post.static.create creating] posts.
+ */
+$.Model.extend('Blog.Models.Post',
+/* @Static */
+{
+	/**
+ 	 * Retrieves posts data from your backend services.
+ 	 * @param {Object} params params that might refine your results.
+ 	 * @param {Function} success a callback function that returns wrapped post objects.
+ 	 * @param {Function} error a callback function for an error in the ajax request.
+ 	 */
+	findAll: function( params, success, error ){
+	  self = this;
+		$.ajax({
+			url: '/rest-example-1.1-SNAPSHOT/api/post/list',
+			type: 'get',
+			dataType: 'json',
+			data: params,
+			success: function(posts){
+                  var wrapped = self.wrapMany(posts.post);
+                  success(wrapped);
+              },
+			error: error
+		});
+	},
+	/**
+	 * Updates a post's data.
+	 * @param {String} id A unique id representing your post.
+	 * @param {Object} attrs Data to update your post with.
+	 * @param {Function} success a callback function that indicates a successful update.
+ 	 * @param {Function} error a callback that should be called with an object of errors.
+     */
+	update: function( id, attrs, success, error ){
+		$.ajax({
+			url: '/posts/'+id,
+			type: 'put',
+			dataType: 'json',
+			data: attrs,
+			success: success,
+			error: error
+		});
+	},
+	/**
+ 	 * Destroys a post's data.
+ 	 * @param {String} id A unique id representing your post.
+	 * @param {Function} success a callback function that indicates a successful destroy.
+ 	 * @param {Function} error a callback that should be called with an object of errors.
+	 */
+	destroy: function( id, success, error ){
+		$.ajax({
+			url: '/posts/'+id,
+			type: 'delete',
+			dataType: 'json',
+			success: success,
+			error: error
+		});
+	},
+	/**
+	 * Creates a post.
+	 * @param {Object} attrs A post's attributes.
+	 * @param {Function} success a callback function that indicates a successful create.  The data that comes back must have an ID property.
+	 * @param {Function} error a callback that should be called with an object of errors.
+	 */
+	create: function( attrs, success, error ){
+		$.ajax({
+			url: '/posts',
+			type: 'post',
+			dataType: 'json',
+			success: success,
+			error: error,
+			data: attrs
+		});
+	}
+},
+/* @Prototype */
+{});
\ No newline at end of file

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/edit.ejs
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/edit.ejs?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/edit.ejs (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/edit.ejs Thu Jul 21 21:42:07 2011
@@ -0,0 +1,16 @@
+<%for(var attribute in Blog.Models.Post.attributes){%>
+	<%if(attribute == 'id' || attribute == 'comments') continue;%>
+	<td class='<%= attribute %>'>
+    <% if(attribute == 'user') { %>
+      <input type="text" value="<%= this[attribute].fullname %>" name="<%= attribute%>"/>
+    <% } else if(attribute == 'content') { %>
+      <textarea rows="10" cols="100" name="<%= attribute%>"><%= this[attribute] %></textarea>
+    <% } else { %>
+      <input type="text" value="<%= this[attribute]%>" name="<%= attribute %>"/>
+    <% } %>
+  </td>
+<%}%>
+<td>
+	<input type='submit' value='Update' class='update'/>
+	<a href='javascript://' class='cancel'>cancel</a>
+</td>
\ No newline at end of file

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/init.ejs
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/init.ejs?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/init.ejs (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/init.ejs Thu Jul 21 21:42:07 2011
@@ -0,0 +1,26 @@
+<h2>posts</h2>
+<table cellspacing='0px'>
+	<thead>
+	<tr>
+		<% for(var attr in Blog.Models.Post.attributes){%>
+            <% if(attr == 'id' || attr == 'comments') continue; %>
+			<th><%= attr%> </th>	 
+		<%}%>
+		<th>Options</th>
+	</tr>
+	</thead>
+	<tbody>
+		<%= $.View('//blog/views/post/list',{posts: posts})%>
+	</tbody>
+</table>
+<h2>New post</h2>
+<form>
+	<% for(var attr in Blog.Models.Post.attributes){ %>
+		<% if(attr == 'id' || attr == 'comments') continue;%>
+		<div>
+			<label><%= attr %> </label><br />
+			<input type="text" value="" name="<%= attr %>"/>
+		</div>
+	<%}%>
+	<input type='submit' value='Create'/>
+</form>
\ No newline at end of file

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/list.ejs
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/list.ejs?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/list.ejs (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/list.ejs Thu Jul 21 21:42:07 2011
@@ -0,0 +1,5 @@
+<%for(var i = 0; i < posts.length ; i++){%>
+	<tr <%= posts[i]%>>
+		<%= $.View('//blog/views/post/show',posts[i])%>
+	</tr>
+<%}%>
\ No newline at end of file

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/show.ejs
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/show.ejs?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/show.ejs (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/blog/views/post/show.ejs Thu Jul 21 21:42:07 2011
@@ -0,0 +1,14 @@
+<% for(var attribute in this.Class.attributes) { %>
+	<% if(attribute == 'id' || attribute == 'comments') continue; %>
+  <td class='<%= attribute %>'>
+	<% if(attribute == 'user') { %>
+	  <%= this[attribute].fullname %>
+	<% } else { %>
+	  <%= this[attribute] %>
+  <% } %>
+  </td>
+<% } %>
+<td>
+	<a href='javascript://' class='edit'>edit</a>
+	<a href='javascript://' class='destroy'>destroy</a>
+</td>
\ No newline at end of file

Added: openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/index.html
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/index.html?rev=1149378&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/index.html (added)
+++ openejb/trunk/openejb3/examples/webapps/rest-example/src/main/webapp/index.html Thu Jul 21 21:42:07 2011
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+	"http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+	<head>
+		<title>OpenEJB REST Blog</title>
+	</head>
+	<body>
+	    <h1>Blog</h1>
+		<script type='text/javascript' 
+                src='steal/steal.js?blog,development'>    
+        </script>
+	</body>
+</html>