List of usage examples for java.lang IllegalArgumentException initCause
public synchronized Throwable initCause(Throwable cause)
From source file:com.microsoft.tfs.core.util.URIUtils.java
/** * <p>//from w w w . jav a 2 s. co m * Constructs a new {@link URI} from the string components of the URI. Any * characters in the components that are illegal for URIs will be quoted. * This method is an alternative to the corresponding {@link URI} * constructor which does encode some characters, but not all necessary * characters like the {@link URIUtil} class does (some RTL Unicode * characters remain unescaped in the {@link URI} constructor which cause * problems in HTTP requests). * </p> * * @param scheme * Unencoded URI scheme * * @param authority * Unencoded URI authority * * @param path * Unencoded URI path * * @param query * Unencoded URI query * * @param fragment * Unencoded URI fragment * @return the new {@link URI} */ public static URI newURI(final String scheme, final String authority, final String path, final String query, final String fragment) { final StringBuffer sb = new StringBuffer(); try { if (scheme != null) { sb.append(scheme); sb.append(':'); } if (authority != null) { sb.append("//"); //$NON-NLS-1$ sb.append(URIUtil.encode(authority, com.microsoft.tfs.core.httpclient.URI.allowed_authority)); } if (path != null) { sb.append(URIUtil.encodePath(path)); } if (query != null) { sb.append('?'); sb.append(URIUtil.encodeQuery(query)); } if (fragment != null) { sb.append('#'); sb.append(URIUtil.encode(fragment, com.microsoft.tfs.core.httpclient.URI.allowed_fragment)); } } catch (final URIException e) { final IllegalArgumentException e2 = new IllegalArgumentException( MessageFormat.format(Messages.getString("URIUtils.IllegalURIPartsFormat"), //$NON-NLS-1$ scheme, authority, path, query, fragment)); e2.initCause(e); throw e2; } return URI.create(sb.toString()); }
From source file:com.microsoft.tfs.core.util.URIUtils.java
/** * <p>/*w w w . j av a2s. com*/ * Appends the specified parent {@link URI} with provided query parameters. * </p> * * <p> * Old query parameters and/or fragments in the specified parent {@link URI} * (if any) are discarded. * </p> * * @param parent * a base {@link URI} (must not be <code>null</code>) * @return a new {@link URI} as described above (never <code>null</code>) */ public static URI addQueryParameters(final URI parent, final Map<String, String> queryParameters) { if (queryParameters == null || queryParameters.size() == 0) { return parent; } // Make sure we use a well escaped URI string for a base. final StringBuilder sb = new StringBuilder(URIUtils.removeQueryParts(parent).toASCIIString()); boolean isFirstParameter = true; for (final Entry<String, String> queryParameter : queryParameters.entrySet()) { if (isFirstParameter) { sb.append("?"); //$NON-NLS-1$ isFirstParameter = false; } else { sb.append("&"); //$NON-NLS-1$ } try { sb.append(URIUtil.encodeWithinQuery(queryParameter.getKey())); sb.append("="); //$NON-NLS-1$ sb.append(URIUtil.encodeWithinQuery(queryParameter.getValue())); } catch (final URIException e) { final IllegalArgumentException e2 = new IllegalArgumentException( MessageFormat.format(Messages.getString("URIUtils.IllegalQueryParameterFormat"), //$NON-NLS-1$ queryParameter.getKey(), queryParameter.getValue())); e2.initCause(e); throw e2; } } return newURI(sb.toString()); }
From source file:com.jeeframework.util.classes.ClassUtils.java
/** * Resolve the given class name into a Class instance. Supports * primitives (like "int") and array class names (like "String[]"). * <p>This is effectively equivalent to the <code>forName</code> * method with the same arguments, with the only difference being * the exceptions thrown in case of class loading failure. * @param className the name of the Class * @param classLoader the class loader to use * (may be <code>null</code>, which indicates the default class loader) * @return Class instance for the supplied name * @throws IllegalArgumentException if the class name was not resolvable * (that is, the class could not be found or the class file could not be loaded) * @see #forName(String, ClassLoader)/*from w w w . j av a2s . co m*/ */ public static Class resolveClassName(String className, ClassLoader classLoader) throws IllegalArgumentException { try { return forName(className, classLoader); } catch (ClassNotFoundException ex) { IllegalArgumentException iae = new IllegalArgumentException("Cannot find class [" + className + "]"); iae.initCause(ex); throw iae; } catch (LinkageError ex) { IllegalArgumentException iae = new IllegalArgumentException( "Error loading class [" + className + "]: problem with class file or dependent class."); iae.initCause(ex); throw iae; } }
From source file:biz.wolschon.fileformats.gnucash.jwsdpimpl.GnucashTransactionWritingImpl.java
/** * @see ${@link #setDatePosted(Date)};// ww w .j a va2s . com */ public void setDatePostedFormatet(final String datePosted) { try { this.setDatePosted(java.text.DateFormat.getDateInstance().parse(datePosted)); } catch (ParseException e) { IllegalArgumentException x = new IllegalArgumentException( "cannot parse datePosted '" + datePosted + "'"); x.initCause(e); throw x; } }
From source file:edu.ksu.cis.indus.common.soot.SootBasedDriver.java
/** * Sets the name of the file containing the scope specification. * /*from w w w. j av a 2 s .c om*/ * @param scopeSpecFileName of the scope spec. * @return the scope definition stored in the given file. */ @Functional protected final SpecificationBasedScopeDefinition setScopeSpecFile( @Immutable @NonNull final String scopeSpecFileName) { SpecificationBasedScopeDefinition _result = null; if (scopeSpecFileName != null) { try { final InputStream _in = new FileInputStream(scopeSpecFileName); final String _contents = IOUtils.toString(_in); IOUtils.closeQuietly(_in); _result = SpecificationBasedScopeDefinition.deserialize(_contents); } catch (final IOException _e) { final String _msg = "Error retrieved specification from " + scopeSpecFileName; LOGGER.error(_msg, _e); final IllegalArgumentException _i = new IllegalArgumentException(_msg); _i.initCause(_e); throw _i; } catch (final JiBXException _e) { final String _msg = "JiBX failed during deserialization."; LOGGER.error(_msg, _e); final IllegalStateException _i = new IllegalStateException(_msg); _i.initCause(_e); throw _i; } } cfgProvider.setScope(_result, getEnvironment()); return _result; }
From source file:com.bytelightning.opensource.pokerface.ScriptHelperImpl.java
/** * {@inheritDoc}/* w w w .ja v a2 s .c o m*/ */ @Override public String makeAbsoluteUrl(String location) { if (location == null) return location; StringBuffer sb = new StringBuffer(); boolean leadingSlash = location.startsWith("/"); if (location.startsWith("//")) { // Scheme relative; Add the scheme String scheme = getScheme(); sb.append(scheme, 0, scheme.length()); sb.append(':'); sb.append(location, 0, location.length()); return sb.toString(); } else if (leadingSlash || !HasScheme(location)) { String scheme = getScheme(); String name = getHOSTName(); int port = getHOSTPort(); try { sb.append(scheme, 0, scheme.length()); sb.append("://", 0, 3); sb.append(name, 0, name.length()); if ((scheme.equals("http") && port != 80) || (scheme.equals("https") && port != 443)) { sb.append(':'); String portS = port + ""; sb.append(portS, 0, portS.length()); } if (!leadingSlash) { String relativePath = request.getRequestLine().getUri(); sb.append(PercentEncodeRfc3986(relativePath)); sb.append('/'); } sb.append(location, 0, location.length()); sb = new StringBuffer(NormalizeURL(sb.toString())); } catch (IOException e) { IllegalArgumentException iae = new IllegalArgumentException(location); iae.initCause(e); throw iae; } return sb.toString(); } else return location; }
From source file:org.apereo.services.persondir.support.RegexGatewayPersonAttributeDao.java
@Override public Set<IPersonAttributes> getPeopleWithMultivaluedAttributes(final Map<String, List<Object>> seed) { Validate.notNull(seed, "Argument 'seed' cannot be null."); if (patterns == null || patterns.size() < 1) { throw new IllegalStateException("patterns Map may not be null and must contain at least 1 mapping."); }/*www. j a v a 2 s . co m*/ if (targetPersonAttributeDao == null) { throw new IllegalStateException("targetPersonAttributeDao may not be null"); } //Flag for patterns that match boolean matchedPatterns = false; //Iterate through all attributeName/pattern pairs for (final Map.Entry<String, Pattern> patternEntry : this.patterns.entrySet()) { final String attributeName = patternEntry.getKey(); final List<Object> attributeValues = seed.get(attributeName); //Check if the value exists if (attributeValues == null) { if (this.matchAllPatterns) { //Need to match ALL patters, if the attribute isn't in the seed it can't be matched, return null if (this.logger.isInfoEnabled()) { this.logger.info("All patterns must match and attribute='" + attributeName + "' does not exist in the seed, returning null."); } return null; } //Don't need to match all, just go to the next attribute and see if it exists continue; } //The pattern to test the attribute's value(s) with final Pattern compiledPattern = patternEntry.getValue(); if (compiledPattern == null) { throw new IllegalStateException("Attribute '" + attributeName + "' has a null pattern"); } //Flag for matching the pattern on the values boolean matchedValues = false; //Iterate over the values for the attribute, testing each against the pattern for (final Object valueObj : attributeValues) { final String value; try { value = (String) valueObj; } catch (final ClassCastException cce) { final IllegalArgumentException iae = new IllegalArgumentException( "RegexGatewayPersonAttributeDao can only accept seeds who's values are String or List of String. Attribute '" + attributeName + "' has a non-String value."); iae.initCause(cce); throw iae; } //Check if the value matches the pattern final Matcher valueMatcher = compiledPattern.matcher(value); matchedValues = valueMatcher.matches(); //Only one value needs to be matched, this one matched so no need to test the rest, break out of the loop if (matchedValues && !this.matchAllValues) { if (this.logger.isDebugEnabled()) { this.logger.debug("value='" + value + "' matched pattern='" + compiledPattern + "' and only one value match is needed, leaving value matching loop."); } break; } //Need to match all values, this one failed so no need to test the rest, break out of the loop else if (!matchedValues && this.matchAllValues) { if (this.logger.isDebugEnabled()) { this.logger.debug("value='" + value + "' did not match pattern='" + compiledPattern + "' and all values need to match, leaving value matching loop."); } break; } //Extra logging else if (this.logger.isDebugEnabled()) { if (matchedValues) { this.logger.debug("value='" + value + "' matched pattern='" + compiledPattern + "' and all values need to match, continuing value matching loop."); } else { this.logger.debug("value='" + value + "' did not match pattern='" + compiledPattern + "' and only one value match is needed, continuing value matching loop."); } } } matchedPatterns = matchedValues; //Only one pattern needs to be matched, this one matched so no need to test the rest, break out of the loop if (matchedPatterns && !this.matchAllPatterns) { if (this.logger.isDebugEnabled()) { this.logger.debug("pattern='" + compiledPattern + "' found a match and only one pattern match is needed, leaving pattern matching loop."); } break; } //Need to match all patterns, this one failed so no need to test the rest, break out of the loop else if (!matchedPatterns && this.matchAllPatterns) { if (this.logger.isDebugEnabled()) { this.logger.debug("pattern='" + compiledPattern + "' did not find a match and all patterns need to match, leaving pattern matching loop."); } break; } //Extra logging else if (this.logger.isDebugEnabled()) { if (matchedPatterns) { this.logger.debug("pattern='" + compiledPattern + "' found a match and all patterns need to match, continuing pattern matching loop."); } else { this.logger.debug("pattern='" + compiledPattern + "' did not find a match and only one pattern match is needed, continuing pattern matching loop."); } } } //Execute the wrapped DAO if the match criteria was met if (matchedPatterns) { if (this.logger.isInfoEnabled()) { this.logger.info("Matching criteria '" + this.patterns + "' was met for query '" + seed + "', delegating call to the targetPersonAttributeDao='" + this.targetPersonAttributeDao + "'"); } return this.targetPersonAttributeDao.getPeopleWithMultivaluedAttributes(seed); } if (this.logger.isInfoEnabled()) { this.logger.info( "Matching criteria '" + this.patterns + "' was not met for query '" + seed + "', return null"); } return null; }
From source file:gov.nih.nci.cabig.caaers.web.filters.BadInputFilter.java
/** * Return an array of regular expression objects initialized from the * specified argument, which must be <code>null</code> or a * comma-delimited list of regular expression patterns. * * @param list The comma-separated list of patterns * @throws IllegalArgumentException if one of the patterns has * invalid syntax *//*from w w w.j a v a 2 s . co m*/ protected Pattern[] precalculate(String list) { if (list == null) return (new Pattern[0]); list = list.trim(); if (list.length() < 1) return (new Pattern[0]); list += ","; ArrayList<Pattern> reList = new ArrayList<Pattern>(); while (list.length() > 0) { int comma = list.indexOf(','); if (comma < 0) break; String pattern = list.substring(0, comma).trim(); try { reList.add(Pattern.compile(pattern)); } catch (PatternSyntaxException e) { IllegalArgumentException iae = new IllegalArgumentException( "Syntax error in request filter pattern" + pattern); iae.initCause(e); throw iae; } list = list.substring(comma + 1); } Pattern reArray[] = new Pattern[reList.size()]; return reList.toArray(reArray); }
From source file:edu.ksu.cis.indus.tools.slicer.SliceXMLizerCLI.java
/** * Process the criteria specification file. * //from w w w. ja v a2 s. c o m * @return a collection of criteria * @throws IllegalArgumentException when the errors occur while accessing the specified file. * @throws IllegalStateException when the parsing of the specified file fails. */ private Collection<ISliceCriterion> processCriteriaSpecFile() throws IllegalArgumentException, IllegalStateException { final Collection<ISliceCriterion> _criteria = new HashSet<ISliceCriterion>(); if (criteriaSpecFileName != null) { try { final InputStream _in = new FileInputStream(criteriaSpecFileName); final String _result = IOUtils.toString(_in); IOUtils.closeQuietly(_in); final String _criteriaSpec = _result; _criteria.addAll(SliceCriteriaParser.deserialize(_criteriaSpec, scene)); if (LOGGER.isInfoEnabled()) { LOGGER.info("Criteria specification before slicing: \n" + _result); LOGGER.info("Criteria before slicing: \n" + _criteria); } } catch (final IOException _e) { if (LOGGER.isWarnEnabled()) { final String _msg = "Error retrieved slicing criteria from " + criteriaSpecFileName; LOGGER.error(_msg, _e); final IllegalArgumentException _i = new IllegalArgumentException(_msg); _i.initCause(_e); throw _i; } } catch (final JiBXException _e) { if (LOGGER.isWarnEnabled()) { final String _msg = "JiBX failed during deserialization."; LOGGER.error(_msg, _e); final IllegalStateException _i = new IllegalStateException(_msg); _i.initCause(_e); throw _i; } } } return _criteria; }
From source file:org.apache.openejb.math.MathRuntimeException.java
/** * Constructs a new <code>IllegalArgumentException</code> with specified nested * <code>Throwable</code> root cause. * * @param rootCause the exception or error that caused this exception * to be thrown.//w w w. ja v a2s . co m * @return built exception */ public static IllegalArgumentException createIllegalArgumentException(final Throwable rootCause) { final IllegalArgumentException iae = new IllegalArgumentException(rootCause.getLocalizedMessage()); iae.initCause(rootCause); return iae; }