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.service.swagger.internal;
020
021import java.util.Map;
022import java.util.Objects;
023import java.util.function.BiConsumer;
024
025import org.springframework.stereotype.Component;
026
027import org.apache.isis.commons.internal.collections._Maps;
028import org.apache.isis.viewer.restfulobjects.rendering.service.swagger.internal.ValuePropertyFactoryDefault.Factory;
029
030/**
031 * Not used by the framework yet, supposed to be reconsidered in the process of 
032 * <a href="https://issues.apache.org/jira/browse/ISIS-1695">ISIS-1695</a>   
033 * 
034 * @apiNote for now any implementing class must also be discovered/managed by Spring,
035 * that is, it needs a direct- or meta-annotation of type {@link Component}  
036 *   
037 * @since 2.0
038 * 
039 */
040public interface ValuePropertyPlugin {
041
042    // -- CONTRACT
043
044    public static interface ValuePropertyCollector {
045        public void addValueProperty(final Class<?> cls, final ValuePropertyFactoryDefault.Factory factory);
046        public void visitEntries(BiConsumer<Class<?>, ValuePropertyFactoryDefault.Factory> visitor);
047    }
048
049    public static ValuePropertyCollector collector() {
050
051        return new ValuePropertyCollector() {
052
053            final Map<Class<?>, Factory> entries = _Maps.newHashMap();
054
055            @Override
056            public void visitEntries(BiConsumer<Class<?>, Factory> visitor) {
057                Objects.requireNonNull(visitor);
058                entries.forEach(visitor);
059            }
060
061            @Override
062            public void addValueProperty(Class<?> cls, Factory factory) {
063                Objects.requireNonNull(cls);
064                Objects.requireNonNull(factory);
065                entries.put(cls, factory);
066            }
067        };
068
069    }
070
071    // -- INTERFACE
072
073    public void plugin(ValuePropertyCollector collector);
074
075}