01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.controls.runtime.bean;
20:
21: import java.lang.reflect.AnnotatedElement;
22: import org.apache.beehive.controls.api.context.ControlBeanContext;
23: import org.apache.beehive.controls.api.properties.PropertyMap;
24: import org.apache.beehive.controls.api.properties.AnnotatedElementMap;
25: import org.apache.beehive.controls.api.versioning.VersionRequired;
26: import org.apache.beehive.controls.api.versioning.Version;
27:
28: /**
29: * The ClientInitializer class is an abstract base class that all generated Control
30: * client initializer classes will extend. It provides common utilities and supporting code
31: * for initialization, and has a shared package relationship with the base ControlBean
32: * class providing access to internals not available in a more general context.
33: */
34: abstract public class ClientInitializer {
35: /**
36: * Enforces the VersionRequired annotation at runtime (called when an instance of a control is annotated
37: * with VersionRequired). Throws a ControlException if enforcement fails.
38: *
39: * @param versionRequired the value of the VersionRequired annotation on a control field
40: */
41: protected static void enforceVersionRequired(ControlBean control,
42: VersionRequired versionRequired) {
43: Class controlIntf = ControlUtils
44: .getMostDerivedInterface(control.getControlInterface());
45:
46: Version versionPresent = (Version) controlIntf
47: .getAnnotation(Version.class);
48: if (versionPresent != null) {
49: ControlBean.enforceVersionRequired(controlIntf
50: .getCanonicalName(), versionPresent,
51: versionRequired);
52: }
53: }
54:
55: /**
56: * Returns the annotation map for the specified element.
57: */
58: public static PropertyMap getAnnotationMap(ControlBeanContext cbc,
59: AnnotatedElement annotElem) {
60: if (cbc == null)
61: return new AnnotatedElementMap(annotElem);
62:
63: return cbc.getAnnotationMap(annotElem);
64: }
65: }
|