You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2011/06/26 13:51:10 UTC

svn commit: r1139763 [3/10] - in /incubator/isis/trunk/viewer: json/ json/applib2/ json/applib2/src/ json/applib2/src/main/ json/applib2/src/main/java/ json/applib2/src/main/java/META-INF/ json/applib2/src/main/java/org/ json/applib2/src/main/java/org/...

Added: incubator/isis/trunk/viewer/json/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/src/site/apt/index.apt?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/src/site/apt/index.apt (added)
+++ incubator/isis/trunk/viewer/json/src/site/apt/index.apt Sun Jun 26 11:51:01 2011
@@ -0,0 +1,53 @@
+~~  Licensed to the Apache Software Foundation (ASF) under one
+~~  or more contributor license agreements.  See the NOTICE file
+~~  distributed with this work for additional information
+~~  regarding copyright ownership.  The ASF licenses this file
+~~  to you under the Apache License, Version 2.0 (the
+~~  "License"); you may not use this file except in compliance
+~~  with the License.  You may obtain a copy of the License at
+~~
+~~        http://www.apache.org/licenses/LICENSE-2.0
+~~
+~~  Unless required by applicable law or agreed to in writing,
+~~  software distributed under the License is distributed on an
+~~  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+~~  KIND, either express or implied.  See the License for the
+~~  specific language governing permissions and limitations
+~~  under the License.
+
+
+Restful Viewer
+
+ The <restful> viewer provides a RESTful interface to the domain object model,
+ running over the HTTP protocol, and implemented as a webapp (servlet).
+ 
+ Each domain object (or part of object) is exposed as a RESTful resource, as
+ defined by the following table:
+ 
+*-----------------+------------------+------------------+------------------+------------------+
+|Method \ Resource|Object            |Property          |Collection        |Action            |
+*-----------------+------------------+------------------+------------------+------------------+
+|GET              |List all property |n/a               |List all objects  |n/a               |
+|                 |values for object |                  |in collection     |                  |
+*-----------------+------------------+------------------+------------------+------------------+
+|PUT              |Add new object    |Set value         |Add object into   |n/a               |
+|                 |                  |                  |collection        |                  |
+*-----------------+------------------+------------------+------------------+------------------+
+|DELETE           |Delete            |Clear value       |Remove object     |n/a               |
+|                 |existing object   |                  |collection        |                  |
+*-----------------+------------------+------------------+------------------+------------------+
+|POST             |                  |                  |                  |Invoke            |
+*-----------------+------------------+------------------+------------------+------------------+
+ 
+
+Representation
+
+  The viewer currently represents all domain object as XHTML, meaning that it can be rendered by
+  browers.  This XHTML also serves up a small amount of JavaScript which enables the HTTP PUT
+  and HTTP DELETE methods.  This allows the developer to interact with the system through
+  the browser.   
+    
+Further Info
+  
+  See this module's {{{./apidocs/index.html}Javadoc}} and the {{{./docbkx/html/guide/isis-restful-viewer.html}user guide}} for more information.
+ 

Added: incubator/isis/trunk/viewer/json/src/site/apt/jottings.apt
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/src/site/apt/jottings.apt?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/src/site/apt/jottings.apt (added)
+++ incubator/isis/trunk/viewer/json/src/site/apt/jottings.apt Sun Jun 26 11:51:01 2011
@@ -0,0 +1,24 @@
+~~  Licensed to the Apache Software Foundation (ASF) under one
+~~  or more contributor license agreements.  See the NOTICE file
+~~  distributed with this work for additional information
+~~  regarding copyright ownership.  The ASF licenses this file
+~~  to you under the Apache License, Version 2.0 (the
+~~  "License"); you may not use this file except in compliance
+~~  with the License.  You may obtain a copy of the License at
+~~
+~~        http://www.apache.org/licenses/LICENSE-2.0
+~~
+~~  Unless required by applicable law or agreed to in writing,
+~~  software distributed under the License is distributed on an
+~~  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+~~  KIND, either express or implied.  See the License for the
+~~  specific language governing permissions and limitations
+~~  under the License.
+
+
+
+Jottings
+ 
+  This page is to capture any random jottings relating to this module prior 
+  to being moved into formal documentation. 
+ 

Added: incubator/isis/trunk/viewer/json/src/site/site.xml
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/src/site/site.xml?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/src/site/site.xml (added)
+++ incubator/isis/trunk/viewer/json/src/site/site.xml Sun Jun 26 11:51:01 2011
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+  
+         http://www.apache.org/licenses/LICENSE-2.0
+         
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<project name="${project.name}">
+    <version position="right"/>
+
+	<body>
+		<breadcrumbs>
+			<item name="JSON" href="index.html"/>
+		</breadcrumbs>
+
+		<menu name="JSON Viewer">
+			<item name="About" href="index.html" />
+            <item name="Jottings" href="jottings.html" />
+		</menu>
+		
+        <menu name="Viewer Modules">
+            <item name="DnD" href="../dnd/index.html" />
+            <item name="HTML" href="../html/index.html" />
+            <item name="Scimpi" href="../scimpi/index.html" />
+            <item name="Wicket" href="../wicket/index.html" />
+            <item name="XHTML" href="../xhtml/index.html" />
+            <item name="JSON" href="../json/index.html" />
+            <item name="JUnit Support" href="../junit/index.html" />
+            <item name="BDD Integration" href="../bdd/index.html" />
+        </menu>
+
+        <menu name="JSON Modules">
+            <item name="Applib" href="./applib/index.html" />
+            <item name="Viewer" href="./viewer/index.html" />
+        </menu>
+
+		<menu name="Documentation">
+			<item name="${docbkxGuideTitle} (PDF)" href="docbkx/pdf/${docbkxGuideName}.pdf" />
+			<item name="${docbkxGuideTitle} (HTML)" href="docbkx/html/guide/${docbkxGuideName}.html" />
+		</menu>
+
+		<menu name="Maven Reports" ref="reports" />
+	</body>
+
+</project>

