KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > runtime > bean > ClientInitializer


1 package org.apache.beehive.controls.runtime.bean;
2 /*
3  * Copyright 2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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
20 import java.lang.reflect.AnnotatedElement JavaDoc;
21 import org.apache.beehive.controls.api.context.ControlBeanContext;
22 import org.apache.beehive.controls.api.properties.PropertyMap;
23 import org.apache.beehive.controls.api.properties.AnnotatedElementMap;
24 import org.apache.beehive.controls.api.versioning.VersionRequired;
25 import org.apache.beehive.controls.api.versioning.Version;
26
27 /**
28  * The ClientInitializer class is an abstract base class that all generated Control
29  * client initializer classes will extend. It provides common utilities and supporting code
30  * for initialization, and has a shared package relationship with the base ControlBean
31  * class providing access to internals not available in a more general context.
32  */

33 abstract public class ClientInitializer
34 {
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, VersionRequired versionRequired )
42     {
43         Class JavaDoc controlIntf = control.getMostDerivedInterface( control.getControlInterface() );
44
45         Version versionPresent = (Version) controlIntf.getAnnotation( Version.class );
46         if ( versionPresent != null )
47         {
48             ControlBean.enforceVersionRequired( controlIntf.getCanonicalName(), versionPresent, versionRequired );
49         }
50     }
51
52     /**
53      * Returns the annotation map for the specified element.
54      */

55     public static PropertyMap getAnnotationMap(ControlBeanContext cbc, AnnotatedElement JavaDoc annotElem)
56     {
57         if ( cbc == null )
58             return new AnnotatedElementMap(annotElem);
59
60         return cbc.getAnnotationMap(annotElem);
61     }
62 }
63
Popular Tags