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/22 00:32:44 UTC

svn commit: r1138223 [1/2] - in /incubator/isis/trunk/viewer/restful/viewer2: ./ src/ src/main/ src/main/java/ src/main/java/META-INF/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/isis/ src/main/java/org/apache/isis/viewer/ src...

Author: danhaywood
Date: Tue Jun 21 22:32:41 2011
New Revision: 1138223

URL: http://svn.apache.org/viewvc?rev=1138223&view=rev
Log:
started on viewer2 : restful JSON protocol

Added:
    incubator/isis/trunk/viewer/restful/viewer2/
    incubator/isis/trunk/viewer/restful/viewer2/pom.xml
    incubator/isis/trunk/viewer/restful/viewer2/src/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/META-INF/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/META-INF/MANIFEST.MF
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/AbstractJaxRsApplication.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/Constants.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RepresentationContext.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/ResourceContext.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RestfulApplication.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyParams.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyTrusted.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/EmbeddedWebViewerRestful.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/RestfulViewerInstaller.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/HttpMethod.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/LinkRepresentation.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/TypeRepresentation.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/ResourceAbstract.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/bootstrap/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/bootstrap/BootstrapResourceImpl.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/home/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/home/HomePageRepresentation.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/home/HomePageResourceImpl.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/ActionRepresentation.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/CollectionRepresentation.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/DomainObjectRepresentation.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/MemberRepresentation.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/PropertyRepresentation.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/ActionUtils.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/InputStreamUtil.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/ListUtils.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/OidUtils.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/PathUtils.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/StringUtil.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/UrlDecoderUtils.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/resources/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/resources/index.html
    incubator/isis/trunk/viewer/restful/viewer2/src/main/resources/isis-json-support.js
    incubator/isis/trunk/viewer/restful/viewer2/src/main/resources/isis-rest-support.js
    incubator/isis/trunk/viewer/restful/viewer2/src/main/resources/json-20110223.js
    incubator/isis/trunk/viewer/restful/viewer2/src/main/resources/org/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/resources/org/apache/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/resources/org/apache/isis/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/resources/org/apache/isis/viewer/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/resources/org/apache/isis/viewer/restful/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/resources/org/apache/isis/viewer/restful/viewer2/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/resources/org/apache/isis/viewer/restful/viewer2/resources/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/test/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/test/net/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/test/net/sf/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/test/net/sf/restfulobjects/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/test/net/sf/restfulobjects/viewer/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/test/net/sf/restfulobjects/viewer/util/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/test/net/sf/restfulobjects/viewer/util/StringUtilTest.java
    incubator/isis/trunk/viewer/restful/viewer2/src/main/test/org/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/test/org/nakedobjects/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/test/org/nakedobjects/nos/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/test/org/nakedobjects/nos/client/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/test/org/nakedobjects/nos/client/rest/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/test/org/nakedobjects/nos/client/rest/util/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/webapp/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/webapp/META-INF/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/webapp/META-INF/MANIFEST.MF
    incubator/isis/trunk/viewer/restful/viewer2/src/main/webapp/WEB-INF/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/webapp/WEB-INF/isis.properties
    incubator/isis/trunk/viewer/restful/viewer2/src/main/webapp/WEB-INF/lib/
    incubator/isis/trunk/viewer/restful/viewer2/src/main/webapp/WEB-INF/web.xml
    incubator/isis/trunk/viewer/restful/viewer2/src/site/
    incubator/isis/trunk/viewer/restful/viewer2/src/site/apt/
    incubator/isis/trunk/viewer/restful/viewer2/src/site/apt/index.apt
    incubator/isis/trunk/viewer/restful/viewer2/src/site/apt/jottings.apt
    incubator/isis/trunk/viewer/restful/viewer2/src/site/resources/
    incubator/isis/trunk/viewer/restful/viewer2/src/site/site.xml
    incubator/isis/trunk/viewer/restful/viewer2/src/test/
    incubator/isis/trunk/viewer/restful/viewer2/src/test/java/
    incubator/isis/trunk/viewer/restful/viewer2/src/test/resources/

