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.traverser; 021 022import static org.apache.isis.core.commons.ensure.Ensure.ensureThatState; 023import static org.hamcrest.CoreMatchers.is; 024import static org.hamcrest.CoreMatchers.notNullValue; 025 026import java.lang.reflect.Method; 027import java.util.List; 028 029import org.apache.isis.core.metamodel.spec.ObjectSpecification; 030import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi; 031import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpiAware; 032 033public class SpecificationTraverserDefault implements SpecificationTraverser, SpecificationLoaderSpiAware { 034 035 private SpecificationLoaderSpi specificationLoaderSpi; 036 037 // //////////////////////////////////////////////////////////////////// 038 // init, shutdown 039 // //////////////////////////////////////////////////////////////////// 040 041 @Override 042 public void init() { 043 ensureThatState(specificationLoaderSpi, is(notNullValue())); 044 } 045 046 @Override 047 public void shutdown() { 048 } 049 050 // //////////////////////////////////////////////////////////////////// 051 // Traverse API 052 // //////////////////////////////////////////////////////////////////// 053 054 /** 055 * Traverses the return types of each method. 056 * 057 * <p> 058 * It's possible for there to be multiple return types: the generic type, 059 * and the parameterized type. 060 */ 061 @Override 062 public void traverseTypes(final Method method, final List<Class<?>> discoveredTypes) { 063 final TypeExtractorMethodReturn returnTypes = new TypeExtractorMethodReturn(method); 064 for (final Class<?> returnType : returnTypes) { 065 discoveredTypes.add(returnType); 066 } 067 } 068 069 /** 070 * Does nothing. 071 */ 072 @Override 073 public void traverseReferencedClasses(final ObjectSpecification noSpec, final List<Class<?>> discoveredTypes) throws ClassNotFoundException { 074 } 075 076 // //////////////////////////////////////////////////////////////////// 077 // Dependencies (due to *Aware) 078 // //////////////////////////////////////////////////////////////////// 079 080 public SpecificationLoaderSpi getSpecificationLoaderSpi() { 081 return specificationLoaderSpi; 082 } 083 084 @Override 085 public void setSpecificationLoaderSpi(final SpecificationLoaderSpi specificationLoader) { 086 this.specificationLoaderSpi = specificationLoader; 087 } 088 089}