01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.injection.factory;
16:
17: import org.strecks.util.ReflectHelper;
18:
19: /**
20: * Utility methods used by the <code>InjectionHandlerFactory</code> implementations
21: * @author Phil Zoio
22: */
23: public abstract class AnnotationFactoryUtils {
24:
25: /**
26: * Returns the name of the annotated property if not already supplied
27: */
28: protected static String getAttributeName(String propertyName,
29: String attributeName) {
30: if (attributeName == null || attributeName.length() == 0) {
31: attributeName = propertyName;
32: }
33: return attributeName;
34: }
35:
36: /**
37: * Uses the <code>Class.newInstance()</code> to instantiate the supplied class. Used for injection annotations
38: * which allow for instances of injected object to be automatically created if the current instance in the supplied
39: * context is null
40: */
41: public static Object maybeAutoCreate(Class autoCreateClass) {
42:
43: Object attribute = null;
44:
45: if (autoCreateClass != null) {
46: attribute = ReflectHelper.createInstance(autoCreateClass,
47: Object.class);
48: }
49: return attribute;
50: }
51: }
|