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.facetapi;
021
022import java.util.List;
023
024import org.apache.isis.applib.filter.Filter;
025
026/**
027 * Anything in the metamodel (which also includes peers in the reflector) that
028 * can be extended.
029 */
030public interface FacetHolder {
031
032    /**
033     * Get the list of all facet <i>types</i> that are supported by objects of
034     * this specification.
035     */
036    Class<? extends Facet>[] getFacetTypes();
037
038    /**
039     * Get the facet of the specified type (as per the type it reports from
040     * {@link Facet#facetType()}).
041     */
042    <T extends Facet> T getFacet(Class<T> cls);
043
044    /**
045     * Whether there is a facet registered of the specified type.
046     */
047    boolean containsFacet(Class<? extends Facet> facetType);
048
049    /**
050     * Whether there is a facet registered of the specified type that is not a
051     * {@link Facet#isNoop() no-op}.
052     * 
053     * <p>
054     * Convenience; saves having to {@link #getFacet(Class)} and then check if
055     * <tt>null</tt> and not a no-op.
056     */
057    boolean containsDoOpFacet(Class<? extends Facet> facetType);
058
059
060    /**
061     * Returns all {@link Facet}s matching the specified {@link FacetFilter}.
062     * 
063     * @param filter
064     * @return
065     */
066    List<Facet> getFacets(Filter<Facet> filter);
067
068    /**
069     * Adds the facet, extracting its {@link Facet#facetType() type} as the key.
070     * 
071     * <p>
072     * If there are any facet of the same type, they will be overwritten
073     * <i>provided</i> that either the {@link Facet} specifies to
074     * {@link Facet#alwaysReplace() always replace} or if the existing
075     * {@link Facet} is a {@link Facet#isNoop() no-op}.
076     */
077    void addFacet(Facet facet);
078
079    /**
080     * Adds the {@link MultiTypedFacet multi-typed facet}, extracting each of
081     * its {@link MultiTypedFacet#facetTypes() types} as keys.
082     * 
083     * <p>
084     * If there are any facet of the same type, they will be overwritten
085     * <i>provided</i> that either the {@link Facet} specifies to
086     * {@link Facet#alwaysReplace() always replace} or if the existing
087     * {@link Facet} is a {@link Facet#isNoop() no-op}.
088     */
089    void addFacet(MultiTypedFacet facet);
090
091    /**
092     * Remove the facet whose type is that reported by {@link Facet#facetType()}
093     * .
094     */
095    void removeFacet(Facet facet);
096
097    /**
098     * Remove the facet of the specified type.
099     */
100    void removeFacet(Class<? extends Facet> facetType);
101
102}