@Override public PrintStream getStream(String inName) throws IOException { System.err.println(Messages.STDERR_STREAM_SUMMARY_HEADER. getText(inName)); return System.err; }
@Override public void setAttribute(Attribute attribute) throws AttributeNotFoundException { //Attributes are not writable throw new AttributeNotFoundException( Messages.MXBEAN_ATTRIB_NOT_WRITABLE.getText( attribute.getName())); }
/** * Get the FIX version value associated with the given string representation. * * @param inVersion a <code>String</code> value * @return a <code>FIXVersion</code> value * @throws IllegalArgumentException if the FIX version of the given message is unsupported */ public static FIXVersion getFIXVersion(String inVersion) { FIXVersion fixVersion = versionMap.get(inVersion); if(fixVersion == null) { throw new IllegalArgumentException(Messages.FIX_VERSION_UNSUPPORTED.getText(inVersion)); } return fixVersion; } /**
/** * Perform a FIX version lookup using the given application version string. * * @param inApplicationVersionString a <code>String</code> value * @return a <code>FIXVersion</code> value * @throws IllegalArgumentException if the version cannot be found */ private static FIXVersion doFixApplicationVersionLookup(String inApplicationVersionString) { FIXVersion fixVersion = applicationVersionMap.get(inApplicationVersionString); if(fixVersion == null) { throw new IllegalArgumentException(Messages.FIX_VERSION_UNSUPPORTED.getText(inApplicationVersionString)); } return fixVersion; } /**
/** * Perform a FIX version lookup using the given version string. * * @param inVersionString a <code>String</code> value * @return a <code>FIXVersion</code> value * @throws FieldNotFound if the version could not be determined * @throws IllegalArgumentException if the version cannot be found */ private static FIXVersion doFixVersionLookup(String inVersionString) throws FieldNotFound { FIXVersion fixVersion = versionMap.get(inVersionString); if(fixVersion == null) { throw new IllegalArgumentException(Messages.FIX_VERSION_UNSUPPORTED.getText(inVersionString)); } return fixVersion; } /**
@Override final Object runCommand(ModuleManagerMXBean inManager, String inCmdString) { int idx = inCmdString.indexOf(';'); //$NON-NLS-1$ if (idx >= 0) { return inManager.createModule(inCmdString.substring(0, idx), inCmdString.substring(++idx)); } else { throw new IllegalArgumentException( Messages.CREATE_MODULE_INVALID_SYNTAX.getText(inCmdString)); } } }
/** * Validates the given hostname value. * * @param inHostname a <code>String</code> value * @throws IllegalArgumentException if <code>inHostname</code> is not valid */ private static void validateHost(String inHostname) { if(inHostname == null) { throw new NullPointerException(INVALID_HOSTNAME.getText(inHostname)); } if(inHostname.isEmpty()) { throw new IllegalArgumentException(INVALID_HOSTNAME.getText(inHostname)); } // this is done to pick up extra validation done by the JVM try { makeUri("validator://", //$NON-NLS-1$ inHostname, null); } catch (URISyntaxException e) { throw new IllegalArgumentException(INVALID_HOSTNAME.getText(inHostname)); } } /**
/** * Gets the <code>FutureExpirationMonth</code> value associated with the given month of the year. * * @param inMonthOfYear a <code>String</code> value * @return a <code>FutureExpirationMonth</code> value * @throws IllegalArgumentException if the given monthOfYear value does not correspond to a value in [1..12] */ public static FutureExpirationMonth getByMonthOfYear(String inMonthOfYear) { int month = Integer.valueOf(inMonthOfYear); Validate.isTrue(month >= 1 && month <= 12, Messages.INVALID_MONTH.getText(inMonthOfYear)); return monthsByMonthOfYear.get(inMonthOfYear); } /**
/** * Deletes the log files. Do not perform any log operations while performing * this operation. */ public void clear() { try { close(); openLogStreams(false); } catch (IOException e) { System.err.println(Messages.ERROR_COULD_NOT_CLEAR_LOG.getText(getClass().getName())); } }
@Override public MBeanInfo getMBeanInfo() { Map<DataFlowID,Integer> queueSizes = getQueueSizes(); List<MBeanAttributeInfo> attribInfo = new ArrayList<MBeanAttributeInfo>(queueSizes.size()); for(Map.Entry<DataFlowID,Integer>entry: queueSizes.entrySet()) { attribInfo.add(new MBeanAttributeInfo(ATTRIB_PREFIX +entry.getKey(), Integer.class.getName(), Messages.JMX_ATTRIBUTE_FLOW_CNT_DESCRIPTION.getText(entry.getKey()), true, false, false)); } return new MBeanInfo(getClass().getName(), Messages.JMX_MXBEAN_DESCRIPTION.getText(), attribInfo.toArray(new MBeanAttributeInfo[attribInfo.size()]), null,null,null); } /**
/** * Executes validation common to symbols and underlying symbols. * * @throws IllegalArgumentException if the validation fails */ private void doCommonSymbolValidation() { Set<String> symbols = getSymbols(); Set<String> underlyingSymbols = getUnderlyingSymbols(); // symbols xor underlying symbols must be specified if(symbols.isEmpty() && underlyingSymbols.isEmpty()) { throw new IllegalArgumentException(NEITHER_SYMBOLS_NOR_UNDERLYING_SYMBOLS_SPECIFIED.getText(this)); } if(!symbols.isEmpty() && !underlyingSymbols.isEmpty()) { throw new IllegalArgumentException(BOTH_SYMBOLS_AND_UNDERLYING_SYMBOLS_SPECIFIED.getText(this)); } } /**
/** * Validates the <code>ExchangeRequest</code>. * * @throws IllegalArgumentException if the request is not valid */ private void validate() { // if instrument is null, underlying must be specified if(instrument == null && underlyingInstrument == null) { throw new IllegalArgumentException(INSTRUMENT_OR_UNDERLYING_INSTRUMENT_REQUIRED.getText()); } // if instrument is specified and its an option, underlying must be specified if(instrument != null && instrument instanceof Option && underlyingInstrument == null) { throw new IllegalArgumentException(OPTION_REQUIRES_UNDERLYING_INSTRUMENT.getText(instrument)); } } /**
/** * Create a new Future instance. * * @param inSymbol a <code>String</code> value containing the future symbol * @param inExpirationMonth a <code>FutureExpirationMonth</code> value containing the future expiry month * @param inExpirationYear an <code>int</code> value containing the future expiration year (values < 100 will be considered years * in the 21st century) * @throws IllegalArgumentException if any of the parameters are invalid */ public Future(String inSymbol, FutureExpirationMonth inExpirationMonth, int inExpirationYear) { symbol = StringUtils.trimToNull(inSymbol); Validate.notNull(symbol, Messages.NULL_SYMBOL.getText()); Validate.notNull(inExpirationMonth, Messages.NULL_MONTH.getText()); Validate.isTrue(inExpirationYear > 0, Messages.INVALID_YEAR.getText(inExpirationYear)); if(inExpirationYear < 100) { inExpirationYear += 2000; } expirationMonth = inExpirationMonth; expirationYear = inExpirationYear; expirationDay = -1; } /**
/** * Parses the given <code>String</code> to create a <code>Future</code> instrument. * * @param inFullSymbol a <code>String</code> value in the form <code>SYMBOL-YYYYMM</code> or <code>SYMBOL-YYYYMDD</code> * @return a <code>Future</code> value * @throws IllegalArgumentException if the given <code>String</code> cannot be parsed */ public static Future fromString(String inFullSymbol) { inFullSymbol = StringUtils.trimToNull(inFullSymbol); Validate.notNull(inFullSymbol, Messages.NULL_SYMBOL.getText()); if(!inFullSymbol.contains("-")) { throw new IllegalArgumentException(Messages.INVALID_SYMBOL.getText(inFullSymbol)); } int dashIndex = inFullSymbol.lastIndexOf('-'); assert(dashIndex != -1); String symbol = inFullSymbol.substring(0, dashIndex); String expiry = inFullSymbol.substring(dashIndex+1); return new Future(symbol, expiry); } /**
/** * Verifies that the <code>Content</code> is valid. * * @throws IllegalArgumentException if the <code>Content</code> is not valid */ private void validateContent() { Set<Content> content = getContent(); // content cannot be empty if(content.isEmpty()) { throw new IllegalArgumentException(MISSING_CONTENT.getText()); } // check to make sure the list of content is valid if(!isValidEnumList(content)) { throw new IllegalArgumentException(new I18NBoundMessage1P(INVALID_CONTENT, String.valueOf(content)).getText()); } // content dividend requires symbols if(content.contains(DIVIDEND) && getSymbols().isEmpty()) { throw new IllegalArgumentException(DIVIDEND_REQUIRES_SYMBOLS.getText(this)); } } /**
/** * Creates a URI composed of the given host and port and this object's {@link #scheme}. * * <P>The contents of an internet URI are regulated by <a href="http://www.ietf.org/rfc/rfc2396.txt">RFC 2396</a>. * This method does not enforce full compliance with this RFC because hostnames might not be internet hostnames * but may be local network hostnames instead. Different standards apply to non-internet hostnames and are difficult * to deterministically predict. * * @param inHostname a <code>String</code> value * @return a <code>String</code> value containing a conforming URI * @throws IllegalArgumentException if the host is not valid */ public String composeUriString(String inHostname) { validateHost(inHostname); try { return makeUri(getFullScheme(), inHostname, null).toString(); } catch (URISyntaxException e) { throw new IllegalArgumentException(INVALID_HOSTNAME.getText(inHostname)); } } /**
@Override public void set(Instrument inInstrument, String inBeginString, FieldMap inMessage) { if(UNSUPPORTED_VERSIONS.contains(FIXVersion.getFIXVersion(inBeginString))) { throw new IllegalArgumentException(Messages.CONVERTIBLE_BONDS_NOT_SUPPORTED_FOR_FIX_VERSION.getText(inBeginString)); } setSecurityType(inInstrument, inBeginString, inMessage); inMessage.setField(new Symbol(inInstrument.getSymbol())); } /* (non-Javadoc)
/** * Get the data dictionary for the given session. * * @param inSessionId a <code>Message</code> value * @return a <code>DataDictionary</code> value * @throws FieldNotFound if the FIX version could not be determined from the given message * @throws UnsupportedOperationException if the given session ID does not correspond to an active session */ public static DataDictionary getDataDictionary(SessionID inSessionId) throws FieldNotFound { Session session = Session.lookupSession(inSessionId); if(session == null) { throw new UnsupportedOperationException(Messages.MISSING_SESSION.getText(session)); } quickfix.field.ApplVerID applVerId = session.getTargetDefaultApplicationVersionID(); return getDataDictionary(FIXVersion.getFIXVersion(applVerId)); } /**
/** * Get all the {@link Group} objects associated with the given <code>Message</code>. * * @param inMessage a <code>Message</code> value * @return a <code>List<Group></code> value * @throws CoreException */ public static List<Group> getGroups(Message inMessage) throws CoreException { int totalSymbols = AbstractMessageTranslator.determineTotalSymbols(inMessage); List<Group> groups = new ArrayList<Group>(); // the message header is valid, make a best effort to parse each group, discarding as few as possible for (int symbolCounter=1;symbolCounter<=totalSymbols;symbolCounter++) { try { Group relatedSymGroup = sMessageFactory.createGroup(MsgType.MARKET_DATA_REQUEST, NoRelatedSym.FIELD); inMessage.getGroup(symbolCounter, relatedSymGroup); // relatedSymGroup is a chunk in the message that encapsulates the Symbol // securityType now holds a description of the symbol (fix tag 167) groups.add(relatedSymGroup); } catch (Throwable e) { SLF4JLoggerProxy.debug(AbstractMessageTranslator.class, e, Messages.GROUP_NUMBER_COULD_NOT_TRANSLATE.getText(symbolCounter)); } } return groups; }
@Override public void set(Instrument inInstrument, String inBeginString, FieldMap inMessage) { if(FIXVersion.FIX40.equals(FIXVersion.getFIXVersion(inBeginString))) { throw new IllegalArgumentException( Messages.FOREX_NOT_SUPPORTED_FOR_FIX_VERSION.getText(inBeginString)); } inMessage.setField(new Symbol(inInstrument.getSymbol())); Currency currency = (Currency)inInstrument; switch(FIXVersion.getFIXVersion(inBeginString)){ case FIX_SYSTEM: //fall through case FIX40: //fall through case FIX41: //fall through case FIX42: //fall through case FIX43: //fall through case FIX44: //fall through setSecurityType(inInstrument, inBeginString, inMessage); break; default: setSecurityType(inInstrument, inBeginString, inMessage); setCFICode(inMessage, currency); break; } }