001// Generated by delombok at Mon Oct 12 22:51:05 BST 2020
002/*
003 *  Licensed to the Apache Software Foundation (ASF) under one
004 *  or more contributor license agreements.  See the NOTICE file
005 *  distributed with this work for additional information
006 *  regarding copyright ownership.  The ASF licenses this file
007 *  to you under the Apache License, Version 2.0 (the
008 *  "License"); you may not use this file except in compliance
009 *  with the License.  You may obtain a copy of the License at
010 *
011 *        http://www.apache.org/licenses/LICENSE-2.0
012 *
013 *  Unless required by applicable law or agreed to in writing,
014 *  software distributed under the License is distributed on an
015 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 *  KIND, either express or implied.  See the License for the
017 *  specific language governing permissions and limitations
018 *  under the License.
019 */
020package org.apache.isis.viewer.restfulobjects.rendering.service.swagger.internal;
021
022import java.util.Set;
023import org.apache.isis.commons.internal.collections._Sets;
024import org.apache.isis.core.metamodel.spec.ObjectSpecification;
025import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
026
027public abstract class ClassExcluderAbstract implements ClassExcluder {
028    private final Set<String> packageNamesToIgnore = _Sets.newHashSet();
029
030    protected void ignorePackage(final String packageName) {
031        packageNamesToIgnore.add(packageName);
032    }
033
034    @Override
035    public boolean exclude(final ObjectSpecification objectSpec) {
036        if (objectSpec == null) {
037            return false;
038        }
039        return packageNamesToIgnore.stream().anyMatch(packageName -> objectSpec.getCorrespondingClass().getName().startsWith(packageName));
040    }
041
042    @Override
043    public boolean exclude(final ObjectAction objectAction) {
044        final ObjectSpecification returnType = objectAction.getReturnType();
045        if (exclude(returnType)) {
046            return true;
047        }
048        final org.apache.isis.commons.collections.Can<org.apache.isis.core.metamodel.spec.ObjectSpecification> parameterTypes = objectAction.getParameterTypes();
049        for (ObjectSpecification parameterType : parameterTypes) {
050            if (exclude(parameterType)) {
051                return true;
052            }
053        }
054        return false;
055    }
056}