Source Code Cross Referenced for AnnotationReader.java in  » Library » Apache-beehive-1.0.2-src » org » apache » beehive » netui » pageflow » internal » 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.netui.pageflow.internal 
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.netui.pageflow.internal;
020:
021:        import org.apache.beehive.netui.pageflow.PageFlowConstants;
022:        import org.apache.beehive.netui.pageflow.internal.annotationreader.AnnotationAttribute;
023:        import org.apache.beehive.netui.pageflow.internal.annotationreader.ProcessedAnnotation;
024:        import org.apache.beehive.netui.pageflow.internal.annotationreader.ProcessedAnnotations;
025:        import org.apache.beehive.netui.pageflow.internal.annotationreader.ProcessedAnnotationParser;
026:        import org.apache.beehive.netui.util.internal.concurrent.InternalConcurrentHashMap;
027:        import org.apache.beehive.netui.util.logging.Logger;
028:
029:        import javax.servlet.ServletContext;
030:        import java.io.InputStream;
031:        import java.io.IOException;
032:        import java.io.Serializable;
033:        import java.lang.reflect.Member;
034:        import java.util.Iterator;
035:        import java.util.Map;
036:
037:        /**
038:         * Utility for reading XML files that describe annotations in classes.  These files are generated during
039:         * Page Flow build.
040:         */
041:        public class AnnotationReader implements  Serializable {
042:            private static final Logger _log = Logger
043:                    .getInstance(AnnotationReader.class);
044:            private static final String CACHE_ATTR = InternalConstants.ATTR_PREFIX
045:                    + "annCache";
046:
047:            private ProcessedAnnotations _annotations;
048:
049:            public static AnnotationReader getAnnotationReader(Class type,
050:                    ServletContext servletContext) {
051:                InternalConcurrentHashMap cache = (InternalConcurrentHashMap) servletContext
052:                        .getAttribute(CACHE_ATTR);
053:
054:                if (cache == null) {
055:                    cache = new InternalConcurrentHashMap();
056:                    servletContext.setAttribute(CACHE_ATTR, cache);
057:                }
058:
059:                AnnotationReader reader = (AnnotationReader) cache.get(type);
060:
061:                if (reader == null) {
062:                    reader = new AnnotationReader(type, servletContext);
063:                    cache.put(type, reader);
064:                }
065:
066:                return reader;
067:            }
068:
069:            private AnnotationReader(Class type, ServletContext servletContext) {
070:                String annotationsXml = PageFlowConstants.PAGEFLOW_MODULE_CONFIG_GEN_DIR
071:                        + "/annotations-"
072:                        + type.getName().replace('.', '-')
073:                        + ".xml";
074:                InputStream in = servletContext
075:                        .getResourceAsStream(annotationsXml);
076:                if (in == null) {
077:                    assert annotationsXml.startsWith("/") : annotationsXml;
078:                    annotationsXml = annotationsXml.substring(1);
079:                    in = Thread.currentThread().getContextClassLoader()
080:                            .getResourceAsStream(annotationsXml);
081:                }
082:
083:                if (in != null) {
084:                    _annotations = ProcessedAnnotationParser.parse(
085:                            annotationsXml, in);
086:                    try {
087:                        in.close();
088:                    } catch (IOException e) {
089:                        _log.error("Could not close input stream for "
090:                                + annotationsXml, e);
091:                    }
092:                }
093:            }
094:
095:            public ProcessedAnnotation getAnnotation(String declarationName,
096:                    String annotationTypeName) {
097:                if (_annotations == null)
098:                    return null;
099:
100:                Map elements = _annotations.getAnnotatedElements();
101:
102:                for (Iterator i = elements.keySet().iterator(); i.hasNext();) {
103:                    String name = (String) i.next();
104:                    if (name.equals(declarationName)) {
105:                        // For now, we can be sure that there's only one element in this array.
106:                        ProcessedAnnotation[] annotations = (ProcessedAnnotation[]) elements
107:                                .get(name);
108:                        assert annotations.length == 1 : annotations.length;
109:                        ProcessedAnnotation pa = annotations[0];
110:                        return pa.getAnnotationName()
111:                                .equals(annotationTypeName) ? pa : null;
112:                    }
113:                }
114:
115:                return null;
116:            }
117:
118:            public ProcessedAnnotation getJpfAnnotation(Member member,
119:                    String annotationTypeName) {
120:                return getAnnotation(member.getName(),
121:                        InternalConstants.ANNOTATION_QUALIFIER
122:                                + annotationTypeName);
123:            }
124:
125:            public ProcessedAnnotation getJpfAnnotation(Class type,
126:                    String annotationTypeName) {
127:                return getAnnotation(type.getName(),
128:                        InternalConstants.ANNOTATION_QUALIFIER
129:                                + annotationTypeName);
130:            }
131:
132:            public static String getStringAttribute(ProcessedAnnotation ann,
133:                    String attrName) {
134:                AnnotationAttribute[] attrs = ann.getAnnotationAttributes();
135:
136:                for (int i = 0; i < attrs.length; i++) {
137:                    AnnotationAttribute attr = attrs[i];
138:
139:                    if (attr.getAttributeName().equals(attrName)) {
140:                        String value = attr.getStringValue();
141:                        assert value != null : "attribute " + attrName
142:                                + " did not have a String value";
143:                        return value;
144:                    }
145:                }
146:
147:                return null;
148:            }
149:
150:            public static ProcessedAnnotation[] getAnnotationArrayAttribute(
151:                    ProcessedAnnotation ann, String attrName) {
152:                AnnotationAttribute[] attrs = ann.getAnnotationAttributes();
153:
154:                for (int i = 0; i < attrs.length; i++) {
155:                    AnnotationAttribute attr = attrs[i];
156:
157:                    if (attr.getAttributeName().equals(attrName)) {
158:                        ProcessedAnnotation[] array = attr
159:                                .getAnnotationValues();
160:                        assert array != null : "attribute " + attrName
161:                                + " did not have an array of annotations.";
162:                        return array;
163:                    }
164:                }
165:
166:                return null;
167:            }
168:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.