You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(4) |
Nov
(7) |
Dec
(18) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(20) |
Feb
(7) |
Mar
|
Apr
(8) |
May
(9) |
Jun
(7) |
Jul
(23) |
Aug
(3) |
Sep
|
Oct
(16) |
Nov
|
Dec
(3) |
2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
2010 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(6) |
Jun
(8) |
Jul
|
Aug
|
Sep
|
Oct
(5) |
Nov
(2) |
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
(1) |
Oct
(30) |
Nov
|
Dec
|
2012 |
Jan
(4) |
Feb
(2) |
Mar
(1) |
Apr
(23) |
May
(4) |
Jun
|
Jul
(1) |
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
(7) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <ope...@li...> - 2008-06-25 03:12:32
|
Revision: 156 http://openfast.svn.sourceforge.net/openfast/?rev=156&view=rev Author: jacob_northey Date: 2008-06-24 20:12:39 -0700 (Tue, 24 Jun 2008) Log Message: ----------- Migrated to multi-module project. Working on single core module with modules session, util and examples to come. Modified Paths: -------------- branches/openfast-2.x/pom.xml Added Paths: ----------- branches/openfast-2.x/core/ branches/openfast-2.x/core/pom.xml branches/openfast-2.x/core/src/ Removed Paths: ------------- branches/openfast-2.x/src/ Property changes on: branches/openfast-2.x/core ___________________________________________________________________ Name: svn:ignore + target Added: branches/openfast-2.x/core/pom.xml =================================================================== --- branches/openfast-2.x/core/pom.xml (rev 0) +++ branches/openfast-2.x/core/pom.xml 2008-06-25 03:12:39 UTC (rev 156) @@ -0,0 +1,89 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>org.openfast</groupId> + <artifactId>openfast</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <groupId>org.openfast</groupId> + <artifactId>openfast-core</artifactId> + <packaging>jar</packaging> + + <organization> + <name>The LaSalle Technology Group, LLC</name> + <url>http://www.lasalletech.com</url> + </organization> + + <name>OpenFAST Core</name> + + <description> + OpenFAST Core contains the core encoding/decoding and message model classes. + </description> + + <build> + <resources> + <resource> + <directory>src/main/resources</directory> + </resource> + </resources> + + <extensions> + <extension> + <groupId>org.apache.maven.wagon</groupId> + <artifactId>wagon-ssh</artifactId> + <version>1.0-beta-2</version> + </extension> + </extensions> + + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.4</source> + <target>1.4</target> + </configuration> + </plugin> + <plugin> + <artifactId>maven-release-plugin</artifactId> + <configuration> + <tagBase> + https://openfast.svn.sourceforge.net/svnroot/openfast/tags + </tagBase> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <executions> + <execution> + <id>javadoc</id> + <phase>site</phase> + <goals> + <goal>javadoc</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <configuration> + <descriptors> + <descriptor>src/assembly/sources-jar.xml</descriptor> + <descriptor>src/assembly/javadoc-jar.xml</descriptor> + <descriptor>src/assembly/source.xml</descriptor> + <descriptor>src/assembly/binary.xml</descriptor> + </descriptors> + </configuration> + <executions> + <execution> + <id>make-assembly</id> + <phase>deploy</phase> + <goals> + <goal>attached</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file Copied: branches/openfast-2.x/core/src (from rev 155, branches/openfast-2.x/src) Modified: branches/openfast-2.x/pom.xml =================================================================== --- branches/openfast-2.x/pom.xml 2008-06-25 02:55:47 UTC (rev 155) +++ branches/openfast-2.x/pom.xml 2008-06-25 03:12:39 UTC (rev 156) @@ -2,8 +2,8 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.openfast</groupId> <artifactId>openfast</artifactId> - <packaging>jar</packaging> - <version>1.0.0-SNAPSHOT</version> + <packaging>pom</packaging> + <version>2.0.0-SNAPSHOT</version> <organization> <name>The LaSalle Technology Group, LLC</name> @@ -16,6 +16,9 @@ OpenFAST is a 100% Java implementation of the FAST Protocol. </description> + <modules> + <module>core</module> + </modules> <developers> <developer> <name>Jacob Northey</name> @@ -71,9 +74,9 @@ </issueManagement> <scm> - <connection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/trunk</connection> - <developerConnection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/trunk</developerConnection> - <url>http://openfast.svn.sourceforge.net/viewvc/openfast/tags/trunk</url> + <connection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/branches/openfast-2.x</connection> + <developerConnection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/branches/openfast-2.x</developerConnection> + <url>http://openfast.svn.sourceforge.net/viewvc/openfast/tags/branches/openfast-2.x</url> </scm> <mailingLists> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-06-25 02:55:38
|
Revision: 155 http://openfast.svn.sourceforge.net/openfast/?rev=155&view=rev Author: jacob_northey Date: 2008-06-24 19:55:47 -0700 (Tue, 24 Jun 2008) Log Message: ----------- Branch completely different code bases Added Paths: ----------- branches/openfast-2.x/ Copied: branches/openfast-2.x (from rev 154, trunk) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-06-02 12:54:13
|
Revision: 154 http://openfast.svn.sourceforge.net/openfast/?rev=154&view=rev Author: jacob_northey Date: 2008-06-02 05:54:19 -0700 (Mon, 02 Jun 2008) Log Message: ----------- Reformatted entire code base to include license header and replace tabs with spaces Modified Paths: -------------- trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java trunk/src/main/java/org/openfast/template/loader/StringParser.java trunk/src/main/java/org/openfast/template/loader/TemplateParser.java Modified: trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java =================================================================== --- trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java 2008-05-30 20:39:17 UTC (rev 153) +++ trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java 2008-06-02 12:54:19 UTC (rev 154) @@ -108,6 +108,7 @@ Thread.sleep(20); } catch (InterruptedException e) {} Message message = session.in.readMessage(); + session.setMessageHandler(messageListener); String serverName = message.getString(1); String vendorId = message.isDefined(2) ? message.getString(2) : "unknown"; session.setClient(new BasicClient(serverName, vendorId)); Modified: trunk/src/main/java/org/openfast/template/loader/StringParser.java =================================================================== --- trunk/src/main/java/org/openfast/template/loader/StringParser.java 2008-05-30 20:39:17 UTC (rev 153) +++ trunk/src/main/java/org/openfast/template/loader/StringParser.java 2008-06-02 12:54:19 UTC (rev 154) @@ -1,3 +1,23 @@ +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> + */ package org.openfast.template.loader; import org.w3c.dom.Element; @@ -3,17 +23,16 @@ public class StringParser extends VariableLengthScalarParser { + public StringParser() { + super("string"); + } - public StringParser() { - super ("string"); - } + public boolean canParse(Element element, ParsingContext context) { + return element.getNodeName().equals("string"); + } - public boolean canParse(Element element, ParsingContext context) { - return element.getNodeName().equals("string"); - } - - protected String getTypeName(Element fieldNode) { - if (fieldNode.hasAttribute("charset")) - return fieldNode.getAttribute("charset"); - return "ascii"; - } + protected String getTypeName(Element fieldNode) { + if (fieldNode.hasAttribute("charset")) + return fieldNode.getAttribute("charset"); + return "ascii"; + } } Modified: trunk/src/main/java/org/openfast/template/loader/TemplateParser.java =================================================================== --- trunk/src/main/java/org/openfast/template/loader/TemplateParser.java 2008-05-30 20:39:17 UTC (rev 153) +++ trunk/src/main/java/org/openfast/template/loader/TemplateParser.java 2008-06-02 12:54:19 UTC (rev 154) @@ -1,3 +1,23 @@ +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> + */ package org.openfast.template.loader; import org.openfast.QName; @@ -6,35 +26,37 @@ import org.w3c.dom.Element; public class TemplateParser extends GroupParser { + private boolean loadTemplateIdFromAuxId; - private boolean loadTemplateIdFromAuxId; + public TemplateParser(boolean loadTemplateIdFromAuxId) { + this.loadTemplateIdFromAuxId = loadTemplateIdFromAuxId; + } - public TemplateParser(boolean loadTemplateIdFromAuxId) { - this.loadTemplateIdFromAuxId = loadTemplateIdFromAuxId; - } - - /** + /** * Creates a MessageTemplate object from the dom template element - * @param context - * @param templateElement The dom element object + * + * @param context + * @param templateElement + * The dom element object * @return Returns a newly created MessageTemplate object */ - protected Field parse(Element templateElement, boolean optional, ParsingContext context) { - MessageTemplate messageTemplate = new MessageTemplate(getTemplateName(templateElement, context), parseFields(templateElement, context)); - parseMore(templateElement, messageTemplate, context); - if (loadTemplateIdFromAuxId && templateElement.hasAttribute("id")) { - try { - int templateId = Integer.parseInt(templateElement.getAttribute("id")); - context.getTemplateRegistry().register(templateId, messageTemplate); - } catch (NumberFormatException e) { - context.getTemplateRegistry().define(messageTemplate); - } - } else - context.getTemplateRegistry().define(messageTemplate); - return messageTemplate; - } + protected Field parse(Element templateElement, boolean optional, ParsingContext context) { + MessageTemplate messageTemplate = new MessageTemplate(getTemplateName(templateElement, context), parseFields(templateElement, + context)); + parseMore(templateElement, messageTemplate, context); + if (loadTemplateIdFromAuxId && templateElement.hasAttribute("id")) { + try { + int templateId = Integer.parseInt(templateElement.getAttribute("id")); + context.getTemplateRegistry().register(templateId, messageTemplate); + } catch (NumberFormatException e) { + context.getTemplateRegistry().define(messageTemplate); + } + } else + context.getTemplateRegistry().define(messageTemplate); + return messageTemplate; + } - private QName getTemplateName(Element templateElement, ParsingContext context) { - return new QName(templateElement.getAttribute("name"), context.getTemplateNamespace()); - } + private QName getTemplateName(Element templateElement, ParsingContext context) { + return new QName(templateElement.getAttribute("name"), context.getTemplateNamespace()); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-05-30 20:39:17
|
Revision: 153 http://openfast.svn.sourceforge.net/openfast/?rev=153&view=rev Author: jacob_northey Date: 2008-05-30 13:39:17 -0700 (Fri, 30 May 2008) Log Message: ----------- Reformatted entire code base to include license header and replace tabs with spaces Modified Paths: -------------- trunk/src/main/java/org/openfast/BitVector.java trunk/src/main/java/org/openfast/BitVectorBuilder.java trunk/src/main/java/org/openfast/BitVectorReader.java trunk/src/main/java/org/openfast/BitVectorValue.java trunk/src/main/java/org/openfast/ByteUtil.java trunk/src/main/java/org/openfast/ByteVectorValue.java trunk/src/main/java/org/openfast/DateValue.java trunk/src/main/java/org/openfast/FieldValue.java trunk/src/main/java/org/openfast/Global.java trunk/src/main/java/org/openfast/GlobalDictionary.java trunk/src/main/java/org/openfast/GroupValue.java trunk/src/main/java/org/openfast/IntegerValue.java trunk/src/main/java/org/openfast/MessageBlockReader.java trunk/src/main/java/org/openfast/MessageHandler.java trunk/src/main/java/org/openfast/MessageInputStream.java trunk/src/main/java/org/openfast/MessageStream.java trunk/src/main/java/org/openfast/NumericValue.java trunk/src/main/java/org/openfast/ScalarValue.java trunk/src/main/java/org/openfast/SequenceValue.java trunk/src/main/java/org/openfast/codec/Coder.java trunk/src/main/java/org/openfast/codec/FastDecoder.java trunk/src/main/java/org/openfast/codec/FastEncoder.java trunk/src/main/java/org/openfast/debug/Trace.java trunk/src/main/java/org/openfast/error/ErrorCode.java trunk/src/main/java/org/openfast/error/ErrorHandler.java trunk/src/main/java/org/openfast/error/ErrorType.java trunk/src/main/java/org/openfast/error/FastAlertSeverity.java trunk/src/main/java/org/openfast/error/FastConstants.java trunk/src/main/java/org/openfast/error/FastDynamicError.java trunk/src/main/java/org/openfast/error/FastException.java trunk/src/main/java/org/openfast/session/AbstractSessionControlProtocol.java trunk/src/main/java/org/openfast/session/BasicClient.java trunk/src/main/java/org/openfast/session/Client.java trunk/src/main/java/org/openfast/session/ConnectionListener.java trunk/src/main/java/org/openfast/session/Endpoint.java trunk/src/main/java/org/openfast/session/FastClient.java trunk/src/main/java/org/openfast/session/FastConnectionException.java trunk/src/main/java/org/openfast/session/LocalConnection.java trunk/src/main/java/org/openfast/session/LocalEndpoint.java trunk/src/main/java/org/openfast/session/MessageListener.java trunk/src/main/java/org/openfast/session/RecordingEndpoint.java trunk/src/main/java/org/openfast/session/SessionConstants.java trunk/src/main/java/org/openfast/session/SessionHandler.java trunk/src/main/java/org/openfast/session/SessionListener.java trunk/src/main/java/org/openfast/session/SessionMessageHandler.java trunk/src/main/java/org/openfast/session/SessionProtocol.java trunk/src/main/java/org/openfast/session/multicast/MulticastConnection.java trunk/src/main/java/org/openfast/session/multicast/MulticastEndpoint.java trunk/src/main/java/org/openfast/session/multicast/MulticastInputStream.java trunk/src/main/java/org/openfast/session/template/exchange/AbstractFieldInstructionConverter.java trunk/src/main/java/org/openfast/session/template/exchange/ComposedDecimalConverter.java trunk/src/main/java/org/openfast/session/template/exchange/ConversionContext.java trunk/src/main/java/org/openfast/session/template/exchange/DynamicTemplateReferenceConverter.java trunk/src/main/java/org/openfast/session/template/exchange/FieldInstructionConverter.java trunk/src/main/java/org/openfast/session/template/exchange/GroupConverter.java trunk/src/main/java/org/openfast/session/template/exchange/ScalarConverter.java trunk/src/main/java/org/openfast/session/template/exchange/SequenceConverter.java trunk/src/main/java/org/openfast/session/template/exchange/StaticTemplateReferenceConverter.java trunk/src/main/java/org/openfast/session/template/exchange/VariableLengthInstructionConverter.java trunk/src/main/java/org/openfast/template/AbstractTemplateRegistry.java trunk/src/main/java/org/openfast/template/BasicTemplateRegistry.java trunk/src/main/java/org/openfast/template/ComposedScalar.java trunk/src/main/java/org/openfast/template/ComposedValueConverter.java trunk/src/main/java/org/openfast/template/DynamicTemplateReference.java trunk/src/main/java/org/openfast/template/Field.java trunk/src/main/java/org/openfast/template/FieldSet.java trunk/src/main/java/org/openfast/template/Group.java trunk/src/main/java/org/openfast/template/LongValue.java trunk/src/main/java/org/openfast/template/MessageTemplate.java trunk/src/main/java/org/openfast/template/NullTemplateRegistry.java trunk/src/main/java/org/openfast/template/Sequence.java trunk/src/main/java/org/openfast/template/StaticTemplateReference.java trunk/src/main/java/org/openfast/template/TemplateRegisteredListener.java trunk/src/main/java/org/openfast/template/TwinValue.java trunk/src/main/java/org/openfast/template/loader/AbstractFieldParser.java trunk/src/main/java/org/openfast/template/loader/ByteVectorParser.java trunk/src/main/java/org/openfast/template/loader/ComposedDecimalParser.java trunk/src/main/java/org/openfast/template/loader/FieldParser.java trunk/src/main/java/org/openfast/template/loader/GroupParser.java trunk/src/main/java/org/openfast/template/loader/MessageTemplateLoader.java trunk/src/main/java/org/openfast/template/loader/ParsingContext.java trunk/src/main/java/org/openfast/template/loader/ScalarParser.java trunk/src/main/java/org/openfast/template/loader/SequenceParser.java trunk/src/main/java/org/openfast/template/loader/TemplateRefParser.java trunk/src/main/java/org/openfast/template/loader/VariableLengthScalarParser.java trunk/src/main/java/org/openfast/template/loader/XMLMessageTemplateLoader.java trunk/src/main/java/org/openfast/template/operator/AlwaysPresentOperatorCodec.java trunk/src/main/java/org/openfast/template/operator/ConstantOperatorCodec.java trunk/src/main/java/org/openfast/template/operator/CopyOperatorCodec.java trunk/src/main/java/org/openfast/template/operator/DefaultOperatorCodec.java trunk/src/main/java/org/openfast/template/operator/DeltaDecimalOperatorCodec.java trunk/src/main/java/org/openfast/template/operator/DeltaStringOperatorCodec.java trunk/src/main/java/org/openfast/template/operator/IncrementIntegerOperatorCodec.java trunk/src/main/java/org/openfast/template/operator/NoneOperatorCodec.java trunk/src/main/java/org/openfast/template/operator/Operator.java trunk/src/main/java/org/openfast/template/operator/OperatorCodec.java trunk/src/main/java/org/openfast/template/operator/OptionallyPresentOperatorCodec.java trunk/src/main/java/org/openfast/template/operator/TailOperatorCodec.java trunk/src/main/java/org/openfast/template/type/ByteVectorType.java trunk/src/main/java/org/openfast/template/type/DateType.java trunk/src/main/java/org/openfast/template/type/DecimalConverter.java trunk/src/main/java/org/openfast/template/type/DecimalType.java trunk/src/main/java/org/openfast/template/type/IntegerType.java trunk/src/main/java/org/openfast/template/type/SignedIntegerType.java trunk/src/main/java/org/openfast/template/type/SimpleType.java trunk/src/main/java/org/openfast/template/type/StringType.java trunk/src/main/java/org/openfast/template/type/Type.java trunk/src/main/java/org/openfast/template/type/UnsignedIntegerType.java trunk/src/main/java/org/openfast/template/type/codec/AsciiString.java trunk/src/main/java/org/openfast/template/type/codec/BitVectorType.java trunk/src/main/java/org/openfast/template/type/codec/DateInteger.java trunk/src/main/java/org/openfast/template/type/codec/DateString.java trunk/src/main/java/org/openfast/template/type/codec/EpochTimestamp.java trunk/src/main/java/org/openfast/template/type/codec/IntegerCodec.java trunk/src/main/java/org/openfast/template/type/codec/MillisecondsSinceMidnight.java trunk/src/main/java/org/openfast/template/type/codec/NotStopBitEncodedTypeCodec.java trunk/src/main/java/org/openfast/template/type/codec/NullableAsciiString.java trunk/src/main/java/org/openfast/template/type/codec/NullableByteVector.java trunk/src/main/java/org/openfast/template/type/codec/NullableSignedInteger.java trunk/src/main/java/org/openfast/template/type/codec/NullableSingleFieldDecimal.java trunk/src/main/java/org/openfast/template/type/codec/NullableStringDelta.java trunk/src/main/java/org/openfast/template/type/codec/NullableUnicodeString.java trunk/src/main/java/org/openfast/template/type/codec/NullableUnsignedInteger.java trunk/src/main/java/org/openfast/template/type/codec/SignedInteger.java trunk/src/main/java/org/openfast/template/type/codec/SingleFieldDecimal.java trunk/src/main/java/org/openfast/template/type/codec/StringDelta.java trunk/src/main/java/org/openfast/template/type/codec/TimeInteger.java trunk/src/main/java/org/openfast/template/type/codec/TimestampInteger.java trunk/src/main/java/org/openfast/template/type/codec/TypeCodec.java trunk/src/main/java/org/openfast/template/type/codec/UnicodeString.java trunk/src/main/java/org/openfast/template/type/codec/UnsignedInteger.java trunk/src/main/java/org/openfast/util/ArrayIterator.java trunk/src/main/java/org/openfast/util/Key.java trunk/src/main/java/org/openfast/util/RecordingInputStream.java trunk/src/main/java/org/openfast/util/RecordingOutputStream.java trunk/src/main/java/org/openfast/util/Util.java Modified: trunk/src/main/java/org/openfast/BitVector.java =================================================================== --- trunk/src/main/java/org/openfast/BitVector.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/BitVector.java 2008-05-30 20:39:17 UTC (rev 153) @@ -17,9 +17,7 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast; public class BitVector { @@ -44,19 +42,14 @@ public byte[] getTruncatedBytes() { int index = bytes.length - 1; - - for (; (index > 0) && ((bytes[index] & VALUE_BITS_SET) == 0); - index--) + for (; (index > 0) && ((bytes[index] & VALUE_BITS_SET) == 0); index--) ; - if (index == (bytes.length - 1)) { return bytes; } - byte[] truncated = new byte[index + 1]; System.arraycopy(bytes, 0, truncated, 0, index + 1); truncated[truncated.length - 1] |= STOP_BIT; - return truncated; } @@ -69,7 +62,8 @@ } public boolean isSet(int fieldIndex) { - if (fieldIndex >= bytes.length * 7) return false; + if (fieldIndex >= bytes.length * 7) + return false; return ((bytes[fieldIndex / 7] & (1 << (6 - (fieldIndex % 7)))) > 0); } @@ -77,7 +71,6 @@ if ((obj == null) || !(obj instanceof BitVector)) { return false; } - return equals((BitVector) obj); } @@ -85,33 +78,30 @@ if (other.size != this.size) { return false; } - for (int i = 0; i < this.bytes.length; i++) { if (this.bytes[i] != other.bytes[i]) { return false; } } - return true; } - + public int hashCode() { - return bytes.hashCode(); + return bytes.hashCode(); } public boolean isOverlong() { - return (bytes.length > 1) && - ((bytes[bytes.length - 1] & VALUE_BITS_SET) == 0); + return (bytes.length > 1) && ((bytes[bytes.length - 1] & VALUE_BITS_SET) == 0); } public String toString() { - return "BitVector [" + ByteUtil.convertByteArrayToBitString(bytes) + - "]"; + return "BitVector [" + ByteUtil.convertByteArrayToBitString(bytes) + "]"; } - public int indexOfLastSet() { - int index = bytes.length * 7 - 1; - while (index >= 0 && !isSet(index)) index--; - return index; - } + public int indexOfLastSet() { + int index = bytes.length * 7 - 1; + while (index >= 0 && !isSet(index)) + index--; + return index; + } } Modified: trunk/src/main/java/org/openfast/BitVectorBuilder.java =================================================================== --- trunk/src/main/java/org/openfast/BitVectorBuilder.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/BitVectorBuilder.java 2008-05-30 20:39:17 UTC (rev 153) @@ -1,36 +1,49 @@ -package org.openfast; +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ -public class BitVectorBuilder { +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. - private final BitVector vector; - private int index=0; +The Original Code is OpenFAST. - public BitVectorBuilder(int size) { - vector = new BitVector(size); - } - - public void set() { - vector.set(index); - index++; - } - - public void skip() { - index++; - } +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. - public BitVector getBitVector() { - return vector; - } +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> + */ +package org.openfast; - public void setOnValueSkipOnNull(Object value) { - if (value == null) - skip(); - else - set(); - } +public class BitVectorBuilder { + private final BitVector vector; + private int index = 0; - public int getIndex() { - return index; - } - + public BitVectorBuilder(int size) { + vector = new BitVector(size); + } + public void set() { + vector.set(index); + index++; + } + public void skip() { + index++; + } + public BitVector getBitVector() { + return vector; + } + public void setOnValueSkipOnNull(Object value) { + if (value == null) + skip(); + else + set(); + } + public int getIndex() { + return index; + } } Modified: trunk/src/main/java/org/openfast/BitVectorReader.java =================================================================== --- trunk/src/main/java/org/openfast/BitVectorReader.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/BitVectorReader.java 2008-05-30 20:39:17 UTC (rev 153) @@ -1,51 +1,68 @@ +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> + */ package org.openfast; public class BitVectorReader { + public static final BitVectorReader NULL = new BitVectorReader(null) { + public boolean read() { + throw new IllegalStateException(); + } - public static final BitVectorReader NULL = new BitVectorReader(null) { - public boolean read() { - throw new IllegalStateException(); - } - - public boolean hasMoreBitsSet() { - return false; - } - }; + public boolean hasMoreBitsSet() { + return false; + } + }; + public static final BitVectorReader INFINITE_TRUE = new BitVectorReader(null) { + public boolean read() { + return true; + } + }; + private final BitVector vector; + private int index = 0; - public static final BitVectorReader INFINITE_TRUE = new BitVectorReader(null) { - public boolean read() { - return true; - } - }; - - private final BitVector vector; - private int index=0; + public BitVectorReader(BitVector vector) { + this.vector = vector; + } - public BitVectorReader(BitVector vector) { - this.vector = vector; - } - - public boolean read() { - return vector.isSet(index++); - } + public boolean read() { + return vector.isSet(index++); + } - public BitVector getBitVector() { - return vector; - } + public BitVector getBitVector() { + return vector; + } - public boolean hasMoreBitsSet() { - return vector.indexOfLastSet() > index; - } - - public String toString() { - return vector.toString(); - } + public boolean hasMoreBitsSet() { + return vector.indexOfLastSet() > index; + } - public boolean peek() { - return vector.isSet(index); - } + public String toString() { + return vector.toString(); + } - public int getIndex() { - return index; - } + public boolean peek() { + return vector.isSet(index); + } + + public int getIndex() { + return index; + } } Modified: trunk/src/main/java/org/openfast/BitVectorValue.java =================================================================== --- trunk/src/main/java/org/openfast/BitVectorValue.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/BitVectorValue.java 2008-05-30 20:39:17 UTC (rev 153) @@ -18,8 +18,6 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> */ - - package org.openfast; public class BitVectorValue extends ScalarValue { Modified: trunk/src/main/java/org/openfast/ByteUtil.java =================================================================== --- trunk/src/main/java/org/openfast/ByteUtil.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/ByteUtil.java 2008-05-30 20:39:17 UTC (rev 153) @@ -17,33 +17,29 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast; import java.io.ByteArrayInputStream; import java.io.InputStream; - public class ByteUtil { /** - * - * @param bitString in the format of space separated 8-bit bytes (i.e. "01010101 10101010") + * + * @param bitString + * in the format of space separated 8-bit bytes (i.e. "01010101 + * 10101010") * @return byte array representation of the bit string */ public static byte[] convertBitStringToFastByteArray(String bitString) { if (bitString.length() == 0) { return new byte[0]; } - String[] bitStrings = bitString.split(" "); byte[] bytes = new byte[bitStrings.length]; - for (int i = 0; i < bitStrings.length; i++) { bytes[i] = (byte) Integer.parseInt(bitStrings[i], 2); } - return bytes; } @@ -51,21 +47,20 @@ if (hexString == null) { return new byte[0]; } - hexString = hexString.replaceAll(" ", ""); - byte[] bytes = new byte[hexString.length()/2]; - - for (int i = 0; i < hexString.length(); i+=2) { - bytes[i/2] = (byte) Integer.parseInt(hexString.substring(i, i+2), 16); + byte[] bytes = new byte[hexString.length() / 2]; + for (int i = 0; i < hexString.length(); i += 2) { + bytes[i / 2] = (byte) Integer.parseInt(hexString.substring(i, i + 2), 16); } - return bytes; } /** - * - * @param bytes byte array - * @return space separated 8-bit string encoding of byte (i.e. "01010101 10101010") + * + * @param bytes + * byte array + * @return space separated 8-bit string encoding of byte (i.e. "01010101 + * 10101010") */ public static String convertByteArrayToBitString(byte[] bytes) { return convertByteArrayToBitString(bytes, bytes.length); @@ -75,43 +70,37 @@ if (bytes.length == 0) { return ""; } - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < length; i++) { String bits = Integer.toString(bytes[i] & 0xFF, 2); - for (int j = 0; j < (8 - bits.length()); j++) builder.append('0'); - builder.append(bits).append(' '); } - if (builder.length() > 0) - builder.deleteCharAt(builder.length() - 1); - + builder.deleteCharAt(builder.length() - 1); return builder.toString(); } public static InputStream createByteStream(String bitString) { - return new ByteArrayInputStream(convertBitStringToFastByteArray( - bitString)); + return new ByteArrayInputStream(convertBitStringToFastByteArray(bitString)); } public static InputStream createByteStreamFromHexBytes(String hexString) { return new ByteArrayInputStream(convertHexStringToByteArray(hexString)); } - public static byte[] combine(byte[] first, byte[] second) { - byte[] result = new byte[first.length + second.length]; - System.arraycopy(first, 0, result, 0, first.length); - System.arraycopy(second, 0, result, first.length, second.length); - return result; - } + public static byte[] combine(byte[] first, byte[] second) { + byte[] result = new byte[first.length + second.length]; + System.arraycopy(first, 0, result, 0, first.length); + System.arraycopy(second, 0, result, first.length, second.length); + return result; + } - public static boolean isEmpty(byte[] bytes) { - for (int i=0; i<bytes.length; i++) - if ((bytes[i] & 0x7f) != 0) return false; - return true; - } + public static boolean isEmpty(byte[] bytes) { + for (int i = 0; i < bytes.length; i++) + if ((bytes[i] & 0x7f) != 0) + return false; + return true; + } } Modified: trunk/src/main/java/org/openfast/ByteVectorValue.java =================================================================== --- trunk/src/main/java/org/openfast/ByteVectorValue.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/ByteVectorValue.java 2008-05-30 20:39:17 UTC (rev 153) @@ -17,39 +17,36 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast; public class ByteVectorValue extends ScalarValue { private static final long serialVersionUID = 1L; - public final byte[] value; + public final byte[] value; public ByteVectorValue(byte[] value) { this.value = value; } - + public byte[] getBytes() { - return value; + return value; } - + public String toString() { - StringBuffer builder = new StringBuffer(value.length*2); - for (int i=0; i<value.length; i++) { - String hex = Integer.toHexString(value[i]); - if (hex.length() == 1) - builder.append('0'); - builder.append(hex); - } - return builder.toString(); + StringBuffer builder = new StringBuffer(value.length * 2); + for (int i = 0; i < value.length; i++) { + String hex = Integer.toHexString(value[i]); + if (hex.length() == 1) + builder.append('0'); + builder.append(hex); + } + return builder.toString(); } public boolean equals(Object obj) { if ((obj == null) || !(obj instanceof ByteVectorValue)) { return false; } - return equals((ByteVectorValue) obj); } @@ -57,16 +54,14 @@ if (this.value.length != other.value.length) { return false; } - for (int i = 0; i < this.value.length; i++) if (this.value[i] != other.value[i]) { return false; } - return true; } public int hashCode() { - return value.hashCode(); + return value.hashCode(); } } Modified: trunk/src/main/java/org/openfast/DateValue.java =================================================================== --- trunk/src/main/java/org/openfast/DateValue.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/DateValue.java 2008-05-30 20:39:17 UTC (rev 153) @@ -1,3 +1,23 @@ +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> + */ package org.openfast; import java.util.Date; @@ -3,31 +23,33 @@ public class DateValue extends ScalarValue { - private static final long serialVersionUID = 1L; - public final Date value; + private static final long serialVersionUID = 1L; + public final Date value; - public DateValue(Date date) { - this.value = date; - } + public DateValue(Date date) { + this.value = date; + } - public long toLong() { - return value.getTime(); - } - - public String toString() { - return value.toString(); - } - - public boolean equals(Object other) { - if (other == this) return true; - if (other == null || !(other instanceof DateValue)) return false; - return equals((DateValue) other); - } - - private boolean equals(DateValue other) { - return other.value.equals(value); - } + public long toLong() { + return value.getTime(); + } + public String toString() { + return value.toString(); + } + + public boolean equals(Object other) { + if (other == this) + return true; + if (other == null || !(other instanceof DateValue)) + return false; + return equals((DateValue) other); + } + + private boolean equals(DateValue other) { + return other.value.equals(value); + } + public int hashCode() { - return value.hashCode(); + return value.hashCode(); } } Modified: trunk/src/main/java/org/openfast/FieldValue.java =================================================================== --- trunk/src/main/java/org/openfast/FieldValue.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/FieldValue.java 2008-05-30 20:39:17 UTC (rev 153) @@ -17,13 +17,11 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast; import java.io.Serializable; public interface FieldValue extends Serializable { - FieldValue copy(); + FieldValue copy(); } Modified: trunk/src/main/java/org/openfast/Global.java =================================================================== --- trunk/src/main/java/org/openfast/Global.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/Global.java 2008-05-30 20:39:17 UTC (rev 153) @@ -1,3 +1,23 @@ +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> + */ package org.openfast; import org.openfast.error.ErrorCode; @@ -4,28 +24,27 @@ import org.openfast.error.ErrorHandler; public final class Global { - private static ErrorHandler errorHandler = ErrorHandler.DEFAULT; - private static int currentImplicitId = (int) (System.currentTimeMillis() % 10000); - - public static void setErrorHandler(ErrorHandler handler) { - if (handler == null) { - throw new NullPointerException(); - } - - Global.errorHandler = handler; - } + private static ErrorHandler errorHandler = ErrorHandler.DEFAULT; + private static int currentImplicitId = (int) (System.currentTimeMillis() % 10000); - public static void handleError(ErrorCode error, String message) { - errorHandler.error(error, message); - } + public static void setErrorHandler(ErrorHandler handler) { + if (handler == null) { + throw new NullPointerException(); + } + Global.errorHandler = handler; + } - public static void handleError(ErrorCode error, String message, Throwable source) { - errorHandler.error(error, message, source); - } + public static void handleError(ErrorCode error, String message) { + errorHandler.error(error, message); + } - public static QName createImplicitName(QName name) { - return new QName(name + "@" + currentImplicitId++, name.getNamespace()); - } + public static void handleError(ErrorCode error, String message, Throwable source) { + errorHandler.error(error, message, source); + } - private Global() {} + public static QName createImplicitName(QName name) { + return new QName(name + "@" + currentImplicitId++, name.getNamespace()); + } + + private Global() {} } Modified: trunk/src/main/java/org/openfast/GlobalDictionary.java =================================================================== --- trunk/src/main/java/org/openfast/GlobalDictionary.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/GlobalDictionary.java 2008-05-30 20:39:17 UTC (rev 153) @@ -18,8 +18,6 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> */ - - package org.openfast; import org.openfast.template.Group; Modified: trunk/src/main/java/org/openfast/GroupValue.java =================================================================== --- trunk/src/main/java/org/openfast/GroupValue.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/GroupValue.java 2008-05-30 20:39:17 UTC (rev 153) @@ -18,7 +18,6 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> */ - package org.openfast; import java.math.BigDecimal; Modified: trunk/src/main/java/org/openfast/IntegerValue.java =================================================================== --- trunk/src/main/java/org/openfast/IntegerValue.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/IntegerValue.java 2008-05-30 20:39:17 UTC (rev 153) @@ -17,20 +17,16 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast; import java.math.BigDecimal; - import org.openfast.error.FastConstants; import org.openfast.template.LongValue; - public class IntegerValue extends NumericValue { private static final long serialVersionUID = 1L; - public final int value; + public final int value; public IntegerValue(int value) { this.value = value; @@ -40,16 +36,15 @@ if ((obj == null) || !(obj instanceof NumericValue)) { return false; } - return equals((NumericValue) obj); } private boolean equals(NumericValue otherValue) { return value == otherValue.toLong(); } - + public int hashCode() { - return value; + return value; } public boolean equalsValue(String defaultValue) { @@ -68,7 +63,6 @@ if (subend instanceof LongValue) { return new LongValue(this.value - subend.toLong()); } - return new IntegerValue(this.value - subend.toInt()); } @@ -76,7 +70,6 @@ if (addend instanceof LongValue) { return addend.add(this); } - return new IntegerValue(this.value + addend.toInt()); } @@ -99,24 +92,24 @@ public String toString() { return String.valueOf(value); } - + public byte toByte() { - if (value > Byte.MAX_VALUE || value < Byte.MIN_VALUE) - Global.handleError(FastConstants.R4_NUMERIC_VALUE_TOO_LARGE, "The value \"" + value + "\" is too large for a byte."); - return (byte) value; + if (value > Byte.MAX_VALUE || value < Byte.MIN_VALUE) + Global.handleError(FastConstants.R4_NUMERIC_VALUE_TOO_LARGE, "The value \"" + value + "\" is too large for a byte."); + return (byte) value; } - + public short toShort() { - if (value > Short.MAX_VALUE || value < Short.MIN_VALUE) - Global.handleError(FastConstants.R4_NUMERIC_VALUE_TOO_LARGE, "The value \"" + value + "\" is too large for a short."); - return (short) value; + if (value > Short.MAX_VALUE || value < Short.MIN_VALUE) + Global.handleError(FastConstants.R4_NUMERIC_VALUE_TOO_LARGE, "The value \"" + value + "\" is too large for a short."); + return (short) value; } - + public double toDouble() { - return value; + return value; } - + public BigDecimal toBigDecimal() { - return new BigDecimal(value); + return new BigDecimal(value); } } Modified: trunk/src/main/java/org/openfast/MessageBlockReader.java =================================================================== --- trunk/src/main/java/org/openfast/MessageBlockReader.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/MessageBlockReader.java 2008-05-30 20:39:17 UTC (rev 153) @@ -1,3 +1,23 @@ +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> + */ package org.openfast; import java.io.InputStream; @@ -3,15 +23,14 @@ public interface MessageBlockReader { + MessageBlockReader NULL = new MessageBlockReader() { + public boolean readBlock(InputStream in) { + return true; + } - MessageBlockReader NULL = new MessageBlockReader(){ - public boolean readBlock(InputStream in) { - return true; - } + public void messageRead(InputStream in, Message message) {} + }; - public void messageRead(InputStream in, Message message) { - }}; + boolean readBlock(InputStream in); - boolean readBlock(InputStream in); - void messageRead(InputStream in, Message message); - + void messageRead(InputStream in, Message message); } Modified: trunk/src/main/java/org/openfast/MessageHandler.java =================================================================== --- trunk/src/main/java/org/openfast/MessageHandler.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/MessageHandler.java 2008-05-30 20:39:17 UTC (rev 153) @@ -18,8 +18,6 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> */ - - package org.openfast; import org.openfast.codec.Coder; Modified: trunk/src/main/java/org/openfast/MessageInputStream.java =================================================================== --- trunk/src/main/java/org/openfast/MessageInputStream.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/MessageInputStream.java 2008-05-30 20:39:17 UTC (rev 153) @@ -17,9 +17,7 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast; import java.io.IOException; @@ -29,20 +27,18 @@ import java.util.HashMap; import java.util.List; import java.util.Map; - import org.openfast.codec.FastDecoder; import org.openfast.template.MessageTemplate; import org.openfast.template.TemplateRegisteredListener; import org.openfast.template.TemplateRegistry; - public class MessageInputStream implements MessageStream { private InputStream in; private FastDecoder decoder; private Context context; private Map templateHandlers = Collections.EMPTY_MAP; - private List handlers = Collections.EMPTY_LIST; - private MessageBlockReader blockReader = MessageBlockReader.NULL; + private List handlers = Collections.EMPTY_LIST; + private MessageBlockReader blockReader = MessageBlockReader.NULL; public MessageInputStream(InputStream inputStream) { this(inputStream, new Context()); @@ -60,32 +56,25 @@ */ public Message readMessage() { if (context.isTraceEnabled()) - context.startTrace(); - + context.startTrace(); boolean keepReading = blockReader.readBlock(in); - - if (!keepReading) return null; - + if (!keepReading) + return null; Message message = decoder.readMessage(); - if (message == null) { return null; } - blockReader.messageRead(in, message); - if (!handlers.isEmpty()) { - for (int i=0; i<handlers.size(); i++) { - ((MessageHandler) handlers.get(i)).handleMessage(message, context, decoder); - } + for (int i = 0; i < handlers.size(); i++) { + ((MessageHandler) handlers.get(i)).handleMessage(message, context, decoder); + } } if (templateHandlers.containsKey(message.getTemplate())) { MessageHandler handler = (MessageHandler) templateHandlers.get(message.getTemplate()); - handler.handleMessage(message, context, decoder); - + handler.handleMessage(message, context, decoder); return readMessage(); } - return message; } @@ -109,37 +98,35 @@ if (templateHandlers == Collections.EMPTY_MAP) { templateHandlers = new HashMap(); } - templateHandlers.put(template, handler); } - public void addMessageHandler(MessageHandler handler) { - if (handlers == Collections.EMPTY_LIST) { - handlers = new ArrayList(4); - } - handlers.add(handler); - } + public void addMessageHandler(MessageHandler handler) { + if (handlers == Collections.EMPTY_LIST) { + handlers = new ArrayList(4); + } + handlers.add(handler); + } - public void setTemplateRegistry(TemplateRegistry registry) { - context.setTemplateRegistry(registry); - } - - public TemplateRegistry getTemplateRegistry() { - return context.getTemplateRegistry(); - } + public void setTemplateRegistry(TemplateRegistry registry) { + context.setTemplateRegistry(registry); + } - public void addTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener) { - } + public TemplateRegistry getTemplateRegistry() { + return context.getTemplateRegistry(); + } - public void reset() { - decoder.reset(); - } + public void addTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener) {} - public Context getContext() { - return context; - } + public void reset() { + decoder.reset(); + } - public void setBlockReader(MessageBlockReader messageBlockReader) { - this.blockReader = messageBlockReader; - } + public Context getContext() { + return context; + } + + public void setBlockReader(MessageBlockReader messageBlockReader) { + this.blockReader = messageBlockReader; + } } Modified: trunk/src/main/java/org/openfast/MessageStream.java =================================================================== --- trunk/src/main/java/org/openfast/MessageStream.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/MessageStream.java 2008-05-30 20:39:17 UTC (rev 153) @@ -18,8 +18,6 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> */ - - package org.openfast; import org.openfast.template.MessageTemplate; Modified: trunk/src/main/java/org/openfast/NumericValue.java =================================================================== --- trunk/src/main/java/org/openfast/NumericValue.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/NumericValue.java 2008-05-30 20:39:17 UTC (rev 153) @@ -18,22 +18,14 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> */ - - package org.openfast; public abstract class NumericValue extends ScalarValue { public abstract NumericValue increment(); - public abstract NumericValue decrement(); - public abstract NumericValue subtract(NumericValue priorValue); - public abstract NumericValue add(NumericValue addend); - public abstract boolean equals(int value); - public abstract long toLong(); - public abstract int toInt(); } Modified: trunk/src/main/java/org/openfast/ScalarValue.java =================================================================== --- trunk/src/main/java/org/openfast/ScalarValue.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/ScalarValue.java 2008-05-30 20:39:17 UTC (rev 153) @@ -17,51 +17,46 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast; import java.math.BigDecimal; - public class ScalarValue implements FieldValue { private static final long serialVersionUID = 1L; + public static final ScalarValue UNDEFINED = new ScalarValue() { + private static final long serialVersionUID = 1L; - public static final ScalarValue UNDEFINED = new ScalarValue() { - private static final long serialVersionUID = 1L; + public boolean isUndefined() { + return true; + } - public boolean isUndefined() { - return true; - } - - public String toString() { - return "UNDEFINED"; - } - }; - + public String toString() { + return "UNDEFINED"; + } + }; static public final ScalarValue NULL = new ScalarValue() { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public boolean isNull() { - return true; - } + public boolean isNull() { + return true; + } - public String toString() { - return "NULL"; - } - }; + public String toString() { + return "NULL"; + } + }; /** * * @return Returns false - */ + */ public boolean equalsValue(String defaultValue) { return false; } - + public FieldValue copy() { - return this; // immutable objects don't need actual copies. + return this; // immutable objects don't need actual copies. } /** @@ -81,34 +76,34 @@ } public byte toByte() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } - + public short toShort() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } - + public int toInt() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } - + public long toLong() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } - + public String toString() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } - + public byte[] getBytes() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } - + public double toDouble() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } - + public BigDecimal toBigDecimal() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } } Modified: trunk/src/main/java/org/openfast/SequenceValue.java =================================================================== --- trunk/src/main/java/org/openfast/SequenceValue.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/SequenceValue.java 2008-05-30 20:39:17 UTC (rev 153) @@ -17,29 +17,24 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast; import org.openfast.template.Sequence; - import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; - public class SequenceValue implements FieldValue { private static final long serialVersionUID = 1L; - private List elements = Collections.EMPTY_LIST; + private List elements = Collections.EMPTY_LIST; private Sequence sequence; public SequenceValue(Sequence sequence) { if (sequence == null) { throw new NullPointerException(); } - this.sequence = sequence; } @@ -55,7 +50,6 @@ if (elements == Collections.EMPTY_LIST) { elements = new ArrayList(); } - elements.add(value); } @@ -63,7 +57,6 @@ if (elements == Collections.EMPTY_LIST) { elements = new ArrayList(); } - elements.add(new GroupValue(sequence.getGroup(), values)); } @@ -71,11 +64,9 @@ if (other == this) { return true; } - if ((other == null) || !(other instanceof SequenceValue)) { return false; } - return equals((SequenceValue) other); } @@ -83,32 +74,27 @@ if (getLength() != other.getLength()) { return false; } - for (int i = 0; i < getLength(); i++) { if (!elements.get(i).equals(other.elements.get(i))) { return false; } } - return true; } - + public int hashCode() { - return elements.hashCode() * 37 + sequence.hashCode(); + return elements.hashCode() * 37 + sequence.hashCode(); } public String toString() { StringBuilder builder = new StringBuilder(); Iterator iter = elements.iterator(); builder.append("[ "); - while (iter.hasNext()) { GroupValue value = (GroupValue) iter.next(); builder.append('[').append(value).append("] "); } - builder.append("]"); - return builder.toString(); } @@ -120,15 +106,15 @@ return sequence; } - public GroupValue[] getValues() { - return (GroupValue[]) this.elements.toArray(new GroupValue[elements.size()]); - } - - public FieldValue copy() { - SequenceValue value = new SequenceValue(this.sequence); - for (int i=0; i<elements.size(); i++) { - value.add((GroupValue) ((GroupValue)elements.get(i)).copy()); - } - return value; - } + public GroupValue[] getValues() { + return (GroupValue[]) this.elements.toArray(new GroupValue[elements.size()]); + } + + public FieldValue copy() { + SequenceValue value = new SequenceValue(this.sequence); + for (int i = 0; i < elements.size(); i++) { + value.add((GroupValue) ((GroupValue) elements.get(i)).copy()); + } + return value; + } } Modified: trunk/src/main/java/org/openfast/codec/Coder.java =================================================================== --- trunk/src/main/java/org/openfast/codec/Coder.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/codec/Coder.java 2008-05-30 20:39:17 UTC (rev 153) @@ -18,8 +18,6 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> */ - - package org.openfast.codec; public interface Coder { Modified: trunk/src/main/java/org/openfast/codec/FastDecoder.java =================================================================== --- trunk/src/main/java/org/openfast/codec/FastDecoder.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/codec/FastDecoder.java 2008-05-30 20:39:17 UTC (rev 153) @@ -18,7 +18,6 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> */ - package org.openfast.codec; import org.openfast.BitVector; Modified: trunk/src/main/java/org/openfast/codec/FastEncoder.java =================================================================== --- trunk/src/main/java/org/openfast/codec/FastEncoder.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/codec/FastEncoder.java 2008-05-30 20:39:17 UTC (rev 153) @@ -29,7 +29,6 @@ import org.openfast.template.MessageTemplate; import org.openfast.template.TemplateRegisteredListener; -/* In 1.5 version use : static import java.lang.Math.*; */ public class FastEncoder implements Coder { private Context context; private List listeners = Collections.EMPTY_LIST; Modified: trunk/src/main/java/org/openfast/debug/Trace.java =================================================================== --- trunk/src/main/java/org/openfast/debug/Trace.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/debug/Trace.java 2008-05-30 20:39:17 UTC (rev 153) @@ -1,3 +1,23 @@ +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> + */ package org.openfast.debug; import org.openfast.FieldValue; @@ -5,8 +25,8 @@ import org.openfast.template.Group; public interface Trace { - void groupStart(Group group); - void groupEnd(); - void field(Field field, FieldValue value, FieldValue encoded, byte[] encoding, int pmapIndex); - void pmap(byte[] pmap); + void groupStart(Group group); + void groupEnd(); + void field(Field field, FieldValue value, FieldValue encoded, byte[] encoding, int pmapIndex); + void pmap(byte[] pmap); } Modified: trunk/src/main/java/org/openfast/error/ErrorCode.java =================================================================== --- trunk/src/main/java/org/openfast/error/ErrorCode.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/error/ErrorCode.java 2008-05-30 20:39:17 UTC (rev 153) @@ -17,17 +17,13 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast.error; import java.util.HashMap; import java.util.Map; - import org.openfast.Message; - public class ErrorCode { private static final Map ALERT_CODES = new HashMap(); private final int code; @@ -36,8 +32,7 @@ private final FastAlertSeverity severity; private final ErrorType type; - public ErrorCode(ErrorType type, int code, String shortName, - String description, FastAlertSeverity severity) { + public ErrorCode(ErrorType type, int code, String shortName, String description, FastAlertSeverity severity) { ALERT_CODES.put(new Integer(code), this); this.type = type; this.code = code; @@ -73,15 +68,17 @@ public ErrorType getType() { return type; } - + public String toString() { - return shortName + ": " + description; + return shortName + ": " + description; } - + public boolean equals(Object obj) { - if (obj == this) return true; - if (obj == null || !(obj instanceof ErrorCode)) return false; - ErrorCode other = (ErrorCode) obj; - return other.code == this.code && other.getType().equals(this.getType()); + if (obj == this) + return true; + if (obj == null || !(obj instanceof ErrorCode)) + return false; + ErrorCode other = (ErrorCode) obj; + return other.code == this.code && other.getType().equals(this.getType()); } } Modified: trunk/src/main/java/org/openfast/error/ErrorHandler.java =================================================================== --- trunk/src/main/java/org/openfast/error/ErrorHandler.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/error/ErrorHandler.java 2008-05-30 20:39:17 UTC (rev 153) @@ -18,8 +18,6 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> */ - - package org.openfast.error; public interface ErrorHandler { Modified: trunk/src/main/java/org/openfast/error/ErrorType.java =================================================================== --- trunk/src/main/java/org/openfast/error/ErrorType.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/error/ErrorType.java 2008-05-30 20:39:17 UTC (rev 153) @@ -18,8 +18,6 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> */ - - package org.openfast.error; public class ErrorType { Modified: trunk/src/main/java/org/openfast/error/FastAlertSeverity.java =================================================================== --- trunk/src/main/java/org/openfast/error/FastAlertSeverity.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/error/FastAlertSeverity.java 2008-05-30 20:39:17 UTC (rev 153) @@ -18,8 +18,6 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> */ - - package org.openfast.error; public class FastAlertSeverity { Modified: trunk/src/main/java/org/openfast/error/FastConstants.java =================================================================== --- trunk/src/main/java/org/openfast/error/FastConstants.java 2008-05-20 18:13:38 UTC (rev 152) +++ trunk/src/main/java/org/openfast/error/FastConstants.java 2008-05-30 20:39:17 UTC (rev 153) @@ -17,59 +17,57 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - + */ package org.openfast.error; import org.openfast.QName; public interface FastConstants { - QName ANY_TYPE = new QName("any"); - - FastAlertSeverity ERROR = FastAlertSeverity.ERROR; - FastAlertSeverity WARN = FastAlertSeverity.WARN; - FastAlertSeverity FATAL = FastAlertSeverity.FATAL; + QName ANY_TYPE = new QName("any"); + FastAlertSeverity ERROR = FastAlertSeverity.ERROR; + FastAlertSeverity WARN = FastAlertSeverity.WARN; + FastAlertSeverity FATAL = FastAlertSeverity.FATAL; // Error Types ErrorType DYNAMIC = new ErrorType("Dynamic"); ErrorType STATIC = new ErrorType("Static"); ErrorType REPORTABLE = new ErrorType("Reportable"); - // Static Errors ErrorCode S1_INVALID_XML = new ErrorCode(STATIC, 1, "ERR S1", "Invalid XML", ERROR); ErrorCode S2_OPERATOR_TYPE_INCOMP = new ErrorCode(STATIC, 2, "ERR S2", "Incompatible operator and type", ERROR); ErrorCode S3_INITIAL_VALUE_INCOMP = new ErrorCode(STATIC, 3, "ERR S3", "Incompatible initial value", ERROR); - ErrorCode S4_NO_INITIAL_VALUE_FOR_CONST = new ErrorCode(STATIC, 4, "ERR S4", "Fields with constant operators must have a default value defined.", ERROR); - ErrorCode S5_NO_INITVAL_MNDTRY_DFALT = new ErrorCode(STATIC, 5, "ERR S5", "No initial value for mandatory field with default operator", ERROR); - + ErrorCode S4_NO_INITIAL_VALUE_FOR_CONST = new ErrorCode(STATIC, 4, "ERR S4", + "Fields with constant operators must have a default value defined.", ERROR); + ErrorCode S5_NO_INITVAL_MNDTRY_DFALT = new ErrorCode(STATIC, 5, "ERR S5", + "No initial value for mandatory field with default operator", ERROR); // Dynamic Errors - ErrorCode D1_FIELD_APP_INCOMP = new ErrorCode(DYNAMIC, 1, "ERR D1", "Field cannot be converted to type of application field", ERROR); - ErrorCode D2_INT_OUT_OF_RANGE = new ErrorCode(DYNAMIC, 2, "ERR D2", "The integer value is out of range for the specified integer type.", WARN); + ErrorCode D1_FIELD_APP_INCOMP = new ErrorCode(DYNAMIC, 1, "ERR D1", "Field cannot be converted to type of application field", + ERROR); + ErrorCode D2_INT_OUT_OF_RANGE = new ErrorCode(DYNAMIC, 2, "ERR D2", + "The integer value is out of range for the specified integer type.", WARN); ErrorCode D3_CANT_ENCODE_VALUE = new ErrorCode(DYNAMIC, 3, "ERR D3", "The value cannot be encoded for the given operator.", ERROR); - ErrorCode D4_INVALID_TYPE = new ErrorCode(DYNAMIC, 4, "ERR D4", "The previous value is not the same type as the type of the current field.", ERROR); - ErrorCode D5_NO_DEFAULT_VALUE = new ErrorCode(DYNAMIC, 5, "ERR D5", "If no prior value is set and the field is not present, there must be a default value or the optional flag must be set.", ERROR); + ErrorCode D4_INVALID_TYPE = new ErrorCode(DYNAMIC, 4, "ERR D4", + "The previous value is not the same type as the type of the current field.", ERROR); + ErrorCode D5_NO_DEFAULT_VALUE = new ErrorCode(DYNAMIC, 5, "ERR D5", + "If no prior value is set and the field is not present, there must be a default value or the optional flag must be set.", + ERROR); ErrorCode D6_MNDTRY_FIELD_NOT_PRESENT = new ErrorCode(DYNAMIC, 6, "ERR D6", "A mandatory field must have a value", ERROR); - ErrorCode D7_SUBTRCTN_LEN_LONG = new ErrorCode(DYNAMIC, 7, "ERR D7", "The subtraction length is longer than the base value.", ERROR); + ErrorCode D7_SUBTRCTN_LEN_LONG = new ErrorCode(DYNAMIC, 7, "ERR D7", "The subtraction length is longer than the base value.", + ERROR); ErrorCode D8_TEMPLATE_NOT_EXIST = new Err... [truncated message content] |
From: <ope...@li...> - 2008-05-20 18:13:35
|
Revision: 152 http://openfast.svn.sourceforge.net/openfast/?rev=152&view=rev Author: jacob_northey Date: 2008-05-20 11:13:38 -0700 (Tue, 20 May 2008) Log Message: ----------- Fixed compiler warnings Modified Paths: -------------- trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java trunk/src/main/java/org/openfast/template/operator/IncrementIntegerOperatorCodec.java trunk/src/main/java/org/openfast/template/type/DecimalConverter.java trunk/src/main/java/org/openfast/template/type/Type.java trunk/src/main/java/org/openfast/template/type/codec/NullableSignedInteger.java trunk/src/main/java/org/openfast/template/type/codec/NullableUnsignedInteger.java Modified: trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java =================================================================== --- trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java 2008-05-20 17:26:41 UTC (rev 151) +++ trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java 2008-05-20 18:13:38 UTC (rev 152) @@ -410,5 +410,4 @@ } private static final Message CLOSE = createFastAlertMessage(SessionConstants.CLOSE); - private static final TemplateRegistry PROTOCOL_TEMPLATES = new BasicTemplateRegistry(); } Modified: trunk/src/main/java/org/openfast/template/operator/IncrementIntegerOperatorCodec.java =================================================================== --- trunk/src/main/java/org/openfast/template/operator/IncrementIntegerOperatorCodec.java 2008-05-20 17:26:41 UTC (rev 151) +++ trunk/src/main/java/org/openfast/template/operator/IncrementIntegerOperatorCodec.java 2008-05-20 18:13:38 UTC (rev 152) @@ -6,7 +6,6 @@ import org.openfast.NumericValue; import org.openfast.ScalarValue; import org.openfast.template.Scalar; -import org.openfast.template.type.IntegerType; import org.openfast.template.type.Type; final class IncrementIntegerOperatorCodec extends OperatorCodec { Modified: trunk/src/main/java/org/openfast/template/type/DecimalConverter.java =================================================================== --- trunk/src/main/java/org/openfast/template/type/DecimalConverter.java 2008-05-20 17:26:41 UTC (rev 151) +++ trunk/src/main/java/org/openfast/template/type/DecimalConverter.java 2008-05-20 18:13:38 UTC (rev 152) @@ -8,6 +8,7 @@ import org.openfast.template.LongValue; public class DecimalConverter implements ComposedValueConverter { + private static final long serialVersionUID = 1L; private static final FieldValue[] NULL_SET = new FieldValue[] { null, null }; Modified: trunk/src/main/java/org/openfast/template/type/Type.java =================================================================== --- trunk/src/main/java/org/openfast/template/type/Type.java 2008-05-20 17:26:41 UTC (rev 151) +++ trunk/src/main/java/org/openfast/template/type/Type.java 2008-05-20 18:13:38 UTC (rev 152) @@ -4,10 +4,7 @@ import java.util.LinkedHashMap; import java.util.Map; -import org.openfast.Global; import org.openfast.ScalarValue; -import org.openfast.error.FastConstants; -import org.openfast.template.LongValue; import org.openfast.template.operator.Operator; import org.openfast.template.type.codec.TypeCodec; import org.openfast.util.Util; Modified: trunk/src/main/java/org/openfast/template/type/codec/NullableSignedInteger.java =================================================================== --- trunk/src/main/java/org/openfast/template/type/codec/NullableSignedInteger.java 2008-05-20 17:26:41 UTC (rev 151) +++ trunk/src/main/java/org/openfast/template/type/codec/NullableSignedInteger.java 2008-05-20 18:13:38 UTC (rev 152) @@ -25,13 +25,12 @@ */ package org.openfast.template.type.codec; -import org.openfast.IntegerValue; +import java.io.InputStream; + import org.openfast.NumericValue; import org.openfast.ScalarValue; -import java.io.InputStream; - public final class NullableSignedInteger extends IntegerCodec { private static final long serialVersionUID = 1L; Modified: trunk/src/main/java/org/openfast/template/type/codec/NullableUnsignedInteger.java =================================================================== --- trunk/src/main/java/org/openfast/template/type/codec/NullableUnsignedInteger.java 2008-05-20 17:26:41 UTC (rev 151) +++ trunk/src/main/java/org/openfast/template/type/codec/NullableUnsignedInteger.java 2008-05-20 18:13:38 UTC (rev 152) @@ -25,13 +25,12 @@ */ package org.openfast.template.type.codec; -import org.openfast.IntegerValue; +import java.io.InputStream; + import org.openfast.NumericValue; import org.openfast.ScalarValue; -import java.io.InputStream; - public final class NullableUnsignedInteger extends IntegerCodec { private static final long serialVersionUID = 1L; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-05-20 17:26:39
|
Revision: 151 http://openfast.svn.sourceforge.net/openfast/?rev=151&view=rev Author: chelckster Date: 2008-05-20 10:26:41 -0700 (Tue, 20 May 2008) Log Message: ----------- Session.java was losing root exception on listen errors Modified Paths: -------------- trunk/src/main/java/org/openfast/session/Session.java Modified: trunk/src/main/java/org/openfast/session/Session.java =================================================================== --- trunk/src/main/java/org/openfast/session/Session.java 2008-05-19 19:22:52 UTC (rev 150) +++ trunk/src/main/java/org/openfast/session/Session.java 2008-05-20 17:26:41 UTC (rev 151) @@ -155,7 +155,7 @@ listening = false; } else if (e instanceof FastException) { FastException fastException = ((FastException) e); - errorHandler.error(fastException.getCode(), fastException.getMessage()); + errorHandler.error(fastException.getCode(), fastException.getMessage(), e); } else { errorHandler.error(FastConstants.GENERAL_ERROR, e.getMessage(), e); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-05-19 19:23:07
|
Revision: 150 http://openfast.svn.sourceforge.net/openfast/?rev=150&view=rev Author: chelckster Date: 2008-05-19 12:22:52 -0700 (Mon, 19 May 2008) Log Message: ----------- Defined MessageTemplates were not being returned by the getTemplate() method. Modified Paths: -------------- trunk/src/main/java/org/openfast/template/BasicTemplateRegistry.java Added Paths: ----------- trunk/src/test/java/org/openfast/template/BasicTemplateRegistryTest.java Modified: trunk/src/main/java/org/openfast/template/BasicTemplateRegistry.java =================================================================== --- trunk/src/main/java/org/openfast/template/BasicTemplateRegistry.java 2008-05-19 13:18:07 UTC (rev 149) +++ trunk/src/main/java/org/openfast/template/BasicTemplateRegistry.java 2008-05-19 19:22:52 UTC (rev 150) @@ -66,7 +66,7 @@ return nameMap.containsKey(name); } public MessageTemplate[] getTemplates() { - return (MessageTemplate[]) templateMap.keySet().toArray(new MessageTemplate[templateMap.size()]); + return (MessageTemplate[]) templates.toArray(new MessageTemplate[templateMap.size()]); } public void remove(QName name) { MessageTemplate template = (MessageTemplate) nameMap.remove(name); Added: trunk/src/test/java/org/openfast/template/BasicTemplateRegistryTest.java =================================================================== --- trunk/src/test/java/org/openfast/template/BasicTemplateRegistryTest.java (rev 0) +++ trunk/src/test/java/org/openfast/template/BasicTemplateRegistryTest.java 2008-05-19 19:22:52 UTC (rev 150) @@ -0,0 +1,65 @@ +/* + The contents of this file are subject to the Mozilla Public License + Version 1.1 (the "License"); you may not use this file except in + compliance with the License. You may obtain a copy of the License at + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + License for the specific language governing rights and limitations + under the License. + + The Original Code is OpenFAST. + + The Initial Developer of the Original Code is The LaSalle Technology + Group, LLC. Portions created by The LaSalle Technology Group, LLC + are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + + Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> +*/ + + +package org.openfast.template; + +import java.util.Arrays; +import java.util.List; +import org.openfast.test.OpenFastTestCase; + + +public class BasicTemplateRegistryTest extends OpenFastTestCase { + + // A defined template should be in the Registry + + public void testDefine() { + MessageTemplate mt = new MessageTemplate("Logon", new Field[0]); + TemplateRegistry registry = new BasicTemplateRegistry(); + registry.define(mt); + + assertContains(mt, registry); + assertEquals(-1, registry.getId("Logon")); + assertEquals(-1, registry.getId(mt)); + assertEquals(null, registry.get(1000)); + assertEquals(mt, registry.get("Logon")); + } + + // A registerd template should be in the Registry with an ID + + public void testRegister() { + MessageTemplate mt = new MessageTemplate("Logon", new Field[0]); + TemplateRegistry registry = new BasicTemplateRegistry(); + registry.register(1000, mt); + + assertContains(mt, registry); + assertEquals(1000, registry.getId("Logon")); + assertEquals(1000, registry.getId(mt)); + assertEquals(mt, registry.get(1000)); + assertEquals(mt, registry.get("Logon")); + } + + private void assertContains(MessageTemplate mt, TemplateRegistry registry) { + List templates = Arrays.asList(registry.getTemplates()); + assertTrue(templates.contains(mt)); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-05-19 13:18:03
|
Revision: 149 http://openfast.svn.sourceforge.net/openfast/?rev=149&view=rev Author: jacob_northey Date: 2008-05-19 06:18:07 -0700 (Mon, 19 May 2008) Log Message: ----------- Fixed SCP 1.1 bugs Modified Paths: -------------- trunk/pom.xml trunk/src/assembly/source.xml trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java trunk/src/test/java/org/openfast/session/SessionControlProtocol_1_1Test.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2008-05-15 13:15:01 UTC (rev 148) +++ trunk/pom.xml 2008-05-19 13:18:07 UTC (rev 149) @@ -124,6 +124,7 @@ <directory>src/main/resources</directory> </resource> </resources> + <extensions> <extension> <groupId>org.apache.maven.wagon</groupId> @@ -154,7 +155,7 @@ <executions> <execution> <id>javadoc</id> - <phase>process-classes</phase> + <phase>site</phase> <goals> <goal>javadoc</goal> </goals> @@ -174,7 +175,7 @@ <executions> <execution> <id>make-assembly</id> - <phase>package</phase> + <phase>deploy</phase> <goals> <goal>attached</goal> </goals> Modified: trunk/src/assembly/source.xml =================================================================== --- trunk/src/assembly/source.xml 2008-05-15 13:15:01 UTC (rev 148) +++ trunk/src/assembly/source.xml 2008-05-19 13:18:07 UTC (rev 149) @@ -7,8 +7,8 @@ <includeBaseDirectory>true</includeBaseDirectory> <fileSets> <fileSet> - <directory>/</directory> - <outputDirectory>/</outputDirectory> + <directory/> + <outputDirectory/> <excludes> <exclude>**/.svn/*</exclude> <exclude>.classpath</exclude> Modified: trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java =================================================================== --- trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java 2008-05-15 13:15:01 UTC (rev 148) +++ trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java 2008-05-19 13:18:07 UTC (rev 149) @@ -58,7 +58,7 @@ private static final Map/* <MessageTemplate, SessionMessageHandler> */messageHandlers = new HashMap(); private ConversionContext initialContext = createInitialContext(); - public SessionControlProtocol_1_1() { + protected SessionControlProtocol_1_1() { messageHandlers.put(FAST_ALERT_TEMPLATE, ALERT_HANDLER); messageHandlers.put(TEMPLATE_DEFINITION, new SessionMessageHandler() { public void handleMessage(Session session, Message message) { @@ -102,6 +102,7 @@ public Session connect(String senderName, Connection connection, TemplateRegistry inboundRegistry, TemplateRegistry outboundRegistry, MessageListener messageListener, SessionListener sessionListener) { Session session = new Session(connection, this, inboundRegistry, outboundRegistry); + configureSession(session); session.out.writeMessage(createHelloMessage(senderName)); try { Thread.sleep(20); @@ -169,8 +170,8 @@ } public static final int FAST_RESET_TEMPLATE_ID = 120; - public static final int FAST_HELLO_TEMPLATE_ID = 16003; - public static final int FAST_ALERT_TEMPLATE_ID = 16004; + public static final int FAST_HELLO_TEMPLATE_ID = 16002; + public static final int FAST_ALERT_TEMPLATE_ID = 16003; public static final int TEMPLATE_DECL_ID = 16010; public static final int TEMPLATE_DEF_ID = 16011; public static final int INT32_INSTR_ID = 16012; @@ -195,12 +196,12 @@ public static final int FOREIGN_INSTR_ID = 16031; public static final int ELEMENT_ID = 16032; public static final int TEXT_ID = 16033; - public final static MessageTemplate FAST_ALERT_TEMPLATE = new MessageTemplate("", new Field[] { + public final static MessageTemplate FAST_ALERT_TEMPLATE = new MessageTemplate("Alert", new Field[] { new Scalar("Severity", Type.U32, Operator.NONE, ScalarValue.UNDEFINED, false), new Scalar("Code", Type.U32, Operator.NONE, ScalarValue.UNDEFINED, false), new Scalar("Value", Type.U32, Operator.NONE, ScalarValue.UNDEFINED, true), new Scalar("Description", Type.ASCII, Operator.NONE, ScalarValue.UNDEFINED, false), }); - public final static MessageTemplate FAST_HELLO_TEMPLATE = new MessageTemplate("", new Field[] { + public final static MessageTemplate FAST_HELLO_TEMPLATE = new MessageTemplate("Hello", new Field[] { new Scalar("SenderName", Type.ASCII, Operator.NONE, ScalarValue.UNDEFINED, false), new Scalar("VendorId", Type.ASCII, Operator.NONE, ScalarValue.UNDEFINED, true) }); public static final Message RESET = new Message(FAST_RESET_TEMPLATE) { Modified: trunk/src/test/java/org/openfast/session/SessionControlProtocol_1_1Test.java =================================================================== --- trunk/src/test/java/org/openfast/session/SessionControlProtocol_1_1Test.java 2008-05-15 13:15:01 UTC (rev 148) +++ trunk/src/test/java/org/openfast/session/SessionControlProtocol_1_1Test.java 2008-05-19 13:18:07 UTC (rev 149) @@ -13,7 +13,7 @@ private SessionControlProtocol_1_1 SCP_1_1; protected void setUp() throws Exception { - SCP_1_1 = new SessionControlProtocol_1_1(); + SCP_1_1 = (SessionControlProtocol_1_1) SessionConstants.SCP_1_1; } public void testSimpleCreateTemplateDefinitionMessage() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-05-15 13:14:56
|
Revision: 148 http://openfast.svn.sourceforge.net/openfast/?rev=148&view=rev Author: jacob_northey Date: 2008-05-15 06:15:01 -0700 (Thu, 15 May 2008) Log Message: ----------- Fixed packaging Modified Paths: -------------- trunk/pom.xml trunk/src/assembly/source.xml Added Paths: ----------- trunk/README trunk/src/assembly/binary.xml trunk/src/assembly/javadoc-jar.xml trunk/src/assembly/sources-jar.xml Added: trunk/README =================================================================== --- trunk/README (rev 0) +++ trunk/README 2008-05-15 13:15:01 UTC (rev 148) @@ -0,0 +1,8 @@ +OpenFAST uses the Maven2 build tool. Downloaded the latest version of Maven2 from http://maven.apache.org. + +To build OpenFAST using maven, enter from a command line: + > mvn package + +To generate Eclipse .project and .classpath files so that OpenFAST can be imported into Eclipse: + > mvn eclipse:eclipse + \ No newline at end of file Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2008-05-15 12:45:25 UTC (rev 147) +++ trunk/pom.xml 2008-05-15 13:15:01 UTC (rev 148) @@ -165,7 +165,10 @@ <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptors> + <descriptor>src/assembly/sources-jar.xml</descriptor> + <descriptor>src/assembly/javadoc-jar.xml</descriptor> <descriptor>src/assembly/source.xml</descriptor> + <descriptor>src/assembly/binary.xml</descriptor> </descriptors> </configuration> <executions> Added: trunk/src/assembly/binary.xml =================================================================== --- trunk/src/assembly/binary.xml (rev 0) +++ trunk/src/assembly/binary.xml 2008-05-15 13:15:01 UTC (rev 148) @@ -0,0 +1,41 @@ +<assembly> + <id>bin</id> + <formats> + <format>zip</format> + <format>tar.gz</format> + </formats> + <includeBaseDirectory>true</includeBaseDirectory> + <fileSets> + <fileSet> + <directory>src/main/java</directory> + <outputDirectory>/src</outputDirectory> + </fileSet> + <fileSet> + <directory>/</directory> + <outputDirectory>/</outputDirectory> + <includes> + <include>license.txt</include> + </includes> + </fileSet> + <fileSet> + <directory>target</directory> + <outputDirectory>/</outputDirectory> + <includes> + <include>*.jar</include> + </includes> + </fileSet> + <fileSet> + <directory>target/site/apidocs</directory> + <outputDirectory>/docs/api</outputDirectory> + </fileSet> + </fileSets> + <moduleSets> + <moduleSet> + <binaries> + <includeDependencies>false</includeDependencies> + <unpack>false</unpack> + <outputDirectory>/</outputDirectory> + </binaries> + </moduleSet> + </moduleSets> +</assembly> \ No newline at end of file Added: trunk/src/assembly/javadoc-jar.xml =================================================================== --- trunk/src/assembly/javadoc-jar.xml (rev 0) +++ trunk/src/assembly/javadoc-jar.xml 2008-05-15 13:15:01 UTC (rev 148) @@ -0,0 +1,13 @@ +<assembly> + <id>javadoc</id> + <formats> + <format>jar</format> + </formats> + <includeBaseDirectory>false</includeBaseDirectory> + <fileSets> + <fileSet> + <directory>target/site/apidocs</directory> + <outputDirectory>/</outputDirectory> + </fileSet> + </fileSets> +</assembly> \ No newline at end of file Modified: trunk/src/assembly/source.xml =================================================================== --- trunk/src/assembly/source.xml 2008-05-15 12:45:25 UTC (rev 147) +++ trunk/src/assembly/source.xml 2008-05-15 13:15:01 UTC (rev 148) @@ -1,50 +1,21 @@ <assembly> - <id>src</id> - <formats> - <format>zip</format> - <format>tar.gz</format> - </formats> - <includeBaseDirectory>true</includeBaseDirectory> - <dependencySets> - <dependencySet> - <outputDirectory>/lib</outputDirectory> - </dependencySet> - </dependencySets> - <fileSets> - <fileSet> - <directory>src/main/java</directory> - <outputDirectory>/src</outputDirectory> - </fileSet> - <fileSet> - <directory>/</directory> - <outputDirectory>/</outputDirectory> - <includes> - <include>license.txt</include> - </includes> - </fileSet> - <fileSet> - <directory>src/test/java</directory> - <outputDirectory>/test</outputDirectory> - </fileSet> - <fileSet> - <directory>target</directory> - <outputDirectory>/dist</outputDirectory> - <includes> - <include>*.jar</include> - </includes> - </fileSet> - <fileSet> - <directory>target/site/apidocs</directory> - <outputDirectory>/docs/api</outputDirectory> - </fileSet> - </fileSets> - <moduleSets> - <moduleSet> - <binaries> - <includeDependencies>false</includeDependencies> - <unpack>false</unpack> - <outputDirectory>dist</outputDirectory> - </binaries> - </moduleSet> - </moduleSets> + <id>src</id> + <formats> + <format>zip</format> + <format>tar.gz</format> + </formats> + <includeBaseDirectory>true</includeBaseDirectory> + <fileSets> + <fileSet> + <directory>/</directory> + <outputDirectory>/</outputDirectory> + <excludes> + <exclude>**/.svn/*</exclude> + <exclude>.classpath</exclude> + <exclude>.settings/**</exclude> + <exclude>.project</exclude> + <exclude>target/**</exclude> + </excludes> + </fileSet> + </fileSets> </assembly> \ No newline at end of file Added: trunk/src/assembly/sources-jar.xml =================================================================== --- trunk/src/assembly/sources-jar.xml (rev 0) +++ trunk/src/assembly/sources-jar.xml 2008-05-15 13:15:01 UTC (rev 148) @@ -0,0 +1,13 @@ +<assembly> + <id>sources</id> + <formats> + <format>jar</format> + </formats> + <includeBaseDirectory>false</includeBaseDirectory> + <fileSets> + <fileSet> + <directory>src/main/java</directory> + <outputDirectory>/</outputDirectory> + </fileSet> + </fileSets> +</assembly> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-05-15 12:45:18
|
Revision: 147 http://openfast.svn.sourceforge.net/openfast/?rev=147&view=rev Author: jacob_northey Date: 2008-05-15 05:45:25 -0700 (Thu, 15 May 2008) Log Message: ----------- Merged 145:146 object-model-refactor branch to trunk Modified Paths: -------------- trunk/src/main/java/org/openfast/MessageOutputStream.java trunk/src/main/java/org/openfast/codec/FastEncoder.java trunk/src/main/java/org/openfast/session/FastClient.java trunk/src/main/java/org/openfast/session/FastServer.java trunk/src/main/java/org/openfast/session/MessageListener.java trunk/src/main/java/org/openfast/session/Session.java trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_0.java trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java trunk/src/main/java/org/openfast/session/SessionProtocol.java trunk/src/main/java/org/openfast/session/multicast/MulticastInputStream.java trunk/src/main/java/org/openfast/template/BasicTemplateRegistry.java trunk/src/main/java/org/openfast/template/NullTemplateRegistry.java trunk/src/main/java/org/openfast/template/TemplateRegistry.java trunk/src/test/java/org/openfast/DictionaryTest.java trunk/src/test/java/org/openfast/session/SCP_1_1_Test.java trunk/src/test/java/org/openfast/util/UtilTest.java Modified: trunk/src/main/java/org/openfast/MessageOutputStream.java =================================================================== --- trunk/src/main/java/org/openfast/MessageOutputStream.java 2008-05-15 12:25:20 UTC (rev 146) +++ trunk/src/main/java/org/openfast/MessageOutputStream.java 2008-05-15 12:45:25 UTC (rev 147) @@ -17,9 +17,7 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast; import java.io.IOException; @@ -35,7 +33,6 @@ import org.openfast.template.MessageTemplate; import org.openfast.template.TemplateRegistry; - public class MessageOutputStream implements MessageStream { private final OutputStream out; private final FastEncoder encoder; @@ -46,54 +43,43 @@ public MessageOutputStream(OutputStream outputStream) { this(outputStream, new Context()); } - public MessageOutputStream(OutputStream outputStream, Context context) { this.out = outputStream; this.encoder = new FastEncoder(context); this.context = context; } - public void writeMessage(Message message) { - writeMessage(message, false); + writeMessage(message, false); } - public void writeMessage(Message message, boolean flush) { try { if (context.isTraceEnabled()) - context.startTrace(); - - if (!handlers.isEmpty()) { - for (int i=0; i<handlers.size(); i++) { - ((MessageHandler) handlers.get(i)).handleMessage(message, context, encoder); - } - } + context.startTrace(); + if (!handlers.isEmpty()) { + for (int i = 0; i < handlers.size(); i++) { + ((MessageHandler) handlers.get(i)).handleMessage(message, context, encoder); + } + } if (templateHandlers.containsKey(message.getTemplate())) { - ((MessageHandler) templateHandlers.get(message.getTemplate())).handleMessage(message, - context, encoder); + ((MessageHandler) templateHandlers.get(message.getTemplate())).handleMessage(message, context, encoder); } - byte[] data = encoder.encode(message); - if ((data == null) || (data.length == 0)) { return; } - out.write(data); if (flush) - out.flush(); + out.flush(); } catch (IOException e) { - Global.handleError(FastConstants.IO_ERROR, "An IO error occurred while writing message " + message, e); + Global.handleError(FastConstants.IO_ERROR, "An IO error occurred while writing message " + message, e); } } - public void reset() { encoder.reset(); } - public void registerTemplate(int templateId, MessageTemplate template) { encoder.registerTemplate(templateId, template); } - public void close() { try { out.close(); @@ -101,35 +87,28 @@ Global.handleError(FastConstants.IO_ERROR, "An error occurred while closing output stream.", e); } } - public OutputStream getUnderlyingStream() { return out; } - public void addMessageHandler(MessageTemplate template, MessageHandler handler) { if (templateHandlers == Collections.EMPTY_MAP) { templateHandlers = new HashMap(); } - templateHandlers.put(template, handler); } - - public void addMessageHandler(MessageHandler handler) { - if (handlers == Collections.EMPTY_LIST) { - handlers = new ArrayList(4); - } - handlers.add(handler); - } - - public void setTemplateRegistry(TemplateRegistry registry) { - context.setTemplateRegistry(registry); - } - - public TemplateRegistry getTemplateRegistry() { - return context.getTemplateRegistry(); - } - - public Context getContext() { - return context; - } + public void addMessageHandler(MessageHandler handler) { + if (handlers == Collections.EMPTY_LIST) { + handlers = new ArrayList(4); + } + handlers.add(handler); + } + public void setTemplateRegistry(TemplateRegistry registry) { + context.setTemplateRegistry(registry); + } + public TemplateRegistry getTemplateRegistry() { + return context.getTemplateRegistry(); + } + public Context getContext() { + return context; + } } Modified: trunk/src/main/java/org/openfast/codec/FastEncoder.java =================================================================== --- trunk/src/main/java/org/openfast/codec/FastEncoder.java 2008-05-15 12:25:20 UTC (rev 146) +++ trunk/src/main/java/org/openfast/codec/FastEncoder.java 2008-05-15 12:45:25 UTC (rev 147) @@ -17,9 +17,7 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast.codec; import java.util.ArrayList; @@ -31,18 +29,17 @@ import org.openfast.template.MessageTemplate; import org.openfast.template.TemplateRegisteredListener; - /* In 1.5 version use : static import java.lang.Math.*; */ public class FastEncoder implements Coder { private Context context; - private List listeners = Collections.EMPTY_LIST; + private List listeners = Collections.EMPTY_LIST; public FastEncoder(Context context) { this.context = context; } - /** * WARNING: Not thread-safe. + * * @param message * @return the fast encoding of the message */ @@ -51,19 +48,16 @@ context.newMessage(template); return template.encode(message, context); } - public void reset() { context.reset(); } - public void registerTemplate(int templateId, MessageTemplate template) { context.registerTemplate(templateId, template); } - - public void addTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener) { - if (listeners.isEmpty()) { - listeners = new ArrayList(); - } - listeners.add(templateRegisteredListener); - } + public void addTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener) { + if (listeners.isEmpty()) { + listeners = new ArrayList(); + } + listeners.add(templateRegisteredListener); + } } Modified: trunk/src/main/java/org/openfast/session/FastClient.java =================================================================== --- trunk/src/main/java/org/openfast/session/FastClient.java 2008-05-15 12:25:20 UTC (rev 146) +++ trunk/src/main/java/org/openfast/session/FastClient.java 2008-05-15 12:45:25 UTC (rev 147) @@ -1,18 +1,47 @@ package org.openfast.session; +import org.openfast.template.BasicTemplateRegistry; +import org.openfast.template.TemplateRegistry; + public class FastClient { private final String clientName; private final Endpoint endpoint; private final SessionProtocol sessionProtocol; + private TemplateRegistry inboundRegistry = new BasicTemplateRegistry(); + private TemplateRegistry outboundRegistry = new BasicTemplateRegistry(); + private MessageListener messageListener = MessageListener.NULL; + private SessionListener sessionListener = SessionListener.NULL; public FastClient(String clientName, SessionProtocol sessionProtocol, Endpoint endpoint) { this.clientName = clientName; this.sessionProtocol = sessionProtocol; this.endpoint = endpoint; } + + public void setInboundTemplateRegistry(TemplateRegistry registry) { + this.inboundRegistry = registry; + } + + public TemplateRegistry getInboundTemplateRegistry() { + return this.inboundRegistry; + } + + public void setOutboundTemplateRegistry(TemplateRegistry registry) { + this.outboundRegistry = registry; + } + + public TemplateRegistry getOutboundTemplateRegistry() { + return this.outboundRegistry; + } + public Session connect() throws FastConnectionException { Connection connection = endpoint.connect(); - Session session = sessionProtocol.connect(clientName, connection); + Session session = sessionProtocol.connect(clientName, connection, inboundRegistry, outboundRegistry, + messageListener, sessionListener); return session; } + + public void setMessageHandler(MessageListener messageListener) { + this.messageListener = messageListener; + } } Modified: trunk/src/main/java/org/openfast/session/FastServer.java =================================================================== --- trunk/src/main/java/org/openfast/session/FastServer.java 2008-05-15 12:25:20 UTC (rev 146) +++ trunk/src/main/java/org/openfast/session/FastServer.java 2008-05-15 12:45:25 UTC (rev 147) @@ -17,23 +17,19 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast.session; import org.openfast.error.ErrorHandler; - public class FastServer implements ConnectionListener { private ErrorHandler errorHandler = ErrorHandler.DEFAULT; private SessionHandler sessionHandler = SessionHandler.NULL; - private boolean listening; - - private final SessionProtocol sessionProtocol; - private final Endpoint endpoint; - private final String serverName; - private Thread serverThread; + private boolean listening; + private final SessionProtocol sessionProtocol; + private final Endpoint endpoint; + private final String serverName; + private Thread serverThread; public FastServer(String serverName, SessionProtocol sessionProtocol, Endpoint endpoint) { if (endpoint == null || sessionProtocol == null) { @@ -44,50 +40,43 @@ this.serverName = serverName; endpoint.setConnectionListener(this); } - public void listen() { - listening = true; - if (serverThread == null) { - Runnable runnable = new Runnable() { - public void run() { - while (listening) { - try { - endpoint.accept(); - } catch (FastConnectionException e) { - errorHandler.error(null, null, e); - } - try { - Thread.sleep(20); - } catch (InterruptedException e) { - } - } - }}; - serverThread = new Thread(runnable, "FastServer"); - } - serverThread.start(); + listening = true; + if (serverThread == null) { + Runnable runnable = new Runnable() { + public void run() { + while (listening) { + try { + endpoint.accept(); + } catch (Exception e) { + errorHandler.error(null, null, e); + } + try { + Thread.sleep(20); + } catch (InterruptedException e) {} + } + } + }; + serverThread = new Thread(runnable, "FastServer"); + } + serverThread.start(); } - public void close() throws FastConnectionException { - listening = false; - endpoint.close(); + listening = false; + endpoint.close(); } - // ************* OPTIONAL DEPENDENCY SETTERS ************** - public void setErrorHandler(ErrorHandler errorHandler) { if (errorHandler == null) { throw new NullPointerException(); } - this.errorHandler = errorHandler; } - - public void onConnect(Connection connection) { - Session session = sessionProtocol.onNewConnection(serverName, connection); - this.sessionHandler.newSession(session); - } - - public void setSessionHandler(SessionHandler sessionHandler) { - this.sessionHandler = sessionHandler; - } + public void onConnect(Connection connection) { + Session session = sessionProtocol.onNewConnection(serverName, connection); + this.sessionHandler.newSession(session); + } + public void setSessionHandler(SessionHandler sessionHandler) { + this.sessionHandler = sessionHandler; + } } Modified: trunk/src/main/java/org/openfast/session/MessageListener.java =================================================================== --- trunk/src/main/java/org/openfast/session/MessageListener.java 2008-05-15 12:25:20 UTC (rev 146) +++ trunk/src/main/java/org/openfast/session/MessageListener.java 2008-05-15 12:45:25 UTC (rev 147) @@ -3,5 +3,8 @@ import org.openfast.Message; public interface MessageListener { - void onMessage(Message message); + MessageListener NULL = new MessageListener() { + public void onMessage(Session session, Message message) {}}; + + void onMessage(Session session, Message message); } Modified: trunk/src/main/java/org/openfast/session/Session.java =================================================================== --- trunk/src/main/java/org/openfast/session/Session.java 2008-05-15 12:25:20 UTC (rev 146) +++ trunk/src/main/java/org/openfast/session/Session.java 2008-05-15 12:45:25 UTC (rev 147) @@ -47,9 +47,11 @@ private ErrorHandler errorHandler = ErrorHandler.DEFAULT; private SessionListener sessionListener = SessionListener.NULL; - public Session(Connection connection, SessionProtocol protocol) { + public Session(Connection connection, SessionProtocol protocol, TemplateRegistry inboundRegistry, TemplateRegistry outboundRegistry) { Context inContext = new Context(); + inContext.getTemplateRegistry().registerAll(inboundRegistry); Context outContext = new Context(); + outContext.getTemplateRegistry().registerAll(outboundRegistry); inContext.setErrorHandler(this); this.connection = connection; @@ -141,7 +143,7 @@ if (protocol.isProtocolMessage(message)) { protocol.handleMessage(Session.this, message); } else if (messageListener != null) { - messageListener.onMessage(message); + messageListener.onMessage(Session.this, message); } else { throw new IllegalStateException("Received non-protocol message without a message listener."); } Modified: trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_0.java =================================================================== --- trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_0.java 2008-05-15 12:25:20 UTC (rev 146) +++ trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_0.java 2008-05-15 12:45:25 UTC (rev 147) @@ -38,15 +38,18 @@ static final int FAST_ALERT_TEMPLATE_ID = 16001; public Session onNewConnection(String serverName, Connection connection) { - Session session = new Session(connection, this); + Session session = new Session(connection, this, TemplateRegistry.NULL, TemplateRegistry.NULL); Message message = session.in.readMessage(); session.out.writeMessage(createHelloMessage(serverName)); String clientName = message.getString(1); session.setClient(new BasicClient(clientName, "unknown")); return session; } - public Session connect(String senderName, Connection connection) { - Session session = new Session(connection, this); + public Session connect(String senderName, Connection connection, TemplateRegistry inboundRegistry, + TemplateRegistry outboundRegistry, MessageListener messageListener, SessionListener sessionListener) { + Session session = new Session(connection, this, inboundRegistry, outboundRegistry); + session.setMessageHandler(messageListener); + session.setSessionListener(sessionListener); session.out.writeMessage(createHelloMessage(senderName)); Message message = session.in.readMessage(); String serverName = message.getString(1); Modified: trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java =================================================================== --- trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java 2008-05-15 12:25:20 UTC (rev 146) +++ trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java 2008-05-15 12:45:25 UTC (rev 147) @@ -99,8 +99,9 @@ public void registerSessionTemplates(TemplateRegistry registry) { registry.registerAll(TEMPLATE_REGISTRY); } - public Session connect(String senderName, Connection connection) { - Session session = new Session(connection, this); + public Session connect(String senderName, Connection connection, TemplateRegistry inboundRegistry, + TemplateRegistry outboundRegistry, MessageListener messageListener, SessionListener sessionListener) { + Session session = new Session(connection, this, inboundRegistry, outboundRegistry); session.out.writeMessage(createHelloMessage(senderName)); try { Thread.sleep(20); @@ -115,7 +116,7 @@ session.out.writeMessage(createFastAlertMessage(code)); } public Session onNewConnection(String serverName, Connection connection) { - Session session = new Session(connection, this); + Session session = new Session(connection, this, TemplateRegistry.NULL, TemplateRegistry.NULL); Message message = session.in.readMessage(); String clientName = message.getString(1); String vendorId = message.isDefined(2) ? message.getString(2) : "unknown"; @@ -408,4 +409,5 @@ } private static final Message CLOSE = createFastAlertMessage(SessionConstants.CLOSE); + private static final TemplateRegistry PROTOCOL_TEMPLATES = new BasicTemplateRegistry(); } Modified: trunk/src/main/java/org/openfast/session/SessionProtocol.java =================================================================== --- trunk/src/main/java/org/openfast/session/SessionProtocol.java 2008-05-15 12:25:20 UTC (rev 146) +++ trunk/src/main/java/org/openfast/session/SessionProtocol.java 2008-05-15 12:45:25 UTC (rev 147) @@ -3,10 +3,11 @@ import org.openfast.Message; import org.openfast.error.ErrorCode; import org.openfast.template.MessageTemplate; +import org.openfast.template.TemplateRegistry; public interface SessionProtocol { public void configureSession(Session session); - public Session connect(String senderName, Connection connection); + public Session connect(String senderName, Connection connection, TemplateRegistry inboundRegistry, TemplateRegistry outboundRegistry, MessageListener messageListener, SessionListener sessionListener); public Session onNewConnection(String serverName, Connection connection); public void onError(Session session, ErrorCode code, String message); public Message getResetMessage(); Modified: trunk/src/main/java/org/openfast/session/multicast/MulticastInputStream.java =================================================================== --- trunk/src/main/java/org/openfast/session/multicast/MulticastInputStream.java 2008-05-15 12:25:20 UTC (rev 146) +++ trunk/src/main/java/org/openfast/session/multicast/MulticastInputStream.java 2008-05-15 12:45:25 UTC (rev 147) @@ -7,24 +7,29 @@ import java.nio.ByteBuffer; public class MulticastInputStream extends InputStream { - private static final int BUFFER_SIZE = 4 * 1024 * 1024; + private static final int BUFFER_SIZE = 256 * 1024; private MulticastSocket socket; private ByteBuffer buffer; public MulticastInputStream(MulticastSocket socket) { + this(socket, BUFFER_SIZE); + } + + public MulticastInputStream(MulticastSocket socket, int bufferSize) { this.socket = socket; - this.buffer = ByteBuffer.allocate(BUFFER_SIZE); + this.buffer = ByteBuffer.allocate(bufferSize); buffer.flip(); } public int read() throws IOException { if (socket.isClosed()) return -1; if (!buffer.hasRemaining()) { + buffer.clear(); + DatagramPacket packet = new DatagramPacket(buffer.array(), buffer.capacity()); + socket.receive(packet); buffer.flip(); - DatagramPacket packet = new DatagramPacket(buffer.array(), buffer.array().length); - socket.receive(packet); buffer.limit(packet.getLength()); } - return buffer.get(); + return (int)(buffer.get() & 0xFF); } } Modified: trunk/src/main/java/org/openfast/template/BasicTemplateRegistry.java =================================================================== --- trunk/src/main/java/org/openfast/template/BasicTemplateRegistry.java 2008-05-15 12:25:20 UTC (rev 146) +++ trunk/src/main/java/org/openfast/template/BasicTemplateRegistry.java 2008-05-15 12:45:25 UTC (rev 147) @@ -9,106 +9,93 @@ import org.openfast.QName; public class BasicTemplateRegistry extends AbstractTemplateRegistry { - private Map nameMap = new HashMap(); - private Map idMap = new HashMap(); - private Map templateMap = new HashMap(); - private List templates = new ArrayList(); + private Map nameMap = new HashMap(); + private Map idMap = new HashMap(); + private Map templateMap = new HashMap(); + private List templates = new ArrayList(); - public void register(int id, MessageTemplate template) { - define(template); - Integer tid = new Integer(id); - idMap.put(tid, template); - templateMap.put(template, tid); - notifyTemplateRegistered(template, id); - } - - public void register(int id, QName name) { - if (!nameMap.containsKey(name)) - throw new IllegalArgumentException("The template named " + name + " is not defined."); - Integer tid = new Integer(id); - MessageTemplate template = (MessageTemplate) nameMap.get(name); - templateMap.put(template, tid); - idMap.put(tid, template); - notifyTemplateRegistered(template, id); - } - - public void define(MessageTemplate template) { - if (!templates.contains(template)) { - nameMap.put(template.getQName(), template); - templates.add(template); - } - } - - public int getId(QName name) { - Object template = nameMap.get(name); - if (template == null || !templateMap.containsKey(template)) return -1; - return ((Integer)templateMap.get(template)).intValue(); - } - - public MessageTemplate get(int templateId) { - return (MessageTemplate) idMap.get(new Integer(templateId)); - } - - public MessageTemplate get(QName name) { - return (MessageTemplate) nameMap.get(name); - } - - public int getId(MessageTemplate template) { - if (!isRegistered(template)) return -1; - return ((Integer)templateMap.get(template)).intValue(); - } - - public boolean isRegistered(QName name) { - return nameMap.containsKey(name); - } - - public boolean isRegistered(int templateId) { - return idMap.containsKey(new Integer(templateId)); - } - - public boolean isRegistered(MessageTemplate template) { - return templateMap.containsKey(template); - } - - public boolean isDefined(QName name) { - return nameMap.containsKey(name); - } - - public MessageTemplate[] getTemplates() { - return (MessageTemplate[]) templateMap.keySet().toArray(new MessageTemplate[templateMap.size()]); - } - - public void remove(QName name) { - MessageTemplate template = (MessageTemplate) nameMap.remove(name); - Object id = templateMap.remove(template); - idMap.remove(id); - templates.remove(template); - } - - public void remove(MessageTemplate template) { - Object id = templateMap.remove(template); - nameMap.remove(template.getName()); - idMap.remove(id); - } - - public void remove(int id) { - MessageTemplate template = (MessageTemplate) idMap.remove(new Integer(id)); - templateMap.remove(template); - nameMap.remove(template.getName()); - } - - public void registerAll(TemplateRegistry registry) { - MessageTemplate[] templates = registry.getTemplates(); - for (int i=0; i<templates.length; i++) { - register(registry.getId(templates[i]), templates[i]); - } - } - - public Iterator nameIterator() { - return nameMap.keySet().iterator(); - } - - public Iterator iterator() { - return templates.iterator(); - } + public void register(int id, MessageTemplate template) { + define(template); + Integer tid = new Integer(id); + idMap.put(tid, template); + templateMap.put(template, tid); + notifyTemplateRegistered(template, id); + } + public void register(int id, QName name) { + if (!nameMap.containsKey(name)) + throw new IllegalArgumentException("The template named " + name + " is not defined."); + Integer tid = new Integer(id); + MessageTemplate template = (MessageTemplate) nameMap.get(name); + templateMap.put(template, tid); + idMap.put(tid, template); + notifyTemplateRegistered(template, id); + } + public void define(MessageTemplate template) { + if (!templates.contains(template)) { + nameMap.put(template.getQName(), template); + templates.add(template); + } + } + public int getId(QName name) { + Object template = nameMap.get(name); + if (template == null || !templateMap.containsKey(template)) + return -1; + return ((Integer) templateMap.get(template)).intValue(); + } + public MessageTemplate get(int templateId) { + return (MessageTemplate) idMap.get(new Integer(templateId)); + } + public MessageTemplate get(QName name) { + return (MessageTemplate) nameMap.get(name); + } + public int getId(MessageTemplate template) { + if (!isRegistered(template)) + return -1; + return ((Integer) templateMap.get(template)).intValue(); + } + public boolean isRegistered(QName name) { + return nameMap.containsKey(name); + } + public boolean isRegistered(int templateId) { + return idMap.containsKey(new Integer(templateId)); + } + public boolean isRegistered(MessageTemplate template) { + return templateMap.containsKey(template); + } + public boolean isDefined(QName name) { + return nameMap.containsKey(name); + } + public MessageTemplate[] getTemplates() { + return (MessageTemplate[]) templateMap.keySet().toArray(new MessageTemplate[templateMap.size()]); + } + public void remove(QName name) { + MessageTemplate template = (MessageTemplate) nameMap.remove(name); + Object id = templateMap.remove(template); + idMap.remove(id); + templates.remove(template); + } + public void remove(MessageTemplate template) { + Object id = templateMap.remove(template); + nameMap.remove(template.getName()); + idMap.remove(id); + } + public void remove(int id) { + MessageTemplate template = (MessageTemplate) idMap.remove(new Integer(id)); + templateMap.remove(template); + nameMap.remove(template.getName()); + } + public void registerAll(TemplateRegistry registry) { + if (registry == null) return; + MessageTemplate[] templates = registry.getTemplates(); + if (templates == null) return; + for (int i = 0; i < templates.length; i++) { + register(registry.getId(templates[i]), templates[i]); + } + } + public Iterator nameIterator() { + return nameMap.keySet().iterator(); + } + public Iterator iterator() { + return templates.iterator(); + } } Modified: trunk/src/main/java/org/openfast/template/NullTemplateRegistry.java =================================================================== --- trunk/src/main/java/org/openfast/template/NullTemplateRegistry.java 2008-05-15 12:25:20 UTC (rev 146) +++ trunk/src/main/java/org/openfast/template/NullTemplateRegistry.java 2008-05-15 12:45:25 UTC (rev 147) @@ -9,139 +9,91 @@ import org.openfast.QName; final class NullTemplateRegistry implements TemplateRegistry { - public void addTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener) { - } - - public MessageTemplate get(int templateId) { - return null; - } - - public MessageTemplate get(String templateName) { - return null; - } - - public int getTemplateId(String templateName) { - return 0; - } - - public int getTemplateId(MessageTemplate template) { - return 0; - } - - public MessageTemplate[] getTemplates() { - return null; - } - - public boolean isRegistered(String templateName) { - return false; - } - - public boolean isRegistered(int templateId) { - return false; - } - - public boolean isRegistered(MessageTemplate template) { - return false; - } - - public void register(int templateId, MessageTemplate template) { - } - - public void remove(String name) { - } - - public void remove(MessageTemplate template) { - } - - public void remove(int id) { - } - - public void add(MessageTemplate template) { - } - - public void define(MessageTemplate template) { - } - - public MessageTemplate getTemplate(String name) { - return null; - } - - public MessageTemplate getTemplate(QName name) { - return null; - } - - public MessageTemplate getTemplate(int id) { - return null; - } - - public boolean hasTemplate(String name) { - return false; - } - - public boolean hasTemplate(QName name) { - return false; - } - - public boolean hasTemplate(int id) { - return false; - } - - public boolean isDefined(MessageTemplate template) { - return false; - } - - public MessageTemplate[] toArray() { - return null; - } - - public MessageTemplate get(QName name) { - return null; - } - - public int getId(String name) { - return 0; - } - - public int getId(MessageTemplate template) { - return 0; - } - - public boolean isDefined(QName name) { - return false; - } - - public boolean isDefined(String name) { - return false; - } - - public void register(int templateId, QName name) { - } - - public void register(int templateId, String name) { - } - - public void removeTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener) { - } - - public int getId(QName name) { - return 0; - } - - public boolean isRegistered(QName name) { - return false; - } - - public void remove(QName name) { - } - - public void registerAll(TemplateRegistry registry) { - } - - public Iterator nameIterator() { - return Collections.EMPTY_LIST.iterator(); - } - - public Iterator iterator() { - return null; - } + public void addTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener) {} + public MessageTemplate get(int templateId) { + return null; + } + public MessageTemplate get(String templateName) { + return null; + } + public int getTemplateId(String templateName) { + return 0; + } + public int getTemplateId(MessageTemplate template) { + return 0; + } + public MessageTemplate[] getTemplates() { + return new MessageTemplate[] {}; + } + public boolean isRegistered(String templateName) { + return false; + } + public boolean isRegistered(int templateId) { + return false; + } + public boolean isRegistered(MessageTemplate template) { + return false; + } + public void register(int templateId, MessageTemplate template) {} + public void remove(String name) {} + public void remove(MessageTemplate template) {} + public void remove(int id) {} + public void add(MessageTemplate template) {} + public void define(MessageTemplate template) {} + public MessageTemplate getTemplate(String name) { + return null; + } + public MessageTemplate getTemplate(QName name) { + return null; + } + public MessageTemplate getTemplate(int id) { + return null; + } + public boolean hasTemplate(String name) { + return false; + } + public boolean hasTemplate(QName name) { + return false; + } + public boolean hasTemplate(int id) { + return false; + } + public boolean isDefined(MessageTemplate template) { + return false; + } + public MessageTemplate[] toArray() { + return null; + } + public MessageTemplate get(QName name) { + return null; + } + public int getId(String name) { + return 0; + } + public int getId(MessageTemplate template) { + return 0; + } + public boolean isDefined(QName name) { + return false; + } + public boolean isDefined(String name) { + return false; + } + public void register(int templateId, QName name) {} + public void register(int templateId, String name) {} + public void removeTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener) {} + public int getId(QName name) { + return 0; + } + public boolean isRegistered(QName name) { + return false; + } + public void remove(QName name) {} + public void registerAll(TemplateRegistry registry) {} + public Iterator nameIterator() { + return Collections.EMPTY_LIST.iterator(); + } + public Iterator iterator() { + return null; + } } \ No newline at end of file Modified: trunk/src/main/java/org/openfast/template/TemplateRegistry.java =================================================================== --- trunk/src/main/java/org/openfast/template/TemplateRegistry.java 2008-05-15 12:25:20 UTC (rev 146) +++ trunk/src/main/java/org/openfast/template/TemplateRegistry.java 2008-05-15 12:45:25 UTC (rev 147) @@ -17,63 +17,53 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast.template; import java.util.Iterator; import org.openfast.QName; - - public interface TemplateRegistry extends Iterable { - TemplateRegistry NULL = new NullTemplateRegistry(); - - void registerAll(TemplateRegistry registry); - void register(int id, MessageTemplate template); - void register(int id, String name); - void register(int id, QName name); - - void define(MessageTemplate template); - - void remove(String name); - void remove(QName name); - void remove(MessageTemplate template); - void remove(int id); - - MessageTemplate get(int id); - MessageTemplate get(String name); - MessageTemplate get(QName name); - - MessageTemplate[] getTemplates(); - - int getId(String name); - int getId(QName name); - int getId(MessageTemplate template); - - boolean isRegistered(String name); - boolean isRegistered(QName name); - boolean isRegistered(int id); - boolean isRegistered(MessageTemplate template); - boolean isDefined(String name); - boolean isDefined(QName name); - - void addTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener); - void removeTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener); - - /** - * Iterator over the names of each template (defined or registered) in this registry - * - * @return an iterator over the qualified names each item is of type QName - */ - Iterator/*<QName>*/ nameIterator(); - - /** - * Iterator over the set of templates (defined or registered) in this registry - * - * @return an iterator over the set of templates each item is an instance of MessageTemplate - */ - Iterator/*<MessageTemplate>*/ iterator(); + TemplateRegistry NULL = new NullTemplateRegistry(); + + void registerAll(TemplateRegistry registry); + void register(int id, MessageTemplate template); + void register(int id, String name); + void register(int id, QName name); + void define(MessageTemplate template); + void remove(String name); + void remove(QName name); + void remove(MessageTemplate template); + void remove(int id); + MessageTemplate get(int id); + MessageTemplate get(String name); + MessageTemplate get(QName name); + MessageTemplate[] getTemplates(); + int getId(String name); + int getId(QName name); + int getId(MessageTemplate template); + boolean isRegistered(String name); + boolean isRegistered(QName name); + boolean isRegistered(int id); + boolean isRegistered(MessageTemplate template); + boolean isDefined(String name); + boolean isDefined(QName name); + void addTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener); + void removeTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener); + /** + * Iterator over the names of each template (defined or registered) in this + * registry + * + * @return an iterator over the qualified names each item is of type QName + */ + Iterator/* <QName> */nameIterator(); + /** + * Iterator over the set of templates (defined or registered) in this + * registry + * + * @return an iterator over the set of templates each item is an instance of + * MessageTemplate + */ + Iterator/* <MessageTemplate> */iterator(); } Modified: trunk/src/test/java/org/openfast/DictionaryTest.java =================================================================== --- trunk/src/test/java/org/openfast/DictionaryTest.java 2008-05-15 12:25:20 UTC (rev 146) +++ trunk/src/test/java/org/openfast/DictionaryTest.java 2008-05-15 12:45:25 UTC (rev 147) @@ -17,9 +17,7 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast; import java.io.ByteArrayOutputStream; @@ -35,11 +33,11 @@ import org.openfast.template.Field; import org.openfast.template.MessageTemplate; import org.openfast.template.Scalar; +import org.openfast.template.TemplateRegistry; import org.openfast.template.operator.Operator; import org.openfast.template.type.Type; import org.openfast.test.TestUtil; - public class DictionaryTest extends TestCase { private Session session; private ByteArrayOutputStream out; @@ -47,57 +45,41 @@ protected void setUp() throws Exception { out = new ByteArrayOutputStream(); session = new Session(new Connection() { - public InputStream getInputStream() throws IOException { - return null; - } - - public OutputStream getOutputStream() throws IOException { - return out; - } - - public void close() { - try { - out.close(); - } catch (IOException e) { - } - } - - }, SessionConstants.SCP_1_0); + public InputStream getInputStream() throws IOException { + return null; + } + public OutputStream getOutputStream() throws IOException { + return out; + } + public void close() { + try { + out.close(); + } catch (IOException e) {} + } + }, SessionConstants.SCP_1_0, TemplateRegistry.NULL, TemplateRegistry.NULL); } - public void testMultipleDictionaryTypes() throws Exception { Scalar bid = new Scalar("bid", Type.DECIMAL, Operator.COPY, ScalarValue.UNDEFINED, false); bid.setDictionary(Dictionary.TEMPLATE); - MessageTemplate quote = new MessageTemplate("quote", new Field[] { bid }); - Scalar bidR = new Scalar("bid", Type.DECIMAL, Operator.COPY, ScalarValue.UNDEFINED, false); - MessageTemplate request = new MessageTemplate("request", - new Field[] { bidR }); - + MessageTemplate request = new MessageTemplate("request", new Field[] { bidR }); Message quote1 = new Message(quote); quote1.setFieldValue(1, new DecimalValue(10.2)); - Message request1 = new Message(request); request1.setFieldValue(1, new DecimalValue(10.3)); - Message quote2 = new Message(quote); quote2.setFieldValue(1, new DecimalValue(10.2)); - Message request2 = new Message(request); request2.setFieldValue(1, new DecimalValue(10.2)); - session.out.registerTemplate(1, request); session.out.registerTemplate(2, quote); session.out.writeMessage(quote1); session.out.writeMessage(request1); session.out.writeMessage(quote2); session.out.writeMessage(request2); - - String expected = "11100000 10000010 11111111 00000000 11100110 " + - "11100000 10000001 11111111 00000000 11100111 " + - "11000000 10000010 " + - "11100000 10000001 11111111 00000000 11100110"; + String expected = "11100000 10000010 11111111 00000000 11100110 " + "11100000 10000001 11111111 00000000 11100111 " + + "11000000 10000010 " + "11100000 10000001 11111111 00000000 11100110"; TestUtil.assertBitVectorEquals(expected, out.toByteArray()); } } Modified: trunk/src/test/java/org/openfast/session/SCP_1_1_Test.java =================================================================== --- trunk/src/test/java/org/openfast/session/SCP_1_1_Test.java 2008-05-15 12:25:20 UTC (rev 146) +++ trunk/src/test/java/org/openfast/session/SCP_1_1_Test.java 2008-05-15 12:45:25 UTC (rev 147) @@ -13,212 +13,188 @@ import org.openfast.util.RecordingOutputStream; public class SCP_1_1_Test extends TestCase { - private static final int MAX_TIMEOUT = 15000; - private LocalEndpoint serverEndpoint; - private RecordingEndpoint clientEndpoint; - private FastServer server; - private FastClient client; - int successfullThreadsCount = 0; + private static final int MAX_TIMEOUT = 15000; + private LocalEndpoint serverEndpoint; + private RecordingEndpoint clientEndpoint; + private FastServer server; + private FastClient client; + int successfullThreadsCount = 0; - protected void setUp() throws Exception { - serverEndpoint = new LocalEndpoint(); - server = new FastServer("server", SessionConstants.SCP_1_1, serverEndpoint); - clientEndpoint = new RecordingEndpoint(new LocalEndpoint(serverEndpoint)); - client = new FastClient("client", SessionConstants.SCP_1_1, clientEndpoint); - } - - protected void tearDown() throws Exception { - server.close(); - } - - public void testSessionEstablishment() throws Exception { - server.setSessionHandler(new SessionHandler() { - public void newSession(Session session) { - assertEquals("client", session.getClient().getName()); - assertEquals(SessionConstants.VENDOR_ID, session.getClient().getVendorId()); - successfullThreadsCount++; - notify0(); - }}); - server.listen(); - - Session session = client.connect(); - - assertEquals("server", session.getClient().getName()); - assertEquals(SessionConstants.VENDOR_ID, session.getClient().getVendorId()); - if (successfullThreadsCount < 1) - wait0(1000); - assertEquals(1, successfullThreadsCount); - } - - public void testSessionReset() throws Exception { - server.setSessionHandler(new SessionHandler() { - public void newSession(Session session) { - session.in.registerTemplate(1, ObjectMother.quoteTemplate()); - - wait0(MAX_TIMEOUT); - Message quote = session.in.readMessage(); - assertEquals(1.0, quote.getDouble(1), .001); - assertEquals(2.0, quote.getDouble(2), .001); - quote = session.in.readMessage(); - assertEquals(1.0, quote.getDouble(1), .001); - assertEquals(2.0, quote.getDouble(2), .001); - quote = session.in.readMessage(); - assertEquals(1.0, quote.getDouble(1), .001); - assertEquals(2.0, quote.getDouble(2), .001); - quote = session.in.readMessage(); - assertEquals(1.0, quote.getDouble(1), .001); - assertEquals(2.0, quote.getDouble(2), .001); - successfullThreadsCount++; - notify0(); - }}); - server.listen(); - Session session = client.connect(); - session.out.registerTemplate(1, ObjectMother.quoteTemplate()); - RecordingOutputStream recordOut = (RecordingOutputStream) session.getConnection().getOutputStream(); - - Message quote = ObjectMother.quote(1.0, 2.0); - - session.out.writeMessage(quote); - recordOut.clear(); - - session.out.writeMessage(quote); - String firstDupe = recordOut.toString(); - recordOut.clear(); - - session.out.writeMessage(quote); - String secondDupe = recordOut.toString(); - - assertEquals(firstDupe, secondDupe); - - session.reset(); - recordOut.clear(); - - session.out.writeMessage(quote); - String lastDupe = recordOut.toString(); - - notify0(); - wait0(MAX_TIMEOUT); - assertFalse(firstDupe.equals(lastDupe)); - assertEquals(1, successfullThreadsCount); - } - - public void testAlert() throws FastConnectionException, IOException { - server.setSessionHandler(new SessionHandler() { - public void newSession(Session session) { - wait0(MAX_TIMEOUT); - session.setListening(true); - session.setErrorHandler(ErrorHandler.NULL); - notify0(); - if (successfullThreadsCount < 0) - wait0(MAX_TIMEOUT); - }}); - server.listen(); - - Session session = client.connect(); - session.setErrorHandler(new ErrorHandler() { - public void error(ErrorCode code, String message) { - assertEquals(SessionConstants.TEMPLATE_NOT_SUPPORTED, code); - successfullThreadsCount++; - notifyAll0(); - } - - public void error(ErrorCode code, String message, Throwable t) { - }}); - session.out.registerTemplate(1, ObjectMother.quoteTemplate()); - - session.out.writeMessage(ObjectMother.quote(1.0, 2.0)); - notify0(); - wait0(MAX_TIMEOUT); - session.setListening(true); - - if (successfullThreadsCount < 1) - wait0(MAX_TIMEOUT); - assertEquals(1, successfullThreadsCount); - } - - public void testTemplateExchange() throws Exception { - server.setSessionHandler(new SessionHandler() { - public void newSession(Session session) { - session.setListening(true); - TemplateRegistry registry = new BasicTemplateRegistry(); - registry.register(24, ObjectMother.quoteTemplate()); - - // Exchange quote template and send a quote with the newly exchanged template. - session.sendTemplates(registry); - session.out.writeMessage(ObjectMother.quote(101.3, 102.4)); - wait0(MAX_TIMEOUT); - try { - session.close(); - } catch (FastConnectionException e) { - } - }}); - server.listen(); - - Session session = client.connect(); - session.setMessageHandler(new MessageListener() { - public void onMessage(Message message) { - if (message.getTemplate().equals(ObjectMother.quoteTemplate())) { - assertEquals(101.3, message.getDouble(1), .1); - assertEquals(102.4, message.getDouble(2), .1); - successfullThreadsCount++; - notifyAll0(); - } - }}); - session.out.registerTemplate(1, ObjectMother.quoteTemplate()); - - if (successfullThreadsCount < 1) - wait0(MAX_TIMEOUT); - assertEquals(1, successfullThreadsCount); - } - - public void testReceiveTemplateDefinitionWithTemplateId() throws Exception { - server.setSessionHandler(new SessionHandler() { - public void newSession(Session session) { - session.setListening(true); - Message templateDef = SessionConstants.SCP_1_1.createTemplateDefinitionMessage(ObjectMother.quoteTemplate()); - templateDef.setInteger("TemplateId", 24); - session.out.registerTemplate(24, ObjectMother.quoteTemplate()); - session.out.writeMessage(templateDef); - session.out.writeMessage(ObjectMother.quote(101.3, 102.4)); - wait0(MAX_TIMEOUT); - try { - session.close(); - } catch (FastConnectionException e) { - } - }}); - server.listen(); - - Session session = client.connect(); - session.setMessageHandler(new MessageListener() { - public void onMessage(Message message) { - if (message.getTemplate().equals(ObjectMother.quoteTemplate())) { - assertEquals(101.3, message.getDouble(1), .1); - assertEquals(102.4, message.getDouble(2), .1); - successfullThreadsCount++; - synchronized(SCP_1_1_Test.this) { - notifyAll0(); - } - } - }}); - session.out.registerTemplate(1, ObjectMother.quoteTemplate()); - - if (successfullThreadsCount < 1) - wait0(MAX_TIMEOUT); - assertEquals(1, successfullThreadsCount); - } - - private synchronized void wait0(int timeout) { - try { - this.wait(timeout); - } catch (InterruptedException e) { - } - } - - private synchronized void notify0() { - this.notify(); - } - - private synchronized void notifyAll0() { - this.notifyAll(); - } + protected void setUp() throws Exception { + serverEndpoint = new LocalEndpoint(); + server = new FastServer("server", SessionConstants.SCP_1_1, serverEndpoint); + clientEndpoint = new RecordingEndpoint(new LocalEndpoint(serverEndpoint)); + client = new FastClient("client", SessionConstants.SCP_1_1, clientEndpoint); + } + protected void tearDown() throws Exception { + server.close(); + } + public void testSessionEstablishment() throws Exception { + server.setSessionHandler(new SessionHandler() { + public void newSession(Session session) { + assertEquals("client", session.getClient().getName()); + assertEquals(SessionConstants.VENDOR_ID, session.getClient().getVendorId()); + successfullThreadsCount++; + notify0(); + } + }); + server.listen(); + Session session = client.connect(); + assertEquals("server", session.getClient().getName()); + assertEquals(SessionConstants.VENDOR_ID, session.getClient().getVendorId()); + if (successfullThreadsCount < 1) + wait0(1000); + assertEquals(1, successfullThreadsCount); + } + public void testSessionReset() throws Exception { + server.setSessionHandler(new SessionHandler() { + public void newSession(Session session) { + session.in.registerTemplate(1, ObjectMother.quoteTemplate()); + wait0(MAX_TIMEOUT); + Message quote = session.in.readMessage(); + assertEquals(1.0, quote.getDouble(1), .001); + assertEquals(2.0, quote.getDouble(2), .001); + quote = session.in.readMessage(); + assertEquals(1.0, quote.getDouble(1), .001); + assertEquals(2.0, quote.getDouble(2), .001); + quote = session.in.readMessage(); + assertEquals(1.0, quote.getDouble(1), .001); + assertEquals(2.0, quote.getDouble(2), .001); + quote = session.in.readMessage(); + assertEquals(1.0, quote.getDouble(1), .001); + assertEquals(2.0, quote.getDouble(2), .001); + successfullThreadsCount++; + notify0(); + } + }); + server.listen(); + Session session = client.connect(); + session.out.registerTemplate(1, ObjectMother.quoteTemplate()); + RecordingOutputStream recordOut = (RecordingOutputStream) session.getConnection().getOutputStream(); + Message quote = ObjectMother.quote(1.0, 2.0); + session.out.writeMessage(quote); + recordOut.clear(); + session.out.writeMessage(quote); + String firstDupe = recordOut.toString(); + recordOut.clear(); + session.out.writeMessage(quote); + String secondDupe = recordOut.toString(); + assertEquals(firstDupe, secondDupe); + session.reset(); + recordOut.clear(); + session.out.writeMessage(quote); + String lastDupe = recordOut.toString(); + notify0(); + wait0(MAX_TIMEOUT); + assertFalse(firstDupe.equals(lastDupe)); + assertEquals(1, successfullThreadsCount); + } + public void testAlert() throws FastConnectionException, IOException { + server.setSessionHandler(new SessionHandler() { + public void newSession(Session session) { + wait0(MAX_TIMEOUT); + session.setListening(true); + session.setErrorHandler(ErrorHandler.NULL); + notify0(); + if (successfullThreadsCount < 0) + wait0(MAX_TIMEOUT); + } + }); + server.listen(); + Session session = client.connect(); + session.setErrorHandler(new ErrorHandler() { + public void error(ErrorCode code, String message) { + assertEquals(SessionConstants.TEMPLATE_NOT_SUPPORTED, code); + successfullThreadsCount++; + notifyAll0(); + } + public void error(ErrorCode code, String message, Throwable t) {} + }); + session.out.registerTemplate(1, ObjectMother.quoteTemplate()); + session.out.writeMessage(ObjectMother.quote(1.0, 2.0)); + notify0(); + wait0(MAX_TIMEOUT); + session.setListening(true); + if (successfullThreadsCount < 1) + wait0(MAX_TIMEOUT); + assertEquals(1, successfullThreadsCount); + } + public void testTemplateExchange() throws Exception { + server.setSessionHandler(new SessionHandler() { + public void newSession(Session session) { + session.setListening(true); + TemplateRegistry registry = new BasicTemplateRegistry(); + registry.register(24, ObjectMother.quoteTemplate()); + // Exchange quote template and send a quote with the newly + // exchanged template. + session.sendTemplates(registry); + session.out.writeMessage(ObjectMother.quote(101.3, 102.4)); + wait0(MAX_TIMEOUT); + try { + session.close(); + } catch (FastConnectionException e) {} + } + }); + server.listen(); + Session session = client.connect(); + session.setMessageHandler(new MessageListener() { + public void onMessage(Session session, Message message) { + if (message.getTemplate().equals(ObjectMother.quoteTemplate())) { + assertEquals(101.3, message.getDouble(1), .1); + assertEquals(102.4, message.getDouble(2), .1); + successfullThreadsCount++; + notifyAll0(); + } + } + }); + session.out.registerTemplate(1, ObjectMother.quoteTemplate()); + if (successfullThreadsCount < 1) + wait0(MAX_TIMEOUT); + assertEquals(1, successfullThreadsCount); + } + public void testReceiveTemplateDefinitionWithTemplateId() throws Exception { + server.setSessionHandler(new SessionHandler() { + public void newSession(Session session) { + session.setListening(true); + Message templateDef = SessionConstants.SCP_1_1.createTemplateDefinitionMessage(ObjectMother.quoteTemplate()); + templateDef.setInteger("TemplateId", 24); + session.out.registerTemplate(24, ObjectMother.quoteTemplate()); + session.out.writeMessage(templateDef); + session.out.writeMessage(ObjectMother.quote(101.3, 102.4)); + wait0(MAX_TIMEOUT); + try { + session.close(); + } catch (FastConnectionException e) {} + } + }); + server.listen(); + Session session = client.connect(); + session.setMessageHandler(new MessageListener() { + public void onMessage(Session session, Message message) { + if (message.getTemplate().equals(ObjectMother.quoteTemplate())) { + assertEquals(101.3, message.getDouble(1), .1); + assertEquals(102.4, message.getDouble(2), .1); + successfullThreadsCount++; + synchronized (SCP_1_1_Test.this) { + notifyAll0(); + } + } + } + }); + session.out.registerTemplate(1, ObjectMother.quoteTemplate()); + if (successfullThreadsCount < 1) + wait0(MAX_TIMEOUT); + assertEquals(1, successfullThreadsCount); + } + private synchronized void wait0(int timeout) { + try { + this.wait(timeout); + } catch (InterruptedException e) {} + } + private synchronized void notify0() { + this.notify(); + } + private synchronized void notifyAll0() { + this.notifyAll(); + } } Modified: trunk/src/test/java/org/openfast/util/UtilTest.java =================================================================== --- trunk/src/test/java/org/openfast/util/UtilTest.java 2008-05-15 12:25:20 UTC (rev 146) +++ trunk/src/test/java/org/openfast/util/UtilTest.java 2008-05-15 12:45:25 UTC (rev 147) @@ -17,72 +17,88 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast.util; +import java.nio.ByteBuffer; import java.util.Calendar; import java.util.LinkedHashMap; import java.util.Map; import junit.framework.TestCase; +import org.openfast.ByteUtil; import org.openfast.IntegerValue; import org.openfast.ScalarValue; import org.openfast.StringValue; import org.openfast.template.TwinValue; +public class UtilTest extends TestCase { + public void testCollectionToString() { + Map map = new LinkedHashMap(); + map.put("abc", "123"); + map.put("def", "456"); + assertEquals("{abc,def}", Util.collectionToString(map.keySet())); + } + + public void testByteVector() { + byte[] bytes = ByteUtil.convertBitStringToFastByteArray("11000000 10000001 10000000"); + ByteBuffer buffer = ByteBuffer.allocate(4096); + buffer.flip(); + putBytes(bytes, buffer); + assertEquals(192, (int) (buffer.get() & 0xFF)); + assertEquals(129, (int) (buffer.get() & 0xFF)); + assertEquals(128, (int) (buffer.get() & 0xFF)); + assertFalse(buffer.hasRemaining()); + bytes = ByteUtil.convertBitStringToFastByteArray("10000001 10000001 10000001"); + putBytes(bytes, buffer); + assertEquals(bytes[0], buffer.get()); + assertEquals(bytes[1], buffer.get()); + assertEquals(bytes[2], buffer.get()); + assertFalse(buffer.hasRemaining()); + + } -public class UtilTest extends TestCase { - public void testCollectionToString() { - Map map = new LinkedHashMap(); - map.put("abc", "123"); - map.put("def", "456"); - assertEquals("{abc,def}", Util.collectionToString(map.keySet())); - } - + private void putBytes(byte[] bytes, ByteBuffer buffer) { + if (!buffer.hasRemaining()) { + buffer.clear(); + buffer.put(bytes); + buffer.flip(); + } + } public void testGetDifference() { assertEquals(tv(0, "d"), diff("abc", "abcd")); assertEquals(tv(1, "ed"), diff("abc", "abed")); - assertEquals(tv(0, "GEH6"), diff("", "GEH6")); assertEquals(tv(2, "M6"), diff("GEH6", "GEM6")); assertEquals(tv(-3, "ES"), diff("GEM6", "ESM6")); assertEquals(tv(-1, "RS"), diff("ESM6", "RSESM6")); assertEquals(tv(0, ""), diff("RSESM6", "RSESM6")); } - public void testApplyDifference() { assertEquals(s("abcd"), apply("abc", tv(0, "d"))); assertEquals(s("abed"), ... [truncated message content] |
From: <ope...@li...> - 2008-05-15 12:25:12
|
Revision: 146 http://openfast.svn.sourceforge.net/openfast/?rev=146&view=rev Author: jacob_northey Date: 2008-05-15 05:25:20 -0700 (Thu, 15 May 2008) Log Message: ----------- Refactored Session classes to prevent race conditions Modified Paths: -------------- branches/object-model-refactor/src/main/java/org/openfast/MessageOutputStream.java branches/object-model-refactor/src/main/java/org/openfast/codec/FastEncoder.java branches/object-model-refactor/src/main/java/org/openfast/session/FastClient.java branches/object-model-refactor/src/main/java/org/openfast/session/FastServer.java branches/object-model-refactor/src/main/java/org/openfast/session/MessageListener.java branches/object-model-refactor/src/main/java/org/openfast/session/Session.java branches/object-model-refactor/src/main/java/org/openfast/session/SessionControlProtocol_1_0.java branches/object-model-refactor/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java branches/object-model-refactor/src/main/java/org/openfast/session/SessionProtocol.java branches/object-model-refactor/src/main/java/org/openfast/session/multicast/MulticastInputStream.java branches/object-model-refactor/src/main/java/org/openfast/template/BasicTemplateRegistry.java branches/object-model-refactor/src/main/java/org/openfast/template/NullTemplateRegistry.java branches/object-model-refactor/src/main/java/org/openfast/template/TemplateRegistry.java branches/object-model-refactor/src/test/java/org/openfast/DictionaryTest.java branches/object-model-refactor/src/test/java/org/openfast/session/SCP_1_1_Test.java branches/object-model-refactor/src/test/java/org/openfast/util/UtilTest.java Modified: branches/object-model-refactor/src/main/java/org/openfast/MessageOutputStream.java =================================================================== --- branches/object-model-refactor/src/main/java/org/openfast/MessageOutputStream.java 2008-05-08 17:25:07 UTC (rev 145) +++ branches/object-model-refactor/src/main/java/org/openfast/MessageOutputStream.java 2008-05-15 12:25:20 UTC (rev 146) @@ -17,9 +17,7 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast; import java.io.IOException; @@ -35,7 +33,6 @@ import org.openfast.template.MessageTemplate; import org.openfast.template.TemplateRegistry; - public class MessageOutputStream implements MessageStream { private final OutputStream out; private final FastEncoder encoder; @@ -46,54 +43,43 @@ public MessageOutputStream(OutputStream outputStream) { this(outputStream, new Context()); } - public MessageOutputStream(OutputStream outputStream, Context context) { this.out = outputStream; this.encoder = new FastEncoder(context); this.context = context; } - public void writeMessage(Message message) { - writeMessage(message, false); + writeMessage(message, false); } - public void writeMessage(Message message, boolean flush) { try { if (context.isTraceEnabled()) - context.startTrace(); - - if (!handlers.isEmpty()) { - for (int i=0; i<handlers.size(); i++) { - ((MessageHandler) handlers.get(i)).handleMessage(message, context, encoder); - } - } + context.startTrace(); + if (!handlers.isEmpty()) { + for (int i = 0; i < handlers.size(); i++) { + ((MessageHandler) handlers.get(i)).handleMessage(message, context, encoder); + } + } if (templateHandlers.containsKey(message.getTemplate())) { - ((MessageHandler) templateHandlers.get(message.getTemplate())).handleMessage(message, - context, encoder); + ((MessageHandler) templateHandlers.get(message.getTemplate())).handleMessage(message, context, encoder); } - byte[] data = encoder.encode(message); - if ((data == null) || (data.length == 0)) { return; } - out.write(data); if (flush) - out.flush(); + out.flush(); } catch (IOException e) { - Global.handleError(FastConstants.IO_ERROR, "An IO error occurred while writing message " + message, e); + Global.handleError(FastConstants.IO_ERROR, "An IO error occurred while writing message " + message, e); } } - public void reset() { encoder.reset(); } - public void registerTemplate(int templateId, MessageTemplate template) { encoder.registerTemplate(templateId, template); } - public void close() { try { out.close(); @@ -101,35 +87,28 @@ Global.handleError(FastConstants.IO_ERROR, "An error occurred while closing output stream.", e); } } - public OutputStream getUnderlyingStream() { return out; } - public void addMessageHandler(MessageTemplate template, MessageHandler handler) { if (templateHandlers == Collections.EMPTY_MAP) { templateHandlers = new HashMap(); } - templateHandlers.put(template, handler); } - - public void addMessageHandler(MessageHandler handler) { - if (handlers == Collections.EMPTY_LIST) { - handlers = new ArrayList(4); - } - handlers.add(handler); - } - - public void setTemplateRegistry(TemplateRegistry registry) { - context.setTemplateRegistry(registry); - } - - public TemplateRegistry getTemplateRegistry() { - return context.getTemplateRegistry(); - } - - public Context getContext() { - return context; - } + public void addMessageHandler(MessageHandler handler) { + if (handlers == Collections.EMPTY_LIST) { + handlers = new ArrayList(4); + } + handlers.add(handler); + } + public void setTemplateRegistry(TemplateRegistry registry) { + context.setTemplateRegistry(registry); + } + public TemplateRegistry getTemplateRegistry() { + return context.getTemplateRegistry(); + } + public Context getContext() { + return context; + } } Modified: branches/object-model-refactor/src/main/java/org/openfast/codec/FastEncoder.java =================================================================== --- branches/object-model-refactor/src/main/java/org/openfast/codec/FastEncoder.java 2008-05-08 17:25:07 UTC (rev 145) +++ branches/object-model-refactor/src/main/java/org/openfast/codec/FastEncoder.java 2008-05-15 12:25:20 UTC (rev 146) @@ -17,9 +17,7 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast.codec; import java.util.ArrayList; @@ -31,18 +29,17 @@ import org.openfast.template.MessageTemplate; import org.openfast.template.TemplateRegisteredListener; - /* In 1.5 version use : static import java.lang.Math.*; */ public class FastEncoder implements Coder { private Context context; - private List listeners = Collections.EMPTY_LIST; + private List listeners = Collections.EMPTY_LIST; public FastEncoder(Context context) { this.context = context; } - /** * WARNING: Not thread-safe. + * * @param message * @return the fast encoding of the message */ @@ -51,19 +48,16 @@ context.newMessage(template); return template.encode(message, context); } - public void reset() { context.reset(); } - public void registerTemplate(int templateId, MessageTemplate template) { context.registerTemplate(templateId, template); } - - public void addTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener) { - if (listeners.isEmpty()) { - listeners = new ArrayList(); - } - listeners.add(templateRegisteredListener); - } + public void addTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener) { + if (listeners.isEmpty()) { + listeners = new ArrayList(); + } + listeners.add(templateRegisteredListener); + } } Modified: branches/object-model-refactor/src/main/java/org/openfast/session/FastClient.java =================================================================== --- branches/object-model-refactor/src/main/java/org/openfast/session/FastClient.java 2008-05-08 17:25:07 UTC (rev 145) +++ branches/object-model-refactor/src/main/java/org/openfast/session/FastClient.java 2008-05-15 12:25:20 UTC (rev 146) @@ -1,18 +1,47 @@ package org.openfast.session; +import org.openfast.template.BasicTemplateRegistry; +import org.openfast.template.TemplateRegistry; + public class FastClient { private final String clientName; private final Endpoint endpoint; private final SessionProtocol sessionProtocol; + private TemplateRegistry inboundRegistry = new BasicTemplateRegistry(); + private TemplateRegistry outboundRegistry = new BasicTemplateRegistry(); + private MessageListener messageListener = MessageListener.NULL; + private SessionListener sessionListener = SessionListener.NULL; public FastClient(String clientName, SessionProtocol sessionProtocol, Endpoint endpoint) { this.clientName = clientName; this.sessionProtocol = sessionProtocol; this.endpoint = endpoint; } + + public void setInboundTemplateRegistry(TemplateRegistry registry) { + this.inboundRegistry = registry; + } + + public TemplateRegistry getInboundTemplateRegistry() { + return this.inboundRegistry; + } + + public void setOutboundTemplateRegistry(TemplateRegistry registry) { + this.outboundRegistry = registry; + } + + public TemplateRegistry getOutboundTemplateRegistry() { + return this.outboundRegistry; + } + public Session connect() throws FastConnectionException { Connection connection = endpoint.connect(); - Session session = sessionProtocol.connect(clientName, connection); + Session session = sessionProtocol.connect(clientName, connection, inboundRegistry, outboundRegistry, + messageListener, sessionListener); return session; } + + public void setMessageHandler(MessageListener messageListener) { + this.messageListener = messageListener; + } } Modified: branches/object-model-refactor/src/main/java/org/openfast/session/FastServer.java =================================================================== --- branches/object-model-refactor/src/main/java/org/openfast/session/FastServer.java 2008-05-08 17:25:07 UTC (rev 145) +++ branches/object-model-refactor/src/main/java/org/openfast/session/FastServer.java 2008-05-15 12:25:20 UTC (rev 146) @@ -17,23 +17,19 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast.session; import org.openfast.error.ErrorHandler; - public class FastServer implements ConnectionListener { private ErrorHandler errorHandler = ErrorHandler.DEFAULT; private SessionHandler sessionHandler = SessionHandler.NULL; - private boolean listening; - - private final SessionProtocol sessionProtocol; - private final Endpoint endpoint; - private final String serverName; - private Thread serverThread; + private boolean listening; + private final SessionProtocol sessionProtocol; + private final Endpoint endpoint; + private final String serverName; + private Thread serverThread; public FastServer(String serverName, SessionProtocol sessionProtocol, Endpoint endpoint) { if (endpoint == null || sessionProtocol == null) { @@ -44,50 +40,43 @@ this.serverName = serverName; endpoint.setConnectionListener(this); } - public void listen() { - listening = true; - if (serverThread == null) { - Runnable runnable = new Runnable() { - public void run() { - while (listening) { - try { - endpoint.accept(); - } catch (FastConnectionException e) { - errorHandler.error(null, null, e); - } - try { - Thread.sleep(20); - } catch (InterruptedException e) { - } - } - }}; - serverThread = new Thread(runnable, "FastServer"); - } - serverThread.start(); + listening = true; + if (serverThread == null) { + Runnable runnable = new Runnable() { + public void run() { + while (listening) { + try { + endpoint.accept(); + } catch (Exception e) { + errorHandler.error(null, null, e); + } + try { + Thread.sleep(20); + } catch (InterruptedException e) {} + } + } + }; + serverThread = new Thread(runnable, "FastServer"); + } + serverThread.start(); } - public void close() throws FastConnectionException { - listening = false; - endpoint.close(); + listening = false; + endpoint.close(); } - // ************* OPTIONAL DEPENDENCY SETTERS ************** - public void setErrorHandler(ErrorHandler errorHandler) { if (errorHandler == null) { throw new NullPointerException(); } - this.errorHandler = errorHandler; } - - public void onConnect(Connection connection) { - Session session = sessionProtocol.onNewConnection(serverName, connection); - this.sessionHandler.newSession(session); - } - - public void setSessionHandler(SessionHandler sessionHandler) { - this.sessionHandler = sessionHandler; - } + public void onConnect(Connection connection) { + Session session = sessionProtocol.onNewConnection(serverName, connection); + this.sessionHandler.newSession(session); + } + public void setSessionHandler(SessionHandler sessionHandler) { + this.sessionHandler = sessionHandler; + } } Modified: branches/object-model-refactor/src/main/java/org/openfast/session/MessageListener.java =================================================================== --- branches/object-model-refactor/src/main/java/org/openfast/session/MessageListener.java 2008-05-08 17:25:07 UTC (rev 145) +++ branches/object-model-refactor/src/main/java/org/openfast/session/MessageListener.java 2008-05-15 12:25:20 UTC (rev 146) @@ -3,5 +3,8 @@ import org.openfast.Message; public interface MessageListener { - void onMessage(Message message); + MessageListener NULL = new MessageListener() { + public void onMessage(Session session, Message message) {}}; + + void onMessage(Session session, Message message); } Modified: branches/object-model-refactor/src/main/java/org/openfast/session/Session.java =================================================================== --- branches/object-model-refactor/src/main/java/org/openfast/session/Session.java 2008-05-08 17:25:07 UTC (rev 145) +++ branches/object-model-refactor/src/main/java/org/openfast/session/Session.java 2008-05-15 12:25:20 UTC (rev 146) @@ -47,9 +47,11 @@ private ErrorHandler errorHandler = ErrorHandler.DEFAULT; private SessionListener sessionListener = SessionListener.NULL; - public Session(Connection connection, SessionProtocol protocol) { + public Session(Connection connection, SessionProtocol protocol, TemplateRegistry inboundRegistry, TemplateRegistry outboundRegistry) { Context inContext = new Context(); + inContext.getTemplateRegistry().registerAll(inboundRegistry); Context outContext = new Context(); + outContext.getTemplateRegistry().registerAll(outboundRegistry); inContext.setErrorHandler(this); this.connection = connection; @@ -141,7 +143,7 @@ if (protocol.isProtocolMessage(message)) { protocol.handleMessage(Session.this, message); } else if (messageListener != null) { - messageListener.onMessage(message); + messageListener.onMessage(Session.this, message); } else { throw new IllegalStateException("Received non-protocol message without a message listener."); } Modified: branches/object-model-refactor/src/main/java/org/openfast/session/SessionControlProtocol_1_0.java =================================================================== --- branches/object-model-refactor/src/main/java/org/openfast/session/SessionControlProtocol_1_0.java 2008-05-08 17:25:07 UTC (rev 145) +++ branches/object-model-refactor/src/main/java/org/openfast/session/SessionControlProtocol_1_0.java 2008-05-15 12:25:20 UTC (rev 146) @@ -38,15 +38,18 @@ static final int FAST_ALERT_TEMPLATE_ID = 16001; public Session onNewConnection(String serverName, Connection connection) { - Session session = new Session(connection, this); + Session session = new Session(connection, this, TemplateRegistry.NULL, TemplateRegistry.NULL); Message message = session.in.readMessage(); session.out.writeMessage(createHelloMessage(serverName)); String clientName = message.getString(1); session.setClient(new BasicClient(clientName, "unknown")); return session; } - public Session connect(String senderName, Connection connection) { - Session session = new Session(connection, this); + public Session connect(String senderName, Connection connection, TemplateRegistry inboundRegistry, + TemplateRegistry outboundRegistry, MessageListener messageListener, SessionListener sessionListener) { + Session session = new Session(connection, this, inboundRegistry, outboundRegistry); + session.setMessageHandler(messageListener); + session.setSessionListener(sessionListener); session.out.writeMessage(createHelloMessage(senderName)); Message message = session.in.readMessage(); String serverName = message.getString(1); Modified: branches/object-model-refactor/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java =================================================================== --- branches/object-model-refactor/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java 2008-05-08 17:25:07 UTC (rev 145) +++ branches/object-model-refactor/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java 2008-05-15 12:25:20 UTC (rev 146) @@ -99,8 +99,9 @@ public void registerSessionTemplates(TemplateRegistry registry) { registry.registerAll(TEMPLATE_REGISTRY); } - public Session connect(String senderName, Connection connection) { - Session session = new Session(connection, this); + public Session connect(String senderName, Connection connection, TemplateRegistry inboundRegistry, + TemplateRegistry outboundRegistry, MessageListener messageListener, SessionListener sessionListener) { + Session session = new Session(connection, this, inboundRegistry, outboundRegistry); session.out.writeMessage(createHelloMessage(senderName)); try { Thread.sleep(20); @@ -115,7 +116,7 @@ session.out.writeMessage(createFastAlertMessage(code)); } public Session onNewConnection(String serverName, Connection connection) { - Session session = new Session(connection, this); + Session session = new Session(connection, this, TemplateRegistry.NULL, TemplateRegistry.NULL); Message message = session.in.readMessage(); String clientName = message.getString(1); String vendorId = message.isDefined(2) ? message.getString(2) : "unknown"; @@ -408,4 +409,5 @@ } private static final Message CLOSE = createFastAlertMessage(SessionConstants.CLOSE); + private static final TemplateRegistry PROTOCOL_TEMPLATES = new BasicTemplateRegistry(); } Modified: branches/object-model-refactor/src/main/java/org/openfast/session/SessionProtocol.java =================================================================== --- branches/object-model-refactor/src/main/java/org/openfast/session/SessionProtocol.java 2008-05-08 17:25:07 UTC (rev 145) +++ branches/object-model-refactor/src/main/java/org/openfast/session/SessionProtocol.java 2008-05-15 12:25:20 UTC (rev 146) @@ -3,10 +3,11 @@ import org.openfast.Message; import org.openfast.error.ErrorCode; import org.openfast.template.MessageTemplate; +import org.openfast.template.TemplateRegistry; public interface SessionProtocol { public void configureSession(Session session); - public Session connect(String senderName, Connection connection); + public Session connect(String senderName, Connection connection, TemplateRegistry inboundRegistry, TemplateRegistry outboundRegistry, MessageListener messageListener, SessionListener sessionListener); public Session onNewConnection(String serverName, Connection connection); public void onError(Session session, ErrorCode code, String message); public Message getResetMessage(); Modified: branches/object-model-refactor/src/main/java/org/openfast/session/multicast/MulticastInputStream.java =================================================================== --- branches/object-model-refactor/src/main/java/org/openfast/session/multicast/MulticastInputStream.java 2008-05-08 17:25:07 UTC (rev 145) +++ branches/object-model-refactor/src/main/java/org/openfast/session/multicast/MulticastInputStream.java 2008-05-15 12:25:20 UTC (rev 146) @@ -7,24 +7,29 @@ import java.nio.ByteBuffer; public class MulticastInputStream extends InputStream { - private static final int BUFFER_SIZE = 4 * 1024 * 1024; + private static final int BUFFER_SIZE = 256 * 1024; private MulticastSocket socket; private ByteBuffer buffer; public MulticastInputStream(MulticastSocket socket) { + this(socket, BUFFER_SIZE); + } + + public MulticastInputStream(MulticastSocket socket, int bufferSize) { this.socket = socket; - this.buffer = ByteBuffer.allocate(BUFFER_SIZE); + this.buffer = ByteBuffer.allocate(bufferSize); buffer.flip(); } public int read() throws IOException { if (socket.isClosed()) return -1; if (!buffer.hasRemaining()) { + buffer.clear(); + DatagramPacket packet = new DatagramPacket(buffer.array(), buffer.capacity()); + socket.receive(packet); buffer.flip(); - DatagramPacket packet = new DatagramPacket(buffer.array(), buffer.array().length); - socket.receive(packet); buffer.limit(packet.getLength()); } - return buffer.get(); + return (int)(buffer.get() & 0xFF); } } Modified: branches/object-model-refactor/src/main/java/org/openfast/template/BasicTemplateRegistry.java =================================================================== --- branches/object-model-refactor/src/main/java/org/openfast/template/BasicTemplateRegistry.java 2008-05-08 17:25:07 UTC (rev 145) +++ branches/object-model-refactor/src/main/java/org/openfast/template/BasicTemplateRegistry.java 2008-05-15 12:25:20 UTC (rev 146) @@ -9,106 +9,93 @@ import org.openfast.QName; public class BasicTemplateRegistry extends AbstractTemplateRegistry { - private Map nameMap = new HashMap(); - private Map idMap = new HashMap(); - private Map templateMap = new HashMap(); - private List templates = new ArrayList(); + private Map nameMap = new HashMap(); + private Map idMap = new HashMap(); + private Map templateMap = new HashMap(); + private List templates = new ArrayList(); - public void register(int id, MessageTemplate template) { - define(template); - Integer tid = new Integer(id); - idMap.put(tid, template); - templateMap.put(template, tid); - notifyTemplateRegistered(template, id); - } - - public void register(int id, QName name) { - if (!nameMap.containsKey(name)) - throw new IllegalArgumentException("The template named " + name + " is not defined."); - Integer tid = new Integer(id); - MessageTemplate template = (MessageTemplate) nameMap.get(name); - templateMap.put(template, tid); - idMap.put(tid, template); - notifyTemplateRegistered(template, id); - } - - public void define(MessageTemplate template) { - if (!templates.contains(template)) { - nameMap.put(template.getQName(), template); - templates.add(template); - } - } - - public int getId(QName name) { - Object template = nameMap.get(name); - if (template == null || !templateMap.containsKey(template)) return -1; - return ((Integer)templateMap.get(template)).intValue(); - } - - public MessageTemplate get(int templateId) { - return (MessageTemplate) idMap.get(new Integer(templateId)); - } - - public MessageTemplate get(QName name) { - return (MessageTemplate) nameMap.get(name); - } - - public int getId(MessageTemplate template) { - if (!isRegistered(template)) return -1; - return ((Integer)templateMap.get(template)).intValue(); - } - - public boolean isRegistered(QName name) { - return nameMap.containsKey(name); - } - - public boolean isRegistered(int templateId) { - return idMap.containsKey(new Integer(templateId)); - } - - public boolean isRegistered(MessageTemplate template) { - return templateMap.containsKey(template); - } - - public boolean isDefined(QName name) { - return nameMap.containsKey(name); - } - - public MessageTemplate[] getTemplates() { - return (MessageTemplate[]) templateMap.keySet().toArray(new MessageTemplate[templateMap.size()]); - } - - public void remove(QName name) { - MessageTemplate template = (MessageTemplate) nameMap.remove(name); - Object id = templateMap.remove(template); - idMap.remove(id); - templates.remove(template); - } - - public void remove(MessageTemplate template) { - Object id = templateMap.remove(template); - nameMap.remove(template.getName()); - idMap.remove(id); - } - - public void remove(int id) { - MessageTemplate template = (MessageTemplate) idMap.remove(new Integer(id)); - templateMap.remove(template); - nameMap.remove(template.getName()); - } - - public void registerAll(TemplateRegistry registry) { - MessageTemplate[] templates = registry.getTemplates(); - for (int i=0; i<templates.length; i++) { - register(registry.getId(templates[i]), templates[i]); - } - } - - public Iterator nameIterator() { - return nameMap.keySet().iterator(); - } - - public Iterator iterator() { - return templates.iterator(); - } + public void register(int id, MessageTemplate template) { + define(template); + Integer tid = new Integer(id); + idMap.put(tid, template); + templateMap.put(template, tid); + notifyTemplateRegistered(template, id); + } + public void register(int id, QName name) { + if (!nameMap.containsKey(name)) + throw new IllegalArgumentException("The template named " + name + " is not defined."); + Integer tid = new Integer(id); + MessageTemplate template = (MessageTemplate) nameMap.get(name); + templateMap.put(template, tid); + idMap.put(tid, template); + notifyTemplateRegistered(template, id); + } + public void define(MessageTemplate template) { + if (!templates.contains(template)) { + nameMap.put(template.getQName(), template); + templates.add(template); + } + } + public int getId(QName name) { + Object template = nameMap.get(name); + if (template == null || !templateMap.containsKey(template)) + return -1; + return ((Integer) templateMap.get(template)).intValue(); + } + public MessageTemplate get(int templateId) { + return (MessageTemplate) idMap.get(new Integer(templateId)); + } + public MessageTemplate get(QName name) { + return (MessageTemplate) nameMap.get(name); + } + public int getId(MessageTemplate template) { + if (!isRegistered(template)) + return -1; + return ((Integer) templateMap.get(template)).intValue(); + } + public boolean isRegistered(QName name) { + return nameMap.containsKey(name); + } + public boolean isRegistered(int templateId) { + return idMap.containsKey(new Integer(templateId)); + } + public boolean isRegistered(MessageTemplate template) { + return templateMap.containsKey(template); + } + public boolean isDefined(QName name) { + return nameMap.containsKey(name); + } + public MessageTemplate[] getTemplates() { + return (MessageTemplate[]) templateMap.keySet().toArray(new MessageTemplate[templateMap.size()]); + } + public void remove(QName name) { + MessageTemplate template = (MessageTemplate) nameMap.remove(name); + Object id = templateMap.remove(template); + idMap.remove(id); + templates.remove(template); + } + public void remove(MessageTemplate template) { + Object id = templateMap.remove(template); + nameMap.remove(template.getName()); + idMap.remove(id); + } + public void remove(int id) { + MessageTemplate template = (MessageTemplate) idMap.remove(new Integer(id)); + templateMap.remove(template); + nameMap.remove(template.getName()); + } + public void registerAll(TemplateRegistry registry) { + if (registry == null) return; + MessageTemplate[] templates = registry.getTemplates(); + if (templates == null) return; + for (int i = 0; i < templates.length; i++) { + register(registry.getId(templates[i]), templates[i]); + } + } + public Iterator nameIterator() { + return nameMap.keySet().iterator(); + } + public Iterator iterator() { + return templates.iterator(); + } } Modified: branches/object-model-refactor/src/main/java/org/openfast/template/NullTemplateRegistry.java =================================================================== --- branches/object-model-refactor/src/main/java/org/openfast/template/NullTemplateRegistry.java 2008-05-08 17:25:07 UTC (rev 145) +++ branches/object-model-refactor/src/main/java/org/openfast/template/NullTemplateRegistry.java 2008-05-15 12:25:20 UTC (rev 146) @@ -9,139 +9,91 @@ import org.openfast.QName; final class NullTemplateRegistry implements TemplateRegistry { - public void addTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener) { - } - - public MessageTemplate get(int templateId) { - return null; - } - - public MessageTemplate get(String templateName) { - return null; - } - - public int getTemplateId(String templateName) { - return 0; - } - - public int getTemplateId(MessageTemplate template) { - return 0; - } - - public MessageTemplate[] getTemplates() { - return null; - } - - public boolean isRegistered(String templateName) { - return false; - } - - public boolean isRegistered(int templateId) { - return false; - } - - public boolean isRegistered(MessageTemplate template) { - return false; - } - - public void register(int templateId, MessageTemplate template) { - } - - public void remove(String name) { - } - - public void remove(MessageTemplate template) { - } - - public void remove(int id) { - } - - public void add(MessageTemplate template) { - } - - public void define(MessageTemplate template) { - } - - public MessageTemplate getTemplate(String name) { - return null; - } - - public MessageTemplate getTemplate(QName name) { - return null; - } - - public MessageTemplate getTemplate(int id) { - return null; - } - - public boolean hasTemplate(String name) { - return false; - } - - public boolean hasTemplate(QName name) { - return false; - } - - public boolean hasTemplate(int id) { - return false; - } - - public boolean isDefined(MessageTemplate template) { - return false; - } - - public MessageTemplate[] toArray() { - return null; - } - - public MessageTemplate get(QName name) { - return null; - } - - public int getId(String name) { - return 0; - } - - public int getId(MessageTemplate template) { - return 0; - } - - public boolean isDefined(QName name) { - return false; - } - - public boolean isDefined(String name) { - return false; - } - - public void register(int templateId, QName name) { - } - - public void register(int templateId, String name) { - } - - public void removeTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener) { - } - - public int getId(QName name) { - return 0; - } - - public boolean isRegistered(QName name) { - return false; - } - - public void remove(QName name) { - } - - public void registerAll(TemplateRegistry registry) { - } - - public Iterator nameIterator() { - return Collections.EMPTY_LIST.iterator(); - } - - public Iterator iterator() { - return null; - } + public void addTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener) {} + public MessageTemplate get(int templateId) { + return null; + } + public MessageTemplate get(String templateName) { + return null; + } + public int getTemplateId(String templateName) { + return 0; + } + public int getTemplateId(MessageTemplate template) { + return 0; + } + public MessageTemplate[] getTemplates() { + return new MessageTemplate[] {}; + } + public boolean isRegistered(String templateName) { + return false; + } + public boolean isRegistered(int templateId) { + return false; + } + public boolean isRegistered(MessageTemplate template) { + return false; + } + public void register(int templateId, MessageTemplate template) {} + public void remove(String name) {} + public void remove(MessageTemplate template) {} + public void remove(int id) {} + public void add(MessageTemplate template) {} + public void define(MessageTemplate template) {} + public MessageTemplate getTemplate(String name) { + return null; + } + public MessageTemplate getTemplate(QName name) { + return null; + } + public MessageTemplate getTemplate(int id) { + return null; + } + public boolean hasTemplate(String name) { + return false; + } + public boolean hasTemplate(QName name) { + return false; + } + public boolean hasTemplate(int id) { + return false; + } + public boolean isDefined(MessageTemplate template) { + return false; + } + public MessageTemplate[] toArray() { + return null; + } + public MessageTemplate get(QName name) { + return null; + } + public int getId(String name) { + return 0; + } + public int getId(MessageTemplate template) { + return 0; + } + public boolean isDefined(QName name) { + return false; + } + public boolean isDefined(String name) { + return false; + } + public void register(int templateId, QName name) {} + public void register(int templateId, String name) {} + public void removeTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener) {} + public int getId(QName name) { + return 0; + } + public boolean isRegistered(QName name) { + return false; + } + public void remove(QName name) {} + public void registerAll(TemplateRegistry registry) {} + public Iterator nameIterator() { + return Collections.EMPTY_LIST.iterator(); + } + public Iterator iterator() { + return null; + } } \ No newline at end of file Modified: branches/object-model-refactor/src/main/java/org/openfast/template/TemplateRegistry.java =================================================================== --- branches/object-model-refactor/src/main/java/org/openfast/template/TemplateRegistry.java 2008-05-08 17:25:07 UTC (rev 145) +++ branches/object-model-refactor/src/main/java/org/openfast/template/TemplateRegistry.java 2008-05-15 12:25:20 UTC (rev 146) @@ -17,63 +17,53 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast.template; import java.util.Iterator; import org.openfast.QName; - - public interface TemplateRegistry extends Iterable { - TemplateRegistry NULL = new NullTemplateRegistry(); - - void registerAll(TemplateRegistry registry); - void register(int id, MessageTemplate template); - void register(int id, String name); - void register(int id, QName name); - - void define(MessageTemplate template); - - void remove(String name); - void remove(QName name); - void remove(MessageTemplate template); - void remove(int id); - - MessageTemplate get(int id); - MessageTemplate get(String name); - MessageTemplate get(QName name); - - MessageTemplate[] getTemplates(); - - int getId(String name); - int getId(QName name); - int getId(MessageTemplate template); - - boolean isRegistered(String name); - boolean isRegistered(QName name); - boolean isRegistered(int id); - boolean isRegistered(MessageTemplate template); - boolean isDefined(String name); - boolean isDefined(QName name); - - void addTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener); - void removeTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener); - - /** - * Iterator over the names of each template (defined or registered) in this registry - * - * @return an iterator over the qualified names each item is of type QName - */ - Iterator/*<QName>*/ nameIterator(); - - /** - * Iterator over the set of templates (defined or registered) in this registry - * - * @return an iterator over the set of templates each item is an instance of MessageTemplate - */ - Iterator/*<MessageTemplate>*/ iterator(); + TemplateRegistry NULL = new NullTemplateRegistry(); + + void registerAll(TemplateRegistry registry); + void register(int id, MessageTemplate template); + void register(int id, String name); + void register(int id, QName name); + void define(MessageTemplate template); + void remove(String name); + void remove(QName name); + void remove(MessageTemplate template); + void remove(int id); + MessageTemplate get(int id); + MessageTemplate get(String name); + MessageTemplate get(QName name); + MessageTemplate[] getTemplates(); + int getId(String name); + int getId(QName name); + int getId(MessageTemplate template); + boolean isRegistered(String name); + boolean isRegistered(QName name); + boolean isRegistered(int id); + boolean isRegistered(MessageTemplate template); + boolean isDefined(String name); + boolean isDefined(QName name); + void addTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener); + void removeTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener); + /** + * Iterator over the names of each template (defined or registered) in this + * registry + * + * @return an iterator over the qualified names each item is of type QName + */ + Iterator/* <QName> */nameIterator(); + /** + * Iterator over the set of templates (defined or registered) in this + * registry + * + * @return an iterator over the set of templates each item is an instance of + * MessageTemplate + */ + Iterator/* <MessageTemplate> */iterator(); } Modified: branches/object-model-refactor/src/test/java/org/openfast/DictionaryTest.java =================================================================== --- branches/object-model-refactor/src/test/java/org/openfast/DictionaryTest.java 2008-05-08 17:25:07 UTC (rev 145) +++ branches/object-model-refactor/src/test/java/org/openfast/DictionaryTest.java 2008-05-15 12:25:20 UTC (rev 146) @@ -17,9 +17,7 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast; import java.io.ByteArrayOutputStream; @@ -35,11 +33,11 @@ import org.openfast.template.Field; import org.openfast.template.MessageTemplate; import org.openfast.template.Scalar; +import org.openfast.template.TemplateRegistry; import org.openfast.template.operator.Operator; import org.openfast.template.type.Type; import org.openfast.test.TestUtil; - public class DictionaryTest extends TestCase { private Session session; private ByteArrayOutputStream out; @@ -47,57 +45,41 @@ protected void setUp() throws Exception { out = new ByteArrayOutputStream(); session = new Session(new Connection() { - public InputStream getInputStream() throws IOException { - return null; - } - - public OutputStream getOutputStream() throws IOException { - return out; - } - - public void close() { - try { - out.close(); - } catch (IOException e) { - } - } - - }, SessionConstants.SCP_1_0); + public InputStream getInputStream() throws IOException { + return null; + } + public OutputStream getOutputStream() throws IOException { + return out; + } + public void close() { + try { + out.close(); + } catch (IOException e) {} + } + }, SessionConstants.SCP_1_0, TemplateRegistry.NULL, TemplateRegistry.NULL); } - public void testMultipleDictionaryTypes() throws Exception { Scalar bid = new Scalar("bid", Type.DECIMAL, Operator.COPY, ScalarValue.UNDEFINED, false); bid.setDictionary(Dictionary.TEMPLATE); - MessageTemplate quote = new MessageTemplate("quote", new Field[] { bid }); - Scalar bidR = new Scalar("bid", Type.DECIMAL, Operator.COPY, ScalarValue.UNDEFINED, false); - MessageTemplate request = new MessageTemplate("request", - new Field[] { bidR }); - + MessageTemplate request = new MessageTemplate("request", new Field[] { bidR }); Message quote1 = new Message(quote); quote1.setFieldValue(1, new DecimalValue(10.2)); - Message request1 = new Message(request); request1.setFieldValue(1, new DecimalValue(10.3)); - Message quote2 = new Message(quote); quote2.setFieldValue(1, new DecimalValue(10.2)); - Message request2 = new Message(request); request2.setFieldValue(1, new DecimalValue(10.2)); - session.out.registerTemplate(1, request); session.out.registerTemplate(2, quote); session.out.writeMessage(quote1); session.out.writeMessage(request1); session.out.writeMessage(quote2); session.out.writeMessage(request2); - - String expected = "11100000 10000010 11111111 00000000 11100110 " + - "11100000 10000001 11111111 00000000 11100111 " + - "11000000 10000010 " + - "11100000 10000001 11111111 00000000 11100110"; + String expected = "11100000 10000010 11111111 00000000 11100110 " + "11100000 10000001 11111111 00000000 11100111 " + + "11000000 10000010 " + "11100000 10000001 11111111 00000000 11100110"; TestUtil.assertBitVectorEquals(expected, out.toByteArray()); } } Modified: branches/object-model-refactor/src/test/java/org/openfast/session/SCP_1_1_Test.java =================================================================== --- branches/object-model-refactor/src/test/java/org/openfast/session/SCP_1_1_Test.java 2008-05-08 17:25:07 UTC (rev 145) +++ branches/object-model-refactor/src/test/java/org/openfast/session/SCP_1_1_Test.java 2008-05-15 12:25:20 UTC (rev 146) @@ -13,212 +13,188 @@ import org.openfast.util.RecordingOutputStream; public class SCP_1_1_Test extends TestCase { - private static final int MAX_TIMEOUT = 15000; - private LocalEndpoint serverEndpoint; - private RecordingEndpoint clientEndpoint; - private FastServer server; - private FastClient client; - int successfullThreadsCount = 0; + private static final int MAX_TIMEOUT = 15000; + private LocalEndpoint serverEndpoint; + private RecordingEndpoint clientEndpoint; + private FastServer server; + private FastClient client; + int successfullThreadsCount = 0; - protected void setUp() throws Exception { - serverEndpoint = new LocalEndpoint(); - server = new FastServer("server", SessionConstants.SCP_1_1, serverEndpoint); - clientEndpoint = new RecordingEndpoint(new LocalEndpoint(serverEndpoint)); - client = new FastClient("client", SessionConstants.SCP_1_1, clientEndpoint); - } - - protected void tearDown() throws Exception { - server.close(); - } - - public void testSessionEstablishment() throws Exception { - server.setSessionHandler(new SessionHandler() { - public void newSession(Session session) { - assertEquals("client", session.getClient().getName()); - assertEquals(SessionConstants.VENDOR_ID, session.getClient().getVendorId()); - successfullThreadsCount++; - notify0(); - }}); - server.listen(); - - Session session = client.connect(); - - assertEquals("server", session.getClient().getName()); - assertEquals(SessionConstants.VENDOR_ID, session.getClient().getVendorId()); - if (successfullThreadsCount < 1) - wait0(1000); - assertEquals(1, successfullThreadsCount); - } - - public void testSessionReset() throws Exception { - server.setSessionHandler(new SessionHandler() { - public void newSession(Session session) { - session.in.registerTemplate(1, ObjectMother.quoteTemplate()); - - wait0(MAX_TIMEOUT); - Message quote = session.in.readMessage(); - assertEquals(1.0, quote.getDouble(1), .001); - assertEquals(2.0, quote.getDouble(2), .001); - quote = session.in.readMessage(); - assertEquals(1.0, quote.getDouble(1), .001); - assertEquals(2.0, quote.getDouble(2), .001); - quote = session.in.readMessage(); - assertEquals(1.0, quote.getDouble(1), .001); - assertEquals(2.0, quote.getDouble(2), .001); - quote = session.in.readMessage(); - assertEquals(1.0, quote.getDouble(1), .001); - assertEquals(2.0, quote.getDouble(2), .001); - successfullThreadsCount++; - notify0(); - }}); - server.listen(); - Session session = client.connect(); - session.out.registerTemplate(1, ObjectMother.quoteTemplate()); - RecordingOutputStream recordOut = (RecordingOutputStream) session.getConnection().getOutputStream(); - - Message quote = ObjectMother.quote(1.0, 2.0); - - session.out.writeMessage(quote); - recordOut.clear(); - - session.out.writeMessage(quote); - String firstDupe = recordOut.toString(); - recordOut.clear(); - - session.out.writeMessage(quote); - String secondDupe = recordOut.toString(); - - assertEquals(firstDupe, secondDupe); - - session.reset(); - recordOut.clear(); - - session.out.writeMessage(quote); - String lastDupe = recordOut.toString(); - - notify0(); - wait0(MAX_TIMEOUT); - assertFalse(firstDupe.equals(lastDupe)); - assertEquals(1, successfullThreadsCount); - } - - public void testAlert() throws FastConnectionException, IOException { - server.setSessionHandler(new SessionHandler() { - public void newSession(Session session) { - wait0(MAX_TIMEOUT); - session.setListening(true); - session.setErrorHandler(ErrorHandler.NULL); - notify0(); - if (successfullThreadsCount < 0) - wait0(MAX_TIMEOUT); - }}); - server.listen(); - - Session session = client.connect(); - session.setErrorHandler(new ErrorHandler() { - public void error(ErrorCode code, String message) { - assertEquals(SessionConstants.TEMPLATE_NOT_SUPPORTED, code); - successfullThreadsCount++; - notifyAll0(); - } - - public void error(ErrorCode code, String message, Throwable t) { - }}); - session.out.registerTemplate(1, ObjectMother.quoteTemplate()); - - session.out.writeMessage(ObjectMother.quote(1.0, 2.0)); - notify0(); - wait0(MAX_TIMEOUT); - session.setListening(true); - - if (successfullThreadsCount < 1) - wait0(MAX_TIMEOUT); - assertEquals(1, successfullThreadsCount); - } - - public void testTemplateExchange() throws Exception { - server.setSessionHandler(new SessionHandler() { - public void newSession(Session session) { - session.setListening(true); - TemplateRegistry registry = new BasicTemplateRegistry(); - registry.register(24, ObjectMother.quoteTemplate()); - - // Exchange quote template and send a quote with the newly exchanged template. - session.sendTemplates(registry); - session.out.writeMessage(ObjectMother.quote(101.3, 102.4)); - wait0(MAX_TIMEOUT); - try { - session.close(); - } catch (FastConnectionException e) { - } - }}); - server.listen(); - - Session session = client.connect(); - session.setMessageHandler(new MessageListener() { - public void onMessage(Message message) { - if (message.getTemplate().equals(ObjectMother.quoteTemplate())) { - assertEquals(101.3, message.getDouble(1), .1); - assertEquals(102.4, message.getDouble(2), .1); - successfullThreadsCount++; - notifyAll0(); - } - }}); - session.out.registerTemplate(1, ObjectMother.quoteTemplate()); - - if (successfullThreadsCount < 1) - wait0(MAX_TIMEOUT); - assertEquals(1, successfullThreadsCount); - } - - public void testReceiveTemplateDefinitionWithTemplateId() throws Exception { - server.setSessionHandler(new SessionHandler() { - public void newSession(Session session) { - session.setListening(true); - Message templateDef = SessionConstants.SCP_1_1.createTemplateDefinitionMessage(ObjectMother.quoteTemplate()); - templateDef.setInteger("TemplateId", 24); - session.out.registerTemplate(24, ObjectMother.quoteTemplate()); - session.out.writeMessage(templateDef); - session.out.writeMessage(ObjectMother.quote(101.3, 102.4)); - wait0(MAX_TIMEOUT); - try { - session.close(); - } catch (FastConnectionException e) { - } - }}); - server.listen(); - - Session session = client.connect(); - session.setMessageHandler(new MessageListener() { - public void onMessage(Message message) { - if (message.getTemplate().equals(ObjectMother.quoteTemplate())) { - assertEquals(101.3, message.getDouble(1), .1); - assertEquals(102.4, message.getDouble(2), .1); - successfullThreadsCount++; - synchronized(SCP_1_1_Test.this) { - notifyAll0(); - } - } - }}); - session.out.registerTemplate(1, ObjectMother.quoteTemplate()); - - if (successfullThreadsCount < 1) - wait0(MAX_TIMEOUT); - assertEquals(1, successfullThreadsCount); - } - - private synchronized void wait0(int timeout) { - try { - this.wait(timeout); - } catch (InterruptedException e) { - } - } - - private synchronized void notify0() { - this.notify(); - } - - private synchronized void notifyAll0() { - this.notifyAll(); - } + protected void setUp() throws Exception { + serverEndpoint = new LocalEndpoint(); + server = new FastServer("server", SessionConstants.SCP_1_1, serverEndpoint); + clientEndpoint = new RecordingEndpoint(new LocalEndpoint(serverEndpoint)); + client = new FastClient("client", SessionConstants.SCP_1_1, clientEndpoint); + } + protected void tearDown() throws Exception { + server.close(); + } + public void testSessionEstablishment() throws Exception { + server.setSessionHandler(new SessionHandler() { + public void newSession(Session session) { + assertEquals("client", session.getClient().getName()); + assertEquals(SessionConstants.VENDOR_ID, session.getClient().getVendorId()); + successfullThreadsCount++; + notify0(); + } + }); + server.listen(); + Session session = client.connect(); + assertEquals("server", session.getClient().getName()); + assertEquals(SessionConstants.VENDOR_ID, session.getClient().getVendorId()); + if (successfullThreadsCount < 1) + wait0(1000); + assertEquals(1, successfullThreadsCount); + } + public void testSessionReset() throws Exception { + server.setSessionHandler(new SessionHandler() { + public void newSession(Session session) { + session.in.registerTemplate(1, ObjectMother.quoteTemplate()); + wait0(MAX_TIMEOUT); + Message quote = session.in.readMessage(); + assertEquals(1.0, quote.getDouble(1), .001); + assertEquals(2.0, quote.getDouble(2), .001); + quote = session.in.readMessage(); + assertEquals(1.0, quote.getDouble(1), .001); + assertEquals(2.0, quote.getDouble(2), .001); + quote = session.in.readMessage(); + assertEquals(1.0, quote.getDouble(1), .001); + assertEquals(2.0, quote.getDouble(2), .001); + quote = session.in.readMessage(); + assertEquals(1.0, quote.getDouble(1), .001); + assertEquals(2.0, quote.getDouble(2), .001); + successfullThreadsCount++; + notify0(); + } + }); + server.listen(); + Session session = client.connect(); + session.out.registerTemplate(1, ObjectMother.quoteTemplate()); + RecordingOutputStream recordOut = (RecordingOutputStream) session.getConnection().getOutputStream(); + Message quote = ObjectMother.quote(1.0, 2.0); + session.out.writeMessage(quote); + recordOut.clear(); + session.out.writeMessage(quote); + String firstDupe = recordOut.toString(); + recordOut.clear(); + session.out.writeMessage(quote); + String secondDupe = recordOut.toString(); + assertEquals(firstDupe, secondDupe); + session.reset(); + recordOut.clear(); + session.out.writeMessage(quote); + String lastDupe = recordOut.toString(); + notify0(); + wait0(MAX_TIMEOUT); + assertFalse(firstDupe.equals(lastDupe)); + assertEquals(1, successfullThreadsCount); + } + public void testAlert() throws FastConnectionException, IOException { + server.setSessionHandler(new SessionHandler() { + public void newSession(Session session) { + wait0(MAX_TIMEOUT); + session.setListening(true); + session.setErrorHandler(ErrorHandler.NULL); + notify0(); + if (successfullThreadsCount < 0) + wait0(MAX_TIMEOUT); + } + }); + server.listen(); + Session session = client.connect(); + session.setErrorHandler(new ErrorHandler() { + public void error(ErrorCode code, String message) { + assertEquals(SessionConstants.TEMPLATE_NOT_SUPPORTED, code); + successfullThreadsCount++; + notifyAll0(); + } + public void error(ErrorCode code, String message, Throwable t) {} + }); + session.out.registerTemplate(1, ObjectMother.quoteTemplate()); + session.out.writeMessage(ObjectMother.quote(1.0, 2.0)); + notify0(); + wait0(MAX_TIMEOUT); + session.setListening(true); + if (successfullThreadsCount < 1) + wait0(MAX_TIMEOUT); + assertEquals(1, successfullThreadsCount); + } + public void testTemplateExchange() throws Exception { + server.setSessionHandler(new SessionHandler() { + public void newSession(Session session) { + session.setListening(true); + TemplateRegistry registry = new BasicTemplateRegistry(); + registry.register(24, ObjectMother.quoteTemplate()); + // Exchange quote template and send a quote with the newly + // exchanged template. + session.sendTemplates(registry); + session.out.writeMessage(ObjectMother.quote(101.3, 102.4)); + wait0(MAX_TIMEOUT); + try { + session.close(); + } catch (FastConnectionException e) {} + } + }); + server.listen(); + Session session = client.connect(); + session.setMessageHandler(new MessageListener() { + public void onMessage(Session session, Message message) { + if (message.getTemplate().equals(ObjectMother.quoteTemplate())) { + assertEquals(101.3, message.getDouble(1), .1); + assertEquals(102.4, message.getDouble(2), .1); + successfullThreadsCount++; + notifyAll0(); + } + } + }); + session.out.registerTemplate(1, ObjectMother.quoteTemplate()); + if (successfullThreadsCount < 1) + wait0(MAX_TIMEOUT); + assertEquals(1, successfullThreadsCount); + } + public void testReceiveTemplateDefinitionWithTemplateId() throws Exception { + server.setSessionHandler(new SessionHandler() { + public void newSession(Session session) { + session.setListening(true); + Message templateDef = SessionConstants.SCP_1_1.createTemplateDefinitionMessage(ObjectMother.quoteTemplate()); + templateDef.setInteger("TemplateId", 24); + session.out.registerTemplate(24, ObjectMother.quoteTemplate()); + session.out.writeMessage(templateDef); + session.out.writeMessage(ObjectMother.quote(101.3, 102.4)); + wait0(MAX_TIMEOUT); + try { + session.close(); + } catch (FastConnectionException e) {} + } + }); + server.listen(); + Session session = client.connect(); + session.setMessageHandler(new MessageListener() { + public void onMessage(Session session, Message message) { + if (message.getTemplate().equals(ObjectMother.quoteTemplate())) { + assertEquals(101.3, message.getDouble(1), .1); + assertEquals(102.4, message.getDouble(2), .1); + successfullThreadsCount++; + synchronized (SCP_1_1_Test.this) { + notifyAll0(); + } + } + } + }); + session.out.registerTemplate(1, ObjectMother.quoteTemplate()); + if (successfullThreadsCount < 1) + wait0(MAX_TIMEOUT); + assertEquals(1, successfullThreadsCount); + } + private synchronized void wait0(int timeout) { + try { + this.wait(timeout); + } catch (InterruptedException e) {} + } + private synchronized void notify0() { + this.notify(); + } + private synchronized void notifyAll0() { + this.notifyAll(); + } } Modified: branches/object-model-refactor/src/test/java/org/openfast/util/UtilTest.java =================================================================== --- branches/object-model-refactor/src/test/java/org/openfast/util/UtilTest.java 2008-05-08 17:25:07 UTC (rev 145) +++ branches/object-model-refactor/src/test/java/org/openfast/util/UtilTest.java 2008-05-15 12:25:20 UTC (rev 146) @@ -17,72 +17,88 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast.util; +import java.nio.ByteBuffer; import java.util.Calendar; import java.util.LinkedHashMap; import java.util.Map; import junit.framework.TestCase; +import org.openfast.ByteUtil; import org.openfast.IntegerValue; import org.openfast.ScalarValue; import org.openfast.StringValue; import org.openfast.template.TwinValue; +public class UtilTest extends TestCase { + public void testCollectionToString() { + Map map = new LinkedHashMap(); + map.put("abc", "123"); + map.put("def", "456"); + assertEquals("{abc,def}", Util.collectionToString(map.keySet())); + } + + public void testByteVector() { + byte[] bytes = ByteUtil.convertBitStringToFastByteArray("11000000 10000001 10000000"); + ByteBuffer buffer = ByteBuffer.allocate(4096); + buffer.flip(); + putBytes(byt... [truncated message content] |
From: <ope...@li...> - 2008-05-08 17:25:18
|
Revision: 145 http://openfast.svn.sourceforge.net/openfast/?rev=145&view=rev Author: thoennes Date: 2008-05-08 10:25:07 -0700 (Thu, 08 May 2008) Log Message: ----------- - Changed encode() method: + Updated javadoc. + Used defined STOP_BIT constant. Modified Paths: -------------- trunk/src/main/java/org/openfast/template/type/codec/TypeCodec.java Modified: trunk/src/main/java/org/openfast/template/type/codec/TypeCodec.java =================================================================== --- trunk/src/main/java/org/openfast/template/type/codec/TypeCodec.java 2008-04-30 14:35:51 UTC (rev 144) +++ trunk/src/main/java/org/openfast/template/type/codec/TypeCodec.java 2008-05-08 17:25:07 UTC (rev 145) @@ -64,13 +64,17 @@ public abstract ScalarValue decode(InputStream in); /** - * Encode the passed object + * Template Method to encode the passed object, the actual encoding is done in the + * encodeValue() method overridden in sub-classes. + * <p> + * <b>Note</b>: The final SBIT is set in this method, not in encodeValue(). + * </p> * @param value The ScalarValue object to be encoded * @return Returns an encoded byte array with an added stop bit at the end */ public byte[] encode(ScalarValue value) { byte[] encoding = encodeValue(value); - encoding[encoding.length - 1] |= 0x80; // add stop bit; + encoding[encoding.length - 1] |= STOP_BIT; return encoding; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-04-30 14:35:46
|
Revision: 144 http://openfast.svn.sourceforge.net/openfast/?rev=144&view=rev Author: jacob_northey Date: 2008-04-30 07:35:51 -0700 (Wed, 30 Apr 2008) Log Message: ----------- Working on using new common extensible object model (atom). Added Paths: ----------- branches/object-model-refactor/ Copied: branches/object-model-refactor (from rev 143, trunk) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-04-30 12:53:52
|
Revision: 143 http://openfast.svn.sourceforge.net/openfast/?rev=143&view=rev Author: jacob_northey Date: 2008-04-30 05:53:45 -0700 (Wed, 30 Apr 2008) Log Message: ----------- Decimal test Modified Paths: -------------- trunk/src/test/java/org/openfast/submitted/DecimalTest.java Modified: trunk/src/test/java/org/openfast/submitted/DecimalTest.java =================================================================== --- trunk/src/test/java/org/openfast/submitted/DecimalTest.java 2008-04-29 18:33:32 UTC (rev 142) +++ trunk/src/test/java/org/openfast/submitted/DecimalTest.java 2008-04-30 12:53:45 UTC (rev 143) @@ -37,4 +37,16 @@ String expected = "11000000 10000001"; assertEquals(expected, encoder.encode(message)); } + + public void testInitialValue() { + MessageTemplate template = template("<template>" + + "<decimal id=\"1\" presence=\"optional\" name=\"Line1\">" + + "<exponent><copy value=\"-2\"/></exponent> " + + "<mantissa><copy value=\"94276\"/></mantissa> " + + "</decimal></template>"); + FastEncoder encoder = encoder(template); + Message m = (Message) template.createValue(null); + m.setDecimal("Line1", 9427.6 ); + assertEquals("11100000 10000001 11111111", encoder.encode(m)); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-04-29 18:33:28
|
Revision: 142 http://openfast.svn.sourceforge.net/openfast/?rev=142&view=rev Author: jacob_northey Date: 2008-04-29 11:33:32 -0700 (Tue, 29 Apr 2008) Log Message: ----------- [maven-release-plugin] prepare for next development iteration Modified Paths: -------------- trunk/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2008-04-29 18:33:20 UTC (rev 141) +++ trunk/pom.xml 2008-04-29 18:33:32 UTC (rev 142) @@ -3,7 +3,7 @@ <groupId>org.openfast</groupId> <artifactId>openfast</artifactId> <packaging>jar</packaging> - <version>0.9.8</version> + <version>1.0.0-SNAPSHOT</version> <organization> <name>The LaSalle Technology Group, LLC</name> @@ -71,9 +71,9 @@ </issueManagement> <scm> - <connection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.8</connection> - <developerConnection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.8</developerConnection> - <url>http://openfast.svn.sourceforge.net/viewvc/openfast/tags/tags/openfast-0.9.8</url> + <connection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/trunk</connection> + <developerConnection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/trunk</developerConnection> + <url>http://openfast.svn.sourceforge.net/viewvc/openfast/tags/trunk</url> </scm> <mailingLists> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-04-29 18:33:25
|
Revision: 141 http://openfast.svn.sourceforge.net/openfast/?rev=141&view=rev Author: jacob_northey Date: 2008-04-29 11:33:20 -0700 (Tue, 29 Apr 2008) Log Message: ----------- [maven-release-plugin] copy for tag openfast-0.9.8 Added Paths: ----------- tags/openfast-0.9.8/ Copied: tags/openfast-0.9.8 (from rev 140, trunk) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-04-29 18:32:40
|
Revision: 140 http://openfast.svn.sourceforge.net/openfast/?rev=140&view=rev Author: jacob_northey Date: 2008-04-29 11:32:26 -0700 (Tue, 29 Apr 2008) Log Message: ----------- [maven-release-plugin] prepare release openfast-0.9.8 Modified Paths: -------------- trunk/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2008-04-29 18:29:18 UTC (rev 139) +++ trunk/pom.xml 2008-04-29 18:32:26 UTC (rev 140) @@ -3,7 +3,7 @@ <groupId>org.openfast</groupId> <artifactId>openfast</artifactId> <packaging>jar</packaging> - <version>0.9.8-SNAPSHOT</version> + <version>0.9.8</version> <organization> <name>The LaSalle Technology Group, LLC</name> @@ -71,9 +71,9 @@ </issueManagement> <scm> - <connection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/trunk</connection> - <developerConnection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/trunk</developerConnection> - <url>http://openfast.svn.sourceforge.net/viewvc/openfast/tags/trunk</url> + <connection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.8</connection> + <developerConnection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.8</developerConnection> + <url>http://openfast.svn.sourceforge.net/viewvc/openfast/tags/tags/openfast-0.9.8</url> </scm> <mailingLists> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-04-29 18:30:04
|
Revision: 139 http://openfast.svn.sourceforge.net/openfast/?rev=139&view=rev Author: jacob_northey Date: 2008-04-29 11:29:18 -0700 (Tue, 29 Apr 2008) Log Message: ----------- Removed Java 5 JMock dependency Modified Paths: -------------- trunk/pom.xml Removed Paths: ------------- trunk/src/test/java/org/openfast/session/multicast/ Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2008-04-29 18:10:52 UTC (rev 138) +++ trunk/pom.xml 2008-04-29 18:29:18 UTC (rev 139) @@ -1,7 +1,4 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.openfast</groupId> <artifactId>openfast</artifactId> @@ -74,15 +71,9 @@ </issueManagement> <scm> - <connection> - scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/trunk - </connection> - <developerConnection> - scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/trunk - </developerConnection> - <url> - http://openfast.svn.sourceforge.net/viewvc/openfast/trunk - </url> + <connection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/trunk</connection> + <developerConnection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/trunk</developerConnection> + <url>http://openfast.svn.sourceforge.net/viewvc/openfast/tags/trunk</url> </scm> <mailingLists> @@ -197,24 +188,6 @@ <version>3.8.2</version> <scope>test</scope> </dependency> - <dependency> - <groupId>org.jmock</groupId> - <artifactId>jmock</artifactId> - <version>2.4.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.jmock</groupId> - <artifactId>jmock-junit3</artifactId> - <version>2.4.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.jmock</groupId> - <artifactId>jmock-legacy</artifactId> - <version>2.4.0</version> - <scope>test</scope> - </dependency> </dependencies> <distributionManagement> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-04-29 18:12:07
|
Revision: 138 http://openfast.svn.sourceforge.net/openfast/?rev=138&view=rev Author: jacob_northey Date: 2008-04-29 11:10:52 -0700 (Tue, 29 Apr 2008) Log Message: ----------- Fixed optional constant encoding bug; fixed increment integer max value bug Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/org/openfast/IntegerValue.java trunk/src/main/java/org/openfast/Message.java trunk/src/main/java/org/openfast/template/Group.java trunk/src/main/java/org/openfast/template/Scalar.java trunk/src/main/java/org/openfast/template/operator/ConstantOperatorCodec.java trunk/src/main/java/org/openfast/template/operator/IncrementIntegerOperatorCodec.java trunk/src/main/java/org/openfast/template/type/IntegerType.java trunk/src/main/java/org/openfast/template/type/SignedIntegerType.java trunk/src/main/java/org/openfast/template/type/Type.java trunk/src/main/java/org/openfast/template/type/UnsignedIntegerType.java trunk/src/test/java/org/openfast/ExhaustiveOperatorTest.java trunk/src/test/java/org/openfast/submitted/ConstantValueTest.java trunk/src/test/java/org/openfast/template/type/IntegerTypeTest.java trunk/src/test/java/org/openfast/template/type/codec/UnsignedIntegerTest.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2008-04-27 19:57:57 UTC (rev 137) +++ trunk/pom.xml 2008-04-29 18:10:52 UTC (rev 138) @@ -132,9 +132,6 @@ <resource> <directory>src/main/resources</directory> </resource> - <resource> - <directory>src/test/resources</directory> - </resource> </resources> <extensions> <extension> Modified: trunk/src/main/java/org/openfast/IntegerValue.java =================================================================== --- trunk/src/main/java/org/openfast/IntegerValue.java 2008-04-27 19:57:57 UTC (rev 137) +++ trunk/src/main/java/org/openfast/IntegerValue.java 2008-04-29 18:10:52 UTC (rev 138) @@ -45,7 +45,7 @@ } private boolean equals(NumericValue otherValue) { - return value == otherValue.toInt(); + return value == otherValue.toLong(); } public int hashCode() { Modified: trunk/src/main/java/org/openfast/Message.java =================================================================== --- trunk/src/main/java/org/openfast/Message.java 2008-04-27 19:57:57 UTC (rev 137) +++ trunk/src/main/java/org/openfast/Message.java 2008-04-29 18:10:52 UTC (rev 138) @@ -21,8 +21,6 @@ package org.openfast; import org.openfast.template.MessageTemplate; -import org.openfast.template.Scalar; -import org.openfast.template.operator.Operator; public class Message extends GroupValue { private static final long serialVersionUID = 1L; @@ -34,14 +32,6 @@ } public Message(MessageTemplate template) { this(template, initializeFieldValues(template.getFieldCount())); - for (int i = 1; i < template.getFieldCount(); i++) { - if (template.getField(i) instanceof Scalar) { - Scalar scalar = ((Scalar) template.getField(i)); - if (scalar.getOperator().equals(Operator.CONSTANT)) { - setFieldValue(i, scalar.getDefaultValue()); - } - } - } } private static FieldValue[] initializeFieldValues(int fieldCount) { FieldValue[] fields = new FieldValue[fieldCount]; Modified: trunk/src/main/java/org/openfast/template/Group.java =================================================================== --- trunk/src/main/java/org/openfast/template/Group.java 2008-04-27 19:57:57 UTC (rev 137) +++ trunk/src/main/java/org/openfast/template/Group.java 2008-04-29 18:10:52 UTC (rev 138) @@ -176,7 +176,7 @@ if (context.isTraceEnabled()) { context.getEncodeTrace().groupStart(this); } - BitVectorBuilder presenceMapBuilder = new BitVectorBuilder(fields.length); + BitVectorBuilder presenceMapBuilder = new BitVectorBuilder(template.getMaxPresenceMapSize()); try { byte[][] fieldEncodings = new byte[fields.length][]; @@ -209,6 +209,10 @@ } } + private int getMaxPresenceMapSize() { + return fields.length * 2; + } + /** * * @param in Modified: trunk/src/main/java/org/openfast/template/Scalar.java =================================================================== --- trunk/src/main/java/org/openfast/template/Scalar.java 2008-04-27 19:57:57 UTC (rev 137) +++ trunk/src/main/java/org/openfast/template/Scalar.java 2008-04-29 18:10:52 UTC (rev 138) @@ -17,9 +17,7 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast.template; import java.io.InputStream; @@ -40,11 +38,9 @@ import org.openfast.template.type.codec.TypeCodec; import org.openfast.util.RecordingInputStream; - public class Scalar extends Field { private static final long serialVersionUID = 1L; - - private final Operator operator; + private final Operator operator; private final OperatorCodec operatorCodec; private final Type type; private final TypeCodec typeCodec; @@ -53,17 +49,23 @@ private final ScalarValue initialValue; /** - * Scalar constructor - sets the dictionary as global and validates the entries - * @param name The name of Scalar as a string - * @param type The type of this Scalar - * @param operator Which operator object is being used - * @param defaultValue The default value of the ScalarValue - * @param optional Determines if the Scalar is required or not for the data + * Scalar constructor - sets the dictionary as global and validates the + * entries + * + * @param name + * The name of Scalar as a string + * @param type + * The type of this Scalar + * @param operator + * Which operator object is being used + * @param defaultValue + * The default value of the ScalarValue + * @param optional + * Determines if the Scalar is required or not for the data */ public Scalar(String name, Type type, Operator operator, ScalarValue defaultValue, boolean optional) { this(new QName(name), type, operator, defaultValue, optional); } - public Scalar(QName name, Type type, Operator operator, ScalarValue defaultValue, boolean optional) { super(name, optional); this.operator = operator; @@ -72,19 +74,23 @@ this.defaultValue = (defaultValue == null) ? ScalarValue.UNDEFINED : defaultValue; this.type = type; this.typeCodec = type.getCodec(operator, optional); - this.initialValue = ((defaultValue == null) || defaultValue.isUndefined()) - ? this.type.getDefaultValue() - : defaultValue; + this.initialValue = ((defaultValue == null) || defaultValue.isUndefined()) ? this.type.getDefaultValue() : defaultValue; operator.validate(this); } - /** - * Scalar constructor - sets the dictionary as global and validates the entries - * @param name The name of Scalar as a string - * @param type The type of the scalar field - * @param operatorCodec Which operatorCodec object is being used - * @param defaultValue The default value of the ScalarValue - * @param optional Determines if the Scalar is required or not for the data + * Scalar constructor - sets the dictionary as global and validates the + * entries + * + * @param name + * The name of Scalar as a string + * @param type + * The type of the scalar field + * @param operatorCodec + * Which operatorCodec object is being used + * @param defaultValue + * The default value of the ScalarValue + * @param optional + * Determines if the Scalar is required or not for the data */ public Scalar(QName name, Type type, OperatorCodec operatorCodec, ScalarValue defaultValue, boolean optional) { super(name, optional); @@ -94,21 +100,16 @@ this.defaultValue = (defaultValue == null) ? ScalarValue.UNDEFINED : defaultValue; this.type = type; this.typeCodec = type.getCodec(operator, optional); - this.initialValue = ((defaultValue == null) || defaultValue.isUndefined()) - ? this.type.getDefaultValue() - : defaultValue; + this.initialValue = ((defaultValue == null) || defaultValue.isUndefined()) ? this.type.getDefaultValue() : defaultValue; operator.validate(this); - - } - - /** - * - * @return Returns the type as a string - */ + } + /** + * + * @return Returns the type as a string + */ public Type getType() { return type; } - /** * * @return Returns the Operator object @@ -116,7 +117,6 @@ public OperatorCodec getOperatorCodec() { return operatorCodec; } - /** * * @return Returns the operator name as a string @@ -124,38 +124,38 @@ public Operator getOperator() { return operator; } - /** - * @param fieldValue The Field value - * @param template The Group object - * @param context The previous object to keep the data in sync - * @param presenceMapBuilder The BitVector builder + * @param fieldValue + * The Field value + * @param template + * The Group object + * @param context + * The previous object to keep the data in sync + * @param presenceMapBuilder + * The BitVector builder * @return byte encoding of field - * @throws Throws RuntimeException if the encoding fails - will print to console the name of the scalar to fail + * @throws Throws + * RuntimeException if the encoding fails - will print to + * console the name of the scalar to fail */ public byte[] encode(FieldValue fieldValue, Group template, Context context, BitVectorBuilder presenceMapBuilder) { ScalarValue priorValue = (ScalarValue) context.lookup(getDictionary(), template, getKey()); ScalarValue value = (ScalarValue) fieldValue; if (!operatorCodec.canEncode(value, this)) - Global.handleError(FastConstants.D3_CANT_ENCODE_VALUE, "The scalar " + this + " cannot encode the value " + value); + Global.handleError(FastConstants.D3_CANT_ENCODE_VALUE, "The scalar " + this + " cannot encode the value " + value); ScalarValue valueToEncode = operatorCodec.getValueToEncode((ScalarValue) value, priorValue, this, presenceMapBuilder); - if (operator.shouldStoreValue(value)) { - context.store(getDictionary(), template, getKey(), (ScalarValue) value); + context.store(getDictionary(), template, getKey(), (ScalarValue) value); } - if (valueToEncode == null) { return new byte[0]; } - byte[] encoding = typeCodec.encode(valueToEncode); - if (context.isTraceEnabled() && encoding.length > 0) { - context.getEncodeTrace().field(this, fieldValue, valueToEncode, encoding, presenceMapBuilder.getIndex()); - } - return encoding; + context.getEncodeTrace().field(this, fieldValue, valueToEncode, encoding, presenceMapBuilder.getIndex()); + } + return encoding; } - /** * * @return Returns the dictionary as a string @@ -163,17 +163,16 @@ public String getDictionary() { return dictionary; } - /** * * @param newValue - * @param previousValue the previous value that was decoded + * @param previousValue + * the previous value that was decoded * @return the actual value given the previous value and newly decoded value */ public ScalarValue decodeValue(ScalarValue newValue, ScalarValue previousValue) { return operatorCodec.decodeValue(newValue, previousValue, this); } - /** * * @return Returns the defaultValue of the current ScalarValue @@ -181,138 +180,135 @@ public ScalarValue getDefaultValue() { return defaultValue; } - /** * - * @param previousValue The previousValue of the ScalarValue + * @param previousValue + * The previousValue of the ScalarValue * @return Depending on the operator, various ScalarValues could be returned */ public ScalarValue decode(ScalarValue previousValue) { return operatorCodec.decodeEmptyValue(previousValue, this); } - /** * @return Returns true */ public boolean usesPresenceMapBit() { return operatorCodec.usesPresenceMapBit(optional); } - /** - * @return Returns true if the byte array has a length + * @return Returns true if the byte array has a length */ public boolean isPresenceMapBitSet(byte[] encoding, FieldValue fieldValue) { return operatorCodec.isPresenceMapBitSet(encoding, fieldValue); } - /** * - * @param in The InputStream to be decoded - * @param template The Group object - * @param context The previous object to keep the data in sync - * @param presenceMapReader - * @return Returns the null if the Operator is constant and the optional boolean is true and the present boolean is true, - * otherwise decodes the previousValue and returns the FieldValue object after decoding + * @param in + * The InputStream to be decoded + * @param template + * The Group object + * @param context + * The previous object to keep the data in sync + * @param presenceMapReader + * @return Returns the null if the Operator is constant and the optional + * boolean is true and the present boolean is true, otherwise + * decodes the previousValue and returns the FieldValue object after + * decoding */ public FieldValue decode(InputStream in, Group template, Context context, BitVectorReader presenceMapReader) { - try { - ScalarValue previousValue = null; - if (operator.usesDictionary()) { - previousValue = context.lookup( getDictionary(), template, getKey()); - validateDictionaryTypeAgainstFieldType(previousValue, this.type); - } - ScalarValue value; - - int pmapIndex = presenceMapReader.getIndex(); - if (isPresent(presenceMapReader)) { - if (context.isTraceEnabled()) - in = new RecordingInputStream(in); - - if (!operatorCodec.shouldDecodeType()) { - return operatorCodec.decodeValue(null, null, this); - } - ScalarValue decodedValue = typeCodec.decode(in); - value = decodeValue(decodedValue, previousValue); - - if (context.isTraceEnabled()) - context.getDecodeTrace().field(this, value, decodedValue, ((RecordingInputStream) in).getBuffer(), pmapIndex); - } else { - value = decode(previousValue); - } - - validateDecodedValueIsCorrectForType(value, type); - - if (!((getOperator() == Operator.DELTA) && (value == null))) { - context.store(getDictionary(), template, getKey(), value); - } - - return value; - } catch (FastException e) { - throw new FastException("Error occurred while decoding " + this, e.getCode(), e); - } + try { + ScalarValue previousValue = null; + if (operator.usesDictionary()) { + previousValue = context.lookup(getDictionary(), template, getKey()); + validateDictionaryTypeAgainstFieldType(previousValue, this.type); + } + ScalarValue value; + int pmapIndex = presenceMapReader.getIndex(); + if (isPresent(presenceMapReader)) { + if (context.isTraceEnabled()) + in = new RecordingInputStream(in); + if (!operatorCodec.shouldDecodeType()) { + return operatorCodec.decodeValue(null, null, this); + } + ScalarValue decodedValue = typeCodec.decode(in); + value = decodeValue(decodedValue, previousValue); + if (context.isTraceEnabled()) + context.getDecodeTrace().field(this, value, decodedValue, ((RecordingInputStream) in).getBuffer(), pmapIndex); + } else { + value = decode(previousValue); + } + validateDecodedValueIsCorrectForType(value, type); + if (!((getOperator() == Operator.DELTA) && (value == null))) { + context.store(getDictionary(), template, getKey(), value); + } + return value; + } catch (FastException e) { + throw new FastException("Error occurred while decoding " + this, e.getCode(), e); + } } - - /** + /** * Validate the passed ScalarValue and the Type objects - * @param value The value to be validated - * @param type The type to be validated + * + * @param value + * The value to be validated + * @param type + * The type to be validated */ private void validateDecodedValueIsCorrectForType(ScalarValue value, Type type) { - if (value == null) return; - type.validateValue(value); - } - + if (value == null) + return; + type.validateValue(value); + } /** * * @param previousValue - * @param type The type to be validated + * @param type + * The type to be validated */ - private void validateDictionaryTypeAgainstFieldType(ScalarValue previousValue, Type type) { - if (previousValue == null || previousValue.isUndefined()) return; - if (!type.isValueOf(previousValue)) { - Global.handleError(FastConstants.D4_INVALID_TYPE, "The value \"" + previousValue + "\" is not valid for the type " + type); - } - } - - /** + private void validateDictionaryTypeAgainstFieldType(ScalarValue previousValue, Type type) { + if (previousValue == null || previousValue.isUndefined()) + return; + if (!type.isValueOf(previousValue)) { + Global.handleError(FastConstants.D4_INVALID_TYPE, "The value \"" + previousValue + "\" is not valid for the type " + type); + } + } + /** * Sets the dictionary to the passed string - * @param dictionary The string to be stored as the dictionary + * + * @param dictionary + * The string to be stored as the dictionary */ public void setDictionary(String dictionary) { - if (dictionary == null) throw new NullPointerException(); + if (dictionary == null) + throw new NullPointerException(); this.dictionary = dictionary; } - /** * @return Returns the string 'Scalar [name=X, operator=X, dictionary=X]' */ public String toString() { - return "Scalar [name=" + name.getName() + ", operator=" + operator + ", type=" + type + - ", dictionary=" + dictionary + "]"; + return "Scalar [name=" + name.getName() + ", operator=" + operator + ", type=" + type + ", dictionary=" + dictionary + "]"; } - /** * @return Returns the class of the current ScalarValue */ public Class getValueType() { return ScalarValue.class; } - /** - * @param value Creates a FieldValue of the passed value + * @param value + * Creates a FieldValue of the passed value * @return Returns the FieldValue object with the passed value */ public FieldValue createValue(String value) { return type.getValue(value); } - /** * @return Returns the string 'scalar' */ public String getTypeName() { return "scalar"; } - /** * * @return Returns the initialValue of the current ScalarValue object @@ -320,36 +316,30 @@ public ScalarValue getBaseValue() { return initialValue; } - /** * * @return Returns the type of the Codec */ public TypeCodec getTypeCodec() { - return typeCodec; + return typeCodec; } - - public String serialize(ScalarValue value) { - return type.serialize(value); - } - - public boolean equals(Object other) { - if (other == this) return true; - if (other == null || !(other instanceof Scalar)) return false; - return equals((Scalar) other); - } - - private boolean equals(Scalar other) { - return name.equals(other.name) && - type.equals(other.type) && - typeCodec.equals(other.typeCodec) && - operator.equals(other.operator) && - operatorCodec.equals(other.operatorCodec) && - initialValue.equals(other.initialValue) && - dictionary.equals(other.dictionary); - } - - public int hashCode() { - return name.hashCode() + type.hashCode() + typeCodec.hashCode() + operator.hashCode() + operatorCodec.hashCode() + initialValue.hashCode() + dictionary.hashCode(); - } + public String serialize(ScalarValue value) { + return type.serialize(value); + } + public boolean equals(Object other) { + if (other == this) + return true; + if (other == null || !(other instanceof Scalar)) + return false; + return equals((Scalar) other); + } + private boolean equals(Scalar other) { + return name.equals(other.name) && type.equals(other.type) && typeCodec.equals(other.typeCodec) + && operator.equals(other.operator) && operatorCodec.equals(other.operatorCodec) + && initialValue.equals(other.initialValue) && dictionary.equals(other.dictionary); + } + public int hashCode() { + return name.hashCode() + type.hashCode() + typeCodec.hashCode() + operator.hashCode() + operatorCodec.hashCode() + + initialValue.hashCode() + dictionary.hashCode(); + } } Modified: trunk/src/main/java/org/openfast/template/operator/ConstantOperatorCodec.java =================================================================== --- trunk/src/main/java/org/openfast/template/operator/ConstantOperatorCodec.java 2008-04-27 19:57:57 UTC (rev 137) +++ trunk/src/main/java/org/openfast/template/operator/ConstantOperatorCodec.java 2008-04-29 18:10:52 UTC (rev 138) @@ -10,66 +10,54 @@ import org.openfast.template.type.Type; final class ConstantOperatorCodec extends OperatorCodec { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - protected ConstantOperatorCodec(Operator operator, Type[] types) { - super(operator, types); - } - - /** - * - */ - public ScalarValue getValueToEncode(ScalarValue value, ScalarValue priorValue, Scalar field, BitVectorBuilder presenceMapBuilder) { - if (field.isOptional()) - presenceMapBuilder.setOnValueSkipOnNull(value); - return null; // Never encode constant value. - } - - public ScalarValue decodeValue(ScalarValue newValue, - ScalarValue previousValue, Scalar field) { - return field.getDefaultValue(); - } - - public boolean isPresenceMapBitSet(byte[] encoding, - FieldValue fieldValue) { - return fieldValue != null; - } - - public boolean shouldDecodeType() { - return false; - } - - /** - * @param previousValue - * @param field - * @return - */ - public ScalarValue decodeEmptyValue(ScalarValue previousValue, - Scalar field) { - if (!field.isOptional()) { - return field.getDefaultValue(); - } - - return null; - } - - /** - * @return Returns the passed optional boolean - */ - public boolean usesPresenceMapBit(boolean optional) { - return optional; - } - - public ScalarValue getValueToEncode(ScalarValue value, ScalarValue priorValue, Scalar field) { - throw new UnsupportedOperationException(); - } - - public boolean canEncode(ScalarValue value, Scalar field) { - if (field.isOptional() && value == null) return true; - return field.getDefaultValue().equals(value); - } - - public boolean equals(Object obj) { - return obj != null && obj.getClass() == getClass(); - } + protected ConstantOperatorCodec(Operator operator, Type[] types) { + super(operator, types); + } + /** + * + */ + public ScalarValue getValueToEncode(ScalarValue value, ScalarValue priorValue, Scalar field, BitVectorBuilder presenceMapBuilder) { + if (field.isOptional()) + presenceMapBuilder.setOnValueSkipOnNull(value); + return null; // Never encode constant value. + } + public ScalarValue decodeValue(ScalarValue newValue, ScalarValue previousValue, Scalar field) { + return field.getDefaultValue(); + } + public boolean isPresenceMapBitSet(byte[] encoding, FieldValue fieldValue) { + return fieldValue != null; + } + public boolean shouldDecodeType() { + return false; + } + /** + * @param previousValue + * @param field + * @return + */ + public ScalarValue decodeEmptyValue(ScalarValue previousValue, Scalar field) { + if (!field.isOptional()) { + return field.getDefaultValue(); + } + return null; + } + /** + * @return Returns the passed optional boolean + */ + public boolean usesPresenceMapBit(boolean optional) { + return optional; + } + public ScalarValue getValueToEncode(ScalarValue value, ScalarValue priorValue, Scalar field) { + throw new UnsupportedOperationException(); + } + public boolean canEncode(ScalarValue value, Scalar field) { + if (field.isOptional() && value == null) + return true; + return field.getDefaultValue().equals(value); + } + public boolean equals(Object obj) { + return obj != null && obj.getClass() == getClass(); + } } \ No newline at end of file Modified: trunk/src/main/java/org/openfast/template/operator/IncrementIntegerOperatorCodec.java =================================================================== --- trunk/src/main/java/org/openfast/template/operator/IncrementIntegerOperatorCodec.java 2008-04-27 19:57:57 UTC (rev 137) +++ trunk/src/main/java/org/openfast/template/operator/IncrementIntegerOperatorCodec.java 2008-04-29 18:10:52 UTC (rev 138) @@ -6,68 +6,61 @@ import org.openfast.NumericValue; import org.openfast.ScalarValue; import org.openfast.template.Scalar; +import org.openfast.template.type.IntegerType; import org.openfast.template.type.Type; final class IncrementIntegerOperatorCodec extends OperatorCodec { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - IncrementIntegerOperatorCodec(Operator operator, Type[] types) { - super(operator, types); - } - - public ScalarValue getValueToEncode(ScalarValue value, ScalarValue priorValue, Scalar field) { - if (priorValue == null) { - return value; - } - - if (value == null) { - if (field.isOptional()) { - if (priorValue == ScalarValue.UNDEFINED && field.getDefaultValue().isUndefined()) { - return null; - } - return ScalarValue.NULL; - } else { - throw new IllegalArgumentException(); - } - } - - if (priorValue.isUndefined()) { - if (value.equals(field.getDefaultValue())) { - return null; - } else { - return value; - } - } - - if (!value.equals(((NumericValue) priorValue).increment())) { - return value; - } - - return null; - } - - public ScalarValue decodeValue(ScalarValue newValue, ScalarValue previousValue, Scalar field) { - return newValue; - } - - public ScalarValue decodeEmptyValue(ScalarValue previousValue, Scalar field) { - if (previousValue == null) return null; - if (previousValue.isUndefined()) { - if (field.getDefaultValue().isUndefined()) { - if (field.isOptional()) { - return null; - } else { - throw new IllegalStateException("Field with operator increment must send a value if no previous value existed."); - } - } else { - return field.getDefaultValue(); - } - } - - return ((NumericValue) previousValue).increment(); - } - - public boolean equals(Object obj) { - return obj != null && obj.getClass() == getClass(); - } + IncrementIntegerOperatorCodec(Operator operator, Type[] types) { + super(operator, types); + } + public ScalarValue getValueToEncode(ScalarValue value, ScalarValue priorValue, Scalar field) { + if (priorValue == null) { + return value; + } + if (value == null) { + if (field.isOptional()) { + if (priorValue == ScalarValue.UNDEFINED && field.getDefaultValue().isUndefined()) { + return null; + } + return ScalarValue.NULL; + } else { + throw new IllegalArgumentException(); + } + } + if (priorValue.isUndefined()) { + if (value.equals(field.getDefaultValue())) { + return null; + } else { + return value; + } + } + if (!value.equals(((NumericValue) priorValue).increment())) { + return value; + } + return null; + } + public ScalarValue decodeValue(ScalarValue newValue, ScalarValue previousValue, Scalar field) { + return newValue; + } + public ScalarValue decodeEmptyValue(ScalarValue previousValue, Scalar field) { + if (previousValue == null) + return null; + if (previousValue.isUndefined()) { + if (field.getDefaultValue().isUndefined()) { + if (field.isOptional()) { + return null; + } else { + throw new IllegalStateException("Field with operator increment must send a value if no previous value existed."); + } + } else { + return field.getDefaultValue(); + } + } + return ((NumericValue) previousValue).increment(); + } + public boolean equals(Object obj) { + return obj != null && obj.getClass() == getClass(); + } } \ No newline at end of file Modified: trunk/src/main/java/org/openfast/template/type/IntegerType.java =================================================================== --- trunk/src/main/java/org/openfast/template/type/IntegerType.java 2008-04-27 19:57:57 UTC (rev 137) +++ trunk/src/main/java/org/openfast/template/type/IntegerType.java 2008-04-29 18:10:52 UTC (rev 138) @@ -3,9 +3,6 @@ */ package org.openfast.template.type; -import java.util.HashMap; -import java.util.Map; - import org.openfast.Global; import org.openfast.IntegerValue; import org.openfast.ScalarValue; @@ -15,38 +12,7 @@ import org.openfast.util.Util; public abstract class IntegerType extends SimpleType { - protected static final Map MAX_VALUES = new HashMap(); - protected static final Map MIN_VALUES = new HashMap(); - static { - MIN_VALUES.put(new Integer(8), new Byte(Byte.MIN_VALUE)); - MIN_VALUES.put(new Integer(16), new Short(Short.MIN_VALUE)); - MIN_VALUES.put(new Integer(32), new Integer(Integer.MIN_VALUE)); - MIN_VALUES.put(new Integer(64), new Long(Long.MIN_VALUE)); - MAX_VALUES.put(new Integer(8), new Byte(Byte.MAX_VALUE)); - MAX_VALUES.put(new Integer(16), new Short(Short.MAX_VALUE)); - MAX_VALUES.put(new Integer(32), new Integer(Integer.MAX_VALUE)); - MAX_VALUES.put(new Integer(64), new Long(Long.MAX_VALUE)); - } - /** - * - * @param numberBits - * The number of bits as an integer - * @return Returns a long of the max value of the passed integer - */ - protected static long getMax(int numberBits) { - return ((Number) MAX_VALUES.get(new Integer(numberBits))).longValue(); - } - /** - * - * @param numberBits - * The number of bits as an integer - * @return Returns a long of the min value of the passed integer - */ - protected static long getMin(int numberBits) { - return ((Number) MIN_VALUES.get(new Integer(numberBits))).longValue(); - } - protected final long minValue; protected final long maxValue; Modified: trunk/src/main/java/org/openfast/template/type/SignedIntegerType.java =================================================================== --- trunk/src/main/java/org/openfast/template/type/SignedIntegerType.java 2008-04-27 19:57:57 UTC (rev 137) +++ trunk/src/main/java/org/openfast/template/type/SignedIntegerType.java 2008-04-29 18:10:52 UTC (rev 138) @@ -3,9 +3,9 @@ import org.openfast.template.type.codec.TypeCodec; public class SignedIntegerType extends IntegerType { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public SignedIntegerType(int numberBits) { - super("int" + numberBits, getMin(numberBits), getMax(numberBits), TypeCodec.INTEGER, TypeCodec.NULLABLE_INTEGER); - } + public SignedIntegerType(int numberBits, long min, long max) { + super("int" + numberBits, min, max, TypeCodec.INTEGER, TypeCodec.NULLABLE_INTEGER); + } } Modified: trunk/src/main/java/org/openfast/template/type/Type.java =================================================================== --- trunk/src/main/java/org/openfast/template/type/Type.java 2008-04-27 19:57:57 UTC (rev 137) +++ trunk/src/main/java/org/openfast/template/type/Type.java 2008-04-29 18:10:52 UTC (rev 138) @@ -13,92 +13,74 @@ import org.openfast.util.Util; public abstract class Type implements Serializable { - private final static Map TYPE_NAME_MAP = new LinkedHashMap(); - private final String name; - - public Type(String typeName) { - this.name = typeName; - TYPE_NAME_MAP.put(typeName, this); - } - - /** - * Return the type that is being searched for - * @param typeName The type name that being searched for - * @return Return a Type object of the type that is being searched for - */ - public static Type getType(String typeName) { - if (!TYPE_NAME_MAP.containsKey(typeName)) - throw new IllegalArgumentException("The type named " + typeName + " does not exist. Existing types are " + Util.collectionToString(TYPE_NAME_MAP.keySet())); - return (Type) TYPE_NAME_MAP.get(typeName); - } - - /** - * - * @return Returns name as a string - */ - public String getName() { - return name; - } - - /** - * @return Returns the name as a string - */ - public String toString() { - return name; - } - - public String serialize(ScalarValue value) { - return value.toString(); - } - - public abstract TypeCodec getCodec(Operator operator, boolean optional); - public abstract ScalarValue getValue(String value); - public abstract ScalarValue getDefaultValue(); - public abstract boolean isValueOf(ScalarValue previousValue); - public void validateValue(ScalarValue value) {} - - public final static Type U8 = new UnsignedIntegerType(8); - public final static Type U16 = new UnsignedIntegerType(16); - public final static Type U32 = new UnsignedIntegerType(32) { - private static final long serialVersionUID = 1L; + private final static Map TYPE_NAME_MAP = new LinkedHashMap(); + private final String name; - public void validateValue(ScalarValue value) { - if (value instanceof LongValue && (value.toLong() > Integer.MAX_VALUE || value.toLong() < Integer.MIN_VALUE)) - Global.handleError(FastConstants.D2_INT_OUT_OF_RANGE, "The value " + value + " is out of range for the type " + this); - } - }; - public final static Type U64 = new UnsignedIntegerType(64); - public final static Type I8 = new SignedIntegerType(8); - public final static Type I16 = new SignedIntegerType(16); - public final static Type I32 = new SignedIntegerType(32) { - private static final long serialVersionUID = 1L; + public Type(String typeName) { + this.name = typeName; + TYPE_NAME_MAP.put(typeName, this); + } + /** + * Return the type that is being searched for + * + * @param typeName + * The type name that being searched for + * @return Return a Type object of the type that is being searched for + */ + public static Type getType(String typeName) { + if (!TYPE_NAME_MAP.containsKey(typeName)) + throw new IllegalArgumentException("The type named " + typeName + " does not exist. Existing types are " + + Util.collectionToString(TYPE_NAME_MAP.keySet())); + return (Type) TYPE_NAME_MAP.get(typeName); + } + /** + * + * @return Returns name as a string + */ + public String getName() { + return name; + } + /** + * @return Returns the name as a string + */ + public String toString() { + return name; + } + public String serialize(ScalarValue value) { + return value.toString(); + } + public abstract TypeCodec getCodec(Operator operator, boolean optional); + public abstract ScalarValue getValue(String value); + public abstract ScalarValue getDefaultValue(); + public abstract boolean isValueOf(ScalarValue previousValue); + public void validateValue(ScalarValue value) {} - public void validateValue(ScalarValue value) { - if (value instanceof LongValue && (value.toLong() > Integer.MAX_VALUE || value.toLong() < Integer.MIN_VALUE)) { - Global.handleError(FastConstants.D2_INT_OUT_OF_RANGE, "The value " + value + " is out of range for the type " + this); - } - } - }; - public final static Type I64 = new SignedIntegerType(64); - public final static Type STRING = new StringType("string", TypeCodec.ASCII, TypeCodec.NULLABLE_ASCII); - public final static Type ASCII = new StringType("ascii", TypeCodec.ASCII, TypeCodec.NULLABLE_ASCII); - public final static Type UNICODE = new StringType("unicode", TypeCodec.UNICODE, TypeCodec.NULLABLE_UNICODE); - public final static Type BYTE_VECTOR = new ByteVectorType(); - public final static Type DECIMAL = new DecimalType(); - - public static final Type[] ALL_TYPES = new Type[] { U8, U16, U32, U64, I8, I16, I32, I64, STRING, ASCII, UNICODE, BYTE_VECTOR, DECIMAL }; - public static final Type[] INTEGER_TYPES = new Type[] { U8, U16, U32, U64, I8, I16, I32, I64 }; + public final static Type U8 = new UnsignedIntegerType(8, 256); + public final static Type U16 = new UnsignedIntegerType(16, 65536); + public final static Type U32 = new UnsignedIntegerType(32, 4294967295L); + public final static Type U64 = new UnsignedIntegerType(64, Long.MAX_VALUE); + public final static Type I8 = new SignedIntegerType(8, Byte.MIN_VALUE, Byte.MAX_VALUE); + public final static Type I16 = new SignedIntegerType(16, Short.MIN_VALUE, Short.MAX_VALUE); + public final static Type I32 = new SignedIntegerType(32, Integer.MIN_VALUE, Integer.MAX_VALUE); + public final static Type I64 = new SignedIntegerType(64, Long.MIN_VALUE, Long.MAX_VALUE); + public final static Type STRING = new StringType("string", TypeCodec.ASCII, TypeCodec.NULLABLE_ASCII); + public final static Type ASCII = new StringType("ascii", TypeCodec.ASCII, TypeCodec.NULLABLE_ASCII); + public final static Type UNICODE = new StringType("unicode", TypeCodec.UNICODE, TypeCodec.NULLABLE_UNICODE); + public final static Type BYTE_VECTOR = new ByteVectorType(); + public final static Type DECIMAL = new DecimalType(); + public static final Type[] ALL_TYPES = new Type[] { U8, U16, U32, U64, I8, I16, I32, I64, STRING, ASCII, UNICODE, BYTE_VECTOR, + DECIMAL }; + public static final Type[] INTEGER_TYPES = new Type[] { U8, U16, U32, U64, I8, I16, I32, I64 }; - public static Map getRegisteredTypeMap() { - return TYPE_NAME_MAP; - } - - public boolean equals(Object obj) { - if (obj == null) return false; - return obj.getClass().equals(this.getClass()); - } - - public int hashCode() { - return name.hashCode(); - } + public static Map getRegisteredTypeMap() { + return TYPE_NAME_MAP; + } + public boolean equals(Object obj) { + if (obj == null) + return false; + return obj.getClass().equals(this.getClass()); + } + public int hashCode() { + return name.hashCode(); + } } Modified: trunk/src/main/java/org/openfast/template/type/UnsignedIntegerType.java =================================================================== --- trunk/src/main/java/org/openfast/template/type/UnsignedIntegerType.java 2008-04-27 19:57:57 UTC (rev 137) +++ trunk/src/main/java/org/openfast/template/type/UnsignedIntegerType.java 2008-04-29 18:10:52 UTC (rev 138) @@ -4,25 +4,26 @@ import org.openfast.template.type.codec.TypeCodec; public class UnsignedIntegerType extends IntegerType { + private static final long serialVersionUID = 1L; - private static final long serialVersionUID = 1L; - - public UnsignedIntegerType(int numberBits) { - super("uInt" + numberBits, 0, getMax(numberBits), TypeCodec.UINT, TypeCodec.NULLABLE_UNSIGNED_INTEGER); - } - - /** - * Get the approprivate codec for the passed operator - * @param operator The operator object in which the codec is trying to get - * @param optional Determines if the Field is required or not for the data - * @return Returns the codec if the field is required - */ - public TypeCodec getCodec(Operator operator, boolean optional) { - if (operator.equals(Operator.DELTA)) - if (optional) - return TypeCodec.NULLABLE_INTEGER; - else - return TypeCodec.INTEGER; - return super.getCodec(operator, optional); - } + public UnsignedIntegerType(int numberBits, long maxValue) { + super("uInt" + numberBits, 0, maxValue, TypeCodec.UINT, TypeCodec.NULLABLE_UNSIGNED_INTEGER); + } + /** + * Get the approprivate codec for the passed operator + * + * @param operator + * The operator object in which the codec is trying to get + * @param optional + * Determines if the Field is required or not for the data + * @return Returns the codec if the field is required + */ + public TypeCodec getCodec(Operator operator, boolean optional) { + if (operator.equals(Operator.DELTA)) + if (optional) + return TypeCodec.NULLABLE_INTEGER; + else + return TypeCodec.INTEGER; + return super.getCodec(operator, optional); + } } Modified: trunk/src/test/java/org/openfast/ExhaustiveOperatorTest.java =================================================================== --- trunk/src/test/java/org/openfast/ExhaustiveOperatorTest.java 2008-04-27 19:57:57 UTC (rev 137) +++ trunk/src/test/java/org/openfast/ExhaustiveOperatorTest.java 2008-04-29 18:10:52 UTC (rev 138) @@ -161,10 +161,9 @@ MessageTemplate template = registerTemplate(field); Message msg1 = new Message(template); - // NOTE: Constant fields are set by default, so set to null to clear; - msg1.setFieldValue(1, null); Message msg2 = new Message(template); + msg2.setInteger(1, 16); // --PMAP-- --TID--- encodeAndAssertEquals("11000000 11110001", msg1); @@ -179,7 +178,7 @@ public void testConstantOperatorWithMandatoryField() throws IOException { Scalar field = new Scalar("", Type.U32, Operator.CONSTANT, new IntegerValue(16), false); - MessageTemplate template = registerTemplate(field); + MessageTemplate template = registerTemplate(field); // NOTE: The field is not set. Message msg1 = new Message(template); Modified: trunk/src/test/java/org/openfast/submitted/ConstantValueTest.java =================================================================== --- trunk/src/test/java/org/openfast/submitted/ConstantValueTest.java 2008-04-27 19:57:57 UTC (rev 137) +++ trunk/src/test/java/org/openfast/submitted/ConstantValueTest.java 2008-04-29 18:10:52 UTC (rev 138) @@ -2,6 +2,7 @@ import org.openfast.Message; import org.openfast.codec.FastDecoder; +import org.openfast.codec.FastEncoder; import org.openfast.template.MessageTemplate; import org.openfast.test.OpenFastTestCase; @@ -12,12 +13,17 @@ "<string name=\"const\" id=\"14\"> <constant value=\"12\"/> </string>" + "</template>"); FastDecoder decoder = decoder(template, bytes("11000000 10000001 10100000")); + FastEncoder encoder = encoder(template); Message message = decoder.readMessage(); assertEquals("12", message.getString("const")); assertEquals(null, message.getString("constOpt")); + assertEquals("11000000 10000001", encoder.encode(message)); + message = decoder.readMessage(); assertEquals("12", message.getString("const")); assertEquals("13", message.getString("constOpt")); + + assertEquals("10100000", encoder.encode(message)); } } Modified: trunk/src/test/java/org/openfast/template/type/IntegerTypeTest.java =================================================================== --- trunk/src/test/java/org/openfast/template/type/IntegerTypeTest.java 2008-04-27 19:57:57 UTC (rev 137) +++ trunk/src/test/java/org/openfast/template/type/IntegerTypeTest.java 2008-04-29 18:10:52 UTC (rev 138) @@ -17,9 +17,7 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast.template.type; import org.openfast.codec.FastDecoder; @@ -29,7 +27,6 @@ import org.openfast.template.type.codec.IntegerCodec; import org.openfast.test.OpenFastTestCase; - public class IntegerTypeTest extends OpenFastTestCase { public void testGetSignedIntegerSize() { assertEquals(1, IntegerCodec.getSignedIntegerSize(63)); @@ -41,20 +38,15 @@ assertEquals(4, IntegerCodec.getSignedIntegerSize(134217727)); assertEquals(4, IntegerCodec.getSignedIntegerSize(-134217728)); } - public void testIntegerSizeTooLarge() { - MessageTemplate template = template( - "<template>" + - " <uInt32 name=\"price\"/>" + - "</template>"); - - FastDecoder decoder = decoder("11000000 10000001 00111111 01111111 01111111 01111111 11111111", template); - try { - decoder.readMessage(); - fail(); - } catch (FastException e) { - assertEquals(FastConstants.D2_INT_OUT_OF_RANGE, e.getCode()); - assertEquals("The value 17179869183 is out of range for the type uInt32", e.getCause().getCause().getMessage()); - } + MessageTemplate template = template("<template>" + " <uInt32 name=\"price\"/>" + "</template>"); + FastDecoder decoder = decoder("11000000 10000001 00111111 01111111 01111111 01111111 11111111", template); + try { + decoder.readMessage(); + fail(); + } catch (FastException e) { + assertEquals(FastConstants.D2_INT_OUT_OF_RANGE, e.getCode()); + assertEquals("The value 17179869183 is out of range for type uInt32", e.getCause().getCause().getMessage()); + } } } Modified: trunk/src/test/java/org/openfast/template/type/codec/UnsignedIntegerTest.java =================================================================== --- trunk/src/test/java/org/openfast/template/type/codec/UnsignedIntegerTest.java 2008-04-27 19:57:57 UTC (rev 137) +++ trunk/src/test/java/org/openfast/template/type/codec/UnsignedIntegerTest.java 2008-04-29 18:10:52 UTC (rev 138) @@ -14,6 +14,8 @@ assertEncodeDecode(i(269435452), "00000001 00000000 00111101 00000100 10111100", TypeCodec.UINT); assertEncodeDecode(l(274877906943L), "00000111 01111111 01111111 01111111 01111111 11111111", TypeCodec.UINT); assertEncodeDecode(l(1181048340000L), "00100010 00101111 01011111 01011101 01111100 10100000", TypeCodec.UINT); + + assertEncodeDecode(l(4294967295L), "00001111 01111111 01111111 01111111 11111111", TypeCodec.UINT); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-04-27 19:57:53
|
Revision: 137 http://openfast.svn.sourceforge.net/openfast/?rev=137&view=rev Author: jacob_northey Date: 2008-04-27 12:57:57 -0700 (Sun, 27 Apr 2008) Log Message: ----------- Added Multicast support; fixed a load of bugs Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/org/openfast/ApplicationTypeDictionary.java trunk/src/main/java/org/openfast/Context.java trunk/src/main/java/org/openfast/Dictionary.java trunk/src/main/java/org/openfast/GlobalDictionary.java trunk/src/main/java/org/openfast/GroupValue.java trunk/src/main/java/org/openfast/IntegerValue.java trunk/src/main/java/org/openfast/Message.java trunk/src/main/java/org/openfast/QName.java trunk/src/main/java/org/openfast/StringValue.java trunk/src/main/java/org/openfast/TemplateDictionary.java trunk/src/main/java/org/openfast/session/Connection.java trunk/src/main/java/org/openfast/session/Endpoint.java trunk/src/main/java/org/openfast/session/FastClient.java trunk/src/main/java/org/openfast/session/Session.java trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_0.java trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java trunk/src/main/java/org/openfast/session/SessionProtocol.java trunk/src/main/java/org/openfast/session/tcp/TcpConnection.java trunk/src/main/java/org/openfast/session/tcp/TcpEndpoint.java trunk/src/main/java/org/openfast/session/template/exchange/ComposedDecimalConverter.java trunk/src/main/java/org/openfast/template/ComposedValueConverter.java trunk/src/main/java/org/openfast/template/LongValue.java trunk/src/main/java/org/openfast/template/MessageTemplate.java trunk/src/main/java/org/openfast/template/type/DateType.java trunk/src/main/java/org/openfast/template/type/IntegerType.java trunk/src/main/java/org/openfast/template/type/codec/ByteVectorType.java trunk/src/main/java/org/openfast/template/type/codec/DateInteger.java trunk/src/main/java/org/openfast/template/type/codec/NullableSignedInteger.java trunk/src/main/java/org/openfast/template/type/codec/NullableSingleFieldDecimal.java trunk/src/main/java/org/openfast/template/type/codec/NullableUnsignedInteger.java trunk/src/main/java/org/openfast/template/type/codec/TimestampInteger.java trunk/src/main/java/org/openfast/template/type/codec/UnsignedInteger.java trunk/src/test/java/org/openfast/ExhaustiveOperatorTest.java trunk/src/test/java/org/openfast/submitted/EbsDecodingErrorTest.java trunk/src/test/java/org/openfast/template/type/codec/NullableUnsignedIntegerTest.java trunk/src/test/java/org/openfast/test/OpenFastTestCase.java Added Paths: ----------- trunk/src/eclipse/ trunk/src/eclipse/codetemplates.xml trunk/src/main/java/org/openfast/session/multicast/ trunk/src/main/java/org/openfast/session/multicast/MulticastConnection.java trunk/src/main/java/org/openfast/session/multicast/MulticastEndpoint.java trunk/src/main/java/org/openfast/session/multicast/MulticastInputStream.java trunk/src/test/java/org/openfast/session/multicast/ trunk/src/test/java/org/openfast/session/multicast/MulticastInputStreamTest.java trunk/src/test/java/org/openfast/submitted/ConstantValueTest.java trunk/src/test/java/org/openfast/submitted/DecimalTest.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2008-02-22 13:09:00 UTC (rev 136) +++ trunk/pom.xml 2008-04-27 19:57:57 UTC (rev 137) @@ -75,13 +75,13 @@ <scm> <connection> - scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.5 + scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/trunk </connection> <developerConnection> - scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.5 + scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/trunk </developerConnection> <url> - http://openfast.svn.sourceforge.net/viewvc/openfast/tags/openfast-0.9.5 + http://openfast.svn.sourceforge.net/viewvc/openfast/trunk </url> </scm> @@ -200,6 +200,24 @@ <version>3.8.2</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.jmock</groupId> + <artifactId>jmock</artifactId> + <version>2.4.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jmock</groupId> + <artifactId>jmock-junit3</artifactId> + <version>2.4.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jmock</groupId> + <artifactId>jmock-legacy</artifactId> + <version>2.4.0</version> + <scope>test</scope> + </dependency> </dependencies> <distributionManagement> Added: trunk/src/eclipse/codetemplates.xml =================================================================== --- trunk/src/eclipse/codetemplates.xml (rev 0) +++ trunk/src/eclipse/codetemplates.xml 2008-04-27 19:57:57 UTC (rev 137) @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="false" context="filecomment_context" deleted="true" description="Comment for created Java files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name="filecomment">/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> + */</template></templates> \ No newline at end of file Modified: trunk/src/main/java/org/openfast/ApplicationTypeDictionary.java =================================================================== --- trunk/src/main/java/org/openfast/ApplicationTypeDictionary.java 2008-02-22 13:09:00 UTC (rev 136) +++ trunk/src/main/java/org/openfast/ApplicationTypeDictionary.java 2008-04-27 19:57:57 UTC (rev 137) @@ -1,33 +1,70 @@ +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> + */ package org.openfast; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import org.openfast.template.Group; public class ApplicationTypeDictionary implements Dictionary { - private Map dictionary = new HashMap(); + private Map dictionary = new HashMap(); - public ScalarValue lookup(Group template, QName key, QName applicationType) { - if (dictionary.containsKey(template.getTypeReference())) { - Map applicationTypeMap = (Map) dictionary.get(template.getTypeReference()); - if (applicationTypeMap.containsKey(key)) - return (ScalarValue) applicationTypeMap.get(key); - } - return ScalarValue.UNDEFINED; - } + public ScalarValue lookup(Group template, QName key, QName applicationType) { + if (dictionary.containsKey(template.getTypeReference())) { + Map applicationTypeMap = (Map) dictionary.get(template.getTypeReference()); + if (applicationTypeMap.containsKey(key)) + return (ScalarValue) applicationTypeMap.get(key); + } + return ScalarValue.UNDEFINED; + } - public void reset() { - dictionary = new HashMap(); - } + public void reset() { + dictionary = new HashMap(); + } - public void store(Group group, QName applicationType, QName key, ScalarValue value) { - if (!dictionary.containsKey(group.getTypeReference())) { - dictionary.put(group.getTypeReference(), new HashMap()); - } - Map applicationTypeDictionary = (Map) dictionary.get(group.getTypeReference()); - applicationTypeDictionary.put(key, value); - } + public void store(Group group, QName applicationType, QName key, ScalarValue value) { + if (!dictionary.containsKey(group.getTypeReference())) { + dictionary.put(group.getTypeReference(), new HashMap()); + } + Map applicationTypeDictionary = (Map) dictionary.get(group.getTypeReference()); + applicationTypeDictionary.put(key, value); + } + public String toString() { + StringBuilder builder = new StringBuilder(); + Iterator templateIterator = dictionary.keySet().iterator(); + while (templateIterator.hasNext()) { + Object type = templateIterator.next(); + builder.append("Dictionary: Type=" + type.toString()); + Map templateMap = (Map)dictionary.get(type); + Iterator keyIterator = templateMap.keySet().iterator(); + while (keyIterator.hasNext()) { + Object key = keyIterator.next(); + builder.append(key).append("=").append(templateMap.get(key)).append("\n"); + } + } + return builder.toString(); + } + } Modified: trunk/src/main/java/org/openfast/Context.java =================================================================== --- trunk/src/main/java/org/openfast/Context.java 2008-02-22 13:09:00 UTC (rev 136) +++ trunk/src/main/java/org/openfast/Context.java 2008-04-27 19:57:57 UTC (rev 137) @@ -17,9 +17,7 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast; import java.util.Collections; @@ -39,129 +37,111 @@ import org.openfast.template.TemplateRegisteredListener; import org.openfast.template.TemplateRegistry; - +/** + * Manages current state of an encoding or decoding process. Each encoder/decoder should have a separate context + * and contexts should never be shared. + * @author Jacob Northey + */ public class Context { - private TemplateRegistry templateRegistry = new BasicTemplateRegistry(); + private TemplateRegistry templateRegistry = new BasicTemplateRegistry(); private int lastTemplateId; private Map dictionaries = new HashMap(); private ErrorHandler errorHandler = ErrorHandler.DEFAULT; - private QName currentApplicationType; - private List listeners = Collections.EMPTY_LIST; - private boolean traceEnabled; - private Trace encodeTrace; - private Trace decodeTrace; + private QName currentApplicationType; + private List listeners = Collections.EMPTY_LIST; + private boolean traceEnabled; + private Trace encodeTrace; + private Trace decodeTrace; public Context() { dictionaries.put("global", new GlobalDictionary()); dictionaries.put("template", new TemplateDictionary()); dictionaries.put("type", new ApplicationTypeDictionary()); } - public int getTemplateId(MessageTemplate template) { if (!templateRegistry.isRegistered(template)) { errorHandler.error(FastConstants.D9_TEMPLATE_NOT_REGISTERED, "The template " + template + " has not been registered."); return 0; } - - return templateRegistry.getId(template); - } - - public MessageTemplate getTemplate(int templateId) { + return templateRegistry.getId(template); + } + public MessageTemplate getTemplate(int templateId) { if (!templateRegistry.isRegistered(templateId)) { - errorHandler.error(FastConstants.D9_TEMPLATE_NOT_REGISTERED, "The template with id " + templateId + " has not been registered."); + errorHandler.error(FastConstants.D9_TEMPLATE_NOT_REGISTERED, "The template with id " + templateId + + " has not been registered."); return null; } - return templateRegistry.get(templateId); } - public void registerTemplate(int templateId, MessageTemplate template) { templateRegistry.register(templateId, template); Iterator iter = listeners.iterator(); while (iter.hasNext()) { - ((TemplateRegisteredListener) iter.next()).templateRegistered(template, templateId); + ((TemplateRegisteredListener) iter.next()).templateRegistered(template, templateId); } } - public int getLastTemplateId() { return lastTemplateId; } - public void setLastTemplateId(int templateId) { lastTemplateId = templateId; } - public ScalarValue lookup(String dictionary, Group group, QName key) { - if (group.hasTypeReference()) - currentApplicationType = group.getTypeReference(); + if (group.hasTypeReference()) + currentApplicationType = group.getTypeReference(); return getDictionary(dictionary).lookup(group, key, currentApplicationType); } - private Dictionary getDictionary(String dictionary) { - if (!dictionaries.containsKey(dictionary)) - dictionaries.put(dictionary, new GlobalDictionary()); + if (!dictionaries.containsKey(dictionary)) + dictionaries.put(dictionary, new GlobalDictionary()); return (Dictionary) dictionaries.get(dictionary); } - public void store(String dictionary, Group group, QName key, ScalarValue valueToEncode) { - if (group.hasTypeReference()) - currentApplicationType = group.getTypeReference(); + if (group.hasTypeReference()) + currentApplicationType = group.getTypeReference(); getDictionary(dictionary).store(group, currentApplicationType, key, valueToEncode); } - public void reset() { for (Iterator iter = dictionaries.values().iterator(); iter.hasNext();) { Dictionary dict = (Dictionary) iter.next(); dict.reset(); } } - public void setErrorHandler(ErrorHandler errorHandler) { this.errorHandler = errorHandler; } - - public void newMessage(MessageTemplate template) { - currentApplicationType = (template.hasTypeReference()) ? template.getTypeReference() : FastConstants.ANY_TYPE; - } - - public void setCurrentApplicationType(QName name) { - currentApplicationType = name; - } - - public TemplateRegistry getTemplateRegistry() { - return templateRegistry; - } - - public void setTemplateRegistry(TemplateRegistry registry) { - this.templateRegistry = registry; - } - - public boolean isTraceEnabled() { - return traceEnabled; - } - - public void startTrace() { - setEncodeTrace(new BasicEncodeTrace()); - setDecodeTrace(new BasicDecodeTrace()); - } - - public void setTraceEnabled(boolean enabled) { - this.traceEnabled = enabled; - } - - public void setEncodeTrace(BasicEncodeTrace encodeTrace) { - this.encodeTrace = encodeTrace; - } - - public Trace getEncodeTrace() { - return encodeTrace; - } - - public void setDecodeTrace(Trace decodeTrace) { - this.decodeTrace = decodeTrace; - } - - public Trace getDecodeTrace() { - return decodeTrace; - } + public void newMessage(MessageTemplate template) { + currentApplicationType = (template.hasTypeReference()) ? template.getTypeReference() : FastConstants.ANY_TYPE; + } + public void setCurrentApplicationType(QName name) { + currentApplicationType = name; + } + public TemplateRegistry getTemplateRegistry() { + return templateRegistry; + } + public void setTemplateRegistry(TemplateRegistry registry) { + this.templateRegistry = registry; + } + public boolean isTraceEnabled() { + return traceEnabled; + } + public void startTrace() { + setEncodeTrace(new BasicEncodeTrace()); + setDecodeTrace(new BasicDecodeTrace()); + } + public void setTraceEnabled(boolean enabled) { + this.traceEnabled = enabled; + } + public void setEncodeTrace(BasicEncodeTrace encodeTrace) { + this.encodeTrace = encodeTrace; + } + public Trace getEncodeTrace() { + return encodeTrace; + } + public void setDecodeTrace(Trace decodeTrace) { + this.decodeTrace = decodeTrace; + } + public Trace getDecodeTrace() { + return decodeTrace; + } } Modified: trunk/src/main/java/org/openfast/Dictionary.java =================================================================== --- trunk/src/main/java/org/openfast/Dictionary.java 2008-02-22 13:09:00 UTC (rev 136) +++ trunk/src/main/java/org/openfast/Dictionary.java 2008-04-27 19:57:57 UTC (rev 137) @@ -18,8 +18,6 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> */ - - package org.openfast; import org.openfast.template.Group; Modified: trunk/src/main/java/org/openfast/GlobalDictionary.java =================================================================== --- trunk/src/main/java/org/openfast/GlobalDictionary.java 2008-02-22 13:09:00 UTC (rev 136) +++ trunk/src/main/java/org/openfast/GlobalDictionary.java 2008-04-27 19:57:57 UTC (rev 137) @@ -25,6 +25,7 @@ import org.openfast.template.Group; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; @@ -46,4 +47,15 @@ public void reset() { table.clear(); } + + public String toString() { + StringBuilder builder = new StringBuilder(); + Iterator keyIterator = table.keySet().iterator(); + while (keyIterator.hasNext()) { + QName key = (QName) keyIterator.next(); + builder.append("Dictionary: Global"); + builder.append(key).append("=").append(table.get(key)).append("\n"); + } + return builder.toString(); + } } Modified: trunk/src/main/java/org/openfast/GroupValue.java =================================================================== --- trunk/src/main/java/org/openfast/GroupValue.java 2008-02-22 13:09:00 UTC (rev 136) +++ trunk/src/main/java/org/openfast/GroupValue.java 2008-04-27 19:57:57 UTC (rev 137) @@ -21,17 +21,17 @@ package org.openfast; +import java.math.BigDecimal; +import java.util.Iterator; + import org.openfast.template.Field; import org.openfast.template.Group; import org.openfast.template.LongValue; import org.openfast.template.Scalar; +import org.openfast.template.operator.Operator; import org.openfast.template.type.Type; - import org.openfast.util.ArrayIterator; -import java.math.BigDecimal; -import java.util.Iterator; - public class GroupValue implements FieldValue { private static final long serialVersionUID = 1L; @@ -46,6 +46,15 @@ this.group = group; this.values = values; + + for (int i=0; i<group.getFieldCount(); i++) { + if (group.getField(i) instanceof Scalar) { + Scalar scalar = ((Scalar) group.getField(i)); + if (scalar.getOperator().equals(Operator.CONSTANT) && !scalar.isOptional()) { + values[i] = scalar.getDefaultValue(); + } + } + } } public GroupValue(Group group) { Modified: trunk/src/main/java/org/openfast/IntegerValue.java =================================================================== --- trunk/src/main/java/org/openfast/IntegerValue.java 2008-02-22 13:09:00 UTC (rev 136) +++ trunk/src/main/java/org/openfast/IntegerValue.java 2008-04-27 19:57:57 UTC (rev 137) @@ -37,15 +37,15 @@ } public boolean equals(Object obj) { - if ((obj == null) || !(obj instanceof IntegerValue)) { + if ((obj == null) || !(obj instanceof NumericValue)) { return false; } - return equals((IntegerValue) obj); + return equals((NumericValue) obj); } - private boolean equals(IntegerValue otherValue) { - return value == otherValue.value; + private boolean equals(NumericValue otherValue) { + return value == otherValue.toInt(); } public int hashCode() { Modified: trunk/src/main/java/org/openfast/Message.java =================================================================== --- trunk/src/main/java/org/openfast/Message.java 2008-02-22 13:09:00 UTC (rev 136) +++ trunk/src/main/java/org/openfast/Message.java 2008-04-27 19:57:57 UTC (rev 137) @@ -17,55 +17,45 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast; import org.openfast.template.MessageTemplate; import org.openfast.template.Scalar; import org.openfast.template.operator.Operator; - public class Message extends GroupValue { private static final long serialVersionUID = 1L; - private final MessageTemplate template; + private final MessageTemplate template; public Message(MessageTemplate template, FieldValue[] fieldValues) { super(template, fieldValues); this.template = template; } - public Message(MessageTemplate template) { this(template, initializeFieldValues(template.getFieldCount())); - for (int i = 1; i < template.getFieldCount(); i++) { if (template.getField(i) instanceof Scalar) { Scalar scalar = ((Scalar) template.getField(i)); - if (scalar.getOperator().equals(Operator.CONSTANT)) { setFieldValue(i, scalar.getDefaultValue()); } } } } - private static FieldValue[] initializeFieldValues(int fieldCount) { FieldValue[] fields = new FieldValue[fieldCount]; return fields; } - public boolean equals(Object obj) { if ((obj == null) || !(obj instanceof Message)) { return false; } - return equals((Message) obj); } - public boolean equals(Message message) { - if (this.getFieldCount() != message.getFieldCount()) return false; - + if (this.getFieldCount() != message.getFieldCount()) + return false; for (int i = 1; i < message.getFieldCount(); i++) if (message.getValue(i) == null) { if (this.getValue(i) == null) { @@ -76,27 +66,22 @@ } else if (!message.getValue(i).equals(this.getValue(i))) { return false; } - return true; } - public int hashCode() { - return super.hashCode() + template.hashCode(); + return super.hashCode() + template.hashCode(); } - public int getFieldCount() { return values.length; } - public MessageTemplate getTemplate() { return template; } - public FieldValue copy() { - FieldValue[] copies = new FieldValue[values.length]; - for (int i=0; i<copies.length; i++) { - copies[i] = values[i].copy(); - } - return new Message(template, this.values); - } + FieldValue[] copies = new FieldValue[values.length]; + for (int i = 0; i < copies.length; i++) { + copies[i] = values[i].copy(); + } + return new Message(template, this.values); + } } Modified: trunk/src/main/java/org/openfast/QName.java =================================================================== --- trunk/src/main/java/org/openfast/QName.java 2008-02-22 13:09:00 UTC (rev 136) +++ trunk/src/main/java/org/openfast/QName.java 2008-04-27 19:57:57 UTC (rev 137) @@ -1,43 +1,71 @@ +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> + */ package org.openfast; -public class QName { - public static final QName NULL = new QName("", ""); - - private final String namespace; - private final String name; +import java.io.Serializable; - public QName(String name) { - this(name, ""); - } - - public QName(String name, String namespace) { - if (name == null) throw new NullPointerException(); - this.name = name; - this.namespace = namespace == null ? "" : namespace; - } +public class QName implements Serializable { + private static final long serialVersionUID = 1L; - public String getNamespace() { - return namespace; - } + public static final QName NULL = new QName("", ""); - public String getName() { - return name; - } - - public boolean equals(Object obj) { - if (obj == this) return true; - if (obj == null || obj.getClass() != this.getClass()) return false; - QName other = (QName) obj; - return other.namespace.equals(namespace) && other.name.equals(name); - } - - public int hashCode() { - return name.hashCode() + 31*namespace.hashCode(); - } - - public String toString() { - if (namespace.equals("")) - return name; - return name + "[" + namespace + "]"; - } + private final String namespace; + + private final String name; + + public QName(String name) { + this(name, ""); + } + + public QName(String name, String namespace) { + if (name == null) + throw new NullPointerException(); + this.name = name; + this.namespace = namespace == null ? "" : namespace; + } + + public String getNamespace() { + return namespace; + } + + public String getName() { + return name; + } + + public boolean equals(Object obj) { + if (obj == this) + return true; + if (obj == null || obj.getClass() != this.getClass()) + return false; + QName other = (QName) obj; + return other.namespace.equals(namespace) && other.name.equals(name); + } + + public int hashCode() { + return name.hashCode() + 31 * namespace.hashCode(); + } + + public String toString() { + if (namespace.equals("")) + return name; + return name + "[" + namespace + "]"; + } } Modified: trunk/src/main/java/org/openfast/StringValue.java =================================================================== --- trunk/src/main/java/org/openfast/StringValue.java 2008-02-22 13:09:00 UTC (rev 136) +++ trunk/src/main/java/org/openfast/StringValue.java 2008-04-27 19:57:57 UTC (rev 137) @@ -17,9 +17,7 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast; import java.math.BigDecimal; @@ -28,86 +26,79 @@ public class StringValue extends ScalarValue { private static final long serialVersionUID = 1L; - public final String value; + public final String value; public StringValue(String value) { - if (value == null) throw new NullPointerException(); + if (value == null) + throw new NullPointerException(); this.value = value; } - public byte toByte() { - int value = toInt(); - if (value > Byte.MAX_VALUE || value < Byte.MIN_VALUE) { - Global.handleError(FastConstants.R4_NUMERIC_VALUE_TOO_LARGE, "The value \"" + value + "\" is too large to fit into a byte."); - return 0; - } - return (byte) value; + int value = toInt(); + if (value > Byte.MAX_VALUE || value < Byte.MIN_VALUE) { + Global.handleError(FastConstants.R4_NUMERIC_VALUE_TOO_LARGE, "The value \"" + value + + "\" is too large to fit into a byte."); + return 0; + } + return (byte) value; } - public short toShort() { - int value = toInt(); - if (value > Short.MAX_VALUE || value < Short.MIN_VALUE) { - Global.handleError(FastConstants.R4_NUMERIC_VALUE_TOO_LARGE, "The value \"" + value + "\" is too large to fit into a short."); - return 0; - } - return (short) value; + int value = toInt(); + if (value > Short.MAX_VALUE || value < Short.MIN_VALUE) { + Global.handleError(FastConstants.R4_NUMERIC_VALUE_TOO_LARGE, "The value \"" + value + + "\" is too large to fit into a short."); + return 0; + } + return (short) value; } - public int toInt() { - try { - return Integer.parseInt(value); - } catch (NumberFormatException e) { - Global.handleError(FastConstants.R4_NUMERIC_VALUE_TOO_LARGE, "The value \"" + value + "\" is too large to fit into an int.", e); - return 0; - } + try { + return Integer.parseInt(value); + } catch (NumberFormatException e) { + Global.handleError(FastConstants.R4_NUMERIC_VALUE_TOO_LARGE, "The value \"" + value + + "\" is too large to fit into an int.", e); + return 0; + } } - public long toLong() { - try { - return Long.parseLong(value); - } catch (NumberFormatException e) { - Global.handleError(FastConstants.R4_NUMERIC_VALUE_TOO_LARGE, "The value \"" + value + "\" is too large to fit into a long.", e); - return 0; - } + try { + return Long.parseLong(value); + } catch (NumberFormatException e) { + Global.handleError(FastConstants.R4_NUMERIC_VALUE_TOO_LARGE, "The value \"" + value + + "\" is too large to fit into a long.", e); + return 0; + } } - public double toDouble() { - try { - return Double.parseDouble(value); - } catch (NumberFormatException e) { - Global.handleError(FastConstants.R4_NUMERIC_VALUE_TOO_LARGE, "The value\"" + value + "\" is too large to fit into a double.", e); - return 0.0; - } + try { + return Double.parseDouble(value); + } catch (NumberFormatException e) { + Global.handleError(FastConstants.R4_NUMERIC_VALUE_TOO_LARGE, "The value\"" + value + + "\" is too large to fit into a double.", e); + return 0.0; + } } - public byte[] getBytes() { - return value.getBytes(); + return value.getBytes(); } - public BigDecimal toBigDecimal() { - return new BigDecimal(value); + return new BigDecimal(value); } - public String toString() { return value; } - public boolean equals(Object obj) { if ((obj == null) || !(obj instanceof StringValue)) { return false; } - return equals((StringValue) obj); } - private boolean equals(StringValue otherValue) { return value.equals(otherValue.value); } - public int hashCode() { - return value.hashCode(); + return value.hashCode(); } - public boolean equalsValue(String defaultValue) { return value.equals(defaultValue); } Modified: trunk/src/main/java/org/openfast/TemplateDictionary.java =================================================================== --- trunk/src/main/java/org/openfast/TemplateDictionary.java 2008-02-22 13:09:00 UTC (rev 136) +++ trunk/src/main/java/org/openfast/TemplateDictionary.java 2008-04-27 19:57:57 UTC (rev 137) @@ -18,13 +18,12 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> */ - - package org.openfast; import org.openfast.template.Group; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; @@ -54,4 +53,20 @@ ((Map) table.get(group)).put(key, valueToEncode); } + + public String toString() { + StringBuilder builder = new StringBuilder(); + Iterator templateIterator = table.keySet().iterator(); + while (templateIterator.hasNext()) { + Object template = templateIterator.next(); + builder.append("Dictionary: Template=" + template.toString()); + Map templateMap = (Map)table.get(template); + Iterator keyIterator = templateMap.keySet().iterator(); + while (keyIterator.hasNext()) { + Object key = keyIterator.next(); + builder.append(key).append("=").append(templateMap.get(key)).append("\n"); + } + } + return builder.toString(); + } } Modified: trunk/src/main/java/org/openfast/session/Connection.java =================================================================== --- trunk/src/main/java/org/openfast/session/Connection.java 2008-02-22 13:09:00 UTC (rev 136) +++ trunk/src/main/java/org/openfast/session/Connection.java 2008-04-27 19:57:57 UTC (rev 137) @@ -1,3 +1,23 @@ +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> + */ package org.openfast.session; import java.io.IOException; @@ -5,7 +25,7 @@ import java.io.OutputStream; public interface Connection { - InputStream getInputStream() throws IOException; - OutputStream getOutputStream() throws IOException; - void close(); + InputStream getInputStream() throws IOException; + OutputStream getOutputStream() throws IOException; + void close(); } Modified: trunk/src/main/java/org/openfast/session/Endpoint.java =================================================================== --- trunk/src/main/java/org/openfast/session/Endpoint.java 2008-02-22 13:09:00 UTC (rev 136) +++ trunk/src/main/java/org/openfast/session/Endpoint.java 2008-04-27 19:57:57 UTC (rev 137) @@ -1,8 +1,8 @@ package org.openfast.session; public interface Endpoint { - Connection connect() throws FastConnectionException; - void setConnectionListener(ConnectionListener listener); - void accept() throws FastConnectionException; - void close(); + Connection connect() throws FastConnectionException; + void setConnectionListener(ConnectionListener listener); + void accept() throws FastConnectionException; + void close(); } Modified: trunk/src/main/java/org/openfast/session/FastClient.java =================================================================== --- trunk/src/main/java/org/openfast/session/FastClient.java 2008-02-22 13:09:00 UTC (rev 136) +++ trunk/src/main/java/org/openfast/session/FastClient.java 2008-04-27 19:57:57 UTC (rev 137) @@ -1,19 +1,18 @@ package org.openfast.session; public class FastClient { - private final String clientName; - private final Endpoint endpoint; - private final SessionProtocol sessionProtocol; + private final String clientName; + private final Endpoint endpoint; + private final SessionProtocol sessionProtocol; - public FastClient(String clientName, SessionProtocol sessionProtocol, Endpoint endpoint) { - this.clientName = clientName; - this.sessionProtocol = sessionProtocol; - this.endpoint = endpoint; - } - - public Session connect() throws FastConnectionException { - Connection connection = endpoint.connect(); - Session session = sessionProtocol.connect(clientName, connection); - return session; - } + public FastClient(String clientName, SessionProtocol sessionProtocol, Endpoint endpoint) { + this.clientName = clientName; + this.sessionProtocol = sessionProtocol; + this.endpoint = endpoint; + } + public Session connect() throws FastConnectionException { + Connection connection = endpoint.connect(); + Session session = sessionProtocol.connect(clientName, connection); + return session; + } } Modified: trunk/src/main/java/org/openfast/session/Session.java =================================================================== --- trunk/src/main/java/org/openfast/session/Session.java 2008-02-22 13:09:00 UTC (rev 136) +++ trunk/src/main/java/org/openfast/session/Session.java 2008-04-27 19:57:57 UTC (rev 137) @@ -17,9 +17,7 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast.session; import java.io.IOException; @@ -37,54 +35,51 @@ import org.openfast.template.MessageTemplate; import org.openfast.template.TemplateRegistry; - public class Session implements ErrorHandler { - private ErrorHandler errorHandler = ErrorHandler.DEFAULT; public final MessageInputStream in; public final MessageOutputStream out; - private final SessionProtocol protocol; private final Connection connection; - private Client client; - private MessageListener messageListener; - private boolean listening; - private Thread listeningThread; - private SessionListener sessionListener = SessionListener.NULL; + private MessageListener messageListener; + private boolean listening; + private Thread listeningThread; + private ErrorHandler errorHandler = ErrorHandler.DEFAULT; + private SessionListener sessionListener = SessionListener.NULL; public Session(Connection connection, SessionProtocol protocol) { Context inContext = new Context(); Context outContext = new Context(); inContext.setErrorHandler(this); - + this.connection = connection; this.protocol = protocol; try { - this.in = new MessageInputStream(connection.getInputStream(), inContext); - this.out = new MessageOutputStream(connection.getOutputStream(), outContext); - } catch (IOException e) { - errorHandler.error(null, "Error occurred in connection.", e); - throw new IllegalStateException(e); - } - + this.in = new MessageInputStream(connection.getInputStream(), inContext); + this.out = new MessageOutputStream(connection.getOutputStream(), outContext); + } catch (IOException e) { + errorHandler.error(null, "Error occurred in connection.", e); + throw new IllegalStateException(e); + } + protocol.configureSession(this); } // INITIATOR public void close() throws FastConnectionException { - listening = false; - out.writeMessage(protocol.getCloseMessage()); + listening = false; + out.writeMessage(protocol.getCloseMessage()); in.close(); out.close(); } // RESPONDER - public void close(ErrorCode alertCode) { - listening = false; - in.close(); - out.close(); - sessionListener.onClose(); - } + public void close(ErrorCode alertCode) { + listening = false; + in.close(); + out.close(); + sessionListener.onClose(); + } public void setClient(Client client) { this.client = client; @@ -95,16 +90,16 @@ } public void error(ErrorCode code, String message) { - if (code.equals(FastConstants.D9_TEMPLATE_NOT_REGISTERED)) { - code = SessionConstants.TEMPLATE_NOT_SUPPORTED; - message = "Template Not Supported"; - } - protocol.onError(this, code, message); + if (code.equals(FastConstants.D9_TEMPLATE_NOT_REGISTERED)) { + code = SessionConstants.TEMPLATE_NOT_SUPPORTED; + message = "Template Not Supported"; + } + protocol.onError(this, code, message); errorHandler.error(code, message); } public void error(ErrorCode code, String message, Throwable t) { - protocol.onError(this, code, message); + protocol.onError(this, code, message); errorHandler.error(code, message, t); } @@ -116,100 +111,102 @@ this.errorHandler = errorHandler; } - public void reset() { - out.reset(); - in.reset(); - out.writeMessage(protocol.getResetMessage()); - } + public void reset() { + out.reset(); + in.reset(); + out.writeMessage(protocol.getResetMessage()); + } - public Connection getConnection() { - return connection; - } + public Connection getConnection() { + return connection; + } - public void setMessageHandler(MessageListener messageListener) { - this.messageListener = messageListener; - setListening(true); - } + public void setMessageHandler(MessageListener messageListener) { + this.messageListener = messageListener; + setListening(true); + } - private void listenForMessages() { - if (listeningThread == null) { - Runnable messageReader = new Runnable() { - public void run() { - while (listening) { - try { - Message message = in.readMessage(); - - if (message == null) { - listening = false; - break; - } - if (protocol.isProtocolMessage(message)) { - protocol.handleMessage(Session.this, message); - } else if (messageListener != null) { - messageListener.onMessage(message); - } else { - throw new IllegalStateException("Received non-protocol message without a message listener."); - } - } catch (Exception e) { - Throwable cause = e.getCause(); - - if (cause != null && cause.getClass().equals(SocketException.class) && - cause.getMessage().equals("Socket closed")) { - listening = false; - } else if (e instanceof FastException) { - FastException fastException = ((FastException) e); - errorHandler.error(fastException.getCode(), fastException.getMessage()); - } else { - errorHandler.error(FastConstants.GENERAL_ERROR, e.getMessage(), e); - } - } - } - }}; - listeningThread = new Thread(messageReader, "FAST Session Message Reader"); - } - if (listeningThread.isAlive()) return; - listeningThread.start(); - } + private void listenForMessages() { + if (listeningThread == null) { + Runnable messageReader = new Runnable() { + public void run() { + while (listening) { + try { + Message message = in.readMessage(); - public void setListening(boolean listening) { - this.listening = listening; - if (listening) - listenForMessages(); - } + if (message == null) { + listening = false; + break; + } + if (protocol.isProtocolMessage(message)) { + protocol.handleMessage(Session.this, message); + } else if (messageListener != null) { + messageListener.onMessage(message); + } else { + throw new IllegalStateException("Received non-protocol message without a message listener."); + } + } catch (Exception e) { + Throwable cause = e.getCause(); - public ErrorHandler getErrorHandler() { - return errorHandler; - } + if (cause != null && cause.getClass().equals(SocketException.class) + && cause.getMessage().equals("Socket closed")) { + listening = false; + } else if (e instanceof FastException) { + FastException fastException = ((FastException) e); + errorHandler.error(fastException.getCode(), fastException.getMessage()); + } else { + errorHandler.error(FastConstants.GENERAL_ERROR, e.getMessage(), e); + } + } + } + } + }; + listeningThread = new Thread(messageReader, "FAST Session Message Reader"); + } + if (listeningThread.isAlive()) + return; + listeningThread.start(); + } - public void sendTemplates(TemplateRegistry registry) { - if (!protocol.supportsTemplateExchange()) { - throw new UnsupportedOperationException("The procotol " + protocol + " does not support template exchange."); - } - MessageTemplate[] templates = registry.getTemplates(); - for (int i=0; i<templates.length; i++) { - MessageTemplate template = templates[i]; - out.writeMessage(protocol.createTemplateDefinitionMessage(template)); - out.writeMessage(protocol.createTemplateDeclarationMessage(template, registry.getId(template))); - if (!out.getTemplateRegistry().isRegistered(template)) - out.registerTemplate(registry.getId(template), template); - } - } - - public void addDynamicTemplateDefinition(MessageTemplate template) { - in.getTemplateRegistry().define(template); - out.getTemplateRegistry().define(template); - } + public void setListening(boolean listening) { + this.listening = listening; + if (listening) + listenForMessages(); + } - public void registerDynamicTemplate(QName templateName, int id) { - if (!in.getTemplateRegistry().isDefined(templateName)) - throw new IllegalStateException("Template " + templateName + " has not been defined."); - in.getTemplateRegistry().register(id, templateName); - if (!out.getTemplateRegistry().isDefined(templateName)) - throw new IllegalStateException("Template " + templateName + " has not been defined."); - out.getTemplateRegistry().register(id, templateName); - } + public ErrorHandler getErrorHandler() { + return errorHandler; + } - public void setSessionListener(SessionListener sessionListener) { - this.sessionListener = sessionListener; - } + public void sendTemplates(TemplateRegistry registry) { + if (!protocol.supportsTemplateExchange()) { + throw new UnsupportedOperationException("The procotol " + protocol + " does not support template exchange."); + } + MessageTemplate[] templates = registry.getTemplates(); + for (int i = 0; i < templates.length; i++) { + MessageTemplate template = templates[i]; + out.writeMessage(protocol.createTemplateDefinitionMessage(template)); + out.writeMessage(protocol.createTemplateDeclarationMessage(template, registry.getId(template))); + if (!out.getTemplateRegistry().isRegistered(template)) + out.registerTemplate(registry.getId(template), template); + } + } + + public void addDynamicTemplateDefinition(MessageTemplate template) { + in.getTemplateRegistry().define(template); + out.getTemplateRegistry().define(template); + } + + public void registerDynamicTemplate(QName templateName, int id) { + if (!in.getTemplateRegistry().isDefined(templateName)) + throw new IllegalStateException("Template " + templateName + " has not been defined."); + in.getTemplateRegistry().register(id, templateName); + if (!out.getTemplateRegistry().isDefined(templateName)) + throw new IllegalStateException("Template " + templateName + " has not been defined."); + out.getTemplateRegistry().register(id, templateName); + } + + public void setSessionListener(SessionListener sessionListener) { + this.sessionListener = sessionListener; + } } Modified: trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_0.java =================================================================== --- trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_0.java 2008-02-22 13:09:00 UTC (rev 136) +++ trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_0.java 2008-04-27 19:57:57 UTC (rev 137) @@ -1,3 +1,23 @@ +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> + */ package org.openfast.session; import org.openfast.Context; @@ -17,109 +37,88 @@ static final int FAST_HELLO_TEMPLATE_ID = 16000; static final int FAST_ALERT_TEMPLATE_ID = 16001; - public Session onNewConnection(String serverName, Connection connection) { - Session session = new Session(connection, this); - Message message = session.in.readMessage(); + public Session onNewConnection(String serverName, Connection connection) { + Session session = new Session(connection, this); + Message message = session.in.readMessage(); session.out.writeMessage(createHelloMessage(serverName)); - String clientName = message.getString(1); - session.setClient(new BasicClient(clientName, "unknown")); + String clientName = message.getString(1); + session.setClient(new BasicClient(clientName, "unknown")); return session; - } - - public Session connect(String senderName, Connection connection) { - Session session = new Session(connection, this); - session.out.writeMessage(createHelloMessage(senderName)); - Message message = session.in.readMessage(); - String serverName = message.getString(1); - session.setClient(new BasicClient(serverName, "unknown")); + } + public Session connect(String senderName, Connection connection) { + Session session = new Session(connection, this); + session.out.writeMessage(createHelloMessage(senderName)); + Message message = session.in.readMessage(); + String serverName = message.getString(1); + session.setClient(new BasicClient(serverName, "unknown")); return session; - } - - public void onError(Session session, ErrorCode code, String message) { - session.out.writeMessage(createFastAlertMessage(code)); - } - - public void registerSessionTemplates(TemplateRegistry registry) { + } + public void onError(Session session, ErrorCode code, String message) { + session.out.writeMessage(createFastAlertMessage(code)); + } + public void registerSessionTemplates(TemplateRegistry registry) { registry.register(FAST_HELLO_TEMPLATE_ID, FAST_HELLO_TEMPLATE); registry.register(FAST_ALERT_TEMPLATE_ID, FAST_ALERT_TEMPLATE); registry.register(FAST_RESET_TEMPLATE_ID, FAST_RESET_TEMPLATE); - } - - public void configureSession(Session session) { - registerSessionTemplates(session.in.getTemplateRegistry()); - registerSessionTemplates(session.out.getTemplateRegistry()); - - session.in.addMessageHandler(FAST_RESET_TEMPLATE, RESET_HANDLER); - session.out.addMessageHandler(FAST_RESET_TEMPLATE, RESET_HANDLER); - } - + } + public void configureSession(Session session) { + registerSessionTemplates(session.in.getTemplateRegistry()); + registerSessionTemplates(session.out.getTemplateRegistry()); + session.in.addMessageHandler(FAST_RESET_TEMPLATE, RESET_HANDLER); + session.out.addMessageHandler(FAST_RESET_TEMPLATE, RESET_HANDLER); + } public static Message createFastAlertMessage(ErrorCode code) { Message alert = new Message(FAST_ALERT_TEMPLATE); alert.setInteger(1, code.getSeverity().getCode()); alert.setInteger(2, code.getCode()); alert.setString(4, code.getDescription()); - return alert; } - public static Message createHelloMessage(String name) { Message message = new Message(FAST_HELLO_TEMPLATE); message.setString(1, name); - return message; } - public final static MessageTemplate FAST_ALERT_TEMPLATE = new MessageTemplate("", - new Field[] { - new Scalar("Severity", Type.U32, Operator.NONE, - ScalarValue.UNDEFINED, false), - new Scalar("Code", Type.U32, Operator.NONE, ScalarValue.UNDEFINED, false), - new Scalar("Value", Type.U32, Operator.NONE, - ScalarValue.UNDEFINED, true), - new Scalar("Description", Type.ASCII, Operator.NONE, ScalarValue.UNDEFINED, false), - }); - - public final static MessageTemplate FAST_HELLO_TEMPLATE = new MessageTemplate("", - new Field[] { - new Scalar("SenderName", Type.ASCII, Operator.NONE, ScalarValue.UNDEFINED, false) - }); - + + public final static MessageTemplate FAST_ALERT_TEMPLATE = new MessageTemplate("", new Field[] { + new Scalar("Severity", Type.U32, Operator.NONE, ScalarValue.UNDEFINED, false), + new Scalar("Code", Type.U32, Operator.NONE, ScalarValue.UNDEFINED, false), + new Scalar("Value", Type.U32, Operator.NONE, ScalarValue.UNDEFINED, true), + new Scalar("Description", Type.ASCII, Operator.NONE, ScalarValue.UNDEFINED, false), }); + public final static MessageTemplate FAST_HELLO_TEMPLATE = new MessageTemplate("", new Field[] { new Scalar("SenderName", + Type.ASCII, Operator.NONE, ScalarValue.UNDEFINED, false) }); private static final MessageHandler RESET_HANDLER = new MessageHandler() { - public void handleMessage(Message readMessage, Context context, Coder coder) { - coder.reset(); - } - }; + public void handleMessage(Message readMessage, Context context, Coder coder) { + coder.reset(); + } + }; - public void handleMessage(Session session, Message message) { - if (message.getTemplate().equals(FAST_ALERT_TEMPLATE)) { - ErrorCode alertCode = ErrorCode.getAlertCode(message); - if (alertCode.equals(SessionConstants.CLOSE)) { - session.close(alertCode); - } else { - session.getErrorHandler().error(alertCode, message.getString(4)); - } - } - } - - public boolean isProtocolMessage(Message message) { - if (message == null) return false; - return (message.getTemplate().equals(FAST_ALERT_TEMPLATE)) || - (message.getTemplate().equals(FAST_HELLO_TEMPLATE)) || - (message.getTemplate().equals(FAST_RESET_TEMPLATE)); - } - - public boolean supportsTemplateExchange() { - return false; - } - - public Message createTemplateDeclarationMessage(MessageTemplate messageTemplate, int templateId) { - return null; - } - - public Message createTemplateDefinitionMessage(MessageTemplate messageTemplate) { - return null; - } - - public Message getCloseMessage() { - return createFastAlertMessage(SessionConstants.CLOSE); - } + public void handleMessage(Session session, Message message) { + if (message.getTemplate().equals(FAST_ALERT_TEMPLATE)) { + ErrorCode alertCode = ErrorCode.getAlertCode(message); + if (alertCode.equals(SessionConstants.CLOSE)) { + session.close(alertCode); + } else { + session.getErrorHandler().error(alertCode, message.getString(4)); + } + } + } + public boolean isProtocolMessage(Message message) { + if (message == null) + return false; + return (message.getTemplate().equals(FAST_ALERT_TEMPLATE)) || (message.getTemplate().equals(FAST_HELLO_TEMPLATE)) + || (message.getTemplate().equals(FAST_RESET_TEMPLATE)); + } + public boolean supportsTemplateExchange() { + return false; + } + public Message createTemplateDeclarationMessage(MessageTemplate messageTemplate, int templateId) { + return null; + } + public Message createTemplateDefinitionMessage(MessageTemplate messageTemplate) { + return null; + } + public Message getCloseMessage() { + return createFastAlertMessage(SessionConstants.CLOSE); + } } Modified: trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java =================================================================== --- trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java 2008-02-22 13:09:00 UTC (rev 136) +++ trunk/src/main/java/org/openfast/session/SessionControlProtocol_1_1.java 2008-04-27 19:57:57 UTC (rev 137) @@ -1,3 +1,23 @@ +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> +*/ package org.openfast.session; import java.util.HashMap; @@ -33,467 +53,314 @@ import org.openfast.template.type.Type; public class SessionControlProtocol_1_1 extends AbstractSessionControlProtocol { - public static final String NAMESPACE = "http://www.fixprotocol.org/ns/fast/scp/1.1"; + public static final String NAMESPACE = "http://www.fixprotocol.org/ns/fast/scp/1.1"; + private static final QName RESET_PROPERTY = new QName("reset", NAMESPACE); + private static final Map/* <MessageTemplate, SessionMessageHandler> */messageHandlers = new HashMap(); + private ConversionContext initialContext = createInitialContext(); - private static final QName RESET_PROPERTY = new QName("reset", NAMESPACE); - - private static final Map/*<MessageTemplate, SessionMessageHandler>*/ messageHandlers = new HashMap(); - private ConversionContext initialContext = createInitialContext(); - - public SessionControlProtocol_1_1() { - messageHandlers.put(FAST_ALERT_TEMPLATE, ALERT_HANDLER); - messageHandlers.put(TEMPLATE_DEFINITION, new SessionMessageHandler() { - public void handleMessage(Session session, Message message) { - MessageTemplate template = createTemplateFromMessage(message, session.in.getTemplateRegistry()); - session.addDynamicTemplateDefinition(template); - if (message.isDefined("TemplateId")) - session.registerDynamicTemplate(template.getQName(), message.getInt("TemplateId")); - }}); - messageHandlers.put(TEMPLATE_DECLARATION, new SessionMessageHandler() { - public void handleMessage(Session session,... [truncated message content] |
From: <ope...@li...> - 2008-02-22 13:08:55
|
Revision: 136 http://openfast.svn.sourceforge.net/openfast/?rev=136&view=rev Author: jacob_northey Date: 2008-02-22 05:09:00 -0800 (Fri, 22 Feb 2008) Log Message: ----------- Added EBS Decoding Test; Fixed DecimalValue bug Modified Paths: -------------- trunk/src/main/java/org/openfast/DecimalValue.java trunk/src/main/java/org/openfast/codec/FastDecoder.java trunk/src/main/java/org/openfast/debug/BasicDecodeTrace.java trunk/src/main/java/org/openfast/debug/BasicEncodeTrace.java trunk/src/main/java/org/openfast/template/Group.java trunk/src/main/java/org/openfast/template/loader/XMLMessageTemplateLoader.java trunk/src/main/java/org/openfast/template/operator/DeltaIntegerOperatorCodec.java trunk/src/test/java/org/openfast/DecimalValueTest.java trunk/src/test/java/org/openfast/submitted/OpraFeedTest.java trunk/src/test/resources/OPRA/OPRATemplate.xml Added Paths: ----------- trunk/src/test/java/org/openfast/submitted/EbsDecodingErrorTest.java trunk/src/test/resources/EBS/ trunk/src/test/resources/EBS/templates.xml Modified: trunk/src/main/java/org/openfast/DecimalValue.java =================================================================== --- trunk/src/main/java/org/openfast/DecimalValue.java 2008-02-18 19:28:30 UTC (rev 135) +++ trunk/src/main/java/org/openfast/DecimalValue.java 2008-02-22 13:09:00 UTC (rev 136) @@ -134,8 +134,11 @@ return mantissa * ((long) Math.pow(10, exponent)); } + /** + * The double value should be rounded using a given precision by users of this method. + */ public double toDouble() { - return (mantissa * Math.pow(10, exponent)); + return mantissa * Math.pow(10.0, exponent); } public BigDecimal toBigDecimal() { Modified: trunk/src/main/java/org/openfast/codec/FastDecoder.java =================================================================== --- trunk/src/main/java/org/openfast/codec/FastDecoder.java 2008-02-18 19:28:30 UTC (rev 135) +++ trunk/src/main/java/org/openfast/codec/FastDecoder.java 2008-02-22 13:09:00 UTC (rev 136) @@ -17,9 +17,8 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ + */ - package org.openfast.codec; import org.openfast.BitVector; @@ -34,9 +33,9 @@ import java.io.InputStream; - public class FastDecoder implements Coder { private final InputStream in; + private final Context context; public FastDecoder(Context context, InputStream in) { @@ -52,8 +51,8 @@ } BitVector pmap = (bitVectorValue).value; - BitVectorReader presenceMapReader = new BitVectorReader(pmap); - + BitVectorReader presenceMapReader = new BitVectorReader(pmap); + // if template id is not present, use previous, else decode template id int templateId = (presenceMapReader.read()) ? ((IntegerValue) TypeCodec.UINT.decode(in)).value : context.getLastTemplateId(); MessageTemplate template = context.getTemplate(templateId); @@ -64,7 +63,7 @@ context.newMessage(template); context.setLastTemplateId(templateId); - + return template.decode(in, templateId, presenceMapReader, context); } Modified: trunk/src/main/java/org/openfast/debug/BasicDecodeTrace.java =================================================================== --- trunk/src/main/java/org/openfast/debug/BasicDecodeTrace.java 2008-02-18 19:28:30 UTC (rev 135) +++ trunk/src/main/java/org/openfast/debug/BasicDecodeTrace.java 2008-02-22 13:09:00 UTC (rev 136) @@ -1,44 +1,71 @@ +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> + */ package org.openfast.debug; +import java.io.PrintWriter; + import org.openfast.ByteUtil; import org.openfast.FieldValue; import org.openfast.template.Field; import org.openfast.template.Group; public class BasicDecodeTrace implements Trace { - private String indent = ""; + private String indent = ""; + private PrintWriter out = new PrintWriter(System.out); - public void groupStart(Group group) { - print(group); - moveDown(); - } - - private void moveDown() { - indent += " "; - } + public void groupStart(Group group) { + print(group); + moveDown(); + } - private void moveUp() { - indent = indent.substring(0, indent.length()-2); - } + private void moveDown() { + indent += " "; + } - private void print(Object object) { - System.out.print(indent); - System.out.println(object); - } + private void moveUp() { + indent = indent.substring(0, indent.length() - 2); + } - public void groupEnd() { - moveUp(); - } + private void print(Object object) { + out.print(indent); + out.println(object); + } - public void field(Field field, FieldValue value, FieldValue decodedValue, byte[] encoding, int pmapIndex) { - StringBuilder scalarDecode = new StringBuilder(); - scalarDecode.append(field.getName()).append(": "); - scalarDecode.append(ByteUtil.convertByteArrayToBitString(encoding)); - scalarDecode.append(" -> ").append(value).append('(').append(decodedValue).append(')'); - print(scalarDecode); - } + public void groupEnd() { + moveUp(); + } - public void pmap(byte[] bytes) { - print("PMAP: " + ByteUtil.convertByteArrayToBitString(bytes)); - } + public void field(Field field, FieldValue value, FieldValue decodedValue, byte[] encoding, int pmapIndex) { + StringBuilder scalarDecode = new StringBuilder(); + scalarDecode.append(field.getName()).append(": "); + scalarDecode.append(ByteUtil.convertByteArrayToBitString(encoding)); + scalarDecode.append(" -> ").append(value).append('(').append(decodedValue).append(')'); + print(scalarDecode); + } + + public void pmap(byte[] bytes) { + print("PMAP: " + ByteUtil.convertByteArrayToBitString(bytes)); + } + + public void setWriter(PrintWriter traceWriter) { + this.out = traceWriter; + } } Modified: trunk/src/main/java/org/openfast/debug/BasicEncodeTrace.java =================================================================== --- trunk/src/main/java/org/openfast/debug/BasicEncodeTrace.java 2008-02-18 19:28:30 UTC (rev 135) +++ trunk/src/main/java/org/openfast/debug/BasicEncodeTrace.java 2008-02-22 13:09:00 UTC (rev 136) @@ -1,5 +1,26 @@ +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> + */ package org.openfast.debug; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.Stack; @@ -11,105 +32,116 @@ public class BasicEncodeTrace implements Trace { - private Stack stack = new Stack(); + private Stack stack = new Stack(); + private PrintWriter out = new PrintWriter(System.out); - public void groupStart(Group group) { - TraceGroup traceGroup = new TraceGroup(group); - if (!stack.isEmpty()) - ((TraceGroup)stack.peek()).addGroup(traceGroup); - stack.push(traceGroup); - } + public void groupStart(Group group) { + TraceGroup traceGroup = new TraceGroup(group); + if (!stack.isEmpty()) + ((TraceGroup) stack.peek()).addGroup(traceGroup); + stack.push(traceGroup); + } - public void field(Field field, FieldValue value, FieldValue encoded, byte[] encoding, int pmapIndex) { - ((TraceGroup)stack.peek()).addField(field, value, encoded, pmapIndex, encoding); - } + public void field(Field field, FieldValue value, FieldValue encoded, byte[] encoding, int pmapIndex) { + ((TraceGroup) stack.peek()).addField(field, value, encoded, pmapIndex, encoding); + } - public void groupEnd() { - TraceGroup group = (TraceGroup) stack.pop(); - if (stack.isEmpty()) { - System.out.println(group); - } - } + public void groupEnd() { + TraceGroup group = (TraceGroup) stack.pop(); + if (stack.isEmpty()) { + out.println(group); + } + } - public void pmap(byte[] pmap) { - ((TraceGroup)stack.peek()).setPmap(pmap); - } + public void pmap(byte[] pmap) { + ((TraceGroup) stack.peek()).setPmap(pmap); + } - private class TraceGroup implements TraceNode { + private class TraceGroup implements TraceNode { - private List nodes; - private byte[] pmap; - private Group group; + private List nodes; - public TraceGroup(Group group) { - this.group = group; - this.nodes = new ArrayList(group.getFieldCount()); - } + private byte[] pmap; - public void setPmap(byte[] pmap) { - this.pmap = pmap; - } + private Group group; - public void addField(Field field, FieldValue value, FieldValue encoded, int fieldIndex, byte[] encoding) { - nodes.add(new TraceField(field, value, encoded, fieldIndex, encoding)); - } + public TraceGroup(Group group) { + this.group = group; + this.nodes = new ArrayList(group.getFieldCount()); + } - public void addGroup(TraceGroup traceGroup) { - nodes.add(traceGroup); - } + public void setPmap(byte[] pmap) { + this.pmap = pmap; + } - public StringBuilder serialize(StringBuilder builder, int indent) { - builder.append(indent(indent)).append(group.getName()).append("\n"); - indent +=2; - if (pmap != null) - builder.append(indent(indent)).append("PMAP: ").append(ByteUtil.convertByteArrayToBitString(pmap)).append("\n"); - for (int i=0; i<nodes.size(); i++) { - ((TraceNode) nodes.get(i)).serialize(builder, indent); - } - indent -=2; - return builder; - } - - public String toString() { - return serialize(new StringBuilder(), 0).toString(); - } - } - - private class TraceField implements TraceNode { - private Field field; - private int pmapIndex; - private byte[] encoding; - private FieldValue value; - private FieldValue encoded; + public void addField(Field field, FieldValue value, FieldValue encoded, int fieldIndex, byte[] encoding) { + nodes.add(new TraceField(field, value, encoded, fieldIndex, encoding)); + } - public TraceField(Field field, FieldValue value, FieldValue encoded, int pmapIndex, byte[] encoding) { - this.field = field; - this.value = value; - this.encoded = encoded; - this.pmapIndex = pmapIndex; - this.encoding = encoding; - } + public void addGroup(TraceGroup traceGroup) { + nodes.add(traceGroup); + } - public StringBuilder serialize(StringBuilder builder, int indent) { - builder.append(indent(indent)); - builder.append(field.getName()).append("["); - if (field.usesPresenceMapBit()) - builder.append("pmapIndex:").append(pmapIndex); - builder.append("]: ").append(value).append(" = ").append(encoded).append(" -> "); - builder.append(ByteUtil.convertByteArrayToBitString(encoding)); - builder.append("\n"); - return builder; - } - } - - private interface TraceNode { - StringBuilder serialize(StringBuilder builder, int indent); - } + public StringBuilder serialize(StringBuilder builder, int indent) { + builder.append(indent(indent)).append(group.getName()).append("\n"); + indent += 2; + if (pmap != null) + builder.append(indent(indent)).append("PMAP: ").append(ByteUtil.convertByteArrayToBitString(pmap)).append("\n"); + for (int i = 0; i < nodes.size(); i++) { + ((TraceNode) nodes.get(i)).serialize(builder, indent); + } + indent -= 2; + return builder; + } - public String indent(int indent) { - String tab = ""; - for (int i=0; i<indent; i++) - tab += " "; - return tab; - } + public String toString() { + return serialize(new StringBuilder(), 0).toString(); + } + } + + private class TraceField implements TraceNode { + private Field field; + + private int pmapIndex; + + private byte[] encoding; + + private FieldValue value; + + private FieldValue encoded; + + public TraceField(Field field, FieldValue value, FieldValue encoded, int pmapIndex, byte[] encoding) { + this.field = field; + this.value = value; + this.encoded = encoded; + this.pmapIndex = pmapIndex; + this.encoding = encoding; + } + + public StringBuilder serialize(StringBuilder builder, int indent) { + builder.append(indent(indent)); + builder.append(field.getName()).append("["); + if (field.usesPresenceMapBit()) + builder.append("pmapIndex:").append(pmapIndex); + builder.append("]: ").append(value).append(" = ").append(encoded).append(" -> "); + builder.append(ByteUtil.convertByteArrayToBitString(encoding)); + builder.append("\n"); + return builder; + } + } + + private interface TraceNode { + StringBuilder serialize(StringBuilder builder, int indent); + } + + public String indent(int indent) { + String tab = ""; + for (int i = 0; i < indent; i++) + tab += " "; + return tab; + } + + public void setWriter(PrintWriter traceWriter) { + this.out = traceWriter; + } } Modified: trunk/src/main/java/org/openfast/template/Group.java =================================================================== --- trunk/src/main/java/org/openfast/template/Group.java 2008-02-18 19:28:30 UTC (rev 135) +++ trunk/src/main/java/org/openfast/template/Group.java 2008-02-22 13:09:00 UTC (rev 136) @@ -17,9 +17,8 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ + */ - package org.openfast.template; import java.io.ByteArrayOutputStream; @@ -44,39 +43,46 @@ import org.openfast.error.FastException; import org.openfast.template.type.codec.TypeCodec; - public class Group extends Field { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - - private QName typeReference = null; - protected String childNamespace = ""; + private QName typeReference = null; + + protected String childNamespace = ""; + protected final Field[] fields; + protected final Map fieldIndexMap; + protected final Map fieldIdMap; + protected final Map fieldNameMap; + protected final boolean usesPresenceMap; - protected final StaticTemplateReference[] staticTemplateReferences; - protected final Field[] fieldDefinitions; - protected final Map introspectiveFieldMap; + protected final StaticTemplateReference[] staticTemplateReferences; + + protected final Field[] fieldDefinitions; + + protected final Map introspectiveFieldMap; + public Group(String name, Field[] fields, boolean optional) { - this(new QName(name), fields, optional); + this(new QName(name), fields, optional); } public Group(QName name, Field[] fields, boolean optional) { super(name, optional); List expandedFields = new ArrayList(); List staticTemplateReferences = new ArrayList(); - for (int i=0; i<fields.length; i++) { - if (fields[i] instanceof StaticTemplateReference) { - Field[] referenceFields = ((StaticTemplateReference) fields[i]).getTemplate().getFields(); - for (int j=1; j<referenceFields.length; j++) - expandedFields.add(referenceFields[j]); - staticTemplateReferences.add(fields[i]); - } else { - expandedFields.add(fields[i]); - } + for (int i = 0; i < fields.length; i++) { + if (fields[i] instanceof StaticTemplateReference) { + Field[] referenceFields = ((StaticTemplateReference) fields[i]).getTemplate().getFields(); + for (int j = 1; j < referenceFields.length; j++) + expandedFields.add(referenceFields[j]); + staticTemplateReferences.add(fields[i]); + } else { + expandedFields.add(fields[i]); + } } this.fields = (Field[]) expandedFields.toArray(new Field[expandedFields.size()]); this.fieldDefinitions = fields; @@ -85,75 +91,91 @@ this.fieldIdMap = constructFieldIdMap(this.fields); this.introspectiveFieldMap = constructInstrospectiveFields(this.fields); this.usesPresenceMap = determinePresenceMapUsage(this.fields); - this.staticTemplateReferences = (StaticTemplateReference[]) staticTemplateReferences.toArray(new StaticTemplateReference[staticTemplateReferences.size()]); + this.staticTemplateReferences = (StaticTemplateReference[]) staticTemplateReferences + .toArray(new StaticTemplateReference[staticTemplateReferences.size()]); } - + // BAD ABSTRACTION private static Map constructInstrospectiveFields(Field[] fields) { - Map map = new HashMap(); - for (int i=0; i<fields.length; i++) { - if (fields[i] instanceof Scalar) { - if (fields[i].hasAttribute(FastConstants.LENGTH_FIELD)) { - map.put(fields[i].getAttribute(FastConstants.LENGTH_FIELD), fields[i]); - } - } - } - if (map.size() == 0) - return Collections.EMPTY_MAP; - return map; - } + Map map = new HashMap(); + for (int i = 0; i < fields.length; i++) { + if (fields[i] instanceof Scalar) { + if (fields[i].hasAttribute(FastConstants.LENGTH_FIELD)) { + map.put(fields[i].getAttribute(FastConstants.LENGTH_FIELD), fields[i]); + } + } + } + if (map.size() == 0) + return Collections.EMPTY_MAP; + return map; + } - /** - * Check to see if the passed field array has a Field that has a MapBit present - * @param fields The Field object array to be checked - * @return Returns true if a Field object has a MapBit present, false otherwise + /** + * Check to see if the passed field array has a Field that has a MapBit + * present + * + * @param fields + * The Field object array to be checked + * @return Returns true if a Field object has a MapBit present, false + * otherwise */ private static boolean determinePresenceMapUsage(Field[] fields) { - for (int i=0; i<fields.length; i++) - if (fields[i].usesPresenceMapBit()) - return true; - return false; - } + for (int i = 0; i < fields.length; i++) + if (fields[i].usesPresenceMapBit()) + return true; + return false; + } - /** - * If your FieldValue already has a BitVector, use this encode method. - * The MapBuilder index is kept track of and stored through this process. - * The supplied data is stored to a byte buffer array and returned. - * @param value The value of the FieldValue to be encoded - * @param template The Group object to be encoded - * @param context The previous object to keep the data in sync - * @param presenceMapBuilder The BitVector object that will be used to encode. - * @return Returns the encoded byte array + /** + * If your FieldValue already has a BitVector, use this encode method. The + * MapBuilder index is kept track of and stored through this process. The + * supplied data is stored to a byte buffer array and returned. + * + * @param value + * The value of the FieldValue to be encoded + * @param template + * The Group object to be encoded + * @param context + * The previous object to keep the data in sync + * @param presenceMapBuilder + * The BitVector object that will be used to encode. + * @return Returns the encoded byte array */ - public byte[] encode(FieldValue value, Group template, Context context, BitVectorBuilder presenceMapBuilder) { - byte[] encoding = encode(value, template, context); - if (optional) { - if (encoding.length != 0) - presenceMapBuilder.set(); - else - presenceMapBuilder.skip(); - } - return encoding; - } - + public byte[] encode(FieldValue value, Group template, Context context, BitVectorBuilder presenceMapBuilder) { + byte[] encoding = encode(value, template, context); + if (optional) { + if (encoding.length != 0) + presenceMapBuilder.set(); + else + presenceMapBuilder.skip(); + } + return encoding; + } + /** - * If there is no BitVector, this encoding method will create one. The supplied data is stored to a byte buffer array and returned. - * The MapBuilder index is kept track of and stored through this process. - * @param value The value of the FieldValue to be encoded - * @param template The Group object to be encoded - * @param context The previous object to keep the data in sync - * @return Returns an new byte array if there are no FieldValue to encode, otherwise returns the buffer to the - * byte array that the data was stored to + * If there is no BitVector, this encoding method will create one. The + * supplied data is stored to a byte buffer array and returned. The + * MapBuilder index is kept track of and stored through this process. + * + * @param value + * The value of the FieldValue to be encoded + * @param template + * The Group object to be encoded + * @param context + * The previous object to keep the data in sync + * @return Returns an new byte array if there are no FieldValue to encode, + * otherwise returns the buffer to the byte array that the data was + * stored to */ public byte[] encode(FieldValue value, Group template, Context context) { if (value == null) { - return new byte[] { }; + return new byte[] {}; } GroupValue groupValue = (GroupValue) value; - if (context.isTraceEnabled()) { - context.getEncodeTrace().groupStart(this); - } + if (context.isTraceEnabled()) { + context.getEncodeTrace().groupStart(this); + } BitVectorBuilder presenceMapBuilder = new BitVectorBuilder(fields.length); try { byte[][] fieldEncodings = new byte[fields.length][]; @@ -162,110 +184,133 @@ FieldValue fieldValue = groupValue.getValue(fieldIndex); Field field = getField(fieldIndex); if (!field.isOptional() && fieldValue == null) - Global.handleError(FastConstants.GENERAL_ERROR, "Mandatory field " + field + " is null"); + Global.handleError(FastConstants.GENERAL_ERROR, "Mandatory field " + field + " is null"); byte[] encoding = field.encode(fieldValue, template, context, presenceMapBuilder); fieldEncodings[fieldIndex] = encoding; } ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - + if (usesPresenceMap()) { - byte[] pmap = presenceMapBuilder.getBitVector().getTruncatedBytes(); - if (context.isTraceEnabled()) - context.getEncodeTrace().pmap(pmap); - buffer.write(pmap); - } + byte[] pmap = presenceMapBuilder.getBitVector().getTruncatedBytes(); + if (context.isTraceEnabled()) + context.getEncodeTrace().pmap(pmap); + buffer.write(pmap); + } for (int i = 0; i < fieldEncodings.length; i++) { if (fieldEncodings[i] != null) { buffer.write(fieldEncodings[i]); } } if (context.isTraceEnabled()) - context.getEncodeTrace().groupEnd(); + context.getEncodeTrace().groupEnd(); return buffer.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } } - + /** * - * @param in The InputStream to be decoded - * @param group The Group object to be decoded - * @param context The previous object to keep the data in sync + * @param in + * The InputStream to be decoded + * @param group + * The Group object to be decoded + * @param context + * The previous object to keep the data in sync * @param present * @return Returns a new GroupValue */ public FieldValue decode(InputStream in, Group group, Context context, BitVectorReader pmapReader) { - try { - if (!usesPresenceMapBit() || pmapReader.read()) { - if (context.isTraceEnabled()) { - context.getDecodeTrace().groupStart(this); - } - GroupValue groupValue = new GroupValue(this, decodeFieldValues(in, group, context)); - if (context.isTraceEnabled()) - context.getDecodeTrace().groupEnd(); - return groupValue; - } else - return null; - } catch (FastException e) { - throw new FastException("Error occurred while decoding " + this, e.getCode(), e); - } + try { + if (!usesPresenceMapBit() || pmapReader.read()) { + if (context.isTraceEnabled()) { + context.getDecodeTrace().groupStart(this); + } + GroupValue groupValue = new GroupValue(this, decodeFieldValues(in, group, context)); + if (context.isTraceEnabled()) + context.getDecodeTrace().groupEnd(); + return groupValue; + } else + return null; + } catch (FastException e) { + throw new FastException("Error occurred while decoding " + this, e.getCode(), e); + } } /** - * If there is not a vector map created for the inputStream, a vector map will be created to pass to the public - * decodeFieldValues method. - * @param in The InputStream to be decoded - * @param template The Group object to be decoded - * @param context The previous object to keep the data in sync - * @return Returns the FieldValue array of the decoded field values passed to it + * If there is not a vector map created for the inputStream, a vector map + * will be created to pass to the public decodeFieldValues method. * + * @param in + * The InputStream to be decoded + * @param template + * The Group object to be decoded + * @param context + * The previous object to keep the data in sync + * @return Returns the FieldValue array of the decoded field values passed + * to it + * */ protected FieldValue[] decodeFieldValues(InputStream in, Group template, Context context) { - if (usesPresenceMap()) { - BitVector pmap = ((BitVectorValue) TypeCodec.BIT_VECTOR.decode(in)).value; - if (context.isTraceEnabled()) - context.getDecodeTrace().pmap(pmap.getBytes()); - if (pmap.isOverlong()) - Global.handleError(FastConstants.R7_PMAP_OVERLONG, "The presence map " + pmap + " for the group " + this + " is overlong."); - return decodeFieldValues(in, template, new BitVectorReader(pmap), context); - } else { - return decodeFieldValues(in, template, BitVectorReader.NULL, context); - } + if (usesPresenceMap()) { + BitVector pmap = ((BitVectorValue) TypeCodec.BIT_VECTOR.decode(in)).value; + if (context.isTraceEnabled()) + context.getDecodeTrace().pmap(pmap.getBytes()); + if (pmap.isOverlong()) + Global.handleError(FastConstants.R7_PMAP_OVERLONG, "The presence map " + pmap + " for the group " + this + + " is overlong."); + return decodeFieldValues(in, template, new BitVectorReader(pmap), context); + } else { + return decodeFieldValues(in, template, BitVectorReader.NULL, context); + } } - /** - * Goes through the all the field value array, starting with the index passed, checks to see if a map actually created for the field to pass - * to the decoder - the field index is created as a new Group object and stored to the the FieldValue array. Once all the field values have - * beed gone through, the method returns. - * @param in The InputStream to be decoded - * @param template The Group object - * @param pmap The BitVector to be decoded - * @param context The previous object to keep the data in sync - * @param start The index of the Field to start decoding from - * @return Returns a FieldValue array of the decoded field values passed to it. - * @throws Throws RuntimeException if there is an problem in the decoding - * + /** + * Goes through the all the field value array, starting with the index + * passed, checks to see if a map actually created for the field to pass to + * the decoder - the field index is created as a new Group object and stored + * to the the FieldValue array. Once all the field values have beed gone + * through, the method returns. + * + * @param in + * The InputStream to be decoded + * @param template + * The Group object + * @param pmap + * The BitVector to be decoded + * @param context + * The previous object to keep the data in sync + * @param start + * The index of the Field to start decoding from + * @return Returns a FieldValue array of the decoded field values passed to + * it. + * @throws Throws + * RuntimeException if there is an problem in the decoding + * */ public FieldValue[] decodeFieldValues(InputStream in, Group template, BitVectorReader pmapReader, Context context) { FieldValue[] values = new FieldValue[fields.length]; int start = this instanceof MessageTemplate ? 1 : 0; for (int fieldIndex = start; fieldIndex < fields.length; fieldIndex++) { Field field = getField(fieldIndex); - values[fieldIndex] = field.decode(in, template, context, pmapReader); + values[fieldIndex] = field.decode(in, template, context, pmapReader); } if (pmapReader.hasMoreBitsSet()) - Global.handleError(FastConstants.R8_PMAP_TOO_MANY_BITS, "The presence map " + pmapReader + " has too many bits for the group " + this); - + Global.handleError(FastConstants.R8_PMAP_TOO_MANY_BITS, "The presence map " + pmapReader + + " has too many bits for the group " + this); + return values; } /** * Determine if there is a Map of the passed byte array and fieldValue - * @param encoding The byte array to be checked - * @param fieldValue The fieldValue to be checked - * @return Returns true if there is a PrecenceMapBit of the specified - * byte array and field, false otherwise + * + * @param encoding + * The byte array to be checked + * @param fieldValue + * The fieldValue to be checked + * @return Returns true if there is a PrecenceMapBit of the specified byte + * array and field, false otherwise */ public boolean isPresenceMapBitSet(byte[] encoding, FieldValue fieldValue) { return encoding.length != 0; @@ -277,13 +322,14 @@ public boolean usesPresenceMapBit() { return optional; } - + public boolean usesPresenceMap() { - return usesPresenceMap; + return usesPresenceMap; } - + /** * Find the number of total fields + * * @return Returns the number of fields */ public int getFieldCount() { @@ -292,8 +338,10 @@ /** * Find the field object of the index passed - * @param index The index within the field that is being searched for - * @return Returns a field object of the specified index + * + * @param index + * The index within the field that is being searched for + * @return Returns a field object of the specified index */ public Field getField(int index) { return fields[index]; @@ -307,7 +355,8 @@ } /** - * @param value The value that the fieldValue that is to be created + * @param value + * The value that the fieldValue that is to be created * @return Returns a new GroupValue */ public FieldValue createValue(String value) { @@ -323,20 +372,26 @@ /** * Find the field object of the passed field name - * @param fieldName The field name of the field object that is to be returned + * + * @param fieldName + * The field name of the field object that is to be returned * @return Returns the field object of the passed field name */ public Field getField(String fieldName) { return (Field) fieldNameMap.get(new QName(fieldName, childNamespace)); } - - public Field getField(QName name) { - return (Field) fieldNameMap.get(name); - } + public Field getField(QName name) { + return (Field) fieldNameMap.get(name); + } + /** - * Creates a map of the passed field array by the field name and the field index number - * @param fields The name of the field array that is going to be placed into a new map object + * Creates a map of the passed field array by the field name and the field + * index number + * + * @param fields + * The name of the field array that is going to be placed into a + * new map object * @return Returns a map object of the field array passed to it */ private static Map constructFieldNameMap(Field[] fields) { @@ -347,7 +402,7 @@ return map; } - + private static Map constructFieldIdMap(Field[] fields) { Map map = new HashMap(); @@ -355,11 +410,15 @@ map.put(fields[i].getId(), fields[i]); return map; - } + } /** - * Creates a map of the passed field array by the field index number, numbered 0 to n - * @param fields The name of the field array that is going to be placed into a new map object + * Creates a map of the passed field array by the field index number, + * numbered 0 to n + * + * @param fields + * The name of the field array that is going to be placed into a + * new map object * @return Returns a map object of the field array passed to it */ private static Map constructFieldIndexMap(Field[] fields) { @@ -373,20 +432,24 @@ /** * Find the index of the passed field name as an integer - * @param fieldName The field name that is being searched for + * + * @param fieldName + * The field name that is being searched for * @return Returns an integer of the field index of the specified field name */ public int getFieldIndex(String fieldName) { return ((Integer) fieldIndexMap.get(getField(fieldName))).intValue(); } - public int getFieldIndex(Field field) { - return ((Integer)fieldIndexMap.get(field)).intValue(); - } + public int getFieldIndex(Field field) { + return ((Integer) fieldIndexMap.get(field)).intValue(); + } /** * Get the Sequence of the passed fieldName - * @param fieldName The field name that is being searched for + * + * @param fieldName + * The field name that is being searched for * @return Returns a sequence object of the specified fieldName */ public Sequence getSequence(String fieldName) { @@ -395,20 +458,24 @@ /** * Get the Scalar Value of the passed fieldName - * @param fieldName The field name that is being searched for + * + * @param fieldName + * The field name that is being searched for * @return Returns a Scalar value of the specified fieldName */ public Scalar getScalar(String fieldName) { return (Scalar) getField(fieldName); } - public Scalar getScalar(int index) { - return (Scalar) getField(index); - } + public Scalar getScalar(int index) { + return (Scalar) getField(index); + } /** * Find the group with the passed fieldName - * @param fieldName The field name that is being searched for + * + * @param fieldName + * The field name that is being searched for * @return Returns a Group object of the specified field name */ public Group getGroup(String fieldName) { @@ -416,20 +483,23 @@ } /** - * Determine if the map has a specified field name. - * @param fieldName The name of the fieldName that is being searched for - * @return Returns true if there is the field name that was passed in the Map, false otherwise + * Determine if the map has a specified field name. + * + * @param fieldName + * The name of the fieldName that is being searched for + * @return Returns true if there is the field name that was passed in the + * Map, false otherwise */ public boolean hasField(String fieldName) { return fieldNameMap.containsKey(new QName(fieldName, childNamespace)); } - + public boolean hasField(QName fieldName) { - return fieldNameMap.containsKey(fieldName); + return fieldNameMap.containsKey(fieldName); } /** - * + * * @return Returns an array of Fields */ public Field[] getFields() { @@ -438,12 +508,14 @@ /** * Set the name of the type referenced by this group - * @param typeReference The name of the application type referenced by this goup + * + * @param typeReference + * The name of the application type referenced by this goup */ public void setTypeReference(QName typeReference) { this.typeReference = typeReference; } - + /** * * @return Returns the application type referenced by this group @@ -451,90 +523,95 @@ public QName getTypeReference() { return typeReference; } - + /** * @return Returns true if the type has a reference, false otherwise */ public boolean hasTypeReference() { - return typeReference != null; + return typeReference != null; } - + public String toString() { - return name.getName(); + return name.getName(); } - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + Group.hashCode(fields); - result = prime * result + name.hashCode(); - result = prime * result + ((typeReference == null) ? 0 : typeReference.hashCode()); - return result; - } + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Group.hashCode(fields); + result = prime * result + name.hashCode(); + result = prime * result + ((typeReference == null) ? 0 : typeReference.hashCode()); + return result; + } - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - final Group other = (Group) obj; - if (other.fields.length != fields.length) return false; - if (!other.name.equals(name)) return false; - for (int i=0; i<fields.length; i++) - if (!fields[i].equals(other.fields[i])) return false; - return true; - } - + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + final Group other = (Group) obj; + if (other.fields.length != fields.length) + return false; + if (!other.name.equals(name)) + return false; + for (int i = 0; i < fields.length; i++) + if (!fields[i].equals(other.fields[i])) + return false; + return true; + } + private static int hashCode(Object[] array) { - final int prime = 31; - if (array == null) - return 0; - int result = 1; - for (int index = 0; index < array.length; index++) { - result = prime * result + (array[index] == null ? 0 : array[index].hashCode()); - } - return result; - } + final int prime = 31; + if (array == null) + return 0; + int result = 1; + for (int index = 0; index < array.length; index++) { + result = prime * result + (array[index] == null ? 0 : array[index].hashCode()); + } + return result; + } - public boolean hasFieldWithId(String id) { - return fieldIdMap.containsKey(id); - } + public boolean hasFieldWithId(String id) { + return fieldIdMap.containsKey(id); + } - public Field getFieldById(String id) { - return (Field) fieldIdMap.get(id); - } + public Field getFieldById(String id) { + return (Field) fieldIdMap.get(id); + } - public String getChildNamespace() { - return childNamespace; - } + public String getChildNamespace() { + return childNamespace; + } - public void setChildNamespace(String childNamespace) { - this.childNamespace = childNamespace; - } + public void setChildNamespace(String childNamespace) { + this.childNamespace = childNamespace; + } - public StaticTemplateReference[] getStaticTemplateReferences() { - return staticTemplateReferences; - } - - public StaticTemplateReference getStaticTemplateReference(String name) { - return getStaticTemplateReference(new QName(name, this.name.getNamespace())); - } - - public StaticTemplateReference getStaticTemplateReference(QName name) { - for (int i=0; i<staticTemplateReferences.length; i++) { - if (staticTemplateReferences[i].getQName().equals(name)) - return staticTemplateReferences[i]; - } - return null; - } + public StaticTemplateReference[] getStaticTemplateReferences() { + return staticTemplateReferences; + } - public Field[] getFieldDefinitions() { - return fieldDefinitions; - } + public StaticTemplateReference getStaticTemplateReference(String name) { + return getStaticTemplateReference(new QName(name, this.name.getNamespace())); + } - public boolean hasIntrospectiveField(String fieldName) { - return introspectiveFieldMap.containsKey(fieldName); - } + public StaticTemplateReference getStaticTemplateReference(QName name) { + for (int i = 0; i < staticTemplateReferences.length; i++) { + if (staticTemplateReferences[i].getQName().equals(name)) + return staticTemplateReferences[i]; + } + return null; + } - public Scalar getIntrospectiveField(String fieldName) { - return (Scalar) introspectiveFieldMap.get(fieldName); - } + public Field[] getFieldDefinitions() { + return fieldDefinitions; + } + + public boolean hasIntrospectiveField(String fieldName) { + return introspectiveFieldMap.containsKey(fieldName); + } + + public Scalar getIntrospectiveField(String fieldName) { + return (Scalar) introspectiveFieldMap.get(fieldName); + } } Modified: trunk/src/main/java/org/openfast/template/loader/XMLMessageTemplateLoader.java =================================================================== --- trunk/src/main/java/org/openfast/template/loader/XMLMessageTemplateLoader.java 2008-02-18 19:28:30 UTC (rev 135) +++ trunk/src/main/java/org/openfast/template/loader/XMLMessageTemplateLoader.java 2008-02-22 13:09:00 UTC (rev 136) @@ -17,9 +17,8 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ + */ - package org.openfast.template.loader; import java.io.IOException; @@ -45,113 +44,127 @@ import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; - public class XMLMessageTemplateLoader implements MessageTemplateLoader { static final String TEMPLATE_DEFINITION_NS = "http://www.fixprotocol.org/ns/fast/td/1.1"; static final ErrorCode IO_ERROR = new ErrorCode(FastConstants.STATIC, -1, "IOERROR", "IO Error", FastAlertSeverity.ERROR); - static final ErrorCode XML_PARSING_ERROR = new ErrorCode(FastConstants.STATIC, -1, "XMLPARSEERR", "XML Parsing Error", FastAlertSeverity.ERROR); - static final ErrorCode INVALID_TYPE = new ErrorCode(FastConstants.STATIC, -1, "INVALIDTYPE", "Invalid Type", FastAlertSeverity.ERROR); - + + static final ErrorCode XML_PARSING_ERROR = new ErrorCode(FastConstants.STATIC, -1, "XMLPARSEERR", "XML Parsing Error", + FastAlertSeverity.ERROR); + + static final ErrorCode INVALID_TYPE = new ErrorCode(FastConstants.STATIC, -1, "INVALIDTYPE", "Invalid Type", + FastAlertSeverity.ERROR); + // IMMUTABLE - private final boolean namespaceAwareness; - private final ParsingContext initialContext; + private final boolean namespaceAwareness; - private boolean loadTemplateIdFromAuxId; + private final ParsingContext initialContext; - public XMLMessageTemplateLoader() { - this(false); - } - + private boolean loadTemplateIdFromAuxId; + + public XMLMessageTemplateLoader() { + this(false); + } + public XMLMessageTemplateLoader(boolean namespaceAwareness) { - this.namespaceAwareness = namespaceAwareness; - this.initialContext = createInitialContext(); + this.namespaceAwareness = namespaceAwareness; + this.initialContext = createInitialContext(); } - public static ParsingContext createInitialContext() { - ParsingContext initialContext = new ParsingContext(); - initialContext.setErrorHandler(ErrorHandler.DEFAULT); - initialContext.setTemplateRegistry(new BasicTemplateRegistry()); - initialContext.setTypeMap(Type.getRegisteredTypeMap()); - initialContext.setFieldParsers(new ArrayList()); - initialContext.addFieldParser(new ScalarParser()); - initialContext.addFieldParser(new GroupParser()); - initialContext.addFieldParser(new SequenceParser()); - initialContext.addFieldParser(new ComposedDecimalParser()); - initialContext.addFieldParser(new StringParser()); - initialContext.addFieldParser(new ByteVectorParser()); - initialContext.addFieldParser(new TemplateRefParser()); - return initialContext; - } + public static ParsingContext createInitialContext() { + ParsingContext initialContext = new ParsingContext(); + initialContext.setErrorHandler(ErrorHandler.DEFAULT); + initialContext.setTemplateRegistry(new BasicTemplateRegistry()); + initialContext.setTypeMap(Type.getRegisteredTypeMap()); + initialContext.setFieldParsers(new ArrayList()); + initialContext.addFieldParser(new ScalarParser()); + initialContext.addFieldParser(new GroupParser()); + initialContext.addFieldParser(new SequenceParser()); + initialContext.addFieldParser(new ComposedDecimalParser()); + initialContext.addFieldParser(new StringParser()); + initialContext.addFieldParser(new ByteVectorParser()); + initialContext.addFieldParser(new TemplateRefParser()); + return initialContext; + } - public void addFieldParser(FieldParser fieldParser) { - initialContext.getFieldParsers().add(fieldParser); - } - - /** + public void addFieldParser(FieldParser fieldParser) { + initialContext.getFieldParsers().add(fieldParser); + } + + /** * Parses the XML stream and creates an array of the elements - * @param source The inputStream object to load + * + * @param source + * The inputStream object to load */ public MessageTemplate[] load(InputStream source) { Document document = parseXml(source); if (document == null) { - return new MessageTemplate[] { }; + return new MessageTemplate[] {}; } Element root = document.getDocumentElement(); - + TemplateParser templateParser = new TemplateParser(loadTemplateIdFromAuxId); - - if (root.getNodeName().equals("template")) { - return new MessageTemplate[] { (MessageTemplate) templateParser.parse(root, initialContext) }; + + if (root.getNodeName().equals("template")) { + return new MessageTemplate[] { (MessageTemplate) templateParser.parse(root, initialContext) }; } else if (root.getNodeName().equals("templates")) { - ParsingContext context = new ParsingContext(root, initialContext); - - NodeList templateTags = root.getElementsByTagName("template"); - MessageTemplate[] templates = new MessageTemplate[templateTags.getLength()]; - for (int i = 0; i < templateTags.getLength(); i++) { - Element templateTag = (Element) templateTags.item(i); - templates[i] = (MessageTemplate) templateParser.parse(templateTag, context); - } - return templates; + ParsingContext context = new ParsingContext(root, initialContext); + + NodeList templateTags = root.getElementsByTagName("template"); + MessageTemplate[] templates = new MessageTemplate[templateTags.getLength()]; + for (int i = 0; i < templateTags.getLength(); i++) { + Element templateTag = (Element) templateTags.item(i); + templates[i] = (MessageTemplate) templateParser.parse(templateTag, context); + } + return templates; } else { - initialContext.getErrorHandler().error(FastConstants.S1_INVALID_XML, "Invalid root node " + root.getNodeName() + ", \"template\" or \"templates\" expected."); - return new MessageTemplate[] {}; + initialContext.getErrorHandler().error(FastConstants.S1_INVALID_XML, + "Invalid root node " + root.getNodeName() + ", \"template\" or \"templates\" expected."); + return new MessageTemplate[] {}; } } /** - * Parse an XML file from an inputStream, returns a DOM org.w3c.dom.Document object. - * @param templateStream The inputStream to be parsed - * @return Returns a DOM org.w3c.dom.Document object, returns null if there are exceptions caught + * Parse an XML file from an inputStream, returns a DOM org.w3c.dom.Document + * object. + * + * @param templateStream + * The inputStream to be parsed + * @return Returns a DOM org.w3c.dom.Document object, returns null if there + * are exceptions caught */ private Document parseXml(InputStream templateStream) { - org.xml.sax.ErrorHandler errorHandler = new org.xml.sax.ErrorHandler() { - public void error(SAXParseException exception) throws SAXException { - initialContext.getErrorHandler().error(XML_PARSING_ERROR, "ERROR: " + exception.getMessage(), exception); - } - public void fatalError(SAXParseException exception) throws SAXException { - initialContext.getErrorHandler().error(XML_PARSING_ERROR, "FATAL: " + exception.getMessage(), exception); - } - public void warning(SAXParseException exception) throws SAXException { - initialContext.getErrorHandler().error(XML_PARSING_ERROR, "WARNING: " + exception.getMessage(), exception); - }}; + org.xml.sax.ErrorHandler errorHandler = new org.xml.sax.ErrorHandler() { + public void error(SAXParseException exception) throws SAXException { + initialContext.getErrorHandler().error(XML_PARSING_ERROR, "ERROR: " + exception.getMessage(), exception); + } + + public void fatalError(SAXParseException exception) throws SAXException { + initialContext.getErrorHandler().error(XML_PARSING_ERROR, "FATAL: " + exception.getMessage(), exception); + } + + public void warning(SAXParseException exception) throws SAXException { + initialContext.getErrorHandler().error(XML_PARSING_ERROR, "WARNING: " + exception.getMessage(), exception); + } + }; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setIgnoringElementContentWhitespace(true); dbf.setNamespaceAware(namespaceAwareness); DocumentBuilder builder = dbf.newDocumentBuilder(); - - builder.setErrorHandler(errorHandler); + + builder.setErrorHandler(errorHandler); InputSource inputSource = new InputSource(templateStream); - Document document = builder.parse(inputSource); - return document; + Document document = builder.parse(inputSource); + return document; } catch (IOException e) { - initialContext.getErrorHandler().error(IO_ERROR, - "Error occurred while trying to read xml template: " + e.getMessage(), e); + initialContext.getErrorHandler().error(IO_ERROR, "Error occurred while trying to read xml template: " + e.getMessage(), e); } catch (Exception e) { - initialContext.getErrorHandler().error(XML_PARSING_ERROR, "Error occurred while parsing xml template: " + e.getMessage(), e); + initialContext.getErrorHandler().error(XML_PARSING_ERROR, "Error occurred while parsing xml template: " + e.getMessage(), + e); } return null; @@ -159,25 +172,27 @@ /** * Sets the errorHandler object to a method - * @param errorHandler The errorHandler that is being set + * + * @param errorHandler + * The errorHandler that is being set */ public void setErrorHandler(ErrorHandler errorHandler) { initialContext.setErrorHandler(errorHandler); } - public void setTemplateRegistry(TemplateRegistry templateRegistry) { - initialContext.setTemplateRegistry(templateRegistry); - } + public void setTemplateRegistry(TemplateRegistry templateRegistry) { + initialContext.setTemplateRegistry(templateRegistry); + } - public TemplateRegistry getTemplateRegistry() { - return initialContext.getTemplateRegistry(); - } - - public void setTypeMap(Map typeMap) { - initialContext.setTypeMap(typeMap); - } + public TemplateRegistry getTemplateRegistry() { + return initialContext.getTemplateRegistry(); + } - public void setLoadTemplateIdFromAuxId(boolean loadTempalteIdFromAuxId) { - this.loadTemplateIdFromAuxId = loadTempalteIdFromAuxId; - } + public void setTypeMap(Map typeMap) { + initialContext.setTypeMap(typeMap); + } + + public void setLoadTemplateIdFromAuxId(boolean loadTempalteIdFromAuxId) { + this.loadTemplateIdFromAuxId = loadTempalteIdFromAuxId; + } } Modified: trunk/src/main/java/org/openfast/template/operator/DeltaIntegerOperatorCodec.java =================================================================== --- trunk/src/main/java/org/openfast/template/operator/DeltaIntegerOperatorCodec.java 2008-02-18 19:28:30 UTC (rev 135) +++ trunk/src/main/java/org/openfast/template/operator/DeltaIntegerOperatorCodec.java 2008-02-22 13:09:00 UTC (rev 136) @@ -1,5 +1,22 @@ -/** - * +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> */ package org.openfast.template.operator; @@ -11,76 +28,71 @@ import org.openfast.template.type.Type; final class DeltaIntegerOperatorCodec extends AlwaysPresentOperatorCodec { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - DeltaIntegerOperatorCodec(Operator operator, Type[] types) { - super(operator, types); - } + DeltaIntegerOperatorCodec(Operator operator, Type[] types) { + super(operator, types); + } - public ScalarValue getValueToEncode(ScalarValue value, - ScalarValue priorValue, Scalar field) { - if (priorValue == null) { - Global.handleError(FastConstants.D6_MNDTRY_FIELD_NOT_PRESENT, "The field " + field + " must have a priorValue defined."); - return null; - } - - if (value == null) { - if (field.isOptional()) { - return ScalarValue.NULL; - } else { - throw new IllegalArgumentException( - "Mandatory fields can't be null."); - } - } - - if (priorValue.isUndefined()) { - priorValue = field.getBaseValue(); - } - - return ((NumericValue) value).subtract((NumericValue) priorValue); - } + public ScalarValue getValueToEncode(ScalarValue value, ScalarValue priorValue, Scalar field) { + if (priorValue == null) { + Global.handleError(FastConstants.D6_MNDTRY_FIELD_NOT_PRESENT, "The field " + field + " must have a priorValue defined."); + return null; + } - public ScalarValue decodeValue(ScalarValue newValue, - ScalarValue previousValue, Scalar field) { - if (previousValue == null) { - Global.handleError(FastConstants.D6_MNDTRY_FIELD_NOT_PRESENT, "The field " + field + " must have a priorValue defined."); - return null; - } - - if ((newValue == null) || newValue.isNull()) { - return null; - } - - if (previousValue.isUndefined()) { - if (field.getDefaultValue().isUndefined()) { - previousValue = field.getBaseValue(); - } else { - previousValue = field.getDefaultValue(); - } - } - - return ((NumericValue) newValue).add((NumericValue) previousValue); - } + if (value == null) { + if (field.isOptional()) { + return ScalarValue.NULL; + } else { + throw new IllegalArgumentException("Mandatory fields can't be null."); + } + } - public ScalarValue decodeEmptyValue(ScalarValue previousValue, - Scalar field) { - if (previousValue.isUndefined()) { - if (field.getDefaultValue().isUndefined()) { - if (field.isOptional()) { - return ScalarValue.UNDEFINED; - } else { - Global.handleError(FastConstants.D5_NO_DEFAULT_VALUE, - ""); - } - } else { - return field.getDefaultValue(); - } - } - - return previousValue; - } + if (priorValue.isUndefined()) { + priorValue = field.getBaseValue(); + } - public boolean equa... [truncated message content] |
From: <ope...@li...> - 2008-02-18 19:28:30
|
Revision: 135 http://openfast.svn.sourceforge.net/openfast/?rev=135&view=rev Author: jacob_northey Date: 2008-02-18 11:28:30 -0800 (Mon, 18 Feb 2008) Log Message: ----------- Fixed Long.MAX_VALUE encoding bug Modified Paths: -------------- trunk/pom.xml trunk/src/main/java/org/openfast/DecimalValue.java trunk/src/main/java/org/openfast/GroupValue.java trunk/src/main/java/org/openfast/template/type/DecimalType.java trunk/src/main/java/org/openfast/template/type/codec/IntegerCodec.java trunk/src/main/java/org/openfast/template/type/codec/SingleFieldDecimal.java trunk/src/site/site.xml trunk/src/test/java/org/openfast/DecimalValueTest.java trunk/src/test/java/org/openfast/submitted/ComposedDecimalNullPointerTest.java trunk/src/test/java/org/openfast/template/GroupTest.java trunk/src/test/java/org/openfast/template/operator/DeltaDecimalOperatorTest.java trunk/src/test/java/org/openfast/template/type/codec/SignedIntegerTest.java trunk/src/test/java/org/openfast/template/type/codec/SingleFieldDecimalTest.java trunk/src/test/java/org/openfast/test/OpenFastTestCase.java trunk/src/test/java/org/openfast/test/TestUtil.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2008-02-07 16:46:47 UTC (rev 134) +++ trunk/pom.xml 2008-02-18 19:28:30 UTC (rev 135) @@ -1,109 +1,141 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.openfast</groupId> <artifactId>openfast</artifactId> <packaging>jar</packaging> <version>0.9.8-SNAPSHOT</version> - + <organization> <name>The LaSalle Technology Group, LLC</name> <url>http://www.lasalletech.com</url> </organization> - - <name>OpenFAST</name> - <description>OpenFAST is a 100% Java implementation of the FAST Protocol.</description> - - <developers> - <developer> - <name>Jacob Northey</name> - <organization>Lasalletech</organization> - <organizationUrl>http://www.lasalletech.com/</organizationUrl> - <roles> - <role>architect</role> - <role>developer</role> - </roles> - <timezone>-5</timezone> - </developer> - <developer> - <name>Craig Otis</name> - <organization>Lasalletech</organization> - <organizationUrl>http://www.lasalletech.com/</organizationUrl> - <roles> - <role>developer</role> - </roles> - <timezone>-5</timezone> - </developer> - </developers> - - <contributors> - <contributor> - <name>Stefan Schwendiman</name> - <organization>Swiss Exchange</organization> - <organizationUrl>http://www.swx.com</organizationUrl> - <roles> - <role>tester</role> - </roles> - <timezone>+1</timezone> - </contributor> - </contributors> - - <licenses> - <license> - <name>Mozilla Public License Version 1.1</name> - <url>http://www.mozilla.org/MPL/MPL-1.1.html</url> - <distribution>repo</distribution> - </license> - </licenses> - + <name>OpenFAST</name> + + <description> + OpenFAST is a 100% Java implementation of the FAST Protocol. + </description> + + <developers> + <developer> + <name>Jacob Northey</name> + <organization>Lasalletech</organization> + <organizationUrl> + http://www.lasalletech.com/ + </organizationUrl> + <roles> + <role>architect</role> + <role>developer</role> + </roles> + <timezone>-5</timezone> + </developer> + <developer> + <name>Craig Otis</name> + <organization>Lasalletech</organization> + <organizationUrl> + http://www.lasalletech.com/ + </organizationUrl> + <roles> + <role>developer</role> + </roles> + <timezone>-5</timezone> + </developer> + </developers> + + <contributors> + <contributor> + <name>Stefan Schwendiman</name> + <organization>Swiss Exchange</organization> + <organizationUrl>http://www.swx.com</organizationUrl> + <roles> + <role>tester</role> + </roles> + <timezone>+1</timezone> + </contributor> + </contributors> + + <licenses> + <license> + <name>Mozilla Public License Version 1.1</name> + <url>http://www.mozilla.org/MPL/MPL-1.1.html</url> + <distribution>repo</distribution> + </license> + </licenses> + <url>http://www.openfast.org</url> <inceptionYear>2006</inceptionYear> - + <issueManagement> - <system>sourceforge</system> - <url>http://sourceforge.net/tracker/?group_id=198357</url> + <system>jira</system> + <url>http://www.quickfixj.org/jira/browse/FAST</url> </issueManagement> - + <scm> - <connection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.5</connection> - <developerConnection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.5</developerConnection> - <url>http://openfast.svn.sourceforge.net/viewvc/openfast/tags/openfast-0.9.5</url> + <connection> + scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.5 + </connection> + <developerConnection> + scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.5 + </developerConnection> + <url> + http://openfast.svn.sourceforge.net/viewvc/openfast/tags/openfast-0.9.5 + </url> </scm> - + <mailingLists> - <mailingList> - <name>OpenFAST Users Mailing List</name> - <subscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-user</subscribe> - <unsubscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-user</unsubscribe> - <archive>https://sourceforge.net/mailarchive/forum.php?forum_name=openfast-user</archive> - <post>ope...@li...</post> - </mailingList> - <mailingList> - <name>OpenFAST Commits Mailing List</name> - <subscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-commit</subscribe> - <unsubscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-commit</unsubscribe> - <archive>https://sourceforge.net/mailarchive/forum.php?forum_name=openfast-commit</archive> - <post>ope...@li...</post> - </mailingList> - <mailingList> - <name>OpenFAST Announcements Mailing List</name> - <subscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-announce</subscribe> - <unsubscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-announce</unsubscribe> - <archive>https://sourceforge.net/mailarchive/forum.php?forum_name=openfast-announce</archive> - <post>ope...@li...</post> - </mailingList> + <mailingList> + <name>OpenFAST Users Mailing List</name> + <subscribe> + http://lists.sourceforge.net/mailman/listinfo/openfast-user + </subscribe> + <unsubscribe> + http://lists.sourceforge.net/mailman/listinfo/openfast-user + </unsubscribe> + <archive> + https://sourceforge.net/mailarchive/forum.php?forum_name=openfast-user + </archive> + <post>ope...@li...</post> + </mailingList> + <mailingList> + <name>OpenFAST Commits Mailing List</name> + <subscribe> + http://lists.sourceforge.net/mailman/listinfo/openfast-commit + </subscribe> + <unsubscribe> + http://lists.sourceforge.net/mailman/listinfo/openfast-commit + </unsubscribe> + <archive> + https://sourceforge.net/mailarchive/forum.php?forum_name=openfast-commit + </archive> + <post>ope...@li...</post> + </mailingList> + <mailingList> + <name>OpenFAST Announcements Mailing List</name> + <subscribe> + http://lists.sourceforge.net/mailman/listinfo/openfast-announce + </subscribe> + <unsubscribe> + http://lists.sourceforge.net/mailman/listinfo/openfast-announce + </unsubscribe> + <archive> + https://sourceforge.net/mailarchive/forum.php?forum_name=openfast-announce + </archive> + <post>ope...@li...</post> + </mailingList> </mailingLists> - - <build> - <resources> - <resource> - <directory>src/main/resources</directory> - </resource> - <resource> - <directory>src/test/resources</directory> - </resource> - </resources> + + <build> + <resources> + <resource> + <directory>src/main/resources</directory> + </resource> + <resource> + <directory>src/test/resources</directory> + </resource> + </resources> <extensions> <extension> <groupId>org.apache.maven.wagon</groupId> @@ -111,8 +143,8 @@ <version>1.0-beta-2</version> </extension> </extensions> - - <plugins> + + <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> @@ -121,68 +153,76 @@ </configuration> </plugin> <plugin> - <artifactId>maven-release-plugin</artifactId> - <configuration> - <tagBase>https://openfast.svn.sourceforge.net/svnroot/openfast/tags</tagBase> - </configuration> + <artifactId>maven-release-plugin</artifactId> + <configuration> + <tagBase> + https://openfast.svn.sourceforge.net/svnroot/openfast/tags + </tagBase> + </configuration> </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-javadoc-plugin</artifactId> - <executions> - <execution> - <id>javadoc</id> - <phase>process-classes</phase> - <goals> - <goal>javadoc</goal> - </goals> - </execution> - </executions> - </plugin> <plugin> - <artifactId>maven-assembly-plugin</artifactId> - <configuration> - <descriptors> - <descriptor>src/assembly/source.xml</descriptor> - </descriptors> - </configuration> - <executions> - <execution> - <id>make-assembly</id> - <phase>package</phase> - <goals> - <goal>attached</goal> - </goals> - </execution> - </executions> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <executions> + <execution> + <id>javadoc</id> + <phase>process-classes</phase> + <goals> + <goal>javadoc</goal> + </goals> + </execution> + </executions> </plugin> - </plugins> - </build> - - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.2</version> - <scope>test</scope> - </dependency> - </dependencies> - - <distributionManagement> - <repository> - <id>sourceforge.net</id> - <name>Sourceforge.net Repository</name> - <url>scp://shell.sourceforge.net/home/groups/o/op/openfast/htdocs/maven/release</url> - </repository> - <snapshotRepository> - <id>sourceforge.net</id> - <name>Sourceforge.net Snapshot Repository</name> - <url>scp://shell.sourceforge.net/home/groups/o/op/openfast/htdocs/maven/snapshot</url> - </snapshotRepository> - <site> - <id>sourceforge.net</id> - <name>Sourceforge.net OpenFAST Web Site</name> - <url>scp://shell.sourceforge.net/home/groups/o/op/openfast/htdocs/</url> - </site> - </distributionManagement> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <configuration> + <descriptors> + <descriptor>src/assembly/source.xml</descriptor> + </descriptors> + </configuration> + <executions> + <execution> + <id>make-assembly</id> + <phase>package</phase> + <goals> + <goal>attached</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.2</version> + <scope>test</scope> + </dependency> + </dependencies> + + <distributionManagement> + <repository> + <id>sourceforge.net</id> + <name>Sourceforge.net Repository</name> + <url> + scp://shell.sourceforge.net/home/groups/o/op/openfast/htdocs/maven/release + </url> + </repository> + <snapshotRepository> + <id>sourceforge.net</id> + <name>Sourceforge.net Snapshot Repository</name> + <url> + scp://shell.sourceforge.net/home/groups/o/op/openfast/htdocs/maven/snapshot + </url> + </snapshotRepository> + <site> + <id>sourceforge.net</id> + <name>Sourceforge.net OpenFAST Web Site</name> + <url> + scp://shell.sourceforge.net/home/groups/o/op/openfast/htdocs/ + </url> + </site> + </distributionManagement> </project> \ No newline at end of file Modified: trunk/src/main/java/org/openfast/DecimalValue.java =================================================================== --- trunk/src/main/java/org/openfast/DecimalValue.java 2008-02-07 16:46:47 UTC (rev 134) +++ trunk/src/main/java/org/openfast/DecimalValue.java 2008-02-18 19:28:30 UTC (rev 135) @@ -22,29 +22,24 @@ package org.openfast; import java.math.BigDecimal; +import java.math.BigInteger; import org.openfast.error.FastConstants; public class DecimalValue extends NumericValue { private static final long serialVersionUID = 1L; - public final double value; - public final int exponent; - public final long mantissa; public DecimalValue(double value) { if (value == 0.0) { - this.value = 0.0; this.exponent = 0; this.mantissa = 0; return; } - this.value = value; - BigDecimal decimalValue = BigDecimal.valueOf(value); int exponent = decimalValue.scale(); long mantissa = decimalValue.unscaledValue().longValue(); @@ -61,12 +56,11 @@ public DecimalValue(long mantissa, int exponent) { this.mantissa = mantissa; this.exponent = exponent; + } - if (exponent < 0) { - this.value = mantissa / Math.pow(10, -exponent); - } else { - this.value = mantissa * Math.pow(10, exponent); - } + public DecimalValue(BigDecimal bigDecimal) { + this.mantissa = bigDecimal.unscaledValue().longValue(); + this.exponent = bigDecimal.scale(); } public NumericValue increment() { @@ -90,59 +84,66 @@ } public boolean equals(DecimalValue other) { - return other.value == this.value; + return other.mantissa == this.mantissa && other.exponent == this.exponent; } - public NumericValue subtract(NumericValue priorValue) { - return new DecimalValue(this.value - ((DecimalValue) priorValue).value); + public NumericValue subtract(NumericValue subtrahend) { + return new DecimalValue(toBigDecimal().subtract(((DecimalValue)subtrahend).toBigDecimal())); } public NumericValue add(NumericValue addend) { - return new DecimalValue(((DecimalValue) addend).value + this.value); + return new DecimalValue(toBigDecimal().add(((DecimalValue)addend).toBigDecimal())); } public String serialize() { - return String.valueOf(value); + return toString(); } public boolean equals(int value) { - return (double) value == this.value; + return false; } public long toLong() { if (exponent < 0) Global.handleError(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, ""); - return (long) value; + return (long) (getValue()); } public int toInt() { - if (exponent < 0) + long value = getValue(); + if (exponent < 0 || (value) > Integer.MAX_VALUE) Global.handleError(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, ""); - return (int) value; + return (int) (value); } public short toShort() { - if (exponent < 0) + long value = getValue(); + if (exponent < 0 || (value) > Short.MAX_VALUE) Global.handleError(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, ""); - return (short) value; + return (short) (value); } public byte toByte() { - if (exponent < 0) + long value = getValue(); + if (exponent < 0 || (value) > Byte.MAX_VALUE) Global.handleError(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, ""); - return (byte) value; + return (byte) (value); } + private long getValue() { + return mantissa * ((long) Math.pow(10, exponent)); + } + public double toDouble() { - return value; + return (mantissa * Math.pow(10, exponent)); } public BigDecimal toBigDecimal() { - return new BigDecimal(value); + return new BigDecimal(BigInteger.valueOf(mantissa), -exponent); } public String toString() { - return String.valueOf(value); + return toBigDecimal().toPlainString(); } public int hashCode() { Modified: trunk/src/main/java/org/openfast/GroupValue.java =================================================================== --- trunk/src/main/java/org/openfast/GroupValue.java 2008-02-07 16:46:47 UTC (rev 134) +++ trunk/src/main/java/org/openfast/GroupValue.java 2008-02-18 19:28:30 UTC (rev 135) @@ -17,9 +17,8 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ + */ - package org.openfast; import org.openfast.template.Field; @@ -33,10 +32,11 @@ import java.math.BigDecimal; import java.util.Iterator; - public class GroupValue implements FieldValue { private static final long serialVersionUID = 1L; - protected final FieldValue[] values; + + protected final FieldValue[] values; + private final Group group; public GroupValue(Group group, FieldValue[] values) { @@ -59,135 +59,137 @@ public int getInt(int fieldIndex) { return getScalar(fieldIndex).toInt(); } - + public int getInt(String fieldName) { - // BAD ABSTRACTION - if (!group.hasField(fieldName)) { - if (group.hasIntrospectiveField(fieldName)) { - Scalar scalar = group.getIntrospectiveField(fieldName); - if (scalar.getType().equals(Type.UNICODE) || - scalar.getType().equals(Type.STRING) || - scalar.getType().equals(Type.ASCII)) - return getString(scalar.getName()).length(); - if (scalar.getType().equals(Type.BYTE_VECTOR)) - return getBytes(scalar.getName()).length; - } - - } - return getScalar(fieldName).toInt(); - } + // BAD ABSTRACTION + if (!group.hasField(fieldName)) { + if (group.hasIntrospectiveField(fieldName)) { + Scalar scalar = group.getIntrospectiveField(fieldName); + if (scalar.getType().equals(Type.UNICODE) || scalar.getType().equals(Type.STRING) + || scalar.getType().equals(Type.ASCII)) + return getString(scalar.getName()).length(); + if (scalar.getType().equals(Type.BYTE_VECTOR)) + return getBytes(scalar.getName()).length; + } - public boolean getBool(String fieldName) { - if (!isDefined(fieldName)) return false; - return getScalar(fieldName).toInt() != 0; - } + } + return getScalar(fieldName).toInt(); + } + public boolean getBool(String fieldName) { + if (!isDefined(fieldName)) + return false; + return getScalar(fieldName).toInt() != 0; + } + public long getLong(int fieldIndex) { return getScalar(fieldIndex).toLong(); } - + public long getLong(String fieldName) { - return getScalar(fieldName).toLong(); - } + return getScalar(fieldName).toLong(); + } - public byte getByte(int fieldIndex) { - return getScalar(fieldIndex).toByte(); + public byte getByte(int fieldIndex) { + return getScalar(fieldIndex).toByte(); } - public byte getByte(String fieldName) { - return getScalar(fieldName).toByte(); + public byte getByte(String fieldName) { + return getScalar(fieldName).toByte(); } - public short getShort(int fieldIndex) { - return getScalar(fieldIndex).toShort(); + public short getShort(int fieldIndex) { + return getScalar(fieldIndex).toShort(); } - public short getShort(String fieldName) { - return getScalar(fieldName).toShort(); + public short getShort(String fieldName) { + return getScalar(fieldName).toShort(); } public String getString(int index) { - return getValue(index).toString(); - } + return getValue(index).toString(); + } - public String getString(String fieldName) { - return getValue(fieldName).toString(); + public String getString(String fieldName) { + FieldValue value = getValue(fieldName); + return (value == null) ? null : value.toString(); } public double getDouble(int fieldIndex) { - return getScalar(fieldIndex).toDouble(); - } + return getScalar(fieldIndex).toDouble(); + } public double getDouble(String fieldName) { - return getScalar(fieldName).toDouble(); - } + return getScalar(fieldName).toDouble(); + } public BigDecimal getBigDecimal(int fieldIndex) { - return getScalar(fieldIndex).toBigDecimal(); - } + return getScalar(fieldIndex).toBigDecimal(); + } public BigDecimal getBigDecimal(String fieldName) { - return getScalar(fieldName).toBigDecimal(); - } + return getScalar(fieldName).toBigDecimal(); + } - public byte[] getBytes(int fieldIndex) { - return getScalar(fieldIndex).getBytes(); - } - - public byte[] getBytes(String fieldName) { - return getScalar(fieldName).getBytes(); - } + public byte[] getBytes(int fieldIndex) { + return getScalar(fieldIndex).getBytes(); + } - public SequenceValue getSequence(int fieldIndex) { - return (SequenceValue) getValue(fieldIndex); - } + public byte[] getBytes(String fieldName) { + return getScalar(fieldName).getBytes(); + } - public SequenceValue getSequence(String fieldName) { - return (SequenceValue) getValue(fieldName); - } - - public ScalarValue getScalar(int fieldIndex) { - return (ScalarValue) getValue(fieldIndex); - } + public SequenceValue getSequence(int fieldIndex) { + return (SequenceValue) getValue(fieldIndex); + } - public ScalarValue getScalar(String fieldName) { - return (ScalarValue) getValue(fieldName); - } + public SequenceValue getSequence(String fieldName) { + return (SequenceValue) getValue(fieldName); + } - public GroupValue getGroup(int fieldIndex) { - return (GroupValue) getValue(fieldIndex); - } + public ScalarValue getScalar(int fieldIndex) { + return (ScalarValue) getValue(fieldIndex); + } - public GroupValue getGroup(String fieldName) { - return (GroupValue) getValue(fieldName); - } + public ScalarValue getScalar(String fieldName) { + return (ScalarValue) getValue(fieldName); + } - public FieldValue getValue(int fieldIndex) { - return values[fieldIndex]; - } + public GroupValue getGroup(int fieldIndex) { + return (GroupValue) getValue(fieldIndex); + } - public FieldValue getValue(String fieldName) { - if (!group.hasField(fieldName)) { - throw new IllegalArgumentException("The field \"" + fieldName + "\" does not exist in group " + group); - } - - return values[group.getFieldIndex(fieldName)]; - } + public GroupValue getGroup(String fieldName) { + return (GroupValue) getValue(fieldName); + } - public Group getGroup() { - return group; - } + public FieldValue getValue(int fieldIndex) { + return values[fieldIndex]; + } - public void setString(Field field, String value) { - if (field == null) throw new IllegalArgumentException("Field must not be null [value=" + value + "]"); - setFieldValue(field, field.createValue(value)); - } + public FieldValue getValue(String fieldName) { + if (!group.hasField(fieldName)) { + throw new IllegalArgumentException("The field \"" + fieldName + "\" does not exist in group " + group); + } - public void setFieldValue(Field field, FieldValue value) { - setFieldValue(group.getFieldIndex(field), value); - } - - public void setFieldValue(int fieldIndex, FieldValue value) { + return values[group.getFieldIndex(fieldName)]; + } + + public Group getGroup() { + return group; + } + + public void setString(Field field, String value) { + if (field == null) + throw new IllegalArgumentException("Field must not be null [value=" + value + "]"); + setFieldValue(field, field.createValue(value)); + } + + public void setFieldValue(Field field, FieldValue value) { + setFieldValue(group.getFieldIndex(field), value); + } + + public void setFieldValue(int fieldIndex, FieldValue value) { values[fieldIndex] = value; } @@ -199,37 +201,45 @@ values[fieldIndex] = new ByteVectorValue(bytes); } - public void setByteVector(String fieldName, byte[] bytes) { - setFieldValue(fieldName, new ByteVectorValue(bytes)); - } + public void setByteVector(String fieldName, byte[] bytes) { + setFieldValue(fieldName, new ByteVectorValue(bytes)); + } public void setDecimal(int fieldIndex, double value) { values[fieldIndex] = new DecimalValue(value); } - public void setDecimal(String fieldName, double value) { - setFieldValue(fieldName, new DecimalValue(value)); - } + public void setDecimal(String fieldName, double value) { + setFieldValue(fieldName, new DecimalValue(value)); + } + + public void setDecimal(int fieldIndex, BigDecimal value) { + values[fieldIndex] = new DecimalValue(value); + } + + public void setDecimal(String fieldName, BigDecimal value) { + setFieldValue(fieldName, new DecimalValue(value)); + } public void setInteger(String fieldName, int value) { setFieldValue(fieldName, new IntegerValue(value)); } - + public void setInteger(int fieldIndex, int value) { - values[fieldIndex] = new IntegerValue(value); + values[fieldIndex] = new IntegerValue(value); } - public void setBool(String fieldName, boolean value) { + public void setBool(String fieldName, boolean value) { setFieldValue(fieldName, new IntegerValue(value ? 1 : 0)); - } + } - public void setLong(String fieldName, long value) { - setFieldValue(fieldName, new LongValue(value)); - } + public void setLong(String fieldName, long value) { + setFieldValue(fieldName, new LongValue(value)); + } - public void setLong(int fieldIndex, long value) { - values[fieldIndex] = new LongValue(value); - } + public void setLong(int fieldIndex, long value) { + values[fieldIndex] = new LongValue(value); + } public void setString(int fieldIndex, String value) { values[fieldIndex] = new StringValue(value); @@ -237,7 +247,7 @@ public void setString(String fieldName, String value) { setFieldValue(fieldName, group.getField(fieldName).createValue(value)); - } + } public boolean equals(Object other) { if (other == this) { @@ -257,20 +267,19 @@ } for (int i = 0; i < values.length; i++) { - if (values[i] == null) { - if (other.values[i] != null) - return false; - } - else if (!values[i].equals(other.values[i])) { + if (values[i] == null) { + if (other.values[i] != null) + return false; + } else if (!values[i].equals(other.values[i])) { return false; } } return true; } - + public int hashCode() { - return values.hashCode(); + return values.hashCode(); } public String toString() { @@ -290,8 +299,8 @@ } public void setFieldValue(String fieldName, FieldValue value) { - if (!group.hasField(fieldName)) - throw new IllegalArgumentException("The field " + fieldName + " does not exist in group " + group); + if (!group.hasField(fieldName)) + throw new IllegalArgumentException("The field " + fieldName + " does not exist in group " + group); int index = group.getFieldIndex(fieldName); setFieldValue(index, value); } @@ -311,12 +320,12 @@ public boolean isDefined(String fieldName) { return getValue(fieldName) != null; } - + public FieldValue copy() { - FieldValue[] copies = new FieldValue[values.length]; - for (int i=0; i<copies.length; i++) { - copies[i] = values[i].copy(); - } - return new GroupValue(group, this.values); - } + FieldValue[] copies = new FieldValue[values.length]; + for (int i = 0; i < copies.length; i++) { + copies[i] = values[i].copy(); + } + return new GroupValue(group, this.values); + } } Modified: trunk/src/main/java/org/openfast/template/type/DecimalType.java =================================================================== --- trunk/src/main/java/org/openfast/template/type/DecimalType.java 2008-02-07 16:46:47 UTC (rev 134) +++ trunk/src/main/java/org/openfast/template/type/DecimalType.java 2008-02-18 19:28:30 UTC (rev 135) @@ -11,51 +11,57 @@ import org.openfast.template.type.codec.TypeCodec; final class DecimalType extends SimpleType { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - DecimalType() { - super("decimal", TypeCodec.SF_SCALED_NUMBER, TypeCodec.NULLABLE_SF_SCALED_NUMBER); - } + DecimalType() { + super("decimal", TypeCodec.SF_SCALED_NUMBER, TypeCodec.NULLABLE_SF_SCALED_NUMBER); + } - /** - * Get the approprivate codec for the passed operator - * @param operator The operator object in which the codec is trying to get - * @param optional Determines if the Field is required or not for the data - * @return Returns the codec if the field is required - */ - public TypeCodec getCodec(Operator operator, boolean optional) { - return super.getCodec(operator, optional); - } + /** + * Get the approprivate codec for the passed operator + * + * @param operator + * The operator object in which the codec is trying to get + * @param optional + * Determines if the Field is required or not for the data + * @return Returns the codec if the field is required + */ + public TypeCodec getCodec(Operator operator, boolean optional) { + return super.getCodec(operator, optional); + } - /** - * @param value - * @return - */ - protected ScalarValue getVal(String value) { - try { - return new DecimalValue(Double.parseDouble(value)); - } catch (NumberFormatException e) { - Global.handleError(FastConstants.S3_INITIAL_VALUE_INCOMP, "The value \"" + value + "\" is not compatible with type " + this); - return null; - } - } + /** + * @param value + * @return + */ + protected ScalarValue getVal(String value) { + try { + return new DecimalValue(Double.parseDouble(value)); + } catch (NumberFormatException e) { + Global.handleError(FastConstants.S3_INITIAL_VALUE_INCOMP, "The value \"" + value + "\" is not compatible with type " + + this); + return null; + } + } - /** - * @return Returns a new DecimalValue with a defualt value - */ - public ScalarValue getDefaultValue() { - return new DecimalValue(0.0); - } + /** + * @return Returns a new DecimalValue with a defualt value + */ + public ScalarValue getDefaultValue() { + return new DecimalValue(0.0); + } - /** - * Determines if previousValue is of type DecimalValue - * @param previousValue The previous value of the Field, used in - * determining the corresponding field value for the current - * message being decoded. - * @return Returns true if the previousValue is an instance of DecimalValue, - * false otherwise - */ - public boolean isValueOf(ScalarValue previousValue) { - return previousValue instanceof DecimalValue; - } + /** + * Determines if previousValue is of type DecimalValue + * + * @param previousValue + * The previous value of the Field, used in determining the + * corresponding field value for the current message being + * decoded. + * @return Returns true if the previousValue is an instance of DecimalValue, + * false otherwise + */ + public boolean isValueOf(ScalarValue previousValue) { + return previousValue instanceof DecimalValue; + } } \ No newline at end of file Modified: trunk/src/main/java/org/openfast/template/type/codec/IntegerCodec.java =================================================================== --- trunk/src/main/java/org/openfast/template/type/codec/IntegerCodec.java 2008-02-07 16:46:47 UTC (rev 134) +++ trunk/src/main/java/org/openfast/template/type/codec/IntegerCodec.java 2008-02-18 19:28:30 UTC (rev 135) @@ -126,8 +126,11 @@ if ((value >= -36028797018963968L) && (value <= 36028797018963967L)) { return 8; // - 2 ^ 55 ... 2 ^ 55 -1 } - - return 9; + + if ((value >= -4611686018427387904L && value <= 4611686018427387903L)) { + return 9; + } + return 10; } public boolean equals(Object obj) { Modified: trunk/src/main/java/org/openfast/template/type/codec/SingleFieldDecimal.java =================================================================== --- trunk/src/main/java/org/openfast/template/type/codec/SingleFieldDecimal.java 2008-02-07 16:46:47 UTC (rev 134) +++ trunk/src/main/java/org/openfast/template/type/codec/SingleFieldDecimal.java 2008-02-18 19:28:30 UTC (rev 135) @@ -84,7 +84,7 @@ Global.handleError(FastConstants.R1_LARGE_DECIMAL, "Encountered exponent of size " + exponent); } - int mantissa = ((IntegerValue) TypeCodec.INTEGER.decode(in)).value; + long mantissa = TypeCodec.INTEGER.decode(in).toLong(); DecimalValue decimalValue = new DecimalValue(mantissa, exponent); return decimalValue; Modified: trunk/src/site/site.xml =================================================================== --- trunk/src/site/site.xml 2008-02-07 16:46:47 UTC (rev 134) +++ trunk/src/site/site.xml 2008-02-18 19:28:30 UTC (rev 135) @@ -29,8 +29,8 @@ <menu name="Documentation"> <item name="Javadocs" href="apidocs/"/> - <item name="15-minute Guide" href="http://openfast.wiki.sourceforge.net/FifteenMinute"/> - <item name="Wiki" href="http://openfast.wiki.sourceforge.net/"/> + <item name="15-minute Guide" href="http://www.quickfixj.org/confluence/display/FAST/FifteenMinuteGettingStarted"/> + <item name="Wiki" href="http://www.quickfixj.org/confluence/display/FAST/Home"/> </menu> <menu name="Developers"> Modified: trunk/src/test/java/org/openfast/DecimalValueTest.java =================================================================== --- trunk/src/test/java/org/openfast/DecimalValueTest.java 2008-02-07 16:46:47 UTC (rev 134) +++ trunk/src/test/java/org/openfast/DecimalValueTest.java 2008-02-18 19:28:30 UTC (rev 135) @@ -17,77 +17,88 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ + */ - package org.openfast; +import java.math.BigDecimal; +import java.math.BigInteger; + import org.openfast.error.FastConstants; import org.openfast.error.FastException; import org.openfast.test.OpenFastTestCase; +public class DecimalValueTest extends OpenFastTestCase { + public void testToBigDecimal() { + assertEquals(new BigDecimal(BigInteger.valueOf(241), -5), new DecimalValue(241, 5).toBigDecimal()); + assertEquals(new BigDecimal(BigInteger.valueOf(15), 4), new DecimalValue(15, -4).toBigDecimal()); + } + + public void testMaxValue() { + DecimalValue max = new DecimalValue(Long.MAX_VALUE, 63); + assertEquals(new BigDecimal(new BigInteger(String.valueOf(Long.MAX_VALUE)), -63), max.toBigDecimal()); + } -public class DecimalValueTest extends OpenFastTestCase { public void testMantissaAndExponent() { DecimalValue value = new DecimalValue(9427.55); assertEquals(942755, value.mantissa); assertEquals(-2, value.exponent); value = new DecimalValue(942755, -2); - assertEquals(9427.55, value.value, .01); + assertEquals(BigDecimal.valueOf(9427.55), value.toBigDecimal()); } + public void testToByte() { - assertEquals(100, d(100.0).toByte()); + assertEquals(100, d(100.0).toByte()); } - + public void testToByteWithDecimalPart() { - try { - d(100.1).toByte(); - fail(); - } catch (FastException e) { - assertEquals(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, e.getCode()); - } + try { + d(100.1).toByte(); + fail(); + } catch (FastException e) { + assertEquals(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, e.getCode()); + } } - + + public void testToLong() { + assertEquals(10000000000000L, d(10000000000000.0).toLong()); + } + public void testToShort() { - assertEquals(128, d(128.0).toShort()); + assertEquals(128, d(128.0).toShort()); } - + public void testToShortWithDecimalPart() { - try { - d(100.1).toShort(); - fail(); - } catch (FastException e) { - assertEquals(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, e.getCode()); - } + try { + d(100.1).toShort(); + fail(); + } catch (FastException e) { + assertEquals(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, e.getCode()); + } } - + public void testToInt() { - assertEquals(100, d(100.0).toInt()); + assertEquals(100, d(100.0).toInt()); } - + public void testToIntWithDecimalPart() { - try { - d(100.1).toInt(); - fail(); - } catch (FastException e) { - assertEquals(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, e.getCode()); - } + try { + d(100.1).toInt(); + fail(); + } catch (FastException e) { + assertEquals(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, e.getCode()); + } } - - public void testToLong() { - assertEquals(10000000000000L, d(10000000000000.0).toLong()); - } - + public void testToLongWithDecimalPart() { - try { - d(100.1).toLong(); - fail(); - } catch (FastException e) { - assertEquals(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, e.getCode()); - } + try { + d(100.1).toLong(); + fail(); + } catch (FastException e) { + assertEquals(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, e.getCode()); + } } - - + } Modified: trunk/src/test/java/org/openfast/submitted/ComposedDecimalNullPointerTest.java =================================================================== --- trunk/src/test/java/org/openfast/submitted/ComposedDecimalNullPointerTest.java 2008-02-07 16:46:47 UTC (rev 134) +++ trunk/src/test/java/org/openfast/submitted/ComposedDecimalNullPointerTest.java 2008-02-18 19:28:30 UTC (rev 135) @@ -11,17 +11,17 @@ import org.openfast.util.RecordingInputStream; public class ComposedDecimalNullPointerTest extends OpenFastTestCase { - public void testNullPointerOnTwinValue() throws Exception { - InputStream templateSource = resource("FPL/FASTTestTemplate.xml"); - MessageTemplateLoader templateLoader = new XMLMessageTemplateLoader(); - MessageTemplate[] templates = templateLoader.load(templateSource); - - InputStream is = resource("FPL/messages.fast"); - MessageInputStream mis = new MessageInputStream(new RecordingInputStream(is)); - mis.registerTemplate(35, templates[0]); - Message msg = mis.readMessage(); - msg = mis.readMessage(); - msg = mis.readMessage(); - assertEquals(templates[0], msg.getTemplate()); - } + public void testNullPointerOnTwinValue() throws Exception { + InputStream templateSource = resource("FPL/FASTTestTemplate.xml"); + MessageTemplateLoader templateLoader = new XMLMessageTemplateLoader(); + MessageTemplate[] templates = templateLoader.load(templateSource); + + InputStream is = resource("FPL/messages.fast"); + MessageInputStream mis = new MessageInputStream(new RecordingInputStream(is)); + mis.registerTemplate(35, templates[0]); + Message msg = mis.readMessage(); + msg = mis.readMessage(); + msg = mis.readMessage(); + assertEquals(templates[0], msg.getTemplate()); + } } Modified: trunk/src/test/java/org/openfast/template/GroupTest.java =================================================================== --- trunk/src/test/java/org/openfast/template/GroupTest.java 2008-02-07 16:46:47 UTC (rev 134) +++ trunk/src/test/java/org/openfast/template/GroupTest.java 2008-02-18 19:28:30 UTC (rev 135) @@ -17,9 +17,8 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ + */ - package org.openfast.template; import java.io.ByteArrayInputStream; @@ -42,29 +41,24 @@ import org.openfast.test.OpenFastTestCase; import org.openfast.test.TestUtil; - public class GroupTest extends OpenFastTestCase { private Group template; + private Context context; protected void setUp() throws Exception { - template = new MessageTemplate("", new Field[] { }); + template = new MessageTemplate("", new Field[] {}); context = new Context(); } public void testEncode() { - Scalar firstName = new Scalar("First Name", Type.U32, - Operator.COPY, ScalarValue.UNDEFINED, true); - Scalar lastName = new Scalar("Last Name", Type.U32, - Operator.NONE, ScalarValue.UNDEFINED, false); + Scalar firstName = new Scalar("First Name", Type.U32, Operator.COPY, ScalarValue.UNDEFINED, true); + Scalar lastName = new Scalar("Last Name", Type.U32, Operator.NONE, ScalarValue.UNDEFINED, false); - Group theGroup = new Group("guy", new Field[] { firstName, lastName }, - false); + Group theGroup = new Group("guy", new Field[] { firstName, lastName }, false); - byte[] actual = theGroup.encode(new GroupValue( - new Group("", new Field[] { }, false), - new FieldValue[] { new IntegerValue(1), new IntegerValue(2) }), - template, context); + byte[] actual = theGroup.encode(new GroupValue(new Group("", new Field[] {}, false), new FieldValue[] { new IntegerValue(1), + new IntegerValue(2) }), template, context); String expected = "11000000 10000010 10000010"; @@ -73,60 +67,54 @@ public void testDecode() { String message = "11000000 10000010 10000010"; - InputStream in = new ByteArrayInputStream(ByteUtil.convertBitStringToFastByteArray( - message)); - Scalar firstname = new Scalar("firstName", Type.U32, - Operator.COPY, ScalarValue.UNDEFINED, true); - Scalar lastName = new Scalar("lastName", Type.U32, - Operator.NONE, ScalarValue.UNDEFINED, false); + InputStream in = new ByteArrayInputStream(ByteUtil.convertBitStringToFastByteArray(message)); + Scalar firstname = new Scalar("firstName", Type.U32, Operator.COPY, ScalarValue.UNDEFINED, true); + Scalar lastName = new Scalar("lastName", Type.U32, Operator.NONE, ScalarValue.UNDEFINED, false); - // MessageInputStream in = new MessageInputStream(new ByteArrayInputStream(message.getBytes())); - Group group = new Group("person", new Field[] { firstname, lastName }, - false); + // MessageInputStream in = new MessageInputStream(new + // ByteArrayInputStream(message.getBytes())); + Group group = new Group("person", new Field[] { firstname, lastName }, false); GroupValue groupValue = (GroupValue) group.decode(in, template, context, BitVectorReader.INFINITE_TRUE); assertEquals(1, ((IntegerValue) groupValue.getValue(0)).value); assertEquals(2, ((IntegerValue) groupValue.getValue(1)).value); } - + public void testGroupWithoutPresenceMap() { - MessageTemplate template = template( - "<template>" + - " <group name=\"priceGroup\" presence=\"optional\">" + - " <decimal name=\"price\"><delta/></decimal>" + - " </group>" + - "</template>"); - Context encodingContext = new Context(); - Context decodingContext = new Context(); - encodingContext.registerTemplate(1, template); - decodingContext.registerTemplate(1, template); - - String encodedBits = "11100000 10000001 11111110 10111111"; - - FastDecoder decoder = new FastDecoder(decodingContext, bitStream(encodedBits)); - Message message = decoder.readMessage(); - assertEquals(0.63, message.getGroup("priceGroup").getDouble("price"), 0.01); - - byte[] encoding = template.encode(message, encodingContext); - assertEquals(encodedBits, encoding); + MessageTemplate template = template("<template>" + " <group name=\"priceGroup\" presence=\"optional\">" + + " <decimal name=\"price\"><delta/></decimal>" + " </group>" + "</template>"); + Context encodingContext = new Context(); + Context decodingContext = new Context(); + encodingContext.registerTemplate(1, template); + decodingContext.registerTemplate(1, template); + + String encodedBits = "11100000 10000001 11111110 10111111"; + + FastDecoder decoder = new FastDecoder(decodingContext, bitStream(encodedBits)); + Message message = decoder.readMessage(); + assertEquals(0.63, message.getGroup("priceGroup").getDouble("price"), 0.01); + + byte[] encoding = template.encode(message, encodingContext); + assertEquals(encodedBits, encoding); } - + public void testDecodeGroupWithOverlongPresenceMap() { - try { - ObjectMother.quoteTemplate().decode(bitStream("00000000 10000000"), ObjectMother.quoteTemplate(), new Context(), BitVectorReader.INFINITE_TRUE); - fail(); - } catch (FastException e) { - assertEquals(FastConstants.R7_PMAP_OVERLONG, e.getCode()); - } + try { + ObjectMother.quoteTemplate().decode(bitStream("00000000 10000000"), ObjectMother.quoteTemplate(), new Context(), + BitVectorReader.INFINITE_TRUE); + fail(); + } catch (FastException e) { + assertEquals(FastConstants.R7_PMAP_OVERLONG, e.getCode()); + } } - + public void testDecodeGroupWithPresenceMapWithTooManyBits() { - MessageTemplate g = ObjectMother.quoteTemplate(); - Context c = new Context(); - c.registerTemplate(1, g); - try { - g.decode(bitStream("11111000 10000001 10000000 10000110 10000000 10000110"), g, c, BitVectorReader.INFINITE_TRUE); - } catch (FastException e) { - assertEquals(FastConstants.R8_PMAP_TOO_MANY_BITS, e.getCode()); - } + MessageTemplate g = ObjectMother.quoteTemplate(); + Context c = new Context(); + c.registerTemplate(1, g); + try { + g.decode(bitStream("11111000 10000001 10000000 10000110 10000000 10000110"), g, c, BitVectorReader.INFINITE_TRUE); + } catch (FastException e) { + assertEquals(FastConstants.R8_PMAP_TOO_MANY_BITS, e.getCode()); + } } } Modified: trunk/src/test/java/org/openfast/template/operator/DeltaDecimalOperatorTest.java =================================================================== --- trunk/src/test/java/org/openfast/template/operator/DeltaDecimalOperatorTest.java 2008-02-07 16:46:47 UTC (rev 134) +++ trunk/src/test/java/org/openfast/template/operator/DeltaDecimalOperatorTest.java 2008-02-18 19:28:30 UTC (rev 135) @@ -22,6 +22,8 @@ package org.openfast.template.operator; +import java.math.BigDecimal; + import org.openfast.DecimalValue; import org.openfast.ScalarValue; import org.openfast.error.FastConstants; @@ -38,7 +40,7 @@ OperatorCodec operator = field.getOperatorCodec(); DecimalValue value = (DecimalValue) operator.getValueToEncode(d(9427.55),ScalarValue.UNDEFINED, field); - assertEquals(9427.55, value.value, 0.1); + assertEquals(BigDecimal.valueOf(9427.55), value.toBigDecimal()); value = (DecimalValue) operator.getValueToEncode(d(9427.51), d(9427.55), field); assertEquals(-4, value.mantissa); @@ -59,7 +61,7 @@ DecimalValue value = (DecimalValue) operator.getValueToEncode(d(9427.55), ScalarValue.UNDEFINED, field); - assertEquals(9427.55, value.value, 0.1); + assertEquals(BigDecimal.valueOf(9427.55), value.toBigDecimal()); value = (DecimalValue) operator.getValueToEncode(d(9427.51), d(9427.55), field); Modified: trunk/src/test/java/org/openfast/template/type/codec/SignedIntegerTest.java =================================================================== --- trunk/src/test/java/org/openfast/template/type/codec/SignedIntegerTest.java 2008-02-07 16:46:47 UTC (rev 134) +++ trunk/src/test/java/org/openfast/template/type/codec/SignedIntegerTest.java 2008-02-18 19:28:30 UTC (rev 135) @@ -4,18 +4,23 @@ public class SignedIntegerTest extends OpenFastTestCase { - public void testEncodeDecode() { - assertEncodeDecode(i(63), "10111111", TypeCodec.INTEGER); - assertEncodeDecode(i(64), "00000000 11000000", TypeCodec.INTEGER); - assertEncodeDecode(i(-1), "11111111", TypeCodec.INTEGER); - assertEncodeDecode(i(-2), "11111110", TypeCodec.INTEGER); - assertEncodeDecode(i(-64), "11000000", TypeCodec.INTEGER); - assertEncodeDecode(i(-65), "01111111 10111111", TypeCodec.INTEGER); - assertEncodeDecode(i(639), "00000100 11111111", TypeCodec.INTEGER); - assertEncodeDecode(i(942755), "00111001 01000101 10100011", TypeCodec.INTEGER); - assertEncodeDecode(i(-942755), "01000110 00111010 11011101", TypeCodec.INTEGER); - assertEncodeDecode(i(8193), "00000000 01000000 10000001", TypeCodec.INTEGER); - assertEncodeDecode(i(-8193), "01111111 00111111 11111111", TypeCodec.INTEGER); - } - + public void testEncodeDecode() { + assertEncodeDecode(i(63), "10111111", TypeCodec.INTEGER); + assertEncodeDecode(i(64), "00000000 11000000", TypeCodec.INTEGER); + assertEncodeDecode(i(-1), "11111111", TypeCodec.INTEGER); + assertEncodeDecode(i(-2), "11111110", TypeCodec.INTEGER); + assertEncodeDecode(i(-64), "11000000", TypeCodec.INTEGER); + assertEncodeDecode(i(-65), "01111111 10111111", TypeCodec.INTEGER); + assertEncodeDecode(i(639), "00000100 11111111", TypeCodec.INTEGER); + assertEncodeDecode(i(942755), "00111001 01000101 10100011", TypeCodec.INTEGER); + assertEncodeDecode(i(-942755), "01000110 00111010 11011101", TypeCodec.INTEGER); + assertEncodeDecode(i(8193), "00000000 01000000 10000001", TypeCodec.INTEGER); + assertEncodeDecode(i(-8193), "01111111 00111111 11111111", TypeCodec.INTEGER); + } + + public void testEncodeDecodeBoundary() { + assertEncodeDecode(l(Long.MAX_VALUE), "00000000 01111111 01111111 01111111 01111111 01111111 01111111 01111111 01111111 11111111", TypeCodec.INTEGER); + assertEncodeDecode(l(Long.MIN_VALUE), "01111111 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 10000000", TypeCodec.INTEGER); + } + } Modified: trunk/src/test/java/org/openfast/template/type/codec/SingleFieldDecimalTest.java =================================================================== --- trunk/src/test/java/org/openfast/template/type/codec/SingleFieldDecimalTest.java 2008-02-07 16:46:47 UTC (rev 134) +++ trunk/src/test/java/org/openfast/template/type/codec/SingleFieldDecimalTest.java 2008-02-18 19:28:30 UTC (rev 135) @@ -22,6 +22,7 @@ package org.openfast.template.type.codec; +import org.openfast.DecimalValue; import org.openfast.error.FastConstants; import org.openfast.error.FastException; @@ -30,6 +31,11 @@ public class SingleFieldDecimalTest extends OpenFastTestCase { + public void testEncodeDecodeBoundary() { + assertEncodeDecode(new DecimalValue(Long.MAX_VALUE, 63), "10111111 00000000 01111111 01111111 01111111 01111111 01111111 01111111 01111111 01111111 11111111", TypeCodec.SF_SCALED_NUMBER); + assertEncodeDecode(new DecimalValue(Long.MIN_VALUE, -63), "11000001 01111111 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 10000000", TypeCodec.SF_SCALED_NUMBER); + } + public void testEncodeDecode() { assertEncodeDecode(94275500, "10000010 00111001 01000101 10100011"); assertEncodeDecode(9427.55, "11111110 00111001 01000101 10100011"); Modified: trunk/src/test/java/org/openfast/test/OpenFastTestCase.java =================================================================== --- trunk/src/test/java/org/openfast/test/OpenFastTestCase.java 2008-02-07 16:46:47 UTC (rev 134) +++ trunk/src/test/java/org/openfast/test/OpenFastTestCase.java 2008-02-18 19:28:30 UTC (rev 135) @@ -17,18 +17,19 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ + */ - package org.openfast.test; import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.math.BigDecimal; import java.util.Calendar; import java.util.Date; import javax.xml.parsers.DocumentBuilderFactory; +import junit.framework.AssertionFailedError; import junit.framework.TestCase; import org.openfast.ByteUtil; @@ -58,10 +59,11 @@ import org.w3c.dom.Document; import org.xml.sax.InputSource; +public abstract class OpenFastTestCase extends TestCase { + protected static final ScalarValue NULL = ScalarValue.NULL; -public abstract class OpenFastTestCase extends TestCase { - protected static final ScalarValue NULL = ScalarValue.NULL; - protected static final ScalarValue UNDEF = ScalarValue.UNDEFINED; + protected static final ScalarValue UNDEF = ScalarValue.UNDEFINED; + public static DecimalValue d(double value) { return new DecimalValue(value); } @@ -82,18 +84,17 @@ TestUtil.assertBitVectorEquals(bitString, encoding); } - protected static void assertEncodeDecode(ScalarValue value, - String bitString, TypeCodec type) { + protected static void assertEncodeDecode(ScalarValue value, String bitString, TypeCodec type) { assertEquals(bitString, type.encode(value == null ? ScalarValue.NULL : value)); assertEquals(value, type.decode(ByteUtil.createByteStream(bitString))); } - protected static InputStream bitStream(String bitString) { + protected static InputStream bitStream(String bitString) { return ByteUtil.createByteStream(bitString); } - + protected static InputStream stream(String source) { - return new ByteArrayInputStream(source.getBytes()); + return new ByteArrayInputStream(source.getBytes()); } protected static InputStream byteStream(byte[] bytes) { @@ -101,151 +102,162 @@ } protected static ByteVectorValue byt(byte[] value) { - return new ByteVectorValue(value); - } + return new ByteVectorValue(value); + } - protected static FastDecoder decoder(String bitString, MessageTemplate template) { - Context context = new Context(); - context.registerTemplate(1, template); - return new FastDecoder(context, bitStream(bitString)); - } + protected static FastDecoder decoder(String bitString, MessageTemplate template) { + Context context = new Context(); + context.registerTemplate(1, template); + return new FastDecoder(context, bitStream(bitString)); + } - protected static FastDecoder decoder(MessageTemplate template, byte[] encoding) { - Context context = new Context(); - context.registerTemplate(1, template); - return new FastDecoder(context, new ByteArrayInputStream(encoding)); - } + protected static FastDecoder decoder(MessageTemplate template, byte[] encoding) { + Context context = new Context(); + context.registerTemplate(1, template); + return new FastDecoder(context, new ByteArrayInputStream(encoding)); + } - protected static FastEncoder encoder(MessageTemplate template) { - Context context = new Context(); - context.registerTemplate(1, template); - return new FastEncoder(context); - } + protected static FastEncoder encoder(MessageTemplate template) { + Context context = new Context(); + context.registerTemplate(1, template); + return new FastEncoder(context); + } - protected static Date date(int year, int month, int day) { - Calendar cal = Calendar.getInstance(); - cal.set(year, month, day, 0, 0, 0); - cal.set(Calendar.MILLISECOND, 0); - return cal.getTime(); - } + protected static Date date(int year, int month, int day) { + Calendar cal = Calendar.getInstance(); + cal.set(year, month, day, 0, 0, 0); + cal.set(Calendar.MILLISECOND, 0); + return cal.getTime(); + } - protected static Date time(int hour, int min, int sec, int ms) { - Calendar cal = Calendar.getInstance(); - cal.set(Calendar.HOUR_OF_DAY, hour); - cal.set(Calendar.MINUTE, min); - cal.set(Calendar.SECOND, sec); - cal.set(Calendar.MILLISECOND, ms); - return cal.getTime(); - } + protected static Date time(int hour, int min, int sec, int ms) { + Calendar cal = Calendar.getInstance(); + cal.set(Calendar.HOUR_OF_DAY, hour); + cal.set(Calendar.MINUTE, min); + cal.set(Calendar.SECOND, sec); + cal.set(Calendar.MILLISECOND, ms); + return cal.getTime(); + } - protected byte[] byt(String hexString) { - return ByteUtil.convertHexStringToByteArray(hexString); - } + protected byte[] byt(String hexString) { + return ByteUtil.convertHexStringToByteArray(hexString); + } - protected DecimalValue d(int mantissa, int exponent) { + protected DecimalValue d(int mantissa, int exponent) { return n... [truncated message content] |
From: <ope...@li...> - 2008-02-07 16:47:21
|
Revision: 134 http://openfast.svn.sourceforge.net/openfast/?rev=134&view=rev Author: jacob_northey Date: 2008-02-07 08:46:47 -0800 (Thu, 07 Feb 2008) Log Message: ----------- [maven-release-plugin] prepare for next development iteration Modified Paths: -------------- trunk/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2008-02-07 16:46:24 UTC (rev 133) +++ trunk/pom.xml 2008-02-07 16:46:47 UTC (rev 134) @@ -4,7 +4,7 @@ <groupId>org.openfast</groupId> <artifactId>openfast</artifactId> <packaging>jar</packaging> - <version>0.9.7</version> + <version>0.9.8-SNAPSHOT</version> <organization> <name>The LaSalle Technology Group, LLC</name> @@ -66,9 +66,9 @@ </issueManagement> <scm> - <connection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.7</connection> - <developerConnection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.7</developerConnection> - <url>http://openfast.svn.sourceforge.net/viewvc/openfast/tags/openfast-0.9.7</url> + <connection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.5</connection> + <developerConnection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.5</developerConnection> + <url>http://openfast.svn.sourceforge.net/viewvc/openfast/tags/openfast-0.9.5</url> </scm> <mailingLists> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-02-07 16:46:38
|
Revision: 133 http://openfast.svn.sourceforge.net/openfast/?rev=133&view=rev Author: jacob_northey Date: 2008-02-07 08:46:24 -0800 (Thu, 07 Feb 2008) Log Message: ----------- [maven-release-plugin] copy for tag openfast-0.9.7 Added Paths: ----------- tags/openfast-0.9.7/ tags/openfast-0.9.7/pom.xml tags/openfast-0.9.7/src/main/java/org/openfast/DecimalValue.java tags/openfast-0.9.7/src/main/java/org/openfast/template/operator/DefaultOperatorCodec.java tags/openfast-0.9.7/src/main/java/org/openfast/template/operator/Operator.java tags/openfast-0.9.7/src/main/java/org/openfast/template/type/DecimalConverter.java tags/openfast-0.9.7/src/main/java/org/openfast/template/type/codec/NullableSingleFieldDecimal.java tags/openfast-0.9.7/src/main/java/org/openfast/template/type/codec/SingleFieldDecimal.java tags/openfast-0.9.7/src/test/java/org/openfast/submitted/LargeValuesTest.java tags/openfast-0.9.7/src/test/java/org/openfast/template/operator/DefaultOperatorTest.java tags/openfast-0.9.7/src/test/java/org/openfast/template/type/codec/ComposedDecimalTest.java Removed Paths: ------------- tags/openfast-0.9.7/pom.xml tags/openfast-0.9.7/src/main/java/org/openfast/DecimalValue.java tags/openfast-0.9.7/src/main/java/org/openfast/template/operator/DefaultOperatorCodec.java tags/openfast-0.9.7/src/main/java/org/openfast/template/operator/Operator.java tags/openfast-0.9.7/src/main/java/org/openfast/template/type/DecimalConverter.java tags/openfast-0.9.7/src/main/java/org/openfast/template/type/codec/NullableSingleFieldDecimal.java tags/openfast-0.9.7/src/main/java/org/openfast/template/type/codec/SingleFieldDecimal.java tags/openfast-0.9.7/src/test/java/org/openfast/template/operator/DefaultOperatorTest.java tags/openfast-0.9.7/src/test/java/org/openfast/template/type/codec/ComposedDecimalTest.java Copied: tags/openfast-0.9.7 (from rev 130, trunk) Deleted: tags/openfast-0.9.7/pom.xml =================================================================== --- trunk/pom.xml 2008-02-07 16:34:58 UTC (rev 130) +++ tags/openfast-0.9.7/pom.xml 2008-02-07 16:46:24 UTC (rev 133) @@ -1,188 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>org.openfast</groupId> - <artifactId>openfast</artifactId> - <packaging>jar</packaging> - <version>0.9.7-SNAPSHOT</version> - - <organization> - <name>The LaSalle Technology Group, LLC</name> - <url>http://www.lasalletech.com</url> - </organization> - - <name>OpenFAST</name> - - <description>OpenFAST is a 100% Java implementation of the FAST Protocol.</description> - - <developers> - <developer> - <name>Jacob Northey</name> - <organization>Lasalletech</organization> - <organizationUrl>http://www.lasalletech.com/</organizationUrl> - <roles> - <role>architect</role> - <role>developer</role> - </roles> - <timezone>-5</timezone> - </developer> - <developer> - <name>Craig Otis</name> - <organization>Lasalletech</organization> - <organizationUrl>http://www.lasalletech.com/</organizationUrl> - <roles> - <role>developer</role> - </roles> - <timezone>-5</timezone> - </developer> - </developers> - - <contributors> - <contributor> - <name>Stefan Schwendiman</name> - <organization>Swiss Exchange</organization> - <organizationUrl>http://www.swx.com</organizationUrl> - <roles> - <role>tester</role> - </roles> - <timezone>+1</timezone> - </contributor> - </contributors> - - <licenses> - <license> - <name>Mozilla Public License Version 1.1</name> - <url>http://www.mozilla.org/MPL/MPL-1.1.html</url> - <distribution>repo</distribution> - </license> - </licenses> - - <url>http://www.openfast.org</url> - <inceptionYear>2006</inceptionYear> - - <issueManagement> - <system>sourceforge</system> - <url>http://sourceforge.net/tracker/?group_id=198357</url> - </issueManagement> - - <scm> - <connection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.5</connection> - <developerConnection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.5</developerConnection> - <url>http://openfast.svn.sourceforge.net/viewvc/openfast/tags/openfast-0.9.5</url> - </scm> - - <mailingLists> - <mailingList> - <name>OpenFAST Users Mailing List</name> - <subscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-user</subscribe> - <unsubscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-user</unsubscribe> - <archive>https://sourceforge.net/mailarchive/forum.php?forum_name=openfast-user</archive> - <post>ope...@li...</post> - </mailingList> - <mailingList> - <name>OpenFAST Commits Mailing List</name> - <subscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-commit</subscribe> - <unsubscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-commit</unsubscribe> - <archive>https://sourceforge.net/mailarchive/forum.php?forum_name=openfast-commit</archive> - <post>ope...@li...</post> - </mailingList> - <mailingList> - <name>OpenFAST Announcements Mailing List</name> - <subscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-announce</subscribe> - <unsubscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-announce</unsubscribe> - <archive>https://sourceforge.net/mailarchive/forum.php?forum_name=openfast-announce</archive> - <post>ope...@li...</post> - </mailingList> - </mailingLists> - - <build> - <resources> - <resource> - <directory>src/main/resources</directory> - </resource> - <resource> - <directory>src/test/resources</directory> - </resource> - </resources> - <extensions> - <extension> - <groupId>org.apache.maven.wagon</groupId> - <artifactId>wagon-ssh</artifactId> - <version>1.0-beta-2</version> - </extension> - </extensions> - - <plugins> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.4</source> - <target>1.4</target> - </configuration> - </plugin> - <plugin> - <artifactId>maven-release-plugin</artifactId> - <configuration> - <tagBase>https://openfast.svn.sourceforge.net/svnroot/openfast/tags</tagBase> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-javadoc-plugin</artifactId> - <executions> - <execution> - <id>javadoc</id> - <phase>process-classes</phase> - <goals> - <goal>javadoc</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <artifactId>maven-assembly-plugin</artifactId> - <configuration> - <descriptors> - <descriptor>src/assembly/source.xml</descriptor> - </descriptors> - </configuration> - <executions> - <execution> - <id>make-assembly</id> - <phase>package</phase> - <goals> - <goal>attached</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.2</version> - <scope>test</scope> - </dependency> - </dependencies> - - <distributionManagement> - <repository> - <id>sourceforge.net</id> - <name>Sourceforge.net Repository</name> - <url>scp://shell.sourceforge.net/home/groups/o/op/openfast/htdocs/maven/release</url> - </repository> - <snapshotRepository> - <id>sourceforge.net</id> - <name>Sourceforge.net Snapshot Repository</name> - <url>scp://shell.sourceforge.net/home/groups/o/op/openfast/htdocs/maven/snapshot</url> - </snapshotRepository> - <site> - <id>sourceforge.net</id> - <name>Sourceforge.net OpenFAST Web Site</name> - <url>scp://shell.sourceforge.net/home/groups/o/op/openfast/htdocs/</url> - </site> - </distributionManagement> -</project> \ No newline at end of file Copied: tags/openfast-0.9.7/pom.xml (from rev 132, trunk/pom.xml) =================================================================== --- tags/openfast-0.9.7/pom.xml (rev 0) +++ tags/openfast-0.9.7/pom.xml 2008-02-07 16:46:24 UTC (rev 133) @@ -0,0 +1,188 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.openfast</groupId> + <artifactId>openfast</artifactId> + <packaging>jar</packaging> + <version>0.9.7</version> + + <organization> + <name>The LaSalle Technology Group, LLC</name> + <url>http://www.lasalletech.com</url> + </organization> + + <name>OpenFAST</name> + + <description>OpenFAST is a 100% Java implementation of the FAST Protocol.</description> + + <developers> + <developer> + <name>Jacob Northey</name> + <organization>Lasalletech</organization> + <organizationUrl>http://www.lasalletech.com/</organizationUrl> + <roles> + <role>architect</role> + <role>developer</role> + </roles> + <timezone>-5</timezone> + </developer> + <developer> + <name>Craig Otis</name> + <organization>Lasalletech</organization> + <organizationUrl>http://www.lasalletech.com/</organizationUrl> + <roles> + <role>developer</role> + </roles> + <timezone>-5</timezone> + </developer> + </developers> + + <contributors> + <contributor> + <name>Stefan Schwendiman</name> + <organization>Swiss Exchange</organization> + <organizationUrl>http://www.swx.com</organizationUrl> + <roles> + <role>tester</role> + </roles> + <timezone>+1</timezone> + </contributor> + </contributors> + + <licenses> + <license> + <name>Mozilla Public License Version 1.1</name> + <url>http://www.mozilla.org/MPL/MPL-1.1.html</url> + <distribution>repo</distribution> + </license> + </licenses> + + <url>http://www.openfast.org</url> + <inceptionYear>2006</inceptionYear> + + <issueManagement> + <system>sourceforge</system> + <url>http://sourceforge.net/tracker/?group_id=198357</url> + </issueManagement> + + <scm> + <connection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.7</connection> + <developerConnection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.7</developerConnection> + <url>http://openfast.svn.sourceforge.net/viewvc/openfast/tags/openfast-0.9.7</url> + </scm> + + <mailingLists> + <mailingList> + <name>OpenFAST Users Mailing List</name> + <subscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-user</subscribe> + <unsubscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-user</unsubscribe> + <archive>https://sourceforge.net/mailarchive/forum.php?forum_name=openfast-user</archive> + <post>ope...@li...</post> + </mailingList> + <mailingList> + <name>OpenFAST Commits Mailing List</name> + <subscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-commit</subscribe> + <unsubscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-commit</unsubscribe> + <archive>https://sourceforge.net/mailarchive/forum.php?forum_name=openfast-commit</archive> + <post>ope...@li...</post> + </mailingList> + <mailingList> + <name>OpenFAST Announcements Mailing List</name> + <subscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-announce</subscribe> + <unsubscribe>http://lists.sourceforge.net/mailman/listinfo/openfast-announce</unsubscribe> + <archive>https://sourceforge.net/mailarchive/forum.php?forum_name=openfast-announce</archive> + <post>ope...@li...</post> + </mailingList> + </mailingLists> + + <build> + <resources> + <resource> + <directory>src/main/resources</directory> + </resource> + <resource> + <directory>src/test/resources</directory> + </resource> + </resources> + <extensions> + <extension> + <groupId>org.apache.maven.wagon</groupId> + <artifactId>wagon-ssh</artifactId> + <version>1.0-beta-2</version> + </extension> + </extensions> + + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.4</source> + <target>1.4</target> + </configuration> + </plugin> + <plugin> + <artifactId>maven-release-plugin</artifactId> + <configuration> + <tagBase>https://openfast.svn.sourceforge.net/svnroot/openfast/tags</tagBase> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <executions> + <execution> + <id>javadoc</id> + <phase>process-classes</phase> + <goals> + <goal>javadoc</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <configuration> + <descriptors> + <descriptor>src/assembly/source.xml</descriptor> + </descriptors> + </configuration> + <executions> + <execution> + <id>make-assembly</id> + <phase>package</phase> + <goals> + <goal>attached</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.2</version> + <scope>test</scope> + </dependency> + </dependencies> + + <distributionManagement> + <repository> + <id>sourceforge.net</id> + <name>Sourceforge.net Repository</name> + <url>scp://shell.sourceforge.net/home/groups/o/op/openfast/htdocs/maven/release</url> + </repository> + <snapshotRepository> + <id>sourceforge.net</id> + <name>Sourceforge.net Snapshot Repository</name> + <url>scp://shell.sourceforge.net/home/groups/o/op/openfast/htdocs/maven/snapshot</url> + </snapshotRepository> + <site> + <id>sourceforge.net</id> + <name>Sourceforge.net OpenFAST Web Site</name> + <url>scp://shell.sourceforge.net/home/groups/o/op/openfast/htdocs/</url> + </site> + </distributionManagement> +</project> \ No newline at end of file Deleted: tags/openfast-0.9.7/src/main/java/org/openfast/DecimalValue.java =================================================================== --- trunk/src/main/java/org/openfast/DecimalValue.java 2008-02-07 16:34:58 UTC (rev 130) +++ tags/openfast-0.9.7/src/main/java/org/openfast/DecimalValue.java 2008-02-07 16:46:24 UTC (rev 133) @@ -1,150 +0,0 @@ -/* -The contents of this file are subject to the Mozilla Public License -Version 1.1 (the "License"); you may not use this file except in -compliance with the License. You may obtain a copy of the License at -http://www.mozilla.org/MPL/ - -Software distributed under the License is distributed on an "AS IS" -basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -License for the specific language governing rights and limitations -under the License. - -The Original Code is OpenFAST. - -The Initial Developer of the Original Code is The LaSalle Technology -Group, LLC. Portions created by The LaSalle Technology Group, LLC -are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. - -Contributor(s): Jacob Northey <ja...@la...> - Craig Otis <co...@la...> -*/ - - -package org.openfast; - -import java.math.BigDecimal; - -import org.openfast.error.FastConstants; - - -public class DecimalValue extends NumericValue { - private static final long serialVersionUID = 1L; - public final double value; - public final int exponent; - public final int mantissa; - - public DecimalValue(double value) { - if (value == 0.0) { - this.value = 0.0; - this.exponent = 0; - this.mantissa = 0; - - return; - } - - this.value = value; - - BigDecimal decimalValue = BigDecimal.valueOf(value); - int exponent = decimalValue.scale(); - int mantissa = decimalValue.unscaledValue().intValue(); - - while (((mantissa % 10) == 0) && (mantissa != 0)) { - mantissa /= 10; - exponent -= 1; - } - - this.mantissa = mantissa; - this.exponent = -exponent; - } - - public DecimalValue(int mantissa, int exponent) { - this.mantissa = mantissa; - this.exponent = exponent; - - if (exponent < 0) { - this.value = mantissa / Math.pow(10, -exponent); - } else { - this.value = mantissa * Math.pow(10, exponent); - } - } - - public NumericValue increment() { - return null; - } - - public NumericValue decrement() { - return null; - } - - public boolean isNull() { - return false; - } - - public boolean equals(Object obj) { - if ((obj == null) || !(obj instanceof DecimalValue)) { - return false; - } - - return equals((DecimalValue) obj); - } - - public boolean equals(DecimalValue other) { - return other.value == this.value; - } - - public NumericValue subtract(NumericValue priorValue) { - return new DecimalValue(this.value - ((DecimalValue) priorValue).value); - } - - public NumericValue add(NumericValue addend) { - return new DecimalValue(((DecimalValue) addend).value + this.value); - } - - public String serialize() { - return String.valueOf(value); - } - - public boolean equals(int value) { - return (double) value == this.value; - } - - public long toLong() { - if (exponent < 0) - Global.handleError(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, ""); - return (long) value; - } - - public int toInt() { - if (exponent < 0) - Global.handleError(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, ""); - return (int) value; - } - - public short toShort() { - if (exponent < 0) - Global.handleError(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, ""); - return (short) value; - } - - public byte toByte() { - if (exponent < 0) - Global.handleError(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, ""); - return (byte) value; - } - - public double toDouble() { - return value; - } - - public BigDecimal toBigDecimal() { - return new BigDecimal(value); - } - - public String toString() { - return String.valueOf(value); - } - - public int hashCode() { - return exponent * 37 + mantissa; - } -} Copied: tags/openfast-0.9.7/src/main/java/org/openfast/DecimalValue.java (from rev 131, trunk/src/main/java/org/openfast/DecimalValue.java) =================================================================== --- tags/openfast-0.9.7/src/main/java/org/openfast/DecimalValue.java (rev 0) +++ tags/openfast-0.9.7/src/main/java/org/openfast/DecimalValue.java 2008-02-07 16:46:24 UTC (rev 133) @@ -0,0 +1,151 @@ +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> + */ + +package org.openfast; + +import java.math.BigDecimal; + +import org.openfast.error.FastConstants; + +public class DecimalValue extends NumericValue { + private static final long serialVersionUID = 1L; + + public final double value; + + public final int exponent; + + public final long mantissa; + + public DecimalValue(double value) { + if (value == 0.0) { + this.value = 0.0; + this.exponent = 0; + this.mantissa = 0; + + return; + } + + this.value = value; + + BigDecimal decimalValue = BigDecimal.valueOf(value); + int exponent = decimalValue.scale(); + long mantissa = decimalValue.unscaledValue().longValue(); + + while (((mantissa % 10) == 0) && (mantissa != 0)) { + mantissa /= 10; + exponent -= 1; + } + + this.mantissa = mantissa; + this.exponent = -exponent; + } + + public DecimalValue(long mantissa, int exponent) { + this.mantissa = mantissa; + this.exponent = exponent; + + if (exponent < 0) { + this.value = mantissa / Math.pow(10, -exponent); + } else { + this.value = mantissa * Math.pow(10, exponent); + } + } + + public NumericValue increment() { + return null; + } + + public NumericValue decrement() { + return null; + } + + public boolean isNull() { + return false; + } + + public boolean equals(Object obj) { + if ((obj == null) || !(obj instanceof DecimalValue)) { + return false; + } + + return equals((DecimalValue) obj); + } + + public boolean equals(DecimalValue other) { + return other.value == this.value; + } + + public NumericValue subtract(NumericValue priorValue) { + return new DecimalValue(this.value - ((DecimalValue) priorValue).value); + } + + public NumericValue add(NumericValue addend) { + return new DecimalValue(((DecimalValue) addend).value + this.value); + } + + public String serialize() { + return String.valueOf(value); + } + + public boolean equals(int value) { + return (double) value == this.value; + } + + public long toLong() { + if (exponent < 0) + Global.handleError(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, ""); + return (long) value; + } + + public int toInt() { + if (exponent < 0) + Global.handleError(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, ""); + return (int) value; + } + + public short toShort() { + if (exponent < 0) + Global.handleError(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, ""); + return (short) value; + } + + public byte toByte() { + if (exponent < 0) + Global.handleError(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, ""); + return (byte) value; + } + + public double toDouble() { + return value; + } + + public BigDecimal toBigDecimal() { + return new BigDecimal(value); + } + + public String toString() { + return String.valueOf(value); + } + + public int hashCode() { + return exponent * 37 + (int) mantissa; + } +} Deleted: tags/openfast-0.9.7/src/main/java/org/openfast/template/operator/DefaultOperatorCodec.java =================================================================== --- trunk/src/main/java/org/openfast/template/operator/DefaultOperatorCodec.java 2008-02-07 16:34:58 UTC (rev 130) +++ tags/openfast-0.9.7/src/main/java/org/openfast/template/operator/DefaultOperatorCodec.java 2008-02-07 16:46:24 UTC (rev 133) @@ -1,39 +0,0 @@ -/** - * - */ -package org.openfast.template.operator; - -import org.openfast.ScalarValue; -import org.openfast.template.Scalar; -import org.openfast.template.type.Type; - -final class DefaultOperatorCodec extends OperatorCodec { - private static final long serialVersionUID = 1L; - - DefaultOperatorCodec(Operator operator, Type[] types) { - super(operator, types); - } - - public ScalarValue getValueToEncode(ScalarValue value, ScalarValue priorValue, Scalar field) { - if (value == null) { - if (field.getDefaultValue().isUndefined()) - return null; - return ScalarValue.NULL; - } - - return value.equals(field.getDefaultValue()) ? null : value; - } - - public ScalarValue decodeValue(ScalarValue newValue, ScalarValue previousValue, Scalar field) { - return newValue; - } - - public ScalarValue decodeEmptyValue(ScalarValue previousValue, Scalar field) { - if (field.getDefaultValue().isUndefined()) return null; - return field.getDefaultValue(); - } - - public boolean equals(Object obj) { - return obj != null && obj.getClass() == getClass(); - } -} \ No newline at end of file Copied: tags/openfast-0.9.7/src/main/java/org/openfast/template/operator/DefaultOperatorCodec.java (from rev 131, trunk/src/main/java/org/openfast/template/operator/DefaultOperatorCodec.java) =================================================================== --- tags/openfast-0.9.7/src/main/java/org/openfast/template/operator/DefaultOperatorCodec.java (rev 0) +++ tags/openfast-0.9.7/src/main/java/org/openfast/template/operator/DefaultOperatorCodec.java 2008-02-07 16:46:24 UTC (rev 133) @@ -0,0 +1,40 @@ +/** + * + */ +package org.openfast.template.operator; + +import org.openfast.ScalarValue; +import org.openfast.template.Scalar; +import org.openfast.template.type.Type; + +final class DefaultOperatorCodec extends OperatorCodec { + private static final long serialVersionUID = 1L; + + DefaultOperatorCodec(Operator operator, Type[] types) { + super(operator, types); + } + + public ScalarValue getValueToEncode(ScalarValue value, ScalarValue priorValue, Scalar field) { + if (value == null) { + if (field.getDefaultValue().isUndefined()) + return null; + return ScalarValue.NULL; + } + + return value.equals(field.getDefaultValue()) ? null : value; + } + + public ScalarValue decodeValue(ScalarValue newValue, ScalarValue previousValue, Scalar field) { + return newValue; + } + + public ScalarValue decodeEmptyValue(ScalarValue previousValue, Scalar field) { + if (field.getDefaultValue().isUndefined()) + return null; + return field.getDefaultValue(); + } + + public boolean equals(Object obj) { + return obj != null && obj.getClass() == getClass(); + } +} Deleted: tags/openfast-0.9.7/src/main/java/org/openfast/template/operator/Operator.java =================================================================== --- trunk/src/main/java/org/openfast/template/operator/Operator.java 2008-02-07 16:34:58 UTC (rev 130) +++ tags/openfast-0.9.7/src/main/java/org/openfast/template/operator/Operator.java 2008-02-07 16:46:24 UTC (rev 133) @@ -1,115 +0,0 @@ -package org.openfast.template.operator; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; - -import org.openfast.Global; -import org.openfast.ScalarValue; -import org.openfast.error.FastConstants; -import org.openfast.template.Scalar; -import org.openfast.template.type.Type; - -public class Operator implements Serializable { - private static final long serialVersionUID = 1L; - private static final Map OPERATOR_NAME_MAP = new HashMap(); - private final String name; - - public static final Operator NONE = new Operator("none") { - private static final long serialVersionUID = 2L; - public boolean usesDictionary() { - return false; - } - public boolean shouldStoreValue(ScalarValue value) { - return false; - } - }; - public static final Operator CONSTANT = new Operator("constant") { - private static final long serialVersionUID = 1L; - - public void validate(Scalar scalar) { - if (scalar.getDefaultValue().isUndefined()) - Global.handleError(FastConstants.S4_NO_INITIAL_VALUE_FOR_CONST, "The field " + scalar + " must have a default value defined."); - } - - public boolean shouldStoreValue(ScalarValue value) { - return false; - } - - public boolean usesDictionary() { - return false; - } - }; - public static final Operator DEFAULT = new Operator("default") { - private static final long serialVersionUID = 1L; - - public void validate(Scalar scalar) { - if (!scalar.isOptional() && scalar.getDefaultValue().isUndefined()) - Global.handleError(FastConstants.S5_NO_INITVAL_MNDTRY_DFALT, "The field " + scalar + " must have a default value defined."); - } - }; - public static final Operator COPY = new Operator("copy") { - private static final long serialVersionUID = 1L; - - public OperatorCodec getCodec(Type type) { - return OperatorCodec.COPY_ALL; - } - }; - public static final Operator INCREMENT = new Operator("increment"); - public static final Operator DELTA = new Operator("delta") { - private static final long serialVersionUID = 1L; - - public boolean shouldStoreValue(ScalarValue value) { - return value != null; - } - }; - public static final Operator TAIL = new Operator("tail"); - - public Operator(String name) { - this.name = name; - OPERATOR_NAME_MAP.put(name, this); - } - - public static Operator getOperator(String name) { - if (!OPERATOR_NAME_MAP.containsKey(name)) - throw new IllegalArgumentException("The operator \"" + name + "\" does not exist."); - return (Operator) OPERATOR_NAME_MAP.get(name); - } - - public OperatorCodec getCodec(Type type) { - return OperatorCodec.getCodec(this, type); - } - - public String toString() { - return name; - } - - public String getName() { - return name; - } - - public boolean shouldStoreValue(ScalarValue value) { - return true; - } - - public void validate(Scalar scalar) { - } - - public boolean equals(Object other) { - if (other == this) return true; - if (other == null || !(other instanceof Operator)) return false; - return equals((Operator) other); - } - - private boolean equals(Operator other) { - return name.equals(other.name); - } - - public int hashCode() { - return name.hashCode(); - } - - public boolean usesDictionary() { - return true; - } -} Copied: tags/openfast-0.9.7/src/main/java/org/openfast/template/operator/Operator.java (from rev 131, trunk/src/main/java/org/openfast/template/operator/Operator.java) =================================================================== --- tags/openfast-0.9.7/src/main/java/org/openfast/template/operator/Operator.java (rev 0) +++ tags/openfast-0.9.7/src/main/java/org/openfast/template/operator/Operator.java 2008-02-07 16:46:24 UTC (rev 133) @@ -0,0 +1,133 @@ +package org.openfast.template.operator; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import org.openfast.Global; +import org.openfast.ScalarValue; +import org.openfast.error.FastConstants; +import org.openfast.template.Scalar; +import org.openfast.template.type.Type; + +public class Operator implements Serializable { + private static final long serialVersionUID = 1L; + + private static final Map OPERATOR_NAME_MAP = new HashMap(); + + private final String name; + + public static final Operator NONE = new Operator("none") { + private static final long serialVersionUID = 2L; + + public boolean usesDictionary() { + return false; + } + + public boolean shouldStoreValue(ScalarValue value) { + return false; + } + }; + + public static final Operator CONSTANT = new Operator("constant") { + private static final long serialVersionUID = 1L; + + public void validate(Scalar scalar) { + if (scalar.getDefaultValue().isUndefined()) + Global.handleError(FastConstants.S4_NO_INITIAL_VALUE_FOR_CONST, "The field " + scalar + + " must have a default value defined."); + } + + public boolean shouldStoreValue(ScalarValue value) { + return false; + } + + public boolean usesDictionary() { + return false; + } + }; + + public static final Operator DEFAULT = new Operator("default") { + private static final long serialVersionUID = 1L; + + public void validate(Scalar scalar) { + if (!scalar.isOptional() && scalar.getDefaultValue().isUndefined()) + Global.handleError(FastConstants.S5_NO_INITVAL_MNDTRY_DFALT, "The field " + scalar + + " must have a default value defined."); + } + + public boolean shouldStoreValue(ScalarValue value) { + return value != null; + } + }; + + public static final Operator COPY = new Operator("copy") { + private static final long serialVersionUID = 1L; + + public OperatorCodec getCodec(Type type) { + return OperatorCodec.COPY_ALL; + } + }; + + public static final Operator INCREMENT = new Operator("increment"); + + public static final Operator DELTA = new Operator("delta") { + private static final long serialVersionUID = 1L; + + public boolean shouldStoreValue(ScalarValue value) { + return value != null; + } + }; + + public static final Operator TAIL = new Operator("tail"); + + public Operator(String name) { + this.name = name; + OPERATOR_NAME_MAP.put(name, this); + } + + public static Operator getOperator(String name) { + if (!OPERATOR_NAME_MAP.containsKey(name)) + throw new IllegalArgumentException("The operator \"" + name + "\" does not exist."); + return (Operator) OPERATOR_NAME_MAP.get(name); + } + + public OperatorCodec getCodec(Type type) { + return OperatorCodec.getCodec(this, type); + } + + public String toString() { + return name; + } + + public String getName() { + return name; + } + + public boolean shouldStoreValue(ScalarValue value) { + return true; + } + + public void validate(Scalar scalar) { + } + + public boolean equals(Object other) { + if (other == this) + return true; + if (other == null || !(other instanceof Operator)) + return false; + return equals((Operator) other); + } + + private boolean equals(Operator other) { + return name.equals(other.name); + } + + public int hashCode() { + return name.hashCode(); + } + + public boolean usesDictionary() { + return true; + } +} Deleted: tags/openfast-0.9.7/src/main/java/org/openfast/template/type/DecimalConverter.java =================================================================== --- trunk/src/main/java/org/openfast/template/type/DecimalConverter.java 2008-02-07 16:34:58 UTC (rev 130) +++ tags/openfast-0.9.7/src/main/java/org/openfast/template/type/DecimalConverter.java 2008-02-07 16:46:24 UTC (rev 133) @@ -1,28 +0,0 @@ -package org.openfast.template.type; - -import org.openfast.DecimalValue; -import org.openfast.FieldValue; -import org.openfast.IntegerValue; -import org.openfast.ScalarValue; -import org.openfast.template.ComposedValueConverter; - -public class DecimalConverter implements ComposedValueConverter { - - private static final FieldValue[] NULL_SET = new FieldValue[] { null, null }; - private static final FieldValue[] UNDEFINED_SET = new FieldValue[] { ScalarValue.UNDEFINED, ScalarValue.UNDEFINED }; - - public FieldValue[] split(FieldValue value) { - if (value == null) - return NULL_SET; - else if (value == ScalarValue.UNDEFINED) - return UNDEFINED_SET; - DecimalValue decimal = (DecimalValue) value; - return new FieldValue[] { new IntegerValue(decimal.exponent), new IntegerValue(decimal.mantissa) }; - } - - public FieldValue compose(FieldValue[] values) { - if (values[0] == null) return null; - if (values[0] == ScalarValue.UNDEFINED) return ScalarValue.UNDEFINED; - return new DecimalValue(((IntegerValue) values[1]).value, ((IntegerValue) values[0]).value); - } -} Copied: tags/openfast-0.9.7/src/main/java/org/openfast/template/type/DecimalConverter.java (from rev 131, trunk/src/main/java/org/openfast/template/type/DecimalConverter.java) =================================================================== --- tags/openfast-0.9.7/src/main/java/org/openfast/template/type/DecimalConverter.java (rev 0) +++ tags/openfast-0.9.7/src/main/java/org/openfast/template/type/DecimalConverter.java 2008-02-07 16:46:24 UTC (rev 133) @@ -0,0 +1,32 @@ +package org.openfast.template.type; + +import org.openfast.DecimalValue; +import org.openfast.FieldValue; +import org.openfast.IntegerValue; +import org.openfast.ScalarValue; +import org.openfast.template.ComposedValueConverter; +import org.openfast.template.LongValue; + +public class DecimalConverter implements ComposedValueConverter { + + private static final FieldValue[] NULL_SET = new FieldValue[] { null, null }; + + private static final FieldValue[] UNDEFINED_SET = new FieldValue[] { ScalarValue.UNDEFINED, ScalarValue.UNDEFINED }; + + public FieldValue[] split(FieldValue value) { + if (value == null) + return NULL_SET; + else if (value == ScalarValue.UNDEFINED) + return UNDEFINED_SET; + DecimalValue decimal = (DecimalValue) value; + return new FieldValue[] { new IntegerValue(decimal.exponent), new LongValue(decimal.mantissa) }; + } + + public FieldValue compose(FieldValue[] values) { + if (values[0] == null) + return null; + if (values[0] == ScalarValue.UNDEFINED) + return ScalarValue.UNDEFINED; + return new DecimalValue(((ScalarValue)values[1]).toLong(), ((IntegerValue) values[0]).value); + } +} Deleted: tags/openfast-0.9.7/src/main/java/org/openfast/template/type/codec/NullableSingleFieldDecimal.java =================================================================== --- trunk/src/main/java/org/openfast/template/type/codec/NullableSingleFieldDecimal.java 2008-02-07 16:34:58 UTC (rev 130) +++ tags/openfast-0.9.7/src/main/java/org/openfast/template/type/codec/NullableSingleFieldDecimal.java 2008-02-07 16:46:24 UTC (rev 133) @@ -1,119 +0,0 @@ -/* -The contents of this file are subject to the Mozilla Public License -Version 1.1 (the "License"); you may not use this file except in -compliance with the License. You may obtain a copy of the License at -http://www.mozilla.org/MPL/ - -Software distributed under the License is distributed on an "AS IS" -basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -License for the specific language governing rights and limitations -under the License. - -The Original Code is OpenFAST. - -The Initial Developer of the Original Code is The LaSalle Technology -Group, LLC. Portions created by The LaSalle Technology Group, LLC -are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. - -Contributor(s): Jacob Northey <ja...@la...> - Craig Otis <co...@la...> -*/ - - -/** - * - */ -package org.openfast.template.type.codec; - -import org.openfast.DecimalValue; -import org.openfast.Global; -import org.openfast.IntegerValue; -import org.openfast.ScalarValue; - -import org.openfast.error.FastConstants; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; - - -final class NullableSingleFieldDecimal extends TypeCodec { - private static final long serialVersionUID = 1L; - - NullableSingleFieldDecimal() { } - - /** - * Takes a ScalarValue object, and converts it to a byte array - * @param v The ScalarValue to be encoded - * @return Returns a byte array of the passed object - */ - public byte[] encodeValue(ScalarValue v) { - if (v == ScalarValue.NULL) { - return TypeCodec.NULL_VALUE_ENCODING; - } - - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - DecimalValue value = (DecimalValue) v; - - try { - if (Math.abs(value.exponent) > 63) { - Global.handleError(FastConstants.R1_LARGE_DECIMAL, ""); - } - - buffer.write(TypeCodec.NULLABLE_INTEGER.encode( - new IntegerValue(value.exponent))); - buffer.write(TypeCodec.INTEGER.encode(new IntegerValue(value.mantissa))); - } catch (IOException e) { - throw new RuntimeException(e); - } - - return buffer.toByteArray(); - } - - /** - * Reads in a stream of data and stores it to a decimalValue object - * @param in The InputStream to be decoded - * @return Returns a decimalValue object with the data stream - */ - public ScalarValue decode(InputStream in) { - ScalarValue exp = TypeCodec.NULLABLE_INTEGER.decode(in); - - if ((exp == null) || exp.isNull()) { - return null; - } - - int exponent = ((IntegerValue) exp).value; - int mantissa = ((IntegerValue) TypeCodec.INTEGER.decode(in)).value; - DecimalValue decimalValue = new DecimalValue(mantissa, exponent); - - return decimalValue; - } - - /** - * Convert a string to a DecimalValue object with the string as the passed value - * @param value The value as a string to be converted - * @return Returns a new DecimalValue object - */ - public ScalarValue fromString(String value) { - return new DecimalValue(Double.parseDouble(value)); - } - - /** - * - * @return Returns a new DecimalValue object with a default value - */ - public ScalarValue getDefaultValue() { - return new DecimalValue(0.0); - } - - /** - * @return Returns true - */ - public boolean isNullable() { - return true; - } - - public boolean equals(Object obj) { - return obj != null && obj.getClass() == getClass(); - } -} Copied: tags/openfast-0.9.7/src/main/java/org/openfast/template/type/codec/NullableSingleFieldDecimal.java (from rev 131, trunk/src/main/java/org/openfast/template/type/codec/NullableSingleFieldDecimal.java) =================================================================== --- tags/openfast-0.9.7/src/main/java/org/openfast/template/type/codec/NullableSingleFieldDecimal.java (rev 0) +++ tags/openfast-0.9.7/src/main/java/org/openfast/template/type/codec/NullableSingleFieldDecimal.java 2008-02-07 16:46:24 UTC (rev 133) @@ -0,0 +1,119 @@ +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> +*/ + + +/** + * + */ +package org.openfast.template.type.codec; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.openfast.DecimalValue; +import org.openfast.Global; +import org.openfast.IntegerValue; +import org.openfast.ScalarValue; +import org.openfast.error.FastConstants; +import org.openfast.template.LongValue; + + +final class NullableSingleFieldDecimal extends TypeCodec { + private static final long serialVersionUID = 1L; + + NullableSingleFieldDecimal() { } + + /** + * Takes a ScalarValue object, and converts it to a byte array + * @param v The ScalarValue to be encoded + * @return Returns a byte array of the passed object + */ + public byte[] encodeValue(ScalarValue v) { + if (v == ScalarValue.NULL) { + return TypeCodec.NULL_VALUE_ENCODING; + } + + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + DecimalValue value = (DecimalValue) v; + + try { + if (Math.abs(value.exponent) > 63) { + Global.handleError(FastConstants.R1_LARGE_DECIMAL, ""); + } + + buffer.write(TypeCodec.NULLABLE_INTEGER.encode( + new IntegerValue(value.exponent))); + buffer.write(TypeCodec.INTEGER.encode(new LongValue(value.mantissa))); + } catch (IOException e) { + throw new RuntimeException(e); + } + + return buffer.toByteArray(); + } + + /** + * Reads in a stream of data and stores it to a decimalValue object + * @param in The InputStream to be decoded + * @return Returns a decimalValue object with the data stream + */ + public ScalarValue decode(InputStream in) { + ScalarValue exp = TypeCodec.NULLABLE_INTEGER.decode(in); + + if ((exp == null) || exp.isNull()) { + return null; + } + + int exponent = ((IntegerValue) exp).value; + int mantissa = ((IntegerValue) TypeCodec.INTEGER.decode(in)).value; + DecimalValue decimalValue = new DecimalValue(mantissa, exponent); + + return decimalValue; + } + + /** + * Convert a string to a DecimalValue object with the string as the passed value + * @param value The value as a string to be converted + * @return Returns a new DecimalValue object + */ + public ScalarValue fromString(String value) { + return new DecimalValue(Double.parseDouble(value)); + } + + /** + * + * @return Returns a new DecimalValue object with a default value + */ + public ScalarValue getDefaultValue() { + return new DecimalValue(0.0); + } + + /** + * @return Returns true + */ + public boolean isNullable() { + return true; + } + + public boolean equals(Object obj) { + return obj != null && obj.getClass() == getClass(); + } +} Deleted: tags/openfast-0.9.7/src/main/java/org/openfast/template/type/codec/SingleFieldDecimal.java =================================================================== --- trunk/src/main/java/org/openfast/template/type/codec/SingleFieldDecimal.java 2008-02-07 16:34:58 UTC (rev 130) +++ tags/openfast-0.9.7/src/main/java/org/openfast/template/type/codec/SingleFieldDecimal.java 2008-02-07 16:46:24 UTC (rev 133) @@ -1,112 +0,0 @@ -/* -The contents of this file are subject to the Mozilla Public License -Version 1.1 (the "License"); you may not use this file except in -compliance with the License. You may obtain a copy of the License at -http://www.mozilla.org/MPL/ - -Software distributed under the License is distributed on an "AS IS" -basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -License for the specific language governing rights and limitations -under the License. - -The Original Code is OpenFAST. - -The Initial Developer of the Original Code is The LaSalle Technology -Group, LLC. Portions created by The LaSalle Technology Group, LLC -are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. - -Contributor(s): Jacob Northey <ja...@la...> - Craig Otis <co...@la...> -*/ - - -/** - * - */ -package org.openfast.template.type.codec; - -import org.openfast.DecimalValue; -import org.openfast.Global; -import org.openfast.IntegerValue; -import org.openfast.ScalarValue; - -import org.openfast.error.FastConstants; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; - - -final class SingleFieldDecimal extends TypeCodec { - private static final long serialVersionUID = 1L; - - SingleFieldDecimal() { } - - /** - * Takes a ScalarValue object, and converts it to a byte array - * @param v The ScalarValue to be encoded - * @return Returns a byte array of the passed object - */ - public byte[] encodeValue(ScalarValue v) { - if (v == ScalarValue.NULL) { - return TypeCodec.NULL_VALUE_ENCODING; - } - - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - DecimalValue value = (DecimalValue) v; - - try { - if (Math.abs(value.exponent) > 63) { - Global.handleError(FastConstants.R1_LARGE_DECIMAL, - "Encountered exponent of size " + value.exponent); - } - - buffer.write(TypeCodec.INTEGER.encode(new IntegerValue(value.exponent))); - buffer.write(TypeCodec.INTEGER.encode(new IntegerValue(value.mantissa))); - } catch (IOException e) { - throw new RuntimeException(e); - } - - return buffer.toByteArray(); - } - - /** - * Reads in a stream of data and stores it to a decimalValue object - * @param in The InputStream to be decoded - * @return Returns a decimalValue object with the data stream - */ - public ScalarValue decode(InputStream in) { - int exponent = ((IntegerValue) TypeCodec.INTEGER.decode(in)).value; - - if (Math.abs(exponent) > 63) { - Global.handleError(FastConstants.R1_LARGE_DECIMAL, - "Encountered exponent of size " + exponent); - } - - int mantissa = ((IntegerValue) TypeCodec.INTEGER.decode(in)).value; - DecimalValue decimalValue = new DecimalValue(mantissa, exponent); - - return decimalValue; - } - - /** - * Convert a string to a DecimalValue object with the string as the passed value - * @param value The value as a string to be converted - * @return Returns a new DecimalValue object - */ - public ScalarValue fromString(String value) { - return new DecimalValue(Double.parseDouble(value)); - } - - /** - * - * @return Returns a new DecimalValue object with a default value - */ - public ScalarValue getDefaultValue() { - return new DecimalValue(0.0); - } - - public boolean equals(Object obj) { - return obj != null && obj.getClass() == getClass(); - } -} Copied: tags/openfast-0.9.7/src/main/java/org/openfast/template/type/codec/SingleFieldDecimal.java (from rev 131, trunk/src/main/java/org/openfast/template/type/codec/SingleFieldDecimal.java) =================================================================== --- tags/openfast-0.9.7/src/main/java/org/openfast/template/type/codec/SingleFieldDecimal.java (rev 0) +++ tags/openfast-0.9.7/src/main/java/org/openfast/template/type/codec/SingleFieldDecimal.java 2008-02-07 16:46:24 UTC (rev 133) @@ -0,0 +1,116 @@ +/* +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is OpenFAST. + +The Initial Developer of the Original Code is The LaSalle Technology +Group, LLC. Portions created by The LaSalle Technology Group, LLC +are Copyright (C) The LaSalle Technology Group, LLC. All Rights Reserved. + +Contributor(s): Jacob Northey <ja...@la...> + Craig Otis <co...@la...> + */ + +/** + * + */ +package org.openfast.template.type.codec; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.openfast.DecimalValue; +import org.openfast.Global; +import org.openfast.IntegerValue; +import org.openfast.ScalarValue; +import org.openfast.error.FastConstants; +import org.openfast.template.LongValue; + +final class SingleFieldDecimal extends TypeCodec { + private static final long serialVersionUID = 1L; + + SingleFieldDecimal() { + } + + /** + * Takes a ScalarValue object, and converts it to a byte array + * + * @param v + * The ScalarValue to be encoded + * @return Returns a byte array of the passed object + */ + public byte[] encodeValue(ScalarValue v) { + if (v == ScalarValue.NULL) { + return TypeCodec.NULL_VALUE_ENCODING; + } + + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + DecimalValue value = (DecimalValue) v; + + try { + if (Math.abs(value.exponent) > 63) { + Global.handleError(FastConstants.R1_LARGE_DECIMAL, "Encountered exponent of size " + value.exponent); + } + + buffer.write(TypeCodec.INTEGER.encode(new IntegerValue(value.exponent))); + buffer.write(TypeCodec.INTEGER.encode(new LongValue(value.mantissa))); + } catch (IOException e) { + throw new RuntimeException(e); + } + + return buffer.toByteArray(); + } + + /** + * Reads in a stream of data and stores it to a decimalValue object + * + * @param in + * The InputStream to be decoded + * @return Returns a decimalValue object with the data stream + */ + public ScalarValue decode(InputStream in) { + int exponent = ((IntegerValue) TypeCodec.INTEGER.decode(in)).value; + + if (Math.abs(exponent) > 63) { + Global.handleError(FastConstants.R1_LARGE_DECIMAL, "Encountered exponent of size " + exponent); + } + + int mantissa = ((IntegerValue) TypeCodec.INTEGER.decode(in)).value; + DecimalValue decimalValue = new DecimalValue(mantissa, exponent); + + return decimalValue; + } + + /** + * Convert a string to a DecimalValue object with the string as the passed + * value + * + * @param value + * The value as a string to be converted + * @return Returns a new DecimalValue object + */ + public ScalarValue fromString(String value) { + return new DecimalValue(Double.parseDouble(value)); + } + + /** + * + * @return Returns a new DecimalValue object with a default value + */ + public ScalarValue getDefaultValue() { + return new DecimalValue(0.0); + } + + public boolean equals(Object obj) { + return obj != null && obj.getClass() == getClass(); + } +} Copied: tags/openfast-0.9.7/src/test/java/org/openfast/submitted/LargeValuesTest.java (from rev 131, trunk/src/test/java/org/openfast/submitted/LargeValuesTest.java) =================================================================== --- tags/openfast-0.9.7/src/test/java/org/openfast/submitted/LargeValuesTest.java (rev 0) +++ tags/openfast-0.9.7/src/test/java/org/openfast/submitted/LargeValuesTest.java 2008-02-07 16:46:24 UTC (rev 133) @@ -0,0 +1,27 @@ +package org.openfast.submitted; + +import org.openfast.IntegerValue; +import org.openfast.Message; +import org.openfast.QName; +import org.openfast.codec.FastDecoder; +import org.openfast.codec.FastEncoder; +import org.openfast.template.MessageTemplate; +import org.openfast.template.operator.Operator; +import org.openfast.test.OpenFastTestCase; +import org.openfast.util.Util; + +public class LargeValuesTest extends OpenFastTestCase { + + public void testLargeDecimal() { + MessageTemplate composed = + template(Util.composedDecimal(new QName("Line1"), Operator.COPY, new IntegerValue(-2), + Operator.COPY, new IntegerValue(94276), true)); + FastEncoder encoder = encoder(composed); + Message message = (Message) composed.createValue(null); + message.setDecimal(1, 987654321.123456); + + byte[] encoded = encoder.encode(message); + FastDecoder decoder = decoder(composed, encoded); + assertEquals(message, decoder.readMessage()); + } +} Deleted: tags/openfast-0.9.7/src/test/java/org/openfast/template/operator/DefaultOperatorTest.java =================================================================== --- trunk/src/test/java/org/openfast/template/operator/DefaultOperatorTest.java 2008-02-07 16:34:58 UTC (rev 130) +++ tags/openfast-0.9.7/src/test/java/org/openfast/template/operator/DefaultOperatorTest.java 2008-02-07 16:46:24 UTC (rev 133) @@ -1,36 +0,0 @@ -package org.openfast.template.operator; - -import org.openfast.IntegerValue; -import org.openfast.Message; -import org.openfast.QName; -import org.openfast.ScalarValue; -import org.openfast.codec.FastEncoder; -import org.openfast.template.MessageTemplate; -import org.openfast.template.Scalar; -import org.openfast.template.type.Type; -import org.openfast.test.OpenFastTestCase; - -public class DefaultOperatorTest extends OpenFastTestCase { - - public void testNullsNoInitialValue() throws Exception { - Scalar field = new Scalar(new QName("mostlyNull"), Type.I32, Operator.DEFAULT, ScalarValue.UNDEFINED, true); - MessageTemplate template = template(field); - FastEncoder encoder = encoder(template); - - Message message = (Message) template.createValue(null); - assertEquals("11000000 10000001", encoder.encode(message)); - assertEquals("10000000", encoder.encode(message)); - } - - public void testNullsWithInitialValue() throws Exception { - Scalar field = new Scalar(new QName("sometimesNull"), Type.I32, Operator.DEFAULT, new IntegerValue(10), true); - MessageTemplate template = template(field); - FastEncoder encoder = encoder(template); - - Message message = (Message) template.createValue(null); - assertEquals("11100000 10000001 10000000", encoder.encode(message)); - assertEquals("10100000 10000000", encoder.encode(message)); - message.setInteger(1, 10); - assertEquals("10000000", encoder.encode(message)); - } -} Copied: tags/openfast-0.9.7/src/test/java/org/openfast/template/operator/DefaultOperatorTest.java (from rev 131, trunk/src/test/java/org/openfast/template/operator/DefaultOperatorTest.java) =================================================================== --- tags/openfast-0.9.7/src/test/java/org/openfast/template/operator/DefaultOperatorTest.java (rev 0) +++ tags/openfast-0.9.7/src/test/java/org/openfast/template/operator/DefaultOperatorTest.java 2008-02-07 16:46:24 UTC (rev 133) @@ -0,0 +1,55 @@ +package org.openfast.template.operator; + +import org.openfast.Context; +import org.openfast.IntegerValue; +import org.openfast.Message; +import org.openfast.QName; +import org.openfast.ScalarValue; +import org.openfast.codec.FastEncoder; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; +import org.openfast.template.type.Type; +import org.openfast.test.OpenFastTestCase; + +public class DefaultOperatorTest extends OpenFastTestCase { + + public void testNullsNoInitialValue() throws Exception { + Scalar field = new Scalar(new QName("mostlyNull"), Type.I32, Operator.DEFAULT, ScalarValue.UNDEFINED, true); + MessageTemplate template = template(field); + FastEncoder encoder = encoder(template); + + Message message = (Message) template.createValue(null); + assertEquals("11000000 10000001", encoder.encode(message)); + assertEquals(... [truncated message content] |
From: <ope...@li...> - 2008-02-07 16:46:16
|
Revision: 132 http://openfast.svn.sourceforge.net/openfast/?rev=132&view=rev Author: jacob_northey Date: 2008-02-07 08:46:01 -0800 (Thu, 07 Feb 2008) Log Message: ----------- [maven-release-plugin] prepare release openfast-0.9.7 Modified Paths: -------------- trunk/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2008-02-07 16:41:36 UTC (rev 131) +++ trunk/pom.xml 2008-02-07 16:46:01 UTC (rev 132) @@ -4,7 +4,7 @@ <groupId>org.openfast</groupId> <artifactId>openfast</artifactId> <packaging>jar</packaging> - <version>0.9.7-SNAPSHOT</version> + <version>0.9.7</version> <organization> <name>The LaSalle Technology Group, LLC</name> @@ -66,9 +66,9 @@ </issueManagement> <scm> - <connection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.5</connection> - <developerConnection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.5</developerConnection> - <url>http://openfast.svn.sourceforge.net/viewvc/openfast/tags/openfast-0.9.5</url> + <connection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.7</connection> + <developerConnection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-0.9.7</developerConnection> + <url>http://openfast.svn.sourceforge.net/viewvc/openfast/tags/openfast-0.9.7</url> </scm> <mailingLists> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |