001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.isis.viewer.restfulobjects.rendering.domaintypes; 020 021import org.apache.isis.core.metamodel.spec.ObjectSpecification; 022import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation; 023import org.apache.isis.viewer.restfulobjects.applib.LinkRepresentation; 024import org.apache.isis.viewer.restfulobjects.applib.Rel; 025import org.apache.isis.viewer.restfulobjects.applib.RepresentationType; 026import org.apache.isis.viewer.restfulobjects.rendering.IResourceContext; 027import org.apache.isis.viewer.restfulobjects.rendering.LinkFollowSpecs; 028import org.apache.isis.viewer.restfulobjects.rendering.ReprRendererAbstract; 029 030public class TypeActionResultReprRenderer extends ReprRendererAbstract<TypeActionResultReprRenderer, ObjectSpecification> { 031 032 private ObjectSpecification objectSpecification; 033 private LinkRepresentation selfLink; 034 private Object value; 035 036 public TypeActionResultReprRenderer(final IResourceContext resourceContext, final LinkFollowSpecs linkFollower, final JsonRepresentation representation) { 037 super(resourceContext, linkFollower, RepresentationType.TYPE_ACTION_RESULT, representation); 038 } 039 040 @Override 041 public TypeActionResultReprRenderer with(final ObjectSpecification objectSpecification) { 042 this.objectSpecification = objectSpecification; 043 return cast(this); 044 } 045 046 public TypeActionResultReprRenderer withValue(final Object value) { 047 this.value = value; 048 return this; 049 } 050 051 public TypeActionResultReprRenderer withSelf(final JsonRepresentation link) { 052 return withLink(Rel.SELF, link); 053 } 054 055 @Override 056 public JsonRepresentation render() { 057 if (includesSelf && selfLink != null) { 058 getLinks().arrayAdd(selfLink); 059 } 060 061 if (value != null) { 062 representation.mapPut("value", value); 063 } 064 getExtensions(); 065 066 return representation; 067 } 068 069 protected void putExtensionsIfService() { 070 getExtensions().mapPut("isService", objectSpecification.isManagedBean()); 071 } 072 073}