KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > upgrade > common > arguments > CertificateArgumentHandler


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * CertificateArgumentHandler.java
26  *
27  * Created on August 25, 2005, 3:24 PM
28  */

29
30 package com.sun.enterprise.tools.upgrade.common.arguments;
31
32 import com.sun.enterprise.tools.upgrade.common.ArgsParser;
33 import java.io.BufferedReader JavaDoc;
34 import java.io.FileInputStream JavaDoc;
35 import java.io.FileNotFoundException JavaDoc;
36 import java.io.InputStreamReader JavaDoc;
37 import java.util.StringTokenizer JavaDoc;
38 import java.util.logging.Level JavaDoc;
39 import com.sun.enterprise.tools.upgrade.common.UpgradeConstants;
40
41 /**
42  *
43  * @author Hans Hrasna
44  */

45 public abstract class CertificateArgumentHandler extends ArgumentHandler {
46     
47     /** Creates a new instance of CertificateArgumentHandler */
48     public CertificateArgumentHandler(ParsedArgument pa) {
49         super(pa);
50         commonInfo.setCertificateConversionFlag(true);
51     }
52     
53     /** processCertificatePasswords
54      * Reads password triplets or doublets from passwordFile and sets them in CommonInfoModel
55      * format: domain_name instance_name password
56      * or: domain_name password
57      */

58     protected void processCertificatePasswords(String JavaDoc pwdfile) {
59         try {
60             BufferedReader JavaDoc reader = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(new FileInputStream JavaDoc(pwdfile)));
61             while(reader.ready()){
62                 String JavaDoc entry = reader.readLine();
63                 StringTokenizer JavaDoc tokens = new StringTokenizer JavaDoc(entry, " ", false);
64                 int tokenCount = tokens.countTokens();
65                 if (tokenCount < 1){
66                     _logger.severe(sm.getString("enterprise.tools.upgrade.cli.password_missing",pwdfile));
67                     System.exit(1);
68                 }
69                 if (tokenCount > 1) {
70                     String JavaDoc domainName = tokens.nextToken();
71                     commonInfo.setCurrentDomain(domainName);
72                     commonInfo.addDomainOptionName(domainName);
73                 }
74                 if (tokenCount == 3) {
75                     commonInfo.setCurrentSourceInstance(tokens.nextToken());
76                 }
77                 setCertificatePassword(tokens.nextToken());
78                 if(commonInfo.getSourceVersion().equals(UpgradeConstants.VERSION_7X)) {
79                     interactiveMap.put(ArgsParser.DOMAIN + "-" + commonInfo.getCurrentDomain() + ":" + commonInfo.getCurrentSourceInstance(), pwdfile);
80                 } else interactiveMap.put(ArgsParser.DOMAIN + "-" + commonInfo.getCurrentDomain(), pwdfile);
81             }
82         } catch(FileNotFoundException JavaDoc fe) {
83             helpUsage();
84             _logger.log(Level.SEVERE,sm.getString("enterprise.tools.upgrade.cli.password_file_missing",pwdfile),fe);
85             System.exit(1);
86         } catch(Exception JavaDoc io) {
87             _logger.log(Level.SEVERE,sm.getString("enterprise.tools.upgrade.cli.password_missing",pwdfile),io);
88             System.exit(1);
89         }
90     }
91     
92     protected abstract void setCertificatePassword(String JavaDoc pwd);
93 }
94
Popular Tags