KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > runtime > generator > AptContextField


1 package org.apache.beehive.controls.runtime.generator;
2
3 /*
4  * Copyright 2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * $Header:$
19  */

20
21 import com.sun.mirror.declaration.FieldDeclaration;
22 import com.sun.mirror.type.InterfaceType;
23 import com.sun.mirror.type.TypeMirror;
24 import org.apache.beehive.controls.runtime.generator.apt.TwoPhaseAnnotationProcessor;
25
26 /**
27  * The AptContextField class contains information about a field referring to a contextual
28  * service with an AptControlImplementation class.
29  */

30 public class AptContextField extends AptEventField
31 {
32     /**
33      * Base constructor, protected so only a custom subclass can invoke
34      * @param controlImpl the declaring ControlImplementation
35      */

36     public AptContextField(AptControlImplementation controlImpl, FieldDeclaration fieldDecl,
37                            TwoPhaseAnnotationProcessor ap)
38     {
39         super(fieldDecl);
40         _controlImpl = controlImpl;
41         _ap = ap;
42     };
43
44     /**
45      * Initializes a ControlInterface associated with this context field. Because
46      * contextual services can expose both APIs and events, they are similar to controls.
47      */

48     protected AptControlInterface initControlInterface()
49     {
50         TypeMirror fieldType = _fieldDecl.getType();
51         if (! (fieldType instanceof InterfaceType))
52         {
53             _ap.printError( _fieldDecl, "context.field.badinterface" );
54             return null;
55         }
56
57         //
58
// For contextual services, the declared type of the field is always the public
59
// interface for the contextual service.
60
//
61
return new AptControlInterface(((InterfaceType)_fieldDecl.getType()).getDeclaration(),
62                                        _ap);
63     }
64
65     private AptControlImplementation _controlImpl;
66     private TwoPhaseAnnotationProcessor _ap;
67 }
68
Popular Tags