skeleton design of BirdShack Business Logic server
authorIang <iang@cacert.org>
Thu, 9 Sep 2010 01:03:50 +0000 (11:03 +1000)
committerIang <iang@cacert.org>
Thu, 9 Sep 2010 01:03:50 +0000 (11:03 +1000)
15 files changed:
Business Logic/trunk/src/org/cacert/birdshack/bl/handler/AbstractBird.java [new file with mode: 0644]
Business Logic/trunk/src/org/cacert/birdshack/bl/handler/AbstractBirdHandler.java [new file with mode: 0644]
Business Logic/trunk/src/org/cacert/birdshack/bl/handler/BigBirdHandler.java [new file with mode: 0644]
Business Logic/trunk/src/org/cacert/birdshack/bl/handler/Bird.java [new file with mode: 0644]
Business Logic/trunk/src/org/cacert/birdshack/bl/handler/BirdHandler.java [new file with mode: 0644]
Business Logic/trunk/src/org/cacert/birdshack/bl/handler/Go.java [new file with mode: 0644]
Business Logic/trunk/src/org/cacert/birdshack/bl/handler/TestSwallow.java [new file with mode: 0644]
Business Logic/trunk/src/org/cacert/birdshack/bl/model/Flight.java [new file with mode: 0644]
Business Logic/trunk/src/org/cacert/birdshack/bl/model/ModelFactory.java [new file with mode: 0644]
Business Logic/trunk/src/org/cacert/birdshack/bl/model/Rid.java [new file with mode: 0644]
Business Logic/trunk/src/org/cacert/birdshack/bl/servlet/Controller.java [new file with mode: 0644]
Business Logic/trunk/src/org/cacert/birdshack/bl/servlet/HttpBird.java [new file with mode: 0644]
Business Logic/trunk/src/org/cacert/birdshack/bl/servlet/HttpController.java [new file with mode: 0644]
Business Logic/trunk/src/org/cacert/birdshack/bl/store/ResourceStore.java [new file with mode: 0644]
Business Logic/trunk/src/org/cacert/birdshack/bl/store/UnbackedStore.java [new file with mode: 0644]

