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(String message, Throwable cause) 

Source Link

Document

Constructs a new exception with the specified detail message and cause.

Usage

From source file:Main.java

/** Creates a schema-unaware XML parser */
private static DocumentBuilder createSchemaUnawareParser() {

    try {//from  www.ja  va2  s . c om
        return createNamespaceAwareDocumentBuilderFactory().newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new IllegalStateException("No document builder found, probably Java is misconfigured!", e);
    }
}

From source file:ch.newscron.registration.UserRegistration.java

/**
 * Provides a connection to the database specified (see fields)
 * @return a Connection for the database
 *//*from  w ww.ja  va 2  s .  com*/
public static Connection connect() {
    try {
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection connection = DriverManager.getConnection(DBurl, username, password);
        return connection;
    } catch (SQLException e) {
        throw new IllegalStateException("Cannot connect the database! ", e);
    } catch (Exception ex) {
        Logger.getLogger(UserRegistration.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:com.homesoft.component.report.configuration.GlobalConfig.java

public GlobalConfig() {
    try {/*w w w .  j  a  v  a2s .c o m*/
        config = new PropertiesConfiguration("report-config.properties");
    } catch (Exception e) {
        throw new IllegalStateException("configuration error", e);
    }
}

From source file:com.apabi.qrcode.utils.DigestUtils.java

/**
 * md5, Hex???./*from  w  ww .j a  va 2  s  . co m*/
 */
public static String md5ToHex(final String input, final String charset) {
    byte[] digestResult;
    try {
        digestResult = digest(input.getBytes(charset), MD5);
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException("Security exception", e);
    }
    return EncodeUtils.hexEncode(digestResult);
}

From source file:com.iorga.iraj.util.QueryDSLUtils.java

@SuppressWarnings("unchecked")
public static <T extends Comparable<?>> OrderSpecifier<T> parseOrderSpecifier(final String orderByPath,
        final String orderByDirection, final Expression<?> baseExpression) {
    final String[] orderByPaths = orderByPath.split("\\.");
    Expression<?> listExpression = baseExpression;

    for (final String orderByPathElement : orderByPaths) {
        // get that public field part
        try {//  w w w  .  j a  v a 2 s . c o  m
            listExpression = (Expression<?>) listExpression.getClass().getField(orderByPathElement)
                    .get(listExpression);
        } catch (final Exception e) {
            throw new IllegalStateException("Cannot get " + listExpression + "." + orderByPathElement, e);
        }
    }

    if (StringUtils.equalsIgnoreCase(orderByDirection, "DESC")) {
        return ((ComparableExpressionBase<T>) listExpression).desc();
    } else {
        return ((ComparableExpressionBase<T>) listExpression).asc();
    }
}

From source file:Main.java

/** Creates an empty XML document. */
public static Document createEmptyDocument() {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;/*from  w ww  .j a va 2s .c  om*/
    try {
        builder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new IllegalStateException("No document builder found, probably Java is misconfigured!", e);
    }
    return builder.newDocument();
}

From source file:Main.java

/**
 * Convert the {@link Date} into a {@link XMLGregorianCalendar}.
 * /*from ww  w  . ja v a 2  s  .  c  o  m*/
 * Calls {@link DatatypeFactory#newInstance()} - if a {@link DatatypeConfigurationException}
 * is thrown it get's wrapped in the unchecked {@link IllegalStateException}.
 * 
 * @param date
 * @return the converted calendar
 * @throws IllegalStateException wrapping a {@link DatatypeConfigurationException}.
 */
public static XMLGregorianCalendar convertDateToXMLGregorianCalendar(final Date date) {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    try {
        return DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
    } catch (DatatypeConfigurationException e) {
        throw new IllegalStateException("unable to invoke DatatypeFactory.newInstance", e);
    }
}

From source file:Main.java

/**
 * Invokes the Cipher to perform encryption or decryption (depending on the
 * initialized mode).//from   ww  w .  jav  a2s  . co m
 */
public static int doFinal(Cipher cipher, byte[] input, int inputOffSet, int inputLen, byte[] ouput,
        int outputOffSet) {
    try {
        return cipher.doFinal(input, inputOffSet, inputLen, ouput, outputOffSet);
    } catch (IllegalBlockSizeException e) {
        throw new IllegalStateException("Unable to invoke Cipher due to illegal block size", e);
    } catch (BadPaddingException e) {
        throw new IllegalStateException("Unable to invoke Cipher due to bad padding", e);
    } catch (ShortBufferException e) {
        throw new IllegalStateException("Short Buffer Exception", e);
    }
}

From source file:javaslang.jackson.datatype.deserialize.SerializableDeserializer.java

@SuppressWarnings("unchecked")
private static <T> T deserialize(byte[] objectData) {
    try {// ww  w.  j  ava2s  .  com
        ObjectInputStream stream = new ObjectInputStream(new ByteArrayInputStream(objectData));
        return (T) stream.readObject();
    } catch (Exception x) {
        throw new IllegalStateException("Error deserializing object", x);
    }
}

From source file:com.amalto.core.storage.prepare.FullTextIndexCleaner.java

private static void doClean(Storage storage) {
    DataSource storageDataSource = storage.getDataSource();
    if (!(storageDataSource instanceof RDBMSDataSource)) {
        throw new IllegalArgumentException("Storage to clean does not seem to be a RDBMS storage.");
    }//  w w  w. ja  v a  2  s.  c o m

    RDBMSDataSource dataSource = (RDBMSDataSource) storageDataSource;
    if (dataSource.supportFullText()) {
        String dataSourceIndexDirectory = dataSource.getIndexDirectory();
        File indexDirectory = new File(dataSourceIndexDirectory + '/' + storage.getName());
        if (indexDirectory.exists()) {
            try {
                FileUtils.deleteDirectory(indexDirectory);
            } catch (IOException e) {
                throw new IllegalStateException(
                        "Could not successfully delete '" + indexDirectory.getAbsolutePath() + "'", e);
            }
        } else {
            LOGGER.warn("Directory '" + dataSourceIndexDirectory
                    + "' does not exist. No need to clean full text indexes.");
        }
    }
}