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.domainobjects;
020
021import org.apache.isis.core.metamodel.services.ServiceUtil;
022import org.apache.isis.core.metamodel.spec.ManagedObject;
023import org.apache.isis.viewer.restfulobjects.applib.Rel;
024import org.apache.isis.viewer.restfulobjects.applib.RepresentationType;
025import org.apache.isis.viewer.restfulobjects.rendering.LinkBuilder;
026
027public class DomainServiceLinkTo extends DomainObjectLinkTo {
028    private String serviceId;
029
030    @Override
031    public ObjectAdapterLinkTo with(final ManagedObject objectAdapter) {
032        serviceId = ServiceUtil.idOfAdapter(objectAdapter);
033        return super.with(objectAdapter);
034    }
035
036    @Override
037    public LinkBuilder builder(final Rel rel) {
038        final LinkBuilder linkBuilder = LinkBuilder.newBuilder(resourceContext,
039                relElseDefault(rel).andParam("serviceId", serviceId),
040                RepresentationType.DOMAIN_OBJECT,
041                linkRef(new StringBuilder()).toString());
042        linkBuilder.withTitle(objectAdapter.titleString());
043        return linkBuilder;
044    }
045
046
047    @Override
048    protected StringBuilder linkRef(StringBuilder buf) {
049        return buf.append("services/").append(serviceId);
050    }
051
052    @Override
053    protected Rel defaultRel() {
054        return Rel.SERVICE;
055    }
056
057
058}