001 /*
002 * Copyright 2008-2014 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 griffon.core.GriffonApplication;
019
020 import javax.annotation.Nonnull;
021 import javax.annotation.Nullable;
022 import java.util.Arrays;
023 import java.util.Set;
024 import java.util.TreeSet;
025
026 /**
027 * Represents any class in a Griffon application that is related to an artifact.</p>
028 * While {@code GriffonArtifact} points to the real artifact instance, this class points to the meta
029 * information that can be obtained from such artifact.
030 *
031 * @author Steven Devijver (Grails 0.1)
032 * @author Graeme Rocher (Grails 0.1)
033 * @author Andres Almiray
034 */
035 public interface GriffonClass {
036 Set<String> STANDARD_PROPERTIES = new TreeSet<>(
037 Arrays.asList("class", "UIThread", "application", "griffonClass", "log", "artifactType", "metaClass"));
038
039 @Nonnull
040 GriffonApplication getApplication();
041
042 /**
043 * Gets the initial value of the given property on the class.</p>
044 *
045 * @param name The name of the property
046 * @return The initial value
047 */
048 @Nullable
049 Object getPropertyValue(@Nonnull String name);
050
051 /**
052 * Returns true if the class has the specified property.</p>
053 *
054 * @param name The name of the property
055 * @return True if it does
056 */
057 boolean hasProperty(@Nonnull String name);
058
059 /**
060 * Returns the logical name of the class in the application without the trailing convention part if applicable
061 * and without the package name.</p>
062 *
063 * @return the logical name
064 */
065 @Nonnull
066 String getName();
067
068 /**
069 * Returns the short name of the class without package prefix</p>
070 *
071 * @return The short name
072 */
073 @Nonnull
074 String getShortName();
075
076 /**
077 * Returns the full name of the class in the application with the the trailing convention part and with
078 * the package name.</p>
079 *
080 * @return the full name
081 */
082 @Nonnull
083 String getFullName();
084
085 /**
086 * Returns the name of the class as a property name</p>
087 *
088 * @return The property name representation
089 */
090 @Nonnull
091 String getPropertyName();
092
093 /**
094 * Returns the logical name of the class as a property name</p>
095 *
096 * @return The logical property name
097 */
098 @Nonnull
099 String getLogicalPropertyName();
100
101 /**
102 * Returns the name of the property in natural terms (eg. 'lastName' becomes 'Last Name').<p>
103 *
104 * @return The natural property name
105 */
106 @Nonnull
107 String getNaturalName();
108
109 /**
110 * Returns the package name of the class.</p>
111 *
112 * @return the package name
113 */
114 @Nonnull
115 String getPackageName();
116
117 /**
118 * Returns the actual class represented by the GriffonClass</p>
119 *
120 * @return the class
121 */
122 @Nonnull
123 Class<?> getClazz();
124
125 /**
126 * Returns the artifact type represented by the GriffonClass</p>
127 *
128 * @return the artifact type, i.e. "controller".
129 */
130 @Nonnull
131 String getArtifactType();
132
133 /**
134 * Obtains a property value for the given name and type.
135 *
136 * @param name The name
137 * @param type The type
138 * @return The property value
139 */
140 @Nullable
141 <T> T getPropertyValue(@Nonnull String name, @Nonnull Class<T> type);
142 }
|