diff --git a/Business Logic/trunk/src/org/cacert/birdshack/bl/handler/AbstractBird.java b/Business Logic/trunk/src/org/cacert/birdshack/bl/handler/AbstractBird.java
new file mode 100644 (file)
index 0000000..f48d4dd
--- /dev/null
@@ -0,0 +1,142 @@
+/**
+ * 
+ */
+package org.cacert.birdshack.bl.handler;
+
+import java.util.Random;
+import org.cacert.birdshack.bl.model.*;
+
+
+/**
+ * This class carries an entire request and response mechanics.
+ * An instance can move through a chain of logic, and at any
+ * time be completed by calling various methods to drop, terminate,
+ * complete.
+ * It is a request that knows how to reply to itself.
+ * @author iang
+ * 
+ */
+public abstract class AbstractBird
+       implements Bird
+{
+       public static final String DOMAIN = "bs.cacert.org";
+
+       /**
+        *  The type of resource indicated, like Member.
+         *  The resource itself will be in the Payload.
+        */
+       private String resource = null;
+       public String getResource()           { return resource; }
+       public boolean isResource(String s)   { return s.equals(resource); }
+
+       /**
+        *  The request payload, being a resource object, a BirdShackObject.
+        */
+       private BirdShackObject payload = null;
+       public BirdShackObject getRequestPayload()          { return payload; }
+       public void setRequestPayload(BirdShackObject x)    { payload = x; }
+       /**
+        *  The response payload, ditto.
+         *  Not clear (yet) why there are two, one for each direction...
+        */
+       private BirdShackObject payload2 = null;
+       public BirdShackObject getResponsePayload()         { return payload2; }
+       public void setResponsePayload(BirdShackObject x)   { payload2 = x; }
+
+       private String uri = null;
+       public String getUri()        { return uri; }
+       private Rid rid = null;
+       public Rid getId()         { return rid; }
+       public Rid getRid()         { return rid; }
+       private String function = null;
+       public String getFunction()   { return function; }
+       private String args = null;
+       public String getArgs()       { return args; }
+
+       private String method = null;
+       protected void setMethod(String s)     { method = s; }
+       public String getMethod()     { return method; }
+       public boolean isGet()        { return GET.equals(method); }
+       public boolean isCreate()     { return POST.equals(method); }
+       public boolean isUpdate()     { return PUT.equals(method); }
+       public boolean isDelete()     { return DELETE.equals(method); }
+
+       /**
+        *  The response, being an integer status code from HTTP.
+        *  http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
+        */
+       private int response;
+       public int getResponse()       { return response; }
+       public void setResponse(int x) { response = x; }
+       /**
+        *  In the event of a POST of a new resource, this is the identifier.
+        *  XXX: not right yet, how to send back?
+        */
+       private Rid newRid;
+       public Rid getNewRid()       { return newRid; }
+       public void setNewRid(Rid x) { newRid = x; }
+
+        public void okGot(BirdShackObject m)   // to a GET or UPDATE
+        {
+                setResponse(OK);
+                setResponsePayload(m);
+        }
+        public void okCreated(Rid id)         // to a POST of new
+        {
+                setResponse(CREATED);
+                setNewRid(id);
+        }
+        public void okUpdated()                // to a PUT of existing
+        {
+                setResponse(UPDATED);
+        }
+        public void okDeleted()
+        {
+                setResponse(OK);
+        }
+
+        public void error(int htmlStatus)
+        {
+                setResponse(htmlStatus);
+        }
+
+
+
+
+
+       public String toString()
+       {
+               String s = method + " ";
+               if (null != resource) s += "R=" + resource + "; ";
+               if (null != rid) s += "rid=" + rid + "; ";
+               if (null != newRid) s += "newRid=" + newRid + "; ";
+               if (null != function) s += "f=" + function + "; ";
+               if (null != args) s += "a=" + args + "; ";
+               if (0 != response) s += " Response " + response + "; ";
+               return s;
+       }
+
+        protected void setContents(String uri)
+        {
+               this.uri = uri;
+               String splituri[] = uri.split("\\/", 5);
+               if(splituri.length > 1)
+                       resource = splituri[1];
+               if(splituri.length > 2)
+                       rid = new Rid( splituri[2] );
+               if(splituri.length > 3)
+                       function = splituri[3];
+               if(splituri.length > 4)
+                       args = splituri[4];
+        }
+
+
+       /**
+        *  This should be someone else.
+        */
+        static Random _r = new Random();
+       static public int rand(int n)
+       {
+               return _r.nextInt(n);
+       }
+}
diff --git a/Business Logic/trunk/src/org/cacert/birdshack/bl/handler/AbstractBirdHandler.java b/Business Logic/trunk/src/org/cacert/birdshack/bl/handler/AbstractBirdHandler.java
new file mode 100644 (file)
index 0000000..2108adb
--- /dev/null
@@ -0,0 +1,84 @@
+/** * 
+ */
+package org.cacert.birdshack.bl.handler;
+
+import org.cacert.birdshack.bl.model.*;
+
+/**
+ * @author iang
+ * 
+ */
+public abstract class AbstractBirdHandler
+    implements BirdHandler
+{
+        public boolean isTest() { return true; }
+        public void setTest(boolean t) { }
+
+       /**
+        * 
+        */
+       
+       public void handle(Bird b)
+       {
+               if (b.isResource(ModelFactory.MEMBER)) {
+                        handleMember(b);
+                } else if(b.isResource(ModelFactory.PROFILE)) {
+                       handleProfile(b);
+                } else if(b.isResource(ModelFactory.ASSURANCE)) {
+                       handleAssurance(b);
+                } else if(b.isResource(ModelFactory.CREDENTIAL)) {
+                       handleCredential(b);
+                } else if(b.isResource(ModelFactory.NOTIFICATION)) {
+                       handleNotification(b);
+                } else if(b.isResource(ModelFactory.TOKEN)) {
+                       handleToken(b);
+                } else if(b.isResource(ModelFactory.EMAIL)) {
+                       handleEmail(b);
+                } else if(b.isResource(ModelFactory.DOMAIN)) {
+                       handleDomain(b);
+                } else if(b.isResource(ModelFactory.DELEGATION)) {
+                       handleDelegation(b);
+                } else if(b.isResource(ModelFactory.NAME)) {
+                       handleName(b);
+                } else if(b.isResource(ModelFactory.APPLICATION)) {
+                       handleApplication(b);
+                } else if(b.isResource(ModelFactory.EVENT)) {
+                       handleEvent(b);
+                } else if(b.isResource(ModelFactory.ROLE)) {
+                       handleRole(b);
+                } else if(b.isResource(ModelFactory.PERMISSION)) {
+                       handlePermission(b);
+                } else if(b.isResource(ModelFactory.PROFILE)) {
+                       handleAuthenticate(b);
+               }
+
+       }
+
+       /**
+        * This one must be provided:
+           public void handle(Bird b)
+        */
+
+       /**
+        * The rest can be left out for now ... don't call them.
+        */
+
+       protected void handleMember(Bird b)             { bummer(); }
+       protected void handleProfile(Bird b)            { bummer(); }
+       protected void handleAssurance(Bird b)          { bummer(); }
+       protected void handleCredential(Bird b)         { bummer(); }
+       protected void handleNotification(Bird b)       { bummer(); }
+       protected void handleToken(Bird b)              { bummer(); }
+       protected void handleEmail(Bird b)              { bummer(); }
+       protected void handleDomain(Bird b)             { bummer(); }
+       protected void handleDelegation(Bird b)         { bummer(); }
+       protected void handleName(Bird b)               { bummer(); }
+       protected void handleApplication(Bird b)        { bummer(); }
+       protected void handleEvent(Bird b)              { bummer(); }
+       protected void handleRole(Bird b)               { bummer(); }
+       protected void handlePermission(Bird b)         { bummer(); }
+       protected void handleAuthenticate(Bird b)       { bummer(); }
+
+        protected void bummer()
+               { throw new Error("not implemented"); }
+}
diff --git a/Business Logic/trunk/src/org/cacert/birdshack/bl/handler/BigBirdHandler.java b/Business Logic/trunk/src/org/cacert/birdshack/bl/handler/BigBirdHandler.java
new file mode 100644 (file)
index 0000000..53659c3
--- /dev/null
@@ -0,0 +1,218 @@
+/**
+ * 
+ */
+package org.cacert.birdshack.bl.handler;
+
+import org.cacert.birdshack.util.Junk;
+import org.cacert.birdshack.bl.model.*;
+import org.cacert.birdshack.bl.store.*;
+
+
+/**
+ * @author law
+ * 
+ */
+public class BigBirdHandler
+       extends AbstractBirdHandler
+{
+       private static ResourceStore db;
+
+       public BigBirdHandler(ResourceStore db) {
+               this.db = db;
+       }
+
+       private void getMember(Bird b)
+       {
+               if(b.getRid() == null) {
+                       // XXX this is get a list of all identifiers ?
+                       b.error(b.BAD); return ;
+               }
+
+               Rid id = b.getRid();
+               String func = b.getFunction();
+               BirdShackObject f;
+               f = db.getResource(id, ModelFactory.MEMBER);
+               if (null == f) {
+                       b.error(b.NOT_FOUND); return ;
+               }
+
+               if (null == func) {      // just get the main member resource
+                       b.okGot(f); return ;
+               }
+               
+       }
+
+       private void createMember(Bird b)
+       {
+               BirdShackObject f = b.getRequestPayload();
+               Rid newRid = db.saveNewResource(f);
+               b.okCreated(newRid);
+       }
+
+       private void updateMember(Bird b)
+       {
+               BirdShackObject f = b.getRequestPayload();
+               BirdShackObject done = db.updateResource(f);
+               b.okUpdated();
+       }
+
+       private void deleteMember(Bird b)
+       {
+               Rid id = b.getRid();
+               db.deleteResource(id);
+               b.okDeleted();
+       }
+
+       protected void handleMember(Bird b)
+       {
+System.err.print("Handle Member: ");
+
+               Rid id = b.getRid();
+               if (null == id) {
+System.err.print("no ID: ");
+                       if (b.isCreate()) {
+System.err.println(" CREATE Member");
+                               createMember(b);
+                       } else if (b.isGet()) {
+System.err.println(" GET Member");
+                               getMember(b);
+                       } else {
+                               b.errorNotImpl();
+                       }
+                       return ;
+               }
+
+               String func = b.getFunction();
+               if (null == func) {
+System.err.print("no Func: ");
+                       if (b.isDelete()) {
+System.err.println(" DELETE Member");
+                               deleteMember(b);
+                       } else if (b.isGet()) {
+System.err.println(" GET Member");
+                               getMember(b);
+                       } else {
+                               b.errorNotImpl();
+                       }
+                       return ;
+               }
+
+               if(b.isGet()) {
+                       getMember(b);
+               } else if(b.isCreate()) {
+                       createMember(b);
+               } else if(b.isUpdate()) {
+                       updateMember(b);
+               } else if(b.isDelete()) {
+                       deleteMember(b);
+                } else {
+                       b.errorNotImpl();
+               }
+
+               if(b.isGet()) {
+                       getMember(b);
+               } else if(b.isCreate()) {
+                       createMember(b);
+               } else if(b.isUpdate()) {
+                       updateMember(b);
+               } else if(b.isDelete()) {
+                       deleteMember(b);
+                } else {
+                       b.errorNotImpl();
+               }
+
+
+
+/*
+               if(args == null) {
+                       if(function.equals("privacy")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("PUT")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("emailaddress")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("PUT")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("assurance")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("profile")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("experience")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("role")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("credential")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("log")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("notification")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("token")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else {
+                               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                       }
+                       return ;
+               }
+
+*/
+
+
+
+       }
+
+}
diff --git a/Business Logic/trunk/src/org/cacert/birdshack/bl/handler/Bird.java b/Business Logic/trunk/src/org/cacert/birdshack/bl/handler/Bird.java
new file mode 100644 (file)
index 0000000..c4e56c9
--- /dev/null
@@ -0,0 +1,71 @@
+/**
+ *  Copyright CAcert Inc.
+ */
+package org.cacert.birdshack.bl.handler;
+import org.cacert.birdshack.bl.model.*;
+
+
+/**
+ * This interface describes an entire request and response mechanics.
+ * An instance of an implementing class eg, HttpBird
+ * can move through a chain of handlers (BirdHandler), and at any
+ * time be completed by calling various methods to drop, terminate,
+ * complete, error-fail it.
+ * It is a request that knows how to reply to itself,
+ * thus avoiding complicated returns over function calls or exceptions.
+ *
+ * @author iang
+ */
+public interface Bird
+{
+       /**
+        * 
+        */
+       public String getMethod();
+       public boolean isGet();
+       public boolean isCreate();
+       public boolean isDelete();
+       public boolean isUpdate();
+
+       public static final String      // HTTP verbs, only for HTTP delivery
+                       GET    = "GET",
+                       POST   = "POST",
+                       PUT    = "PUT",
+                       DELETE = "DELETE";
+
+       public String getResource();
+       public boolean isResource(String s);
+
+       public BirdShackObject getRequestPayload();
+       public void setRequestPayload(BirdShackObject x);
+       public BirdShackObject getResponsePayload();
+       public void setResponsePayload(BirdShackObject x);
+
+       public Rid    getId();
+       public Rid    getRid();          // get unique Resource id
+       public String getFunction();
+       public String getArgs();
+
+       /*
+        *  The results in REST format.
+        *  These calls will trigger the response to be sent.
+        */
+       public void okGot(BirdShackObject m);
+       public void okCreated(Rid newId);
+       public void okUpdated();
+       public void okDeleted();
+
+       public void error(int httpStatus);
+       public void errorNotImpl();
+       public void errorNotAllowed();
+
+        public static final int OK = 200,
+                        CREATED = 201,
+                        UPDATED = 200,
+                        ACCEPTED = 202;
+        public static final int BAD = 400,
+                        UNAUTHORIZED = 401,
+                        NOT_FOUND = 404,
+                        NOT_IMPLEMENTED = 501;
+
+}
diff --git a/Business Logic/trunk/src/org/cacert/birdshack/bl/handler/BirdHandler.java b/Business Logic/trunk/src/org/cacert/birdshack/bl/handler/BirdHandler.java
new file mode 100644 (file)
index 0000000..86d0d0a
--- /dev/null
@@ -0,0 +1,18 @@
+/**
+ * 
+ */
+package org.cacert.birdshack.bl.handler;
+
+
+/**
+ * This is the Handler that takes a Bird into the Shack.
+ * @author iang
+ */
+public interface BirdHandler
+{
+       /**
+         *  Pass the Bird into the handler.
+         *  No return, no exceptions, always works :)
+        */
+       public void handle(Bird b);
+}
diff --git a/Business Logic/trunk/src/org/cacert/birdshack/bl/handler/Go.java b/Business Logic/trunk/src/org/cacert/birdshack/bl/handler/Go.java
new file mode 100644 (file)
index 0000000..1f81fe0
--- /dev/null
@@ -0,0 +1,69 @@
+/**
+ *
+ */
+package org.cacert.birdshack.bl.handler;
+import org.cacert.birdshack.bl.model.*;
+import org.cacert.birdshack.bl.store.*;
+
+
+
+/**
+ * @author iang
+ *
+ */
+public class Go
+{
+
+    public static void main(String[] argv)
+        throws Exception
+    {
+        int a = 0;
+        boolean test = true;
+        String myName = argv.length > 0 ? argv[0] : "";
+        boolean bad = false;
+
+        while (a < (argv.length - 1))          // now process my args
+        {
+            if (argv[a].equals("-test"))
+                test = true;
+            else
+            {
+                System.err.println("unknown argv[" + a + "]: " + argv[a]);
+                bad = true;
+            }
+
+            a++;
+        }
+
+        String usage = "\n\nUsage: " + myName +
+                                   "[-test] " +
+                                   "\n";
+        if (bad)
+            throw new RuntimeException(usage);
+
+        // _logger.info("  PRNG...");  // hmmm, we need a logging facility
+
+       ResourceStore rs = new UnbackedStore();
+        BigBirdHandler handler = new BigBirdHandler(rs);
+
+        if (test) {
+            handler.setTest(test);
+            testCycle(handler, 100);
+            System.exit(0);
+        }
+
+    }
+
+    protected static void testCycle(BirdHandler handler, int count)
+    {
+        for (int i = 0; i < count; i++)
+        {
+             System.out.println("========================= " + i + "\n");
+             TestSwallow b = (TestSwallow)TestSwallow.example();
+             System.out.println(b.toString() + "\n");
+             System.out.println(" - - - - - - - - - - - -  " + i + "\n");
+             handler.handle(b);
+             System.out.println("Response: " + b.getResponse() + "\n\n");
+        }
+    }
+}
diff --git a/Business Logic/trunk/src/org/cacert/birdshack/bl/handler/TestSwallow.java b/Business Logic/trunk/src/org/cacert/birdshack/bl/handler/TestSwallow.java
new file mode 100644 (file)
index 0000000..97c7470
--- /dev/null
@@ -0,0 +1,123 @@
+/**
+ * 
+ */
+package org.cacert.birdshack.bl.handler;
+import org.cacert.birdshack.util.Junk;
+import org.cacert.birdshack.bl.model.*;
+
+
+/**
+ * This class carries a Test request and response.
+ * It is used to push into a handler to test its capabilities.
+ * @author iang
+ */
+public class TestSwallow
+       extends AbstractBird {
+
+       static String[] methods = {
+                GET, POST, DELETE,
+       };
+
+
+       /**
+        * 
+        */
+       
+       public TestSwallow(String method, String uri)
+       {
+                this.setContents(uri);
+               this.setMethod(method);
+       }
+
+
+       public void okGot(BirdShackObject m)
+       {
+               super.okGot(m);
+               sendBackResponse();
+       }
+       public void okCreated(Rid newRid)
+       {
+               super.okCreated(newRid);
+               sendBackResponse();
+       }
+       public void okUpdated()
+       {
+               super.okUpdated();
+               sendBackResponse();
+       }
+       public void okDeleted()
+       {
+               super.okDeleted();
+               sendBackResponse();
+       }
+       public void errorNotImpl()
+       {
+               error(NOT_IMPLEMENTED);
+       }
+       public void errorNotAllowed()
+       {
+               error(UNAUTHORIZED);
+       }
+
+       public void error(int httpStatus)
+       {
+               super.error(httpStatus);
+               sendBackResponse();
+       }
+
+       private void sendBackResponse()
+       {
+               /*
+                *  This is the act of sending back the response!
+                */
+               System.err.println( "ZOOM " + toString() );
+       }
+
+
+
+
+       public String toString()
+       {
+               String s = "TestSwallow: ";
+               s += " " + super.toString();
+               return s;
+       }
+
+
+
+       public static Bird example()
+       {
+               return example(false);
+       }
+       public static Bird example(boolean validUrl)
+       {
+               String resource = ModelFactory.exampleResource();
+               String method = exampleMethod(resource);
+               String uri = exampleUri(resource, method);
+               // here, add the rest...
+               TestSwallow b = new TestSwallow(method, uri);
+               if (b.isUpdate() || b.isCreate()) {
+                   BirdShackObject f = ModelFactory.exampleObject(resource);
+                   b.setRequestPayload(f);
+               }
+               return b;
+       }
+
+
+
+       public static String exampleUri(String resource, String method)
+       {
+               String uri = DOMAIN + '/' + resource;
+               if (method.equals(GET)) {
+                       uri += '/' + Junk.identifier();
+               } else if (method.equals(DELETE)) {
+                       uri += '/' + Junk.identifier();
+               }
+               return uri;
+       }
+       public static String exampleMethod(String resource)
+       {
+               int i = rand(methods.length);
+               return methods[i];
+       }
+}
diff --git a/Business Logic/trunk/src/org/cacert/birdshack/bl/model/Flight.java b/Business Logic/trunk/src/org/cacert/birdshack/bl/model/Flight.java
new file mode 100644 (file)
index 0000000..83526c0
--- /dev/null
@@ -0,0 +1,62 @@
+/**
+ * 
+ */
+package org.cacert.birdshack.bl.model;
+
+/**
+ * @author iang
+ * A way to externalise (like serialise) a BirdShack model object for
+ * transmission back and forth to the external client.
+ * Suitable for handlers to recover/return info from/to clients
+ * (typically, the body of a POST or a response to a GET).
+ *
+ * Typically, there are two ways to handle this in the Java Design space.
+ * This way,
+ * in which every member provides these single in/out layouts.
+ * (Where, layouts are things like JSON, XML, ...).
+ * This works if there is only one layout and we can all agree...
+ *
+ * Alternatively, there will be a package of proto-members,
+ * whose only job is to capture the data and externalise into the model-members.
+ * This is much more work because there are L*M classes, where
+ * L is the number of formatted layouts, and M is the number of members.
+ * But may be inevitable if there are many layouts...
+ *
+ * FOR NOW:  Agree on one layout, say JSON?
+ */
+public interface Flight
+{
+
+       /**
+        *  Called by a factory method, that knows what the text is.
+        *  Takes an incoming obj (POST body?) in string form and recovers it.
+       public ClassName(String s);
+         *  Might be better to provide a stream type.
+        */
+
+       /**
+        *  Called by a handler that has prepared this object for return
+        *  to caller, as part of a GET response or similar.
+        */
+       public String prepareForFlight();
+
+        /**
+         *  return an example object filled with junk data, for self-testing.
+       public static Flight example();
+        */
+
+
+
+
+       /**
+        *  Number of Model, to assist recovery (optional).
+       public int modelNumber();
+         *  this is derived from WebFunds' Wire methods, so may not be needed here.
+         *  Looks like it will be performed by the Resource Name.
+        */
+       /**
+        *  Name of Model, to assist recovery (optional).
+       public static String modelName();
+         *  Looks like it will be performed by the Resource Name.
+         */
+}
diff --git a/Business Logic/trunk/src/org/cacert/birdshack/bl/model/ModelFactory.java b/Business Logic/trunk/src/org/cacert/birdshack/bl/model/ModelFactory.java
new file mode 100644 (file)
index 0000000..188f387
--- /dev/null
@@ -0,0 +1,94 @@
+/**
+ *
+ */
+package org.cacert.birdshack.bl.model;
+
+import java.util.List;
+
+import org.cacert.birdshack.util.Junk;
+
+
+/**
+ * @author iang
+ * Factory methods for all BirdShackObjects.
+ */
+public class ModelFactory
+{
+       /**
+        *  These are the string names for each resource
+        *  from REST to Store.
+        */
+       public static final String
+                MEMBER        = "member",
+                PROFILE       = "profile",
+                ASSURANCE     = "assurance",
+                CREDENTIAL    = "credential",
+                NOTIFICATION  = "notification",
+                TOKEN         = "token",
+                EMAIL         = "email",
+                DOMAIN        = "domain",
+                DELEGATION    = "delegation",
+                NAME          = "name",
+                APPLICATION   = "application",
+                EVENT         = "event",
+                ROLE          = "role",
+                PERMISSION    = "permission" ;
+
+        public static String[] resources = {
+                MEMBER,
+        };
+
+
+       public boolean isResource(String s) {
+               for (int i = 0; i < resources.length; i++) {
+                       if (resources[i].equals(s)) return true;
+               }
+               return false;
+       }
+
+       public static Class resourceToClass(String s) {
+                if (MEMBER.equals(s))       return Member.class;
+                if (PROFILE.equals(s))      return Profile.class;
+                if (ASSURANCE.equals(s))    return Assurance.class;
+                if (CREDENTIAL.equals(s))   return Credential.class;
+                if (NOTIFICATION.equals(s)) return Notification.class;
+                if (TOKEN.equals(s))        return Token.class;
+                if (EMAIL.equals(s))        return Email.class;
+                if (DOMAIN.equals(s))       return Domain.class;
+                if (DELEGATION.equals(s))   return Delegation.class;
+                if (NAME.equals(s))         return Name.class;
+                if (APPLICATION.equals(s))  return Application.class;
+                if (EVENT.equals(s))        return Event.class;
+                if (ROLE.equals(s))         return Role.class;
+                if (PERMISSION.equals(s))   return Permission.class;
+
+               return null;
+       }
+
+
+
+
+        public static String exampleResource()
+        {
+                int i = Junk.exampleInt(0, resources.length - 1);
+                return resources[i];
+        }
+
+        public static BirdShackObject exampleObject()
+        {
+                String name = exampleResource();
+               return exampleObject(name);
+        }
+
+       /*
+        *  You must ask for a valid & implemented resource name.
+        */
+        public static BirdShackObject exampleObject(String name)
+        {
+               if (MEMBER.equals(name))    return Member.example();
+
+               throw new Error("wkc927");
+        }
+
+
+}
diff --git a/Business Logic/trunk/src/org/cacert/birdshack/bl/model/Rid.java b/Business Logic/trunk/src/org/cacert/birdshack/bl/model/Rid.java
new file mode 100644 (file)
index 0000000..c852d59
--- /dev/null
@@ -0,0 +1,40 @@
+/**
+ * 
+ */
+package org.cacert.birdshack.bl.model;
+
+
+import org.cacert.birdshack.util.Junk;
+import org.cacert.birdshack.util.Equals;
+
+
+/**
+ *  Basically, just a local object name for the ID,
+ *  currently a String but we might want to change that.
+ *
+ *  @author iang
+ */
+public class Rid {
+
+       private String rid;
+
+       public Rid (String s) {
+               this.rid = s;
+       }
+
+
+
+
+       public boolean equals(Rid other) {
+               return Equals.equals(this.rid, other.rid);
+       }
+
+       public static Rid example() {
+               Rid rid = new Rid( Junk.identifier() );
+               return rid;
+        }
+
+        public String toString() {
+                return "Rid: " + rid.toString();
+        }
+}
diff --git a/Business Logic/trunk/src/org/cacert/birdshack/bl/servlet/Controller.java b/Business Logic/trunk/src/org/cacert/birdshack/bl/servlet/Controller.java
new file mode 100644 (file)
index 0000000..4a256be
--- /dev/null
@@ -0,0 +1,706 @@
+/**
+ *  Started from api/Controller.
+ */
+package org.cacert.birdshack.bl.api;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import Bird;
+
+/**
+ * @author law
+ * 
+ */
+public class Controller extends HttpServlet {
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 2942637779582104096L;
+       
+       private void handleRequest2(HttpServletRequest req, HttpServletResponse resp, String uri)
+                       throws IOException
+       {
+               Bird bird = new Bird(req, resp);
+
+               if (bird.isResource("member")) {
+                        handleMember(bird);
+                } else if(bird.isResource("profile")) {
+                       handleProfile(bird);
+                } else if(bird.isResource("assurance")) {
+                       handleAssurance(bird);
+                } else if(bird.isResource("credential")) {
+                       handleCredential(bird);
+                } else if(bird.isResource("notification")) {
+                       handleNotification(bird);
+                } else if(bird.isResource("token")) {
+                       handleToken(bird);
+                } else if(bird.isResource("email")) {
+                       handleEmail(bird);
+                } else if(bird.isResource("domain")) {
+                       handleDomain(bird);
+                } else if(bird.isResource("delegation")) {
+                       handleDelegation(bird);
+                } else if(bird.isResource("name")) {
+                       handleName(bird);
+                } else if(bird.isResource("application")) {
+                       handleApplication(bird);
+                } else if(bird.isResource("event")) {
+                       handleEvent(bird);
+                } else if(bird.isResource("role")) {
+                       handleRole(bird);
+                } else if(bird.isResource("permission")) {
+                       handlePermission(bird);
+                } else if(bird.isResource("authenticate")) {
+                       handleAuthenticate(bird);
+               }
+
+       }
+
+       private void handleMember(Bird b)
+       {
+               if(b.getId() == null) {
+                       if(b.isGet()) {
+                               b.errorNotImpl();
+                       } else if(b.isPost()) {
+                               b.errorNotImpl();
+                       } else {
+                               b.errorNotAllowed();
+                       }
+                       return ;
+               }
+
+               if(function == null) {
+                       if(b.isGet()) {
+                               b.errorNotImpl();
+                       } else if(b.isDelete()) {
+                               b.errorNotImpl();
+                       } else {
+                               b.errorNotAllowed();
+                       }
+                       return ;
+               }
+
+////////////// following not converted as yet ///////////////////
+               if(args == null) {
+                       if(function.equals("privacy")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("PUT")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("emailaddress")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("PUT")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("assurance")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("profile")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("experience")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("role")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("credential")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("log")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("notification")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("token")) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else {
+                               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                       }
+                       return ;
+               }
+
+               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+       }
+
+       private void handleRequest2(HttpServletRequest req, HttpServletResponse resp, String uri)
+                       throws IOException {
+               String resource = null;
+               String id = null;
+               String function = null;
+               String args = null;
+               
+               resp.getOutputStream().println(req.getMethod()+" "+req.getRequestURI()+"?"+req.getQueryString()+"\n\n");
+
+               String splituri[] = req.getRequestURI().split("\\/", 5);
+               if(splituri.length > 1)
+                       resource = splituri[1];
+               if(splituri.length > 2)
+                       id = splituri[2];
+               if(splituri.length > 3)
+                       function = splituri[3];
+               if(splituri.length > 4)
+                       args = splituri[4];
+               
+               resp.getOutputStream().println(resource);
+               resp.getOutputStream().println(id);
+               resp.getOutputStream().println(function);
+               resp.getOutputStream().println(args);
+
+               if(resource.equals("member")) {
+                       if(id == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else {
+                               if(function == null) {
+                                       if(req.getMethod().equals("GET")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else if(req.getMethod().equals("DELETE")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else {
+                                               resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                       }
+                               } else if(args == null) {
+                                       if(function.equals("privacy")) {
+                                               if(req.getMethod().equals("GET")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else if(req.getMethod().equals("PUT")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else {
+                                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                               }
+                                       } else if(function.equals("emailaddress")) {
+                                               if(req.getMethod().equals("GET")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else if(req.getMethod().equals("PUT")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else {
+                                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                               }
+                                       } else if(function.equals("assurance")) {
+                                               if(req.getMethod().equals("GET")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else if(req.getMethod().equals("POST")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else {
+                                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                               }
+                                       } else if(function.equals("profile")) {
+                                               if(req.getMethod().equals("GET")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else if(req.getMethod().equals("POST")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else {
+                                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                               }
+                                       } else if(function.equals("experience")) {
+                                               if(req.getMethod().equals("GET")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else if(req.getMethod().equals("POST")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else {
+                                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                               }
+                                       } else if(function.equals("role")) {
+                                               if(req.getMethod().equals("GET")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else if(req.getMethod().equals("POST")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else {
+                                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                               }
+                                       } else if(function.equals("credential")) {
+                                               if(req.getMethod().equals("GET")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else if(req.getMethod().equals("POST")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else {
+                                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                               }
+                                       } else if(function.equals("log")) {
+                                               if(req.getMethod().equals("GET")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else {
+                                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                               }
+                                       } else if(function.equals("notification")) {
+                                               if(req.getMethod().equals("GET")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else if(req.getMethod().equals("POST")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else {
+                                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                               }
+                                       } else if(function.equals("token")) {
+                                               if(req.getMethod().equals("GET")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else if(req.getMethod().equals("POST")) {
+                                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                               } else {
+                                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                               }
+                                       } else {
+                                               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                                       }
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                               }
+                       }
+               } else if(resource.equals("profile")) {
+                       if(id == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(args == null) {
+                               if(function == null) {
+                                       if(req.getMethod().equals("GET")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else if(req.getMethod().equals("DELETE")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else {
+                                               resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                       }
+                               } else if(function.equals("permisssion")) {
+                                       if(req.getMethod().equals("GET")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else if(req.getMethod().equals("POST")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else {
+                                               resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                       }
+                               } else if(function.equals("email")) {
+                                       if(req.getMethod().equals("GET")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else if(req.getMethod().equals("POST")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else {
+                                               resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                       }
+                               } else if(function.equals("credential")) {
+                                       if(req.getMethod().equals("GET")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else if(req.getMethod().equals("POST")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else {
+                                               resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                       }
+                               } else if(function.equals("delegation")) {
+                                       if(req.getMethod().equals("GET")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else if(req.getMethod().equals("POST")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else {
+                                               resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                       }
+                               } else if(function.equals("dob")) {
+                                       if(req.getMethod().equals("GET")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else if(req.getMethod().equals("PUT")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else {
+                                               resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                       }
+                               } else if(function.equals("name")) {
+                                       if(req.getMethod().equals("GET")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else if(req.getMethod().equals("POST")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else {
+                                               resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                       }
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                               }
+                       } else {
+                               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                       }
+               } else if(resource.equals("assurance")) {
+                       if(id == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("DELETE")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else {
+                               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                       }
+               } else if(resource.equals("credential")) {
+                       if(id == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("PUT")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("DELETE")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else {
+                               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                       }
+               } else if(resource.equals("notification")) {
+                       if(id == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function == null) {
+                               if(req.getMethod().equals("PUT")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else {
+                               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                       }
+               } else if(resource.equals("token")) {
+                       if(id == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function == null) {
+                               if(req.getMethod().equals("DELETE")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else {
+                               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                       }
+               } else if(resource.equals("email")) {
+                       if(id == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("PUT")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("DELETE")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else {
+                               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                       }
+               } else if(resource.equals("domain")) {
+                       if(id == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("PUT")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("DELETE")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else {
+                               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                       }
+               } else if(resource.equals("delegation")) {
+                       if(id == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("PUT")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("DELETE")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else {
+                               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                       }
+               } else if(resource.equals("name")) {
+                       if(id == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("PUT")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("DELETE")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else {
+                               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                       }
+               } else if(resource.equals("application")) {
+                       if(id == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("PUT")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("DELETE")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function.equals("member")) {
+                               if(args == null) {
+                                       if(req.getMethod().equals("GET")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else if(req.getMethod().equals("POST")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else {
+                                               resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                       }
+                               } else {
+                                       if(req.getMethod().equals("PUT")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else if(req.getMethod().equals("DELETE")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else {
+                                               resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                       }
+                               }
+                       } else {
+                               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                       }
+               } else if(resource.equals("event")) {
+                       if(id == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else {
+                               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                       }
+               } else if(resource.equals("role")) {
+                       if(id == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function != null && args == null) {
+                               if(function.equals("member")) {
+                                       if(req.getMethod().equals("GET")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else {
+                                               resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                       }
+                               } else if(function.equals("permission")) {
+                                       if(req.getMethod().equals("GET")) {
+                                               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                                       } else {
+                                               resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                                       }
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                               }
+                       } else {
+                               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                       }
+               } else if(resource.equals("permission")) {
+                       if(id == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else if(function == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("PUT")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("DELETE")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else {
+                               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                       }
+               } else if(resource.equals("authenticate")) {
+                       if(id == null) {
+                               if(req.getMethod().equals("GET")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else if(req.getMethod().equals("POST")) {
+                                       resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+                               } else {
+                                       resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The requested action is not available on the requested resource");
+                               }
+                       } else {
+                               resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "The requested is invalid");
+                       }
+               } else {
+                       resp.sendError(HttpServletResponse.SC_NOT_FOUND, "The requested resource does not exists");
+               }
+       }
+       
+       private void handleRequest(HttpServletRequest req, HttpServletResponse resp)
+                       throws IOException {
+               handleRequest(req, resp, req.getRequestURI());
+       }
+       
+       /* (non-Javadoc)
+        * @see javax.servlet.http.HttpServlet#doDelete(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+        */
+       @Override
+       protected void doDelete(HttpServletRequest req, HttpServletResponse resp)
+                       throws ServletException, IOException {
+               handleRequest(req, resp);
+       }
+
+       /* (non-Javadoc)
+        * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+        */
+       @Override
+       protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                       throws ServletException, IOException {
+               handleRequest(req, resp);
+       }
+
+       /* (non-Javadoc)
+        * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+        */
+       @Override
+       protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+                       throws ServletException, IOException {
+               handleRequest(req, resp);
+       }
+
+       /* (non-Javadoc)
+        * @see javax.servlet.http.HttpServlet#doPut(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+        */
+       @Override
+       protected void doPut(HttpServletRequest req, HttpServletResponse resp)
+                       throws ServletException, IOException {
+               handleRequest(req, resp);
+       }
+
+
+}
diff --git a/Business Logic/trunk/src/org/cacert/birdshack/bl/servlet/HttpBird.java b/Business Logic/trunk/src/org/cacert/birdshack/bl/servlet/HttpBird.java
new file mode 100644 (file)
index 0000000..6d26842
--- /dev/null
@@ -0,0 +1,57 @@
+/**
+ * 
+ */
+package org.cacert.birdshack.bl.api;
+
+// import java.io.IOException;
+
+// import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.cacert.birdshack.bl.api.AbstractBird;
+
+/**
+ * This class carries the Servlet request and response
+ * through the handler.
+ * Its job is to convert the Servlet into the internal Bird mechanics.
+ * @author iang
+ * 
+ */
+public class HttpBird
+       extends AbstractBird {
+       /**
+        * 
+        */
+       private HttpServletRequest req = null;
+       public String getRequest()    { return req; }
+       private HttpServletResponse resp = null;
+       public String getResponse()    { return resp; }
+       
+       public void HttpBird(HttpServletRequest req, HttpServletResponse resp)
+                       // throws IOException
+       {
+               setContents(req.getRequestURI());
+               this.req = req;
+               this.resp = resp;
+               this.setMethod(req.getMethod());
+       }
+
+       public void okresponse(Externalisable m)
+       {
+               String bla = m.externalise();
+               resp.sendOK(HttpServletResponse.SC_DONE, bla);
+       }
+       public void okdone()
+       {
+               resp.sendOK(HttpServletResponse.SC_DONE, "");
+       }
+       public void errorNotImpl()
+       {
+               resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "This function is not implemented yet");
+       }
+       public void errorNotAllowed()
+       {
+               resp.sendError(HttpServletResponse.SC_NOT_ALLOWED, "The requested action is not available on the requested resource");
+       }
+}
diff --git a/Business Logic/trunk/src/org/cacert/birdshack/bl/servlet/HttpController.java b/Business Logic/trunk/src/org/cacert/birdshack/bl/servlet/HttpController.java
new file mode 100644 (file)
index 0000000..cc70c69
--- /dev/null
@@ -0,0 +1,74 @@
+/**
+ * 
+ */
+package org.cacert.birdshack.bl.api;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.cacert.birdshack.bl.api.Bird;
+
+/**
+ * @author law
+ * 
+ */
+public class HttpController extends HttpServlet {
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 2942637779582104096L;
+
+       private static Handler h = new BigBirdHandler();
+       
+       
+       private void handleRequest(HttpServletRequest req, HttpServletResponse resp)
+               throws IOException
+        {
+               HttpBird bird = new HttpBird(req, resp);
+               h.handle(bird);
+       }
+       
+
+
+       /* (non-Javadoc)
+        * @see javax.servlet.http.HttpServlet#doDelete(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+        */
+       @Override
+       protected void doDelete(HttpServletRequest req, HttpServletResponse resp)
+                       throws ServletException, IOException {
+               handleRequest(req, resp);
+       }
+
+       /* (non-Javadoc)
+        * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+        */
+       @Override
+       protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                       throws ServletException, IOException {
+               handleRequest(req, resp);
+       }
+
+       /* (non-Javadoc)
+        * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+        */
+       @Override
+       protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+                       throws ServletException, IOException {
+               handleRequest(req, resp);
+       }
+
+       /* (non-Javadoc)
+        * @see javax.servlet.http.HttpServlet#doPut(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+        */
+       @Override
+       protected void doPut(HttpServletRequest req, HttpServletResponse resp)
+                       throws ServletException, IOException {
+               handleRequest(req, resp);
+       }
+
+
+}
diff --git a/Business Logic/trunk/src/org/cacert/birdshack/bl/store/ResourceStore.java b/Business Logic/trunk/src/org/cacert/birdshack/bl/store/ResourceStore.java
new file mode 100644 (file)
index 0000000..2b6797f
--- /dev/null
@@ -0,0 +1,39 @@
+/**
+ *  Resource Store is an interface to store all resources.
+ */
+package org.cacert.birdshack.bl.store;
+
+import org.cacert.birdshack.bl.model.*;   // all the resource classes
+
+
+/**
+ *  ResourceStore approximates the semantics of the REST set for BirdShack
+ *  and the possibilities for databases.
+ *
+ *  @author iang
+ *
+ */
+public interface ResourceStore 
+{
+        public BirdShackObject getResource(Rid rid);
+        public BirdShackObject getResource(Rid rid, String type);
+
+       /**
+        *  @returns the new Identifier for the saved object.
+        *  Note this is not idempotent:  calling twice will result in two saves,
+        *  two objects and two identifiers.
+        */
+       public Rid saveNewResource(BirdShackObject o);
+
+       /**
+        *  @returns the freshly saved object (may include some admin changes)
+        *  Idempotent.
+        */
+       public BirdShackObject updateResource(BirdShackObject o);
+
+       /**
+        *  Deletes the object.
+        *  Idempotent (repeated requests always return as done).
+        */
+       public void deleteResource(Rid rid);
+}
diff --git a/Business Logic/trunk/src/org/cacert/birdshack/bl/store/UnbackedStore.java b/Business Logic/trunk/src/org/cacert/birdshack/bl/store/UnbackedStore.java
new file mode 100644 (file)
index 0000000..1aae5e5
--- /dev/null
@@ -0,0 +1,101 @@
+/**
+ *  Test Store is store to work with dynamic internal storage.
+ */
+package org.cacert.birdshack.bl.store;
+
+import java.util.*;
+
+import org.cacert.birdshack.bl.model.*;   // all the resource classes
+
+
+/**
+ *  UnbackedStore provides storage by means of internal lists, etc.
+ *  All data disappears when the program stops;  no backing store.
+ *  Useful for testing and development, not for real ops.
+ *
+ *  @author iang
+ *
+ */
+public class UnbackedStore 
+       implements ResourceStore
+{
+       private static Map<Rid, BirdShackObject> objects;
+       private static int nextRid;
+
+       public UnbackedStore() {
+               objects = new HashMap<Rid, BirdShackObject>();
+       }
+
+        private static Map<Rid, BirdShackObject> getMap() {
+               return objects;
+        }
+
+        private static Rid getNextIndex() {
+               return new Rid( ++nextRid + "" );
+        }
+
+        public BirdShackObject getResource(Rid id) {
+               Map<Rid, BirdShackObject> x = getMap();
+               return x.get(id);
+        }
+
+       /**
+        *  If you know what the object's class is, specify it.
+        *  This method obviates any checking on caller's part.
+        */
+        public BirdShackObject getResource(Rid id, String type) {
+               Map<Rid, BirdShackObject> x = getMap();
+               BirdShackObject obj = x.get(id);
+               if (null == obj)
+                       return null;
+
+               Class cuss = ModelFactory.resourceToClass(type);
+               if (!obj.getClass().equals(cuss))
+                       throw new Error("wha729 " + id + " => " + type);
+
+               return obj;
+        }
+
+       /**
+        *  @returns the new Identifier for the saved object.
+        *  Note this is not idempotent:  calling twice will result in two saves,
+        *  two objects and two identifiers.
+        */
+       public Rid saveNewResource(BirdShackObject o) {
+               Rid newRid = getNextIndex();
+               Map m = getMap();
+               m.put(newRid, o);
+               bug("new resource " + newRid);
+               return newRid;
+        }
+
+       /**
+        *  @returns the freshly saved object (may include some admin changes)
+        *  Idempotent.
+        */
+       public BirdShackObject updateResource(BirdShackObject o) {
+               Rid id = o.getRid();
+               Map m = getMap();
+               m.put(id, o);
+               return o;
+        }
+
+       /**
+        *  @returns the freshly saved object (may include some admin changes)
+        *  Idempotent.
+        */
+       public void deleteResource(Rid id) {
+               Map m = getMap();
+               m.remove(id);
+               return ;
+        }
+
+
+
+       public String toString() {
+               return "UnS:  " + objects.size() + " objects";
+       }
+       private void bug(String s) {
+               System.err.println(s);
+       }
+}