Example usage for java.lang IllegalStateException initCause

List of usage examples for java.lang IllegalStateException initCause

Introduction

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

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

From source file:org.apache.jackrabbit.core.persistence.bundle.BundleDbPersistenceManager.java

/**
 * Returns the local name index/*  www .j  a  v a  2  s.  com*/
 * @return the local name index
 * @throws IllegalStateException if an error occurs.
 */
public StringIndex getNameIndex() {
    try {
        if (nameIndex == null) {
            FileSystemResource res = new FileSystemResource(context.getFileSystem(), RES_NAME_INDEX);
            if (res.exists()) {
                nameIndex = super.getNameIndex();
            } else {
                // create db nameindex
                nameIndex = createDbNameIndex();
            }
        }
        return nameIndex;
    } catch (Exception e) {
        IllegalStateException exception = new IllegalStateException("Unable to create nsIndex");
        exception.initCause(e);
        throw exception;
    }
}

From source file:org.apache.karaf.jms.pool.internal.PooledSession.java

@Override
public void close() throws JMSException {
    if (!ignoreClose) {
        boolean invalidate = false;
        try {/* ww  w . j  a v a  2  s.c om*/
            // lets reset the session
            getInternalSession().setMessageListener(null);

            // Close any consumers and browsers that may have been created.
            for (MessageConsumer consumer : consumers) {
                consumer.close();
            }

            for (QueueBrowser browser : browsers) {
                browser.close();
            }

            if (transactional && !isXa) {
                try {
                    getInternalSession().rollback();
                } catch (JMSException e) {
                    invalidate = true;
                    LOG.warn(
                            "Caught exception trying rollback() when putting session back into the pool, will invalidate. "
                                    + e,
                            e);
                }
            }
        } catch (JMSException ex) {
            invalidate = true;
            LOG.warn(
                    "Caught exception trying close() when putting session back into the pool, will invalidate. "
                            + ex,
                    ex);
        } finally {
            consumers.clear();
            browsers.clear();
            for (PooledSessionEventListener listener : this.sessionEventListeners) {
                listener.onSessionClosed(this);
            }
            sessionEventListeners.clear();
        }

        if (invalidate) {
            // lets close the session and not put the session back into the pool
            // instead invalidate it so the pool can create a new one on demand.
            if (session != null) {
                try {
                    session.close();
                } catch (JMSException e1) {
                    LOG.trace("Ignoring exception on close as discarding session: " + e1, e1);
                }
                session = null;
            }
            try {
                sessionPool.invalidateObject(key, this);
            } catch (Exception e) {
                LOG.trace("Ignoring exception on invalidateObject as discarding session: " + e, e);
            }
        } else {
            try {
                sessionPool.returnObject(key, this);
            } catch (Exception e) {
                javax.jms.IllegalStateException illegalStateException = new javax.jms.IllegalStateException(
                        e.toString());
                illegalStateException.initCause(e);
                throw illegalStateException;
            }
        }
    }
}

From source file:org.apache.struts2.jasper.runtime.PageContextImpl.java

private void doForward(String relativeUrlPath) throws ServletException, IOException {

    // JSP.4.5 If the buffer was flushed, throw IllegalStateException
    try {/*from ww  w . j ava 2 s . com*/
        out.clear();
    } catch (IOException ex) {
        IllegalStateException ise = new IllegalStateException(
                Localizer.getMessage("jsp.error.attempt_to_clear_flushed_buffer"));
        ise.initCause(ex);
        throw ise;
    }

    // Make sure that the response object is not the wrapper for include
    while (response instanceof ServletResponseWrapperInclude) {
        response = ((ServletResponseWrapperInclude) response).getResponse();
    }

    final String path = getAbsolutePathRelativeToContext(relativeUrlPath);
    String includeUri = (String) request.getAttribute(Constants.INC_SERVLET_PATH);

    if (includeUri != null)
        request.removeAttribute(Constants.INC_SERVLET_PATH);
    try {
        context.getRequestDispatcher(path).forward(request, response);
    } finally {
        if (includeUri != null)
            request.setAttribute(Constants.INC_SERVLET_PATH, includeUri);
        request.setAttribute(Constants.FORWARD_SEEN, "true");
    }
}

