| 
001 /*002  * Copyright 2008-2015 the original author or authors.
 003  *
 004  * Licensed under the Apache License, Version 2.0 (the "License");
 005  * you may not use this file except in compliance with the License.
 006  * You may obtain a copy of the License at
 007  *
 008  *     http://www.apache.org/licenses/LICENSE-2.0
 009  *
 010  * Unless required by applicable law or agreed to in writing, software
 011  * distributed under the License is distributed on an "AS IS" BASIS,
 012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 013  * See the License for the specific language governing permissions and
 014  * limitations under the License.
 015  */
 016 package griffon.core.artifact;
 017
 018 import javax.annotation.Nonnull;
 019 import javax.annotation.Nullable;
 020 import java.util.Map;
 021
 022 /**
 023  * The ArtifactHandler interface's purpose is to allow the analysis of conventions within a Griffon application.<p>
 024  * An artifact is represented by the GriffonClass interface and this interface provides methods that allow artifacts to
 025  * be identified, created and initialized.
 026  *
 027  * @author Andres Almiray
 028  */
 029 public interface ArtifactHandler<A extends GriffonArtifact> {
 030     @Nonnull
 031     Class<A> getArtifactType();
 032
 033     /**
 034      * Get the type of artifact this handler processes.
 035      *
 036      * @return the type of artifacts this handler can handle, e.g. 'service'
 037      */
 038     @Nonnull
 039     String getType();
 040
 041     /**
 042      * Get the trailing suffix that identifies the artifact.<p>
 043      * May be empty but non-null.
 044      *
 045      * @return the trailing name suffix (if any), e.g. 'Service'
 046      */
 047     @Nonnull
 048     String getTrailing();
 049
 050     /**
 051      * Returns true if the target Class is a class artifact
 052      * handled by this object.
 053      *
 054      * @param clazz a Class instance
 055      * @return true if this handler is capable of handling the artifact class, false otherwise.
 056      */
 057     boolean isArtifact(@Nonnull Class<A> clazz);
 058
 059     /**
 060      * Returns true if the target GriffonClass is a class artifact
 061      * handled by this object.
 062      *
 063      * @param clazz a GriffonClass instance
 064      * @return true if this handler is capable of handling the clazz parameter, false otherwise.
 065      */
 066     boolean isArtifact(@Nonnull GriffonClass clazz);
 067
 068     /**
 069      * Initializes the handler with a collection of all available
 070      * classes this handler can process.<p>
 071      * This is a good time to pre-emptively instantiate beans or
 072      * perform additional checks on artifacts.
 073      *
 074      * @param classes an array of all classes this handler should manage
 075      */
 076     void initialize(@Nonnull Class<A>[] classes);
 077
 078     /**
 079      * Returns the set of all artifact classes this handler manages.
 080      *
 081      * @return an array of all GriffonClasses managed by this handler. Never returns null.
 082      */
 083     @Nonnull
 084     GriffonClass[] getClasses();
 085
 086     /**
 087      * Finds an artifact by its property name.<p>
 088      * Examples: findClassfor("fooService") returns an artifact class
 089      * that can handle FooService.<p>
 090      * <p>
 091      * Should {@code propertyName} contain any dots then the portion
 092      * after the last dot will be considered only.
 093      *
 094      * @param propertyName the property representation of an artifact, e.g. 'fooService'
 095      * @return a GriffonClass instance if there's a match, null otherwise.
 096      */
 097     @Nullable
 098     GriffonClass findClassFor(@Nonnull String propertyName);
 099
 100     /**
 101      * Finds an artifact if the target {@code clazz} is handled by this
 102      * ArtifactHandler.<p>
 103      *
 104      * @param clazz a class object, i.e, BookController
 105      * @return a GriffonClass that can handle the target class or null
 106      * if the clazz is not handled by this ArtifactHandler.
 107      */
 108     @Nullable
 109     GriffonClass getClassFor(@Nonnull Class<A> clazz);
 110
 111     /**
 112      * Finds an artifact by class name if it represents a class that
 113      * is handled by this ArtifactHandler.<p>
 114      *
 115      * @param fqnClassName a full qualified class name, i.e, "book.BookController"
 116      * @return a GriffonClass that can handle the target class or null
 117      * if the clazz is not handled by this ArtifactHandler.
 118      */
 119     @Nullable
 120     GriffonClass getClassFor(@Nonnull String fqnClassName);
 121
 122     @Nonnull
 123     GriffonClass newGriffonClassInstance(@Nonnull Class<A> clazz);
 124
 125     @Nonnull
 126     Map<String, GriffonClass> getClassesByName();
 127 }
 |