Source Code Cross Referenced for EventAdaptor.java in  » Library » Apache-beehive-1.0.2-src » org » apache » beehive » controls » runtime » generator » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache beehive 1.0.2 src » org.apache.beehive.controls.runtime.generator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         *
017:         * $Header:$
018:         */
019:        package org.apache.beehive.controls.runtime.generator;
020:
021:        import java.util.HashMap;
022:
023:        import com.sun.mirror.type.TypeMirror;
024:        import com.sun.mirror.declaration.TypeParameterDeclaration;
025:
026:        /**
027:         * The EventAdaptor class represents the generated class that is necessary to route
028:         * events for a EventSet onto implemented EventHandlers on an implementation class.
029:         */
030:        public class EventAdaptor {
031:            /**
032:             * Constructs a new EventAdaptor for events declared on an EventSet
033:             */
034:            public EventAdaptor(AptEventField eventField, AptEventSet eventSet) {
035:                _eventField = eventField;
036:                _eventSet = eventSet;
037:                _className = initClassName();
038:            }
039:
040:            /**
041:             * Computes a unique adaptor class name
042:             */
043:            private String initClassName() {
044:                StringBuffer sb = new StringBuffer();
045:                String fieldName = _eventField.getName();
046:                String setName = _eventSet.getClassName();
047:                sb.append(Character.toUpperCase(fieldName.charAt(0)));
048:                if (fieldName.length() > 1)
049:                    sb.append(fieldName.substring(1));
050:                sb.append(setName.substring(setName.lastIndexOf('.') + 1));
051:                sb.append("EventAdaptor");
052:                return sb.toString();
053:            }
054:
055:            /**
056:             * Returns the name of the generated class for this adaptor.
057:             */
058:            public String getClassName() {
059:                return _className;
060:            }
061:
062:            /**
063:             * Returns the name of the generated class for this adaptor, including any formal type
064:             * declarations from the associate event set.
065:             */
066:            public String getFormalClassName() {
067:                StringBuffer sb = new StringBuffer(_className);
068:                sb.append(_eventSet.getFormalTypeParameters());
069:                return sb.toString();
070:            }
071:
072:            /**
073:             * Returns the event field associated with this event adaptor
074:             */
075:            public AptEventField getEventField() {
076:                return _eventField;
077:            }
078:
079:            /**
080:             * Returns the EventSet associated with this Adaptor
081:             */
082:            public AptEventSet getEventSet() {
083:                return _eventSet;
084:            }
085:
086:            /**
087:             * Adds a new EventHandler for a Event to the EventAdaptor
088:             */
089:            public void addHandler(AptEvent event, AptMethod eventHandler) {
090:                assert event.getEventSet() == _eventSet;
091:                _handlerMap.put(event, eventHandler);
092:            }
093:
094:            /**
095:             * Returns true if there is an EventHandler for ControlEvent on this EventAdaptor
096:             */
097:            public boolean hasHandler(AptEvent event) {
098:                return _handlerMap.containsKey(event);
099:            }
100:
101:            /**
102:             * Returns the EventHandler for a ControlEvent on this EventAdaptor
103:             */
104:            public AptMethod getHandler(AptEvent event) {
105:                return _handlerMap.get(event);
106:            }
107:
108:            /**
109:             * Returns any formal type parameter declaration for EventSet interface associated with 
110:             * the adaptor class.  This will bind the formal types of the interface based on any type 
111:             * binding from the event field declaration
112:             */
113:            public String getEventSetBinding() {
114:                // Get the type bindings for the associated event field.
115:                HashMap<String, TypeMirror> typeBinding = _eventField
116:                        .getTypeBindingMap();
117:
118:                StringBuffer sb = new StringBuffer();
119:                boolean isFirst = true;
120:                for (TypeParameterDeclaration tpd : _eventSet.getDeclaration()
121:                        .getFormalTypeParameters()) {
122:                    if (isFirst) {
123:                        sb.append("<");
124:                        isFirst = false;
125:                    } else
126:                        sb.append(", ");
127:
128:                    // Map from the declared formal type name to the bound type name
129:                    // If no map entry exists (i.e. not bindings were specified on the field
130:                    // declaration, then the implied binding is to Object.class
131:                    String typeName = tpd.getSimpleName();
132:                    if (typeBinding.containsKey(typeName))
133:                        sb.append(typeBinding.get(tpd.getSimpleName()));
134:                    else
135:                        sb.append("java.lang.Object");
136:                }
137:                if (!isFirst)
138:                    sb.append(">");
139:
140:                return sb.toString();
141:            }
142:
143:            private String _className;
144:            private AptEventField _eventField;
145:            private AptEventSet _eventSet;
146:            private HashMap<AptEvent, AptMethod> _handlerMap = new HashMap<AptEvent, AptMethod>();
147:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.