Example usage for java.lang IllegalStateException IllegalStateException

List of usage examples for java.lang IllegalStateException IllegalStateException

Introduction

In this page you can find the example usage for java.lang IllegalStateException IllegalStateException.

Prototype

public IllegalStateException() 

Source Link

Document

Constructs an IllegalStateException with no detail message.

Usage

From source file:at.peppol.smp.client.console.SMPClient.java

public static void main(final String[] args) throws Exception {
    if (false) {//from ww  w  .j a  va2 s  .c  o m
        // Enable this section in development mode, if you want to trust all HTTPS
        // certificates
        final SSLContext aSSLContext = SSLContext.getInstance("SSL");
        aSSLContext.init(null, new TrustManager[] { new DoNothingTrustManager() },
                VerySecureRandom.getInstance());
        HttpsURLConnection.setDefaultSSLSocketFactory(aSSLContext.getSocketFactory());
    }

    final SMPClientOptions aOptions = new SMPClientOptions();
    final CommandLine cmd = new PosixParser().parse(aOptions, args);

    ECommand eAction = null;
    boolean bGoodCmd = true;
    String cert = null;

    if (!cmd.hasOption("h")) {
        s_aLogger.error("No Host specified use -h to specify Host");
        bGoodCmd = false;
    }

    if (!cmd.hasOption("u")) {
        s_aLogger.error("No Username specified use -u to specify username");
        bGoodCmd = false;
    }

    if (!cmd.hasOption("p")) {
        s_aLogger.error("No Password specified use -p to specify password");
        bGoodCmd = false;
    }

    if (!cmd.hasOption("c")) {
        s_aLogger.error("No Action specified please use -c parameter to specify command("
                + ECommand.getAllAsString() + ")");
        bGoodCmd = false;
    } else {
        final String sCommand = cmd.getOptionValue("c");
        eAction = ECommand.getFromNameOrNull(sCommand);
        if (eAction == null) {
            s_aLogger.error("Illegal Action specified:" + sCommand + " allowed commands("
                    + ECommand.getAllAsString() + ")");
            bGoodCmd = false;
        } else
            switch (eAction) {
            case ADDGROUP:
                if (!cmd.hasOption("b")) {
                    s_aLogger.error(
                            "No Business/Participant ID specified use -b to specify Business/Participant ID");
                    bGoodCmd = false;
                }
                break;
            case DELGROUP:
                if (!cmd.hasOption("b")) {
                    s_aLogger.error(
                            "No Business/Participant ID specified use -b to specify Business/Participant ID");
                    bGoodCmd = false;
                }
                break;
            case ADD:
                if (!cmd.hasOption("a")) {
                    s_aLogger.error("No Accesspoint URL defined use -a to Specifify AP-URL");
                    bGoodCmd = false;
                }
                if (!cmd.hasOption("b")) {
                    s_aLogger.error(
                            "No Business/Participant ID specified use -b to specify Business/Participant ID");
                    bGoodCmd = false;
                }
                if (!cmd.hasOption("d")) {
                    s_aLogger.error("No DocumentType ID specified use -d to specify Document Type ID");
                    bGoodCmd = false;
                }
                if (!cmd.hasOption("r")) {
                    s_aLogger.error("No Process ID specified use -r to specify Process ID");
                    bGoodCmd = false;
                }
                if (!cmd.hasOption("e")) {
                    s_aLogger.error("No Certificate PEM file specified use -e to specify Certificate PEM file");
                    bGoodCmd = false;
                } else {
                    cert = SimpleFileIO.readFileAsString(new File(cmd.getOptionValue('e')),
                            CCharset.CHARSET_ISO_8859_1);
                }
                break;
            case DEL:
                if (!cmd.hasOption("b")) {
                    s_aLogger.error(
                            "No Business/Participant ID specified use -b to specify Business/Participant ID");
                    bGoodCmd = false;
                }
                if (!cmd.hasOption("d")) {
                    s_aLogger.error("No Document Type ID specified use -d to specify Document Type ID");
                    bGoodCmd = false;
                }
            }
    }

    if (!bGoodCmd) {
        final NonBlockingStringWriter aSW = new NonBlockingStringWriter();
        new HelpFormatter().printHelp(new PrintWriter(aSW), HelpFormatter.DEFAULT_WIDTH,
                CGStringHelper.getClassLocalName(SMPClient.class), null, aOptions,
                HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null);
        s_aLogger.info(aSW.getAsString());
        System.exit(-3);
    }

    final SMPClient client = new SMPClient(new URI(cmd.getOptionValue('h')), cmd.getOptionValue('u'),
            cmd.getOptionValue('p'), cmd.getOptionValue('b'), cmd.getOptionValue('d'), cmd.getOptionValue('r'),
            cmd.getOptionValue('a'), cert);

    switch (eAction) {
    case ADDGROUP:
        client._createServiceGroup();
        break;
    case DELGROUP:
        client._deleteServiceGroup();
        break;
    case ADD:
        client._addDocument();
        break;
    case DEL:
        client._deleteDocument();
        break;
    case LIST:
        client._listDocuments();
        break;
    default:
        throw new IllegalStateException();
    }
}

From source file:com.microsoft.tfs.client.common.ui.framework.diagnostics.InternalSupportUtils.java

public static String promptForExportFile(final Shell shell) {
    final FileDialog dlg = new FileDialog(shell, SWT.SAVE);
    dlg.setFilterNames(new String[] { "*.zip" //$NON-NLS-1$
    });/*from  w w  w.j a  v a  2  s. c o m*/
    dlg.setFilterExtensions(new String[] { "*.zip" //$NON-NLS-1$
    });

    final SupportProvider supportProvider = SupportManager.getInstance().getSupportProviderCache()
            .getSupportProvider();
    if (supportProvider == null) {
        throw new IllegalStateException();
    }
    final SimpleDateFormat dateFormat = new SimpleDateFormat(EXPORT_FILE_DATE_FORMAT);
    final String name = supportProvider.getExportFilenamePrefix() + dateFormat.format(new Date()) + ".zip"; //$NON-NLS-1$

    dlg.setFileName(name);
    dlg.setText(Messages.getString("InternalSupportUtils.DialogTitle")); //$NON-NLS-1$
    return dlg.open();
}

From source file:Main.java

/**
 * Returns an iterator over the values referenced by the elements of {@code
 * iterable}.//from   w w w  . ja  v a2  s .c  o m
 *
 * @param trim true to remove reference objects from the iterable after
 *     their referenced values have been cleared.
 */
public static <T> Iterable<T> dereferenceIterable(final Iterable<? extends Reference<T>> iterable,
        final boolean trim) {
    return new Iterable<T>() {
        public Iterator<T> iterator() {
            return new Iterator<T>() {
                private final Iterator<? extends Reference<T>> delegate = iterable.iterator();
                private boolean removeIsOkay;
                private T next;

                private void computeNext() {
                    removeIsOkay = false;
                    while (next == null && delegate.hasNext()) {
                        next = delegate.next().get();
                        if (trim && next == null) {
                            delegate.remove();
                        }
                    }
                }

                @Override
                public boolean hasNext() {
                    computeNext();
                    return next != null;
                }

                @Override
                public T next() {
                    if (!hasNext()) {
                        throw new IllegalStateException();
                    }
                    T result = next;
                    removeIsOkay = true;
                    next = null;
                    return result;
                }

                public void remove() {
                    if (!removeIsOkay) {
                        throw new IllegalStateException();
                    }
                    delegate.remove();
                }
            };
        }
    };
}