Example usage for java.lang IllegalArgumentException initCause

List of usage examples for java.lang IllegalArgumentException initCause

Introduction

In this page you can find the example usage for java.lang IllegalArgumentException 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.apromore.helper.Version.java

/**
 * Creates a version identifier from the specified string.
 * <p/>//  ww  w .jav  a2  s.co  m
 * <p/>
 * Version string grammar:
 * <p/>
 * <pre>
 * version ::= major('.'minor('.'micro('.'qualifier)?)?)?
 * major ::= digit+
 * minor ::= digit+
 * micro ::= digit+
 * qualifier ::= (alpha|digit|'_'|'-')+
 * digit ::= [0..9]
 * alpha ::= [a..zA..Z]
 * </pre>
 *
 * @param version String representation of the version identifier. There
 *                must be no whitespace in the argument.
 * @throws IllegalArgumentException If {@code version} is improperly
 *                                  formatted.
 */
public Version(String version) {
    Integer maj;
    Integer min = null;
    Integer mic = null;
    String qual = "";

    try {
        StringTokenizer st = new StringTokenizer(version, SEPARATOR, true);
        maj = parseInt(st.nextToken(), version);

        if (st.hasMoreTokens()) { // minor
            st.nextToken(); // consume delimiter
            min = parseInt(st.nextToken(), version);

            if (st.hasMoreTokens()) { // micro
                st.nextToken(); // consume delimiter
                mic = parseInt(st.nextToken(), version);

                if (st.hasMoreTokens()) { // qualifier separator
                    st.nextToken(); // consume delimiter
                    qual = st.nextToken(""); // remaining string

                    if (st.hasMoreTokens()) { // fail safe
                        throw new IllegalArgumentException(
                                "invalid version \"" + version + "\": invalid format");
                    }
                }
            }
        }
    } catch (NoSuchElementException e) {
        IllegalArgumentException iae = new IllegalArgumentException(
                "invalid version \"" + version + "\": invalid format");
        iae.initCause(e);
        throw iae;
    }

    major = maj;
    minor = min;
    micro = mic;
    qualifier = qual;
    validate();
}

From source file:org.apromore.helper.Version.java

/**
 * Parse numeric component into an int.//from  w  w  w. j a  v  a2s  .c o m
 *
 * @param value   Numeric component
 * @param version Complete version string for exception message, if any
 * @return int value of numeric component
 */
private static int parseInt(String value, String version) {
    try {
        return Integer.parseInt(value);
    } catch (NumberFormatException e) {
        IllegalArgumentException iae = new IllegalArgumentException(
                "invalid version \"" + version + "\": non-numeric \"" + value + "\"");
        iae.initCause(e);
        throw iae;
    }
}

From source file:org.basket3.web.S3ObjectRequest.java

/**
 * Create an <code>S3Object</code> based on the request supporting virtual
 * hosting of buckets./*  w  ww  . j  a v  a  2  s .com*/
 * 
 * @param req
 *            The original request.
 * @param baseHost
 *            The <code>baseHost</code> is the HTTP Host header that is
 *            "expected". This is used to help determine how the bucket name
 *            will be interpreted. This is used to implement the "Virtual
 *            Hosting of Buckets".
 * @param authenticator
 *            The authenticator to use to authenticate this request.
 * @return An object initialized from the request.
 * @throws IllegalArgumentException
 *             Invalid request.
 */