Added: incubator/isis/trunk/viewer/json/viewer2/NOTICE
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/NOTICE?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/NOTICE (added)
+++ incubator/isis/trunk/viewer/json/viewer2/NOTICE Sun Jun 26 11:51:01 2011
@@ -0,0 +1,7 @@
+Apache Isis
+Copyright 2010-2011 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+

Added: incubator/isis/trunk/viewer/json/viewer2/pom.xml
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/pom.xml?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/pom.xml (added)
+++ incubator/isis/trunk/viewer/json/viewer2/pom.xml Sun Jun 26 11:51:01 2011
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+  
+         http://www.apache.org/licenses/LICENSE-2.0
+         
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<groupId>org.apache.isis.viewer</groupId>
+		<artifactId>restful</artifactId>
+		<version>0.1.2-incubating-SNAPSHOT</version>
+	</parent>
+
+	<artifactId>restful-viewer2</artifactId>
+	<name>Restful Viewer2 Implementation</name>
+
+	<properties>
+		<siteBaseDir>../../..</siteBaseDir>
+		<relativeUrl>viewer/restful/viewer/</relativeUrl>
+	</properties>
+
+    <!-- used in Site generation for relative references. -->
+    <url>http://incubator.apache.org/isis/${relativeUrl}</url>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.isis.viewer</groupId>
+			<artifactId>restful-applib2</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.isis</groupId>
+			<artifactId>applib</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.isis.core</groupId>
+			<artifactId>webapp</artifactId>
+		</dependency>
+
+        <dependency>
+            <groupId>org.apache.isis.runtimes.dflt</groupId>
+            <artifactId>webapp</artifactId>
+        </dependency>
+
+        <!-- the javax:* equivalents of these are excluded in 
+             dependencyManagement of resteasy-jaxrs, so  
+             are required here -->           
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-servlet_2.5_spec</artifactId>
+            <version>1.2</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-annotation_1.0_spec</artifactId>
+            <version>1.1.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-activation_1.1_spec</artifactId>
+            <version>1.1</version>
+        </dependency>
+
+	</dependencies>
+</project>

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/AbstractJaxRsApplication.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/AbstractJaxRsApplication.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/AbstractJaxRsApplication.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/AbstractJaxRsApplication.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,53 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2;
+
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+public abstract class AbstractJaxRsApplication extends Application {
+
+    private final Set<Object> singletons = new LinkedHashSet<Object>();
+    private final Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
+
+    public AbstractJaxRsApplication() {
+    }
+
+    @Override
+    public Set<Class<?>> getClasses() {
+        return Collections.unmodifiableSet(classes);
+    }
+
+    @Override
+    public Set<Object> getSingletons() {
+        return Collections.unmodifiableSet(singletons);
+    }
+
+    protected boolean addClass(final Class<?> cls) {
+        return classes.add(cls);
+    }
+
+    protected boolean addSingleton(final Object resource) {
+        return singletons.add(resource);
+    }
+
+}
\ No newline at end of file

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/Constants.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/Constants.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/Constants.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/Constants.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,37 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2;
+
+import org.apache.isis.runtimes.dflt.runtime.system.SystemConstants;
+
+public final class Constants {
+
+    public static final String VIEWER_PREFIX_KEY = SystemConstants.VIEWER_KEY + ".restful";
+    public static final String JAVASCRIPT_DEBUG_KEY = VIEWER_PREFIX_KEY + ".javascript-debug";
+
+    public static final String ISIS_REST_SUPPORT_JS = "isis-rest-support.js";
+    public static final String JQUERY_SRC_JS = "jquery-1.6.1.js";
+    public static final String JQUERY_MIN_JS = "jquery-1.6.1.min.js";
+    public static final String URL_ENCODING_CHAR_SET =
+        org.apache.isis.viewer.restful.applib2.Constants.URL_ENCODING_CHAR_SET;
+
+    private Constants() {
+    }
+
+}

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RepContext.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RepContext.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RepContext.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RepContext.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,82 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2;
+
+import java.util.Arrays;
+
+import org.apache.isis.viewer.restful.viewer2.representations.Representation;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+/**
+ * The context within which this representation is being requested.
+ * 
+ * <p>
+ * Part of the context is the overall {@link ResourceContext}, which incorporates
+ * such things as the current user, and HTTP headers.
+ * 
+ * <p>
+ * The other part of the context is an indication of the attribute that this
+ * representation will be keyed under.  This is required in order that
+ * 'rel' links for attributes correctly concatenate.  It is also used to
+ * infer whether member representations (which appear in summary form in
+ * the {@link Representation} and in more detail in their own resources)
+ * should include a _self attribute or not.
+ */
+public class RepContext {
+
+    private final ResourceContext resourceContext;
+    private final String attribute;
+
+    public RepContext(ResourceContext resourceContext, String attribute) {
+        this.resourceContext = resourceContext;
+        this.attribute = attribute;
+    }
+
+    public String urlFor(String url) {
+        return resourceContext.getUriInfo().getBaseUri().toString() + url;
+    }
+
+    public String relFor(String relSuffix) {
+        return Joiner.on(".").join( 
+            Iterables.filter(Arrays.asList(attribute, relSuffix), nonNulls())); 
+    }
+
+    private static <T> Predicate<T> nonNulls() {
+        return new Predicate<T>() {
+            @Override
+            public boolean apply(T input) {
+                return input != null;
+            }
+        };
+    }
+
+    public boolean hasAttribute() {
+        return attribute != null;
+    }
+
+    /**
+     * Returns a new {@link RepContext} with a different attribute.
+     */
+    public RepContext underAttribute(String attribute) {
+        return resourceContext.repContext(attribute);
+    }
+}

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/ResourceContext.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/ResourceContext.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/ResourceContext.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/ResourceContext.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,79 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.UriInfo;
+
+public class ResourceContext {
+
+    public RepContext repContext() {
+        return repContext(null);
+    }
+    public RepContext repContext(String attribute) {
+        return new RepContext(this, attribute);
+    }
+
+
+    private final HttpHeaders httpHeaders;
+    private final UriInfo uriInfo;
+    private final Request request;
+    private final HttpServletRequest httpServletRequest;
+    private final HttpServletResponse httpServletResponse;
+    private final SecurityContext securityContext;
+
+    public ResourceContext(final HttpHeaders httpHeaders, final UriInfo uriInfo, final Request request,
+        final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse,
+        final SecurityContext securityContext) {
+        this.httpHeaders = httpHeaders;
+        this.uriInfo = uriInfo;
+        this.request = request;
+        this.httpServletRequest = httpServletRequest;
+        this.httpServletResponse = httpServletResponse;
+        this.securityContext = securityContext;
+    }
+
+    public HttpHeaders getHttpHeaders() {
+        return httpHeaders;
+    }
+
+    public UriInfo getUriInfo() {
+        return uriInfo;
+    }
+
+    public Request getRequest() {
+        return request;
+    }
+
+    public HttpServletRequest getHttpServletRequest() {
+        return httpServletRequest;
+    }
+
+    public HttpServletResponse getServletResponse() {
+        return httpServletResponse;
+    }
+
+    public SecurityContext getSecurityContext() {
+        return securityContext;
+    }
+}

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RestfulApplication.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RestfulApplication.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RestfulApplication.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RestfulApplication.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,35 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2;
+
+import org.apache.isis.viewer.restful.viewer2.resources.bootstrap.BootstrapResourceImpl;
+import org.apache.isis.viewer.restful.viewer2.resources.home.HomePageResourceImpl;
+import org.apache.isis.viewer.restful.viewer2.resources.objects.DomainObjectResourceImpl;
+import org.apache.isis.viewer.restful.viewer2.resources.services.ServicesResourceImpl;
+
+public class RestfulApplication extends AbstractJaxRsApplication {
+
+    public RestfulApplication() {
+        addSingleton(new BootstrapResourceImpl());
+        addSingleton(new HomePageResourceImpl());
+        addSingleton(new ServicesResourceImpl());
+        addSingleton(new DomainObjectResourceImpl());
+    }
+
+}

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyParams.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyParams.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyParams.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyParams.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,51 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2.authentication;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.runtime.authentication.AuthenticationRequestPassword;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.webapp.auth.AuthenticationSessionLookupStrategyDefault;
+
+import com.google.common.base.Strings;
+
+public class AuthenticationSessionLookupStrategyParams extends AuthenticationSessionLookupStrategyDefault {
+
+    @Override
+    public AuthenticationSession lookup(final ServletRequest servletRequest, final ServletResponse servletResponse) {
+        final AuthenticationSession session = super.lookup(servletRequest, servletResponse);
+        if (session != null) {
+            return session;
+        }
+
+        final HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
+        final String user = httpServletRequest.getParameter("user");
+        final String password = httpServletRequest.getParameter("password");
+
+        if (Strings.isNullOrEmpty(user) || Strings.isNullOrEmpty(password)) {
+            return null;
+        }
+        final AuthenticationRequestPassword request = new AuthenticationRequestPassword(user, password);
+        return IsisContext.getAuthenticationManager().authenticate(request);
+    }
+}

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyTrusted.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyTrusted.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyTrusted.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyTrusted.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,42 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2.authentication;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.runtimes.dflt.runtime.authentication.exploration.AuthenticationRequestExploration;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.webapp.auth.AuthenticationSessionLookupStrategyDefault;
+
+public class AuthenticationSessionLookupStrategyTrusted extends AuthenticationSessionLookupStrategyDefault {
+
+    @Override
+    public AuthenticationSession lookup(final ServletRequest servletRequest, final ServletResponse servletResponse) {
+        final AuthenticationSession session = super.lookup(servletRequest, servletResponse);
+        if (session != null) {
+            return session;
+        }
+
+        // will always succeed.
+        final AuthenticationRequestExploration request = new AuthenticationRequestExploration();
+        return IsisContext.getAuthenticationManager().authenticate(request);
+    }
+}

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/EmbeddedWebViewerRestful.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/EmbeddedWebViewerRestful.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/EmbeddedWebViewerRestful.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/EmbeddedWebViewerRestful.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,53 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2.embedded;
+
+import org.apache.isis.core.commons.lang.MapUtils;
+import org.apache.isis.core.webapp.content.ResourceCachingFilter;
+import org.apache.isis.core.webapp.content.ResourceServlet;
+import org.apache.isis.runtimes.dflt.runtime.viewer.web.WebAppSpecification;
+import org.apache.isis.runtimes.dflt.runtime.web.EmbeddedWebViewer;
+import org.apache.isis.runtimes.dflt.webapp.IsisSessionFilter;
+import org.apache.isis.viewer.restful.viewer2.RestfulApplication;
+import org.apache.isis.viewer.restful.viewer2.authentication.AuthenticationSessionLookupStrategyTrusted;
+import org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher;
+import org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap;
+
+final class EmbeddedWebViewerRestful extends EmbeddedWebViewer {
+    @Override
+    public WebAppSpecification getWebAppSpecification() {
+        final WebAppSpecification webAppSpec = new WebAppSpecification();
+
+        webAppSpec.addContextParams("isis.viewers", "restful");
+
+        webAppSpec.addContextParams(RestfulViewerInstaller.JAVAX_WS_RS_APPLICATION, RestfulApplication.class.getName());
+
+        webAppSpec.addServletContextListener(ResteasyBootstrap.class);
+
+        webAppSpec.addFilterSpecification(IsisSessionFilter.class, MapUtils.asMap(
+            IsisSessionFilter.AUTHENTICATION_SESSION_LOOKUP_STRATEGY_KEY,
+            AuthenticationSessionLookupStrategyTrusted.class.getName()), RestfulViewerInstaller.EVERYTHING);
+        webAppSpec.addServletSpecification(HttpServletDispatcher.class, RestfulViewerInstaller.ROOT);
+
+        webAppSpec.addFilterSpecification(ResourceCachingFilter.class, RestfulViewerInstaller.STATIC_CONTENT);
+        webAppSpec.addServletSpecification(ResourceServlet.class, RestfulViewerInstaller.STATIC_CONTENT);
+
+        return webAppSpec;
+    }
+}
\ No newline at end of file

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/RestfulViewerInstaller.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/RestfulViewerInstaller.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/RestfulViewerInstaller.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/RestfulViewerInstaller.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,51 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2.embedded;
+
+import org.apache.isis.Isis;
+import org.apache.isis.runtimes.dflt.runtime.installerregistry.installerapi.IsisViewerInstallerAbstract;
+import org.apache.isis.runtimes.dflt.runtime.viewer.IsisViewer;
+import org.apache.isis.runtimes.dflt.runtime.viewer.web.WebAppSpecification;
+
+/**
+ * Convenience implementation of a {@link IsisViewer} providing the ability to configured for the Restful viewer from
+ * the {@link Isis command line} using <tt>--viewer restful</tt> command line option.
+ * 
+ * <p>
+ * In a production deployment the configuration represented by the {@link WebAppSpecification} would be specified in the
+ * <tt>web.xml<tt> file.
+ */
+public class RestfulViewerInstaller extends IsisViewerInstallerAbstract {
+
+    static final String JAVAX_WS_RS_APPLICATION = "javax.ws.rs.Application";
+
+    protected static final String EVERYTHING = "*";
+    protected static final String ROOT = "/";
+    protected static final String[] STATIC_CONTENT = new String[] { "*.js", "*.gif", "*.png" };
+
+    public RestfulViewerInstaller() {
+        super("restful");
+    }
+
+    @Override
+    protected IsisViewer doCreateViewer() {
+        return new EmbeddedWebViewerRestful();
+    }
+
+}

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/HttpMethod.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/HttpMethod.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/HttpMethod.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/HttpMethod.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,22 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2.representations;
+
+
+public enum HttpMethod {
+    GET, PUT, DELETE, POST;
+}

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/LinkRepBuilder.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/LinkRepBuilder.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/LinkRepBuilder.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/LinkRepBuilder.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,65 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2.representations;
+
+import java.util.List;
+
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.viewer.restful.viewer2.RepContext;
+
+public class LinkRepBuilder extends RepresentationBuilder {
+
+    public static LinkRepBuilder newBuilder(RepContext repContext, String relSuffix, String url) {
+        return new LinkRepBuilder(repContext, relSuffix, url);
+    }
+    public static TypeBuilder newTypeBuilder(RepContext repContext, String relSuffix, ObjectSpecification objectSpec) {
+        return new TypeBuilder(repContext, relSuffix, objectSpec);
+    }
+
+    private final String relSuffix;
+    private final String url;
+    
+    private HttpMethod method = HttpMethod.GET;
+    private String title;
+    private List<String> body;
+    
+    public LinkRepBuilder(RepContext repContext, String relSuffix, String url) {
+        super(repContext);
+        this.relSuffix = relSuffix;
+        this.url = url;
+    }
+    public LinkRepBuilder withHttpMethod(HttpMethod method) {
+        this.method = method;
+        return this;
+    }
+    public LinkRepBuilder withTitle(String title) {
+        this.title = title;
+        return this;
+    }
+    public LinkRepBuilder withBody(List<String> body) {
+        this.body = body;
+        return this;
+    }
+    public Representation build() {
+        representation.put("rel", repContext.relFor(relSuffix));
+        representation.put("url", repContext.urlFor(url));
+        representation.put("method", method);
+        representation.put("title", title);
+        representation.put("body", body);
+        return representation;
+    }
+}
\ No newline at end of file

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/Representation.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/Representation.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/Representation.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/Representation.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,37 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2.representations;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+
+public class Representation extends LinkedHashMap<String, Object> {
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public Object put(String key, Object value) {
+        if(value ==null) {
+            return null;
+        }
+        return super.put(key, value);
+    }
+
+    
+}

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/RepresentationBuilder.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/RepresentationBuilder.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/RepresentationBuilder.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/RepresentationBuilder.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,59 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2.representations;
+
+import org.apache.isis.applib.profiles.Localization;
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.metamodel.adapter.oid.stringable.OidStringifier;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.OidGenerator;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.viewer.restful.viewer2.RepContext;
+
+public abstract class RepresentationBuilder {
+
+    protected final RepContext repContext;
+    protected final Representation representation = new Representation();
+    
+    public RepresentationBuilder(RepContext repContext) {
+        this.repContext = repContext;
+    }
+
+    public abstract Representation build();
+    
+    protected OidStringifier getOidStringifier() {
+        return getOidGenerator().getOidStringifier();
+    }
+
+    protected OidGenerator getOidGenerator() {
+        return getPersistenceSession().getOidGenerator();
+    }
+
+    protected PersistenceSession getPersistenceSession() {
+        return IsisContext.getPersistenceSession();
+    }
+
+    protected AuthenticationSession getSession() {
+        return IsisContext.getAuthenticationSession();
+    }
+
+    protected Localization getLocalization() {
+        return IsisContext.getLocalization();
+    }
+
+
+}
\ No newline at end of file

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/TypeBuilder.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/TypeBuilder.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/TypeBuilder.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/TypeBuilder.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,72 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2.representations;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.viewer.restful.viewer2.RepContext;
+
+import com.google.common.collect.Maps;
+
+public class TypeBuilder extends LinkRepBuilder {
+    
+    private static Map<String,String> WELL_KNOWN_TYPES =
+        mapOf(
+            java.lang.String.class.getName(), "string",
+            java.lang.Byte.class.getName(), "byte",
+            java.lang.Short.class.getName(), "short",
+            java.lang.Integer.class.getName(), "int",
+            java.lang.Long.class.getName(), "long",
+            java.lang.Float.class.getName(), "float",
+            java.lang.Double.class.getName(), "double",
+            java.math.BigInteger.class.getName(), "bigint",
+            java.math.BigDecimal.class.getName(), "bigdec"
+            );
+
+    public TypeBuilder(RepContext repContext, String relSuffix, ObjectSpecification objectSpec) {
+        super(repContext, relSuffix, urlFor(objectSpec));
+    }
+    
+    private static String urlFor(ObjectSpecification objectSpec) {
+        return "types/application/vnd+" + map(objectSpec.getFullIdentifier());
+    }
+
+    private static String map(String className) {
+        String wellKnownType = WELL_KNOWN_TYPES.get(className);
+        return wellKnownType != null? wellKnownType: className;
+    }
+
+    /**
+     * Utility to converts varargs into an immutable map. 
+     */
+    private static Map<String, String> mapOf(String... keyOrValues) {
+        Map<String, String> map = Maps.newLinkedHashMap();
+        String key = null;
+        for(String keyOrValue: keyOrValues) {
+            if(key != null) {
+                map.put(key, keyOrValue);
+                key = null;
+            } else {
+                key = keyOrValue;
+            }
+        }
+        return Collections.unmodifiableMap(map);
+    }
+
+}
\ No newline at end of file

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/ResourceAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/ResourceAbstract.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/ResourceAbstract.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/ResourceAbstract.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,218 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2.resources;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.stringable.OidStringifier;
+import org.apache.isis.core.metamodel.consent.Consent;
+import org.apache.isis.core.metamodel.spec.ActionType;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.SpecificationLoader;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.OidGenerator;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.viewer.restful.viewer2.ResourceContext;
+import org.apache.isis.viewer.restful.viewer2.representations.Representation;
+import org.apache.isis.viewer.restful.viewer2.representations.RepresentationBuilder;
+import org.apache.isis.viewer.restful.viewer2.util.OidUtils;
+import org.apache.isis.viewer.restful.viewer2.util.UrlDecoderUtils;
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+
+public abstract class ResourceAbstract {
+
+    public final static ActionType[] ACTION_TYPES = { ActionType.USER, ActionType.DEBUG, ActionType.EXPLORATION,
+    // SET is excluded; we simply flatten contributed actions.
+        };
+
+
+    @Context
+    HttpHeaders httpHeaders;
+
+    @Context
+    UriInfo uriInfo;
+
+    @Context
+    Request request;
+
+    @Context
+    HttpServletRequest httpServletRequest;
+
+    @Context
+    HttpServletResponse httpServletResponse;
+
+    @Context
+    SecurityContext securityContext;
+
+    private ResourceContext resourceContext;
+
+
+    protected void init() {
+        this.resourceContext =
+            new ResourceContext(httpHeaders, uriInfo, request, httpServletRequest, httpServletResponse, securityContext);
+    }
+
+    protected ResourceContext getResourceContext() {
+        return resourceContext;
+    }
+
+    
+    // //////////////////////////////////////////////////////////////
+    // Rendering
+    // //////////////////////////////////////////////////////////////
+
+    protected String jsonRepresentionFrom(RepresentationBuilder builder) {
+        Representation representation = builder.build();
+        return asJson(representation);
+    }
+
+    protected String asJson(final Object object) {
+        ObjectMapper objectMapper = new ObjectMapper();
+        objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+        try {
+            return objectMapper.writeValueAsString(object);
+        } catch (JsonGenerationException e) {
+            throw new RuntimeException(e);
+        } catch (JsonMappingException e) {
+            throw new RuntimeException(e);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+
+    // //////////////////////////////////////////////////////////////
+    // Isis integration
+    // //////////////////////////////////////////////////////////////
+
+    protected ObjectSpecification getSpecification(final String specFullName) {
+        return getSpecificationLoader().loadSpecification(specFullName);
+    }
+
+    protected ObjectAdapter getObjectAdapter(final String oidEncodedStr) {
+        final ObjectAdapter objectAdapter = OidUtils.getObjectAdapter(oidEncodedStr, getOidStringifier());
+        
+        if (objectAdapter == null) {
+            final String oidStr = UrlDecoderUtils.urlDecode(oidEncodedStr);
+            throw new WebApplicationException(responseOfNotFound("could not determine adapter for OID: '" + oidStr + "'"));
+        }
+        return objectAdapter;
+    }
+
+    protected String getOidStr(final ObjectAdapter objectAdapter) {
+        return OidUtils.getOidStr(objectAdapter, getOidStringifier());
+    }
+
+
+
+    // //////////////////////////////////////////////////////////////
+    // Responses
+    // //////////////////////////////////////////////////////////////
+
+    protected Response responseOfOk() {
+        return Response.ok().build();
+    }
+
+    protected Response responseOfGone(final String reason) {
+        return Response.status(Status.GONE).header("isis-reason", reason).build();
+    }
+
+    protected Response responseOfBadRequest(final Consent consent) {
+        return responseOfBadRequest(consent.getReason());
+    }
+
+    protected Response responseOfNoContent(final String reason) {
+        return Response.status(Status.NO_CONTENT).header("isis-reason", reason).build();
+    }
+
+    protected Response responseOfBadRequest(final String reason) {
+        return Response.status(Status.BAD_REQUEST).header("isis-reason", reason).build();
+    }
+
+    protected Response responseOfNotFound(final IllegalArgumentException e) {
+        return responseOfNotFound(e.getMessage());
+    }
+
+    protected Response responseOfNotFound(final String reason) {
+        return Response.status(Status.NOT_FOUND).header("isis-reason", reason).build();
+    }
+
+    protected Response responseOfInternalServerError(final Exception ex) {
+        return responseOfInternalServerError(ex.getMessage());
+    }
+
+    protected Response responseOfInternalServerError(final String reason) {
+        return Response.status(Status.INTERNAL_SERVER_ERROR).header("isis-reason", reason).build();
+    }
+
+    // //////////////////////////////////////////////////////////////
+    // Dependencies (from singletons)
+    // //////////////////////////////////////////////////////////////
+
+    protected AuthenticationSession getSession() {
+        return IsisContext.getAuthenticationSession();
+    }
+
+    private SpecificationLoader getSpecificationLoader() {
+        return IsisContext.getSpecificationLoader();
+    }
+
+    protected AdapterManager getAdapterManager() {
+        return getPersistenceSession().getAdapterManager();
+    }
+
+    protected PersistenceSession getPersistenceSession() {
+        return IsisContext.getPersistenceSession();
+    }
+
+    private OidGenerator getOidGenerator() {
+        return getPersistenceSession().getOidGenerator();
+    }
+
+    private OidStringifier getOidStringifier() {
+        return getOidGenerator().getOidStringifier();
+    }
+
+    // //////////////////////////////////////////////////////////////
+    // Dependencies (injected via @Context)
+    // //////////////////////////////////////////////////////////////
+
+    protected HttpServletRequest getServletRequest() {
+        return getResourceContext().getHttpServletRequest();
+    }
+
+}

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/bootstrap/BootstrapResourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/bootstrap/BootstrapResourceImpl.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/bootstrap/BootstrapResourceImpl.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/bootstrap/BootstrapResourceImpl.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,57 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2.resources.bootstrap;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.isis.viewer.restful.applib2.resources.BootstrapResource;
+import org.apache.isis.viewer.restful.viewer2.resources.ResourceAbstract;
+
+import com.google.common.io.ByteStreams;
+
+/**
+ * Implementation note: it seems to be necessary to annotate the implementation with {@link Path} rather than the
+ * interface (at least under RestEasy 1.0.2 and 1.1-RC2).
+ */
+@Path("/")
+public class BootstrapResourceImpl extends ResourceAbstract implements BootstrapResource {
+
+
+    @Override
+    @Produces(MediaType.TEXT_HTML)
+    public String bootstrap() {
+        init();
+        try {
+            InputStream resourceAsStream = BootstrapResourceImpl.class.getResourceAsStream("/index.html");
+            byte[] byteArray = ByteStreams.toByteArray(resourceAsStream);
+            return new String(byteArray, Charset.defaultCharset());
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+
+
+}
\ No newline at end of file

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/home/HomePageResourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/home/HomePageResourceImpl.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/home/HomePageResourceImpl.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/home/HomePageResourceImpl.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,55 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2.resources.home;
+
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.isis.viewer.restful.applib2.resources.HomePageResource;
+import org.apache.isis.viewer.restful.viewer2.representations.LinkRepBuilder;
+import org.apache.isis.viewer.restful.viewer2.representations.Representation;
+import org.apache.isis.viewer.restful.viewer2.resources.ResourceAbstract;
+
+/**
+ * Implementation note: it seems to be necessary to annotate the implementation with {@link Path} rather than the
+ * interface (at least under RestEasy 1.0.2 and 1.1-RC2).
+ */
+@Path("/index")
+public class HomePageResourceImpl extends ResourceAbstract implements HomePageResource {
+
+
+    @Override
+    @Produces(MediaType.APPLICATION_JSON)
+    public String resources() {
+        init();
+        
+        Representation representation = new Representation();
+        representation.put("user", linkTo("user"));
+        representation.put("services", linkTo("services"));
+        
+        return asJson(representation);
+    }
+
+    protected Representation linkTo(String url) {
+        return LinkRepBuilder.newBuilder(getResourceContext().repContext(url), null, url).build();
+    }
+
+
+}
\ No newline at end of file

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/AbstractMemberRepBuilder.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/AbstractMemberRepBuilder.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/AbstractMemberRepBuilder.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/AbstractMemberRepBuilder.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,183 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2.resources.objects;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.oid.stringable.OidStringifier;
+import org.apache.isis.core.metamodel.consent.Consent;
+import org.apache.isis.core.metamodel.facetapi.Facet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectMember;
+import org.apache.isis.viewer.restful.viewer2.RepContext;
+import org.apache.isis.viewer.restful.viewer2.representations.LinkRepBuilder;
+import org.apache.isis.viewer.restful.viewer2.representations.Representation;
+import org.apache.isis.viewer.restful.viewer2.representations.RepresentationBuilder;
+
+import com.google.common.collect.Lists;
+
+public abstract class AbstractMemberRepBuilder<T extends ObjectMember> extends RepresentationBuilder {
+
+    protected final ObjectAdapter objectAdapter;
+    protected final MemberType memberType;
+    protected final T objectMember;
+    protected final MemberRepType memberRepType;
+
+    public AbstractMemberRepBuilder(RepContext repContext, ObjectAdapter objectAdapter, MemberType memberType, T objectMember) {
+        super(repContext);
+        this.objectAdapter = objectAdapter;
+        this.memberType = memberType;
+        this.objectMember = objectMember;
+        this.memberRepType = repContext.hasAttribute()?MemberRepType.INLINE:MemberRepType.STANDALONE;
+    }
+
+    protected void putSelfIfRequired() {
+        if(memberRepType.hasSelf()) {
+            Representation selfRep = MemberSelfRepBuilder.newBuilder(repContext, objectAdapter, memberType, objectMember).build();
+            representation.put("self", selfRep);
+        }
+    }
+
+    protected void putMemberTypeRep() {
+        representation.put("memberType", memberType);
+    }
+
+    protected void putTypeRep() {
+        Representation typeRep = LinkRepBuilder.newTypeBuilder(repContext, "type", memberType.specFor(objectMember)).build();
+        representation.put("type", typeRep);
+    }
+
+    protected void putMutatorsIfRequired() {
+        if(!memberRepType.hasMutators() || usability().isVetoed()) {
+            return;
+        }
+        Map<String, MutatorSpec> mutators = memberType.getMutators();
+        for(String mutator: mutators.keySet()) {
+            MutatorSpec mutatorSpec = mutators.get(mutator);
+            if(hasMemberFacet(mutatorSpec.mutatorFacetType)) {
+                String urlForMember = urlForMember(mutatorSpec.suffix);
+                List<String> body = mutatorArgValues(mutatorSpec);
+                Representation detailsLink = 
+                    LinkRepBuilder.newBuilder(repContext, mutator, urlForMember)
+                        .withHttpMethod(mutatorSpec.httpMethod)
+                        .withBody(body)
+                        .build();
+                representation.put(mutator, detailsLink);
+            }
+        }
+    }
+
+    /**
+     * Can be optionally overridden by members that are able
+     * to provide argument values (eg contributed actions).
+     */
+    protected List<String> mutatorArgValues(MutatorSpec mutatorSpec) {
+        List<String> values = Lists.newArrayList();
+        if(mutatorSpec.argSpec.isOne()) {
+            values.add("{arg}");
+        }
+        return values;
+    }
+
+
+    protected void putValueIfRequired() {
+        if(!memberRepType.hasValue(memberType)) {
+            return;
+        } 
+        representation.put("value", valueRep());
+        return;
+    }
+
+    /**
+     * Members that can provide a value should override.
+     */
+    protected Object valueRep() {
+        return null;
+    }
+
+
+    protected final void putDisabledReason() {
+        String disabledReasonRep = usability().getReason();
+        representation.put("disabledReason", disabledReasonRep);
+    }
+
+    protected void putDetailsIfRequired() {
+        if(!memberRepType.hasLinkToDetails()) {
+            return;
+        } 
+        String urlForMember = urlForMember();
+        Representation detailsLink = LinkRepBuilder.newBuilder(repContext, "details", urlForMember).build();
+        representation.put("details", detailsLink);
+    }
+
+    /**
+     * For Resources to call.
+     */
+    public boolean isMemberVisible() {
+        return visibility().isAllowed();
+    }
+
+
+    protected <F extends Facet> F getMemberSpecFacet(Class<F> facetType) {
+        ObjectSpecification otoaSpec = objectMember.getSpecification();
+        return otoaSpec.getFacet(facetType);
+    }
+
+    protected boolean hasMemberFacet(Class<? extends Facet> facetType) {
+        return objectMember.getFacet(facetType) != null;
+    }
+
+
+    protected String urlForObject() {
+        return DomainObjectRepBuilder.urlFor(objectAdapter, getOidStringifier());
+    }
+
+    protected String urlForMember(String... parts) {
+        return urlForMember(objectAdapter, memberType, objectMember, getOidStringifier(), parts);
+    }
+
+    protected Consent usability() {
+        return objectMember.isUsable(getSession(), objectAdapter);
+    }
+
+    protected Consent visibility() {
+        return objectMember.isVisible(getSession(), objectAdapter);
+    }
+
+    
+    /////////////////////////////////////////////////////////////////
+    // statics
+    /////////////////////////////////////////////////////////////////
+
+    public static String urlForMember(ObjectAdapter objectAdapter, MemberType memberType, ObjectMember objectMember,
+        OidStringifier oidStringifier, String... parts) {
+        String oidStr = oidStringifier.enString(objectAdapter.getOid());
+        StringBuilder buf = new StringBuilder();
+        buf.append("objects/").append(oidStr);
+        buf.append("/").append(memberType.urlPart()).append(objectMember.getId());
+        for(String part: parts) {
+            if(part == null) {
+                continue;
+            }
+            buf.append("/").append(part);
+        }
+        return buf.toString();
+    }
+
+}
\ No newline at end of file

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/ActionRepBuilder.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/ActionRepBuilder.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/ActionRepBuilder.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/ActionRepBuilder.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,64 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2.resources.objects;
+
+import java.util.List;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
+import org.apache.isis.viewer.restful.viewer2.RepContext;
+import org.apache.isis.viewer.restful.viewer2.representations.Representation;
+
+import com.google.common.collect.Lists;
+
+public class ActionRepBuilder extends AbstractMemberRepBuilder<ObjectAction> {
+
+    public static ActionRepBuilder newBuilder(RepContext repContext, ObjectAdapter objectAdapter, ObjectAction oa) {
+        return new ActionRepBuilder(repContext, objectAdapter, oa);
+    }
+
+    public ActionRepBuilder(RepContext repContext, ObjectAdapter objectAdapter, ObjectAction oa) {
+        super(repContext, objectAdapter, MemberType.ACTION, oa);
+    }
+
+    public Representation build() {
+        putSelfIfRequired();
+        putTypeRep();
+        putMemberTypeRep();
+        representation.put("actionType", objectMember.getType());
+        representation.put("numParameters", objectMember.getParameterCount());
+        putValueIfRequired();
+        putDisabledReason();
+        putMutatorsIfRequired();
+        putDetailsIfRequired();
+        return representation;
+    }
+    
+    protected List<String> mutatorArgValues(MutatorSpec mutatorSpec) {
+        List<String> values = Lists.newArrayList();
+        for(int i=0; i<objectMember.getParameterCount(); i++) {
+            values.add(argValueFor(i)); 
+        }
+        return values;
+    }
+
+    // TODO: expect in future to provide values for contributed actions.
+    private String argValueFor(int i) {
+        return "{arg" + i + "}";
+    }
+
+}
\ No newline at end of file

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/BodyArgs.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/BodyArgs.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/BodyArgs.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/BodyArgs.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,37 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2.resources.objects;
+
+public enum BodyArgs {
+    /**
+     * eg property clear
+     */
+    NONE,
+    /**
+     * eg property modify, collection addto/remove
+     */
+    ONE,
+    /**
+     * eg action invoke
+     */
+    MANY;
+
+    public boolean isOne() {
+        return this == ONE;
+    }
+
+}

Added: incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/CollectionRepBuilder.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/CollectionRepBuilder.java?rev=1139763&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/CollectionRepBuilder.java (added)
+++ incubator/isis/trunk/viewer/json/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/CollectionRepBuilder.java Sun Jun 26 11:51:01 2011
@@ -0,0 +1,79 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2.resources.objects;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacetUtils;
+import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
+import org.apache.isis.core.metamodel.facets.object.title.TitleFacet;
+import org.apache.isis.core.metamodel.facets.object.value.ValueFacet;
+import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
+import org.apache.isis.core.progmodel.facets.CollectionUtils;
+import org.apache.isis.viewer.restful.viewer2.RepContext;
+import org.apache.isis.viewer.restful.viewer2.representations.LinkRepBuilder;
+import org.apache.isis.viewer.restful.viewer2.representations.Representation;
+
+import com.google.common.collect.Lists;
+
+public class CollectionRepBuilder extends AbstractMemberRepBuilder<OneToManyAssociation> {
+
+    public static CollectionRepBuilder newBuilder(RepContext repContext, ObjectAdapter objectAdapter, OneToManyAssociation otma) {
+        return new CollectionRepBuilder(repContext, objectAdapter, otma);
+    }
+
+    public CollectionRepBuilder(RepContext repContext, ObjectAdapter objectAdapter, OneToManyAssociation otma) {
+        super(repContext, objectAdapter, MemberType.COLLECTION, otma);
+    }
+
+    public Representation build() {
+        putSelfIfRequired();
+        putTypeRep();
+        putMemberTypeRep();
+        putValueIfRequired();
+        putDisabledReason();
+        putMutatorsIfRequired();
+        putDetailsIfRequired();
+        return representation;
+    }
+
+    protected List<String> mutatorArgValues(MutatorSpec mutatorSpec) {
+        List<String> values = Lists.newArrayList();
+        values.add(null);
+        return values;
+    }
+
+    @Override
+    protected Object valueRep() {
+        ObjectAdapter valueAdapter = objectMember.get(objectAdapter);
+        if(valueAdapter == null) {
+            return null;
+        }
+        final CollectionFacet facet = CollectionFacetUtils.getCollectionFacetFromSpec(valueAdapter);
+        List<Representation> list = Lists.newArrayList();
+        for (final ObjectAdapter elementAdapter : facet.iterable(valueAdapter)) {
+            String url = DomainObjectRepBuilder.urlFor(elementAdapter, getOidStringifier());
+            list.add(LinkRepBuilder.newBuilder(repContext, "value", url).build());
+        }
+        
+        return list;
+    }
+
+}
\ No newline at end of file