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