001 /*
002 * file HelloWorld.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.HelloWorld
010 *
011 * (C) 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 java.util.ArrayList;
018 import java.util.List;
019 import java.util.Map;
020
021 import javax.swing.JOptionPane;
022 import javax.wvcm.ProviderFactory;
023
024 import com.ibm.rational.wvcm.stp.StpException;
025 import com.ibm.rational.wvcm.stp.StpProvider;
026 import com.ibm.rational.wvcm.stp.StpProvider.Domain;
027
028 /**
029 * Instantiates a CM API provider and reports what's installed and what's not
030 */
031 public class HelloWorld {
032 public static void main(String[] args) throws Exception {
033 boolean debug = args.length > 0 && args[0].equals("-debug");
034 StpProvider provider = (StpProvider) ProviderFactory
035 .createProvider(StpProvider.PROVIDER_CLASS, null);
036 ArrayList<String> about = new ArrayList<String>();
037
038 about.add(provider.getClass().getName() + ", version "
039 + provider.getClass().getPackage().getImplementationVersion());
040
041 // Identify which repository types have providers at this time
042 int failures = 0;
043 Map<Object, StpException> errors = provider.getInstantiationErrors();
044
045 for (Domain type: Domain.values()) {
046 if (type != Domain.NONE && type != Domain.INVALID) {
047 StpException error = errors.get(type);
048
049 if (error == null) {
050 about.add(" " + type.toString() + " -- OK");
051 } else {
052 ++failures;
053 about.add(" " + type.toString() + " -- " + error.toString());
054
055 if (debug)
056 error.printStackTrace();
057 }
058 }
059 }
060
061 List<String> seen = new ArrayList<String>();
062
063 for (Package myPackage: Package.getPackages()) {
064 String title = myPackage.getImplementationTitle();
065
066 if (title != null && title.length() > 0
067 && (debug || !seen.contains(title))) {
068 if (debug)
069 about.add(myPackage.getName());
070
071 about.add(" " + myPackage.getImplementationTitle()
072 + ", " + myPackage.getImplementationVersion());
073 seen.add(title);
074 }
075 }
076
077 JOptionPane.showMessageDialog(null, about.toArray(), "About CM API",
078 JOptionPane.INFORMATION_MESSAGE);
079 System.exit(failures);
080 }
081 }