Source Code Cross Referenced for AbstractHandler.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » console » jmsmanager » wizard » 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 » plugins » org.apache.geronimo.console.jmsmanager.wizard 
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.console.jmsmanager.wizard;
017:
018:        import java.io.BufferedOutputStream;
019:        import java.io.ByteArrayOutputStream;
020:        import java.io.File;
021:        import java.io.FileOutputStream;
022:        import java.io.IOException;
023:        import java.util.ArrayList;
024:        import java.util.Iterator;
025:        import java.util.List;
026:        import java.util.Map;
027:        import java.util.Properties;
028:        import javax.enterprise.deploy.model.DDBean;
029:        import javax.enterprise.deploy.model.DDBeanRoot;
030:        import javax.enterprise.deploy.spi.DeploymentConfiguration;
031:        import javax.enterprise.deploy.spi.DeploymentManager;
032:        import javax.enterprise.deploy.spi.Target;
033:        import javax.enterprise.deploy.spi.TargetModuleID;
034:        import javax.enterprise.deploy.spi.status.ProgressObject;
035:        import javax.portlet.ActionResponse;
036:        import javax.portlet.PortletRequest;
037:        import javax.portlet.PortletSession;
038:        import org.apache.commons.logging.Log;
039:        import org.apache.commons.logging.LogFactory;
040:        import org.apache.geronimo.connector.deployment.jsr88.AdminObjectDCB;
041:        import org.apache.geronimo.connector.deployment.jsr88.AdminObjectInstance;
042:        import org.apache.geronimo.connector.deployment.jsr88.ConnectionDefinition;
043:        import org.apache.geronimo.connector.deployment.jsr88.ConnectionDefinitionInstance;
044:        import org.apache.geronimo.connector.deployment.jsr88.Connector15DCBRoot;
045:        import org.apache.geronimo.connector.deployment.jsr88.ConnectorDCB;
046:        import org.apache.geronimo.connector.deployment.jsr88.ResourceAdapter;
047:        import org.apache.geronimo.connector.deployment.jsr88.ResourceAdapterInstance;
048:        import org.apache.geronimo.connector.deployment.jsr88.SinglePool;
049:        import org.apache.geronimo.console.MultiPageAbstractHandler;
050:        import org.apache.geronimo.console.MultiPageModel;
051:        import org.apache.geronimo.console.jmsmanager.ManagementHelper;
052:        import org.apache.geronimo.console.util.PortletManager;
053:        import org.apache.geronimo.deployment.service.jsr88.EnvironmentData;
054:        import org.apache.geronimo.deployment.tools.loader.ConnectorDeployable;
055:        import org.apache.geronimo.kernel.repository.Artifact;
056:        import org.apache.geronimo.naming.deployment.jsr88.GBeanLocator;
057:
058:        /**
059:         * Base class for portlet helpers
060:         *
061:         * @version $Rev: 611338 $ $Date: 2008-01-11 16:42:22 -0800 (Fri, 11 Jan 2008) $
062:         */
063:        public abstract class AbstractHandler extends MultiPageAbstractHandler {
064:            private final static Log log = LogFactory
065:                    .getLog(AbstractHandler.class);
066:            // ********** This part specific to JMS portlets **********
067:
068:            protected final static String LIST_MODE = "list";
069:            protected final static String SELECT_PROVIDER_MODE = "provider";
070:            protected final static String CONFIGURE_RA_MODE = "ra";
071:            protected final static String ADD_FACTORY_MODE = "factory";
072:            protected final static String SELECT_FACTORY_TYPE_MODE = "factoryType";
073:            protected final static String ADD_DESTINATION_MODE = "destination";
074:            protected final static String SELECT_DESTINATION_TYPE_MODE = "destinationType";
075:            protected final static String REVIEW_MODE = "review";
076:            protected final static String SHOW_PLAN_MODE = "plan";
077:            protected final static String DEPLOY_MODE = "deploy";
078:
079:            protected final static String PROVIDER_PARAMETER = "provider";
080:            protected final static String RAR_FILE_PARAMETER = "rar";
081:            protected final static String DEPENDENCY_PARAMETER = "dependency";
082:            protected final static String INSTANCE_NAME_PARAMETER = "instanceName";
083:            protected final static String NAME_PARAMETER = "name";
084:            protected final static String CURRENT_FACTORY_PARAMETER = "currentFactoryID";
085:            protected final static String CURRENT_DEST_PARAMETER = "currentDestinationID";
086:            protected final static String FACTORY_TYPE_PARAMETER = "factoryType";
087:            protected final static String DEST_TYPE_PARAMETER = "destinationType";
088:            protected final static String TRANSACTION_PARAMETER = "transaction";
089:            protected final static String XA_TRANSACTION_PARAMETER = "xaTransaction";
090:            protected final static String XA_THREAD_PARAMETER = "xaThread";
091:            protected final static String MIN_SIZE_PARAMETER = "poolMinSize";
092:            protected final static String MAX_SIZE_PARAMETER = "poolMaxSize";
093:            protected final static String IDLE_TIME_PARAMETER = "poolIdleTimeout";
094:            protected final static String BLOCK_TIME_PARAMETER = "poolBlockingTimeout";
095:
096:            public AbstractHandler(String mode, String viewName) {
097:                super (mode, viewName);
098:            }
099:
100:            public static class JMSResourceData implements  MultiPageModel {
101:                private String rarURI;
102:                private String dependency;
103:                private String instanceName;
104:                private Properties instanceProps = new Properties();
105:                private String workManager;
106:                private int currentFactory = -1;
107:                private int currentDestination = -1;
108:                private int factoryType = -1;
109:                private int destinationType = -1;
110:                private List connectionFactories = new ArrayList();
111:                private List adminObjects = new ArrayList();
112:                // Used for editing an existing resource
113:                private String objectName;
114:
115:                public JMSResourceData(PortletRequest request) {
116:                    Map map = request.getParameterMap();
117:                    rarURI = request.getParameter(RAR_FILE_PARAMETER);
118:                    dependency = request.getParameter(DEPENDENCY_PARAMETER);
119:                    instanceName = request
120:                            .getParameter(INSTANCE_NAME_PARAMETER);
121:                    factoryType = isEmpty(request
122:                            .getParameter(FACTORY_TYPE_PARAMETER)) ? -1
123:                            : Integer.parseInt(request
124:                                    .getParameter(FACTORY_TYPE_PARAMETER));
125:                    currentFactory = isEmpty(request
126:                            .getParameter(CURRENT_FACTORY_PARAMETER)) ? -1
127:                            : Integer.parseInt(request
128:                                    .getParameter(CURRENT_FACTORY_PARAMETER));
129:                    destinationType = isEmpty(request
130:                            .getParameter(DEST_TYPE_PARAMETER)) ? -1
131:                            : Integer.parseInt(request
132:                                    .getParameter(DEST_TYPE_PARAMETER));
133:                    currentDestination = isEmpty(request
134:                            .getParameter(CURRENT_DEST_PARAMETER)) ? -1
135:                            : Integer.parseInt(request
136:                                    .getParameter(CURRENT_DEST_PARAMETER));
137:                    for (int i = 0; i < 20; i++) {
138:                        String key = "instance-config-" + i;
139:                        if (map.containsKey(key)) {
140:                            instanceProps.setProperty(key, request
141:                                    .getParameter(key));
142:                        }
143:                    }
144:                    workManager = "DefaultWorkManager"; //todo
145:                    int index = 0;
146:                    while (true) {
147:                        String key = "factory." + (index++) + ".";
148:                        if (!map.containsKey(key + FACTORY_TYPE_PARAMETER)) {
149:                            break;
150:                        }
151:                        JMSConnectionFactoryData data = new JMSConnectionFactoryData();
152:                        data.load(request, key);
153:                        connectionFactories.add(data);
154:                    }
155:                    index = 0;
156:                    while (true) {
157:                        String key = "destination." + (index++) + ".";
158:                        if (!map.containsKey(key + DEST_TYPE_PARAMETER)) {
159:                            break;
160:                        }
161:                        JMSAdminObjectData data = new JMSAdminObjectData();
162:                        data.load(request, key);
163:                        adminObjects.add(data);
164:                    }
165:                    createIfNecessary();
166:                }
167:
168:                public void createIfNecessary() {
169:                    while (currentFactory >= connectionFactories.size()) {
170:                        connectionFactories.add(new JMSConnectionFactoryData());
171:                    }
172:                    while (currentDestination >= adminObjects.size()) {
173:                        adminObjects.add(new JMSAdminObjectData());
174:                    }
175:                }
176:
177:                public void save(ActionResponse response, PortletSession session) {
178:                    if (!isEmpty(rarURI))
179:                        response.setRenderParameter(RAR_FILE_PARAMETER, rarURI);
180:                    if (!isEmpty(dependency))
181:                        response.setRenderParameter(DEPENDENCY_PARAMETER,
182:                                dependency);
183:                    if (!isEmpty(instanceName))
184:                        response.setRenderParameter(INSTANCE_NAME_PARAMETER,
185:                                instanceName);
186:                    for (Iterator it = instanceProps.entrySet().iterator(); it
187:                            .hasNext();) {
188:                        Map.Entry entry = (Map.Entry) it.next();
189:                        if (!isEmpty((String) entry.getValue())) {
190:                            response.setRenderParameter(
191:                                    (String) entry.getKey(), (String) entry
192:                                            .getValue());
193:                        }
194:                    }
195:                    if (!isEmpty(workManager))
196:                        response.setRenderParameter("workManager", workManager);
197:                    response.setRenderParameter(FACTORY_TYPE_PARAMETER, Integer
198:                            .toString(factoryType));
199:                    response.setRenderParameter(DEST_TYPE_PARAMETER, Integer
200:                            .toString(destinationType));
201:                    response.setRenderParameter(CURRENT_DEST_PARAMETER, Integer
202:                            .toString(currentDestination));
203:                    response.setRenderParameter(CURRENT_FACTORY_PARAMETER,
204:                            Integer.toString(currentFactory));
205:                    for (int i = 0; i < connectionFactories.size(); i++) {
206:                        JMSConnectionFactoryData data = (JMSConnectionFactoryData) connectionFactories
207:                                .get(i);
208:                        String key = "factory." + i + ".";
209:                        data.save(response, key);
210:                    }
211:                    for (int i = 0; i < adminObjects.size(); i++) {
212:                        JMSAdminObjectData data = (JMSAdminObjectData) adminObjects
213:                                .get(i);
214:                        String key = "destination." + i + ".";
215:                        data.save(response, key);
216:                    }
217:                }
218:
219:                public int getFactoryType() {
220:                    return factoryType;
221:                }
222:
223:                public void setFactoryType(int factoryType) {
224:                    this .factoryType = factoryType;
225:                }
226:
227:                public int getDestinationType() {
228:                    return destinationType;
229:                }
230:
231:                public void setDestinationType(int destinationType) {
232:                    this .destinationType = destinationType;
233:                }
234:
235:                public int getCurrentFactoryID() {
236:                    return currentFactory;
237:                }
238:
239:                public void setCurrentFactoryID(int id) {
240:                    currentFactory = id;
241:                }
242:
243:                public int getCurrentDestinationID() {
244:                    return currentDestination;
245:                }
246:
247:                public void setCurrentDestinationID(int id) {
248:                    currentDestination = id;
249:                }
250:
251:                public String getRarURI() {
252:                    return rarURI;
253:                }
254:
255:                public void setRarURI(String rarURI) {
256:                    this .rarURI = rarURI;
257:                }
258:
259:                public String getDependency() {
260:                    return dependency;
261:                }
262:
263:                public void setDependency(String dependency) {
264:                    this .dependency = dependency;
265:                }
266:
267:                public String getInstanceName() {
268:                    return instanceName;
269:                }
270:
271:                public void setInstanceName(String instanceName) {
272:                    this .instanceName = instanceName;
273:                }
274:
275:                public String getWorkManager() {
276:                    return workManager;
277:                }
278:
279:                public void setWorkManager(String workManager) {
280:                    this .workManager = workManager;
281:                }
282:
283:                public Properties getInstanceProps() {
284:                    return instanceProps;
285:                }
286:
287:                public List getConnectionFactories() {
288:                    return connectionFactories;
289:                }
290:
291:                public List getAdminObjects() {
292:                    return adminObjects;
293:                }
294:
295:                public JMSConnectionFactoryData getCurrentFactory() {
296:                    return (JMSConnectionFactoryData) connectionFactories
297:                            .get(currentFactory);
298:                }
299:
300:                public JMSAdminObjectData getCurrentDestination() {
301:                    return (JMSAdminObjectData) adminObjects
302:                            .get(currentDestination);
303:                }
304:
305:                public int getConnectionFactoryCount() {
306:                    return connectionFactories.size();
307:                }
308:
309:                public int getDestinationCount() {
310:                    return adminObjects.size();
311:                }
312:            }
313:
314:            public static class JMSConnectionFactoryData {
315:                private int factoryType;
316:                private String instanceName;
317:                private String transaction; //none, local, xa
318:                private boolean xaTransactionCaching;
319:                private boolean xaThreadCaching;
320:                private Integer poolMinSize;
321:                private Integer poolMaxSize;
322:                private Integer poolBlockingTimeout;
323:                private Integer poolIdleTimeout;
324:                private Properties instanceProps = new Properties();
325:
326:                public void load(PortletRequest request, String prefix) {
327:                    factoryType = isEmpty(request.getParameter(prefix
328:                            + FACTORY_TYPE_PARAMETER)) ? -1 : Integer
329:                            .parseInt(request.getParameter(prefix
330:                                    + FACTORY_TYPE_PARAMETER));
331:                    instanceName = request.getParameter(prefix
332:                            + INSTANCE_NAME_PARAMETER);
333:                    transaction = request.getParameter(prefix
334:                            + TRANSACTION_PARAMETER);
335:                    xaThreadCaching = !isEmpty(request.getParameter(prefix
336:                            + XA_THREAD_PARAMETER))
337:                            && request.getParameter(
338:                                    prefix + XA_THREAD_PARAMETER)
339:                                    .equals("true");
340:                    xaTransactionCaching = isEmpty(request.getParameter(prefix
341:                            + XA_TRANSACTION_PARAMETER))
342:                            || request.getParameter(
343:                                    prefix + XA_TRANSACTION_PARAMETER).equals(
344:                                    "true");
345:                    poolMinSize = isEmpty(request.getParameter(prefix
346:                            + MIN_SIZE_PARAMETER)) ? null : new Integer(request
347:                            .getParameter(prefix + MIN_SIZE_PARAMETER));
348:                    poolMaxSize = isEmpty(request.getParameter(prefix
349:                            + MAX_SIZE_PARAMETER)) ? null : new Integer(request
350:                            .getParameter(prefix + MAX_SIZE_PARAMETER));
351:                    poolIdleTimeout = isEmpty(request.getParameter(prefix
352:                            + IDLE_TIME_PARAMETER)) ? null : new Integer(
353:                            request.getParameter(prefix + IDLE_TIME_PARAMETER));
354:                    poolBlockingTimeout = isEmpty(request.getParameter(prefix
355:                            + BLOCK_TIME_PARAMETER)) ? null
356:                            : new Integer(request.getParameter(prefix
357:                                    + BLOCK_TIME_PARAMETER));
358:                    Map map = request.getParameterMap();
359:                    for (int i = 0; i < 20; i++) {
360:                        String key = prefix + "instance-config-" + i;
361:                        if (map.containsKey(key)) {
362:                            instanceProps.setProperty(key.substring(prefix
363:                                    .length()), request.getParameter(key));
364:                        }
365:                    }
366:                }
367:
368:                public void save(ActionResponse response, String prefix) {
369:                    if (factoryType > -1)
370:                        response.setRenderParameter(prefix
371:                                + FACTORY_TYPE_PARAMETER, Integer
372:                                .toString(factoryType));
373:                    if (!isEmpty(instanceName))
374:                        response.setRenderParameter(prefix
375:                                + INSTANCE_NAME_PARAMETER, instanceName);
376:                    if (!isEmpty(transaction))
377:                        response.setRenderParameter(prefix
378:                                + TRANSACTION_PARAMETER, transaction);
379:                    response.setRenderParameter(prefix + XA_THREAD_PARAMETER,
380:                            Boolean.toString(xaThreadCaching));
381:                    response.setRenderParameter(prefix
382:                            + XA_TRANSACTION_PARAMETER, Boolean
383:                            .toString(xaTransactionCaching));
384:                    if (poolMinSize != null)
385:                        response.setRenderParameter(
386:                                prefix + MIN_SIZE_PARAMETER, poolMinSize
387:                                        .toString());
388:                    if (poolMaxSize != null)
389:                        response.setRenderParameter(
390:                                prefix + MAX_SIZE_PARAMETER, poolMaxSize
391:                                        .toString());
392:                    if (poolBlockingTimeout != null)
393:                        response.setRenderParameter(prefix
394:                                + BLOCK_TIME_PARAMETER, poolBlockingTimeout
395:                                .toString());
396:                    if (poolIdleTimeout != null)
397:                        response.setRenderParameter(prefix
398:                                + IDLE_TIME_PARAMETER, poolIdleTimeout
399:                                .toString());
400:                    for (Iterator it = instanceProps.entrySet().iterator(); it
401:                            .hasNext();) {
402:                        Map.Entry entry = (Map.Entry) it.next();
403:                        if (!isEmpty((String) entry.getValue())) {
404:                            response.setRenderParameter(
405:                                    prefix + entry.getKey(), (String) entry
406:                                            .getValue());
407:                        }
408:                    }
409:                }
410:
411:                public int getFactoryType() {
412:                    return factoryType;
413:                }
414:
415:                public void setFactoryType(int factoryType) {
416:                    this .factoryType = factoryType;
417:                }
418:
419:                public String getInstanceName() {
420:                    return instanceName;
421:                }
422:
423:                public void setInstanceName(String instanceName) {
424:                    this .instanceName = instanceName;
425:                }
426:
427:                public String getTransaction() {
428:                    return transaction;
429:                }
430:
431:                public void setTransaction(String transaction) {
432:                    this .transaction = transaction;
433:                }
434:
435:                public boolean isXaTransactionCaching() {
436:                    return xaTransactionCaching;
437:                }
438:
439:                public void setXaTransactionCaching(boolean xaTransactionCaching) {
440:                    this .xaTransactionCaching = xaTransactionCaching;
441:                }
442:
443:                public boolean isXaThreadCaching() {
444:                    return xaThreadCaching;
445:                }
446:
447:                public void setXaThreadCaching(boolean xaThreadCaching) {
448:                    this .xaThreadCaching = xaThreadCaching;
449:                }
450:
451:                public Integer getPoolMinSize() {
452:                    return poolMinSize;
453:                }
454:
455:                public void setPoolMinSize(Integer poolMinSize) {
456:                    this .poolMinSize = poolMinSize;
457:                }
458:
459:                public Integer getPoolMaxSize() {
460:                    return poolMaxSize;
461:                }
462:
463:                public void setPoolMaxSize(Integer poolMaxSize) {
464:                    this .poolMaxSize = poolMaxSize;
465:                }
466:
467:                public Integer getPoolBlockingTimeout() {
468:                    return poolBlockingTimeout;
469:                }
470:
471:                public void setPoolBlockingTimeout(Integer poolBlockingTimeout) {
472:                    this .poolBlockingTimeout = poolBlockingTimeout;
473:                }
474:
475:                public Integer getPoolIdleTimeout() {
476:                    return poolIdleTimeout;
477:                }
478:
479:                public void setPoolIdleTimeout(Integer poolIdleTimeout) {
480:                    this .poolIdleTimeout = poolIdleTimeout;
481:                }
482:
483:                public Properties getInstanceProps() {
484:                    return instanceProps;
485:                }
486:            }
487:
488:            public static class JMSAdminObjectData {
489:                private int destinationType;
490:                private String name;
491:                private Properties instanceProps = new Properties();
492:
493:                public void load(PortletRequest request, String prefix) {
494:                    destinationType = isEmpty(request.getParameter(prefix
495:                            + DEST_TYPE_PARAMETER)) ? -1 : Integer
496:                            .parseInt(request.getParameter(prefix
497:                                    + DEST_TYPE_PARAMETER));
498:                    name = request.getParameter(prefix + NAME_PARAMETER);
499:                    Map map = request.getParameterMap();
500:                    for (int i = 0; i < 20; i++) {
501:                        String key = prefix + "instance-config-" + i;
502:                        if (map.containsKey(key)) {
503:                            instanceProps.setProperty(key.substring(prefix
504:                                    .length()), request.getParameter(key));
505:                        }
506:                    }
507:                }
508:
509:                public void save(ActionResponse response, String prefix) {
510:                    if (destinationType > -1)
511:                        response.setRenderParameter(prefix
512:                                + DEST_TYPE_PARAMETER, Integer
513:                                .toString(destinationType));
514:                    if (!isEmpty(name))
515:                        response.setRenderParameter(prefix + NAME_PARAMETER,
516:                                name);
517:                    for (Iterator it = instanceProps.entrySet().iterator(); it
518:                            .hasNext();) {
519:                        Map.Entry entry = (Map.Entry) it.next();
520:                        if (!isEmpty((String) entry.getValue())) {
521:                            response.setRenderParameter(
522:                                    prefix + entry.getKey(), (String) entry
523:                                            .getValue());
524:                        }
525:                    }
526:                }
527:
528:                public int getDestinationType() {
529:                    return destinationType;
530:                }
531:
532:                public void setDestinationType(int destinationType) {
533:                    this .destinationType = destinationType;
534:                }
535:
536:                public String getName() {
537:                    return name;
538:                }
539:
540:                public void setName(String name) {
541:                    this .name = name;
542:                }
543:
544:                public Properties getInstanceProps() {
545:                    return instanceProps;
546:                }
547:            }
548:
549:            private static String getPropertyName(String propertyKey,
550:                    JMSProviderData.ConfigPropertyData[] configs) {
551:                int pos = propertyKey.lastIndexOf('-');
552:                String num = propertyKey.substring(pos + 1);
553:                return configs[Integer.parseInt(num)].getName();
554:            }
555:
556:            protected static String save(PortletRequest request,
557:                    ActionResponse response, JMSResourceData data,
558:                    boolean planOnly) throws IOException {
559:                JMSProviderData provider = JMSProviderData.getProviderData(
560:                        data.rarURI, request);
561:                if (data.objectName == null || data.objectName.equals("")) { // we're creating a new pool
562:                    //data.instanceName = data.instanceName.replaceAll("\\s", "");
563:                    DeploymentManager mgr = ManagementHelper
564:                            .getManagementHelper(request)
565:                            .getDeploymentManager();
566:                    try {
567:                        File rarFile = PortletManager.getRepositoryEntry(
568:                                request, data.getRarURI());
569:                        ConnectorDeployable deployable = new ConnectorDeployable(
570:                                rarFile.toURL());
571:                        DeploymentConfiguration config = mgr
572:                                .createConfiguration(deployable);
573:                        final DDBeanRoot ddBeanRoot = deployable
574:                                .getDDBeanRoot();
575:                        Connector15DCBRoot root = (Connector15DCBRoot) config
576:                                .getDConfigBeanRoot(ddBeanRoot);
577:                        ConnectorDCB connector = (ConnectorDCB) root
578:                                .getDConfigBean(ddBeanRoot.getChildBean(root
579:                                        .getXpaths()[0])[0]);
580:
581:                        EnvironmentData environment = new EnvironmentData();
582:                        connector.setEnvironment(environment);
583:                        org.apache.geronimo.deployment.service.jsr88.Artifact configId = new org.apache.geronimo.deployment.service.jsr88.Artifact();
584:                        environment.setConfigId(configId);
585:                        configId.setGroupId("console.jms");
586:                        configId.setArtifactId(data.instanceName);
587:                        configId.setVersion("1.0");
588:                        configId.setType("rar");
589:                        if (data.dependency != null
590:                                && !data.dependency.trim().equals("")) {
591:                            Artifact artifact = Artifact.create(data.dependency
592:                                    .trim());
593:                            org.apache.geronimo.deployment.service.jsr88.Artifact dep = new org.apache.geronimo.deployment.service.jsr88.Artifact();
594:                            environment
595:                                    .setDependencies(new org.apache.geronimo.deployment.service.jsr88.Artifact[] { dep });
596:                            dep.setArtifactId(artifact.getArtifactId());
597:                            if (artifact.getGroupId() != null) {
598:                                dep.setGroupId(artifact.getGroupId());
599:                            }
600:                            if (artifact.getType() != null) {
601:                                dep.setType(artifact.getType());
602:                            }
603:                            if (artifact.getVersion() != null) {
604:                                dep
605:                                        .setVersion(artifact.getVersion()
606:                                                .toString());
607:                            }
608:                        }
609:
610:                        // Basic settings on RA plan and RA instance
611:                        ResourceAdapter ra;
612:                        if (connector.getResourceAdapter().length > 0) {
613:                            ra = connector.getResourceAdapter(0);
614:                        } else {
615:                            ra = new ResourceAdapter();
616:                            connector
617:                                    .setResourceAdapter(new ResourceAdapter[] { ra });
618:                        }
619:                        ResourceAdapterInstance raInstance = new ResourceAdapterInstance();
620:                        ra.setResourceAdapterInstance(raInstance);
621:                        raInstance.setResourceAdapterName(data.instanceName);
622:                        for (Iterator it = data.instanceProps.entrySet()
623:                                .iterator(); it.hasNext();) {
624:                            Map.Entry entry = (Map.Entry) it.next();
625:                            String name = getPropertyName((String) entry
626:                                    .getKey(), provider
627:                                    .getInstanceConfigProperties());
628:                            for (int i = 0; i < raInstance
629:                                    .getConfigPropertySetting().length; i++) {
630:                                if (raInstance.getConfigPropertySetting(i)
631:                                        .getName().equals(name)) {
632:                                    raInstance
633:                                            .getConfigPropertySetting(i)
634:                                            .setValue((String) entry.getValue());
635:                                    break;
636:                                }
637:                            }
638:                        }
639:                        GBeanLocator workManager = new GBeanLocator();
640:                        raInstance.setWorkManager(workManager);
641:                        workManager.setGBeanLink(data.workManager); //todo
642:                        // Connection Factories
643:                        if (data.getConnectionFactoryCount() > 0) {
644:                            ConnectionDefinition[] defs = new ConnectionDefinition[data
645:                                    .getConnectionFactoryCount()];
646:                            for (int i = 0; i < defs.length; i++) {
647:                                defs[i] = new ConnectionDefinition();
648:                            }
649:                            ra.setConnectionDefinition(defs);
650:                            for (int i = 0; i < data.getConnectionFactories()
651:                                    .size(); i++) {
652:                                JMSConnectionFactoryData factoryData = (JMSConnectionFactoryData) data
653:                                        .getConnectionFactories().get(i);
654:                                JMSProviderData.ConnectionDefinition providerData = provider
655:                                        .getConnectionDefinitions()[factoryData
656:                                        .getFactoryType()];
657:                                ConnectionDefinition def = defs[i];
658:                                def.setConnectionFactoryInterface(providerData
659:                                        .getConnectionFactoryInterface());
660:                                ConnectionDefinitionInstance instance = new ConnectionDefinitionInstance();
661:                                def
662:                                        .setConnectionInstance(new ConnectionDefinitionInstance[] { instance });
663:                                if (providerData
664:                                        .getConnectionFactoryInterface()
665:                                        .equals("javax.jms.ConnectionFactory")) {
666:                                    instance
667:                                            .setImplementedInterface(new String[] {
668:                                                    "javax.jms.QueueConnectionFactory",
669:                                                    "javax.jms.TopicConnectionFactory" });
670:                                }
671:                                instance.setName(factoryData.getInstanceName());
672:                                SinglePool pool = new SinglePool();
673:                                instance.getConnectionManager().setPoolSingle(
674:                                        pool);
675:                                pool.setMatchOne(true);
676:                                pool.setMaxSize(factoryData.getPoolMaxSize());
677:                                pool.setMinSize(factoryData.getPoolMinSize());
678:                                pool.setBlockingTimeoutMillis(factoryData
679:                                        .getPoolBlockingTimeout());
680:                                pool.setIdleTimeoutMinutes(factoryData
681:                                        .getPoolIdleTimeout());
682:                                if (factoryData.getTransaction().equals("none")) {
683:                                    instance.getConnectionManager()
684:                                            .setTransactionNone(true);
685:                                } else if (factoryData.getTransaction().equals(
686:                                        "local")) {
687:                                    instance.getConnectionManager()
688:                                            .setTransactionLocal(true);
689:                                } else if (factoryData.getTransaction().equals(
690:                                        "xa")) {
691:                                    instance.getConnectionManager()
692:                                            .setTransactionXA(true);
693:                                    instance
694:                                            .getConnectionManager()
695:                                            .setTransactionXACachingThread(
696:                                                    factoryData
697:                                                            .isXaThreadCaching());
698:                                    instance
699:                                            .getConnectionManager()
700:                                            .setTransactionXACachingTransaction(
701:                                                    factoryData
702:                                                            .isXaTransactionCaching());
703:                                }
704:                                for (Iterator it = factoryData.instanceProps
705:                                        .entrySet().iterator(); it.hasNext();) {
706:                                    Map.Entry entry = (Map.Entry) it.next();
707:                                    String name = getPropertyName(
708:                                            (String) entry.getKey(),
709:                                            providerData.getConfigProperties());
710:                                    for (int j = 0; j < instance
711:                                            .getConfigPropertySetting().length; j++) {
712:                                        if (instance
713:                                                .getConfigPropertySetting(j)
714:                                                .getName().equals(name)) {
715:                                            instance
716:                                                    .getConfigPropertySetting(j)
717:                                                    .setValue(
718:                                                            (String) entry
719:                                                                    .getValue());
720:                                            break;
721:                                        }
722:                                    }
723:                                }
724:                            }
725:                        }
726:
727:                        // Destinations
728:                        DDBean[] ddBeans = connector.getDDBean().getChildBean(
729:                                connector.getXpaths()[0]);
730:                        AdminObjectDCB[] adminDCBs = new AdminObjectDCB[ddBeans.length];
731:                        for (int i = 0; i < adminDCBs.length; i++) {
732:                            adminDCBs[i] = (AdminObjectDCB) connector
733:                                    .getDConfigBean(ddBeans[i]);
734:                        }
735:                        for (int i = 0; i < data.getAdminObjects().size(); i++) {
736:                            JMSAdminObjectData admin = (JMSAdminObjectData) data
737:                                    .getAdminObjects().get(i);
738:                            JMSProviderData.AdminObjectDefinition providerData = provider
739:                                    .getAdminObjectDefinitions()[admin
740:                                    .getDestinationType()];
741:                            for (int j = 0; j < adminDCBs.length; j++) {
742:                                AdminObjectDCB adminDCB = adminDCBs[j];
743:                                if (adminDCB.getAdminObjectInterface().equals(
744:                                        providerData.getAdminObjectInterface())) {
745:                                    AdminObjectInstance[] before = adminDCB
746:                                            .getAdminObjectInstance();
747:                                    AdminObjectInstance[] after = new AdminObjectInstance[before.length + 1];
748:                                    System.arraycopy(before, 0, after, 0,
749:                                            before.length);
750:                                    AdminObjectInstance instance = new AdminObjectInstance();
751:                                    after[before.length] = instance;
752:                                    adminDCB.setAdminObjectInstance(after);
753:                                    instance.setMessageDestinationName(admin
754:                                            .getName());
755:                                    for (Iterator it = admin.instanceProps
756:                                            .entrySet().iterator(); it
757:                                            .hasNext();) {
758:                                        Map.Entry entry = (Map.Entry) it.next();
759:                                        String name = getPropertyName(
760:                                                (String) entry.getKey(),
761:                                                providerData
762:                                                        .getConfigProperties());
763:                                        for (int k = 0; k < instance
764:                                                .getConfigPropertySetting().length; k++) {
765:                                            if (instance
766:                                                    .getConfigPropertySetting(k)
767:                                                    .getName().equals(name)) {
768:                                                instance
769:                                                        .getConfigPropertySetting(
770:                                                                k)
771:                                                        .setValue(
772:                                                                (String) entry
773:                                                                        .getValue());
774:                                                break;
775:                                            }
776:                                        }
777:                                    }
778:                                    break;
779:                                }
780:                            }
781:                        }
782:
783:                        // Save
784:                        if (planOnly) {
785:                            ByteArrayOutputStream out = new ByteArrayOutputStream();
786:                            config.save(out);
787:                            out.close();
788:                            return new String(out.toByteArray(), "US-ASCII");
789:                        } else {
790:                            File tempFile = File.createTempFile(
791:                                    "console-deployment", ".xml");
792:                            tempFile.deleteOnExit();
793:                            log
794:                                    .debug("Writing JMS Resource deployment plan to "
795:                                            + tempFile.getAbsolutePath());
796:                            BufferedOutputStream out = new BufferedOutputStream(
797:                                    new FileOutputStream(tempFile));
798:                            config.save(out);
799:                            out.flush();
800:                            out.close();
801:                            Target[] targets = mgr.getTargets();
802:                            if (null == targets) {
803:                                throw new IllegalStateException(
804:                                        "No target to distribute to");
805:                            }
806:                            targets = new Target[] { targets[0] };
807:
808:                            ProgressObject po = mgr.distribute(targets,
809:                                    rarFile, tempFile);
810:                            waitForProgress(po);
811:                            if (po.getDeploymentStatus().isCompleted()) {
812:                                TargetModuleID[] ids = po
813:                                        .getResultTargetModuleIDs();
814:                                po = mgr.start(ids);
815:                                waitForProgress(po);
816:                                if (po.getDeploymentStatus().isCompleted()) {
817:                                    ids = po.getResultTargetModuleIDs();
818:                                    log
819:                                            .info("Deployment completed successfully!");
820:                                }
821:                            }
822:                        }
823:                    } catch (Exception e) {
824:                        log.error("Unable to save connection pool", e);
825:                    } finally {
826:                        if (mgr != null)
827:                            mgr.release();
828:                    }
829:                } else { // We're saving updates to an existing pool
830:                    if (planOnly) {
831:                        throw new UnsupportedOperationException(
832:                                "Can't update a plan for an existing deployment");
833:                    }
834:                    throw new UnsupportedOperationException(
835:                            "Can't edit existing configurations yet");
836:                }
837:                return null;
838:            }
839:
840:            protected static void waitForProgress(ProgressObject po) {
841:                while (po.getDeploymentStatus().isRunning()) {
842:                    try {
843:                        Thread.sleep(100);
844:                    } catch (InterruptedException e) {
845:                        e.printStackTrace();
846:                    }
847:                }
848:            }
849:
850:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.