Source Code Cross Referenced for MLETTask.java in  » Library » Apache-commons-modeler-2.0.1-src » org » apache » commons » modeler » ant » 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 commons modeler 2.0.1 src » org.apache.commons.modeler.ant 
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:
018:        package org.apache.commons.modeler.ant;
019:
020:        import java.net.URL;
021:        import java.util.ArrayList;
022:        import java.util.List;
023:
024:        import javax.management.JMException;
025:        import javax.management.MBeanServer;
026:        import javax.management.MBeanServerFactory;
027:        import javax.management.ObjectName;
028:        import javax.management.loading.MLet;
029:
030:        import org.apache.commons.logging.Log;
031:        import org.apache.commons.logging.LogFactory;
032:        import org.apache.tools.ant.BuildException;
033:        import org.apache.tools.ant.Task;
034:
035:        /**
036:         * Load an MBean. The syntax is similar with the <mlet>, with few
037:         * ant-specific extensions.
038:         *
039:         * A separate classloader can be used, the mechanism is similar with
040:         * what taskdef is using.
041:         *
042:         * Note that mlet will use the arguments in the constructor.
043:         *
044:         *
045:         */
046:        public class MLETTask extends Task {
047:            private static Log log = LogFactory.getLog(MLETTask.class);
048:            String code;
049:            String archive;
050:            String codebase;
051:            String objectName;
052:            ObjectName oname;
053:
054:            List args = new ArrayList();
055:            List attributes = new ArrayList();
056:
057:            // ant specific
058:            String loaderRef; // class loader ref
059:
060:            public MLETTask() {
061:            }
062:
063:            public void addArg(Arg arg) {
064:                args.add(arg);
065:            }
066:
067:            public void addAttribute(JmxSet arg) {
068:                attributes.add(arg);
069:            }
070:
071:            public void setCode(String code) {
072:                this .code = code;
073:            }
074:
075:            public void setArchive(String archive) {
076:                this .archive = archive;
077:            }
078:
079:            public void setCodebase(String codebase) {
080:                this .codebase = codebase;
081:            }
082:
083:            public void setName(String name) {
084:                this .objectName = name;
085:            }
086:
087:            MBeanServer server;
088:
089:            public MBeanServer getMBeanServer() {
090:                if (server != null)
091:                    return server;
092:
093:                server = (MBeanServer) project.getReference("jmx.server");
094:
095:                if (server != null)
096:                    return server;
097:
098:                try {
099:                    if (MBeanServerFactory.findMBeanServer(null).size() > 0) {
100:                        server = (MBeanServer) MBeanServerFactory
101:                                .findMBeanServer(null).get(0);
102:                    } else {
103:                        server = MBeanServerFactory.createMBeanServer();
104:
105:                        // Register a loader that will be find ant classes.
106:                        ObjectName defaultLoader = new ObjectName(
107:                                "modeler-ant", "loader", "ant");
108:                        MLet mlet = new MLet(new URL[0], this .getClass()
109:                                .getClassLoader());
110:                        server.registerMBean(mlet, defaultLoader);
111:
112:                        if (log.isDebugEnabled())
113:                            log.debug("Creating mbean server and loader "
114:                                    + mlet + " "
115:                                    + this .getClass().getClassLoader());
116:                    }
117:                    project.addReference("jmx.server", server);
118:
119:                    // Create the MLet object
120:                } catch (JMException ex) {
121:                    log.error("Error creating server", ex);
122:                }
123:
124:                if (log.isDebugEnabled())
125:                    log.debug("Using Mserver " + server);
126:
127:                return server;
128:            }
129:
130:            boolean modeler = false;
131:
132:            public void setModeler(boolean modeler) {
133:                this .modeler = modeler;
134:            }
135:
136:            protected void bindJmx(String objectName, String code, String arg0,
137:                    List args) throws Exception {
138:                MBeanServer server = getMBeanServer();
139:                oname = new ObjectName(objectName);
140:                if (modeler) {
141:                    Arg codeArg = new Arg();
142:                    codeArg.setType("java.lang.String");
143:                    codeArg.setValue(code);
144:                    if (args == null)
145:                        args = new ArrayList();
146:                    args.add(0, codeArg);
147:                    code = "org.apache.commons.modeler.BaseModelMBean";
148:                }
149:
150:                Object argsA[] = new Object[args.size()];
151:                String sigA[] = new String[args.size()];
152:                for (int i = 0; i < args.size(); i++) {
153:                    Arg arg = (Arg) args.get(i);
154:                    if (arg.type == null)
155:                        arg.type = "java.lang.String";
156:                    sigA[i] = arg.getType();
157:                    argsA[i] = arg.getValue();
158:                    // XXX Deal with not string types - IntrospectionUtils
159:                }
160:
161:                // XXX Use the loader ref, if any
162:                if (args.size() == 0) {
163:                    server.createMBean(code, oname);
164:                } else {
165:                    server.createMBean(code, oname, argsA, sigA);
166:                }
167:                log.debug("Created MBEAN " + oname + " " + code);
168:            }
169:
170:            public ObjectName getObjectName() {
171:                return oname;
172:            }
173:
174:            public void execute() throws BuildException {
175:                try {
176:                    // create the mbean
177:                    bindJmx(objectName, code, null, args);
178:
179:                    // process attributes
180:                    for (int i = 0; i < attributes.size(); i++) {
181:                        JmxSet att = (JmxSet) attributes.get(i);
182:                        att.setObjectName(oname);
183:                        log.info("Setting attribute " + oname + " "
184:                                + att.getName());
185:                        att.execute();
186:                    }
187:                } catch (Exception ex) {
188:                    log.error("Can't create mbean " + objectName, ex);
189:                }
190:            }
191:
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.