001    /*
002     * file InstallCheck.java
003     *
004     * Licensed Materials - Property of IBM
005     * Restricted Materials of IBM - you are allowed to copy, modify and 
006     * redistribute this file as part of any program that interfaces with 
007     * IBM Rational CM API.
008     *
009     * com.ibm.rational.stp.client.samples.InstallCheck
010     *
011     * © Copyright IBM Corporation 2005, 2008.  All Rights Reserved.
012     * Note to U.S. Government Users Restricted Rights:  Use, duplication or 
013     * disclosure restricted by GSA ADP  Schedule Contract with IBM Corp.
014     */
015    package com.ibm.rational.stp.client.samples;
016    
017    import javax.wvcm.ProviderFactory;
018    
019    import com.ibm.rational.wvcm.stp.StpProvider;
020    import com.ibm.rational.wvcm.stp.cq.CqProvider;
021    
022    /**
023     * An application for testing proper installation of the CM API library for a
024     * specific repository type or types
025     */
026    public class InstallCheck {
027        /**
028         * Instantiates a provider and tests for successful instantiation of
029         * the repository types specified on the input command line.
030         * @param args The Selector symbols for the repository type(s) to be tested.
031         */
032        public static void main(String[] args)
033        {
034            int errors = 0;
035    
036            try {
037                StpProvider provider = (StpProvider) ProviderFactory
038                    .createProvider(StpProvider.PROVIDER_CLASS, null);
039                Package[] packages = Package.getPackages();
040                
041                for (int i = 0; i < args.length; ++i) {
042                    StpProvider.Domain type = StpProvider.Domain.fromSymbol(args[i]);
043                    Exception error = 
044                        (Exception)provider.getInstantiationErrors().get(type);
045        
046                    if (error != null) {
047                        ++errors;
048                        error.printStackTrace();
049                    } else {
050                        for (int j = 0; j < packages.length; ++j) {
051                            Package myPackage = packages[j];
052                            String name = myPackage.getName();
053                            
054                            if (name.indexOf("." + args[i]) >= 0
055                                && !name.startsWith("com.ibm.rational.wvcm")) {
056                                System.out.println(
057                                    "Instantiated " + name
058                                    + "  " + myPackage.getImplementationTitle()
059                                    + ", " + myPackage.getImplementationVersion()
060                                    + ", " + myPackage.getImplementationVendor());
061                            }
062                        }
063                    }
064                }
065            } catch (Throwable t) {
066                errors = 100;
067                t.printStackTrace();
068            }
069            
070            System.exit(errors);
071        }
072    }