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