Added: incubator/isis/trunk/viewer/restful/viewer2/pom.xml
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/pom.xml?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/pom.xml (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/pom.xml Tue Jun 21 22:32:41 2011
@@ -0,0 +1,101 @@
+<?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-applib</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>
+
+		<dependency>
+			<groupId>org.jboss.resteasy</groupId>
+			<artifactId>resteasy-jaxrs</artifactId>
+		</dependency>
+
+        <dependency>
+            <groupId>org.jboss.resteasy</groupId>
+            <artifactId>resteasy-jaxrs</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.codehaus.jackson</groupId>
+            <artifactId>jackson-core-asl</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.codehaus.jackson</groupId>
+            <artifactId>jackson-mapper-asl</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/restful/viewer2/src/main/java/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/META-INF/MANIFEST.MF?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/META-INF/MANIFEST.MF (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/META-INF/MANIFEST.MF Tue Jun 21 22:32:41 2011
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path: 
+

Added: incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/AbstractJaxRsApplication.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/AbstractJaxRsApplication.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/AbstractJaxRsApplication.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/AbstractJaxRsApplication.java Tue Jun 21 22:32:41 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/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/Constants.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/Constants.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/Constants.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/Constants.java Tue Jun 21 22:32:41 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.applib.Constants.URL_ENCODING_CHAR_SET;
+
+    private Constants() {
+    }
+
+}

Added: incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RepresentationContext.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RepresentationContext.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RepresentationContext.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RepresentationContext.java Tue Jun 21 22:32:41 2011
@@ -0,0 +1,39 @@
+/*
+ *  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;
+
+
+public class RepresentationContext {
+
+    private final ResourceContext resourceContext;
+    private final String attribute;
+
+    public RepresentationContext(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 attribute == null? relSuffix: attribute + (relSuffix!=null?"." + relSuffix:"");
+    }
+}

Added: incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/ResourceContext.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/ResourceContext.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/ResourceContext.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/ResourceContext.java Tue Jun 21 22:32:41 2011
@@ -0,0 +1,76 @@
+/*
+ *  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 RepresentationContext representationSelfLinkTo(String attribute) {
+        return new RepresentationContext(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/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RestfulApplication.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RestfulApplication.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RestfulApplication.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/RestfulApplication.java Tue Jun 21 22:32:41 2011
@@ -0,0 +1,33 @@
+/*
+ *  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.services.ServicesResourceImpl;
+
+public class RestfulApplication extends AbstractJaxRsApplication {
+
+    public RestfulApplication() {
+        addSingleton(new BootstrapResourceImpl());
+        addSingleton(new HomePageResourceImpl());
+        addSingleton(new ServicesResourceImpl());
+    }
+
+}

Added: incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyParams.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyParams.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyParams.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyParams.java Tue Jun 21 22:32:41 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/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyTrusted.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyTrusted.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyTrusted.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/authentication/AuthenticationSessionLookupStrategyTrusted.java Tue Jun 21 22:32:41 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/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/EmbeddedWebViewerRestful.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/EmbeddedWebViewerRestful.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/EmbeddedWebViewerRestful.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/EmbeddedWebViewerRestful.java Tue Jun 21 22:32:41 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.ResourceServlet;
+import org.apache.isis.core.webapp.content.ResourceCachingFilter;
+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/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/RestfulViewerInstaller.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/RestfulViewerInstaller.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/RestfulViewerInstaller.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/embedded/RestfulViewerInstaller.java Tue Jun 21 22:32:41 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/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/HttpMethod.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/HttpMethod.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/HttpMethod.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/HttpMethod.java Tue Jun 21 22:32:41 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/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/LinkRepresentation.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/LinkRepresentation.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/LinkRepresentation.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/LinkRepresentation.java Tue Jun 21 22:32:41 2011
@@ -0,0 +1,114 @@
+/**
+ *  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.viewer.restful.viewer2.RepresentationContext;
+import org.apache.isis.viewer.restful.viewer2.ResourceContext;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+
+
+@JsonSerialize(include=Inclusion.NON_NULL)
+public class LinkRepresentation {
+
+    private String rel;
+    private String url;
+    private HttpMethod method;
+    private String title;
+    private String body;
+    private Object value;
+    
+    
+    public String getRel() {
+        return rel;
+    }
+    public void setRel(String rel) {
+        this.rel = rel;
+    }
+    public String getUrl() {
+        return url;
+    }
+    public void setUrl(String url) {
+        this.url = url;
+    }
+    public HttpMethod getMethod() {
+        return method;
+    }
+    public void setMethod(HttpMethod method) {
+        this.method = method;
+    }
+    public String getTitle() {
+        return title;
+    }
+    public void setTitle(String title) {
+        this.title = title;
+    }
+    public String getBody() {
+        return body;
+    }
+    public void setBody(String body) {
+        this.body = body;
+    }
+    public Object getValue() {
+        return value;
+    }
+    public void setValue(Object value) {
+        this.value = value;
+    }
+
+    public static Builder newBuilder(RepresentationContext representationContext, String relSuffix, String url) {
+        return new Builder(representationContext, relSuffix, url);
+    }
+    
+    public static class Builder {
+        
+        private final RepresentationContext representationContext;
+        private final String relSuffix;
+        private final String url;
+        
+        private HttpMethod method = HttpMethod.GET;
+        private String title;
+        private String body;
+        
+        public Builder(RepresentationContext representationContext, String relSuffix, String url) {
+            this.representationContext = representationContext;
+            this.relSuffix = relSuffix;
+            this.url = url;
+        }
+        public LinkRepresentation.Builder withMethod(HttpMethod method) {
+            this.method = method;
+            return this;
+        }
+        public LinkRepresentation.Builder withTitle(String title) {
+            this.title = title;
+            return this;
+        }
+        public LinkRepresentation.Builder withBody(String body) {
+            this.body = body;
+            return this;
+        }
+        public LinkRepresentation build() {
+            LinkRepresentation linkRepresentation = new LinkRepresentation();
+            linkRepresentation.setMethod(method);
+            linkRepresentation.setTitle(title);
+            linkRepresentation.setRel(representationContext.relFor(relSuffix));
+            linkRepresentation.setUrl(representationContext.urlFor(url));
+            linkRepresentation.setBody(body);
+            return linkRepresentation;
+        }
+    }
+}

Added: incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/TypeRepresentation.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/TypeRepresentation.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/TypeRepresentation.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/representations/TypeRepresentation.java Tue Jun 21 22:32:41 2011
@@ -0,0 +1,67 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.isis.viewer.restful.viewer2.representations;
+
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.viewer.restful.viewer2.RepresentationContext;
+import org.apache.isis.viewer.restful.viewer2.ResourceContext;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+
+
+@JsonSerialize(include=Inclusion.NON_NULL)
+public class TypeRepresentation {
+    
+    private LinkRepresentation link;
+
+    public LinkRepresentation getLink() {
+        return link;
+    }
+
+    public void setLink(LinkRepresentation link) {
+        this.link = link;
+    }
+
+    public static Builder newBuilder(RepresentationContext representationContext, String relSuffix, ObjectSpecification objectSpec) {
+        return new Builder(representationContext, relSuffix, objectSpec);
+    }
+    
+    public static class Builder {
+        
+        private final RepresentationContext representationContext;
+        private final String relSuffix;
+        private final ObjectSpecification objectSpec;
+        
+        public Builder(RepresentationContext representationContext, String relSuffix, ObjectSpecification objectSpec) {
+            this.representationContext = representationContext;
+            this.relSuffix = relSuffix;
+            this.objectSpec = objectSpec;
+        }
+        
+        public TypeRepresentation build() {
+            TypeRepresentation typeRepresentation = new TypeRepresentation();
+            LinkRepresentation.Builder typeBuilder = LinkRepresentation.newBuilder(representationContext, relSuffix, urlFor(objectSpec));
+            LinkRepresentation linkRepresentation = typeBuilder.build();
+            typeRepresentation.setLink(linkRepresentation);
+            return typeRepresentation;
+        }
+
+        private static String urlFor(ObjectSpecification objectSpec) {
+            return "types/application/vnd+" + objectSpec.getFullIdentifier();
+        }
+    }
+}

Added: incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/ResourceAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/ResourceAbstract.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/ResourceAbstract.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/ResourceAbstract.java Tue Jun 21 22:32:41 2011
@@ -0,0 +1,207 @@
+/*
+ *  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.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.resources.objects.DomainObjectRepresentation;
+import org.apache.isis.viewer.restful.viewer2.util.OidUtils;
+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 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);
+        }
+    }
+
+    protected String asJsonList(List<DomainObjectRepresentation> services) {
+        return asJson(services);
+    }
+
+    // //////////////////////////////////////////////////////////////
+    // Isis integration
+    // //////////////////////////////////////////////////////////////
+
+    protected ObjectSpecification getSpecification(final String specFullName) {
+        return getSpecificationLoader().loadSpecification(specFullName);
+    }
+
+    protected ObjectAdapter getNakedObject(final String oidEncodedStr) {
+        return OidUtils.getNakedObject(oidEncodedStr, getOidStringifier());
+    }
+
+    protected String getOidStr(final ObjectAdapter nakedObject) {
+        return OidUtils.getOidStr(nakedObject, 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/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/bootstrap/BootstrapResourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/bootstrap/BootstrapResourceImpl.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/bootstrap/BootstrapResourceImpl.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/bootstrap/BootstrapResourceImpl.java Tue Jun 21 22:32:41 2011
@@ -0,0 +1,58 @@
+/*
+ *  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.applib.resources.BootstrapResource;
+import org.apache.isis.viewer.restful.applib.resources.HomePageResource;
+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/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/home/HomePageRepresentation.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/home/HomePageRepresentation.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/home/HomePageRepresentation.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/home/HomePageRepresentation.java Tue Jun 21 22:32:41 2011
@@ -0,0 +1,73 @@
+/**
+ *  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 org.apache.isis.viewer.restful.viewer2.representations.LinkRepresentation;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+
+@JsonSerialize(include=Inclusion.NON_NULL)
+public class HomePageRepresentation {
+    
+    @JsonSerialize(include=Inclusion.NON_NULL)
+    public static class SelfRepresentation {
+        private LinkRepresentation link;
+
+        public SelfRepresentation(LinkRepresentation link) {
+            this.link = link;
+        }
+
+        public LinkRepresentation getLink() {
+            return link;
+        }
+
+        public void setLink(LinkRepresentation link) {
+            this.link = link;
+        }
+    }
+    
+    private SelfRepresentation _self;
+    
+    private LinkRepresentation services;
+    private LinkRepresentation user;
+
+    public SelfRepresentation get_self() {
+        return _self;
+    }
+
+    public void set_self(SelfRepresentation self) {
+        this._self = self;
+    }
+    
+    public LinkRepresentation getServices() {
+        return services;
+    }
+
+    public void setServices(LinkRepresentation services) {
+        this.services = services;
+    }
+
+    public LinkRepresentation getUser() {
+        return user;
+    }
+
+    public void setUser(LinkRepresentation user) {
+        this.user = user;
+    }
+    
+
+}

Added: incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/home/HomePageResourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/home/HomePageResourceImpl.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/home/HomePageResourceImpl.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/home/HomePageResourceImpl.java Tue Jun 21 22:32:41 2011
@@ -0,0 +1,54 @@
+/*
+ *  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.applib.resources.HomePageResource;
+import org.apache.isis.viewer.restful.viewer2.representations.LinkRepresentation;
+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();
+        
+        HomePageRepresentation homePageRepresentation = new HomePageRepresentation();
+        homePageRepresentation.setUser(linkTo("user"));
+
+        homePageRepresentation.setServices(linkTo("services"));
+        return asJson(homePageRepresentation);
+    }
+
+    protected LinkRepresentation linkTo(String url) {
+        return LinkRepresentation.newBuilder(getResourceContext().representationSelfLinkTo(url), null, url).build();
+    }
+
+
+}
\ No newline at end of file

Added: incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/ActionRepresentation.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/ActionRepresentation.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/ActionRepresentation.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/ActionRepresentation.java Tue Jun 21 22:32:41 2011
@@ -0,0 +1,25 @@
+/**
+ *  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 org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+
+@JsonSerialize(include=Inclusion.NON_NULL)
+public class ActionRepresentation extends MemberRepresentation {
+
+}

Added: incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/CollectionRepresentation.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/CollectionRepresentation.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/CollectionRepresentation.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/CollectionRepresentation.java Tue Jun 21 22:32:41 2011
@@ -0,0 +1,25 @@
+/**
+ *  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 org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+
+@JsonSerialize(include=Inclusion.NON_NULL)
+public class CollectionRepresentation extends MemberRepresentation {
+
+}

Added: incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/DomainObjectRepresentation.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/DomainObjectRepresentation.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/DomainObjectRepresentation.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/DomainObjectRepresentation.java Tue Jun 21 22:32:41 2011
@@ -0,0 +1,176 @@
+/**
+ *  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.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.RepresentationContext;
+import org.apache.isis.viewer.restful.viewer2.ResourceContext;
+import org.apache.isis.viewer.restful.viewer2.representations.LinkRepresentation;
+import org.apache.isis.viewer.restful.viewer2.representations.TypeRepresentation;
+
+import com.google.common.base.Function;
+
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+
+@JsonSerialize(include=Inclusion.NON_NULL)
+public class DomainObjectRepresentation {
+
+    public static Function<ObjectAdapter, DomainObjectRepresentation> fromAdapter(final RepresentationContext representationContext) {
+        return new Function<ObjectAdapter, DomainObjectRepresentation>() {
+            @Override
+            public DomainObjectRepresentation apply(ObjectAdapter input) {
+                return newBuilder(representationContext, input).build();
+            }
+        };
+    }
+
+
+    @JsonSerialize(include=Inclusion.NON_NULL)
+    public static class SelfRepresentation {
+        private LinkRepresentation link;
+        private TypeRepresentation type;
+        private String title;
+        private LinkRepresentation icon;
+        
+        public SelfRepresentation(LinkRepresentation link) {
+            this.link = link;
+        }
+
+        public LinkRepresentation getLink() {
+            return link;
+        }
+
+        public void setLink(LinkRepresentation link) {
+            this.link = link;
+        }
+
+        public TypeRepresentation getType() {
+            return type;
+        }
+
+        public void setType(TypeRepresentation type) {
+            this.type = type;
+        }
+
+        public String getTitle() {
+            return title;
+        }
+
+        public void setTitle(String title) {
+            this.title = title;
+        }
+
+        public LinkRepresentation getIcon() {
+            return icon;
+        }
+
+        public void setIcon(LinkRepresentation icon) {
+            this.icon = icon;
+        }
+    }
+    
+    private SelfRepresentation _self;
+    private List<PropertyRepresentation> properties;
+    private List<CollectionRepresentation> collections;
+    private List<ActionRepresentation> actions;
+    
+    public SelfRepresentation get_self() {
+        return _self;
+    }
+    public void set_self(SelfRepresentation self) {
+        this._self = self;
+    }
+    public List<PropertyRepresentation> getProperties() {
+        return properties;
+    }
+    public void setProperties(List<PropertyRepresentation> properties) {
+        this.properties = properties;
+    }
+    public List<CollectionRepresentation> getCollections() {
+        return collections;
+    }
+    public void setCollections(List<CollectionRepresentation> collections) {
+        this.collections = collections;
+    }
+    public List<ActionRepresentation> getActions() {
+        return actions;
+    }
+    public void setActions(List<ActionRepresentation> actions) {
+        this.actions = actions;
+    }
+    
+
+    public static Builder newBuilder(RepresentationContext representationContext, ObjectAdapter objectAdapter) {
+        return new Builder(representationContext, objectAdapter);
+    }
+
+    public static class Builder {
+
+        private final RepresentationContext representationContext;
+        private final ObjectAdapter objectAdapter;
+        
+        public Builder(RepresentationContext representationContext, ObjectAdapter objectAdapter) {
+            this.representationContext = representationContext;
+            this.objectAdapter = objectAdapter;
+        }
+        
+        public DomainObjectRepresentation build() {
+            DomainObjectRepresentation domainObject = new DomainObjectRepresentation();
+            LinkRepresentation selfLink = LinkRepresentation.newBuilder(representationContext, "link", urlFor(objectAdapter)).build();
+            TypeRepresentation selfType = TypeRepresentation.newBuilder(representationContext, "type", objectAdapter.getSpecification()).build();
+            String title = objectAdapter.titleString();
+            LinkRepresentation iconLink = LinkRepresentation.newBuilder(representationContext, "icon", iconFor(objectAdapter)).build();
+            SelfRepresentation self = new SelfRepresentation(selfLink);
+            self.setTitle(title);
+            self.setIcon(iconLink);
+            self.setType(selfType);
+            domainObject.set_self(self);
+            return domainObject;
+        }
+
+        private String iconFor(ObjectAdapter objectAdapter) {
+            String iconName = objectAdapter.getIconName();
+            return "images/" + iconName + ".png";
+        }
+
+        private String urlFor(ObjectAdapter objectAdapter) {
+            String className = objectAdapter.getSpecification().getFullIdentifier();
+            OidStringifier oidStringifier = getOidStringifier();
+            String oidStr = oidStringifier.enString(objectAdapter.getOid());
+            return className + "|" + oidStr;
+        }
+
+        protected OidStringifier getOidStringifier() {
+            return getOidGenerator().getOidStringifier();
+        }
+
+        protected OidGenerator getOidGenerator() {
+            return getPersistenceSession().getOidGenerator();
+        }
+
+        protected PersistenceSession getPersistenceSession() {
+            return IsisContext.getPersistenceSession();
+        }
+    }
+}

Added: incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/MemberRepresentation.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/MemberRepresentation.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/MemberRepresentation.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/MemberRepresentation.java Tue Jun 21 22:32:41 2011
@@ -0,0 +1,30 @@
+/**
+ *  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 org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+
+@JsonSerialize(include=Inclusion.NON_NULL)
+public abstract class MemberRepresentation {
+    
+    @JsonSerialize(include=Inclusion.NON_NULL)
+    public static class SelfRepresentation {
+        
+    }
+
+}

Added: incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/PropertyRepresentation.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/PropertyRepresentation.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/PropertyRepresentation.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/resources/objects/PropertyRepresentation.java Tue Jun 21 22:32:41 2011
@@ -0,0 +1,25 @@
+/**
+ *  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 org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+
+@JsonSerialize(include=Inclusion.NON_NULL)
+public class PropertyRepresentation extends MemberRepresentation {
+
+}

Added: incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/ActionUtils.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/ActionUtils.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/ActionUtils.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/ActionUtils.java Tue Jun 21 22:32:41 2011
@@ -0,0 +1,50 @@
+/*
+ *  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.util;
+
+import java.util.List;
+
+import org.apache.isis.core.metamodel.spec.ActionType;
+import org.apache.isis.core.metamodel.spec.ObjectActionSet;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
+
+import com.google.inject.internal.Lists;
+
+public final class ActionUtils {
+
+    private ActionUtils() {
+    }
+
+    public static List<ObjectAction> flattened(final List<ObjectAction> objectActions) {
+        final List<ObjectAction> actions = Lists.newArrayList();
+        for (final ObjectAction action : objectActions) {
+            if (action.getType() == ActionType.SET) {
+                final ObjectActionSet actionSet = (ObjectActionSet) action;
+                final List<ObjectAction> subActions = actionSet.getActions();
+                for (final ObjectAction subAction : subActions) {
+                    actions.add(subAction);
+                }
+            } else {
+                actions.add(action);
+            }
+        }
+        return actions;
+    }
+
+}

Added: incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/InputStreamUtil.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/InputStreamUtil.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/InputStreamUtil.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/InputStreamUtil.java Tue Jun 21 22:32:41 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.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+public final class InputStreamUtil {
+
+    private InputStreamUtil() {
+    }
+
+    public static List<String> getArgs(final InputStream body) {
+        // will be sorted by arg
+        final Map<String, String> args = new TreeMap<String, String>();
+        if (body == null) {
+            return listOfValues(args);
+        }
+        try {
+            final InputStreamReader inputStreamReader = new InputStreamReader(body);
+            final BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
+            String readLine = bufferedReader.readLine();
+            while (readLine != null) {
+                final String[] keyValuePairs = readLine.split("&");
+                for (final String keyValuePair : keyValuePairs) {
+                    final String[] keyThenValue = keyValuePair.split("=");
+                    args.put(keyThenValue[0], keyThenValue[1]);
+                }
+                readLine = bufferedReader.readLine();
+            }
+            return listOfValues(args);
+        } catch (final IOException ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+
+    private static ArrayList<String> listOfValues(final Map<String, String> args) {
+        // returns the values in the order of the keys
+        return new ArrayList<String>(args.values());
+    }
+
+}

Added: incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/ListUtils.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/ListUtils.java?rev=1138223&view=auto
==============================================================================
--- incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/ListUtils.java (added)
+++ incubator/isis/trunk/viewer/restful/viewer2/src/main/java/org/apache/isis/viewer/restful/viewer2/util/ListUtils.java Tue Jun 21 22:32:41 2011
@@ -0,0 +1,38 @@
+/*
+ *  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.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public final class ListUtils {
+
+    private ListUtils() {
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <T> List<T> toList(final Object[] objects) {
+        final List<T> list = new ArrayList<T>();
+        for (final Object o : objects) {
+            list.add((T) o);
+        }
+        return list;
+    }
+
+}