@SuppressWarnings("unchecked")
public static S3ObjectRequest create(HttpServletRequest req, String baseHost, Authenticator authenticator)
        throws IllegalArgumentException, AuthenticatorException {
    S3ObjectRequest o = new S3ObjectRequest();
    String pathInfo = req.getPathInfo();
    String contextPath = req.getContextPath();
    String requestURI = req.getRequestURI();
    String undecodedPathPart = null;
    int pathInfoLength;
    String requestURL;
    String serviceEndpoint;
    String bucket = null;
    String key = null;
    String host;
    String value;
    String timestamp;

    baseHost = baseHost.toLowerCase();

    host = req.getHeader("Host");
    if (host != null) {
        host = host.toLowerCase();
    }

    try {
        requestURL = URLDecoder.decode(req.getRequestURL().toString(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        // should never happen
        e.printStackTrace();
        IllegalArgumentException t = new IllegalArgumentException("Unsupport encoding: UTF-8");
        t.initCause(e);
        throw t;
    }

    if (!requestURL.endsWith(pathInfo)) {
        String m = "requestURL [" + requestURL + "] does not end with pathInfo [" + pathInfo + "]";
        throw new IllegalArgumentException(m);
    }

    pathInfoLength = pathInfo.length();

    serviceEndpoint = requestURL.substring(0, requestURL.length() - pathInfoLength);

    if (debug) {
        System.out.println("---------------");
        System.out.println("requestURI: " + requestURI);
        System.out.println("serviceEndpoint: " + serviceEndpoint);
        System.out.println("---------------");
    }
    Preconditions.checkNotNull(contextPath, "Context path cannot be null");

    if ((host == null) || // http 1.0 form
            (host.equals(baseHost))) { // ordinary method
        // http 1.0 form
        // bucket first part of path info
        // key second part of path info
        if (pathInfoLength > 1) {
            int index = pathInfo.indexOf('/', 1);
            if (index > -1) {
                bucket = pathInfo.substring(1, index);

                if (pathInfoLength > (index + 1)) {
                    key = pathInfo.substring(index + 1);
                    undecodedPathPart = requestURI.substring(contextPath.length() + 1 + bucket.length(),
                            requestURI.length());
                }
            } else {
                bucket = pathInfo.substring(1);
            }
        }
    } else if (host.endsWith("." + baseHost)) {
        // bucket prefix of host
        // key is path info
        bucket = host.substring(0, host.length() - 1 - baseHost.length());
        if (pathInfoLength > 1) {
            key = pathInfo.substring(1);
            undecodedPathPart = requestURI.substring(contextPath.length(), requestURI.length());
        }
    } else {
        // bucket is host
        // key is path info
        bucket = host;
        if (pathInfoLength > 1) {
            key = pathInfo.substring(1);
            undecodedPathPart = requestURI.substring(contextPath.length(), requestURI.length());
        }
    }

    // timestamp
    timestamp = req.getHeader("Date");

    // CanonicalizedResource
    StringBuffer canonicalizedResource = new StringBuffer();

    canonicalizedResource.append('/');
    if (bucket != null) {
        canonicalizedResource.append(bucket);
    }
    if (undecodedPathPart != null) {
        canonicalizedResource.append(undecodedPathPart);
    }
    if (req.getParameter(PARAMETER_ACL) != null) {
        canonicalizedResource.append("?").append(PARAMETER_ACL);
    }

    // CanonicalizedAmzHeaders
    StringBuffer canonicalizedAmzHeaders = new StringBuffer();
    Map<String, String> headers = new TreeMap<String, String>();
    String headerName;
    String headerValue;

    Preconditions.checkNotNull(req.getHeaderNames(), "Http Request Header names cannot be null");

    for (Enumeration headerNames = req.getHeaderNames(); headerNames.hasMoreElements();) {
        headerName = ((String) headerNames.nextElement()).toLowerCase();

        if (headerName.startsWith("x-amz-")) {
            for (Enumeration headerValues = req.getHeaders(headerName); headerValues.hasMoreElements();) {
                headerValue = (String) headerValues.nextElement();
                String currentValue = headers.get(headerValue);

                if (currentValue != null) {
                    // combine header fields with the same name
                    headers.put(headerName, currentValue + "," + headerValue);
                } else {
                    headers.put(headerName, headerValue);
                }

                if (headerName.equals("x-amz-date")) {
                    timestamp = headerValue;
                }
            }
        }
    }

    for (Iterator<String> iter = headers.keySet().iterator(); iter.hasNext();) {
        headerName = iter.next();
        headerValue = headers.get(headerName);
        canonicalizedAmzHeaders.append(headerName).append(":").append(headerValue).append("\n");
    }

    StringBuffer stringToSign = new StringBuffer();

    stringToSign.append(req.getMethod()).append("\n");
    value = req.getHeader("Content-MD5");
    if (value != null) {
        stringToSign.append(value);
    }
    stringToSign.append("\n");
    value = req.getHeader("Content-Type");
    if (value != null) {
        stringToSign.append(value);
    }
    stringToSign.append("\n");
    value = req.getHeader("Date");
    if (value != null) {
        stringToSign.append(value);
    }
    stringToSign.append("\n");
    stringToSign.append(canonicalizedAmzHeaders);
    stringToSign.append(canonicalizedResource);

    if (debug) {
        System.out.println(":v:v:v:v:");
        System.out.println("undecodedPathPart: " + undecodedPathPart);
        System.out.println("canonicalizedAmzHeaders: " + canonicalizedAmzHeaders);
        System.out.println("canonicalizedResource: " + canonicalizedResource);
        System.out.println("stringToSign: " + stringToSign);
        System.out.println(":^:^:^:^:");
    }

    o.setServiceEndpoint(serviceEndpoint);
    o.setBucket(bucket);
    o.setKey(key);
    try {
        if (timestamp == null) {
            o.setTimestamp(null);
        } else {
            o.setTimestamp(DateUtil.parseDate(timestamp));
        }
    } catch (DateParseException e) {
        o.setTimestamp(null);
    }
    o.setStringToSign(stringToSign.toString());
    o.setRequestor(authenticate(req, o));

    return o;
}

From source file:org.codehaus.mojo.webstart.generator.AbstractGenerator.java

protected AbstractGenerator(Log log, GeneratorTechnicalConfig config, C extraConfig) {

    this.log = log;
    this.config = config;
    this.extraConfig = extraConfig;

    Properties props = new Properties();

    String inputFileTemplatePath = config.getInputFileTemplatePath();

    if (inputFileTemplatePath != null) {
        props.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS,
                "org.apache.velocity.runtime.log.NullLogSystem");
        props.setProperty("file.resource.loader.path", config.getResourceLoaderPath().getAbsolutePath());

        initVelocity(props);//from   w ww . j a  v a2  s.c  om

        if (!engine.templateExists(inputFileTemplatePath)) {
            log.warn("Warning, template not found. Will probably fail.");
        }
    } else {
        log.info("No template specified Using default one.");

        inputFileTemplatePath = config.getDefaultTemplateResourceName();

        String webstartJarURL = config.getWebstartJarURL();
        log.debug("***** Webstart JAR URL: " + webstartJarURL);

        props = new Properties();
        props.setProperty("resource.loader", "jar");
        props.setProperty("jar.resource.loader.description",
                "Jar resource loader for default webstart templates");
        props.setProperty("jar.resource.loader.class",
                "org.apache.velocity.runtime.resource.loader.JarResourceLoader");
        props.setProperty("jar.resource.loader.path", webstartJarURL);

        initVelocity(props);

        if (!engine.templateExists(inputFileTemplatePath)) {
            log.error("Inbuilt template not found!! " + config.getDefaultTemplateResourceName()
                    + " Will probably fail.");
        }
    }

    try {
        this.velocityTemplate = engine.getTemplate(inputFileTemplatePath, config.getEncoding());
    } catch (Exception e) {
        IllegalArgumentException iae = new IllegalArgumentException(
                "Could not load the template file from '" + inputFileTemplatePath + "'");
        iae.initCause(e);
        throw iae;
    }
}

From source file:org.codehaus.mojo.webstart.generator.AbstractGenerator.java

private void initVelocity(Properties props) {
    try {/*from   ww w.  ja  v  a 2 s  .c  o m*/
        engine = new VelocityEngine();
        engine.setProperty("runtime.log.logsystem", new NullLogSystem());
        engine.init(props);
    } catch (Exception e) {
        IllegalArgumentException iae = new IllegalArgumentException("Could not initialise Velocity");
        iae.initCause(e);
        throw iae;
    }
}

From source file:org.eclipse.php.internal.core.ast.rewrite.ASTRewriteAnalyzer.java

final void handleException(Throwable e) {
    IllegalArgumentException runtimeException = new IllegalArgumentException("Document does not match the AST"); //$NON-NLS-1$
    runtimeException.initCause(e);
    throw runtimeException;
}

From source file:org.gatein.pc.test.unit.protocol.response.InvokeMethodResponse.java

public InvokeMethodResponse(String uri) throws IllegalArgumentException {
    if (uri == null) {
        throw new IllegalArgumentException("Cannot invoke against a null URL");
    }/* w w w .ja  va  2  s  .  com*/

    //
    URI tmp;
    try {
        tmp = new URI(uri);
    } catch (URISyntaxException e) {
        IllegalArgumentException iae = new IllegalArgumentException("Wrong URI syntax");
        iae.initCause(e);
        throw iae;
    }

    //
    if (tmp.isOpaque()) {
        throw new IllegalArgumentException("No opaque URI accepted");
    }

    //
    this.uri = tmp;
    this.headers = new HashMap<String, Header>();
}

From source file:org.geotools.utils.imagemosaic.MosaicIndexBuilder.java

/**
 * @param locationPath//w  w w . ja  va2s  .c  o  m
 *            the locationPath to set
 */
public final void setLocationPath(String locationPath) {
    this.locationPath = locationPath;
    final File inDir = new File(locationPath);
    if (!inDir.isDirectory()) {
        LOGGER.severe("Provided input dir does not exist or is not a dir!");
        throw new IllegalArgumentException("Provided input dir does not exist or is not a dir!");
    }
    try {
        locationPath = inDir.getCanonicalPath();
        locationPath = locationPath.replace('\\', '/');
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
        final IllegalArgumentException ex = new IllegalArgumentException();
        ex.initCause(e);
        throw ex;
    }
}

From source file:org.intermine.pathquery.LogicExpression.java

/**
 * Parse a logic expression./*from   w  ww.  j  ava  2  s. c  o  m*/
 * @param expression logic expression
 */
private Node parse(String expression) {
    AST ast = null;
    try {
        LogicLexer lexer = new LogicLexer(new StringReader(expression));
        LogicParser parser = new LogicParser(lexer);
        Node rootNode;
        // The root context
        parser.expr();
        ast = parser.getAST();
        //new antlr.DumpASTVisitor().visit(ast);
        if ("or".equals(ast.getText().toLowerCase())) {
            rootNode = new Or(ast);
        } else if ("and".equals(ast.getText().toLowerCase())) {
            rootNode = new And(ast);
        } else {
            rootNode = new Variable(ast.getText());
        }
        return rootNode;
    } catch (antlr.RecognitionException e) {
        new antlr.DumpASTVisitor().visit(ast);
        IllegalArgumentException e2 = new IllegalArgumentException(
                e.getMessage() + " while parsing " + expression);
        e2.initCause(e);
        throw e2;
    } catch (antlr.TokenStreamException e) {
        new antlr.DumpASTVisitor().visit(ast);
        IllegalArgumentException e2 = new IllegalArgumentException(
                e.getMessage() + " while parsing " + expression);
        e2.initCause(e);
        throw e2;
    } catch (IllegalArgumentException e) {
        new antlr.DumpASTVisitor().visit(ast);
        throw e;
    }
}

From source file:org.jcurl.core.base.Collider.java

public static Collider newInstance(final Class clz) {
    final Class parent = Collider.class;
    if (!parent.isAssignableFrom(clz))
        throw new IllegalArgumentException(
                "Class [" + clz.getName() + "] is no descendant of [" + parent.getName() + "]");
    try {//from  www. j a v a 2s .  c  om
        return (Collider) clz.newInstance();
    } catch (InstantiationException e) {
        final IllegalArgumentException ex = new IllegalArgumentException();
        ex.initCause(e);
        throw ex;
    } catch (IllegalAccessException e) {
        final IllegalArgumentException ex = new IllegalArgumentException();
        ex.initCause(e);
        throw ex;
    }
}