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 */
019
020package org.apache.isis.core.metamodel.specloader.specimpl.objectlist;
021
022import java.util.Collections;
023import java.util.List;
024import java.util.Properties;
025
026import org.apache.isis.applib.profiles.Localization;
027import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
028import org.apache.isis.core.metamodel.facetapi.FacetUtil;
029import org.apache.isis.core.metamodel.facets.typeof.TypeOfFacetDefaultToObject;
030import org.apache.isis.core.metamodel.spec.ActionType;
031import org.apache.isis.core.metamodel.spec.FreeStandingList;
032import org.apache.isis.core.metamodel.spec.ObjectSpecification;
033import org.apache.isis.core.metamodel.spec.SpecificationContext;
034import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
035import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
036import org.apache.isis.core.metamodel.spec.feature.ObjectMemberContext;
037import org.apache.isis.core.metamodel.specloader.specimpl.ObjectSpecificationAbstract;
038
039/**
040 * A custom {@link ObjectSpecification} that is designed to treat the
041 * {@link FreeStandingList} class as a "standalone" collection.
042 */
043public class ObjectSpecificationForFreeStandingList extends ObjectSpecificationAbstract {
044
045    /**
046     * Used as {@link #getShortIdentifier()}, {@link #getName()} and
047     * {@link #getPluralName()}.
048     */
049    private static final String NAME = "Instances";
050    private static final String DESCRIBED_AS = "Typed instances";
051    private static final String ICON_NAME = "instances";
052
053    public ObjectSpecificationForFreeStandingList(
054            final SpecificationContext specificationContext,
055            final ObjectMemberContext objectMemberContext) {
056        super(FreeStandingList.class, NAME, specificationContext, objectMemberContext);
057    }
058
059    // /////////////////////////////////////////////////////////
060    // Introspection
061    // /////////////////////////////////////////////////////////
062
063    @Override
064    public void introspectTypeHierarchyAndMembers() {
065        updateSuperclass(Object.class);
066
067        addFacet(new CollectionFacetForFreeStandingList(this));
068        addFacet(new TypeOfFacetDefaultToObject(this, getSpecificationLookup()) {
069        });
070
071        // ObjectList specific
072        FacetUtil.addFacet(new NamedFacetForObjectList(NAME, this));
073        FacetUtil.addFacet(new PluralFacetForObjectList(NAME, this));
074        FacetUtil.addFacet(new DescribedAsFacetForObjectList(DESCRIBED_AS, this));
075        // don't install anything for NotPersistableFacet
076    }
077
078    // /////////////////////////////////////////////////////////
079    // Override facets
080    // /////////////////////////////////////////////////////////
081
082    // /////////////////////////////////////////////////////
083    // Service
084    // /////////////////////////////////////////////////////
085
086    /**
087     * No-op.
088     * 
089     * <p>
090     * Review: is this ever called for an instance of this class? If not, then
091     * no need to override.
092     */
093    @Override
094    public void markAsService() {
095    }
096
097    @Override
098    public boolean isService() {
099        return false;
100    }
101
102    // /////////////////////////////////////////////////////
103    // Associations
104    // /////////////////////////////////////////////////////
105
106    /**
107     * Review: is this ever called for an instance of this class? If not, then
108     * no need to override.
109     */
110    @Override
111    public ObjectAssociation getAssociation(final String id) {
112        return null;
113    }
114
115    // /////////////////////////////////////////////////////
116    // Title and Icon
117    // /////////////////////////////////////////////////////
118
119    @Override
120    public String getTitle(final ObjectAdapter object, final Localization localization) {
121        return ((FreeStandingList) object.getObject()).titleString();
122    }
123
124    @Override
125    public String getIconName(final ObjectAdapter object) {
126        return ICON_NAME;
127    }
128
129    // /////////////////////////////////////////////////////
130    // Object Actions
131    // /////////////////////////////////////////////////////
132
133    /**
134     * Review: is it necessary to override for this subclass?
135     */
136    @Override
137    public ObjectAction getObjectAction(final ActionType type, final String id, final List<ObjectSpecification> parameters) {
138        return null;
139    }
140
141    /**
142     * Review: is it necessary to override for this subclass?
143     */
144    @Override
145    public ObjectAction getObjectAction(final ActionType type, final String id) {
146        return null;
147    }
148
149    /**
150     * Review: is it necessary to override for this subclass?
151     */
152    @Override
153    public ObjectAction getObjectAction(final String nameParmsIdentityString) {
154        return null;
155    }
156
157    // /////////////////////////////////////////////////////
158    // Service Actions
159    // /////////////////////////////////////////////////////
160
161    /**
162     * Review: is it necessary to override for this subclass?
163     */
164    @Override
165    public List<ObjectAction> getServiceActionsReturning(final List<ActionType> type) {
166        return Collections.emptyList();
167    }
168
169
170}