KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.apache.beehive.controls.runtime.generator;
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 com.sun.mirror.declaration.MethodDeclaration;
21 import com.sun.mirror.type.VoidType;
22
23 import org.apache.beehive.controls.runtime.generator.apt.TwoPhaseAnnotationProcessor;
24
25 /**
26  * The AptEvent class represents a control Property where the event attributes
27  * are derived using APT metadata
28  */

29 public class AptEvent extends AptMethod
30 {
31     /**
32      * Constructs a new AptEvent instance from APT metadata
33      * @param eventSet the declaring EventSet
34      * @param eventDecl the event annotation type element declaration
35      */

36     public AptEvent(AptEventSet eventSet, MethodDeclaration eventDecl, TwoPhaseAnnotationProcessor ap)
37     {
38         super(eventDecl, ap);
39         _eventSet = eventSet;
40         _eventDecl = eventDecl;
41
42         //
43
// If the event is in multicast event set but does not return 'void', then generate
44
// an error. Only unicast events can have a return value, to avoid ambiguity over
45
// which listener gets to provide the value.
46
//
47
if (!eventSet.isUnicast() && !(eventDecl.getReturnType() instanceof VoidType))
48         {
49             ap.printError( eventDecl, "eventset.illegal.multicast" );
50         }
51     }
52
53     /**
54      * Returns the name of the static field that holds the name of this method.
55      */

56     public String JavaDoc getMethodField()
57     {
58         //
59
// Both the event set and event name must be used for the generated field to avoid
60
// conflicts between same-named events in different event sets.
61
//
62
StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
63         sb.append("_");
64         sb.append(_eventSet.getShortName());
65         sb.append("_");
66         sb.append(getName());
67         int methodIndex = getIndex();
68         if (methodIndex != -1)
69             sb.append(methodIndex);
70         sb.append("Event");
71         return sb.toString();
72     }
73
74     /**
75      * Returns the EventSet associated with the event
76      */

77     public AptEventSet getEventSet() { return _eventSet; }
78
79     MethodDeclaration _eventDecl;
80     private AptEventSet _eventSet;
81 }
82
Popular Tags