From source file:org.dhatim.cdr.SmooksResourceConfigurationStore.java

/**
* Load a Java Object defined by the supplied SmooksResourceConfiguration instance.
* @param resourceConfig SmooksResourceConfiguration instance.
* @return An Object instance from the SmooksResourceConfiguration.
*///  w ww .ja  v a2s.  c o m
public Object getObject(SmooksResourceConfiguration resourceConfig) {
    Object object = resourceConfig.getJavaResourceObject();

    if (object == null) {
        String className = ClasspathUtils.toClassName(resourceConfig.getResource());

        // Load the runtime class...
        Class classRuntime;
        try {
            classRuntime = ClassUtil.forName(className, getClass());
        } catch (ClassNotFoundException e) {
            IllegalStateException state = new IllegalStateException("Error loading Java class: " + className);
            state.initCause(e);
            throw state;
        }

        // Try constructing via a SmooksResourceConfiguration constructor...
        Constructor constructor;
        try {
            constructor = classRuntime.getConstructor(new Class[] { SmooksResourceConfiguration.class });
            object = constructor.newInstance(new Object[] { resourceConfig });
        } catch (NoSuchMethodException e) {
            // OK, we'll try a default constructor later...
        } catch (Exception e) {
            IllegalStateException state = new IllegalStateException("Error loading Java class: " + className);
            state.initCause(e);
            throw state;
        }

        // If we still don't have an object, try constructing via the default construtor...
        if (object == null) {
            try {
                object = classRuntime.newInstance();
            } catch (Exception e) {
                IllegalStateException state = new IllegalStateException("Java class " + className
                        + " must contain a default constructor if it does not contain a constructor that takes an instance of "
                        + SmooksResourceConfiguration.class.getName() + ".");
                state.initCause(e);
                throw state;
            }
        }

        if (object instanceof ContentHandler || object instanceof DataDecoder) {
            Configurator.configure(object, resourceConfig, applicationContext);
            initializedObjects.add(object);
        }

        resourceConfig.setJavaResourceObject(object);
    }

    return object;
}

From source file:org.displaytag.portlet.PortletHref.java

/**
 * @see org.displaytag.util.Href#toString()
 *//*from  w  w  w .j ava 2  s . co m*/
public String toString() {
    final PortletURL url;
    if (this.isAction()) {
        url = this.renderResponse.createActionURL();
    } else {
        url = this.renderResponse.createRenderURL();
    }

    if (this.isRequestedSecure()) {
        try {
            url.setSecure(true);
        } catch (PortletSecurityException pse) {
            throw new RuntimeException("Creating secure PortletURL Failed.", pse);
        }
    }

    if (this.getRequestedMode() != null) {
        try {
            url.setPortletMode(this.getRequestedMode());
        } catch (PortletModeException pme) {
            final IllegalStateException ise = new IllegalStateException(
                    "Requested PortletMode='" + this.getRequestedMode() + "' could not be set.");
            ise.initCause(pme);
            throw ise;
        }
    }

    if (this.getRequestedState() != null) {
        try {
            url.setWindowState(this.getRequestedState());
        } catch (WindowStateException wse) {
            final IllegalStateException ise = new IllegalStateException(
                    "Requested WindowState='" + this.getRequestedState() + "' could not be set.");
            ise.initCause(wse);
            throw ise;
        }
    }

    for (final Iterator paramItr = this.parameters.entrySet().iterator(); paramItr.hasNext();) {
        final Map.Entry entry = (Map.Entry) paramItr.next();

        final String name = (String) entry.getKey();
        final Object value = entry.getValue();

        if (value instanceof String) {
            url.setParameter(name, (String) value);
        } else if (value instanceof String[]) {
            url.setParameter(name, (String[]) value);
        }
    }

    if (this.getAnchor() == null) {
        return url.toString();
    } else {
        return url.toString() + "#" + this.getAnchor();
    }
}

From source file:org.milyn.edisax.EDIParser.java

