public static void validateTenor(String tenor) throws OrderValidationException { sdf.setLenient(false); try { sdf.parse(tenor); } catch (Exception e) { throw new OrderValidationException(new I18NBoundMessage1P (Messages.INVALID_CURRENCY_TENOR_FORMAT,tenor)); } } }
/** * Create a new UriScheme instance. * * <p>Create a new scheme as defined by <a href="http://rfc.net/std0066.html">Internet Standard 66</a> and * <a href="http://tools.ietf.org/html/rfc3986">RFC 3986</a>. The given <code>inSchemeName</code> may be * composed of any combination of letters, digits, the plus character("+"), period("."), and hyphen("-"). * * @param inSchemeName a <code>String</code> value containing the name of the <code>UriScheme</code> * @throws IllegalArgumentException if the given scheme name is not valid as defined above */ public UriScheme(String inSchemeName) { if(inSchemeName.isEmpty() || !SCHEME_PATTERN.matcher(inSchemeName).matches()) { throw new IllegalArgumentException(new I18NBoundMessage1P(INVALID_SCHEME_NAME, inSchemeName).getText()); } scheme = inSchemeName; fullScheme = String.format("%s://", //$NON-NLS-1$ scheme); } /**
/** * Validates that the given value represents a valid future expiration year. * * @param inExpirationYear an <code>int</code> value * @throws OrderValidationException if the given value is invalid */ public static void validateExpirationYear(int inExpirationYear) throws OrderValidationException { if(inExpirationYear <= 0) { throw new OrderValidationException(new I18NBoundMessage1P(Messages.INVALID_FUTURE_EXPIRATION_YEAR_FORMAT, inExpirationYear)); } } /**
/** * Verifies that the symbols are valid. * * @throws IllegalArgumentException if the symbols are not valid */ private void validateSymbols() { Set<String> symbols = getSymbols(); // symbols is non-empty, underlying symbols is empty for(String symbol : symbols) { if(symbol == null || symbol.trim().isEmpty()) { throw new IllegalArgumentException(new I18NBoundMessage1P(INVALID_SYMBOLS, String.valueOf(symbols)).getText()); } } } /**
/** * Sets the refresh listener that intercepts the {@link #refresh()} * invocations. Only one refresh listener can be setup. If a * refresh listener is already setup when this method is invoked, * an exception is thrown. * * @param inRefreshListener the refresh listener instance * * @throws ModuleException if a refresh listener is already setup. */ public void setRefreshListener(RefreshListener inRefreshListener) throws ModuleException { synchronized (mOperationsLock) { if (mRefreshListener == null) { mRefreshListener = inRefreshListener; } else { throw new ModuleException(new I18NBoundMessage1P( Messages.REFRESH_LISTENER_ALREADY_SETUP, mRefreshListener.getClass().getName())); } } }
/** * Verifies that the underlying symbols are valid. * * @throws IllegalArgumentException if the underlying symbols are not valid */ private void validateUnderlyingSymbols() { Set<String> underlyingSymbols = getUnderlyingSymbols(); // underlying symbols is non-empty, symbols is empty for(String underlyingSymbol : underlyingSymbols) { if(underlyingSymbol == null || underlyingSymbol.trim().isEmpty()) { throw new IllegalArgumentException(new I18NBoundMessage1P(INVALID_UNDERLYING_SYMBOLS, String.valueOf(underlyingSymbols)).getText()); } } } /**
public static void validateCurrencySymbol(String symbol) throws OrderValidationException { if(symbol == null || symbol.isEmpty()) { return; } try { String[] currencyPair = symbol.split("/"); if (currencyPair==null || currencyPair.length !=2 || currencyPair[0].equalsIgnoreCase(currencyPair[1])) { throw new OrderValidationException(new I18NBoundMessage1P (Messages.INVALID_CURRENCY_SYMBOL_FORMAT,symbol)); } } catch (OrderValidationException e) { throw e; } catch (Exception e) { throw new OrderValidationException(new I18NBoundMessage1P (Messages.INVALID_CURRENCY_SYMBOL_FORMAT,symbol)); } }
@SuppressWarnings("rawtypes") public Object convert(Class inClass, Object o) { if(Properties.class.equals(inClass)) { if(o instanceof Properties) { return o; } else if(o instanceof String) { return Util.propertiesFromString((String)o); } } throw new ConversionException(new I18NBoundMessage1P( Messages.CANNOT_CONVERT_TO_PROPERTIES, o == null ? null : o.toString()).getText()); } }
/** * Validates that the given value represents a valid future expiration year. * * @param inExpirationYear a <code>String</code> value * @throws OrderValidationException if the given value is invalid */ public static void validateExpirationYear(String inExpirationYear) throws OrderValidationException { if(inExpirationYear == null || inExpirationYear.isEmpty()) { return; } try { if(Integer.parseInt(inExpirationYear) <= 0) { throw new OrderValidationException(new I18NBoundMessage1P(Messages.INVALID_FUTURE_EXPIRATION_YEAR_FORMAT, inExpirationYear)); } } catch (OrderValidationException e) { throw e; } catch (Exception e) { throw new OrderValidationException(new I18NBoundMessage1P(Messages.INVALID_FUTURE_EXPIRATION_YEAR_FORMAT, inExpirationYear)); } } /**
@SuppressWarnings("rawtypes") public Object convert(Class inClass, Object o) { if(ModuleURN.class.equals(inClass)) { try { if(o instanceof ModuleURN) { return o; } else if(o instanceof String) { return new ModuleURN((String)o); } else if(o != null) { return new ModuleURN(o.toString()); } } catch (IllegalArgumentException e) { throw new ConversionException(new I18NBoundMessage1P( Messages.CANNOT_CONVERT_TO_MODULE_URN, o.toString()).getText(),e); } } throw new ConversionException(new I18NBoundMessage1P( Messages.CANNOT_CONVERT_TO_MODULE_URN, o == null ? null : o.toString()).getText()); } }
/** * Creates a connection exception wrapping the supplied exception. * * <p>If the supplied exception is a <code>RemoteException</code>, * the exception wrapped by it is extracted and wrapped into the * returned exception. * * @param inFailure the exception that needs to be wrapped. * @return the connection exception wrapping the failure. */ protected ConnectionException wrapRemoteFailure(Exception inFailure) { Throwable cause; //if it's a remote server failure, extract the nested cause. if(inFailure instanceof RemoteException) { cause = inFailure.getCause() != null ? inFailure.getCause() : inFailure; } else { cause = inFailure; } return new ConnectionException(cause, new I18NBoundMessage1P(Messages.ERROR_WS_OPERATION, cause.getLocalizedMessage())); } /**
/** * Extracts the hostname from the given URI string. * * <p>The URI must be syntactically valid and of this object's scheme. * * @param inUriString a <code>String</code> value * @return a <code>String</code> value * @throws IllegalArgumentException if the given URI is not syntactically valid, is syntactically valid but is not of * the correct scheme, or if the host is missing or invalid */ public String hostnameFromUri(String inUriString) { validate(inUriString); URI uri; try { uri = new URI(inUriString); return uri.getHost(); } catch (URISyntaxException e) { throw new IllegalArgumentException(new I18NBoundMessage1P(SCHEME_REQUIRED, getScheme()).getText()); } } /**
Matcher m = EXPIRY_PATTERN.matcher(inExpiry); if(!m.matches()) { throw new OrderValidationException(new I18NBoundMessage1P( Messages.INVALID_OPTION_EXPIRY_FORMAT,inExpiry));
for(String contentString : inContent) { if(contentString == null) { throw new IllegalArgumentException(new I18NBoundMessage1P(INVALID_CONTENT, contentString).getText()); throw new IllegalArgumentException(new I18NBoundMessage1P(INVALID_CONTENT, contentString).getText());
/** * Gets the strategy parameters for the given module. * * @param inInstance a <code>ModuleURN</code> value * @return a <code>CreateStrategyParameters</code> value */ private CreateStrategyParameters doGetStrategyCreateParms(ModuleURN inInstance) { failOnNullURN(inInstance); CreateStrategyParameters parameters = mStrategies.get(inInstance); if(parameters == null) { throw new I18NException(new I18NBoundMessage1P(Messages.NO_CREATE_PARAMETERS_FOR_STRATEGY, inInstance)); } return parameters; } /**
return object; } else { throw new MessageConversionException(new I18NBoundMessage1P( Messages.UNEXPECTED_MESSAGE_RECEIVED, ObjectUtils.toString(object)).getText()); throw new MessageConversionException(new I18NBoundMessage1P( Messages.UNEXPECTED_MESSAGE_RECEIVED, ObjectUtils.toString(message)).getText());
/** * Changes the response and throws an exception if there was a problem. * * @param inFailed a <code>boolean</code> value * @param inMessage a <code>String</code> value */ private void validateResponse(boolean inFailed, String inMessage) { if(inFailed) { if(inMessage.contains(NoMarketDataProvidersAvailable.class.getSimpleName())) { throw new NoMarketDataProvidersAvailable(); } throw new MarketDataRequestFailed(new I18NBoundMessage1P(Messages.MARKETDATA_ERROR_MESSAGE, inMessage)); } } /**
/** * Extracts the port from the given URI string. * * <p>The URI must be syntactically valid and of this object's scheme. * * @param inUriString a <code>String</code> value * @return an <code>int</code> value * @throws IllegalArgumentException if the given URI is not syntactically valid, is syntactically valid but is not of * the correct scheme, or if the hostname or port is missing or invalid */ public int portFromUri(String inUriString) { validate(inUriString); URI uri; try { uri = new URI(inUriString); validatePort(uri.getPort()); return uri.getPort(); } catch (URISyntaxException e) { throw new IllegalArgumentException(new I18NBoundMessage1P(SCHEME_REQUIRED, getScheme()).getText()); } } /**
/** * Throws an exception with the supplied message if the supplied URN * is not a strategy module URN. * * @param inURN the URN to test. * @param inFailureMessage the message to use in the exception. * * @throws I18NException if the supplied URN is not a strategy URN. */ private static void failIfNotStrategy(ModuleURN inURN, I18NMessage1P inFailureMessage) throws I18NException { if(!STRATEGY_PROVIDER.parentOf(inURN)) { throw new I18NException(new I18NBoundMessage1P( inFailureMessage, inURN)); } } /**
/** * Converts a JMS Message to an object. * * @param message the received JMS message. It should be of type * {@link ObjectMessage}. * * @return the object converted from the supplied JMS message. * * @throws JMSException if there were errors extracting the contents * of the JMS message. * @throws MessageConversionException if there were errors converting * the contents of the JMS message to an object. */ @Override public Object fromMessage(Message message) throws JMSException, MessageConversionException { SLF4JLoggerProxy.debug(this, "Converting from JMS {}", message); //$NON-NLS-1$ if(message instanceof ObjectMessage) { return ((ObjectMessage) message).getObject(); } else { throw new MessageConversionException(new I18NBoundMessage1P( Messages.UNEXPECTED_MESSAGE_RECEIVED, ObjectUtils.toString(message)).getText()); } }