001: /**
002: * $Id: NewPortalBean.java,v 1.10 2006/04/18 03:52:27 pd109850 Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.admin.console.fabric;
014:
015: import com.sun.web.ui.model.Option;
016: import com.sun.web.ui.component.RadioButton;
017: import com.sun.web.ui.event.WizardEvent;
018: import com.sun.web.ui.event.WizardEventListener;
019:
020: import javax.faces.event.ActionEvent;
021: import javax.faces.event.ValueChangeEvent;
022: import javax.faces.context.FacesContext;
023: import javax.faces.application.FacesMessage;
024: import javax.faces.component.UIComponent;
025: import javax.faces.validator.Validator;
026: import javax.faces.validator.ValidatorException;
027:
028: import java.util.logging.Level;
029: import java.util.Properties;
030: import java.util.Map;
031: import java.util.List;
032: import java.util.ArrayList;
033: import java.util.Iterator;
034: import java.util.Set;
035:
036: import java.io.IOException;
037: import java.text.MessageFormat;
038:
039: import javax.management.MBeanServerConnection;
040: import javax.management.ObjectName;
041:
042: import com.sun.portal.admin.common.util.AdminClientUtil;
043: import com.sun.portal.admin.common.InstanceAttributes;
044:
045: public class NewPortalBean extends FabricBaseBean implements
046: WizardEventListener {
047:
048: //resource bundle name
049: public static final String RB_NAME = "fabric";
050: //keys in resource bundle
051: public static final String SJSWS6 = "SJSWS6";
052: public static final String SJSWS7 = "SJSWS7";
053: public static final String SJSAS81 = "SJSAS81";
054: public static final String BEAWL8 = "BEAWL8";
055: public static final String IBMWAS5 = "IBMWAS5";
056:
057: public NewPortalBean() {
058: }
059:
060: /**
061: * wcOptions (init in constructor)
062: */
063: private Option[] wcOptions = null;
064:
065: public Option[] getWcOptions() {
066: if (wcOptions == null) {
067: Map fabric = getResourceStringMap(RB_NAME);
068: wcOptions = wcOptions = new Option[] {
069: new Option(SJSWS7, (String) fabric.get(SJSWS7)),
070: new Option(SJSAS81, (String) fabric.get(SJSAS81)),
071: new Option(SJSWS6, (String) fabric.get(SJSWS6)),
072: new Option(BEAWL8, (String) fabric.get(BEAWL8)),
073: new Option(IBMWAS5, (String) fabric.get(IBMWAS5)) };
074: }
075: return wcOptions;
076: }
077:
078: /**
079: * protocolOptions
080: */
081: private Option[] protocolOptions = { new Option("HTTP", "HTTP"),
082: new Option("HTTPS", "HTTPS") };
083:
084: public Option[] getProtocolOptions() {
085: return protocolOptions;
086: }
087:
088: public void setProtocolOptions(Option[] protocolOptions) {
089: protocolOptions = protocolOptions;
090: }
091:
092: /**
093: * portalId
094: */
095: protected String portalId = null;
096:
097: public String getPortalId() {
098: return portalId;
099: }
100:
101: public void setPortalId(String id) {
102: portalId = id;
103: }
104:
105: /**
106: * uri
107: */
108: protected String uri = null;
109:
110: public String getUri() {
111: return uri;
112: }
113:
114: public void setUri(String uri) {
115: this .uri = uri;
116: }
117:
118: /**
119: * wcType
120: */
121: private Object wcType = SJSWS7;
122:
123: public Object getWcType() {
124: return wcType;
125: }
126:
127: public void setWcType(Object wcType) {
128: this .wcType = wcType;
129: }
130:
131: /**
132: * wcProtocol
133: */
134: private Object wcProtocol = "HTTP";
135:
136: public Object getWcProtocol() {
137: return wcProtocol;
138: }
139:
140: public void setWcProtocol(Object wcProtocol) {
141: this .wcProtocol = wcProtocol;
142: }
143:
144: /**
145: * wcHost
146: */
147: private String wcHost = null;
148:
149: public String getWcHost() {
150: return wcHost;
151: }
152:
153: public void setWcHost(String wcHost) {
154: this .wcHost = wcHost;
155: }
156:
157: /**
158: * wcPort
159: */
160: private String wcPort = null;
161:
162: public String getWcPort() {
163: return wcPort;
164: }
165:
166: public void setWcPort(String wcPort) {
167: this .wcPort = wcPort;
168: }
169:
170: /**
171: * wcInstallDir
172: */
173: private String wcInstallDir = null;
174:
175: public String getWcInstallDir() {
176: return wcInstallDir;
177: }
178:
179: public void setWcInstallDir(String wcInstallDir) {
180: this .wcInstallDir = wcInstallDir;
181: }
182:
183: /**
184: * wcInstanceName
185: */
186: private String wcInstanceName = null;
187:
188: public String getWcInstanceName() {
189: return wcInstanceName;
190: }
191:
192: public void setWcInstanceName(String wcInstanceName) {
193: this .wcInstanceName = wcInstanceName;
194: }
195:
196: /**
197: * wcInstanceDir
198: */
199: private String wcInstanceDir = null;
200:
201: public String getWcInstanceDir() {
202: return wcInstanceDir;
203: }
204:
205: public void setWcInstanceDir(String wcInstanceDir) {
206: this .wcInstanceDir = wcInstanceDir;
207: }
208:
209: /**
210: * wcDocRoot
211: */
212: private String wcDocRoot = null;
213:
214: public String getWcDocRoot() {
215: return wcDocRoot;
216: }
217:
218: public void setWcDocRoot(String wcDocRoot) {
219: this .wcDocRoot = wcDocRoot;
220: }
221:
222: /**
223: * wcDomainName
224: */
225: private String wcDomainName = null;
226:
227: public String getWcDomainName() {
228: return wcDomainName;
229: }
230:
231: public void setWcDomainName(String wcDomainName) {
232: this .wcDomainName = wcDomainName;
233: }
234:
235: /**
236: * adminProtocol
237: */
238: private Object adminProtocol = "HTTP";
239:
240: public Object getAdminProtocol() {
241: return adminProtocol;
242: }
243:
244: public void setAdminProtocol(Object adminProtocol) {
245: this .adminProtocol = adminProtocol;
246: }
247:
248: /**
249: * adminHost
250: */
251: private String adminHost = null;
252:
253: public String getAdminHost() {
254: return adminHost;
255: }
256:
257: public void setAdminHost(String adminHost) {
258: this .adminHost = adminHost;
259: }
260:
261: /**
262: * adminPort
263: */
264: private String adminPort = null;
265:
266: public String getAdminPort() {
267: return adminPort;
268: }
269:
270: public void setAdminPort(String adminPort) {
271: this .adminPort = adminPort;
272: }
273:
274: /**
275: * adminUid
276: */
277: private String adminUid = null;
278:
279: public String getAdminUid() {
280: return adminUid;
281: }
282:
283: public void setAdminUid(String adminUid) {
284: this .adminUid = adminUid;
285: }
286:
287: /**
288: * adminPassword
289: */
290: private String adminPassword = null;
291:
292: public String getAdminPassword() {
293: return adminPassword;
294: }
295:
296: public void setAdminPassword(String adminPassword) {
297: this .adminPassword = adminPassword;
298: }
299:
300: /**
301: * jdkDir
302: */
303: private String jdkDir = null;
304:
305: public String getJdkDir() {
306: return jdkDir;
307: }
308:
309: public void setJdkDir(String jdkDir) {
310: this .jdkDir = jdkDir;
311: }
312:
313: /**
314: * managedServer
315: */
316: private boolean managedServer = false;
317:
318: public boolean getManagedServer() {
319: return managedServer;
320: }
321:
322: public void setManagedServer(boolean managedServer) {
323: this .managedServer = managedServer;
324: }
325:
326: private String deployCell = null;
327:
328: public String getDeployCell() {
329: return deployCell;
330: }
331:
332: public void setDeployCell(String deployCell) {
333: this .deployCell = deployCell;
334: }
335:
336: private String deployNode = null;
337:
338: public String getDeployNode() {
339: return deployNode;
340: }
341:
342: public void setDeployNode(String deployNode) {
343: this .deployNode = deployNode;
344: }
345:
346: private String certDBPassword = null;
347:
348: public String getCertDBPassword() {
349: return certDBPassword;
350: }
351:
352: public void setCertDBPassword(String certDBPassword) {
353: this .certDBPassword = certDBPassword;
354: }
355:
356: private String masterPassword = null;
357:
358: public String getMasterPassword() {
359: return masterPassword;
360: }
361:
362: public void setMasterPassword(String masterPassword) {
363: this .masterPassword = masterPassword;
364: }
365:
366: public String getWcTypeStr() {
367: return getLocalizedString(RB_NAME, wcType.toString());
368: }
369:
370: private String logMessage = null;
371:
372: public String getLogMessage() {
373: String logDisplay = logMessage == null ? "" : logMessage;
374: return logDisplay.replaceAll("\n", "<br>");
375: }
376:
377: /*
378: * Localized messages required by the create thread
379: * These messaged have to be localized before the thread is spawned
380: * because once the thread is spawned, the context is not available
381: * and hence it is not possible to know the locale of the user
382: */
383: public String createPortalSuccessMsg;
384: public String createPortalSuccessDetailsMsg;
385: public String createPortalSuccessInstanceFailedCheckLogsMsg;
386: public String createPortalFailedMsg;
387: public String createPortalFailedCheckLogsMsg;
388:
389: public String createInstanceSuccessMsg;
390: public String createInstanceSuccessDetailsMsg;
391: public String createInstanceFailedMsg;
392: public String createInstanceFailedCheckLogsMsg;
393:
394: private void initLocalizedMsgs() {
395: String pattern;
396: MessageFormat mf;
397: Object[] args = { portalId };
398:
399: createPortalSuccessMsg = getLocalizedString("fabric",
400: "message.createPortal.success");
401:
402: pattern = getLocalizedString("fabric",
403: "message.createPortal.success.details");
404: mf = new MessageFormat(pattern);
405: createPortalSuccessDetailsMsg = mf.format(args);
406:
407: pattern = getLocalizedString("fabric",
408: "message.createPortal.success.createInstance.failed");
409: mf = new MessageFormat(pattern);
410: createPortalSuccessInstanceFailedCheckLogsMsg = mf.format(args);
411:
412: createPortalFailedMsg = getLocalizedString("fabric",
413: "message.createPortal.failed");
414:
415: pattern = getLocalizedString("fabric",
416: "message.createPortal.failed.checkLogs");
417: mf = new MessageFormat(pattern);
418: createPortalFailedCheckLogsMsg = mf.format(args);
419:
420: createInstanceSuccessMsg = getLocalizedString("fabric",
421: "message.createInstance.success");
422:
423: pattern = getLocalizedString("fabric",
424: "message.createInstance.success.details");
425: mf = new MessageFormat(pattern);
426: createInstanceSuccessDetailsMsg = mf.format(args);
427:
428: createInstanceFailedMsg = getLocalizedString("fabric",
429: "message.createInstance.failed");
430:
431: pattern = getLocalizedString("fabric",
432: "message.createInstance.failed.checkLogs");
433: mf = new MessageFormat(pattern);
434: createInstanceFailedCheckLogsMsg = mf.format(args);
435: }
436:
437: public String beginCreatePortal() {
438: //make sure that log method is called before
439: //starting the thread so that the base bean
440: //caches the logger, otherwise NPE will result
441: log(Level.FINEST, "begin create portal ...");
442: initLocalizedMsgs();
443: if (inProgress == true) {
444: alert = true;
445: alertSummary = createPortalFailedMsg;
446: alertDetail = getLocalizedString("fabric",
447: "message.createPortal.alreadyRunning");
448: return null;
449: }
450:
451: inProgress = true;
452: new CreateThread(this , true, getMBeanServerConnection())
453: .start();
454: return null;
455: }
456:
457: public String beginCreateInstance() {
458: //make sure that log method is called before
459: //starting the thread so that the base bean
460: //caches the logger, otherwise NPE will result
461: log(Level.FINEST, "begin create instance ...");
462: initLocalizedMsgs();
463: if (inProgress == true) {
464: alert = true;
465: alertSummary = createInstanceFailedMsg;
466: alertDetail = getLocalizedString("fabric",
467: "message.createPortal.alreadyRunning");
468: return null;
469: }
470: inProgress = true;
471: new CreateThread(this , false, getMBeanServerConnection())
472: .start();
473: return null;
474: }
475:
476: class CreateThread extends Thread {
477: NewPortalBean bean = null;
478: boolean createPortal;
479: MBeanServerConnection mbsc = null;
480:
481: CreateThread(NewPortalBean bean, boolean createPortal,
482: MBeanServerConnection mbsc) {
483: this .bean = bean;
484: this .createPortal = createPortal;
485: this .mbsc = mbsc;
486: }
487:
488: public void run() {
489: if (createPortal) {
490: bean.createPortal(mbsc);
491: //bean.test(true);
492: } else {
493: bean.createInstance(mbsc, null);
494: //bean.test(false);
495: }
496: inProgress = false;
497: }
498: }
499:
500: public void test(boolean portal) {
501: log(Level.FINEST, "Process begin ...");
502: try {
503: Thread.sleep(1000 * 30);
504: } catch (Exception e) {
505: }
506: log(Level.FINEST, "Process done...");
507: alert = true;
508: alertSummary = "???Testing: New Portal/Instance created???";
509: if (portal) {
510: alertDetail = createPortalSuccessDetailsMsg;
511: } else {
512: alertDetail = createInstanceSuccessDetailsMsg;
513: }
514: }
515:
516: public String createPortal(MBeanServerConnection mbsc) {
517: alert = false;
518: alertType = null;
519: Properties webconfig = getWebConfigProperties();
520:
521: try {
522: // Get the Domain MBean object
523: ObjectName objName = AdminClientUtil
524: .getPortalDomainMBeanObjectName(AdminClientUtil.DEFAULT_DOMAIN);
525:
526: // Setting the params and signature and invoke validate method
527: Object[] vParams = { webconfig };
528: String[] vSignature = { "java.util.Map" };
529: mbsc.invoke(objName, "validateWebContainer", vParams,
530: vSignature);
531:
532: // Setting the params and signature and invoke the create portal
533: // method on the domain MBean
534: Object[] params = { portalId, wcHost, uri };
535: String[] signature = { "java.lang.String",
536: "java.lang.String", "java.lang.String" };
537: log(Level.FINEST,
538: "NewPortalBean.createPortal: Target host for task="
539: + wcHost);
540: log(Level.FINEST,
541: "NewPortalBean.createPortal: Invoking mbean operation createPortal for id="
542: + portalId);
543: mbsc.invoke(objName, "createPortal", params, signature);
544: log(Level.FINEST,
545: "NewPortalBean.createPortal: Completed mbean operation createPortal for id="
546: + portalId);
547:
548: } catch (Exception e) {
549: log(
550: Level.SEVERE,
551: "NewPortalBean.createPortal: Create Portal operation failed",
552: e);
553: alertType = "error";
554: alertSummary = createPortalFailedMsg;
555: alertDetail = createPortalFailedCheckLogsMsg;
556: alert = true;
557: logMessage = e.getCause().getMessage();
558: }
559:
560: if (!"error".equals(alertType)) {
561: createInstance(mbsc, webconfig);
562: if ("error".equals(alertType)) {
563: alert = true;
564: alertSummary = createPortalFailedMsg;
565: alertDetail = createPortalSuccessInstanceFailedCheckLogsMsg;
566: }
567: }
568:
569: if ("information".equals(alertType)) {
570: alert = true;
571: alertSummary = createPortalSuccessMsg;
572: alertDetail = createPortalSuccessDetailsMsg;
573: logMessage = createPortalSuccessDetailsMsg;
574: }
575:
576: return null;
577: }
578:
579: /* Properties required for Webcontainer
580: 1. Scheme
581: 2. Host
582: 3. Port
583: 4. WebContainerType
584: 5. WebContainerInstallDir
585: 6. WebContainerInstanceName
586: 7. WebContainerInstanceDir
587: 8. WebContainerDocRoot
588: 9. WebContainerDomainName - only for SJSAS81
589: 10. WebContainerAdminScheme - not for SJSWS
590: 11. WebContainerAdminHost - not for SJSWS
591: 12. WebContainerAdminPort - not for SJSWS
592: 13. WebContainerAdminUid - not for SJSWS
593: 14. WebContainerAdminPassword - not for SJSWS and IBMAS5
594: 15. WebContainerJDKDir - only for BEAWL81 and IBMAS5
595: 16. WebContainerManagedServer - only for BEAWL81
596: 17. WebContainerDeployCell - only for IBMAS5
597: 18. WebContainerDeployNode - only for IBMAS5
598: 19. WebContainerCertificateDBPassword - only SJSWS6
599: 20. WebContainerMasterPassword - only SJSAS81
600: */
601: private Properties getWebConfigProperties() {
602: String container = null;
603:
604: if (SJSWS7.equals(wcType)) {
605: container = InstanceAttributes.TYPE_JESWS7;
606: } else if (SJSWS6.equals(wcType)) {
607: container = InstanceAttributes.TYPE_JESWS6;
608: } else if (SJSAS81.equals(wcType)) {
609: container = InstanceAttributes.TYPE_JESAS81;
610: } else if (BEAWL8.equals(wcType)) {
611: container = InstanceAttributes.TYPE_BEAWL8;
612: } else if (IBMWAS5.equals(wcType)) {
613: container = InstanceAttributes.TYPE_IBMWS5;
614: }
615:
616: log(Level.FINEST, "Container type : " + container);
617:
618: Properties webConfigProp = new Properties();
619: webConfigProp.setProperty(InstanceAttributes.SCHEME, wcProtocol
620: .toString());
621: webConfigProp.setProperty(InstanceAttributes.HOST, wcHost);
622: webConfigProp.setProperty(InstanceAttributes.PORT, wcPort);
623: webConfigProp.setProperty(
624: InstanceAttributes.WEB_CONTAINER_TYPE, container);
625: webConfigProp.setProperty(
626: InstanceAttributes.WEB_CONTAINER_INSTALL_DIR,
627: wcInstallDir);
628: webConfigProp.setProperty(
629: InstanceAttributes.WEB_CONTAINER_INSTANCE,
630: wcInstanceName);
631: webConfigProp.setProperty(
632: InstanceAttributes.WEB_CONTAINER_INSTANCE_DIR,
633: wcInstanceDir);
634: webConfigProp.setProperty(
635: InstanceAttributes.WEB_CONTAINER_DOC_ROOT, wcDocRoot);
636: webConfigProp.setProperty(
637: InstanceAttributes.WEB_CONTAINER_DOMAIN,
638: wcDomainName == null ? "" : wcDomainName);
639: webConfigProp.setProperty(
640: InstanceAttributes.WEB_CONTAINER_ADMIN_SCHEME,
641: adminProtocol.toString());
642: webConfigProp.setProperty(
643: InstanceAttributes.WEB_CONTAINER_ADMIN_HOST,
644: adminHost == null ? "" : adminHost);
645: webConfigProp.setProperty(
646: InstanceAttributes.WEB_CONTAINER_ADMIN_PORT,
647: adminPort == null ? "" : adminPort);
648: webConfigProp.setProperty(
649: InstanceAttributes.WEB_CONTAINER_ADMIN_UID,
650: adminUid == null ? "" : adminUid);
651: webConfigProp.setProperty(
652: InstanceAttributes.WEB_CONTAINER_ADMIN_PASSWORD,
653: adminPassword == null ? "" : adminPassword);
654: webConfigProp.setProperty(
655: InstanceAttributes.WEB_CONTAINER_JDK_DIR,
656: jdkDir == null ? "" : jdkDir);
657: webConfigProp.setProperty(
658: InstanceAttributes.WEB_CONTAINER_MANAGED_SERVER,
659: managedServer == false ? "false" : "true");
660: webConfigProp.setProperty(
661: InstanceAttributes.WEB_CONTAINER_DEPLOY_CELL,
662: deployCell == null ? "" : deployCell);
663: webConfigProp.setProperty(
664: InstanceAttributes.WEB_CONTAINER_DEPLOY_NODE,
665: deployNode == null ? "" : deployNode);
666: webConfigProp.setProperty(
667: InstanceAttributes.WEB_CONTAINER_CERTDB_PASSWORD,
668: certDBPassword == null ? "" : certDBPassword);
669: webConfigProp.setProperty(
670: InstanceAttributes.WEB_CONTAINER_MASTER_PASSWORD,
671: masterPassword == null ? "" : masterPassword);
672:
673: return webConfigProp;
674:
675: }
676:
677: public String createInstance(MBeanServerConnection mbsc,
678: Properties webconfig) {
679: alert = false;
680: alertType = null;
681:
682: try {
683: // If the webconfig passed is null, then this method is being
684: // invoked from just an instance creation. Not as a part of the
685: // portal create operation. Hence the webconfig properties object
686: // should be generated and its contents should be validated
687: if (webconfig == null) {
688: webconfig = getWebConfigProperties();
689: // Get the Domain MBean object
690: ObjectName objName = AdminClientUtil
691: .getPortalDomainMBeanObjectName(AdminClientUtil.DEFAULT_DOMAIN);
692: // Setting the params and signature and invoke validate method
693: Object[] vParams = { webconfig };
694: String[] vSignature = { "java.util.Map" };
695: mbsc.invoke(objName, "validateWebContainer", vParams,
696: vSignature);
697: }
698:
699: // Set the right params and signature
700: Object[] iParams = { null, webconfig };
701: String[] iSignature = { "java.lang.String",
702: "java.util.Properties" };
703: // Get the MBean object for the newly created portal
704: ObjectName iObjName = AdminClientUtil
705: .getPortalMBeanObjectName(
706: AdminClientUtil.DEFAULT_DOMAIN, portalId);
707:
708: log(Level.FINEST,
709: "NewPortalBean.createInstance: Invoking mbean operation createInstance for id="
710: + portalId);
711: // Invoke the Create instance operation on the newly created portal
712: mbsc.invoke(iObjName, "createAndFinalizeInstance", iParams,
713: iSignature);
714: log(
715: Level.FINEST,
716: "NewPortalBean.createInstance: Completed mbean operation createInstance for id="
717: + portalId);
718: logMessage = createInstanceSuccessDetailsMsg;
719: alertType = "information";
720: alertSummary = createInstanceSuccessMsg;
721: alertDetail = createInstanceSuccessDetailsMsg;
722: alert = true;
723: } catch (Exception e) {
724: log(
725: Level.SEVERE,
726: "NewPortalBean.createInstance: Create Instance operation failed",
727: e);
728: logMessage = e.getCause().getMessage();
729: alertType = "error";
730: alertSummary = createInstanceFailedMsg;
731: alertDetail = createInstanceFailedCheckLogsMsg;
732: alert = true;
733: }
734: return null;
735: }
736:
737: private boolean alert = false;
738:
739: public boolean isAlert() {
740: boolean show = alert;
741: //toggle alert if true
742: alert = false;
743: return show;
744: }
745:
746: private String alertDetail = null;
747:
748: public String getAlertDetail() {
749: return alertDetail;
750: }
751:
752: private String alertSummary = null;
753:
754: public String getAlertSummary() {
755: return alertSummary;
756: }
757:
758: private String alertType = null;
759:
760: public String getAlertType() {
761: return alertType;
762: }
763:
764: private boolean inProgress = false;
765:
766: public boolean isInProgress() {
767: return inProgress;
768: }
769:
770: protected void resetBean() {
771: if (!inProgress) {
772: portalId = null;
773: uri = null;
774: wcHost = null;
775: wcPort = null;
776: wcInstallDir = null;
777: wcInstanceName = null;
778: wcInstanceDir = null;
779: wcDocRoot = null;
780: wcDomainName = null;
781: adminHost = null;
782: adminPort = null;
783: adminUid = null;
784: adminPassword = null;
785: jdkDir = null;
786: managedServer = false;
787: deployCell = null;
788: deployNode = null;
789: certDBPassword = null;
790: masterPassword = null;
791:
792: alert = false;
793: alertDetail = null;
794: alertSummary = null;
795: alertType = null;
796: }
797: }
798:
799: /**
800: * validate the portalId as:
801: * - contains only ASCII alphanumeric and hyphen
802: * - not duplicate of any existing portal-id
803: * otherwise throw an exception with localized faces message
804: */
805: public void validatePortalId(FacesContext context,
806: UIComponent component, Object value)
807: throws ValidatorException {
808: String portalId = (String) value;
809: if (portalId != null && portalId.matches(".*[^a-zA-Z0-9-].*")) {
810: log(Level.SEVERE,
811: "NewPortalBean.validatePortalId: Invalid portal id");
812: String msgString = getLocalizedString(RB_NAME,
813: "wizard.newPortal.portalid.invalid.message");
814: FacesMessage msg = new FacesMessage(msgString);
815: throw new ValidatorException(msg);
816: }
817: Iterator iter = getPortalNames().iterator();
818: while (iter.hasNext()) {
819: String id = (String) iter.next();
820: if (id.equalsIgnoreCase(portalId)) {
821: log(Level.SEVERE,
822: "NewPortalBean.validatePortalId: Portal already exists.");
823: String msgString = getLocalizedString(RB_NAME,
824: "wizard.newPortal.portalid.duplicate.message");
825: FacesMessage msg = new FacesMessage(msgString);
826: throw new ValidatorException(msg);
827: }
828: }
829: }
830:
831: /**
832: * uri must begin with slash and must confirm to RFC 2396
833: */
834: public void validatePortalURI(FacesContext context,
835: UIComponent component, Object value)
836: throws ValidatorException {
837: String context_path = (String) value;
838: //context_path will never be null but still...
839: context_path = context_path == null ? "" : context_path;
840:
841: if (!context_path.startsWith("/")) {
842: String msgString = getLocalizedString(RB_NAME,
843: "wizard.newPortal.invalid.portaluri.noslash");
844: FacesMessage msg = new FacesMessage(msgString);
845: throw new ValidatorException(msg);
846: }
847:
848: try {
849: java.net.URI.create(context_path);
850: } catch (IllegalArgumentException e) {
851: log(Level.SEVERE, "NewPortalBean.validatePortalURI:"
852: + e.getCause().getMessage());
853: String msgString = getLocalizedString(RB_NAME,
854: "wizard.newPortal.invalid.portaluri");
855: FacesMessage msg = new FacesMessage(msgString);
856: throw new ValidatorException(msg);
857: }
858: }
859:
860: private List getPortalNames() {
861: List pNames = new ArrayList();
862: try {
863: ObjectName portalPat = AdminClientUtil
864: .getPortalsPattern(AdminClientUtil.DEFAULT_DOMAIN);
865: Set objNames = getMBeanServerConnection().queryNames(
866: portalPat, null);
867: Iterator iter = objNames.iterator();
868: while (iter.hasNext()) {
869: pNames
870: .add(getAttribute((ObjectName) iter.next(),
871: "ID"));
872: }
873: } catch (IOException ie) {
874: log(
875: Level.SEVERE,
876: "NewPortalBean.getPortalNames: Exception when trying to get the list of portals",
877: ie);
878: } catch (Exception ex) {
879: log(
880: Level.SEVERE,
881: "NewPortalBean.getPortalNames: Exception when trying to get the list of portals",
882: ex);
883: }
884: return pNames;
885: }
886:
887: /*
888: * thows an exception with localized faces message if the port number
889: * is not an integer
890: */
891: public void validatePort(FacesContext context,
892: UIComponent component, Object value)
893: throws ValidatorException {
894: try {
895: Integer i = new Integer((String) value);
896: } catch (NumberFormatException e) {
897: String msgString = getLocalizedString(RB_NAME,
898: "wizard.newPortal.port.invalid.message");
899: FacesMessage msg = new FacesMessage(msgString);
900: throw new ValidatorException(msg);
901: }
902: }
903:
904: ///////////begin wizard evert listner impl////////////
905: public boolean handleEvent(WizardEvent event) {
906: switch (event.getNavigationEvent()) {
907: case WizardEvent.FINISH:
908: //start the thread to create portal
909: beginCreatePortal();
910: break;
911: case WizardEvent.CANCEL:
912: case WizardEvent.CLOSE:
913: resetBean();
914: break;
915: default:
916: break;
917: }
918: return true;
919: }
920:
921: public boolean isTransient() {
922: return false;
923: }
924:
925: public void setTransient(boolean flag) {
926: }
927:
928: public Object saveState(FacesContext context) {
929: return null;
930: }
931:
932: public void restoreState(FacesContext context, Object state) {
933: }
934: ///////////end wizard evern listner impl////////////
935:
936: }
|