/**
* Get the actual mapping configuration data (the XML).
* @param resourceLocator Resource locator used to open the config stream.
* @param mappingConfig Mapping config path.
* 
* @return The mapping configuration data stream.
*///  www  . j  a va  2s . c  o  m
private static InputStream getMappingConfigData(URIResourceLocator resourceLocator, String mappingConfig) {
    InputStream configStream = null;

    try {
        configStream = resourceLocator.getResource(mappingConfig);
    } catch (IOException e) {
        IllegalStateException state = new IllegalStateException(
                "Invalid EDI mapping model config specified for " + EDIParser.class.getName()
                        + ".  Unable to access URI based mapping model ["
                        + resourceLocator.resolveURI(mappingConfig) + "].");
        state.initCause(e);
        throw state;
    }

    return configStream;
}

From source file:org.mule.util.ClassUtils.java

/**
 * Ensure that the given class is properly initialized when the argument is passed in
 * as .class literal. This method can never fail unless the bytecode is corrupted or
 * the VM is otherwise seriously confused.
 *
 * @param clazz the Class to be initialized
 * @return the same class but initialized
 *///from   w  ww. jav a2 s .  c o  m
public static Class<?> initializeClass(Class<?> clazz) {
    try {
        return getClass(clazz.getName(), true);
    } catch (ClassNotFoundException e) {
        IllegalStateException ise = new IllegalStateException();
        ise.initCause(e);
        throw ise;
    }
}

From source file:org.springframework.richclient.application.support.DefaultPropertyEditorRegistry.java

private static PropertyEditor instantiatePropertyEditor(Class propEdClass) {
    try {//from  w w  w  . j  ava 2  s . co m
        return (PropertyEditor) propEdClass.newInstance();
    } catch (InstantiationException e) {
        IllegalStateException exp = new IllegalStateException("Could not instantiate " + propEdClass);
        exp.initCause(e);
        throw exp;
    } catch (IllegalAccessException e) {
        IllegalStateException exp = new IllegalStateException("Could not instantiate " + propEdClass);
        exp.initCause(e);
        throw exp;
    }
}

From source file:org.springframework.webflow.mvc.view.AbstractMvcView.java

public void render() throws IOException {
    Map<String, Object> model = new HashMap<String, Object>();
    model.putAll(flowScopes());//w w  w  .  java  2  s  .  c  o m
    exposeBindingModel(model);
    model.put("flowRequestContext", requestContext);
    FlowExecutionKey key = requestContext.getFlowExecutionContext().getKey();
    if (key != null) {
        model.put("flowExecutionKey", requestContext.getFlowExecutionContext().getKey().toString());
        model.put("flowExecutionUrl", requestContext.getFlowExecutionUrl());
    }
    model.put("currentUser", requestContext.getExternalContext().getCurrentUser());
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Rendering MVC [" + view + "] with model map [" + model + "]");
        }
        doRender(model);
    } catch (IOException e) {
        throw e;
    } catch (Exception e) {
        IllegalStateException ise = new IllegalStateException("Exception occurred rendering view " + view);
        ise.initCause(e);
        throw ise;
    }
}

From source file:org.tinygroup.jspengine.runtime.PageContextImpl.java

public void forward(String relativeUrlPath) throws ServletException, IOException {

    // JSP.4.5 If the buffer was flushed, throw IllegalStateException
    try {//from  w w  w .j  av  a2  s.c om
        out.clear();
    } catch (IOException ex) {
        IllegalStateException ise = new IllegalStateException(
                Localizer.getMessage("jsp.error.attempt_to_clear_flushed_buffer"));
        ise.initCause(ex);
        throw ise;
    }

    // Make sure that the response object is not the wrapper for include
    while (response instanceof ServletResponseWrapperInclude) {
        response = ((ServletResponseWrapperInclude) response).getResponse();
    }

    final String path = getAbsolutePathRelativeToContext(relativeUrlPath);
    String includeUri = (String) request.getAttribute(Constants.INC_SERVLET_PATH);

    final ServletResponse fresponse = response;
    final ServletRequest frequest = request;

    if (includeUri != null)
        request.removeAttribute(Constants.INC_SERVLET_PATH);
    try {
        context.getRequestDispatcher(path).forward(request, response);
    } finally {
        if (includeUri != null)
            request.setAttribute(Constants.INC_SERVLET_PATH, includeUri);
        request.setAttribute(Constants.FORWARD_SEEN, "true");
    }
}