Source Code Cross Referenced for CommandDistribute.java in  » EJB-Server-geronimo » deploy-tool » org » apache » geronimo » deployment » cli » 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 » EJB Server geronimo » deploy tool » org.apache.geronimo.deployment.cli 
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:         */package org.apache.geronimo.deployment.cli;
017:
018:        import java.io.File;
019:        import java.io.PrintWriter;
020:        import java.io.IOException;
021:        import java.util.Arrays;
022:        import java.util.List;
023:        import java.util.StringTokenizer;
024:
025:        import javax.enterprise.deploy.spi.DeploymentManager;
026:        import javax.enterprise.deploy.spi.Target;
027:        import javax.enterprise.deploy.spi.TargetModuleID;
028:        import javax.enterprise.deploy.spi.status.ProgressObject;
029:
030:        import org.apache.geronimo.cli.deployer.CommandArgs;
031:        import org.apache.geronimo.cli.deployer.DistributeCommandArgs;
032:        import org.apache.geronimo.common.DeploymentException;
033:        import org.apache.geronimo.deployment.plugin.jmx.JMXDeploymentManager;
034:        import jline.ConsoleReader;
035:
036:        /**
037:         * The CLI deployer logic to distribute.
038:         *
039:         * @version $Rev: 596987 $ $Date: 2007-11-21 00:39:04 -0800 (Wed, 21 Nov 2007) $
040:         */
041:        public class CommandDistribute extends AbstractCommand {
042:
043:            protected ProgressObject runCommand(DeploymentManager mgr,
044:                    ConsoleReader out, boolean inPlace, Target[] tlist,
045:                    File module, File plan) throws DeploymentException {
046:                if (inPlace) {
047:                    if (!(mgr instanceof  JMXDeploymentManager)) {
048:                        throw new DeploymentSyntaxException(
049:                                "Target DeploymentManager is not a Geronimo one. \n"
050:                                        + "Cannot perform in-place deployment.");
051:                    }
052:                    JMXDeploymentManager jmxMgr = (JMXDeploymentManager) mgr;
053:                    try {
054:                        jmxMgr.setInPlace(true);
055:                        return mgr.distribute(tlist, module, plan);
056:                    } finally {
057:                        jmxMgr.setInPlace(false);
058:                    }
059:                } else {
060:                    return mgr.distribute(tlist, module, plan);
061:                }
062:            }
063:
064:            protected String getAction() {
065:                return "Distributed";
066:            }
067:
068:            public void execute(ConsoleReader consoleReader,
069:                    ServerConnection connection, CommandArgs commandArgs)
070:                    throws DeploymentException {
071:                if (!(commandArgs instanceof  DistributeCommandArgs)) {
072:                    throw new DeploymentSyntaxException(
073:                            "CommandArgs has the type ["
074:                                    + commandArgs.getClass() + "]; expected ["
075:                                    + DistributeCommandArgs.class + "]");
076:                }
077:                DistributeCommandArgs distributeCommandArgs = (DistributeCommandArgs) commandArgs;
078:
079:                BooleanHolder inPlaceHolder = new BooleanHolder();
080:                inPlaceHolder.inPlace = distributeCommandArgs.isInPlace();
081:
082:                List<String> targets = Arrays.asList(distributeCommandArgs
083:                        .getTargets());
084:
085:                String[] args = distributeCommandArgs.getArgs();
086:                File module = null;
087:                File plan = null;
088:                if (args.length > 0) {
089:                    File test = new File(args[0]);
090:                    if (DeployUtils.isJarFile(test) || test.isDirectory()) {
091:                        if (module != null) {
092:                            throw new DeploymentSyntaxException(
093:                                    "Module and plan cannot both be JAR files or directories!");
094:                        }
095:                        module = test;
096:                    } else {
097:                        if (plan != null) {
098:                            throw new DeploymentSyntaxException(
099:                                    "Module or plan must be a JAR file or directory!");
100:                        }
101:                        plan = test;
102:                    }
103:                }
104:                if (args.length > 1) {
105:                    File test = new File(args[1]);
106:                    if (DeployUtils.isJarFile(test) || test.isDirectory()) {
107:                        if (module != null) {
108:                            throw new DeploymentSyntaxException(
109:                                    "Module and plan cannot both be JAR files or directories!");
110:                        }
111:                        module = test;
112:                    } else {
113:                        if (plan != null) {
114:                            throw new DeploymentSyntaxException(
115:                                    "Module or plan must be a JAR file or directory!");
116:                        }
117:                        plan = test;
118:                    }
119:                }
120:                if (module != null) {
121:                    module = module.getAbsoluteFile();
122:                }
123:                if (plan != null) {
124:                    plan = plan.getAbsoluteFile();
125:                }
126:                try {
127:                    executeOnline(connection, inPlaceHolder.inPlace, targets,
128:                            consoleReader, module, plan);
129:                } catch (IOException e) {
130:                    throw new DeploymentException("Could not write to output",
131:                            e);
132:                }
133:            }
134:
135:            private void executeOnline(ServerConnection connection,
136:                    boolean inPlace, List targets, ConsoleReader out,
137:                    File module, File plan) throws DeploymentException,
138:                    IOException {
139:                final DeploymentManager mgr = connection.getDeploymentManager();
140:                TargetModuleID[] results;
141:                boolean multipleTargets;
142:                ProgressObject po;
143:                if (targets.size() > 0) {
144:                    Target[] tlist = identifyTargets(targets, mgr);
145:                    multipleTargets = tlist.length > 1;
146:                    po = runCommand(mgr, out, inPlace, tlist, module, plan);
147:                    waitForProgress(out, po);
148:                } else {
149:                    Target[] tlist = mgr.getTargets();
150:                    if (null == tlist) {
151:                        throw new IllegalStateException(
152:                                "No target to distribute to");
153:                    }
154:                    tlist = new Target[] { tlist[0] };
155:
156:                    multipleTargets = tlist.length > 1;
157:                    po = runCommand(mgr, out, inPlace, tlist, module, plan);
158:                    waitForProgress(out, po);
159:                }
160:
161:                // print the results that succeeded
162:                results = po.getResultTargetModuleIDs();
163:                for (int i = 0; i < results.length; i++) {
164:                    TargetModuleID result = results[i];
165:                    out.printString(DeployUtils.reformat(getAction()
166:                            + " "
167:                            + result.getModuleID()
168:                            + (multipleTargets ? " to "
169:                                    + result.getTarget().getName() : "")
170:                            + (result.getWebURL() == null
171:                                    || !getAction().equals("Deployed") ? ""
172:                                    : " @ " + result.getWebURL()), 4, 72));
173:                    if (result.getChildTargetModuleID() != null) {
174:                        for (int j = 0; j < result.getChildTargetModuleID().length; j++) {
175:                            TargetModuleID child = result
176:                                    .getChildTargetModuleID()[j];
177:                            out
178:                                    .printString(DeployUtils
179:                                            .reformat(
180:                                                    "  `-> "
181:                                                            + child
182:                                                                    .getModuleID()
183:                                                            + (child
184:                                                                    .getWebURL() == null
185:                                                                    || !getAction()
186:                                                                            .equals(
187:                                                                                    "Deployed") ? ""
188:                                                                    : " @ "
189:                                                                            + child
190:                                                                                    .getWebURL()),
191:                                                    4, 72));
192:                        }
193:                    }
194:                }
195:
196:                // if any results failed then throw so that we'll return non-0
197:                // to the operating system
198:                if (po.getDeploymentStatus().isFailed()) {
199:                    throw new DeploymentException("Operation failed: "
200:                            + po.getDeploymentStatus().getMessage());
201:                }
202:            }
203:
204:            private String[] processTargets(String[] args, List targets) {
205:                if (args.length >= 2 && args[0].equals("--targets")) {
206:                    String value = args[1];
207:                    StringTokenizer tok = new StringTokenizer(value, ";", false);
208:                    while (tok.hasMoreTokens()) {
209:                        targets.add(tok.nextToken());
210:                    }
211:                    String[] temp = new String[args.length - 2];
212:                    System.arraycopy(args, 2, temp, 0, temp.length);
213:                    args = temp;
214:                }
215:                return args;
216:            }
217:
218:            private String[] processInPlace(String[] args,
219:                    BooleanHolder inPlaceHolder) {
220:                if (args.length >= 2 && args[0].equals("--inPlace")) {
221:                    inPlaceHolder.inPlace = true;
222:                    String[] temp = new String[args.length - 1];
223:                    System.arraycopy(args, 1, temp, 0, temp.length);
224:                    args = temp;
225:                }
226:                return args;
227:            }
228:
229:            private final class BooleanHolder {
230:                public boolean inPlace;
231:            }
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.