Source Code Cross Referenced for Assembler.java in  » Library » Apache-beehive-1.0.2-src » org » apache » beehive » controls » runtime » assembly » 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.assembly 
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.assembly;
020:
021:        import org.apache.beehive.controls.api.bean.ControlImplementation;
022:        import org.apache.beehive.controls.api.assembly.ControlAssemblyContext;
023:        import org.apache.beehive.controls.api.assembly.ControlAssemblyException;
024:        import org.apache.beehive.controls.api.assembly.ControlAssembler;
025:        import org.apache.beehive.controls.api.assembly.DefaultControlAssembler;
026:
027:        import java.io.File;
028:        import java.io.IOException;
029:        import java.util.Map;
030:        import java.util.Set;
031:
032:        /**
033:         * Helper class to execute assembly logic.
034:         */
035:        public class Assembler {
036:            /**
037:             * Executes basic assembly algorithm.  For each control type & impl specified, query each impl for the presence
038:             * of an assembler -- for each assembler present, build the specified ControlAssemblyContext implementation,
039:             * create an instance of the assembler and execute it.
040:             *
041:             * @param moduleRoot dir root of the module
042:             * @param moduleName name of the module
043:             * @param srcOutputRoot dir where assemblers can output source files
044:             * @param factoryName name of the ControlAssemblyContext factory to use
045:             * @param controlTypeToImpl map of control type name to control impl for all control types to be assembled in this module
046:             * @param controlTypeToClients map of control type name to a set of control clients (in this module) that use this type
047:             * @param cl classloader used to load factories and assemblers
048:             * @throws ControlAssemblyException
049:             * @throws IOException
050:             */
051:            public static void assemble(File moduleRoot, String moduleName,
052:                    File srcOutputRoot, String factoryName,
053:                    Map<String, String> controlTypeToImpl,
054:                    Map<String, Set<String>> controlTypeToClients,
055:                    ClassLoader cl) throws ControlAssemblyException,
056:                    IOException {
057:                if (!moduleRoot.exists() || !srcOutputRoot.exists())
058:                    throw new IOException("Directories " + moduleRoot + " or "
059:                            + srcOutputRoot + " don't exist!");
060:
061:                if (factoryName == null)
062:                    throw new ControlAssemblyException(
063:                            "Missing context factory names");
064:
065:                if (cl == null)
066:                    throw new ControlAssemblyException(
067:                            "Must specify a classloader");
068:
069:                ClassLoader origCL = Thread.currentThread()
070:                        .getContextClassLoader();
071:                Thread.currentThread().setContextClassLoader(cl);
072:
073:                try {
074:                    // Create the requested ControlAssemblyContext.Factory
075:                    Class factoryClass = cl.loadClass(factoryName);
076:                    ControlAssemblyContext.Factory factory = (ControlAssemblyContext.Factory) factoryClass
077:                            .newInstance();
078:
079:                    // Iterate over control types
080:                    Set<String> controlTypes = controlTypeToImpl.keySet();
081:                    for (String ct : controlTypes) {
082:                        // Search for applicable ControlAssemblers as specified on the control impls
083:                        String cImpl = controlTypeToImpl.get(ct);
084:                        Class cImplClass = cl.loadClass(cImpl);
085:
086:                        ControlImplementation a = (ControlImplementation) cImplClass
087:                                .getAnnotation(ControlImplementation.class);
088:                        if (a == null)
089:                            throw new ControlAssemblyException(
090:                                    "Control implementation class="
091:                                            + cImpl
092:                                            + " missing ControlImplementation annotation");
093:
094:                        // For each non-default ControlAssembler, create one and call it.
095:                        Class<? extends ControlAssembler> assemblerClass = a
096:                                .assembler();
097:                        if (!assemblerClass
098:                                .equals(DefaultControlAssembler.class)) {
099:                            ControlAssembler assembler = assemblerClass
100:                                    .newInstance();
101:                            Set<String> clients = controlTypeToClients.get(ct);
102:                            ControlAssemblyContext cac = factory.newInstance(cl
103:                                    .loadClass(ct), null, clients, moduleRoot,
104:                                    moduleName, srcOutputRoot);
105:                            assembler.assemble(cac);
106:                        }
107:                    }
108:                } catch (ControlAssemblyException cae) {
109:                    // just rethrow ControlAssemblyExceptions, which will typically come from user-provided assemblers.
110:                    throw cae;
111:                } catch (Throwable t) {
112:                    // Not expecting any throwables other than ControlAssemblyExceptions, so consider them as
113:                    // unexpected infrastructure issues and wrap them in a CAE.
114:                    throw new ControlAssemblyException(
115:                            "Assembly infrastructure exception", t);
116:                } finally {
117:                    Thread.currentThread().setContextClassLoader(origCL);
118:                }
119:            }
120:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.