01 /*
02 * Copyright 2010-2013 the original author or authors.
03 *
04 * Licensed under the Apache License, Version 2.0 (the "License");
05 * you may not use this file except in compliance with the License.
06 * You may obtain a copy of the License at
07 *
08 * http://www.apache.org/licenses/LICENSE-2.0
09 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.codehaus.griffon.runtime.core;
17
18 import griffon.core.GriffonApplication;
19 import griffon.core.GriffonServiceClass;
20 import griffon.util.GriffonClassUtils;
21 import groovy.lang.Closure;
22
23 import java.lang.reflect.Method;
24 import java.util.LinkedHashSet;
25 import java.util.Set;
26
27 /**
28 * @author Andres Almiray
29 * @since 0.9.1
30 */
31 public class DefaultGriffonServiceClass extends DefaultGriffonClass implements GriffonServiceClass {
32 protected final Set<String> serviceCache = new LinkedHashSet<String>();
33
34 public DefaultGriffonServiceClass(GriffonApplication app, Class<?> clazz) {
35 super(app, clazz, TYPE, TRAILING);
36 }
37
38 public void resetCaches() {
39 super.resetCaches();
40 serviceCache.clear();
41 }
42
43 public String[] getServiceNames() {
44 if (serviceCache.isEmpty()) {
45 for (String propertyName : getPropertiesWithFields()) {
46 if (!STANDARD_PROPERTIES.contains(propertyName) &&
47 !serviceCache.contains(propertyName) &&
48 !GriffonClassUtils.isEventHandler(propertyName) &&
49 getPropertyValue(propertyName, Closure.class) != null) {
50 serviceCache.add(propertyName);
51 }
52 }
53 for (Method method : getClazz().getMethods()) {
54 String methodName = method.getName();
55 if (!serviceCache.contains(methodName) &&
56 GriffonClassUtils.isPlainMethod(method) &&
57 !GriffonClassUtils.isEventHandler(methodName)) {
58 serviceCache.add(methodName);
59 }
60 }
61 }
62
63 return serviceCache.toArray(new String[serviceCache.size()]);
64 }
65 }
|