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

Source Link

Document

Constructs a new exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:Main.java

public static final void writeXml(Transformer transformer, OutputStream outputEntry, Document document) {
    Assert.notNull(transformer, "Transformer required");
    Assert.notNull(outputEntry, "Output entry required");
    Assert.notNull(document, "Document required");

    transformer.setOutputProperty(OutputKeys.METHOD, "xml");

    try {/*  w w w.  j a v a2  s.co  m*/
        transformer.transform(new DOMSource(document), createUnixStreamResultForEntry(outputEntry));
    } catch (Exception ex) {
        throw new IllegalStateException(ex);
    }
}

From source file:com.qcadoo.mes.cmmsMachineParts.constants.ActionAppliesTo.java

public static ActionAppliesTo parseString(final String appliesTo) {
    if (StringUtils.isEmpty(appliesTo)) {
        return NONE;
    } else if ("01workstationOrSubassembly".equals(appliesTo)) {
        return WORKSTATION_OR_SUBASSEMBLY;
    } else if ("02workstationType".equals(appliesTo)) {
        return WORKSTATION_TYPE;
    }/*from   ww  w. ja  va2s  .c  o  m*/

    throw new IllegalStateException("Unsupported AppliesTo: " + appliesTo);
}

From source file:com.sun.socialsite.business.Factory.java

/**
 * Static accessor for the instance of SocialSite
 *//*w  w w .  ja va  2 s .  c  o  m*/
public static SocialSite getSocialSite() {
    if (socialSite == null) {
        throw new IllegalStateException("SocialSite has not been bootstrapped yet");
    }
    return ((threadLocalSocialSite.get() != null) ? threadLocalSocialSite.get() : socialSite);
}

From source file:Profiler.java

/**
 * Starts a profiling session// w  ww . j  a v  a  2  s .c  o  m
 */
public void startSession() {
    if (theRoutineStartTimes[0] >= 0)
        throw new IllegalStateException("Profiler session \"" + theName + "\" is already running");
    theRoutineStartTimes[0] = System.currentTimeMillis();
}

From source file:XMLUtils.java

/**
 * Returns the value of the given node./*  ww w  .j  a  va2  s .c o  m*/
 * @param base the element from where to search.
 * @param name of the element to get.
 * @return the value of this element.
 */
public static String getStringValueElement(final Element base, final String name) {
    String value = null;

    // Get element
    NodeList list = base.getElementsByTagName(name);
    if (list.getLength() == 1) {
        Element element = (Element) list.item(0);
        Node node = element.getFirstChild();
        if (node != null) {
            value = node.getNodeValue();
        }
    } else if (list.getLength() > 1) {
        throw new IllegalStateException("Element '" + name + "' on '" + base
                + "' should be unique but there are '" + list.getLength() + "' elements");
    }

    if (value != null) {
        value = value.trim();
    }
    return value;
}

From source file:Main.java

/**
 * Return the data stored in the cursor at the given index and given position
 * (ie the given row which the cursor is currently on) as null OR a String.
 * <p>/*  w  ww. j a v a2s  .c o  m*/
 * NB: Currently only checks for Strings, long, int, and double.
 *
 * @param c
 * @param i
 * @return
 */
@SuppressLint("NewApi")
public static String getIndexAsString(Cursor c, int i) {
    // If you add additional return types here be sure to modify the javadoc.
    if (i == -1)
        return null;
    if (c.isNull(i)) {
        return null;
    }
    switch (c.getType(i)) {
    case Cursor.FIELD_TYPE_STRING:
        return c.getString(i);
    case Cursor.FIELD_TYPE_FLOAT: {
        // the static version of this seems to have problems...
        Double d = c.getDouble(i);
        String v = d.toString();
        return v;
    }
    case Cursor.FIELD_TYPE_INTEGER: {
        // the static version of this seems to have problems...
        Long l = c.getLong(i);
        String v = l.toString();
        return v;
    }
    case Cursor.FIELD_TYPE_NULL:
        return c.getString(i);
    default:
    case Cursor.FIELD_TYPE_BLOB:
        throw new IllegalStateException("Unexpected data type in SQLite table");
    }
}

From source file:com.seyren.core.security.Token.java

public static String computeSignature(UserDetails userDetails, long expires) {
    StringBuilder signatureBuilder = new StringBuilder();
    signatureBuilder.append(userDetails.getUsername());
    signatureBuilder.append(":");
    signatureBuilder.append(expires);//from w  w w .j  ava2s  .co m
    signatureBuilder.append(":");
    signatureBuilder.append(userDetails.getPassword());
    signatureBuilder.append(":");
    signatureBuilder.append(Token.MAGIC_KEY);

    MessageDigest digest;
    try {
        digest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException("No MD5 algorithm available!");
    }

    return new String(Hex.encode(digest.digest(signatureBuilder.toString().getBytes())));
}

From source file:com.android.fastlibrary.volley.VolleyHelper.java

/**
 * @return Volley //from w w w. j  ava  2  s .com
 */
public static RequestQueue getRequestQueue() {
    if (requestQueue != null) {
        return requestQueue;
    } else {
        throw new IllegalStateException("RequestQueue not initialized");
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionRegistry.java

/**
 * Create the registry and store it in the context.
 *///from  w  ww. j  a v a2  s  .c o m
public static void createRegistry(ServletContext ctx, Collection<? extends Permission> permissions) {
    if (ctx == null) {
        throw new NullPointerException("ctx may not be null.");
    }
    if (permissions == null) {
        throw new NullPointerException("permissions may not be null.");
    }
    if (ctx.getAttribute(ATTRIBUTE_NAME) != null) {
        throw new IllegalStateException("PermissionRegistry has already been set.");
    }

    PermissionRegistry registry = new PermissionRegistry();
    registry.addPermissions(permissions);
    ctx.setAttribute(ATTRIBUTE_NAME, registry);
}

From source file:com.simiacryptus.mindseye.applications.HadoopUtil.java

/**
 * Gets files./*from w  w w .  j  a v  a  2  s. c  o  m*/
 *
 * @param file the file
 * @return the files
 */
public static List<CharSequence> getFiles(CharSequence file) {
    try {
        FileSystem fileSystem = getFileSystem(file);
        Path path = new Path(file.toString());
        if (!fileSystem.exists(path))
            throw new IllegalStateException(path + " does not exist");
        List<CharSequence> collect = toStream(fileSystem.listFiles(path, false)).map(FileStatus::getPath)
                .map(Path::toString).collect(Collectors.toList());
        collect.stream().forEach(child -> {
            try {
                if (!fileSystem.exists(new Path(child.toString())))
                    throw new IllegalStateException(child + " does not exist");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
        return collect;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}