Source Code Cross Referenced for DPACommand.java in  » Portal » Open-Portal » com » sun » portal » desktop » dp » 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 » Portal » Open Portal » com.sun.portal.desktop.dp.cli 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved. 
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms. 
004:         */
005:        package com.sun.portal.desktop.dp.cli;
006:
007:        import java.util.Map;
008:        import java.util.TreeMap;
009:        import java.util.Set;
010:        import java.util.List;
011:        import java.util.ArrayList;
012:        import java.util.ResourceBundle;
013:        import java.util.PropertyResourceBundle;
014:        import java.util.Locale;
015:        import java.util.Iterator;
016:        import java.util.Properties;
017:        import java.util.logging.Level;
018:        import java.util.logging.Logger;
019:
020:        import java.io.BufferedReader;
021:        import java.io.StringReader;
022:        import java.io.InputStreamReader;
023:        import java.io.FileInputStream;
024:        import java.io.ByteArrayInputStream;
025:        import java.io.InputStream;
026:        import java.io.IOException;
027:        import java.io.BufferedInputStream;
028:        import java.io.FileNotFoundException;
029:
030:        import com.iplanet.sso.SSOException;
031:
032:        import com.sun.portal.desktop.context.AdminDPContext;
033:        import com.sun.portal.desktop.context.DSAMEAdminDPContext;
034:        import com.sun.portal.desktop.context.ContextError;
035:        import com.sun.portal.log.common.PortalLogger;
036:        import com.sun.portal.util.ResourceLoader;
037:
038:        class DPACommand {
039:
040:            // subcommands
041:            protected static final String LIST = "list";
042:            protected static final String MERGE = "merge";
043:            protected static final String MODIFY = "modify";
044:            protected static final String ADD = "add";
045:            protected static final String REMOVE = "remove";
046:            protected static final String BATCH = "batch";
047:
048:            protected static final int SUBCMD_LIST = 1;
049:            protected static final int SUBCMD_MERGE = 2;
050:            protected static final int SUBCMD_MODIFY = 3;
051:            protected static final int SUBCMD_ADD = 4;
052:            protected static final int SUBCMD_REMOVE = 5;
053:            protected static final int SUBCMD_BATCH = 6;
054:
055:            // options
056:            protected static final String HELP = "help";
057:            protected static final String UID = "runasdn";
058:            protected static final String PASSWORD = "password";
059:            protected static final String DN = "dn";
060:            protected static final String GLOBAL = "global";
061:            protected static final String NAME = "name";
062:            protected static final String PARENT = "parent";
063:            protected static final String TYPE = "type";
064:            protected static final String COMBINE = "combine";
065:            protected static final String VERBOSE = "verbose";
066:            protected static final String VERSION = "version";
067:            protected static final String LOCALE = "locale";
068:            protected static final String DRYRUN = "dry-run";
069:            protected static final String CONT = "continue";
070:            protected static final String FILE = "file";
071:
072:            // default value for unrequired options
073:            public static final String OPT_DEFAULT = "*";
074:
075:            //default value for the locale option
076:            public static final String LOCALE_DEFAULT = Locale.getDefault()
077:                    .toString();
078:
079:            // option values
080:            protected int subcmd = -1;
081:            protected String uid = null;
082:            protected String password = null;
083:            protected String dn = null;
084:            protected boolean global = false;
085:            protected boolean verbose = false;
086:            protected boolean version = false;
087:            protected String name = null;
088:            protected String parent = null;
089:            protected String type = null;
090:            protected boolean combine = false;
091:            protected boolean dryrun = false;
092:            protected String[] files = null;
093:            protected InputStream[] xmlByteStreams = null;
094:            protected boolean cont = false;
095:            protected String batchFile = null;
096:            protected boolean batchMode = false;
097:            protected boolean isPreAuthorized = false;
098:
099:            private static Logger logger = PortalLogger
100:                    .getLogger(DPACommand.class);
101:
102:            DPACommand(CLIPParser clipp, String[] args, boolean batchMode)
103:                    throws DPAException {
104:
105:                this .batchMode = batchMode;
106:                parse(clipp, args);
107:            }
108:
109:            DPACommand(CLIPParser clipp, String cmdEntry, boolean batchMode,
110:                    boolean isPreAuthorized) throws DPAException {
111:
112:                String cmd = null;
113:                try {
114:                    BufferedReader br = new BufferedReader(new StringReader(
115:                            cmdEntry));
116:
117:                    cmd = br.readLine();
118:
119:                } catch (Exception ex) {
120:                    Object[] tokens = { cmdEntry };
121:                    throw new DPAException("errorParseBatch", ex, tokens);
122:                }
123:
124:                List cmdList = new ArrayList();
125:
126:                StringBuffer tokenBuf = new StringBuffer();
127:                boolean isQuoted = false;
128:                for (int i = 0; i < cmd.length(); i++) {
129:                    if (cmd.charAt(i) == '"') {
130:                        isQuoted = !isQuoted;
131:                    } else {
132:                        if (!isQuoted && cmd.charAt(i) == (' ')) {
133:                            if (tokenBuf.length() > 0) {
134:                                cmdList.add(tokenBuf.toString());
135:                            }
136:                            tokenBuf = new StringBuffer();
137:                        } else {
138:                            tokenBuf.append(cmd.charAt(i));
139:                        }
140:                    }
141:                }
142:                if (tokenBuf.length() > 0) {
143:                    cmdList.add(tokenBuf.toString());
144:                }
145:
146:                // check for unmatched quote
147:                if (isQuoted) {
148:                    Object[] tokens = { cmdEntry };
149:                    throw new DPAException("errorUnmatchedQuote", tokens);
150:                }
151:
152:                String[] cmdArray = new String[cmdList.size()];
153:                cmdList.toArray(cmdArray);
154:
155:                this .batchMode = batchMode;
156:                this .isPreAuthorized = isPreAuthorized;
157:                parse(clipp, cmdArray);
158:            }
159:
160:            private void parse(CLIPParser clipp, String[] argv)
161:                    throws DPAException {
162:
163:                // version (before CLIP parsing begins)
164:                if (clipp.needsVersion(argv)) {
165:                    System.err.println(getVersionInfo());
166:                    System.exit(0);
167:                }
168:
169:                // help
170:                if (clipp.needsHelp(argv)) {
171:                    System.err.println(clipp.getHelp(argv));
172:                    System.exit(0);
173:                }
174:
175:                // get options
176:                Map options = null;
177:                try {
178:                    options = clipp.getOptions(argv);
179:                } catch (CLIPException ce) {
180:                    throw new DPAException("errorCLIPParseError", ce);
181:                }
182:
183:                //
184:                // FIXME(susu): for debugging purpose
185:                //
186:                /*
187:                try {
188:                    System.out.println("------------------------------------------------------------------");
189:                    System.out.println("CLIP CONTENT (for debug purpose only): " + clipp.toString(argv));
190:                    System.out.println("------------------------------------------------------------------");
191:                } catch (CLIPException ce) {
192:                    ce.printStackTrace();
193:                }
194:                 */
195:
196:                try {
197:                    clipp.verifyArguments(argv);
198:                } catch (CLIPException ce) {
199:                    throw new DPAException("errorCLIPParseError", ce);
200:                }
201:
202:                // verbose
203:                if (((String[]) options.get(VERBOSE))[0].equals("true")) {
204:                    verbose = true;
205:                } else {
206:                    verbose = false;
207:                }
208:
209:                // get subcommad
210:                String sc = null;
211:                try {
212:                    sc = clipp.getSubCommand(argv);
213:                } catch (CLIPException ce) {
214:                    Object[] tokens = { sc };
215:                    throw new DPAException("errorInvalidSubCmd", ce, tokens);
216:                }
217:                if (sc.equals(LIST)) {
218:                    subcmd = SUBCMD_LIST;
219:                } else if (sc.equals(MERGE)) {
220:                    subcmd = SUBCMD_MERGE;
221:                } else if (sc.equals(MODIFY)) {
222:                    subcmd = SUBCMD_MODIFY;
223:                } else if (sc.equals(ADD)) {
224:                    subcmd = SUBCMD_ADD;
225:                } else if (sc.equals(REMOVE)) {
226:                    subcmd = SUBCMD_REMOVE;
227:                } else if (sc.equals(BATCH)) {
228:                    subcmd = SUBCMD_BATCH;
229:                }
230:
231:                // required options
232:                uid = ((String[]) options.get(UID))[0];
233:                password = ((String[]) options.get(PASSWORD))[0];
234:
235:                if (subcmd != SUBCMD_BATCH) {
236:                    if (batchMode && !isAuthProvided() && !isPreAuthorized) {
237:                        throw new DPAException("errorNoAuth");
238:                    }
239:
240:                    /**
241:                     * TBD (susu): prompting for password disabled for now.
242:                     *             need to implement masking
243:                     *
244:                    if (password.equals(OPT_DEFAULT)) {
245:                        System.out.print(DPAUtil.getLocalizedString("msgPassword"));
246:                        BufferedReader br =
247:                            new BufferedReader(new InputStreamReader(System.in));
248:                        String line = null;
249:                        try {
250:                            line = br.readLine();
251:                        } catch (IOException ioe) {
252:                            throw new DPAException("errorPassword", ioe);
253:                        }
254:                        password = line;
255:                    throw new DPAException("errorNoPassword");
256:                    }
257:                     */
258:
259:                    // either DN or GLOBAL has to be specified
260:                    // can't specify both
261:                    dn = ((String[]) options.get(DN))[0];
262:                    global = ((String[]) options.get(GLOBAL))[0].equals("true");
263:                    if (dn.equals(OPT_DEFAULT)) {
264:                        if (!global) {
265:                            throw new DPAException("errorNoDNGlobal");
266:                        }
267:                    } else if (global) {
268:                        throw new DPAException("errorBothDNGlobal");
269:                    }
270:                } else {
271:                    cont = ((String[]) options.get(CONT))[0].equals("true");
272:                    batchFile = ((String[]) options.get(FILE))[0];
273:                }
274:
275:                // get args for subcmd
276:                if (subcmd == SUBCMD_LIST || subcmd == SUBCMD_MERGE
277:                        || subcmd == SUBCMD_REMOVE) {
278:                    String[] names = ((String[]) options.get(NAME));
279:                    if (names != null && names.length > 0) {
280:                        if (!names[0].equals(OPT_DEFAULT)) {
281:                            name = names[0];
282:                        }
283:                    }
284:                }
285:                if (subcmd == SUBCMD_ADD || subcmd == SUBCMD_REMOVE
286:                        || subcmd == SUBCMD_MODIFY) {
287:                    String[] parents = ((String[]) options.get(PARENT));
288:                    if (parents != null && parents.length > 0) {
289:                        if (!parents[0].equals(OPT_DEFAULT)) {
290:                            parent = parents[0];
291:                        }
292:                    }
293:                }
294:                if (subcmd == SUBCMD_REMOVE) {
295:                    String[] types = ((String[]) options.get(TYPE));
296:                    if (types != null && types.length > 0) {
297:                        if (!types[0].equals(OPT_DEFAULT)) {
298:                            type = types[0];
299:                        }
300:                    }
301:                }
302:
303:                if (subcmd == SUBCMD_MODIFY) {
304:                    if (((String[]) options.get(COMBINE))[0].equals("true")) {
305:                        combine = true;
306:                    } else {
307:                        combine = false;
308:                    }
309:                }
310:
311:                // check for dryrun
312:                if (subcmd != SUBCMD_BATCH) {
313:                    if (((String[]) options.get(DRYRUN))[0].equals("true")) {
314:                        dryrun = true;
315:                    } else {
316:                        dryrun = false;
317:                    }
318:                }
319:
320:                // get operand
321:                if ((subcmd == SUBCMD_MODIFY || subcmd == SUBCMD_ADD)) {
322:                    xmlByteStreams = getXMLInput(argv, clipp);
323:                    if (xmlByteStreams == null || xmlByteStreams.length == 0) {
324:                        throw new DPAException("errorEmptyXML");
325:                    }
326:                }
327:            }
328:
329:            protected boolean isBatch() {
330:                return (subcmd == SUBCMD_BATCH);
331:            }
332:
333:            protected boolean isAuthProvided() {
334:                boolean authProvided = !uid.equals(OPT_DEFAULT)
335:                        && !password.equals(OPT_DEFAULT);
336:                return authProvided;
337:            }
338:
339:            private InputStream[] getXMLInput(String[] argv, CLIPParser clipp)
340:                    throws DPAException {
341:
342:                InputStream[] streams = null;
343:
344:                // get input file (if any)
345:                try {
346:                    files = clipp.getOperands(argv);
347:                } catch (CLIPException ce) {
348:                    Object[] tokens = { ce.toString() };
349:                    throw new DPAException("errorOperand", tokens);
350:                }
351:
352:                if (files != null && files.length > 0) {
353:                    streams = new InputStream[files.length];
354:                    for (int i = 0; i < files.length; i++) {
355:                        FileInputStream fis = null;
356:                        try {
357:                            /* The stream is parsed twice and hence needs to be reset.
358:                             * FileInputStream does not support mark. Hence create and
359:                             * return a ByteArrayInputStream.
360:                             */
361:                            fis = new FileInputStream(files[i]);
362:                            int nBytes = fis.available();
363:                            byte[] byteArray = new byte[nBytes];
364:                            fis.read(byteArray);
365:                            fis.close();
366:                            streams[i] = new ByteArrayInputStream(byteArray);
367:                        } catch (IOException ioe) {
368:                            Object[] tokens = { files[i] };
369:                            throw new DPAException("errorFileRead", ioe, tokens);
370:                        }
371:                    }
372:                } else {
373:                    if (!batchMode) {
374:                        streams = new InputStream[1];
375:                        // prompt for xml input if no file is specified
376:                        streams[0] = new BufferedInputStream(System.in);
377:                        //The stream is parsed twice and hence needs to be reset.
378:                        streams[0].mark(Integer.MAX_VALUE);
379:                    }
380:                }
381:                return streams;
382:            }
383:
384:            protected void runCommand() throws DPAException {
385:                AdminDPContext adc = doAuth();
386:                runCommand(adc);
387:            }
388:
389:            protected void runCommand(AdminDPContext adc) throws DPAException {
390:
391:                //
392:                // if auth info is provided, re-authorize
393:                //
394:                if (isAuthProvided()) {
395:                    adc = doAuth();
396:                }
397:
398:                switch (subcmd) {
399:                case SUBCMD_LIST:
400:                    DPAList dpal = new DPAList();
401:                    String res = dpal.process(adc, dn, global, name, verbose,
402:                            null);
403:                    if (res != null) {
404:                        byte[] bytes = null;
405:                        try {
406:                            bytes = res.getBytes("UTF-8");
407:                        } catch (java.io.UnsupportedEncodingException ue) {
408:                            //This may never happen because utf-8 is always supported!
409:                            bytes = res.getBytes();
410:                        }
411:                        System.out.write(bytes, 0, bytes.length);
412:                    } else {
413:                        throw new DPAException("errorNotFound");
414:                    }
415:                    break;
416:
417:                case SUBCMD_MERGE:
418:                    DPAMerge dpag = new DPAMerge();
419:                    res = dpag.process(adc, dn, global, name, verbose, null);
420:                    if (res != null) {
421:                        byte[] bytes = null;
422:                        try {
423:                            bytes = res.getBytes("UTF-8");
424:                        } catch (java.io.UnsupportedEncodingException ue) {
425:                            //This may never happen because utf-8 is always supported!
426:                            bytes = res.getBytes();
427:                        }
428:                        System.out.write(bytes, 0, bytes.length);
429:                    } else {
430:                        throw new DPAException("errorNotFound");
431:                    }
432:                    break;
433:
434:                case SUBCMD_MODIFY:
435:                    DPAModify dpam = new DPAModify();
436:                    try {
437:                        dpam.process(adc, dn, global, parent, combine,
438:                                xmlByteStreams, verbose, dryrun, null);
439:                    } finally {
440:                        try {
441:                            for (int i = 0; i < xmlByteStreams.length; i++) {
442:                                xmlByteStreams[i].close();
443:                            }
444:                        } catch (IOException ioe) {
445:                            throw new DPAException("errorStreamClose", ioe);
446:                        }
447:                    }
448:                    if (!dryrun) {
449:                        System.out.println(DPAUtil
450:                                .getLocalizedString("msgSuccess"));
451:                    } else {
452:                        System.out.println(DPAUtil
453:                                .getLocalizedString("msgDryrunSuccess"));
454:                    }
455:                    break;
456:
457:                case SUBCMD_ADD:
458:                    DPAAdd dpaa = new DPAAdd();
459:                    try {
460:                        dpaa.process(adc, dn, global, parent, xmlByteStreams,
461:                                verbose, dryrun, null);
462:                    } finally {
463:                        try {
464:                            for (int i = 0; i < xmlByteStreams.length; i++) {
465:                                xmlByteStreams[i].close();
466:                            }
467:                        } catch (IOException ioe) {
468:                            throw new DPAException("errorStreamClose", ioe);
469:                        }
470:                    }
471:                    if (!dryrun) {
472:                        System.out.println(DPAUtil
473:                                .getLocalizedString("msgSuccess"));
474:                    } else {
475:                        System.out.println(DPAUtil
476:                                .getLocalizedString("msgDryrunSuccess"));
477:                    }
478:                    break;
479:
480:                case SUBCMD_REMOVE:
481:                    DPARemove dpar = new DPARemove();
482:                    dpar.process(adc, dn, global, parent, name, type, verbose,
483:                            dryrun, null);
484:                    if (!dryrun) {
485:                        System.out.println(DPAUtil
486:                                .getLocalizedString("msgSuccess"));
487:                    } else {
488:                        System.out.println(DPAUtil
489:                                .getLocalizedString("msgDryrunSuccess"));
490:                    }
491:                    break;
492:
493:                default:
494:                    Object[] tokens = { new Integer(subcmd) };
495:                    throw new DPAException("errorInvalidSubCmd", tokens);
496:                }
497:            }
498:
499:            protected AdminDPContext doAuth() throws DPAException {
500:                if (verbose) {
501:                    logger.log(Level.FINEST, "PSDT_CSPDDC0018");
502:                }
503:
504:                String propertiesFile = System
505:                        .getProperty("desktop.propertiesFile");
506:                if (propertiesFile == null) {
507:                    throw new DPAException("errorProperties");
508:                }
509:
510:                AdminDPContext adc = null;
511:                try {
512:                    //adc = getAdminDPContext(propertiesFile);
513:                    adc = new DSAMEAdminDPContext();
514:                    adc.init(uid, password, null, ResourceLoader.getInstance(
515:                            System.getProperties()).getPortalId());
516:                } catch (ContextError ce) {
517:                    throw new DPAException("errorAuthFailed", ce);
518:                }
519:                return adc;
520:            }
521:
522:            private AdminDPContext getAdminDPContext(String propertiesFile)
523:                    throws DPAException {
524:                Properties desktopProps = new Properties();
525:                try {
526:                    desktopProps.load(new FileInputStream(propertiesFile));
527:                } catch (FileNotFoundException fnfe) {
528:                    throw new DPAException("DPACommand.getAdminDPContext() ",
529:                            fnfe);
530:                } catch (IOException ioe) {
531:                    throw new DPAException("DPACommand.getAdminDPContext() ",
532:                            ioe);
533:                }
534:
535:                String adminDPContextClassName = desktopProps
536:                        .getProperty(AdminDPContext.ADMINDPCONTEXTCLASSNAME_KEY);
537:                AdminDPContext adc = null;
538:
539:                try {
540:                    adc = (AdminDPContext) (Class
541:                            .forName(adminDPContextClassName).newInstance());
542:                } catch (ClassNotFoundException cnfe) {
543:                    throw new DPAException("DPACommand.getAdminDPContext()",
544:                            cnfe);
545:                } catch (NoClassDefFoundError ncdfe) {
546:                    throw new DPAException("DPACommand.getAdminDPContext()",
547:                            ncdfe);
548:                } catch (IllegalAccessException iae) {
549:                    throw new DPAException("DPACommand.getAdminDPContext()",
550:                            iae);
551:                } catch (ClassCastException cce) {
552:                    throw new DPAException("DPACommand.getAdminDPContext()",
553:                            cce);
554:                } catch (InstantiationException ie) {
555:                    throw new DPAException("DPACommand.getAdminDPContext()", ie);
556:                } catch (SecurityException se) {
557:                    throw new DPAException("DPACommand.getAdminDPContext()", se);
558:                }
559:
560:                return adc;
561:            }
562:
563:            protected static CLIPParser getCLIPParser(boolean batchMode)
564:                    throws CLIPException {
565:
566:                CLIPParser.SubCommand[] subcmds = null;
567:
568:                CLIPParser.Option[] optsList = {
569:                        new CLIPParser.Option(HELP, "?", CLIPParser.BOOLEAN,
570:                                "false", DPAUtil.getLocalizedString("optHelp")),
571:                        new CLIPParser.Option(UID, "u", CLIPParser.REGULAR,
572:                                (batchMode ? OPT_DEFAULT : null), DPAUtil
573:                                        .getLocalizedString("optArgUID"),
574:                                DPAUtil.getLocalizedString("optUID")),
575:                        new CLIPParser.Option(PASSWORD, "w",
576:                                CLIPParser.REGULAR, (batchMode ? OPT_DEFAULT
577:                                        : null), DPAUtil
578:                                        .getLocalizedString("optArgPassword"),
579:                                DPAUtil.getLocalizedString("optPassword")),
580:                        new CLIPParser.Option(DN, "d", CLIPParser.REGULAR,
581:                                OPT_DEFAULT, DPAUtil
582:                                        .getLocalizedString("optArgDN"),
583:                                DPAUtil.getLocalizedString("optDN")),
584:                        new CLIPParser.Option(GLOBAL, "g", CLIPParser.BOOLEAN,
585:                                "false", DPAUtil
586:                                        .getLocalizedString("optGlobal")),
587:                        new CLIPParser.Option(NAME, "n", CLIPParser.REGULAR,
588:                                OPT_DEFAULT, DPAUtil
589:                                        .getLocalizedString("optArgName"),
590:                                DPAUtil.getLocalizedString("optName")),
591:                        new CLIPParser.Option(VERBOSE, "b", CLIPParser.BOOLEAN,
592:                                "false", DPAUtil
593:                                        .getLocalizedString("optVerbose")),
594:                        new CLIPParser.Option(VERSION, "V", CLIPParser.BOOLEAN,
595:                                "false", DPAUtil
596:                                        .getLocalizedString("optVersion")),
597:                        new CLIPParser.Option(LOCALE, "l", CLIPParser.REGULAR,
598:                                LOCALE_DEFAULT, DPAUtil
599:                                        .getLocalizedString("optArgLocale"),
600:                                DPAUtil.getLocalizedString("optLocale")),
601:                        new CLIPParser.Option(DRYRUN, "r", CLIPParser.BOOLEAN,
602:                                "false", DPAUtil
603:                                        .getLocalizedString("optDryrun")) };
604:                CLIPParser.SubCommand scList = new CLIPParser.SubCommand(LIST,
605:                        optsList, 0, 0, DPAUtil.getLocalizedString("helpList"),
606:                        "");
607:
608:                CLIPParser.Option[] optsMerge = {
609:                        new CLIPParser.Option(HELP, "?", CLIPParser.BOOLEAN,
610:                                "false", DPAUtil.getLocalizedString("optHelp")),
611:                        new CLIPParser.Option(UID, "u", CLIPParser.REGULAR,
612:                                (batchMode ? OPT_DEFAULT : null), DPAUtil
613:                                        .getLocalizedString("optArgUID"),
614:                                DPAUtil.getLocalizedString("optUID")),
615:                        new CLIPParser.Option(PASSWORD, "w",
616:                                CLIPParser.REGULAR, (batchMode ? OPT_DEFAULT
617:                                        : null), DPAUtil
618:                                        .getLocalizedString("optArgPassword"),
619:                                DPAUtil.getLocalizedString("optPassword")),
620:                        new CLIPParser.Option(DN, "d", CLIPParser.REGULAR,
621:                                OPT_DEFAULT, DPAUtil
622:                                        .getLocalizedString("optArgDN"),
623:                                DPAUtil.getLocalizedString("optDN")),
624:                        new CLIPParser.Option(GLOBAL, "g", CLIPParser.BOOLEAN,
625:                                "false", DPAUtil
626:                                        .getLocalizedString("optGlobal")),
627:                        new CLIPParser.Option(NAME, "n", CLIPParser.REGULAR,
628:                                OPT_DEFAULT, DPAUtil
629:                                        .getLocalizedString("optArgName"),
630:                                DPAUtil.getLocalizedString("optName")),
631:                        new CLIPParser.Option(VERBOSE, "b", CLIPParser.BOOLEAN,
632:                                "false", DPAUtil
633:                                        .getLocalizedString("optVerbose")),
634:                        new CLIPParser.Option(VERSION, "V", CLIPParser.BOOLEAN,
635:                                "false", DPAUtil
636:                                        .getLocalizedString("optVersion")),
637:                        new CLIPParser.Option(LOCALE, "l", CLIPParser.REGULAR,
638:                                LOCALE_DEFAULT, DPAUtil
639:                                        .getLocalizedString("optArgLocale"),
640:                                DPAUtil.getLocalizedString("optLocale")),
641:                        new CLIPParser.Option(DRYRUN, "r", CLIPParser.BOOLEAN,
642:                                "false", DPAUtil
643:                                        .getLocalizedString("optDryrun")) };
644:                CLIPParser.SubCommand scMerge = new CLIPParser.SubCommand(
645:                        MERGE, optsMerge, 0, 0, DPAUtil
646:                                .getLocalizedString("helpMerge"), "");
647:
648:                CLIPParser.Option[] optsModify = {
649:                        new CLIPParser.Option(HELP, "?", CLIPParser.BOOLEAN,
650:                                "false", DPAUtil.getLocalizedString("optHelp")),
651:                        new CLIPParser.Option(UID, "u", CLIPParser.REGULAR,
652:                                (batchMode ? OPT_DEFAULT : null), DPAUtil
653:                                        .getLocalizedString("optArgUID"),
654:                                DPAUtil.getLocalizedString("optUID")),
655:                        new CLIPParser.Option(PASSWORD, "w",
656:                                CLIPParser.REGULAR, (batchMode ? OPT_DEFAULT
657:                                        : null), DPAUtil
658:                                        .getLocalizedString("optArgPassword"),
659:                                DPAUtil.getLocalizedString("optPassword")),
660:                        new CLIPParser.Option(DN, "d", CLIPParser.REGULAR,
661:                                OPT_DEFAULT, DPAUtil
662:                                        .getLocalizedString("optArgDN"),
663:                                DPAUtil.getLocalizedString("optDN")),
664:                        new CLIPParser.Option(GLOBAL, "g", CLIPParser.BOOLEAN,
665:                                "false", DPAUtil
666:                                        .getLocalizedString("optGlobal")),
667:                        new CLIPParser.Option(PARENT, "p", CLIPParser.REGULAR,
668:                                OPT_DEFAULT, DPAUtil
669:                                        .getLocalizedString("optArgParent"),
670:                                DPAUtil.getLocalizedString("optParent")),
671:                        new CLIPParser.Option(COMBINE, "m", CLIPParser.BOOLEAN,
672:                                "false", DPAUtil
673:                                        .getLocalizedString("optCombine")),
674:                        new CLIPParser.Option(VERBOSE, "b", CLIPParser.BOOLEAN,
675:                                "false", DPAUtil
676:                                        .getLocalizedString("optVerbose")),
677:                        new CLIPParser.Option(VERSION, "V", CLIPParser.BOOLEAN,
678:                                "false", DPAUtil
679:                                        .getLocalizedString("optVersion")),
680:                        new CLIPParser.Option(LOCALE, "l", CLIPParser.REGULAR,
681:                                LOCALE_DEFAULT, DPAUtil
682:                                        .getLocalizedString("optArgLocale"),
683:                                DPAUtil.getLocalizedString("optLocale")),
684:                        new CLIPParser.Option(DRYRUN, "r", CLIPParser.BOOLEAN,
685:                                "false", DPAUtil
686:                                        .getLocalizedString("optDryrun")) };
687:                CLIPParser.SubCommand scModify = new CLIPParser.SubCommand(
688:                        MODIFY, optsModify, 0, Integer.MAX_VALUE, DPAUtil
689:                                .getLocalizedString("helpModify"), DPAUtil
690:                                .getLocalizedString("helpFile"));
691:
692:                CLIPParser.Option[] optsAdd = {
693:                        new CLIPParser.Option(HELP, "?", CLIPParser.BOOLEAN,
694:                                "false", DPAUtil.getLocalizedString("optHelp")),
695:                        new CLIPParser.Option(UID, "u", CLIPParser.REGULAR,
696:                                (batchMode ? OPT_DEFAULT : null), DPAUtil
697:                                        .getLocalizedString("optArgUID"),
698:                                DPAUtil.getLocalizedString("optUID")),
699:                        new CLIPParser.Option(PASSWORD, "w",
700:                                CLIPParser.REGULAR, (batchMode ? OPT_DEFAULT
701:                                        : null), DPAUtil
702:                                        .getLocalizedString("optArgPassword"),
703:                                DPAUtil.getLocalizedString("optPassword")),
704:                        new CLIPParser.Option(DN, "d", CLIPParser.REGULAR,
705:                                OPT_DEFAULT, DPAUtil
706:                                        .getLocalizedString("optArgDN"),
707:                                DPAUtil.getLocalizedString("optDN")),
708:                        new CLIPParser.Option(GLOBAL, "g", CLIPParser.BOOLEAN,
709:                                "false", DPAUtil
710:                                        .getLocalizedString("optGlobal")),
711:                        new CLIPParser.Option(PARENT, "p", CLIPParser.REGULAR,
712:                                OPT_DEFAULT, DPAUtil
713:                                        .getLocalizedString("optArgParent"),
714:                                DPAUtil.getLocalizedString("optParent")),
715:                        new CLIPParser.Option(VERBOSE, "b", CLIPParser.BOOLEAN,
716:                                "false", DPAUtil
717:                                        .getLocalizedString("optVerbose")),
718:                        new CLIPParser.Option(VERSION, "V", CLIPParser.BOOLEAN,
719:                                "false", DPAUtil
720:                                        .getLocalizedString("optVersion")),
721:                        new CLIPParser.Option(LOCALE, "l", CLIPParser.REGULAR,
722:                                LOCALE_DEFAULT, DPAUtil
723:                                        .getLocalizedString("optArgLocale"),
724:                                DPAUtil.getLocalizedString("optLocale")),
725:                        new CLIPParser.Option(DRYRUN, "r", CLIPParser.BOOLEAN,
726:                                "false", DPAUtil
727:                                        .getLocalizedString("optDryrun")) };
728:
729:                CLIPParser.SubCommand scAdd = new CLIPParser.SubCommand(ADD,
730:                        optsAdd, 0, Integer.MAX_VALUE, DPAUtil
731:                                .getLocalizedString("helpAdd"), DPAUtil
732:                                .getLocalizedString("helpFile"));
733:
734:                CLIPParser.Option[] optsRemove = {
735:                        new CLIPParser.Option(HELP, "?", CLIPParser.BOOLEAN,
736:                                "false", DPAUtil.getLocalizedString("optHelp")),
737:                        new CLIPParser.Option(UID, "u", CLIPParser.REGULAR,
738:                                (batchMode ? OPT_DEFAULT : null), DPAUtil
739:                                        .getLocalizedString("optArgUID"),
740:                                DPAUtil.getLocalizedString("optUID")),
741:                        new CLIPParser.Option(PASSWORD, "w",
742:                                CLIPParser.REGULAR, (batchMode ? OPT_DEFAULT
743:                                        : null), DPAUtil
744:                                        .getLocalizedString("optArgPassword"),
745:                                DPAUtil.getLocalizedString("optPassword")),
746:                        new CLIPParser.Option(DN, "d", CLIPParser.REGULAR,
747:                                OPT_DEFAULT, DPAUtil
748:                                        .getLocalizedString("optArgDN"),
749:                                DPAUtil.getLocalizedString("optDN")),
750:                        new CLIPParser.Option(GLOBAL, "g", CLIPParser.BOOLEAN,
751:                                "false", DPAUtil
752:                                        .getLocalizedString("optGlobal")),
753:                        new CLIPParser.Option(NAME, "n", CLIPParser.REGULAR,
754:                                OPT_DEFAULT, DPAUtil
755:                                        .getLocalizedString("optArgName"),
756:                                DPAUtil.getLocalizedString("optName")),
757:                        new CLIPParser.Option(PARENT, "p", CLIPParser.REGULAR,
758:                                OPT_DEFAULT, DPAUtil
759:                                        .getLocalizedString("optArgParent"),
760:                                DPAUtil.getLocalizedString("optParent")),
761:                        new CLIPParser.Option(TYPE, "t", CLIPParser.REGULAR,
762:                                null, DPAUtil.getLocalizedString("optArgType"),
763:                                DPAUtil.getLocalizedString("optType")),
764:                        new CLIPParser.Option(VERBOSE, "b", CLIPParser.BOOLEAN,
765:                                "false", DPAUtil
766:                                        .getLocalizedString("optVerbose")),
767:                        new CLIPParser.Option(VERSION, "V", CLIPParser.BOOLEAN,
768:                                "false", DPAUtil
769:                                        .getLocalizedString("optVersion")),
770:                        new CLIPParser.Option(LOCALE, "l", CLIPParser.REGULAR,
771:                                LOCALE_DEFAULT, DPAUtil
772:                                        .getLocalizedString("optArgLocale"),
773:                                DPAUtil.getLocalizedString("optLocale")),
774:                        new CLIPParser.Option(DRYRUN, "r", CLIPParser.BOOLEAN,
775:                                "false", DPAUtil
776:                                        .getLocalizedString("optDryrun")) };
777:                CLIPParser.SubCommand scRemove = new CLIPParser.SubCommand(
778:                        REMOVE, optsRemove, 0, 0, DPAUtil
779:                                .getLocalizedString("helpRemove"), "");
780:
781:                if (!batchMode) {
782:                    CLIPParser.Option[] optsBatch = {
783:                            new CLIPParser.Option(HELP, "?",
784:                                    CLIPParser.BOOLEAN, "false", DPAUtil
785:                                            .getLocalizedString("optHelp")),
786:                            new CLIPParser.Option(UID, "u", CLIPParser.REGULAR,
787:                                    OPT_DEFAULT, DPAUtil
788:                                            .getLocalizedString("optArgUID"),
789:                                    DPAUtil.getLocalizedString("optUID")),
790:                            new CLIPParser.Option(
791:                                    PASSWORD,
792:                                    "w",
793:                                    CLIPParser.REGULAR,
794:                                    OPT_DEFAULT,
795:                                    DPAUtil
796:                                            .getLocalizedString("optArgPassword"),
797:                                    DPAUtil.getLocalizedString("optPassword")),
798:                            new CLIPParser.Option(CONT, "c",
799:                                    CLIPParser.BOOLEAN, "false", DPAUtil
800:                                            .getLocalizedString("optCont")),
801:                            new CLIPParser.Option(FILE, "f",
802:                                    CLIPParser.REGULAR, null, DPAUtil
803:                                            .getLocalizedString("optArgFile"),
804:                                    DPAUtil.getLocalizedString("optFile")),
805:                            new CLIPParser.Option(VERBOSE, "b",
806:                                    CLIPParser.BOOLEAN, "false", DPAUtil
807:                                            .getLocalizedString("optVerbose")),
808:                            new CLIPParser.Option(VERSION, "V",
809:                                    CLIPParser.BOOLEAN, "false", DPAUtil
810:                                            .getLocalizedString("optVersion")),
811:                            new CLIPParser.Option(LOCALE, "l",
812:                                    CLIPParser.REGULAR, LOCALE_DEFAULT,
813:                                    DPAUtil.getLocalizedString("optArgLocale"),
814:                                    DPAUtil.getLocalizedString("optLocale")) };
815:                    CLIPParser.SubCommand scBatch = new CLIPParser.SubCommand(
816:                            BATCH, optsBatch, 0, 0, DPAUtil
817:                                    .getLocalizedString("helpBatch"), "");
818:                    CLIPParser.SubCommand[] sc = { scList, scMerge, scModify,
819:                            scAdd, scRemove, scBatch };
820:                    subcmds = sc;
821:
822:                } else {
823:                    // batch within batch not allowed
824:                    CLIPParser.SubCommand[] sc = { scList, scMerge, scModify,
825:                            scAdd, scRemove };
826:                    subcmds = sc;
827:                }
828:
829:                return new CLIPParser(DPAMain.COMMANDNAME, subcmds, DPAUtil
830:                        .getLocalizedString("helpCmd"));
831:            }
832:
833:            private String getVersionInfo() {
834:                ResourceBundle prodRB = PropertyResourceBundle
835:                        .getBundle("PSversion");
836:                StringBuffer vinfo = new StringBuffer();
837:                vinfo.append(DPAMain.COMMANDNAME).append(" (").append(
838:                        prodRB.getString("productname")).append(" ").append(
839:                        prodRB.getString("productversion")).append(") ")
840:                        .append(DPAMain.COMMANDVERSION);
841:                vinfo.append("\n").append(prodRB.getString("copyright"));
842:                return vinfo.toString();
843:            }
844:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.