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-07-31 18:04:14
|
Revision: 181 http://openfast.svn.sourceforge.net/openfast/?rev=181&view=rev Author: jacob_northey Date: 2008-07-31 18:04:01 +0000 (Thu, 31 Jul 2008) Log Message: ----------- Modified Paths: -------------- branches/openfast-2.x/core/src/main/java/org/openfast/FastObject.java branches/openfast-2.x/core/src/main/java/org/openfast/Message.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/CodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/IntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/SinglePresenceMapEntryFieldCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/AlwaysPresentCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorLongCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorULongCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementLongCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementULongCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/MandatoryConstantIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/MandatoryConstantStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/OptionalConstantIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/OptionalConstantStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/TailAsciiCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/TailOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/BasicFastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/IntegerEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/LongEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/StringEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast_1_1Implementation.java branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleFastObject.java branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleMessage.java branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleSequence.java branches/openfast-2.x/core/src/main/java/org/openfast/template/AbstractOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Operator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/ScalarBuilder.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ParsingContext.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/XMLMessageTemplateLoader.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastLongOperatorTestHarness.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastOperatorTestHarness.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastStringOperatorTestHarness.java branches/openfast-2.x/examples/pom.xml Added Paths: ----------- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicGroupCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicSequenceCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/GroupCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/ObjectEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/CommonFastImplementation.java branches/openfast-2.x/core/src/main/java/org/openfast/test/ branches/openfast-2.x/core/src/main/java/org/openfast/test/OpenFastTestCase.java branches/openfast-2.x/core/src/main/java/org/openfast/test/TestUtil.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/BasicGroupCodecTest.java branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/codec/ branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/codec/operator/ branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/codec/operator/CacheCodecFactory.java branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/examples/xml/ branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/examples/xml/Fast11PlusCacheImplementation.java branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/examples/xml/XmlToFastTool.java branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/template/ branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/template/loader/ branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/template/loader/CacheOperatorParser.java branches/openfast-2.x/examples/src/main/resources/xml/ branches/openfast-2.x/examples/src/main/resources/xml/xmlOverFastTemplates.xml branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/codec/ branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/codec/operator/ branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/codec/operator/CacheStringCodec.java branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/template/ branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/template/operator/ branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/template/operator/CacheOperator.java branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/util/BasicCache.java branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/util/BiDirectionalCache.java branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/util/Cache.java branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/util/LRUCache.java branches/openfast-2.x/util/src/test/ branches/openfast-2.x/util/src/test/java/ branches/openfast-2.x/util/src/test/java/com/ branches/openfast-2.x/util/src/test/java/com/lasalletech/ branches/openfast-2.x/util/src/test/java/com/lasalletech/openfast/ branches/openfast-2.x/util/src/test/java/com/lasalletech/openfast/codec/ branches/openfast-2.x/util/src/test/java/com/lasalletech/openfast/codec/operator/ branches/openfast-2.x/util/src/test/java/com/lasalletech/openfast/codec/operator/CacheStringCodecTest.java branches/openfast-2.x/util/src/test/java/com/lasalletech/openfast/util/ branches/openfast-2.x/util/src/test/java/com/lasalletech/openfast/util/BasicCacheTest.java branches/openfast-2.x/util/src/test/java/com/lasalletech/openfast/util/LRUCacheTest.java Removed Paths: ------------- branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java branches/openfast-2.x/core/src/test/java/org/openfast/test/OpenFastTestCase.java branches/openfast-2.x/core/src/test/java/org/openfast/test/TestUtil.java Property Changed: ---------------- branches/openfast-2.x/util/ Modified: branches/openfast-2.x/core/src/main/java/org/openfast/FastObject.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/FastObject.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/FastObject.java 2008-07-31 18:04:01 UTC (rev 181) @@ -1,11 +1,11 @@ package org.openfast; import org.lasalletech.entity.EObject; +import org.openfast.template.Composite; import org.openfast.template.Field; -import org.openfast.template.Group; import org.openfast.template.MessageTemplate; import org.openfast.template.Type; -public interface FastObject extends EObject<Group, FastObject, Type, Field, MessageTemplate, Message, Group, FastObject> { +public interface FastObject extends EObject<Composite<FastObject>, FastObject, Type, Field, MessageTemplate, Message, Composite<FastObject>, FastObject> { } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Message.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Message.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Message.java 2008-07-31 18:04:01 UTC (rev 181) @@ -21,11 +21,11 @@ package org.openfast; import org.lasalletech.entity.EObject; +import org.openfast.template.Composite; import org.openfast.template.Field; -import org.openfast.template.Group; import org.openfast.template.MessageTemplate; import org.openfast.template.Type; -public interface Message extends EObject<MessageTemplate, Message, Type, Field, MessageTemplate, Message, Group, FastObject> { +public interface Message extends EObject<MessageTemplate, Message, Type, Field, MessageTemplate, Message, Composite<FastObject>, FastObject> { MessageTemplate getTemplate(); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java 2008-07-31 18:04:01 UTC (rev 181) @@ -2,8 +2,11 @@ import java.util.HashMap; import java.util.Map; +import org.openfast.FastObject; import org.openfast.dictionary.DictionaryRegistry; import org.openfast.fast.impl.FastImplementation; +import org.openfast.template.Composite; +import org.openfast.template.Field; import org.openfast.template.MessageTemplate; import org.openfast.template.Scalar; @@ -14,11 +17,11 @@ return new BasicMessageCodec(id, template, implementation, dictionaryRegistry, this); } - public ScalarCodec createScalarCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, DictionaryRegistry dictionaryRegistry) { + public FieldCodec createScalarCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, DictionaryRegistry dictionaryRegistry) { if (!codecFactories.containsKey(scalar.getOperator().getName())) { throw new IllegalArgumentException("Encountered unknown operator " + scalar.getOperator() + " in scalar " + scalar.getQName()); } - ScalarCodec codec = codecFactories.get(scalar.getOperator().getName()).createCodec(template, scalar, implementation, dictionaryRegistry); + FieldCodec codec = codecFactories.get(scalar.getOperator().getName()).createCodec(template, scalar, implementation, dictionaryRegistry); if (codec == null) throw new IllegalArgumentException("Could not create codec for field " + scalar); return codec; @@ -27,4 +30,16 @@ public void register(String operator, ScalarCodecFactory scalarCodecFactory) { codecFactories.put(operator, scalarCodecFactory); } + + public FieldCodec createCompositeCodec(MessageTemplate template, Field field, FastImplementation implementation, + DictionaryRegistry dictionaryRegistry) { + if (field.getType().isRepeating()) { + return new BasicSequenceCodec(template, field, implementation, dictionaryRegistry, this); + } + return createGroupCodec(template, field, implementation, dictionaryRegistry); + } + + public FieldCodec createGroupCodec(MessageTemplate template, Field field, FastImplementation implementation, DictionaryRegistry dictionaryRegistry) { + return new BasicGroupCodec(template, (Composite<FastObject>) field, implementation, dictionaryRegistry); + } } Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicGroupCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicGroupCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicGroupCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -0,0 +1,82 @@ +package org.openfast.codec; + +import org.lasalletech.entity.EObject; +import org.openfast.Context; +import org.openfast.FastObject; +import org.openfast.dictionary.DictionaryRegistry; +import org.openfast.error.FastConstants; +import org.openfast.fast.FastTypes; +import org.openfast.fast.impl.FastImplementation; +import org.openfast.template.Composite; +import org.openfast.template.Field; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; +import org.openfast.util.BitVector; +import org.openfast.util.BitVectorBuilder; +import org.openfast.util.BitVectorReader; + +public class BasicGroupCodec implements GroupCodec { + private final BitVectorCodec bitVectorCodec; + private final FieldCodec[] fieldCodecs; + private final Composite<FastObject> composite; + + public BasicGroupCodec(MessageTemplate template, Composite<FastObject> composite, FastImplementation implementation, DictionaryRegistry dictionaryRegistry) { + this.bitVectorCodec = implementation.getTypeCodecRegistry().getBitVectorCodec(FastTypes.BIT_VECTOR); + this.fieldCodecs = new FieldCodec[composite.getFieldCount()]; + this.composite = composite; + int index = 0; + CodecFactory codecFactory = implementation.getCodecFactory(); + for (Field field : composite.getFields()) { + if (field instanceof Scalar) { + Scalar scalar = (Scalar) field; + fieldCodecs[index] = codecFactory.createScalarCodec(template, scalar, implementation, dictionaryRegistry); + index++; + } else { + fieldCodecs[index] = codecFactory.createCompositeCodec(template, field, implementation, dictionaryRegistry); + index++; + } + } + } + + public int decode(EObject object, int index, byte[] buffer, int offset, BitVectorReader pmapReader, Context context) { + return 0; + } + + public EObject decode(byte[] buffer, int offset, BitVectorReader reader, Context context) { + BitVector vector = bitVectorCodec.decode(buffer, offset); + BitVectorReader pmapReader = new BitVectorReader(vector); + offset += bitVectorCodec.getLength(buffer, offset); + FastObject o = composite.newObject(); + for (int i=0; i<fieldCodecs.length; i++) { + offset = fieldCodecs[i].decode(o, i, buffer, offset, pmapReader, context); + } + return o; + } + + public int encode(EObject object, int index, byte[] buffer, int offset, BitVectorBuilder pmapBuilder, Context context) { + return encode(object.getEObject(index), buffer, offset, context); + } + + public int encode(EObject object, byte[] buffer, int offset, Context context) { + byte[] temp = context.getTemporaryBuffer(); + int index = 0; + int pmapLen = 0; + try { + BitVectorBuilder pmapBuilder = new BitVectorBuilder(7); // TODO - calculate size of pmap builder + for (int i=0; i<fieldCodecs.length; i++) { + index = fieldCodecs[i].encode(object, i, temp, index, pmapBuilder, context); + } + pmapLen = bitVectorCodec.encode(buffer, offset, pmapBuilder.getBitVector()); + System.arraycopy(temp, 0, buffer, offset + pmapLen, index); + } catch (Throwable t) { + context.getErrorHandler().error(FastConstants.GENERAL_ERROR, "Error occurred while encoding " + object, t); + } finally { + context.discardTemporaryBuffer(temp); + } + return offset + pmapLen + index; + } + + public int getLength(byte[] buffer, int offset, BitVectorReader reader) { + return 0; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -30,6 +30,9 @@ Scalar scalar = (Scalar) field; fieldCodecs[index] = codecFactory.createScalarCodec(template, scalar, implementation, dictionaryRegistry); index++; + } else { + fieldCodecs[index] = codecFactory.createCompositeCodec(template, field, implementation, dictionaryRegistry); + index++; } } } @@ -49,7 +52,7 @@ pmapBuilder.skip(); } for (int i=0; i<fieldCodecs.length; i++) { - index = fieldCodecs[i].encode(message, i, temp, index, message.getTemplate().getField(i), pmapBuilder, context); + index = fieldCodecs[i].encode(message, i, temp, index, pmapBuilder, context); } pmapLen = bitVectorCodec.encode(buffer, offset, pmapBuilder.getBitVector()); System.arraycopy(temp, 0, buffer, offset + pmapLen, index); @@ -74,7 +77,7 @@ @SuppressWarnings("unchecked") public void decode(Message message, byte[] buffer, int offset, BitVectorReader reader, Context context) { for (int i=0; i<fieldCodecs.length; i++) { - offset = fieldCodecs[i].decode(message, i, buffer, offset, message.getTemplate().getField(i), reader, context); + offset = fieldCodecs[i].decode(message, i, buffer, offset, reader, context); } } } Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicSequenceCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicSequenceCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicSequenceCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -0,0 +1,66 @@ +package org.openfast.codec; + +import org.lasalletech.entity.EObject; +import org.lasalletech.entity.EObjectList; +import org.lasalletech.entity.EmptyEObject; +import org.lasalletech.entity.EntityType; +import org.openfast.Context; +import org.openfast.dictionary.DictionaryRegistry; +import org.openfast.fast.impl.FastImplementation; +import org.openfast.template.Field; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; +import org.openfast.template.Sequence; +import org.openfast.util.BitVectorBuilder; +import org.openfast.util.BitVectorReader; + +public class BasicSequenceCodec implements FieldCodec { + public class IntEObjectWrapper extends EmptyEObject { + private final int value; + + public IntEObjectWrapper(int value) { + this.value = value; + } + @Override + public int getInt(int index) { + return value; + } + + @Override + public boolean isDefined(int index) { + return true; + } + } + + private final FieldCodec lengthCodec; + private final Scalar lengthScalar; + private final BasicGroupCodec groupCodec; + + public BasicSequenceCodec(MessageTemplate template, Field field, FastImplementation implementation, + DictionaryRegistry dictionaryRegistry, BasicCodecFactory basicCodecFactory) { + lengthScalar = ((Sequence) ((EntityType)field.getType()).getEntity()).getLength(); + lengthCodec = basicCodecFactory.createScalarCodec(template, lengthScalar, implementation, dictionaryRegistry); + groupCodec = (BasicGroupCodec) basicCodecFactory.createGroupCodec(template, field, implementation, dictionaryRegistry); + } + + public int decode(EObject object, int index, byte[] buffer, int offset, BitVectorReader pmapReader, Context context) { + return 0; + } + + public int encode(EObject object, int index, byte[] buffer, int offset, BitVectorBuilder pmapBuilder, Context context) { + if (!object.isDefined(index)) { + return lengthCodec.encode(EObject.EMPTY, 0, buffer, offset, pmapBuilder, context); + } + EObjectList list = object.getList(index); + EObject wrapper = new IntEObjectWrapper(list.size()); + int newOffset = lengthCodec.encode(wrapper, 0, buffer, offset, pmapBuilder, context); + for (EObject o : list) { + newOffset = groupCodec.encode(o, buffer, newOffset, context); + } + return newOffset; + } + + public int getLength(byte[] buffer, int offset, BitVectorReader reader) { + return 0; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/CodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/CodecFactory.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/CodecFactory.java 2008-07-31 18:04:01 UTC (rev 181) @@ -2,10 +2,14 @@ import org.openfast.dictionary.DictionaryRegistry; import org.openfast.fast.impl.FastImplementation; +import org.openfast.template.Field; import org.openfast.template.MessageTemplate; import org.openfast.template.Scalar; public interface CodecFactory { MessageCodec createMessageCodec(int id, MessageTemplate template, FastImplementation implementation, DictionaryRegistry dictionaryRegistry); - ScalarCodec createScalarCodec(MessageTemplate template, Scalar scalar, FastImplementation fastImplementation, DictionaryRegistry dictionaryRegistry); + FieldCodec createScalarCodec(MessageTemplate template, Scalar scalar, FastImplementation fastImplementation, DictionaryRegistry dictionaryRegistry); + FieldCodec createCompositeCodec(MessageTemplate template, Field field, FastImplementation implementation, + DictionaryRegistry dictionaryRegistry); + FieldCodec createGroupCodec(MessageTemplate template, Field field, FastImplementation implementation, DictionaryRegistry dictionaryRegistry); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -5,7 +5,7 @@ import org.openfast.util.BitVectorBuilder; import org.openfast.util.BitVectorReader; -public interface FieldCodec<T> { +public interface FieldCodec { /** * @param object the message to decode the field value into @@ -15,10 +15,10 @@ * @param field the field definition that this codec was built from * @param pmapReader the presence map reader * @param context the current decoding context - * @return the new offset in the encoded buffer + * @return the new offset in the decoded buffer */ @SuppressWarnings("unchecked") - int decode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorReader pmapReader, Context context); + int decode(EObject object, int index, byte[] buffer, int offset, BitVectorReader pmapReader, Context context); /** * @param object * @param index @@ -30,6 +30,6 @@ * @return the new offset in the encoded buffer */ @SuppressWarnings("unchecked") - int encode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorBuilder pmapBuilder, Context context); + int encode(EObject object, int index, byte[] buffer, int offset, BitVectorBuilder pmapBuilder, Context context); int getLength(byte[] buffer, int offset, BitVectorReader reader); } Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/GroupCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/GroupCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/GroupCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -0,0 +1,10 @@ +package org.openfast.codec; + +import org.lasalletech.entity.EObject; +import org.openfast.Context; +import org.openfast.util.BitVectorReader; + +public interface GroupCodec extends FieldCodec { + int encode(EObject object, byte[] buffer, int offset, Context context); + EObject decode(byte[] buffer, int offset, BitVectorReader pmapReader, Context context); +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/IntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/IntegerCodec.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/IntegerCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -2,5 +2,14 @@ public interface IntegerCodec extends TypeCodec { int decode(byte[] buffer, int offset); + + /** + * Encodes the value into the FAST encoded buffer + * + * @param buffer the destination for fast encoded bytes + * @param offset the index in the buffer to continue encoding + * @param value the value to encode + * @return the new offset in the buffer + */ int encode(byte[] buffer, int offset, int value); } Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -1,26 +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.codec; - -import org.openfast.template.Scalar; - -public interface ScalarCodec extends FieldCodec<Scalar> { -} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodecFactory.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodecFactory.java 2008-07-31 18:04:01 UTC (rev 181) @@ -6,5 +6,5 @@ import org.openfast.template.Scalar; public interface ScalarCodecFactory { - ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, DictionaryRegistry dictionaryRegistry); + FieldCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, DictionaryRegistry dictionaryRegistry); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/SinglePresenceMapEntryFieldCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/SinglePresenceMapEntryFieldCodec.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/SinglePresenceMapEntryFieldCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -5,10 +5,10 @@ import org.openfast.util.BitVectorBuilder; import org.openfast.util.BitVectorReader; -public abstract class SinglePresenceMapEntryFieldCodec<T> implements FieldCodec<T> { +public abstract class SinglePresenceMapEntryFieldCodec implements FieldCodec { - public int encode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorBuilder pmapBuilder, Context context) { - int newOffset = encode(object, index, buffer, offset, field, context); + public int encode(EObject object, int index, byte[] buffer, int offset, BitVectorBuilder pmapBuilder, Context context) { + int newOffset = encode(object, index, buffer, offset, context); if (newOffset == offset) pmapBuilder.skip(); else @@ -16,12 +16,12 @@ return newOffset; }; - public int decode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorReader reader, Context context) { + public int decode(EObject object, int index, byte[] buffer, int offset, BitVectorReader reader, Context context) { if (reader.read()) { - decode(object, index, buffer, offset, field, context); + decode(object, index, buffer, offset, context); return offset + getLength(buffer, offset); } - decodeEmpty(object, index, field, context); + decodeEmpty(object, index, context); return offset; } public int getLength(byte[] buffer, int offset, BitVectorReader reader) { @@ -29,8 +29,8 @@ return getLength(buffer, offset); return 0; } - public abstract int encode(EObject object, int index, byte[] buffer, int offset, T field, Context context); - public abstract void decode(EObject object, int index, byte[] buffer, int offset, T field, Context context); - public abstract void decodeEmpty(EObject object, int index, T field, Context context); + public abstract int encode(EObject object, int index, byte[] buffer, int offset, Context context); + public abstract void decode(EObject object, int index, byte[] buffer, int offset, Context context); + public abstract void decodeEmpty(EObject object, int index, Context context); public abstract int getLength(byte[] buffer, int offset); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/AlwaysPresentCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/AlwaysPresentCodec.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/AlwaysPresentCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -6,15 +6,15 @@ import org.openfast.util.BitVectorBuilder; import org.openfast.util.BitVectorReader; -public abstract class AlwaysPresentCodec<T> implements FieldCodec<T> { +public abstract class AlwaysPresentCodec implements FieldCodec { - public int decode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorReader reader, Context context) { - decode(object, index, buffer, offset, field, context); + public int decode(EObject object, int index, byte[] buffer, int offset, BitVectorReader reader, Context context) { + decode(object, index, buffer, offset, context); return offset + getLength(buffer, offset); } - public int encode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorBuilder pmapBuilder, Context context) { - return encode(object, index, buffer, offset, field, context); + public int encode(EObject object, int index, byte[] buffer, int offset, BitVectorBuilder pmapBuilder, Context context) { + return encode(object, index, buffer, offset, context); } public int getLength(byte[] buffer, int offset, BitVectorReader reader) { @@ -23,6 +23,6 @@ public abstract int getLength(byte[] buffer, int offset); - public abstract void decode(EObject object, int index, byte[] buffer, int offset, T field, Context context); - public abstract int encode(EObject object, int index, byte[] buffer, int offset, T field, Context context); + public abstract void decode(EObject object, int index, byte[] buffer, int offset, Context context); + public abstract int encode(EObject object, int index, byte[] buffer, int offset, Context context); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantOperatorCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantOperatorCodecFactory.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantOperatorCodecFactory.java 2008-07-31 18:04:01 UTC (rev 181) @@ -1,6 +1,6 @@ package org.openfast.codec.operator; -import org.openfast.codec.ScalarCodec; +import org.openfast.codec.FieldCodec; import org.openfast.codec.ScalarCodecFactory; import org.openfast.dictionary.DictionaryRegistry; import org.openfast.fast.impl.FastImplementation; @@ -10,7 +10,7 @@ import org.openfast.template.type.StringType; public class ConstantOperatorCodecFactory implements ScalarCodecFactory { - public ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, + public FieldCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, DictionaryRegistry dictionaryRegistry) { if (scalar.getType() instanceof IntegerType) { int defaultValue = Integer.parseInt(scalar.getOperator().getDefaultValue()); Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -3,13 +3,13 @@ import org.lasalletech.entity.EObject; import org.openfast.Context; import org.openfast.Fast; +import org.openfast.codec.FieldCodec; import org.openfast.codec.IntegerCodec; -import org.openfast.codec.ScalarCodec; import org.openfast.dictionary.DictionaryEntry; import org.openfast.template.Scalar; import org.openfast.template.operator.DictionaryOperator; -public class CopyIntegerCodec extends DictionaryOperatorIntegerCodec implements ScalarCodec { +public class CopyIntegerCodec extends DictionaryOperatorIntegerCodec implements FieldCodec { public CopyIntegerCodec(DictionaryEntry entry, DictionaryOperator operator, IntegerCodec integerCodec) { super(entry, operator, integerCodec); @@ -19,7 +19,7 @@ return integerCodec.getLength(buffer, offset); } - public void decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public void decode(EObject object, int index, byte[] buffer, int offset, Context context) { if (integerCodec.isNull(buffer, offset)) { dictionaryEntry.setNull(); return; @@ -29,7 +29,7 @@ dictionaryEntry.set(value); } - public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public int encode(EObject object, int index, byte[] buffer, int offset, Context context) { boolean dictionaryUndefined = !dictionaryEntry.isDefined(); boolean dictionaryNull = dictionaryEntry.isNull(); if (!object.isDefined(index)) { @@ -58,7 +58,7 @@ return newOffset; } - public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { + public void decodeEmpty(EObject object, int index, Context context) { if (dictionaryEntry.isNull()) return; if (dictionaryEntry.isDefined()) Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyOperatorCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyOperatorCodecFactory.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyOperatorCodecFactory.java 2008-07-31 18:04:01 UTC (rev 181) @@ -1,7 +1,7 @@ package org.openfast.codec.operator; +import org.openfast.codec.FieldCodec; import org.openfast.codec.IntegerCodec; -import org.openfast.codec.ScalarCodec; import org.openfast.codec.ScalarCodecFactory; import org.openfast.codec.StringCodec; import org.openfast.dictionary.DictionaryEntry; @@ -14,7 +14,7 @@ import org.openfast.template.type.IntegerType; public class CopyOperatorCodecFactory implements ScalarCodecFactory { - public ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, + public FieldCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, DictionaryRegistry dictionaryRegistry) { DictionaryEntry entry = dictionaryRegistry.get(((DictionaryOperator)scalar.getOperator()).getDictionary()).getEntry(scalar); if (FastTypes.ASCII.equals(scalar.getType())) { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyStringCodec.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyStringCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -3,23 +3,20 @@ import org.lasalletech.entity.EObject; import org.openfast.Context; import org.openfast.Fast; -import org.openfast.codec.ScalarCodec; import org.openfast.codec.StringCodec; import org.openfast.dictionary.DictionaryEntry; -import org.openfast.template.Scalar; import org.openfast.template.operator.DictionaryOperator; -public class CopyStringCodec extends DictionaryOperatorStringCodec implements ScalarCodec { - +public class CopyStringCodec extends DictionaryOperatorStringCodec { public CopyStringCodec(DictionaryEntry dictionaryEntry, DictionaryOperator operator, StringCodec stringCodec) { super(dictionaryEntry, operator, stringCodec); } - + public int getLength(byte[] buffer, int offset) { return stringCodec.getLength(buffer, offset); } - public void decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public void decode(EObject object, int index, byte[] buffer, int offset, Context context) { if (stringCodec.isNull(buffer, offset)) { dictionaryEntry.setNull(); return; @@ -29,7 +26,7 @@ dictionaryEntry.set(value); } - public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public int encode(EObject object, int index, byte[] buffer, int offset, Context context) { boolean dictionaryUndefined = !dictionaryEntry.isDefined(); boolean dictionaryNull = dictionaryEntry.isNull(); if (!object.isDefined(index)) { @@ -38,7 +35,7 @@ return offset; } else { buffer[offset] = Fast.NULL; - return offset+1; + return offset + 1; } } String value = object.getString(index); @@ -58,15 +55,13 @@ return newOffset; } - public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { + public void decodeEmpty(EObject object, int index, Context context) { if (dictionaryEntry.isNull()) return; if (dictionaryEntry.isDefined()) { object.set(index, dictionaryEntry.getString()); - } - else if (operator.hasDefaultValue()) { + } else if (operator.hasDefaultValue()) object.set(index, operator.getDefaultValue()); - dictionaryEntry.set(operator.getDefaultValue()); - } + dictionaryEntry.set(operator.getDefaultValue()); } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultIntegerCodec.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultIntegerCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -3,13 +3,12 @@ import org.lasalletech.entity.EObject; import org.openfast.Context; import org.openfast.Fast; +import org.openfast.codec.FieldCodec; import org.openfast.codec.IntegerCodec; -import org.openfast.codec.ScalarCodec; import org.openfast.codec.SinglePresenceMapEntryFieldCodec; import org.openfast.template.Operator; -import org.openfast.template.Scalar; -public class DefaultIntegerCodec extends SinglePresenceMapEntryFieldCodec<Scalar> implements ScalarCodec { +public class DefaultIntegerCodec extends SinglePresenceMapEntryFieldCodec implements FieldCodec { private final Operator operator; private final IntegerCodec integerCodec; private final int defaultValue; @@ -23,19 +22,19 @@ return integerCodec.getLength(buffer, offset); } - public void decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public void decode(EObject object, int index, byte[] buffer, int offset, Context context) { if (integerCodec.isNull(buffer, offset)) return; int value = integerCodec.decode(buffer, offset); object.set(index, value); } - public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { + public void decodeEmpty(EObject object, int index, Context context) { if (operator.hasDefaultValue()) object.set(index, defaultValue); } - public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public int encode(EObject object, int index, byte[] buffer, int offset, Context context) { if (object.isDefined(index)) { if (operator.hasDefaultValue() && object.getInt(index) == defaultValue) return offset; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultOperatorCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultOperatorCodecFactory.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultOperatorCodecFactory.java 2008-07-31 18:04:01 UTC (rev 181) @@ -1,7 +1,7 @@ package org.openfast.codec.operator; +import org.openfast.codec.FieldCodec; import org.openfast.codec.IntegerCodec; -import org.openfast.codec.ScalarCodec; import org.openfast.codec.ScalarCodecFactory; import org.openfast.codec.StringCodec; import org.openfast.dictionary.DictionaryRegistry; @@ -12,7 +12,7 @@ import org.openfast.template.type.StringType; public class DefaultOperatorCodecFactory implements ScalarCodecFactory { - public ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, + public FieldCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, DictionaryRegistry dictionaryRegistry) { if (scalar.getType() instanceof IntegerType) { IntegerCodec integerCodec = implementation.getTypeCodecRegistry().getIntegerCodec(scalar.getType(), scalar.isOptional()); Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultStringCodec.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultStringCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -3,13 +3,12 @@ import org.lasalletech.entity.EObject; import org.openfast.Context; import org.openfast.Fast; -import org.openfast.codec.ScalarCodec; +import org.openfast.codec.FieldCodec; import org.openfast.codec.SinglePresenceMapEntryFieldCodec; import org.openfast.codec.StringCodec; import org.openfast.template.Operator; -import org.openfast.template.Scalar; -public class DefaultStringCodec extends SinglePresenceMapEntryFieldCodec<Scalar> implements ScalarCodec { +public class DefaultStringCodec extends SinglePresenceMapEntryFieldCodec implements FieldCodec { private final Operator operator; private final StringCodec stringCodec; @@ -21,19 +20,19 @@ return stringCodec.getLength(buffer, offset); } - public void decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public void decode(EObject object, int index, byte[] buffer, int offset, Context context) { if (stringCodec.isNull(buffer, offset)) return; String value = stringCodec.decode(buffer, offset); object.set(index, value); } - public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { + public void decodeEmpty(EObject object, int index, Context context) { if (operator.hasDefaultValue()) object.set(index, operator.getDefaultValue()); } - public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public int encode(EObject object, int index, byte[] buffer, int offset, Context context) { if (object.isDefined(index)) { if (operator.hasDefaultValue() && operator.getDefaultValue().equals(object.getString(index))) return offset; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -3,15 +3,14 @@ import org.lasalletech.entity.EObject; import org.openfast.Context; import org.openfast.Fast; +import org.openfast.codec.FieldCodec; import org.openfast.codec.IntegerCodec; -import org.openfast.codec.ScalarCodec; import org.openfast.codec.StringCodec; import org.openfast.dictionary.DictionaryEntry; import org.openfast.error.FastConstants; -import org.openfast.template.Scalar; import org.openfast.template.operator.DictionaryOperator; -public class DeltaAsciiCodec extends DictionaryOperatorStringCodec implements ScalarCodec { +public class DeltaAsciiCodec extends DictionaryOperatorStringCodec implements FieldCodec { private IntegerCodec integerCodec; public DeltaAsciiCodec(DictionaryEntry dictionaryEntry, DictionaryOperator operator, IntegerCodec integerCodec, StringCodec stringCodec) { @@ -26,39 +25,39 @@ return len + stringCodec.getLength(buffer, offset + len); } - public void decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public void decode(EObject object, int index, byte[] buffer, int offset, Context context) { if (integerCodec.isNull(buffer, offset)) { return; } int subtractionLength = integerCodec.decode(buffer, offset); offset += integerCodec.getLength(buffer, offset); String delta = stringCodec.decode(buffer, offset); - String value = new StringDelta(subtractionLength, delta).applyTo(getPreviousValue(object, field, context)); + String value = new StringDelta(subtractionLength, delta).applyTo(getPreviousValue(object, context)); dictionaryEntry.set(value); object.set(index, value); } - private String getPreviousValue(EObject object, Scalar field, Context context) { + private String getPreviousValue(EObject object, Context context) { if (!dictionaryEntry.isDefined()) { if (operator.hasDefaultValue()) return operator.getDefaultValue(); return ""; } else if (dictionaryEntry.isNull()) { - context.getErrorHandler().error(FastConstants.D6_MNDTRY_FIELD_NOT_PRESENT, "The field " + field + " must have a priorValue defined."); + context.getErrorHandler().error(FastConstants.D6_MNDTRY_FIELD_NOT_PRESENT, "The field must have a priorValue defined."); return ""; } return dictionaryEntry.getString(); } - public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) {} + public void decodeEmpty(EObject object, int index, Context context) {} - public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public int encode(EObject object, int index, byte[] buffer, int offset, Context context) { if (!object.isDefined(index)){ buffer[offset] = Fast.NULL; return offset + 1; } String value = object.getString(index); - StringDelta diff = StringDelta.diff(value, getPreviousValue(object, field, context)); + StringDelta diff = StringDelta.diff(value, getPreviousValue(object, context)); int subtractionLength = diff.getSubtractionLength(); int newOffset = integerCodec.encode(buffer, offset, subtractionLength); dictionaryEntry.set(value); Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -3,14 +3,13 @@ import static org.openfast.Fast.NULL; import org.lasalletech.entity.EObject; import org.openfast.Context; +import org.openfast.codec.FieldCodec; import org.openfast.codec.IntegerCodec; -import org.openfast.codec.ScalarCodec; import org.openfast.dictionary.DictionaryEntry; import org.openfast.error.FastConstants; -import org.openfast.template.Scalar; import org.openfast.template.operator.DictionaryOperator; -public class DeltaIntegerCodec extends DictionaryOperatorIntegerCodec implements ScalarCodec { +public class DeltaIntegerCodec extends DictionaryOperatorIntegerCodec implements FieldCodec { public DeltaIntegerCodec(DictionaryEntry entry, DictionaryOperator operator, IntegerCodec integerDeltaCodec) { super(entry, operator, integerDeltaCodec); @@ -20,36 +19,36 @@ return integerCodec.getLength(buffer, offset); } - public void decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public void decode(EObject object, int index, byte[] buffer, int offset, Context context) { if (integerCodec.isNull(buffer, offset)) { return; } int delta = integerCodec.decode(buffer, offset); - int previousValue = getPreviousValue(object, context, field); + int previousValue = getPreviousValue(object, context); int newValue = delta + previousValue; object.set(index, newValue); dictionaryEntry.set(newValue); } - private int getPreviousValue(EObject object, Context context, Scalar field) { + private int getPreviousValue(EObject object, Context context) { if (!dictionaryEntry.isDefined()) { return initialValue; } else if (dictionaryEntry.isNull()) { - context.getErrorHandler().error(FastConstants.D6_MNDTRY_FIELD_NOT_PRESENT, "The field " + field + " must have a priorValue defined."); + context.getErrorHandler().error(FastConstants.D6_MNDTRY_FIELD_NOT_PRESENT, "The field must have a priorValue defined."); return 0; } return dictionaryEntry.getInt(); } - public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) {} + public void decodeEmpty(EObject object, int index, Context context) {} - public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public int encode(EObject object, int index, byte[] buffer, int offset, Context context) { if (!object.isDefined(index)) { buffer[offset] = NULL; return offset + 1; } int value = object.getInt(index); - int previousValue = getPreviousValue(object, context, field); + int previousValue = getPreviousValue(object, context); dictionaryEntry.set(value); return integerCodec.encode(buffer, offset, value - previousValue); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaOperatorCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaOperatorCodecFactory.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaOperatorCodecFactory.java 2008-07-31 18:04:01 UTC (rev 181) @@ -1,7 +1,7 @@ package org.openfast.codec.operator; +import org.openfast.codec.FieldCodec; import org.openfast.codec.IntegerCodec; -import org.openfast.codec.ScalarCodec; import org.openfast.codec.ScalarCodecFactory; import org.openfast.codec.StringCodec; import org.openfast.dictionary.DictionaryEntry; @@ -14,7 +14,7 @@ import org.openfast.template.type.IntegerType; public class DeltaOperatorCodecFactory implements ScalarCodecFactory { - public ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, + public FieldCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, DictionaryRegistry dictionaryRegistry) { DictionaryEntry entry = dictionaryRegistry.get(((DictionaryOperator) scalar.getOperator()).getDictionary()).getEntry(scalar); if (FastTypes.ASCII.equals(scalar.getType())) { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorIntegerCodec.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorIntegerCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -1,13 +1,12 @@ package org.openfast.codec.operator; +import org.openfast.codec.FieldCodec; import org.openfast.codec.IntegerCodec; -import org.openfast.codec.ScalarCodec; import org.openfast.codec.SinglePresenceMapEntryFieldCodec; import org.openfast.dictionary.DictionaryEntry; -import org.openfast.template.Scalar; import org.openfast.template.operator.DictionaryOperator; -public abstract class DictionaryOperatorIntegerCodec extends SinglePresenceMapEntryFieldCodec<Scalar> implements ScalarCodec { +public abstract class DictionaryOperatorIntegerCodec extends SinglePresenceMapEntryFieldCodec implements FieldCodec { protected final IntegerCodec integerCodec; protected final DictionaryOperator operator; protected final int initialValue; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorLongCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorLongCodec.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorLongCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -1,13 +1,12 @@ package org.openfast.codec.operator; +import org.openfast.codec.FieldCodec; import org.openfast.codec.LongCodec; -import org.openfast.codec.ScalarCodec; import org.openfast.codec.SinglePresenceMapEntryFieldCodec; import org.openfast.dictionary.DictionaryEntry; -import org.openfast.template.Scalar; import org.openfast.template.operator.DictionaryOperator; -public abstract class DictionaryOperatorLongCodec extends SinglePresenceMapEntryFieldCodec<Scalar> implements ScalarCodec { +public abstract class DictionaryOperatorLongCodec extends SinglePresenceMapEntryFieldCodec implements FieldCodec { protected final LongCodec longCodec; protected final DictionaryOperator operator; protected final long initialValue; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorStringCodec.java 2008-07-23 21:09:20 UTC (rev 180) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorStringCodec.java 2008-07-31 18:04:01 UTC (rev 181) @@ -1,13 +1,12 @@ package org.openfast.codec.operator; -import org.openfast.codec.ScalarCodec; +import org.openfast.codec.FieldCodec; import org.openfast.codec.SinglePresenceMapEntryFieldCodec; import org.openfast.codec.StringCodec; import org.openfast.dictionary.DictionaryEntry; -import org.openfast.template.Scalar; import org.openfast.template.operator.DictionaryOperator; -public abstract class DictionaryOperatorStringCodec extends SinglePresenceMapEntryFieldCodec<Scalar> implements ScalarCodec { +public abstract class DictionaryOperatorStr... [truncated message content] |
From: <ope...@li...> - 2008-07-23 21:09:19
|
Revision: 180 http://openfast.svn.sourceforge.net/openfast/?rev=180&view=rev Author: jacob_northey Date: 2008-07-23 21:09:20 +0000 (Wed, 23 Jul 2008) Log Message: ----------- Finished all type codecs (Decimal, ULong, Long, ByteVector, Unicode String) Modified Paths: -------------- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java branches/openfast-2.x/core/src/main/java/org/openfast/MessageHandler.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicTypeCodecRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/Coder.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastEncoder.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/StringDelta.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/AsciiStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/FastTypeCodecs.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableAsciiStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableSignedIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableUnsignedIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/SignedIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/StopBitEncodedTypeCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/UnsignedIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/AbstractDictionaryEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/IntegerEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/StringEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/error/FastConstants.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastTypes.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast_1_1Implementation.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/XMLMessageTemplateLoader.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/ByteVectorType.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/DecimalType.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/IntegerType.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/StringType.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/CopyIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/DeltaAsciiCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/DeltaIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/IncrementIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/AsciiStringCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/SignedIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/test/OpenFastTestCase.java branches/openfast-2.x/core/src/test/resources/acceptance/integerTemplates.xml branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/examples/simple/SimpleClient.java branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/examples/simple/SimpleServer.java branches/openfast-2.x/examples/src/main/resources/simple/data/constantU32.csv branches/openfast-2.x/examples/src/main/resources/simple/templates/commonTemplates.xml branches/openfast-2.x/nio/src/main/java/com/lasalletech/openfast/nio/mina/FastMessageDecoder.java Added Paths: ----------- branches/openfast-2.x/core/src/main/java/org/openfast/Decimal.java branches/openfast-2.x/core/src/main/java/org/openfast/ULong.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/ByteVectorCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/DecimalCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/LongCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/ULongCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorLongCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorULongCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementLongCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementULongCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/MandatoryConstantStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/OptionalConstantStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/TailAsciiCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/TailOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/BasicByteVectorCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/BasicDecimalCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/BasicULongCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/LengthEncodedTypeCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableByteVectorCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableDecimalCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableSignedLongCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableULongCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableUnicodeStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableUnsignedLongCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/SignedLongCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/UnicodeStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/UnsignedLongCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/BasicFastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/LongEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/template/ScalarBuilder.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/AbstractType.java branches/openfast-2.x/core/src/test/java/org/openfast/ULongTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastLongOperatorTestHarness.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/IncrementLongCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/StringDeltaTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/BasicByteVectorCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/BasicDecimalCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/BasicULongCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/NullableAsciiStringCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/NullableByteVectorCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/NullableDecimalCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/NullableSignedIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/NullableSignedLongCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/NullableULongCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/NullableUnicodeStringCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/NullableUnsignedIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/NullableUnsignedLongCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/SignedLongCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/UnicodeStringCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/UnsignedIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/UnsignedLongCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/dictionary/ branches/openfast-2.x/examples/src/main/resources/simple/data/constantAscii.csv branches/openfast-2.x/examples/src/main/resources/simple/data/deltaAscii.csv branches/openfast-2.x/examples/src/main/resources/simple/data/tailAscii.csv branches/openfast-2.x/examples/src/main/resources/simple/templates/asciiTemplates.xml branches/openfast-2.x/examples/src/main/resources/simple/templates/u32Templates.xml Removed Paths: ------------- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/Type.java branches/openfast-2.x/examples/src/main/resources/simple/templates/integerTemplates.xml branches/openfast-2.x/examples/src/main/resources/simple/templates/stringTemplates.xml Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Context.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-07-21 14:00:33 UTC (rev 179) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-07-23 21:09:20 UTC (rev 180) @@ -26,7 +26,7 @@ import java.util.Map; import org.lasalletech.entity.QName; import org.openfast.dictionary.FastDictionary; -import org.openfast.dictionary.GlobalFastDictionary; +import org.openfast.dictionary.BasicFastDictionary; import org.openfast.error.ErrorHandler; import org.openfast.error.FastConstants; import org.openfast.template.BasicTemplateRegistry; @@ -50,7 +50,7 @@ private byte[] tempBuffer = new byte[1024 * 32]; // max 32 kB message size public Context() { - dictionaries.put("global", new GlobalFastDictionary()); + dictionaries.put("global", new BasicFastDictionary()); } public int getTemplateId(MessageTemplate template) { if (!templateRegistry.isRegistered(template)) { Added: branches/openfast-2.x/core/src/main/java/org/openfast/Decimal.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Decimal.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Decimal.java 2008-07-23 21:09:20 UTC (rev 180) @@ -0,0 +1,86 @@ +package org.openfast; + +import java.math.BigDecimal; +import java.math.BigInteger; + +public class Decimal extends Number { + private static final long serialVersionUID = 1L; + public final int exponent; + public final long mantissa; + + public Decimal(double value) { + if (value == 0.0) { + this.exponent = 0; + this.mantissa = 0; + + return; + } + + 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 Decimal(long mantissa, int exponent) { + this.mantissa = mantissa; + this.exponent = exponent; + } + + public Decimal(BigDecimal bigDecimal) { + this.mantissa = bigDecimal.unscaledValue().longValue(); + this.exponent = bigDecimal.scale(); + } + + public BigDecimal toBigDecimal() { + return new BigDecimal(BigInteger.valueOf(mantissa), -exponent); + } + + @Override + public int hashCode() { + return (exponent * 37 + ((int)mantissa)); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (obj == null || !(obj instanceof Decimal)) return false; + return equals((Decimal) obj); + } + + private boolean equals(Decimal decimal) { + return mantissa == decimal.mantissa && exponent == decimal.exponent; + } + + @Override + public String toString() { + return toBigDecimal().toPlainString(); + } + + @Override + public double doubleValue() { + return mantissa * Math.pow(10.0, exponent); + } + + @Override + public float floatValue() { + return (float) (mantissa * Math.pow(10.0, exponent)); + } + + @Override + public int intValue() { + return (int) doubleValue(); + } + + @Override + public long longValue() { + return (long) doubleValue(); + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java 2008-07-21 14:00:33 UTC (rev 179) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java 2008-07-23 21:09:20 UTC (rev 180) @@ -12,4 +12,6 @@ public static final String GLOBAL = "global"; public static final String TEMPLATE = "template"; public static final MessageTemplateFactory SIMPLE = new SimpleMessageTemplateFactory(); + public static final String SCP_1_1_NAMESPACE = "http://www.fixprotocol.org/ns/fast/scp/1.1"; + public static final byte SIGN_BIT = 0x40; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/MessageHandler.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/MessageHandler.java 2008-07-21 14:00:33 UTC (rev 179) +++ branches/openfast-2.x/core/src/main/java/org/openfast/MessageHandler.java 2008-07-23 21:09:20 UTC (rev 180) @@ -24,5 +24,5 @@ public interface MessageHandler { - void handleMessage(Message readMessage, Context context, Coder coder); + void handleMessage(Message message, Context context, Coder coder); } Added: branches/openfast-2.x/core/src/main/java/org/openfast/ULong.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/ULong.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/ULong.java 2008-07-23 21:09:20 UTC (rev 180) @@ -0,0 +1,132 @@ +package org.openfast; + +import java.math.BigInteger; + +/** + * Represents an unsigned 64-bit integer number. Callers should + * check isLarge to prevent data loss. + * + * <blockquote><pre> + * ULong ulong = FastTypeCodecs.ULONG.decode(buffer, offset); + * if (ulong.isLarge()) { + * BigInteger bigInt = ulong.toBigInteger(); + * // handle large value cases + * } else { + * long value = ulong.longValue(); + * // handle regular case + * } + * </pre></blockquote> + * + * @author Jacob Northey + */ +public class ULong extends Number { + private static final long serialVersionUID = 1L; + private static final long SIGN_BIT = 0x8000000000000000L; + private final long value; + public static final long MAX_VALUE = 0xffffffffffffffffL; + + public ULong(long raw) { + this.value = raw; + } + + @Override + public double doubleValue() { + return longValue(); + } + + @Override + public float floatValue() { + return longValue(); + } + + @Override + public int intValue() { + return (int) longValue(); + } + + /** + * Callers should check isLarge to see if the ULong + * is too large to be contained in a primitive long + * to prevent data loss. + * + * @return the long value of this ULong. + */ + @Override + public long longValue() { + return value; + } + + public BigInteger toBigInteger() { + return new BigInteger(toByteArray()); + } + + /** + * Converts the long value to the two's-complement, + * big-endian representation. + * + * @return byte array containing the value of this ULong + */ + public byte[] toByteArray() { + int size = getSize(value); + byte[] bytes = new byte[size]; + int index = bytes.length - 1; + long l = value; + while (index >= 0) { + bytes[index] = (byte) (l & 0xff); + l >>>= 8; + index--; + } + return bytes; + } + + private static int getSize(long value) { + if (value < 0) { + return 9; + } else if (value <= 0x7f) { + return 1; + } else if (value <= 0x7fff) { + return 2; + } else if (value <= 0x7fffff) { + return 3; + } else if (value <= 0x7fffffff) { + return 4; + } else if (value <= 0x7fffffffffL) { + return 5; + } else if (value <= 0x7fffffffffffL) { + return 6; + } else if (value <= 0x7fffffffffffffL) { + return 7; + } + return 8; + } + + /** + * This method should be called before calling {@link #longValue()} + * + * @return true if the value is too large for a primitive long + */ + public boolean isLarge() { + return (value & SIGN_BIT) == SIGN_BIT; + } + + @Override + public String toString() { + return toBigInteger().toString(); + } + + @Override + public int hashCode() { + return (int)(value * 37); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (obj == null || !(obj instanceof ULong)) return false; + return equals((ULong) obj); + } + + public boolean equals(ULong other) { + return value == other.value; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java 2008-07-21 14:00:33 UTC (rev 179) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java 2008-07-23 21:09:20 UTC (rev 180) @@ -1,6 +1,5 @@ package org.openfast.codec; -import org.openfast.ByteUtil; import org.openfast.Context; import org.openfast.Message; import org.openfast.dictionary.DictionaryRegistry; @@ -15,14 +14,14 @@ public class BasicMessageCodec implements MessageCodec { private final int templateId; - private final IntegerCodec uintCodec; + private final LongCodec uintCodec; private final BitVectorCodec bitVectorCodec; @SuppressWarnings("unchecked") private final FieldCodec[] fieldCodecs; public BasicMessageCodec(int id, MessageTemplate template, FastImplementation implementation, DictionaryRegistry dictionaryRegistry, CodecFactory codecFactory) { this.templateId = id; - this.uintCodec = implementation.getTypeCodecRegistry().getIntegerCodec(FastTypes.U32); + this.uintCodec = implementation.getTypeCodecRegistry().getLongCodec(FastTypes.U32); this.bitVectorCodec = implementation.getTypeCodecRegistry().getBitVectorCodec(FastTypes.BIT_VECTOR); this.fieldCodecs = new FieldCodec[template.getFieldCount()]; int index = 0; @@ -59,7 +58,6 @@ } finally { context.discardTemporaryBuffer(temp); } - System.out.println(ByteUtil.convertByteArrayToBitString(buffer, offset + pmapLen + index)); return offset + pmapLen + index; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicTypeCodecRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicTypeCodecRegistry.java 2008-07-21 14:00:33 UTC (rev 179) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicTypeCodecRegistry.java 2008-07-23 21:09:20 UTC (rev 180) @@ -39,4 +39,20 @@ public BitVectorCodec getBitVectorCodec(Type type) { return (BitVectorCodec) getCodec(type, false); } + + public LongCodec getLongCodec(Type type) { + return (LongCodec) getCodec(type, false); + } + + public LongCodec getLongCodec(Type type, boolean nullable) { + return (LongCodec) getCodec(type, nullable); + } + + public ULongCodec getULongCodec(Type type) { + return null; + } + + public ULongCodec getULongCodec(Type type, boolean nullable) { + return null; + } } Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/ByteVectorCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/ByteVectorCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/ByteVectorCodec.java 2008-07-23 21:09:20 UTC (rev 180) @@ -0,0 +1,7 @@ +package org.openfast.codec; + + +public interface ByteVectorCodec extends TypeCodec { + byte[] decode(byte[] buffer, int offset); + int encode(byte[] buffer, int offset, byte[] bytes); +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/Coder.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/Coder.java 2008-07-21 14:00:33 UTC (rev 179) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/Coder.java 2008-07-23 21:09:20 UTC (rev 180) @@ -20,6 +20,10 @@ */ package org.openfast.codec; +import org.openfast.MessageHandler; +import org.openfast.template.MessageTemplate; + public interface Coder { void reset(); + void registerMessageHandler(MessageTemplate template, MessageHandler messageHandler); } Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/DecimalCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/DecimalCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/DecimalCodec.java 2008-07-23 21:09:20 UTC (rev 180) @@ -0,0 +1,8 @@ +package org.openfast.codec; + +import org.openfast.Decimal; + +public interface DecimalCodec extends TypeCodec { + Decimal decode(byte[] buffer, int offset); + int encode(byte[] buffer, int offset, Decimal value); +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java 2008-07-21 14:00:33 UTC (rev 179) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java 2008-07-23 21:09:20 UTC (rev 180) @@ -1,7 +1,10 @@ package org.openfast.codec; +import java.util.HashMap; +import java.util.Map; import org.openfast.Context; import org.openfast.Message; +import org.openfast.MessageHandler; import org.openfast.dictionary.BasicDictionaryRegistry; import org.openfast.dictionary.DictionaryRegistry; import org.openfast.fast.FastTypes; @@ -17,7 +20,8 @@ private final FastImplementation implementation; private final DictionaryRegistry dictionaryRegistry; private final BitVectorCodec bitVectorCodec; - private final IntegerCodec uintCodec; + private final LongCodec uintCodec; + private Map<MessageTemplate, MessageHandler> messageHandlers = new HashMap<MessageTemplate, MessageHandler>(); public FastDecoder(TemplateRegistry templateRegistry) { this(FastImplementation.getDefaultVersion(), templateRegistry); @@ -28,7 +32,7 @@ this.implementation = implementation; dictionaryRegistry = new BasicDictionaryRegistry(implementation.getDictionaryTypeRegistry()); bitVectorCodec = implementation.getTypeCodecRegistry().getBitVectorCodec(FastTypes.BIT_VECTOR); - uintCodec = implementation.getTypeCodecRegistry().getIntegerCodec(FastTypes.U32); + uintCodec = implementation.getTypeCodecRegistry().getLongCodec(FastTypes.U32); } public Message decode(byte[] buffer, int offset) { @@ -36,7 +40,7 @@ offset += bitVectorCodec.getLength(buffer, offset); int templateId = 0; if (reader.read()) { - templateId = uintCodec.decode(buffer, offset); + templateId = (int) uintCodec.decode(buffer, offset); offset += uintCodec.getLength(buffer, offset); context.setLastTemplateId(templateId); } else { @@ -46,6 +50,8 @@ MessageCodec codec = getCodec(templateId, template); Message message = template.newObject(); codec.decode(message, buffer, offset, reader, context); + if (messageHandlers.containsKey(message.getTemplate())) + messageHandlers.get(message.getTemplate()).handleMessage(message, context, this); return message; } @@ -65,7 +71,7 @@ int newOffset = offset + bitVectorCodec.getLength(buffer, offset); int templateId = 0; if (reader.read()) { - templateId = uintCodec.decode(buffer, newOffset); + templateId = (int) uintCodec.decode(buffer, newOffset); newOffset += uintCodec.getLength(buffer, newOffset); } else { templateId = context.getLastTemplateId(); @@ -75,4 +81,8 @@ newOffset += codec.getLength(buffer, newOffset, reader, context); return newOffset - offset; } + + public void registerMessageHandler(MessageTemplate template, MessageHandler messageHandler) { + messageHandlers.put(template, messageHandler); + } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastEncoder.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastEncoder.java 2008-07-21 14:00:33 UTC (rev 179) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastEncoder.java 2008-07-23 21:09:20 UTC (rev 180) @@ -1,10 +1,14 @@ package org.openfast.codec; +import java.util.HashMap; +import java.util.Map; import org.openfast.Context; import org.openfast.Message; +import org.openfast.MessageHandler; import org.openfast.dictionary.BasicDictionaryRegistry; import org.openfast.dictionary.DictionaryRegistry; import org.openfast.fast.impl.FastImplementation; +import org.openfast.template.MessageTemplate; import org.openfast.template.TemplateRegistry; public class FastEncoder implements Coder { @@ -13,6 +17,7 @@ private final FastImplementation implementation; private final DictionaryRegistry dictionaryRegistry; private MessageCodecRegistry codecRegistry = new BasicCodecRegistry(); + private Map<MessageTemplate, MessageHandler> handlers = new HashMap<MessageTemplate, MessageHandler>(); public FastEncoder(TemplateRegistry templateRegistry) { this(FastImplementation.getDefaultVersion(), templateRegistry); @@ -25,12 +30,13 @@ codecFactory = implementation.getCodecFactory(); } - public void setFastImplementation(FastImplementation implementation) { - } - public int encode(byte[] buffer, int offset, Message message) { MessageCodec encoder = getEncoder(message); - return encoder.encode(buffer, offset, message, context); + int encoded = encoder.encode(buffer, offset, message, context); + if (handlers.containsKey(message.getTemplate())) { + handlers.get(message.getTemplate()).handleMessage(message, context, this); + } + return encoded; } public void reset() { @@ -44,4 +50,8 @@ } return codecRegistry.get(id); } + + public void registerMessageHandler(MessageTemplate template, MessageHandler messageHandler) { + handlers.put(template, messageHandler); + } } Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/LongCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/LongCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/LongCodec.java 2008-07-23 21:09:20 UTC (rev 180) @@ -0,0 +1,6 @@ +package org.openfast.codec; + +public interface LongCodec extends TypeCodec { + long decode(byte[] buffer, int offset); + int encode(byte[] buffer, int offset, long value); +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java 2008-07-21 14:00:33 UTC (rev 179) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java 2008-07-23 21:09:20 UTC (rev 180) @@ -8,7 +8,11 @@ IntegerCodec getIntegerCodec(Type type, boolean nullable); StringCodec getStringCodec(Type type); StringCodec getStringCodec(Type type, boolean nullable); - BitVectorCodec getBitVectorCodec(Type bitVector); + BitVectorCodec getBitVectorCodec(Type type); + ULongCodec getULongCodec(Type type); + ULongCodec getULongCodec(Type type, boolean nullable); + LongCodec getLongCodec(Type type); + LongCodec getLongCodec(Type type, boolean nullable); void register(Type type, TypeCodec codec); void register(Type type, boolean nullable, TypeCodec codec); Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/ULongCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/ULongCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/ULongCodec.java 2008-07-23 21:09:20 UTC (rev 180) @@ -0,0 +1,8 @@ +package org.openfast.codec; + +import org.openfast.ULong; + +public interface ULongCodec extends TypeCodec { + ULong decode(byte[] buffer, int offset); + int encode(byte[] buffer, int offset, ULong value); +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantOperatorCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantOperatorCodecFactory.java 2008-07-21 14:00:33 UTC (rev 179) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantOperatorCodecFactory.java 2008-07-23 21:09:20 UTC (rev 180) @@ -7,6 +7,7 @@ import org.openfast.template.MessageTemplate; import org.openfast.template.Scalar; import org.openfast.template.type.IntegerType; +import org.openfast.template.type.StringType; public class ConstantOperatorCodecFactory implements ScalarCodecFactory { public ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, @@ -17,6 +18,10 @@ return new OptionalConstantIntegerCodec(defaultValue); } return new MandatoryConstantIntegerCodec(defaultValue); + } else if (scalar.getType() instanceof StringType) { + if (scalar.isOptional()) + return new OptionalConstantStringCodec(scalar.getOperator().getDefaultValue()); + return new MandatoryConstantStringCodec(scalar.getOperator().getDefaultValue()); } return null; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java 2008-07-21 14:00:33 UTC (rev 179) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java 2008-07-23 21:09:20 UTC (rev 180) @@ -31,7 +31,7 @@ return; } int subtractionLength = integerCodec.decode(buffer, offset); - offset = integerCodec.getLength(buffer, offset); + offset += integerCodec.getLength(buffer, offset); String delta = stringCodec.decode(buffer, offset); String value = new StringDelta(subtractionLength, delta).applyTo(getPreviousValue(object, field, context)); dictionaryEntry.set(value); @@ -57,8 +57,11 @@ buffer[offset] = Fast.NULL; return offset + 1; } - StringDelta diff = StringDelta.diff(object.getString(index), getPreviousValue(object, field, context)); - int newOffset = integerCodec.encode(buffer, offset, diff.getSubtractionLength()); + String value = object.getString(index); + StringDelta diff = StringDelta.diff(value, getPreviousValue(object, field, context)); + int subtractionLength = diff.getSubtractionLength(); + int newOffset = integerCodec.encode(buffer, offset, subtractionLength); + dictionaryEntry.set(value); return stringCodec.encode(buffer, newOffset, diff.getValue()); } } Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorLongCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorLongCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorLongCodec.java 2008-07-23 21:09:20 UTC (rev 180) @@ -0,0 +1,23 @@ +package org.openfast.codec.operator; + +import org.openfast.codec.LongCodec; +import org.openfast.codec.ScalarCodec; +import org.openfast.codec.SinglePresenceMapEntryFieldCodec; +import org.openfast.dictionary.DictionaryEntry; +import org.openfast.template.Scalar; +import org.openfast.template.operator.DictionaryOperator; + +public abstract class DictionaryOperatorLongCodec extends SinglePresenceMapEntryFieldCodec<Scalar> implements ScalarCodec { + protected final LongCodec longCodec; + protected final DictionaryOperator operator; + protected final long initialValue; + protected final DictionaryEntry dictionaryEntry; + + public DictionaryOperatorLongCodec(DictionaryEntry entry, DictionaryOperator operator, LongCodec longCodec) { + if (entry == null || operator == null || longCodec == null) throw new NullPointerException(); + this.dictionaryEntry = entry; + this.longCodec = longCodec; + this.operator = operator; + this.initialValue = operator.hasDefaultValue() ? Long.parseLong(operator.getDefaultValue()) : 0; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorULongCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorULongCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorULongCodec.java 2008-07-23 21:09:20 UTC (rev 180) @@ -0,0 +1,23 @@ +package org.openfast.codec.operator; + +import org.openfast.codec.ScalarCodec; +import org.openfast.codec.SinglePresenceMapEntryFieldCodec; +import org.openfast.codec.ULongCodec; +import org.openfast.dictionary.DictionaryEntry; +import org.openfast.template.Scalar; +import org.openfast.template.operator.DictionaryOperator; + +public abstract class DictionaryOperatorULongCodec extends SinglePresenceMapEntryFieldCodec<Scalar> implements ScalarCodec { + protected final ULongCodec longCodec; + protected final DictionaryOperator operator; + protected final long initialValue; + protected final DictionaryEntry dictionaryEntry; + + public DictionaryOperatorULongCodec(DictionaryEntry entry, DictionaryOperator operator, ULongCodec longCodec) { + if (entry == null || operator == null || longCodec == null) throw new NullPointerException(); + this.dictionaryEntry = entry; + this.longCodec = longCodec; + this.operator = operator; + this.initialValue = operator.hasDefaultValue() ? Long.parseLong(operator.getDefaultValue()) : 0; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementLongCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementLongCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementLongCodec.java 2008-07-23 21:09:20 UTC (rev 180) @@ -0,0 +1,117 @@ +/* +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.codec.operator; + +import org.lasalletech.entity.EObject; +import org.openfast.Context; +import org.openfast.codec.LongCodec; +import org.openfast.codec.ScalarCodec; +import org.openfast.dictionary.DictionaryEntry; +import org.openfast.error.FastConstants; +import org.openfast.template.Scalar; +import org.openfast.template.operator.DictionaryOperator; + +public final class IncrementLongCodec extends DictionaryOperatorLongCodec implements ScalarCodec { + private static final long serialVersionUID = 1L; + + public IncrementLongCodec(DictionaryEntry dictionaryEntry, DictionaryOperator operator, LongCodec longCodec) { + super(dictionaryEntry, operator, longCodec); + + } + + public void decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { + if (longCodec.isNull(buffer, offset)) + return; + long value = longCodec.decode(buffer, offset); + dictionaryEntry.set(value); + object.set(index, value); + } + + public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { + if (dictionaryEntry.isNull()) { + // leave object value set to null + dictionaryEntry.setNull(); + } else if (!dictionaryEntry.isDefined()) { + if (operator.hasDefaultValue()) { + object.set(index, initialValue); + dictionaryEntry.set(initialValue); + } else { + if (!scalar.isOptional()) { + throw new IllegalStateException("Field with operator increment must send a value if no previous value existed."); + } else { + // leave object value set to null + dictionaryEntry.setNull(); + } + } + } else { + long previousValue = dictionaryEntry.getLong(); + object.set(index, previousValue + 1); + dictionaryEntry.set(previousValue + 1); + } + } + + public int getLength(byte[] buffer, int offset) { + return longCodec.getLength(buffer, offset); + } + + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { + if (!object.isDefined(index)) { + if (!scalar.isOptional()) { + // TODO - error when value is null and scalar is mandatory + } + if (dictionaryEntry.isNull()) + return offset; + else { + return encodeNull(buffer, offset, context, scalar); + } + } + long value = object.getLong(index); + if (dictionaryEntry.isNull()) { + dictionaryEntry.set(value); + return longCodec.encode(buffer, offset, value); + } + if (!dictionaryEntry.isDefined()) { + if (!operator.hasDefaultValue()) { + dictionaryEntry.set(value); + return longCodec.encode(buffer, offset, value); + } else if (operator.hasDefaultValue() && value == initialValue) { + dictionaryEntry.set(value); + return offset; + } else { + return longCodec.encode(buffer, offset, value); + } + } + long previousValue = dictionaryEntry.getLong(); + if (value == previousValue + 1) { + dictionaryEntry.set(value); + return offset; + } + + dictionaryEntry.set(value); + return longCodec.encode(buffer, offset, value); + } + + private int encodeNull(byte[] buffer, int offset, Context context, Scalar scalar) { + buffer[offset] = FastConstants.NULL_BYTE; + dictionaryEntry.setNull(); + return offset + 1; + } +} \ No newline at end of file Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementOperatorCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementOperatorCodecFactory.java 2008-07-21 14:00:33 UTC (rev 179) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementOperatorCodecFactory.java 2008-07-23 21:09:20 UTC (rev 180) @@ -1,10 +1,13 @@ package org.openfast.codec.operator; import org.openfast.codec.IntegerCodec; +import org.openfast.codec.LongCodec; import org.openfast.codec.ScalarCodec; import org.openfast.codec.ScalarCodecFactory; +import org.openfast.codec.ULongCodec; import org.openfast.dictionary.DictionaryEntry; import org.openfast.dictionary.DictionaryRegistry; +import org.openfast.fast.FastTypes; import org.openfast.fast.impl.FastImplementation; import org.openfast.template.MessageTemplate; import org.openfast.template.Scalar; @@ -13,9 +16,16 @@ public class IncrementOperatorCodecFactory implements ScalarCodecFactory { public ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, DictionaryRegistry dictionaryRegistry) { - IntegerCodec integerCodec = implementation.getTypeCodecRegistry().getIntegerCodec(scalar.getType(), scalar.isOptional()); DictionaryOperator operator = (DictionaryOperator) scalar.getOperator(); DictionaryEntry entry = dictionaryRegistry.get(((DictionaryOperator)scalar.getOperator()).getDictionary()).getEntry(scalar); + if (FastTypes.U64.equals(scalar.getType())) { + ULongCodec ulongCodec = implementation.getTypeCodecRegistry().getULongCodec(scalar.getType(), scalar.isOptional()); + return new IncrementULongCodec(entry, operator, ulongCodec); + } else if (FastTypes.U32.equals(scalar.getType()) || FastTypes.I64.equals(scalar.getType())) { + LongCodec longCodec = implementation.getTypeCodecRegistry().getLongCodec(scalar.getType(), scalar.isOptional()); + return new IncrementLongCodec(entry, operator, longCodec); + } + IntegerCodec integerCodec = implementation.getTypeCodecRegistry().getIntegerCodec(scalar.getType(), scalar.isOptional()); return new IncrementIntegerCodec(entry, operator, integerCodec); } } Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementULongCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementULongCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementULongCodec.java 2008-07-23 21:09:20 UTC (rev 180) @@ -0,0 +1,118 @@ +/* +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.codec.operator; + +import org.lasalletech.entity.EObject; +import org.openfast.Context; +import org.openfast.ULong; +import org.openfast.codec.ScalarCodec; +import org.openfast.codec.ULongCodec; +import org.openfast.dictionary.DictionaryEntry; +import org.openfast.error.FastConstants; +import org.openfast.template.Scalar; +import org.openfast.template.operator.DictionaryOperator; + +public final class IncrementULongCodec extends DictionaryOperatorULongCodec implements ScalarCodec { + private static final long serialVersionUID = 1L; + + public IncrementULongCodec(DictionaryEntry dictionaryEntry, DictionaryOperator operator, ULongCodec longCodec) { + super(dictionaryEntry, operator, longCodec); + + } + + public void decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { + if (longCodec.isNull(buffer, offset)) + return; + ULong value = longCodec.decode(buffer, offset); + dictionaryEntry.set(value.longValue()); + object.set(index, value); + } + + public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { + if (dictionaryEntry.isNull()) { + // leave object value set to null + dictionaryEntry.setNull(); + } else if (!dictionaryEntry.isDefined()) { + if (operator.hasDefaultValue()) { + object.set(index, initialValue); + dictionaryEntry.set(initialValue); + } else { + if (!scalar.isOptional()) { + throw new IllegalStateException("Field with operator increment must send a value if no previous value existed."); + } else { + // leave object value set to null + dictionaryEntry.setNull(); + } + } + } else { + long previousValue = dictionaryEntry.getLong(); + object.set(index, previousValue + 1); + dictionaryEntry.set(previousValue + 1); + } + } + + public int getLength(byte[] buffer, int offset) { + return longCodec.getLength(buffer, offset); + } + + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { + if (!object.isDefined(index)) { + if (!scalar.isOptional()) { + // TODO - error when value is null and scalar is mandatory + } + if (dictionaryEntry.isNull()) + return offset; + else { + return encodeNull(buffer, offset, context, scalar); + } + } + long value = object.getLong(index); + if (dictionaryEntry.isNull()) { + dictionaryEntry.set(value); + return longCodec.encode(buffer, offset, new ULong(value)); + } + if (!dictionaryEntry.isDefined()) { + if (!operator.hasDefaultValue()) { + dictionaryEntry.set(value); + return longCodec.encode(buffer, offset, new ULong(value)); + } else if (operator.hasDefaultValue() && value == initialValue) { + dictionaryEntry.set(value); + return offset; + } else { + return longCodec.encode(buffer, offset, new ULong(value)); + } + } + long previousValue = dictionaryEntry.getLong(); + if (value == previousValue + 1) { + dictionaryEntry.set(value); + return offset; + } + + dictionaryEntry.set(value); + return longCodec.encode(buffer, offset, new ULong(value)); + } + + private int encodeNull(byte[] buffer, int offset, Context context, Scalar scalar) { + buffer[offset] = FastConstants.NULL_BYTE; + dictionaryEntry.setNull(); + return offset + 1; + } +} \ No newline at end of file Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/MandatoryConstantStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/MandatoryConstantStringCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/MandatoryConstantStringCodec.java 2008-07-23 21:09:20 UTC (rev 180) @@ -0,0 +1,26 @@ +package org.openfast.codec.operator; + +import org.lasalletech.entity.EObject; +import org.openfast.Context; +import org.openfast.codec.ScalarCodec; +import org.openfast.template.Scalar; +import org.openfast.util.BitVectorBuilder; +import org.openfast.util.BitVectorReader; + +public class MandatoryConstantStringCodec implements ScalarCodec { + private final String defaultValue; + + public MandatoryConstantStringCodec(String defaultValue) { + this.defaultValue = defaultValue; + } + public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, BitVectorReader reader, Context context) { + object.set(index, defaultValue); + return offset; + } + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, BitVectorBuilder pmapBuilder, Context context) { + return offset; + } + public int getLength(byte[] buffer, int offset, BitVectorReader reader) { + return 0; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/OptionalConstantStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/OptionalConstantStringCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/OptionalConstantStringCodec.java 2008-07-23 21:09:20 UTC (rev 180) @@ -0,0 +1,31 @@ +package org.openfast.codec.operator; + +import org.lasalletech.entity.EObject; +import org.openfast.Context; +import org.openfast.codec.ScalarCodec; +import org.openfast.template.Scalar; +import org.openfast.util.BitVectorBuilder; +import org.openfast.util.BitVectorReader; + +public class OptionalConstantStringCodec implements ScalarCodec { + private final String defaultValue; + + public OptionalConstantStringCodec(String defaultValue) { + this.defaultValue = defaultValue; + } + public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, BitVectorReader reader, Context context) { + if (reader.read()) + object.set(index, defaultValue); + return offset; + } + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, BitVectorBuilder pmapBuilder, Context context) { + if (object.isDefined(index)) + pmapBuilder.set(); + else + pmapBuilder.skip(); + return offset; + } + public int getLength(byte[] buffer, int offset, BitVectorReader reader) { + return 0; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/StringDelta.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/StringDelta.java 2008-07-21 14:00:33 UTC (rev 179) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/StringDelta.java 2008-07-23 21:09:20 UTC (rev 180) @@ -23,6 +23,8 @@ int length = (-1 * subtractionLength) - 1; return value + previousValue.substring(length, previousValue.length()); } + if (subtractionLength > previousValue.length()) + throw new IllegalArgumentException("The delta " + this + " cannot be applied to value \""+ previousValue + "\"."); return previousValue.substring(0, previousValue.length() - subtractionLength) + value; } Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/TailAsciiCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/TailAsciiCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/TailAsciiCodec.java 2008-07-23 21:09:20 UTC (rev 180) @@ -0,0 +1,78 @@ +package org.openfast.codec.operator; + +import org.lasalletech.entity.EObject; +import org.openfast.Context; +import org.openfast.Fast; +import org.openfast.codec.ScalarCodec; +import org.openfast.codec.StringCodec; +import org.openfast.dictionary.DictionaryEntry; +import org.openfast.error.FastConstants; +import org.openfast.template.Scalar; +import org.openfast.template.operator.DictionaryOperator; + +public class TailAsciiCodec extends DictionaryOperatorStringCodec implements ScalarCodec { + protected TailAsciiCodec(DictionaryEntry dictionaryEntry, DictionaryOperator operator, StringCodec stringCodec) { + super(dictionaryEntry, operator, stringCodec); + } + + @Override + public void decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + if (stringCodec.isNull(buffer, offset)) { + dictionaryEntry.setNull(); + return; + } + String baseValue = getBaseValue(); + String encodedValue = stringCodec.decode(buffer, offset); + String value; + if (encodedValue.length() > baseValue.length()) + value = encodedValue; + else + value = baseValue.substring(0,baseValue.length() - encodedValue.length()) + encodedValue; + dictionaryEntry.set(value); + object.set(index, value); + } + + @Override + public void decodeEmpty(EObject object, int index, Scalar field, Context context) { + object.set(index, getBaseValue()); + } + + @Override + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + if (!object.isDefined(index)) { + buffer[offset] = Fast.NULL; + dictionaryEntry.setNull(); + return offset+1; + } + String value = object.getString(index); + String baseValue = getBaseValue(); + if (value.length() < baseValue.length()) + context.getErrorHandler().error(FastConstants.D3_CANT_ENCODE_VALUE, "The value " + value + + " cannot be encoded by a tail operator with previous value " + baseValue); + dictionaryEntry.set(value); + if (value.length() > baseValue.length()) { + return stringCodec.encode(buffer, offset, value); + } + int i = 0; + while (i < value.length() && value.charAt(i) == baseValue.charAt(i)) + i++; + if (i == value.length()) + return offset; + return stringCodec.encode(buffer, offset, value.substring(i)); + } + + private String getBaseValue() { + if (dictionaryEntry.isNull()) + return ""; + if (dictionaryEntry.isDefined()) + return dictionaryEntry.getString(); + if (operator.hasDefaultValue()) + return operator.getDefaultValue(); + return ""; + } + + @Override + public int getLength(byte[] buffer, int offset) { + return stringCodec.getLength(buffer, offset); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/TailOperatorCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/TailOperatorCodecFactory.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/TailOperatorCodecFactory.java 2008-07-23 21:09:20 UTC (rev 180) @@ -0,0 +1,23 @@ +package org.openfast.codec.operator; + +import org.openfast.codec.ScalarCodec; +import org.openfast.codec.ScalarCodecFactory; +import org.openfast.codec.StringCodec; +import org.openfast.dictionary.DictionaryEntry; +import org.openfast.dictionary.DictionaryRegistry; +import org.openfast.fast.impl.FastImplementation; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; +import org.openfast.template.operator.DictionaryOperator; + +public class TailOperatorCodecFactory implements ScalarCodecFactory { + public ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, + DictionaryRegistry dictionaryRegistry) { + DictionaryEntry entry = dictionaryRegistry.get(((DictionaryOperator) scalar.getOperator()).getDictionary()).getEntry(scalar); + if ("ascii".equals(scalar.getType().getName())) { + StringCodec stringCodec = implementation.getTypeCodecRegistry().getStringCodec(scalar.getType(), scalar.isOptional()); + return new TailAsciiCodec(entry, (DictionaryOperator) scalar.getOperator(), stringCodec); + } + return null; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/AsciiStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/AsciiStringCodec.java 2008-07-21 14:00:33 UTC (rev 179) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/AsciiStringCodec.java 2008-07-23 21:09:20 UTC (rev 180) @@ -20,11 +20,14 @@ try { int length = getLength(buffer, offset); if ((buffer[offset] & Fast.VALUE_BITS) == 0) { - if (!ByteUtil.isEmpty(buffer, offset, length)) + if (!ByteUtil.isEmpty(buffer, offset, length)) { Global.handleError(FastConstants.R9_STRING_OVERLONG, null); - if (length > 1 && (buffer[offset+1] & Fast.VALUE_BITS) == 0) + offset++; + } + else if (length > 1 && (buffer[offset+1] & Fast.VALUE_BITS) == 0) return Fast.ZERO_TERMINATOR; - return ""; + else + return ""; } buffer[length + offset - 1] &= Fast.VALUE_BITS; // remove stop bit decoded = decoder.decode(ByteBuffer.wrap(buffer, offset, length)); Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/BasicByteVectorCodec.java =================================================================== ... [truncated message content] |
From: <ope...@li...> - 2008-07-21 14:00:29
|
Revision: 179 http://openfast.svn.sourceforge.net/openfast/?rev=179&view=rev Author: jacob_northey Date: 2008-07-21 14:00:33 +0000 (Mon, 21 Jul 2008) Log Message: ----------- Added example tests for U32(constant,copy,default,delta) and Ascii(copy,default) Modified Paths: -------------- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/SinglePresenceMapEntryFieldCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/AlwaysPresentCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableAsciiStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast_1_1Implementation.java branches/openfast-2.x/examples/src/main/resources/simple/templates/integerTemplates.xml branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/util/csv/CsvParser.java Added Paths: ----------- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/MandatoryConstantIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/OptionalConstantIntegerCodec.java branches/openfast-2.x/examples/src/main/resources/simple/data/constantU32.csv branches/openfast-2.x/examples/src/main/resources/simple/data/copyAscii.csv branches/openfast-2.x/examples/src/main/resources/simple/data/copyU32.csv branches/openfast-2.x/examples/src/main/resources/simple/data/defaultAscii.csv branches/openfast-2.x/examples/src/main/resources/simple/data/defaultU32.csv branches/openfast-2.x/examples/src/main/resources/simple/data/deltaU32.csv branches/openfast-2.x/examples/src/main/resources/simple/templates/stringTemplates.xml Removed Paths: ------------- branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/CopyOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/DeltaOperatorCodecFactory.java Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Context.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-07-21 14:00:33 UTC (rev 179) @@ -106,6 +106,8 @@ return traceEnabled; } public byte[] getTemporaryBuffer() { + if (tempBuffer == null) + throw new IllegalStateException("The temporary buffer was not checked in."); byte[] pointer = tempBuffer; tempBuffer = null; return pointer; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java 2008-07-21 14:00:33 UTC (rev 179) @@ -18,7 +18,10 @@ if (!codecFactories.containsKey(scalar.getOperator().getName())) { throw new IllegalArgumentException("Encountered unknown operator " + scalar.getOperator() + " in scalar " + scalar.getQName()); } - return codecFactories.get(scalar.getOperator().getName()).createCodec(template, scalar, implementation, dictionaryRegistry); + ScalarCodec codec = codecFactories.get(scalar.getOperator().getName()).createCodec(template, scalar, implementation, dictionaryRegistry); + if (codec == null) + throw new IllegalArgumentException("Could not create codec for field " + scalar); + return codec; } public void register(String operator, ScalarCodecFactory scalarCodecFactory) { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java 2008-07-21 14:00:33 UTC (rev 179) @@ -4,6 +4,7 @@ import org.openfast.Context; import org.openfast.Message; import org.openfast.dictionary.DictionaryRegistry; +import org.openfast.error.FastConstants; import org.openfast.fast.FastTypes; import org.openfast.fast.impl.FastImplementation; import org.openfast.template.Field; @@ -38,20 +39,26 @@ public int encode(byte[] buffer, int offset, Message message, Context context) { byte[] temp = context.getTemporaryBuffer(); int index = 0; - BitVectorBuilder pmapBuilder = new BitVectorBuilder(7); // TODO - calculate size of pmap builder - if (context.getLastTemplateId() != templateId) { - index = uintCodec.encode(temp, offset, templateId); - context.setLastTemplateId(templateId); - pmapBuilder.set(); - } else { - pmapBuilder.skip(); + int pmapLen = 0; + try { + BitVectorBuilder pmapBuilder = new BitVectorBuilder(7); // TODO - calculate size of pmap builder + if (context.getLastTemplateId() != templateId) { + index = uintCodec.encode(temp, offset, templateId); + context.setLastTemplateId(templateId); + pmapBuilder.set(); + } else { + pmapBuilder.skip(); + } + for (int i=0; i<fieldCodecs.length; i++) { + index = fieldCodecs[i].encode(message, i, temp, index, message.getTemplate().getField(i), pmapBuilder, context); + } + pmapLen = bitVectorCodec.encode(buffer, offset, pmapBuilder.getBitVector()); + System.arraycopy(temp, 0, buffer, offset + pmapLen, index); + } catch (Throwable t) { + context.getErrorHandler().error(FastConstants.GENERAL_ERROR, "Error occurred while encoding " + message, t); + } finally { + context.discardTemporaryBuffer(temp); } - for (int i=0; i<fieldCodecs.length; i++) { - index = fieldCodecs[i].encode(message, i, temp, index, message.getTemplate().getField(i), pmapBuilder, context); - } - int pmapLen = bitVectorCodec.encode(buffer, offset, pmapBuilder.getBitVector()); - System.arraycopy(temp, 0, buffer, offset + pmapLen, index); - context.discardTemporaryBuffer(temp); System.out.println(ByteUtil.convertByteArrayToBitString(buffer, offset + pmapLen + index)); return offset + pmapLen + index; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java 2008-07-21 14:00:33 UTC (rev 179) @@ -6,7 +6,30 @@ import org.openfast.util.BitVectorReader; public interface FieldCodec<T> { - int decode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorReader reader, Context context); + + /** + * @param object the message to decode the field value into + * @param index the field index to decode the value into + * @param buffer the encoded source buffer + * @param offset the current index in the buffer + * @param field the field definition that this codec was built from + * @param pmapReader the presence map reader + * @param context the current decoding context + * @return the new offset in the encoded buffer + */ + @SuppressWarnings("unchecked") + int decode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorReader pmapReader, Context context); + /** + * @param object + * @param index + * @param buffer + * @param offset + * @param field + * @param pmapBuilder + * @param context + * @return the new offset in the encoded buffer + */ + @SuppressWarnings("unchecked") int encode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorBuilder pmapBuilder, Context context); int getLength(byte[] buffer, int offset, BitVectorReader reader); } Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementOperatorCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementOperatorCodecFactory.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementOperatorCodecFactory.java 2008-07-21 14:00:33 UTC (rev 179) @@ -1,19 +0,0 @@ -package org.openfast.codec; - -import org.openfast.codec.operator.IncrementIntegerCodec; -import org.openfast.dictionary.DictionaryEntry; -import org.openfast.dictionary.DictionaryRegistry; -import org.openfast.fast.impl.FastImplementation; -import org.openfast.template.MessageTemplate; -import org.openfast.template.Scalar; -import org.openfast.template.operator.DictionaryOperator; - -public class IncrementOperatorCodecFactory implements ScalarCodecFactory { - public ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, - DictionaryRegistry dictionaryRegistry) { - IntegerCodec integerCodec = implementation.getTypeCodecRegistry().getIntegerCodec(scalar.getType(), scalar.isOptional()); - DictionaryOperator operator = (DictionaryOperator) scalar.getOperator(); - DictionaryEntry entry = dictionaryRegistry.get(((DictionaryOperator)scalar.getOperator()).getDictionary()).getEntry(scalar); - return new IncrementIntegerCodec(entry, operator, integerCodec); - } -} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/SinglePresenceMapEntryFieldCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/SinglePresenceMapEntryFieldCodec.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/SinglePresenceMapEntryFieldCodec.java 2008-07-21 14:00:33 UTC (rev 179) @@ -18,7 +18,8 @@ public int decode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorReader reader, Context context) { if (reader.read()) { - return decode(object, index, buffer, offset, field, context); + decode(object, index, buffer, offset, field, context); + return offset + getLength(buffer, offset); } decodeEmpty(object, index, field, context); return offset; @@ -29,7 +30,7 @@ return 0; } public abstract int encode(EObject object, int index, byte[] buffer, int offset, T field, Context context); - public abstract int decode(EObject object, int index, byte[] buffer, int offset, T field, Context context); + public abstract void decode(EObject object, int index, byte[] buffer, int offset, T field, Context context); public abstract void decodeEmpty(EObject object, int index, T field, Context context); public abstract int getLength(byte[] buffer, int offset); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/AlwaysPresentCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/AlwaysPresentCodec.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/AlwaysPresentCodec.java 2008-07-21 14:00:33 UTC (rev 179) @@ -9,7 +9,8 @@ public abstract class AlwaysPresentCodec<T> implements FieldCodec<T> { public int decode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorReader reader, Context context) { - return decode(object, index, buffer, offset, field, context); + decode(object, index, buffer, offset, field, context); + return offset + getLength(buffer, offset); } public int encode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorBuilder pmapBuilder, Context context) { @@ -22,6 +23,6 @@ public abstract int getLength(byte[] buffer, int offset); - public abstract int decode(EObject object, int index, byte[] buffer, int offset, T field, Context context); + public abstract void decode(EObject object, int index, byte[] buffer, int offset, T field, Context context); public abstract int encode(EObject object, int index, byte[] buffer, int offset, T field, Context context); } Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantIntegerCodec.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantIntegerCodec.java 2008-07-21 14:00:33 UTC (rev 179) @@ -1,26 +0,0 @@ -package org.openfast.codec.operator; - -import org.lasalletech.entity.EObject; -import org.openfast.Context; -import org.openfast.codec.ScalarCodec; -import org.openfast.template.Scalar; -import org.openfast.util.BitVectorBuilder; -import org.openfast.util.BitVectorReader; - -public class ConstantIntegerCodec implements ScalarCodec { - private final int defaultValue; - - public ConstantIntegerCodec(int defaultValue) { - this.defaultValue = defaultValue; - } - public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, BitVectorReader reader, Context context) { - object.set(index, defaultValue); - return offset; - } - public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, BitVectorBuilder pmapBuilder, Context context) { - return offset; - } - public int getLength(byte[] buffer, int offset, BitVectorReader reader) { - return 0; - } -} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantOperatorCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantOperatorCodecFactory.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantOperatorCodecFactory.java 2008-07-21 14:00:33 UTC (rev 179) @@ -0,0 +1,23 @@ +package org.openfast.codec.operator; + +import org.openfast.codec.ScalarCodec; +import org.openfast.codec.ScalarCodecFactory; +import org.openfast.dictionary.DictionaryRegistry; +import org.openfast.fast.impl.FastImplementation; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; +import org.openfast.template.type.IntegerType; + +public class ConstantOperatorCodecFactory implements ScalarCodecFactory { + public ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, + DictionaryRegistry dictionaryRegistry) { + if (scalar.getType() instanceof IntegerType) { + int defaultValue = Integer.parseInt(scalar.getOperator().getDefaultValue()); + if (scalar.isOptional()) { + return new OptionalConstantIntegerCodec(defaultValue); + } + return new MandatoryConstantIntegerCodec(defaultValue); + } + return null; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java 2008-07-21 14:00:33 UTC (rev 179) @@ -16,18 +16,17 @@ } public int getLength(byte[] buffer, int offset) { - throw new UnsupportedOperationException(); + return integerCodec.getLength(buffer, offset); } - public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public void decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { if (integerCodec.isNull(buffer, offset)) { dictionaryEntry.setNull(); - return offset + 1; + return; } int value = integerCodec.decode(buffer, offset); object.set(index, value); dictionaryEntry.set(value); - return integerCodec.getLength(buffer, offset) + offset; } public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { Copied: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyOperatorCodecFactory.java (from rev 175, branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/CopyOperatorCodecFactory.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyOperatorCodecFactory.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyOperatorCodecFactory.java 2008-07-21 14:00:33 UTC (rev 179) @@ -0,0 +1,29 @@ +package org.openfast.codec.operator; + +import org.openfast.codec.IntegerCodec; +import org.openfast.codec.ScalarCodec; +import org.openfast.codec.ScalarCodecFactory; +import org.openfast.codec.StringCodec; +import org.openfast.dictionary.DictionaryEntry; +import org.openfast.dictionary.DictionaryRegistry; +import org.openfast.fast.FastTypes; +import org.openfast.fast.impl.FastImplementation; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; +import org.openfast.template.operator.DictionaryOperator; +import org.openfast.template.type.IntegerType; + +public class CopyOperatorCodecFactory implements ScalarCodecFactory { + public ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, + DictionaryRegistry dictionaryRegistry) { + DictionaryEntry entry = dictionaryRegistry.get(((DictionaryOperator)scalar.getOperator()).getDictionary()).getEntry(scalar); + if (FastTypes.ASCII.equals(scalar.getType())) { + StringCodec stringCodec = implementation.getTypeCodecRegistry().getStringCodec(scalar.getType(), scalar.isOptional()); + return new CopyStringCodec(entry, (DictionaryOperator) scalar.getOperator(), stringCodec); + } else if (scalar.getType() instanceof IntegerType) { + IntegerCodec integerCodec = implementation.getTypeCodecRegistry().getIntegerCodec(scalar.getType(), scalar.isOptional()); + return new CopyIntegerCodec(entry, (DictionaryOperator) scalar.getOperator(), integerCodec); + } + throw new IllegalArgumentException("The type " + scalar.getType() + " found in " + scalar + " is not supported by the copy operator."); + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyStringCodec.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyStringCodec.java 2008-07-21 14:00:33 UTC (rev 179) @@ -16,18 +16,17 @@ } public int getLength(byte[] buffer, int offset) { - throw new UnsupportedOperationException(); + return stringCodec.getLength(buffer, offset); } - public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public void decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { if (stringCodec.isNull(buffer, offset)) { dictionaryEntry.setNull(); - return offset + 1; + return; } String value = stringCodec.decode(buffer, offset); object.set(index, value); dictionaryEntry.set(value); - return stringCodec.getLength(buffer, offset) + offset; } public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { @@ -62,9 +61,12 @@ public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { if (dictionaryEntry.isNull()) return; - if (dictionaryEntry.isDefined()) + if (dictionaryEntry.isDefined()) { object.set(index, dictionaryEntry.getString()); - else if (operator.hasDefaultValue()) + } + else if (operator.hasDefaultValue()) { object.set(index, operator.getDefaultValue()); + dictionaryEntry.set(operator.getDefaultValue()); + } } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultIntegerCodec.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultIntegerCodec.java 2008-07-21 14:00:33 UTC (rev 179) @@ -20,15 +20,14 @@ this.defaultValue = operator.hasDefaultValue() ? Integer.parseInt(operator.getDefaultValue()) : 0; } public int getLength(byte[] buffer, int offset) { - return 0; + return integerCodec.getLength(buffer, offset); } - public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public void decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { if (integerCodec.isNull(buffer, offset)) - return offset + 1; - int newOffset = integerCodec.decode(buffer, offset); - object.set(index, newOffset); - return newOffset; + return; + int value = integerCodec.decode(buffer, offset); + object.set(index, value); } public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultOperatorCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultOperatorCodecFactory.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultOperatorCodecFactory.java 2008-07-21 14:00:33 UTC (rev 179) @@ -0,0 +1,26 @@ +package org.openfast.codec.operator; + +import org.openfast.codec.IntegerCodec; +import org.openfast.codec.ScalarCodec; +import org.openfast.codec.ScalarCodecFactory; +import org.openfast.codec.StringCodec; +import org.openfast.dictionary.DictionaryRegistry; +import org.openfast.fast.impl.FastImplementation; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; +import org.openfast.template.type.IntegerType; +import org.openfast.template.type.StringType; + +public class DefaultOperatorCodecFactory implements ScalarCodecFactory { + public ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, + DictionaryRegistry dictionaryRegistry) { + if (scalar.getType() instanceof IntegerType) { + IntegerCodec integerCodec = implementation.getTypeCodecRegistry().getIntegerCodec(scalar.getType(), scalar.isOptional()); + return new DefaultIntegerCodec(scalar.getOperator(), integerCodec); + } else if (scalar.getType() instanceof StringType) { + StringCodec stringCodec = implementation.getTypeCodecRegistry().getStringCodec(scalar.getType(), scalar.isOptional()); + return new DefaultStringCodec(scalar.getOperator(), stringCodec); + } + return null; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultStringCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultStringCodec.java 2008-07-21 14:00:33 UTC (rev 179) @@ -0,0 +1,49 @@ +package org.openfast.codec.operator; + +import org.lasalletech.entity.EObject; +import org.openfast.Context; +import org.openfast.Fast; +import org.openfast.codec.ScalarCodec; +import org.openfast.codec.SinglePresenceMapEntryFieldCodec; +import org.openfast.codec.StringCodec; +import org.openfast.template.Operator; +import org.openfast.template.Scalar; + +public class DefaultStringCodec extends SinglePresenceMapEntryFieldCodec<Scalar> implements ScalarCodec { + private final Operator operator; + private final StringCodec stringCodec; + + public DefaultStringCodec(Operator operator, StringCodec stringCodec) { + this.operator = operator; + this.stringCodec = stringCodec; + } + public int getLength(byte[] buffer, int offset) { + return stringCodec.getLength(buffer, offset); + } + + public void decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + if (stringCodec.isNull(buffer, offset)) + return; + String value = stringCodec.decode(buffer, offset); + object.set(index, value); + } + + public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { + if (operator.hasDefaultValue()) + object.set(index, operator.getDefaultValue()); + } + + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + if (object.isDefined(index)) { + if (operator.hasDefaultValue() && operator.getDefaultValue().equals(object.getString(index))) + return offset; + return stringCodec.encode(buffer, offset, object.getString(index)); + } else { + if (!operator.hasDefaultValue()) + return offset; + buffer[offset] = Fast.NULL; + return offset + 1; + } + } + +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java 2008-07-21 14:00:33 UTC (rev 179) @@ -21,12 +21,14 @@ } public int getLength(byte[] buffer, int offset) { - return 0; + if (integerCodec.isNull(buffer, offset)) return 1; + int len = integerCodec.getLength(buffer, offset); + return len + stringCodec.getLength(buffer, offset + len); } - public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public void decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { if (integerCodec.isNull(buffer, offset)) { - return offset + 1; + return; } int subtractionLength = integerCodec.decode(buffer, offset); offset = integerCodec.getLength(buffer, offset); @@ -34,7 +36,6 @@ String value = new StringDelta(subtractionLength, delta).applyTo(getPreviousValue(object, field, context)); dictionaryEntry.set(value); object.set(index, value); - return stringCodec.getLength(buffer, offset) + offset; } private String getPreviousValue(EObject object, Scalar field, Context context) { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java 2008-07-21 14:00:33 UTC (rev 179) @@ -17,19 +17,18 @@ } public int getLength(byte[] buffer, int offset) { - return 0; + return integerCodec.getLength(buffer, offset); } - public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public void decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { if (integerCodec.isNull(buffer, offset)) { - return offset; + return; } int delta = integerCodec.decode(buffer, offset); int previousValue = getPreviousValue(object, context, field); int newValue = delta + previousValue; object.set(index, newValue); dictionaryEntry.set(newValue); - return integerCodec.getLength(buffer, offset) + offset; } private int getPreviousValue(EObject object, Context context, Scalar field) { @@ -51,6 +50,7 @@ } int value = object.getInt(index); int previousValue = getPreviousValue(object, context, field); + dictionaryEntry.set(value); return integerCodec.encode(buffer, offset, value - previousValue); } } Copied: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaOperatorCodecFactory.java (from rev 175, branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/DeltaOperatorCodecFactory.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaOperatorCodecFactory.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaOperatorCodecFactory.java 2008-07-21 14:00:33 UTC (rev 179) @@ -0,0 +1,31 @@ +package org.openfast.codec.operator; + +import org.openfast.codec.IntegerCodec; +import org.openfast.codec.ScalarCodec; +import org.openfast.codec.ScalarCodecFactory; +import org.openfast.codec.StringCodec; +import org.openfast.dictionary.DictionaryEntry; +import org.openfast.dictionary.DictionaryRegistry; +import org.openfast.fast.FastTypes; +import org.openfast.fast.impl.FastImplementation; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; +import org.openfast.template.operator.DictionaryOperator; +import org.openfast.template.type.IntegerType; + +public class DeltaOperatorCodecFactory implements ScalarCodecFactory { + public ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, + DictionaryRegistry dictionaryRegistry) { + DictionaryEntry entry = dictionaryRegistry.get(((DictionaryOperator) scalar.getOperator()).getDictionary()).getEntry(scalar); + if (FastTypes.ASCII.equals(scalar.getType())) { + StringCodec stringCodec = implementation.getTypeCodecRegistry().getStringCodec(scalar.getType()); + IntegerCodec integerCodec = implementation.getTypeCodecRegistry().getIntegerCodec(FastTypes.I32, scalar.isOptional()); + return new DeltaAsciiCodec(entry, (DictionaryOperator) scalar.getOperator(), integerCodec, + stringCodec); + } else if (scalar.getType() instanceof IntegerType) { + IntegerCodec integerCodec = implementation.getTypeCodecRegistry().getIntegerCodec(scalar.getType(), scalar.isOptional()); + return new DeltaIntegerCodec(entry, (DictionaryOperator) scalar.getOperator(), integerCodec); + } + throw new IllegalArgumentException("The type " + scalar.getType() + " found in " + scalar + " is not supported by the delta operator."); + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java 2008-07-21 14:00:33 UTC (rev 179) @@ -36,14 +36,12 @@ super(dictionaryEntry, operator, integerCodec); } - public int decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { + public void decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { if (integerCodec.isNull(buffer, offset)) - return offset; - int length = integerCodec.getLength(buffer, offset); + return; int value = integerCodec.decode(buffer, offset); dictionaryEntry.set(value); object.set(index, value); - return offset + length; } public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { Copied: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementOperatorCodecFactory.java (from rev 175, branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementOperatorCodecFactory.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementOperatorCodecFactory.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementOperatorCodecFactory.java 2008-07-21 14:00:33 UTC (rev 179) @@ -0,0 +1,21 @@ +package org.openfast.codec.operator; + +import org.openfast.codec.IntegerCodec; +import org.openfast.codec.ScalarCodec; +import org.openfast.codec.ScalarCodecFactory; +import org.openfast.dictionary.DictionaryEntry; +import org.openfast.dictionary.DictionaryRegistry; +import org.openfast.fast.impl.FastImplementation; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; +import org.openfast.template.operator.DictionaryOperator; + +public class IncrementOperatorCodecFactory implements ScalarCodecFactory { + public ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, + DictionaryRegistry dictionaryRegistry) { + IntegerCodec integerCodec = implementation.getTypeCodecRegistry().getIntegerCodec(scalar.getType(), scalar.isOptional()); + DictionaryOperator operator = (DictionaryOperator) scalar.getOperator(); + DictionaryEntry entry = dictionaryRegistry.get(((DictionaryOperator)scalar.getOperator()).getDictionary()).getEntry(scalar); + return new IncrementIntegerCodec(entry, operator, integerCodec); + } +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/MandatoryConstantIntegerCodec.java (from rev 176, branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantIntegerCodec.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/MandatoryConstantIntegerCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/MandatoryConstantIntegerCodec.java 2008-07-21 14:00:33 UTC (rev 179) @@ -0,0 +1,26 @@ +package org.openfast.codec.operator; + +import org.lasalletech.entity.EObject; +import org.openfast.Context; +import org.openfast.codec.ScalarCodec; +import org.openfast.template.Scalar; +import org.openfast.util.BitVectorBuilder; +import org.openfast.util.BitVectorReader; + +public class MandatoryConstantIntegerCodec implements ScalarCodec { + private final int defaultValue; + + public MandatoryConstantIntegerCodec(int defaultValue) { + this.defaultValue = defaultValue; + } + public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, BitVectorReader reader, Context context) { + object.set(index, defaultValue); + return offset; + } + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, BitVectorBuilder pmapBuilder, Context context) { + return offset; + } + public int getLength(byte[] buffer, int offset, BitVectorReader reader) { + return 0; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneIntegerCodec.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneIntegerCodec.java 2008-07-21 14:00:33 UTC (rev 179) @@ -14,14 +14,13 @@ this.integerCodec = integerCodec; } public int getLength(byte[] buffer, int offset) { - return 0; + return integerCodec.getLength(buffer, offset); } - public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public void decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { if (!integerCodec.isNull(buffer, offset)) { object.set(index, integerCodec.decode(buffer, offset)); } - return integerCodec.getLength(buffer, offset); } public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneStringCodec.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneStringCodec.java 2008-07-21 14:00:33 UTC (rev 179) @@ -14,14 +14,13 @@ this.stringCodec = stringCodec; } public int getLength(byte[] buffer, int offset) { - return 0; + return stringCodec.getLength(buffer, offset); } - public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public void decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { if (!stringCodec.isNull(buffer, offset)) { object.set(index, stringCodec.decode(buffer, offset)); } - return stringCodec.getLength(buffer, offset); } public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/OptionalConstantIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/OptionalConstantIntegerCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/OptionalConstantIntegerCodec.java 2008-07-21 14:00:33 UTC (rev 179) @@ -0,0 +1,31 @@ +package org.openfast.codec.operator; + +import org.lasalletech.entity.EObject; +import org.openfast.Context; +import org.openfast.codec.ScalarCodec; +import org.openfast.template.Scalar; +import org.openfast.util.BitVectorBuilder; +import org.openfast.util.BitVectorReader; + +public class OptionalConstantIntegerCodec implements ScalarCodec { + private final int defaultValue; + + public OptionalConstantIntegerCodec(int defaultValue) { + this.defaultValue = defaultValue; + } + public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, BitVectorReader reader, Context context) { + if (reader.read()) + object.set(index, defaultValue); + return offset; + } + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, BitVectorBuilder pmapBuilder, Context context) { + if (object.isDefined(index)) + pmapBuilder.set(); + else + pmapBuilder.skip(); + return offset; + } + public int getLength(byte[] buffer, int offset, BitVectorReader reader) { + return 0; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableAsciiStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableAsciiStringCodec.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableAsciiStringCodec.java 2008-07-21 14:00:33 UTC (rev 179) @@ -5,6 +5,7 @@ import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; +import java.nio.charset.CharsetEncoder; import org.openfast.ByteUtil; import org.openfast.Fast; import org.openfast.Global; @@ -13,7 +14,7 @@ public class NullableAsciiStringCodec extends StopBitEncodedTypeCodec implements StringCodec { private final CharsetDecoder decoder = Charset.forName("US-ASCII").newDecoder(); -// private final CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder(); + private final CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder(); public String decode(byte[] buffer, int offset) { CharBuffer decoded; try { @@ -21,9 +22,11 @@ if ((buffer[offset] & Fast.VALUE_BITS) == 0) { if (!ByteUtil.isEmpty(buffer, offset, length)) Global.handleError(FastConstants.R9_STRING_OVERLONG, null); - if (length > 1 && (buffer[offset+1] & Fast.VALUE_BITS) == 0) + if (length == 3 && buffer[offset+1] == 0 && (buffer[offset+2] & Fast.VALUE_BITS) == 0) return Fast.ZERO_TERMINATOR; - return ""; + if (length == 2 && (buffer[offset+1] * Fast.VALUE_BITS) == 0) + return ""; + return null; } buffer[length + offset - 1] &= Fast.VALUE_BITS; // remove stop bit decoded = decoder.decode(ByteBuffer.wrap(buffer, offset, length)); @@ -35,7 +38,30 @@ } public int encode(byte[] buffer, int offset, String value) { - return 0; + if (value == null) { + buffer[offset] = Fast.NULL; + return offset + 1; + } + if (value.length() == 0) { + buffer[offset] = 0; + buffer[offset] = Fast.STOP_BIT; + return offset + 2; + } + if (value.startsWith(Fast.ZERO_TERMINATOR)) { + buffer[offset] = 0; + buffer[offset+1] = 0; + buffer[offset+2] = Fast.STOP_BIT; + return offset + 3; + } + ByteBuffer encoded; + try { + encoded = encoder.encode(CharBuffer.wrap(value)); + } catch (CharacterCodingException e) { + throw new RuntimeException(e); + } + encoded.get(buffer, offset, encoded.limit()); + buffer[encoded.limit() - 1 + offset] |= Fast.STOP_BIT; + return encoded.limit() + offset; } public boolean isNull(byte[] buffer, int offset) { Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/CopyOperatorCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/CopyOperatorCodecFactory.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/CopyOperatorCodecFactory.java 2008-07-21 14:00:33 UTC (rev 179) @@ -1,30 +0,0 @@ -package org.openfast.fast.impl; - -import org.openfast.codec.IntegerCodec; -import org.openfast.codec.ScalarCodec; -import org.openfast.codec.ScalarCodecFactory; -import org.openfast.codec.StringCodec; -import org.openfast.codec.operator.CopyIntegerCodec; -import org.openfast.codec.operator.CopyStringCodec; -import org.openfast.dictionary.DictionaryEntry; -import org.openfast.dictionary.DictionaryRegistry; -import org.openfast.fast.FastTypes; -import org.openfast.template.MessageTemplate; -import org.openfast.template.Scalar; -import org.openfast.template.operator.DictionaryOperator; -import org.openfast.template.type.IntegerType; - -public class CopyOperatorCodecFactory implements ScalarCodecFactory { - public ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, - DictionaryRegistry dictionaryRegistry) { - DictionaryEntry entry = dictionaryRegistry.get(((DictionaryOperator)scalar.getOperator()).getDictionary()).getEntry(scalar); - if (FastTypes.ASCII.equals(scalar.getType())) { - StringCodec stringCodec = implementation.getTypeCodecRegistry().getStringCodec(scalar.getType(), scalar.isOptional()); - return new CopyStringCodec(entry, (DictionaryOperator) scalar.getOperator(), stringCodec); - } else if (scalar.getType() instanceof IntegerType) { - IntegerCodec integerCodec = implementation.getTypeCodecRegistry().getIntegerCodec(scalar.getType(), scalar.isOptional()); - return new CopyIntegerCodec(entry, (DictionaryOperator) scalar.getOperator(), integerCodec); - } - throw new IllegalArgumentException("The type " + scalar.getType() + " found in " + scalar + " is not supported by the copy operator."); - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/DeltaOperatorCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/DeltaOperatorCodecFactory.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/DeltaOperatorCodecFactory.java 2008-07-21 14:00:33 UTC (rev 179) @@ -1,32 +0,0 @@ -package org.openfast.fast.impl; - -import org.openfast.codec.IntegerCodec; -import org.openfast.codec.ScalarCodec; -import org.openfast.codec.ScalarCodecFactory; -import org.openfast.codec.StringCodec; -import org.openfast.codec.operator.DeltaAsciiCodec; -import org.openfast.codec.operator.DeltaIntegerCodec; -import org.openfast.dictionary.DictionaryEntry; -import org.openfast.dictionary.DictionaryRegistry; -import org.openfast.fast.FastTypes; -import org.openfast.template.MessageTemplate; -import org.openfast.template.Scalar; -import org.openfast.template.operator.DictionaryOperator; -import org.openfast.template.type.IntegerType; - -public class DeltaOperatorCodecFactory implements ScalarCodecFactory { - public ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, - DictionaryRegistry dictionaryRegistry) { - DictionaryEntry entry = dictionaryRegistry.get(((DictionaryOperator) scalar.getOperator()).getDictionary()).getEntry(scalar); - if (FastTypes.ASCII.equals(scalar.getType())) { - StringCodec stringCodec = implementation.getTypeCodecRegistry().getStringCodec(scalar.getType()); - IntegerCodec integerCodec = implementation.getTypeCodecRegistry().getIntegerCodec(FastTypes.I32, scalar.isOptional()); - return new DeltaAsciiCodec(entry, (DictionaryOperator) scalar.getOperator(), integerCodec, - stringCodec); - } else if (scalar.getType() instanceof IntegerType) { - IntegerCodec integerCodec = implementation.getTypeCodecRegistry().getIntegerCodec(scalar.getType(), scalar.isOptional()); - return new DeltaIntegerCodec(entry, (DictionaryOperator) scalar.getOperator(), integerCodec); - } - throw new IllegalArgumentException("The type " + scalar.getType() + " found in " + scalar + " is not supported by the delta operator."); - } -} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast_1_1Implementation.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast_1_1Implementation.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast_1_1Implementation.java 2008-07-21 14:00:33 UTC (rev 179) @@ -6,8 +6,12 @@ import org.openfast.codec.BasicCodecFactory; import org.openfast.codec.BasicTypeCodecRegistry; import org.openfast.codec.CodecFactory; -import org.openfast.codec.IncrementOperatorCodecFactory; import org.openfast.codec.TypeCodecRegistry; +import org.openfast.codec.operator.ConstantOperatorCodecFactory; +import org.openfast.codec.operator.CopyOperatorCodecFactory; +import org.openfast.codec.operator.DefaultOperatorCodecFactory; +import org.openfast.codec.operator.DeltaOperatorCodecFactory; +import org.openfast.codec.operator.IncrementOperatorCodecFactory; import org.openfast.codec.type.FastTypeCodecs; import org.openfast.dictionary.BasicDictionaryTypeRegistry; import org.openfast.dictionary.DictionaryTypeRegistry; @@ -96,7 +100,9 @@ codecFactory = new BasicCodecFactory(); codecFactory.register("increment", new IncrementOperatorCodecFactory()); codecFactory.register("copy", new CopyOperatorCodecFactory()); + codecFactory.register("default", new DefaultOperatorCodecFactory()); codecFactory.register("delta", new DeltaOperatorCodecFactory()); + codecFactory.register("constant", new ConstantOperatorCodecFactory()); } return codecFactory; } Added: branches/openfast-2.x/examples/src/main/resources/simple/data/constantU32.csv =================================================================== --- branches/openfast-2.x/examples/src/main/resources/simple/data/constantU32.csv (rev 0) +++ branches/openfast-2.x/examples/src/main/resources/simple/data/constantU32.csv 2008-07-21 14:00:33 UTC (rev 179) @@ -0,0 +1,8 @@ +TemplateID,constantU32,constantU32default +14,6600,3022008 +14,6600, +14,6600,3022008 +1 +14,6600, +14,6600,3022008 +14,6600, \ No newline at end of file Added: branches/openfast-2.x/examples/src/main/resources/simple/data/copyAscii.csv =================================================================== --- branches/openfast-2.x/examples/src/main/resources/simple/data/copyAscii.csv (rev 0) +++ branches/openfast-2.x/examples/src/main/resources/simple/data/copyAscii.csv 2008-07-21 14:00:33 UTC (rev 179) @@ -0,0 +1,9 @@ +TemplateID,copyAsciiNoDefault,copyAsciiDefault,copyAsciiOptionalNoDefault,copyAsciiOptionalDefault +21,Shene,technological,Seidel,university +21,Shene,technological,Seidel,university +21,Carr,algorithms,Mayo,school +1 +21,Carr,algorithms,Mayo,school +21,Shene,technological,Seidel,university +21,Shene,technological,Seidel,university +21,Carr,algorithms,Mayo,school Added: branches/openfast-2.x/examples/src/main/resources/simple/data/copyU32.csv =================================================================== --- branches/openfast-2.x/examples/src/main/resources/simple/data/copyU32.csv (rev 0) +++ branches/openfast-2.x/examples/src/main/resources/simple/data/copyU32.csv 2008-07-21 14:00:33 UTC (rev 179) @@ -0,0 +1,6 @@ +TemplateID,copyU32NoDefault,copyU32Default,copyU32OptionalNoDefault,copyU32OptionalDefault +11,100,200, , +11,100,200, ,200 +11,101,201,300,200 +11,102,201,300,201 +11,102,205, , \ No newline at end of file Added: branches/openfast-2.x/examples/src/main/resources/simple/data/defaultAscii.csv =================================================================== --- branches/openfast-2.x/examples/src/main/resources/simple/data/defaultAscii.csv (rev 0) +++ branches/openfast-2.x/examples/src/main/resources/simple/data/defaultAscii.csv 2008-07-21 14:00:33 UTC (rev 179) @@ -0,0 +1,5 @@ +TemplateID,defaultAscii,defaultAsciiOptionalNull,defaultAsciiOptional +22,Houghton, ,MTU +22,Houghton, Bridge,MTU +22,Hancock, ,FU +22,Hancock,Bridge, \ No newline at end of file Added: branches/openfast-2.x/examples/src/main/resources/simple/data/defaultU32.csv =================================================================== --- branches/openfast-2.x/examples/src/main/resources/simple/data/defaultU32.csv (rev 0) +++ branches/openfast-2.x/examples/src/main/resources/simple/data/defaultU32.csv 2008-07-21 14:00:33 UTC (rev 179) @@ -0,0 +1,5 @@ +TemplateID,defaultU32,defaultU32OptionalNull,defaultU32Optional +12,200, ,7192008 +12,200, ,7192008 +12,201,11,1 +12,200, ,7192008 \ No newline at end of file Added: branches/openfast-2.x/examples/src/main/resources/simple/data/deltaU32.csv =================================================================== --- branches/openfast-2.x/examples/src/main/resources/simple/data/deltaU32.csv (rev 0) +++ branches/openfast-2.x/examples/src/main/resources/simple/data/deltaU32.csv 2008-07-21 14:00:33 UTC (rev 179) @@ -0,0 +1,7 @@ +TemplateID,deltaU32NoDefault,deltaU32Default,deltaU32OptionalNoDefault,deltaU32OptionalDefault +13,100,200, , +13,150,150,100,200 +13,50,250,150,150 +13,25000,35000,50,250 +13,1,1, , +13,2,0,1,1 \ No newline at end of file Modified: branches/openfast-2.x/examples/src/main/resources/simple/templates/integerTemplates.xml =================================================================== --- branches/openfast-2.x/examples/src/main/resources/simple/templates/integerTemplates.xml 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/examples/src/main/resources/simple/templates/integerTemplates.xml 2008-07-21 14:00:33 UTC (rev 179) @@ -5,4 +5,25 @@ <uInt32 name="incU32OptionalNoDefault" presence="optional"><increment/></uInt32> <uInt32 name="incU32OptionalDefault" presence="optional"><increment value="200"/></uInt32> </template> + <template name="copyU32" id="11"> + <uInt32 name="copyU32NoDefault"><copy/></uInt32> + <uInt32 name="copyU32Default"><copy value="200"/></uInt32> + <uInt32 name="copyU32OptionalNoDefault" presence="optional"><copy/></uInt32> + <uInt32 name="copyU32OptionalDefault" presence="optional"><copy value="200"/></uInt32> + </template> + <template name="defaultU32" id="12"> + <uInt32 name="defaultU32"><default value="200"/></uInt32> + <uInt32 name="defaultU32OptionalNull" presence="optional"><default/></uInt32> + <uInt32 name="defaultU32Optional" presence="optional"><default value="7192008"/></uInt32> + </template> + <template name="deltaU32" id="13"> + <uInt32 name="deltaU32NoDefault"><delta/></uInt32> + <uInt32 name="deltaU32Default"><delta value="200"/></uInt32> + <uInt32 name="deltaU32OptionalNoDefault" presence="optional"><delta/></uInt32> + <uInt32 name="deltaU32OptionalDefault" presence="optional"><delta value="200"/></uInt32> + </template> + <template name="constantU32" id="14"> + <uInt32 name="constantU32"><constant value="6600"/></uInt32> + <uInt32 name="constantU32Optional" presence="optional"><constant value="3022008"/></uInt32> + </template> </templates> \ No newline at end of file Added: branches/openfast-2.x/examples/src/main/resources/simple/templates/stringTemplates.xml =================================================================== --- branches/openfast-2.x/examples/src/main/resources/simple/templates/stringTemplates.xml (rev 0) +++ branches/openfast-2.x/examples/src/main/resources/simple/templates/stringTemplates.xml 2008-07-21 14:00:33 UTC (rev 179) @@ -0,0 +1,23 @@ +<templates xmlns="http://www.fixprotocol.org/ns/fast/td/1.1"> + <template name="copyAscii" id="21"> + <string name="copyAsciiNoDefault"><copy/></string> + <string name="copyAsciiDefault"><copy value="technological"/></string> + <string name="copyAsciiOptionalNoDefault" presence="optional"><copy/></string> + <string name="copyAsciiOptionalDefault" presence="optional"><copy value="university"/></string> + </template> + <template name="defaultAscii" id="22"> + <string name="defaultAscii"><default value="Houghton"/></string> + <string name="defaultAsciiOptionalNull" presence="optional"><default/></string> + <string name="defaultAsciiOptional" presence="optional"><default value="MTU"/></string> + </template> + <template name="deltaAscii" id="23"> + <string name="deltaAsciiNoDefault"><delta/></string> + <string name="deltaAsciiDefault"><delta value="CMX"/></string> + <string name="deltaAsciiOptionalNoDefault" presence="optional"><delta/></string> + <string name="deltaAsciiOptionalDefault" presence="optional"><delta value="michigan"/></string> + </template> + <template name="constantAscii" id="24"> + <string name="constantAscii"><constant value="SE"/></string> + <string name="constantAsciiOptional" presence="optional"><constant value="CS"/></string> + </template> +</templates> \ No newline at end of file Modified: branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/util/csv/CsvParser.java =================================================================== --- branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/util/csv/CsvParser.java 2008-07-18 21:19:20 UTC (rev 178) +++ branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/util/csv/CsvParser.java 2008-07-21 14:00:33 UTC (rev 179) @@ -11,6 +11,7 @@ import org.openfast.template.TemplateRegistry; public class CsvParser { + private static final String[] EMPTY = new String[0]; private final TemplateRegistry registry; private boolean indexBased = true; public CsvParser(TemplateRegistry registry) { @@ -25,6 +26,7 @@ String line = reader.readLine(); while ((line = reader.readLine()) != null) { String[] values = parse(line); + if (values.length == 0) continue; int templateId = Integer.parseInt(values[0]); MessageTemplate template = registry.get(templateId); Message message = template.newObject(); @@ -39,6 +41,7 @@ return messages; } private String[] parse(String line) { + if ("".equals(line.trim())) return EMPTY; String[] values = line.split(","); f... [truncated message content] |
From: <ope...@li...> - 2008-07-18 21:19:17
|
Revision: 178 http://openfast.svn.sourceforge.net/openfast/?rev=178&view=rev Author: jacob_northey Date: 2008-07-18 21:19:20 +0000 (Fri, 18 Jul 2008) Log Message: ----------- Got test harness working; Refactored to use Entity Framework generics Modified Paths: -------------- branches/openfast-2.x/core/pom.xml branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java branches/openfast-2.x/core/src/main/java/org/openfast/Message.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/UnsignedIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastTypes.java branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicField.java branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Field.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Group.java branches/openfast-2.x/core/src/main/java/org/openfast/template/MessageTemplate.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Type.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ComposedDecimalParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/FieldParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/GroupParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ScalarParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/SequenceParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TemplateParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/XMLMessageTemplateLoader.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/ByteVectorType.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/DecimalType.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/SignedIntegerType.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/StringType.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/Type.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/UnsignedIntegerType.java branches/openfast-2.x/core/src/test/java/org/openfast/BasicMessageEncodingAcceptanceTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/CopyIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/CopyStringCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/DeltaAsciiCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/DeltaIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastOperatorTestHarness.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastStringOperatorTestHarness.java branches/openfast-2.x/core/src/test/java/org/openfast/template/BasicTemplateRegistryTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/XMLMessageTemplateLoaderTest.java branches/openfast-2.x/core/src/test/java/org/openfast/test/OpenFastTestCase.java branches/openfast-2.x/examples/pom.xml branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/examples/simple/SimpleClient.java branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/examples/simple/SimpleServer.java branches/openfast-2.x/nio/src/main/java/com/lasalletech/openfast/nio/mina/FastMessageDecoder.java branches/openfast-2.x/pom.xml Added Paths: ----------- branches/openfast-2.x/core/src/main/java/org/openfast/FastObject.java branches/openfast-2.x/core/src/main/java/org/openfast/MessageTemplateBuilder.java branches/openfast-2.x/core/src/main/java/org/openfast/MessageTemplateFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/simple/ branches/openfast-2.x/core/src/main/java/org/openfast/simple/FastEntityType.java branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleComposite.java branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleFastField.java branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleFastObject.java branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleGroup.java branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleMessage.java branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleMessageTemplate.java branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleMessageTemplateFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleSequence.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Composite.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/Parser.java branches/openfast-2.x/examples/src/main/resources/simple/data/ branches/openfast-2.x/examples/src/main/resources/simple/data/incrementU32.csv branches/openfast-2.x/examples/src/main/resources/simple/templates/ branches/openfast-2.x/examples/src/main/resources/simple/templates/commonTemplates.xml branches/openfast-2.x/examples/src/main/resources/simple/templates/integerTemplates.xml branches/openfast-2.x/util/ branches/openfast-2.x/util/pom.xml branches/openfast-2.x/util/src/ branches/openfast-2.x/util/src/main/ branches/openfast-2.x/util/src/main/java/ branches/openfast-2.x/util/src/main/java/com/ branches/openfast-2.x/util/src/main/java/com/lasalletech/ branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/ branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/util/ branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/util/csv/ branches/openfast-2.x/util/src/main/java/com/lasalletech/openfast/util/csv/CsvParser.java Removed Paths: ------------- branches/openfast-2.x/examples/src/main/resources/simple/integerTemplates.xml Modified: branches/openfast-2.x/core/pom.xml =================================================================== --- branches/openfast-2.x/core/pom.xml 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/pom.xml 2008-07-18 21:19:20 UTC (rev 178) @@ -82,7 +82,7 @@ <dependency> <groupId>com.lasalletech.entity</groupId> <artifactId>entity</artifactId> - <version>0.3.0-SNAPSHOT</version> + <version>0.4.0-SNAPSHOT</version> </dependency> </dependencies> </project> \ No newline at end of file Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java 2008-07-18 21:19:20 UTC (rev 178) @@ -1,5 +1,7 @@ package org.openfast; +import org.openfast.simple.SimpleMessageTemplateFactory; + public class Fast { public static final byte STOP_BIT = (byte) 0x80; public static final byte VALUE_BITS = (byte) 0x7f; @@ -9,4 +11,5 @@ public static final String GLOBAL = "global"; public static final String TEMPLATE = "template"; + public static final MessageTemplateFactory SIMPLE = new SimpleMessageTemplateFactory(); } Added: branches/openfast-2.x/core/src/main/java/org/openfast/FastObject.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/FastObject.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/FastObject.java 2008-07-18 21:19:20 UTC (rev 178) @@ -0,0 +1,11 @@ +package org.openfast; + +import org.lasalletech.entity.EObject; +import org.openfast.template.Field; +import org.openfast.template.Group; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Type; + +public interface FastObject extends EObject<Group, FastObject, Type, Field, MessageTemplate, Message, Group, FastObject> { + +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Message.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Message.java 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Message.java 2008-07-18 21:19:20 UTC (rev 178) @@ -20,18 +20,12 @@ */ package org.openfast; -import org.lasalletech.entity.simple.SimpleEObject; +import org.lasalletech.entity.EObject; +import org.openfast.template.Field; +import org.openfast.template.Group; import org.openfast.template.MessageTemplate; +import org.openfast.template.Type; -public class Message extends SimpleEObject { - private static final long serialVersionUID = 1L; - private final MessageTemplate template; - - public Message(MessageTemplate template) { - super(template); - this.template = template; - } - public MessageTemplate getTemplate() { - return template; - } +public interface Message extends EObject<MessageTemplate, Message, Type, Field, MessageTemplate, Message, Group, FastObject> { + MessageTemplate getTemplate(); } Added: branches/openfast-2.x/core/src/main/java/org/openfast/MessageTemplateBuilder.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/MessageTemplateBuilder.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/MessageTemplateBuilder.java 2008-07-18 21:19:20 UTC (rev 178) @@ -0,0 +1,27 @@ +package org.openfast; + +import java.util.ArrayList; +import java.util.List; +import org.lasalletech.entity.QName; +import org.openfast.template.Field; +import org.openfast.template.MessageTemplate; + +public class MessageTemplateBuilder { + private final QName name; + private final MessageTemplateFactory factory; + private final List<Field> fields = new ArrayList<Field>(); + + public MessageTemplateBuilder(MessageTemplateFactory factory, String name) { + this.name = new QName(name); + this.factory = factory; + } + + public MessageTemplateBuilder(MessageTemplateFactory factory, QName name) { + this.factory = factory; + this.name = name; + } + + public MessageTemplate build() { + return factory.createMessageTemplate(name, fields.toArray(new Field[fields.size()])); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/MessageTemplateFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/MessageTemplateFactory.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/MessageTemplateFactory.java 2008-07-18 21:19:20 UTC (rev 178) @@ -0,0 +1,19 @@ +package org.openfast; + +import org.lasalletech.entity.QName; +import org.openfast.template.Field; +import org.openfast.template.Group; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; +import org.openfast.template.Sequence; + +public interface MessageTemplateFactory { + MessageTemplate createMessageTemplate(String name, Field[] fields); + MessageTemplate createMessageTemplate(QName name, Field[] fields); + MessageTemplateBuilder createMessageTemplateBuilder(String name); + MessageTemplateBuilder createMessageTemplateBuilder(QName name); + Field createField(Group group, boolean optional); + Field createField(Sequence sequence, boolean optional); + Group createGroup(QName name, Field[] parseFields); + Sequence createSequence(QName name, Scalar parseSequenceLengthField, Field[] parseFields); +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java 2008-07-18 21:19:20 UTC (rev 178) @@ -1,12 +1,12 @@ package org.openfast.codec; -import org.lasalletech.entity.Field; import org.openfast.ByteUtil; import org.openfast.Context; import org.openfast.Message; import org.openfast.dictionary.DictionaryRegistry; import org.openfast.fast.FastTypes; import org.openfast.fast.impl.FastImplementation; +import org.openfast.template.Field; import org.openfast.template.MessageTemplate; import org.openfast.template.Scalar; import org.openfast.util.BitVectorBuilder; @@ -59,7 +59,9 @@ public int getLength(byte[] buffer, int offset, BitVectorReader reader, Context context) { int length = 0; for (int i=0; i<fieldCodecs.length; i++) { - length += fieldCodecs[i].getLength(buffer, offset, reader); + int fieldLength = fieldCodecs[i].getLength(buffer, offset, reader); + length += fieldLength; + offset += fieldLength; } return length; } @@ -67,7 +69,7 @@ @SuppressWarnings("unchecked") public void decode(Message message, byte[] buffer, int offset, BitVectorReader reader, Context context) { for (int i=0; i<fieldCodecs.length; i++) { - fieldCodecs[i].decode(message, i, buffer, offset, message.getTemplate().getField(i), reader, context); + offset = fieldCodecs[i].decode(message, i, buffer, offset, message.getTemplate().getField(i), reader, context); } } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java 2008-07-18 21:19:20 UTC (rev 178) @@ -44,7 +44,7 @@ } MessageTemplate template = context.getTemplate(templateId); MessageCodec codec = getCodec(templateId, template); - Message message = new Message(template); + Message message = template.newObject(); codec.decode(message, buffer, offset, reader, context); return message; } @@ -62,7 +62,7 @@ public int getNextMessageLength(byte[] buffer, final int offset) { BitVectorReader reader = new BitVectorReader(bitVectorCodec.decode(buffer, offset)); - int newOffset = bitVectorCodec.getLength(buffer, offset); + int newOffset = offset + bitVectorCodec.getLength(buffer, offset); int templateId = 0; if (reader.read()) { templateId = uintCodec.decode(buffer, newOffset); @@ -73,6 +73,6 @@ MessageTemplate template = context.getTemplate(templateId); MessageCodec codec = getCodec(templateId, template); newOffset += codec.getLength(buffer, newOffset, reader, context); - return newOffset; + return newOffset - offset; } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java 2008-07-18 21:19:20 UTC (rev 178) @@ -37,6 +37,8 @@ } public int decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { + if (integerCodec.isNull(buffer, offset)) + return offset; int length = integerCodec.getLength(buffer, offset); int value = integerCodec.decode(buffer, offset); dictionaryEntry.set(value); @@ -92,6 +94,7 @@ dictionaryEntry.set(value); return integerCodec.encode(buffer, offset, value); } else if (operator.hasDefaultValue() && value == initialValue) { + dictionaryEntry.set(value); return offset; } else { return integerCodec.encode(buffer, offset, value); @@ -99,7 +102,7 @@ } int previousValue = dictionaryEntry.getInt(); if (value == previousValue + 1) { - dictionaryEntry.set(previousValue + 1); + dictionaryEntry.set(value); return offset; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/UnsignedIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/UnsignedIntegerCodec.java 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/UnsignedIntegerCodec.java 2008-07-18 21:19:20 UTC (rev 178) @@ -1,25 +1,27 @@ package org.openfast.codec.type; -import org.openfast.Fast; +import static org.openfast.Fast.STOP_BIT; +import static org.openfast.Fast.VALUE_BITS; import org.openfast.codec.IntegerCodec; public class UnsignedIntegerCodec extends StopBitEncodedTypeCodec implements IntegerCodec { public int decode(byte[] buffer, int offset) { int value = 0; - int index = offset; + int index = offset - 1; do { - value = (value << 7) | (buffer[index] & 0x7f); - } while ((buffer[index] & 0x80) == 0); + index++; + value = (value << 7) | (buffer[index] & VALUE_BITS); + } while ((buffer[index] & STOP_BIT) == 0); return value; } public int encode(byte[] buffer, int offset, int value) { int size = getUnsignedIntegerSize(value); for (int factor = 0; factor < size; factor++) { - buffer[size - factor - 1 + offset] = (byte) ((value >> (factor * 7)) & 0x7f); + buffer[size - factor - 1 + offset] = (byte) ((value >> (factor * 7)) & VALUE_BITS); } - buffer[offset + size - 1] |= Fast.STOP_BIT; + buffer[offset + size - 1] |= STOP_BIT; return offset + size; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java 2008-07-18 21:19:20 UTC (rev 178) @@ -1,7 +1,7 @@ package org.openfast.dictionary; import org.lasalletech.entity.QName; -import org.openfast.template.type.Type; +import org.openfast.template.Type; public interface FastDictionary { int lookupInt(QName key); Modified: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java 2008-07-18 21:19:20 UTC (rev 178) @@ -3,7 +3,7 @@ import org.lasalletech.entity.QName; import org.openfast.template.type.IntegerType; import org.openfast.template.type.StringType; -import org.openfast.template.type.Type; +import org.openfast.template.Type; public class GlobalFastDictionary implements FastDictionary { // Use power of 2 for size so that hashes can be calculated quickly Modified: branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastTypes.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastTypes.java 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastTypes.java 2008-07-18 21:19:20 UTC (rev 178) @@ -1,5 +1,6 @@ package org.openfast.fast; +import org.lasalletech.entity.EObject; import org.openfast.template.Type; import org.openfast.template.type.ByteVectorType; import org.openfast.template.type.DecimalType; @@ -26,5 +27,9 @@ public static final Type[] INTEGER_TYPES = new Type[] { U8, U16, U32, U64, I8, I16, I32, I64 }; public static final Type BIT_VECTOR = new org.openfast.template.type.Type("bitVector"){ private static final long serialVersionUID = 1L; + + public void parse(EObject o, int index, String value) { + throw new UnsupportedOperationException(); + } }; } Added: branches/openfast-2.x/core/src/main/java/org/openfast/simple/FastEntityType.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/simple/FastEntityType.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/simple/FastEntityType.java 2008-07-18 21:19:20 UTC (rev 178) @@ -0,0 +1,25 @@ +package org.openfast.simple; + +import org.lasalletech.entity.EObject; +import org.lasalletech.entity.Entity; +import org.lasalletech.entity.EntityType; +import org.lasalletech.entity.QName; +import org.openfast.template.Type; + +@SuppressWarnings("unchecked") +public class FastEntityType<T extends Entity> extends EntityType<T> implements Type { + private static final long serialVersionUID = 1L; + + public FastEntityType(T entity) { + this(entity, false); + } + + public FastEntityType(T entity, boolean repeating) { + super(entity, repeating); + } + + + public void parse(EObject o, int index, String value) { + throw new UnsupportedOperationException(); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleComposite.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleComposite.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleComposite.java 2008-07-18 21:19:20 UTC (rev 178) @@ -0,0 +1,54 @@ +package org.openfast.simple; + +import org.lasalletech.entity.EObject; +import org.lasalletech.entity.EntityType; +import org.lasalletech.entity.QName; +import org.lasalletech.entity.simple.SimpleEntity; +import org.openfast.template.Composite; +import org.openfast.template.Field; +import org.openfast.template.Group; +import org.openfast.template.Scalar; +import org.openfast.template.Sequence; +import org.openfast.template.Type; + +@SuppressWarnings("unchecked") +public abstract class SimpleComposite<O extends EObject> extends SimpleEntity<O, Type, Field> implements Composite<O> { + public SimpleComposite(QName name) { + super(name); + } + + private String childNamespace; + private QName typeReference; + + public QName getTypeReference() { + return typeReference; + } + + public boolean hasTypeReference() { + return typeReference != null; + } + + public Scalar getScalar(int index) { + return (Scalar) getField(index); + } + + public void setChildNamespace(String namespace) { + this.childNamespace = namespace; + } + + public String getChildNamespace() { + return childNamespace; + } + + public void setTypeReference(QName typeReference) { + this.typeReference = typeReference; + } + + public Group getGroup(int index) { + return ((EntityType<Group>)getField(index).getType()).getEntity(); + } + + public Sequence getSequence(int index) { + return ((EntityType<Sequence>)getField(index).getType()).getEntity(); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleFastField.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleFastField.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleFastField.java 2008-07-18 21:19:20 UTC (rev 178) @@ -0,0 +1,40 @@ +package org.openfast.simple; + +import org.lasalletech.entity.QName; +import org.lasalletech.entity.simple.SimpleField; +import org.openfast.template.Field; +import org.openfast.template.Type; + +public class SimpleFastField extends SimpleField<Type> implements Field { + private static final long serialVersionUID = 1L; + + public SimpleFastField(String name, Type type) { + super(name, type); + } + + public void addAttribute(QName name, String value) {} + + public String getAttribute(QName name) { + return null; + } + + public String getId() { + return null; + } + + public QName getKey() { + return null; + } + + public boolean hasAttribute(QName attributeName) { + return false; + } + + public boolean isOptional() { + return !isRequired(); + } + + public void setId(String id) {} + + public void setKey(QName key) {} +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleFastObject.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleFastObject.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleFastObject.java 2008-07-18 21:19:20 UTC (rev 178) @@ -0,0 +1,15 @@ +package org.openfast.simple; + +import org.lasalletech.entity.simple.SimpleEObject; +import org.openfast.FastObject; +import org.openfast.Message; +import org.openfast.template.Field; +import org.openfast.template.Group; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Type; + +public class SimpleFastObject extends SimpleEObject<Group, FastObject, Type, Field, MessageTemplate, Message, Group, FastObject> implements FastObject { + protected SimpleFastObject(Group group) { + super(group); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleGroup.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleGroup.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleGroup.java 2008-07-18 21:19:20 UTC (rev 178) @@ -0,0 +1,16 @@ +package org.openfast.simple; + +import org.lasalletech.entity.QName; +import org.openfast.FastObject; +import org.openfast.template.Group; + +public class SimpleGroup extends SimpleComposite<FastObject> implements Group { + + public SimpleGroup(QName name) { + super(name); + } + + public FastObject newObject() { + return new SimpleFastObject(this); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleMessage.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleMessage.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleMessage.java 2008-07-18 21:19:20 UTC (rev 178) @@ -0,0 +1,21 @@ +package org.openfast.simple; + +import org.lasalletech.entity.simple.SimpleEObject; +import org.openfast.FastObject; +import org.openfast.Message; +import org.openfast.template.Field; +import org.openfast.template.Group; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Type; + + +public class SimpleMessage extends SimpleEObject<MessageTemplate, Message, Type, Field, MessageTemplate, Message, Group, FastObject> implements Message { + + protected SimpleMessage(MessageTemplate template) { + super(template); + } + + public MessageTemplate getTemplate() { + return getEntity(); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleMessageTemplate.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleMessageTemplate.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleMessageTemplate.java 2008-07-18 21:19:20 UTC (rev 178) @@ -0,0 +1,19 @@ +package org.openfast.simple; + +import org.lasalletech.entity.QName; +import org.openfast.Message; +import org.openfast.template.MessageTemplate; + +public class SimpleMessageTemplate extends SimpleComposite<Message> implements MessageTemplate { + public SimpleMessageTemplate(QName name) { + super(name); + } + + public SimpleMessageTemplate(String name) { + super(new QName(name)); + } + + public Message newObject() { + return new SimpleMessage(this); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleMessageTemplateFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleMessageTemplateFactory.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleMessageTemplateFactory.java 2008-07-18 21:19:20 UTC (rev 178) @@ -0,0 +1,78 @@ +package org.openfast.simple; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import org.lasalletech.entity.QName; +import org.openfast.MessageTemplateBuilder; +import org.openfast.MessageTemplateFactory; +import org.openfast.template.Field; +import org.openfast.template.Group; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; +import org.openfast.template.Sequence; +import org.openfast.template.StaticTemplateReference; + +public class SimpleMessageTemplateFactory implements MessageTemplateFactory { + public MessageTemplate createMessageTemplate(String name, Field[] fields) { + SimpleMessageTemplate template = new SimpleMessageTemplate(name); + for (Field field : getFields(fields)) + template.add(field); + return template; + } + + public MessageTemplate createMessageTemplate(QName name, Field[] fields) { + SimpleMessageTemplate template = new SimpleMessageTemplate(name); + for (Field field : getFields(fields)) + template.add(field); + return template; + } + + public MessageTemplateBuilder createMessageTemplateBuilder(String name) { + return new MessageTemplateBuilder(this, name); + } + + public MessageTemplateBuilder createMessageTemplateBuilder(QName name) { + return new MessageTemplateBuilder(this, name); + } + + public Field createField(Group group, boolean optional) { + return new SimpleFastField(group.getName(), new FastEntityType<Group>(group)); + } + + public Field createField(Sequence sequence, boolean optional) { + return new SimpleFastField(sequence.getName(), new FastEntityType<Sequence>(sequence, true)); + } + + public Group createGroup(QName name, Field[] fields) { + SimpleGroup group = new SimpleGroup(name); + for (Field field : getFields(fields)) + group.add(field); + return group; + } + + public Sequence createSequence(QName name, Scalar length, Field[] fields) { + SimpleSequence sequence = new SimpleSequence(name, length); + for (Field field : getFields(fields)) + sequence.add(field); + return sequence; + } + + private List<Field> getFields(Field[] fields) { + List<Field> newFields = new ArrayList<Field>(); + for (Field field : fields) { + if (field instanceof StaticTemplateReference) { + StaticTemplateReference reference = (StaticTemplateReference) field; + for (Field referencedField : reference.getTemplate().getFields()) + newFields.add(referencedField); +// if (staticTemplateReferences.isEmpty()) { +// staticTemplateReferences = new LinkedList<StaticTemplateReference>(); +// } +// staticTemplateReferences.add(reference); + } else { + newFields.add(field); + } + } + return newFields; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleSequence.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleSequence.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/simple/SimpleSequence.java 2008-07-18 21:19:20 UTC (rev 178) @@ -0,0 +1,26 @@ +package org.openfast.simple; + +import org.lasalletech.entity.QName; +import org.openfast.FastObject; +import org.openfast.Global; +import org.openfast.fast.FastTypes; +import org.openfast.template.Operator; +import org.openfast.template.Scalar; +import org.openfast.template.Sequence; + +public class SimpleSequence extends SimpleComposite<FastObject> implements Sequence { + private final Scalar length; + + public SimpleSequence(QName name, Scalar length) { + super(name); + this.length = length; + } + + public FastObject newObject() { + return null; + } + + public Scalar getLength() { + return length; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicField.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicField.java 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicField.java 2008-07-18 21:19:20 UTC (rev 178) @@ -23,7 +23,6 @@ import java.util.HashMap; import java.util.Map; import org.lasalletech.entity.QName; -import org.lasalletech.entity.Type; public class BasicField implements Field { private static final long serialVersionUID = 1L; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java 2008-07-18 21:19:20 UTC (rev 178) @@ -46,7 +46,7 @@ return false; } - public org.lasalletech.entity.Type getType() { + public Type getType() { return type; } Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/Composite.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Composite.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Composite.java 2008-07-18 21:19:20 UTC (rev 178) @@ -0,0 +1,16 @@ +package org.openfast.template; + +import org.lasalletech.entity.EObject; +import org.lasalletech.entity.Entity; +import org.lasalletech.entity.QName; + +@SuppressWarnings("unchecked") +public interface Composite<O extends EObject> extends Entity<O, Field> { + Scalar getScalar(int index); + Sequence getSequence(int index); + Group getGroup(int index); + void setChildNamespace(String namespace); + void setTypeReference(QName typeReference); + boolean hasTypeReference(); + QName getTypeReference(); +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Field.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Field.java 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Field.java 2008-07-18 21:19:20 UTC (rev 178) @@ -24,7 +24,7 @@ import org.lasalletech.entity.Named; import org.lasalletech.entity.QName; -public interface Field extends org.lasalletech.entity.Field, Named, Serializable { +public interface Field extends org.lasalletech.entity.Field<Type>, Named, Serializable { boolean isOptional(); QName getKey(); void setKey(QName key); Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Group.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Group.java 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Group.java 2008-07-18 21:19:20 UTC (rev 178) @@ -20,162 +20,119 @@ */ package org.openfast.template; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; import org.lasalletech.entity.QName; -import org.lasalletech.entity.Type; -import org.lasalletech.entity.simple.SimpleEntity; +import org.openfast.FastObject; -public class Group extends SimpleEntity implements Field { - private static final long serialVersionUID = 1L; - protected QName typeReference = null; - protected String childNamespace = ""; - protected final boolean optional; - protected final Field field; - protected List<StaticTemplateReference> staticTemplateReferences = Collections.emptyList(); +public interface Group extends Composite<FastObject> { - public Group(String name, Field[] fields, boolean optional) { - this(new QName(name), fields, optional); - } +// private static final long serialVersionUID = 1L; +// protected QName typeReference = null; +// protected String childNamespace = ""; +// protected final boolean optional; +// protected List<StaticTemplateReference> staticTemplateReferences = Collections.emptyList(); +// +// public Group(String name, Field[] fields, boolean optional) { +// this(new QName(name), fields, optional); +// } +// +// public Group(QName name, Field[] fields, boolean optional) { +// super(name.getName()); +// field = new BasicField(name, optional); +// this.optional = optional; +// for (Field field : fields) { +// if (field instanceof StaticTemplateReference) { +// StaticTemplateReference reference = (StaticTemplateReference) field; +// for (Field referencedField : reference.getTemplate().getFields()) +// add(referencedField); +// if (staticTemplateReferences.isEmpty()) { +// staticTemplateReferences = new LinkedList<StaticTemplateReference>(); +// } +// staticTemplateReferences.add(reference); +// } else { +// add(field); +// } +// } +// } +// +// /** +// * @return Returns the string 'group' +// */ +// public String getTypeName() { +// return "group"; +// } +// +// /** +// * Get the Sequence of the passed fieldName +// * +// * @param fieldName +// * The field name that is being searched for +// * @return Returns a sequence object of the specified fieldName +// */ +// public Sequence getSequence(String fieldName) { +// return (Sequence) getField(fieldName); +// } +// +// /** +// * Get the Scalar Value of the passed fieldName +// * +// * @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); +// } +// +// /** +// * Find the group with the passed fieldName +// * +// * @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) { +// return (Group) getField(fieldName); +// } +// +// /** +// * Set the name of the type referenced by this group +// * +// * @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 +// */ +// public QName getTypeReference() { +// return typeReference; +// } +// +// /** +// * @return Returns true if the type has a reference, false otherwise +// */ +// public boolean hasTypeReference() { +// return typeReference != null; +// } +// +// public String toString() { +// return getName(); +// } +// +// public String getChildNamespace() { +// return childNamespace; +// } +// +// public void setChildNamespace(String childNamespace) { +// this.childNamespace = childNamespace; +// } - public Group(QName name, Field[] fields, boolean optional) { - super(name.getName()); - field = new BasicField(name, optional); - this.optional = optional; - for (Field field : fields) { - if (field instanceof StaticTemplateReference) { - StaticTemplateReference reference = (StaticTemplateReference) field; - for (org.lasalletech.entity.Field referencedField : reference.getTemplate().getFields()) - add(referencedField); - if (staticTemplateReferences.isEmpty()) { - staticTemplateReferences = new LinkedList<StaticTemplateReference>(); - } - staticTemplateReferences.add(reference); - } else { - add(field); - } - } - } - - /** - * @return Returns the string 'group' - */ - public String getTypeName() { - return "group"; - } - - /** - * Get the Sequence of the passed fieldName - * - * @param fieldName - * The field name that is being searched for - * @return Returns a sequence object of the specified fieldName - */ - public Sequence getSequence(String fieldName) { - return (Sequence) getField(fieldName); - } - - /** - * Get the Scalar Value of the passed fieldName - * - * @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); - } - - /** - * Find the group with the passed fieldName - * - * @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) { - return (Group) getField(fieldName); - } - - /** - * Set the name of the type referenced by this group - * - * @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 - */ - public QName getTypeReference() { - return typeReference; - } - - /** - * @return Returns true if the type has a reference, false otherwise - */ - public boolean hasTypeReference() { - return typeReference != null; - } - - public String toString() { - return getName(); - } - - public String getChildNamespace() { - return childNamespace; - } - - public void setChildNamespace(String childNamespace) { - this.childNamespace = childNamespace; - } - - public Type getType() { - return null; - } - - public boolean isRequired() { - return !optional; - } - - public void addAttribute(QName name, String value) { - field.addAttribute(name, value); - } - - public String getAttribute(QName name) { - return field.getAttribute(name); - } - - public String getId() { - return field.getId(); - } - - public QName getKey() { - return field.getKey(); - } - - public boolean hasAttribute(QName attributeName) { - return field.hasAttribute(attributeName); - } - - public boolean isOptional() { - return false; - } - - public void setId(String id) { - field.setId(id); - } - - public void setKey(QName key) { - field.setKey(key); - } } \ No newline at end of file Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/MessageTemplate.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/MessageTemplate.java 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/MessageTemplate.java 2008-07-18 21:19:20 UTC (rev 178) @@ -20,28 +20,8 @@ */ package org.openfast.template; -import org.lasalletech.entity.QName; import org.openfast.Message; -public class MessageTemplate extends Group implements Field { - private static final long serialVersionUID = 1L; +public interface MessageTemplate extends Composite<Message> { - public MessageTemplate(QName name, Field[] fields) { - super(name, fields, false); - } - - public MessageTemplate(String name, Field[] fields) { - this(new QName(name), fields); - } - - /** - * @return Returns the class of the message - */ - public Class<?> getValueType() { - return Message.class; - } - - public String toString() { - return getName(); - } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java 2008-07-18 21:19:20 UTC (rev 178) @@ -21,7 +21,7 @@ package org.openfast.template; import org.lasalletech.entity.QName; -import org.openfast.template.type.Type; +import org.openfast.template.Type; public class Scalar extends BasicField implements Cloneable { private static final long serialVersionUID = 1L; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java 2008-07-18 21:19:20 UTC (rev 178) @@ -20,176 +20,178 @@ */ package org.openfast.template; -import org.lasalletech.entity.QName; -import org.openfast.Global; -import org.openfast.template.type.Type; +import org.openfast.FastObject; -public class Sequence extends BasicField { - private static final long serialVersionUID = 1L; - private final Group group; - private final Scalar length; - private boolean implicitLength; - /** - * Sequence Constructor - Sets the implicitLength to true - * - * @param name - * The name of the sequence as a string - * @param fields - * Field array object - * @param optional - * Determines if the Field is required or not for the data - * - */ - public Sequence(QName name, Field[] fields, boolean optional) { - this(name, createLength(name, optional), fields, optional); - implicitLength = true; - } +public interface Sequence extends Composite<FastObject> { +// private static final long serialVersionUID = 1L; +// private final Group group; +// private final Scalar length; +// private boolean implicitLength; +// +// /** +// * Sequence Constructor - Sets the implicitLength to true +// * +// * @param name +// * The name of the sequence as a string +// * @param fields +// * Field array object +// * @param optional +// * Determines if the Field is required or not for the data +// * +// */ +// public Sequence(QName name, Field[] fields, boolean optional) { +// this(name, createLength(name, optional), fields, optional); +// implicitLength = true; +// } +// +// public Sequence(String name, Field[] fields, boolean optional) { +// this(new QName(name), fields, optional); +// } +// +// /** +// * Sequence Constructor - If no length, a length is created and the +// * implicitLength is set to true. A new Group is also created with with the +// * respected information. +// * +// * @param name +// * Name of the sequence, a string +// * @param length +// * Length of the sequence, a Scalar value +// * @param fields +// * Field array +// * @param optional +// * Determines if the Field is required or not for the data +// */ +// public Sequence(QName name, Scalar length, Field[] fields, boolean optional) { +// super(name, optional); +// this.group = new Group(name, fields, optional); +// if (length == null) { +// this.length = createLength(name, optional); +// implicitLength = true; +// } else { +// this.length = length; +// } +// } +// +// /** +// * Creates a Scalar value length +// * +// * @param name +// * The name of the Scalar object +// * @param optional +// * Determines if the Field is required or not for the data +// * @return A Scalar value +// */ +// private static Scalar createLength(QName name, boolean optional) { +// return new Scalar(Global.createImplicitName(name), Type.U32, null, optional); +// } +// +// /** +// * Find the number of fields in the current group +// * +// * @return Returns an integer of the number of fields +// */ +// public int getFieldCount() { +// return group.getFieldCount(); +// } +// +// /** +// * Find the length of a Scalar value +// * +// * @return The length of the Scalar value +// */ +// public Scalar getLength() { +// return length; +// } +// +// /** +// * @return Returns the string 'sequence' +// */ +// public String getTypeName() { +// return "sequence"; +// } +// +// /** +// * +// * @return Return the current Group +// */ +// public Group getGroup() { +// return group; +// } +// +// /** +// * +// * @param fieldName +// * String of the FieldName that is to be found +// * @return Returns true if there is a field with the specified name, false +// * otherwise +// */ +// public boolean hasField(String fieldName) { +// return group.hasField(fieldName); +// } +// +// /** +// * +// * @return Returns the implicitLength, true or false - whichever is set +// */ +// public boolean isImplicitLength() { +// return implicitLength; +// } +// +// /** +// * Set the type reference +// * +// * @param typeReference +// * The type reference name as a string +// */ +// public void setTypeReference(QName typeReference) { +// this.group.setTypeReference(typeReference); +// } +// +// /** +// * +// * @return Returns the typeReference as a string +// */ +// public QName getTypeReference() { +// return group.getTypeReference(); +// } +// +// /** +// * +// * @return Returns true if there is a type reference +// */ +// public boolean hasTypeReference() { +// return group.hasTypeReference(); +// } +// +// public String toString() { +// return name.getName(); +// } +// +// public int hashCode() { +// final int prime = 31; +// int result = 1; +// result = prime * result + ((group == null) ? 0 : group.hashCode()); +// result = prime * result + ((length == null) ? 0 : length.hashCode()); +// return result; +// } +// +// public boolean equals(Object obj) { +// if (this == obj) +// return true; +// if (obj == null || getClass() != obj.getClass()) +// return false; +// final Sequence other = (Sequence) obj; +// if (!group.equals(other.group)) +// return false; +// if (isImplicitLength() != other.isImplicitLength()) +// return false; +// if (!isImplicitLength() && !length.equals(other.length)) +// return false; +// return true; +// } - public Sequence(String name, Field[] fields, boolean optional) { - this(new QName(name), fields, optional); - } - - /** - * Sequence Constructor - If no length, a length is created and the - * implicitLength is set to true. A new Group is also created with with the - * respected information. - * - * @param name - * Name of the sequence, a string - * @param length - * Length of the sequence, a Scalar value - * @param fields - * Field array - * @param optional - * Determines if the Field is required or not for the data - */ - public Sequence(QName name, Scalar length, Field[] fields, boolean optional) { - super(name, optional); - this.group = new Group(name, fields, optional); - if (length == null) { - this.length = createLength(name, optional); - implicitLength = true; - } else { - this.length = length; - } - } - - /** - * Creates a Scalar value length - * - * @param name - * The name of the Scalar object - * @param optional - * Determines if the Field is required or not for the data - * @return A Scalar value - */ - private static Scalar createLength(QName name, boolean optional) { - return new Scalar(Global.createImplicitName(name), Type.U32, null, optional); - } - - /** - * Find the number of fields in the current group - * - * @return Returns an integer of the number of fields - */ - public int getFieldCount() { - return group.getFieldCount(); - } - - /** - * Find the length of a Scalar value - * - * @return The length of the Scalar value - */ - public Scalar getLength() { - return length; - } - - /** - * @return Returns the string 'sequence' - */ - public String getTypeName() { - return "sequence"; - } - - /** - * - * @return Return the current Group - */ - public Group getGroup() { - return group; - } - - /** - * - * @param fieldName - * String of the FieldName that is to be found - * @return Returns true if there is a field with the specified name, false - * otherwise - */ - public boolean hasField(String fieldName) { - return group.hasField(fieldName); - } - - /** - * - * @return Returns the implicitLength, true or false - whichever is set - */ - public boolean isImplicitLength() { - return implicitLength; - } - - /** - * Set the type reference - * - * @param typeReference - * The type reference name as a string - */ - public void setTypeReference(QName typeReference) { - this.group.setTypeReference(typeReference); - } - - /** - * - * @return Returns the typeReference as a string - */ - public QName getTypeReference() { - return group.getTypeReference(); - } - - /** - * - * @return Returns true if there is a type reference - */ - public boolean hasTypeReference() { - return group.hasTypeReference(); - } - - public String toString() { - return name.getName(); - } - - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((group == null) ? 0 : group.hashCode()); - result = prime * result + ((length == null) ? 0 : length.hashCode()); - return result; - } - - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null || getClass() != obj.getClass()) - return false; - final Sequence other = (Sequence) obj; - if (!group.equals(other.group)) - return false; - if (isImplicitLength() != other.isImplicitLength()) - return false; - if (!isImplicitLength() && !length.equals(other.length)) - return false; - return true; - } + String getName(); + Scalar getLength(); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Type.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Type.java 2008-07-18 02:44:48 UTC (rev 177) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Type.java 2008-07-18 21:19:20 UTC (rev 178) @@ -21,77 +21,9 @@ package org.openfast.template; import java.io.Serializable; +import org.lasalletech.entity.EObject; public interface Type extends Serializable, org.lasalletech.entity.Type { String getName(); -// 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, 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_VAL... [truncated message content] |
From: <ope...@li...> - 2008-07-18 02:44:43
|
Revision: 177 http://openfast.svn.sourceforge.net/openfast/?rev=177&view=rev Author: jacob_northey Date: 2008-07-18 02:44:48 +0000 (Fri, 18 Jul 2008) Log Message: ----------- Created simple example server and client Modified Paths: -------------- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastEncoder.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java branches/openfast-2.x/nio/pom.xml branches/openfast-2.x/nio/src/main/java/com/lasalletech/openfast/nio/mina/FastMessageDecoder.java branches/openfast-2.x/nio/src/main/java/com/lasalletech/openfast/nio/mina/FastMessageEncoder.java branches/openfast-2.x/nio/src/main/java/com/lasalletech/openfast/nio/mina/FastProtocolCodecFactory.java branches/openfast-2.x/pom.xml Added Paths: ----------- branches/openfast-2.x/core/src/eclipse/openfast-code-formatter.xml branches/openfast-2.x/examples/ branches/openfast-2.x/examples/pom.xml branches/openfast-2.x/examples/src/ branches/openfast-2.x/examples/src/main/ branches/openfast-2.x/examples/src/main/java/ branches/openfast-2.x/examples/src/main/java/com/ branches/openfast-2.x/examples/src/main/java/com/lasalletech/ branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/ branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/examples/ branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/examples/simple/ branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/examples/simple/SimpleClient.java branches/openfast-2.x/examples/src/main/java/com/lasalletech/openfast/examples/simple/SimpleServer.java branches/openfast-2.x/examples/src/main/resources/ branches/openfast-2.x/examples/src/main/resources/simple/ branches/openfast-2.x/examples/src/main/resources/simple/integerTemplates.xml branches/openfast-2.x/src/eclipse/ Removed Paths: ------------- branches/openfast-2.x/etc/openfast-code-formatter.xml Copied: branches/openfast-2.x/core/src/eclipse/openfast-code-formatter.xml (from rev 175, branches/openfast-2.x/etc/openfast-code-formatter.xml) =================================================================== --- branches/openfast-2.x/core/src/eclipse/openfast-code-formatter.xml (rev 0) +++ branches/openfast-2.x/core/src/eclipse/openfast-code-formatter.xml 2008-07-18 02:44:48 UTC (rev 177) @@ -0,0 +1,251 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<profiles version="10"> +<profile name="OpenFAST" version="10"> +<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_comments" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="80"/> +<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/> +<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/> +<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="135"/> +<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="tab"/> +<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/> +<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/> +</profile> +</profiles> Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Context.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-07-18 00:13:47 UTC (rev 176) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-07-18 02:44:48 UTC (rev 177) @@ -41,7 +41,7 @@ */ public class Context { private TemplateRegistry templateRegistry = new BasicTemplateRegistry(); - private int lastTemplateId; + private int lastTemplateId = -1; private Map<String, FastDictionary> dictionaries = new HashMap<String, FastDictionary>(); private ErrorHandler errorHandler = ErrorHandler.DEFAULT; private QName currentApplicationType; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java 2008-07-18 00:13:47 UTC (rev 176) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java 2008-07-18 02:44:48 UTC (rev 177) @@ -1,6 +1,7 @@ package org.openfast.codec; import org.lasalletech.entity.Field; +import org.openfast.ByteUtil; import org.openfast.Context; import org.openfast.Message; import org.openfast.dictionary.DictionaryRegistry; @@ -14,12 +15,14 @@ public class BasicMessageCodec implements MessageCodec { private final int templateId; private final IntegerCodec uintCodec; + private final BitVectorCodec bitVectorCodec; @SuppressWarnings("unchecked") private final FieldCodec[] fieldCodecs; public BasicMessageCodec(int id, MessageTemplate template, FastImplementation implementation, DictionaryRegistry dictionaryRegistry, CodecFactory codecFactory) { this.templateId = id; this.uintCodec = implementation.getTypeCodecRegistry().getIntegerCodec(FastTypes.U32); + this.bitVectorCodec = implementation.getTypeCodecRegistry().getBitVectorCodec(FastTypes.BIT_VECTOR); this.fieldCodecs = new FieldCodec[template.getFieldCount()]; int index = 0; for (Field field : template.getFields()) { @@ -40,15 +43,17 @@ index = uintCodec.encode(temp, offset, templateId); context.setLastTemplateId(templateId); pmapBuilder.set(); + } else { + pmapBuilder.skip(); } for (int i=0; i<fieldCodecs.length; i++) { index = fieldCodecs[i].encode(message, i, temp, index, message.getTemplate().getField(i), pmapBuilder, context); } - byte[] pmap = pmapBuilder.getBitVector().getBytes(); - System.arraycopy(pmap, 0, buffer, offset, pmap.length); - System.arraycopy(temp, 0, buffer, offset + pmap.length, index); + int pmapLen = bitVectorCodec.encode(buffer, offset, pmapBuilder.getBitVector()); + System.arraycopy(temp, 0, buffer, offset + pmapLen, index); context.discardTemporaryBuffer(temp); - return offset + pmap.length + index; + System.out.println(ByteUtil.convertByteArrayToBitString(buffer, offset + pmapLen + index)); + return offset + pmapLen + index; } public int getLength(byte[] buffer, int offset, BitVectorReader reader, Context context) { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java 2008-07-18 00:13:47 UTC (rev 176) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java 2008-07-18 02:44:48 UTC (rev 177) @@ -67,13 +67,12 @@ if (reader.read()) { templateId = uintCodec.decode(buffer, newOffset); newOffset += uintCodec.getLength(buffer, newOffset); - context.setLastTemplateId(templateId); } else { templateId = context.getLastTemplateId(); } MessageTemplate template = context.getTemplate(templateId); MessageCodec codec = getCodec(templateId, template); newOffset += codec.getLength(buffer, newOffset, reader, context); - return newOffset - offset; + return newOffset; } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastEncoder.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastEncoder.java 2008-07-18 00:13:47 UTC (rev 176) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastEncoder.java 2008-07-18 02:44:48 UTC (rev 177) @@ -9,20 +9,25 @@ public class FastEncoder implements Coder { private final Context context = new Context(); - private CodecFactory codecFactory = FastImplementation.getDefaultVersion().getCodecFactory(); + private final CodecFactory codecFactory; + private final FastImplementation implementation; + private final DictionaryRegistry dictionaryRegistry; private MessageCodecRegistry codecRegistry = new BasicCodecRegistry(); - private FastImplementation implementation = FastImplementation.getDefaultVersion(); - private DictionaryRegistry dictionaryRegistry = new BasicDictionaryRegistry(FastImplementation.getDefaultVersion().getDictionaryTypeRegistry()); public FastEncoder(TemplateRegistry templateRegistry) { - context.setTemplateRegistry(templateRegistry); + this(FastImplementation.getDefaultVersion(), templateRegistry); } - public void setFastImplementation(FastImplementation implementation) { + public FastEncoder(FastImplementation implementation, TemplateRegistry templateRegistry) { this.implementation = implementation; + context.setTemplateRegistry(templateRegistry); dictionaryRegistry = new BasicDictionaryRegistry(implementation.getDictionaryTypeRegistry()); + codecFactory = implementation.getCodecFactory(); } + public void setFastImplementation(FastImplementation implementation) { + } + public int encode(byte[] buffer, int offset, Message message) { MessageCodec encoder = getEncoder(message); return encoder.encode(buffer, offset, message, context); Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java 2008-07-18 00:13:47 UTC (rev 176) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java 2008-07-18 02:44:48 UTC (rev 177) @@ -99,8 +99,11 @@ } int previousValue = dictionaryEntry.getInt(); if (value == previousValue + 1) { + dictionaryEntry.set(previousValue + 1); return offset; } + + dictionaryEntry.set(value); return integerCodec.encode(buffer, offset, value); } Deleted: branches/openfast-2.x/etc/openfast-code-formatter.xml =================================================================== --- branches/openfast-2.x/etc/openfast-code-formatter.xml 2008-07-18 00:13:47 UTC (rev 176) +++ branches/openfast-2.x/etc/openfast-code-formatter.xml 2008-07-18 02:44:48 UTC (rev 177) @@ -1,251 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<profiles version="10"> -<profile name="OpenFAST" version="10"> -<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/> -<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/> -<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/> -<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/> -<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="1"/> -<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/> -<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/> -<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/> -<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/> -<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/> -<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/> -<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/> -<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/> -<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/> -<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/> -<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/> -<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/> -<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/> -<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/> -<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/> -<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/> -<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/> -<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/> -<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines" value="false"/> -<setting id="org.eclipse.jdt.core.formatter.comment.format_comments" value="true"/> -<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/> -<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/> -<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/> -<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/> -<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/> -<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="80"/> -<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/> -<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/> -<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/> -<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/> -<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/> -<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/> -<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/> -<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/> -<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/> -<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/> -<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/> -<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/> -<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/> -<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="false"/> -<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/> -<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/> -<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ope... [truncated message content] |
From: <ope...@li...> - 2008-07-18 00:14:07
|
Revision: 176 http://openfast.svn.sourceforge.net/openfast/?rev=176&view=rev Author: jacob_northey Date: 2008-07-18 00:13:47 +0000 (Fri, 18 Jul 2008) Log Message: ----------- Implemented basic decoding Modified Paths: -------------- branches/openfast-2.x/core/pom.xml branches/openfast-2.x/core/src/main/java/org/openfast/Context.java branches/openfast-2.x/core/src/main/java/org/openfast/Global.java branches/openfast-2.x/core/src/main/java/org/openfast/Message.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicTypeCodecRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/MessageCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/FastTypeCodecs.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/AbstractDictionaryEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/IntegerEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/StringEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/TemplateDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/error/FastConstants.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastTypes.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast_1_1Implementation.java branches/openfast-2.x/core/src/main/java/org/openfast/template/AbstractTemplateRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicField.java branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicTemplateRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java branches/openfast-2.x/core/src/main/java/org/openfast/template/DynamicTemplateReference.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Field.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Group.java branches/openfast-2.x/core/src/main/java/org/openfast/template/MessageTemplate.java branches/openfast-2.x/core/src/main/java/org/openfast/template/NullTemplateRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java branches/openfast-2.x/core/src/main/java/org/openfast/template/TemplateRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Type.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/AbstractFieldParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ComposedDecimalParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/CopyOperatorParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DeltaOperatorParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DictionaryOperatorParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/GroupParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/IncrementOperatorParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ParsingContext.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ScalarParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/SequenceParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TailOperatorParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TemplateParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TemplateRefParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/CopyOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DeltaOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DictionaryOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/IncrementOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/TailOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/Type.java branches/openfast-2.x/core/src/main/java/org/openfast/util/BitVector.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastOperatorTestHarness.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastStringOperatorTestHarness.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/Array.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/XMLMessageTemplateLoaderTest.java branches/openfast-2.x/pom.xml branches/openfast-2.x/src/assembly/binary.xml branches/openfast-2.x/src/assembly/source.xml Added Paths: ----------- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BitVectorCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/SinglePresenceMapEntryFieldCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/AlwaysPresentCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/BasicBitVectorCodec.java branches/openfast-2.x/core/src/test/java/org/openfast/BasicMessageDecodingAcceptanceTest.java branches/openfast-2.x/core/src/test/java/org/openfast/BasicMessageEncodingAcceptanceTest.java branches/openfast-2.x/nio/ branches/openfast-2.x/nio/pom.xml branches/openfast-2.x/nio/src/ branches/openfast-2.x/nio/src/main/ branches/openfast-2.x/nio/src/main/java/ branches/openfast-2.x/nio/src/main/java/com/ branches/openfast-2.x/nio/src/main/java/com/lasalletech/ branches/openfast-2.x/nio/src/main/java/com/lasalletech/openfast/ branches/openfast-2.x/nio/src/main/java/com/lasalletech/openfast/nio/ branches/openfast-2.x/nio/src/main/java/com/lasalletech/openfast/nio/mina/ branches/openfast-2.x/nio/src/main/java/com/lasalletech/openfast/nio/mina/FastMessageDecoder.java branches/openfast-2.x/nio/src/main/java/com/lasalletech/openfast/nio/mina/FastMessageEncoder.java branches/openfast-2.x/nio/src/main/java/com/lasalletech/openfast/nio/mina/FastProtocolCodecFactory.java branches/openfast-2.x/nio/src/test/ branches/openfast-2.x/nio/src/test/java/ branches/openfast-2.x/src/ branches/openfast-2.x/src/assembly/ Removed Paths: ------------- branches/openfast-2.x/core/src/assembly/ branches/openfast-2.x/core/src/main/java/org/openfast/template/GroupReference.java branches/openfast-2.x/core/src/test/java/org/openfast/GeneralAcceptanceTest.java Property Changed: ---------------- branches/openfast-2.x/core/ Property changes on: branches/openfast-2.x/core ___________________________________________________________________ Modified: svn:ignore - target .classpath .project .settings bin + target .classpath .project .settings bin hotspot.log Modified: branches/openfast-2.x/core/pom.xml =================================================================== --- branches/openfast-2.x/core/pom.xml 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/pom.xml 2008-07-18 00:13:47 UTC (rev 176) @@ -75,32 +75,14 @@ </execution> </executions> </plugin> - <plugin> - <artifactId>maven-assembly-plugin</artifactId> - <configuration> - <descriptors> - <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> <dependencies> <dependency> - <groupId>com.lasalletech.exom</groupId> - <artifactId>exom</artifactId> - <version>0.2.0-SNAPSHOT</version> + <groupId>com.lasalletech.entity</groupId> + <artifactId>entity</artifactId> + <version>0.3.0-SNAPSHOT</version> </dependency> </dependencies> </project> \ No newline at end of file Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Context.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-07-18 00:13:47 UTC (rev 176) @@ -24,7 +24,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; import org.openfast.dictionary.FastDictionary; import org.openfast.dictionary.GlobalFastDictionary; import org.openfast.error.ErrorHandler; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Global.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Global.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Global.java 2008-07-18 00:13:47 UTC (rev 176) @@ -20,7 +20,7 @@ */ package org.openfast; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; import org.openfast.error.ErrorCode; import org.openfast.error.ErrorHandler; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Message.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Message.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Message.java 2008-07-18 00:13:47 UTC (rev 176) @@ -20,7 +20,7 @@ */ package org.openfast; -import org.lasalletech.exom.simple.SimpleEObject; +import org.lasalletech.entity.simple.SimpleEObject; import org.openfast.template.MessageTemplate; public class Message extends SimpleEObject { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,6 +1,6 @@ package org.openfast.codec; -import org.lasalletech.exom.Field; +import org.lasalletech.entity.Field; import org.openfast.Context; import org.openfast.Message; import org.openfast.dictionary.DictionaryRegistry; @@ -9,6 +9,7 @@ import org.openfast.template.MessageTemplate; import org.openfast.template.Scalar; import org.openfast.util.BitVectorBuilder; +import org.openfast.util.BitVectorReader; public class BasicMessageCodec implements MessageCodec { private final int templateId; @@ -40,14 +41,8 @@ context.setLastTemplateId(templateId); pmapBuilder.set(); } - int previousIndex; for (int i=0; i<fieldCodecs.length; i++) { - previousIndex = index; - index = fieldCodecs[i].encode(message, i, temp, index, message.getTemplate().getField(i), context); - if (index != previousIndex) - pmapBuilder.set(); - else - pmapBuilder.skip(); + index = fieldCodecs[i].encode(message, i, temp, index, message.getTemplate().getField(i), pmapBuilder, context); } byte[] pmap = pmapBuilder.getBitVector().getBytes(); System.arraycopy(pmap, 0, buffer, offset, pmap.length); @@ -55,4 +50,19 @@ context.discardTemporaryBuffer(temp); return offset + pmap.length + index; } + + public int getLength(byte[] buffer, int offset, BitVectorReader reader, Context context) { + int length = 0; + for (int i=0; i<fieldCodecs.length; i++) { + length += fieldCodecs[i].getLength(buffer, offset, reader); + } + return length; + } + + @SuppressWarnings("unchecked") + public void decode(Message message, byte[] buffer, int offset, BitVectorReader reader, Context context) { + for (int i=0; i<fieldCodecs.length; i++) { + fieldCodecs[i].decode(message, i, buffer, offset, message.getTemplate().getField(i), reader, context); + } + } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicTypeCodecRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicTypeCodecRegistry.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicTypeCodecRegistry.java 2008-07-18 00:13:47 UTC (rev 176) @@ -35,4 +35,8 @@ public StringCodec getStringCodec(Type type, boolean nullable) { return (StringCodec) getCodec(type, nullable); } + + public BitVectorCodec getBitVectorCodec(Type type) { + return (BitVectorCodec) getCodec(type, false); + } } Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BitVectorCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BitVectorCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BitVectorCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -0,0 +1,8 @@ +package org.openfast.codec; + +import org.openfast.util.BitVector; + +public interface BitVectorCodec extends TypeCodec { + BitVector decode(byte[] buffer, int offset); + int encode(byte[] buffer, int offset, BitVector vector); +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java 2008-07-18 00:13:47 UTC (rev 176) @@ -0,0 +1,79 @@ +package org.openfast.codec; + +import org.openfast.Context; +import org.openfast.Message; +import org.openfast.dictionary.BasicDictionaryRegistry; +import org.openfast.dictionary.DictionaryRegistry; +import org.openfast.fast.FastTypes; +import org.openfast.fast.impl.FastImplementation; +import org.openfast.template.MessageTemplate; +import org.openfast.template.TemplateRegistry; +import org.openfast.util.BitVectorReader; + +public class FastDecoder implements Coder { + private final Context context = new Context(); + private final CodecFactory codecFactory = FastImplementation.getDefaultVersion().getCodecFactory(); + private final MessageCodecRegistry codecRegistry = new BasicCodecRegistry(); + private final FastImplementation implementation; + private final DictionaryRegistry dictionaryRegistry; + private final BitVectorCodec bitVectorCodec; + private final IntegerCodec uintCodec; + + public FastDecoder(TemplateRegistry templateRegistry) { + this(FastImplementation.getDefaultVersion(), templateRegistry); + } + + public FastDecoder(FastImplementation implementation, TemplateRegistry templateRegistry) { + context.setTemplateRegistry(templateRegistry); + this.implementation = implementation; + dictionaryRegistry = new BasicDictionaryRegistry(implementation.getDictionaryTypeRegistry()); + bitVectorCodec = implementation.getTypeCodecRegistry().getBitVectorCodec(FastTypes.BIT_VECTOR); + uintCodec = implementation.getTypeCodecRegistry().getIntegerCodec(FastTypes.U32); + } + + public Message decode(byte[] buffer, int offset) { + BitVectorReader reader = new BitVectorReader(bitVectorCodec.decode(buffer, offset)); + offset += bitVectorCodec.getLength(buffer, offset); + int templateId = 0; + if (reader.read()) { + templateId = uintCodec.decode(buffer, offset); + offset += uintCodec.getLength(buffer, offset); + context.setLastTemplateId(templateId); + } else { + templateId = context.getLastTemplateId(); + } + MessageTemplate template = context.getTemplate(templateId); + MessageCodec codec = getCodec(templateId, template); + Message message = new Message(template); + codec.decode(message, buffer, offset, reader, context); + return message; + } + + public void reset() { + dictionaryRegistry.reset(); + } + + private MessageCodec getCodec(int id, MessageTemplate template) { + if (!codecRegistry.isRegistered(id)) { + codecRegistry.register(id, codecFactory.createMessageCodec(id, template, implementation, dictionaryRegistry)); + } + return codecRegistry.get(id); + } + + public int getNextMessageLength(byte[] buffer, final int offset) { + BitVectorReader reader = new BitVectorReader(bitVectorCodec.decode(buffer, offset)); + int newOffset = bitVectorCodec.getLength(buffer, offset); + int templateId = 0; + if (reader.read()) { + templateId = uintCodec.decode(buffer, newOffset); + newOffset += uintCodec.getLength(buffer, newOffset); + context.setLastTemplateId(templateId); + } else { + templateId = context.getLastTemplateId(); + } + MessageTemplate template = context.getTemplate(templateId); + MessageCodec codec = getCodec(templateId, template); + newOffset += codec.getLength(buffer, newOffset, reader, context); + return newOffset - offset; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,11 +1,12 @@ package org.openfast.codec; -import org.lasalletech.exom.EObject; +import org.lasalletech.entity.EObject; import org.openfast.Context; -import org.openfast.template.Scalar; +import org.openfast.util.BitVectorBuilder; +import org.openfast.util.BitVectorReader; public interface FieldCodec<T> { - int decode(EObject object, int index, byte[] buffer, int offset, T field, Context context); - void decodeEmpty(EObject object, int index, Scalar scalar, Context context); - int encode(EObject object, int index, byte[] buffer, int offset, T field, Context context); + int decode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorReader reader, Context context); + int encode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorBuilder pmapBuilder, Context context); + int getLength(byte[] buffer, int offset, BitVectorReader reader); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/MessageCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/MessageCodec.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/MessageCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -2,9 +2,10 @@ import org.openfast.Context; import org.openfast.Message; +import org.openfast.util.BitVectorReader; public interface MessageCodec { - int encode(byte[] buffer, int offset, Message message, Context context); - + void decode(Message message, byte[] buffer, int offset, BitVectorReader reader, Context context); + int getLength(byte[] buffer, int offset, BitVectorReader reader, Context context); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -23,5 +23,4 @@ import org.openfast.template.Scalar; public interface ScalarCodec extends FieldCodec<Scalar> { - int getLength(byte[] buffer, int offset); } Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/SinglePresenceMapEntryFieldCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/SinglePresenceMapEntryFieldCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/SinglePresenceMapEntryFieldCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -0,0 +1,35 @@ +package org.openfast.codec; + +import org.lasalletech.entity.EObject; +import org.openfast.Context; +import org.openfast.util.BitVectorBuilder; +import org.openfast.util.BitVectorReader; + +public abstract class SinglePresenceMapEntryFieldCodec<T> implements FieldCodec<T> { + + public int encode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorBuilder pmapBuilder, Context context) { + int newOffset = encode(object, index, buffer, offset, field, context); + if (newOffset == offset) + pmapBuilder.skip(); + else + pmapBuilder.set(); + return newOffset; + }; + + public int decode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorReader reader, Context context) { + if (reader.read()) { + return decode(object, index, buffer, offset, field, context); + } + decodeEmpty(object, index, field, context); + return offset; + } + public int getLength(byte[] buffer, int offset, BitVectorReader reader) { + if (reader.read()) + return getLength(buffer, offset); + return 0; + } + public abstract int encode(EObject object, int index, byte[] buffer, int offset, T field, Context context); + public abstract int decode(EObject object, int index, byte[] buffer, int offset, T field, Context context); + public abstract void decodeEmpty(EObject object, int index, T field, Context context); + public abstract int getLength(byte[] buffer, int offset); +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java 2008-07-18 00:13:47 UTC (rev 176) @@ -8,6 +8,7 @@ IntegerCodec getIntegerCodec(Type type, boolean nullable); StringCodec getStringCodec(Type type); StringCodec getStringCodec(Type type, boolean nullable); + BitVectorCodec getBitVectorCodec(Type bitVector); void register(Type type, TypeCodec codec); void register(Type type, boolean nullable, TypeCodec codec); Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/AlwaysPresentCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/AlwaysPresentCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/AlwaysPresentCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -0,0 +1,27 @@ +package org.openfast.codec.operator; + +import org.lasalletech.entity.EObject; +import org.openfast.Context; +import org.openfast.codec.FieldCodec; +import org.openfast.util.BitVectorBuilder; +import org.openfast.util.BitVectorReader; + +public abstract class AlwaysPresentCodec<T> implements FieldCodec<T> { + + public int decode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorReader reader, Context context) { + return decode(object, index, buffer, offset, field, context); + } + + public int encode(EObject object, int index, byte[] buffer, int offset, T field, BitVectorBuilder pmapBuilder, Context context) { + return encode(object, index, buffer, offset, field, context); + } + + public int getLength(byte[] buffer, int offset, BitVectorReader reader) { + return getLength(buffer, offset); + } + + public abstract int getLength(byte[] buffer, int offset); + + public abstract int decode(EObject object, int index, byte[] buffer, int offset, T field, Context context); + public abstract int encode(EObject object, int index, byte[] buffer, int offset, T field, Context context); +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantIntegerCodec.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantIntegerCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,9 +1,11 @@ package org.openfast.codec.operator; -import org.lasalletech.exom.EObject; +import org.lasalletech.entity.EObject; import org.openfast.Context; import org.openfast.codec.ScalarCodec; import org.openfast.template.Scalar; +import org.openfast.util.BitVectorBuilder; +import org.openfast.util.BitVectorReader; public class ConstantIntegerCodec implements ScalarCodec { private final int defaultValue; @@ -11,19 +13,14 @@ public ConstantIntegerCodec(int defaultValue) { this.defaultValue = defaultValue; } - public int getLength(byte[] buffer, int offset) { - return 0; - } - - public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, BitVectorReader reader, Context context) { object.set(index, defaultValue); return offset; } - - public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, BitVectorBuilder pmapBuilder, Context context) { return offset; } - public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { - object.set(index, defaultValue); + public int getLength(byte[] buffer, int offset, BitVectorReader reader) { + return 0; } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,6 +1,6 @@ package org.openfast.codec.operator; -import org.lasalletech.exom.EObject; +import org.lasalletech.entity.EObject; import org.openfast.Context; import org.openfast.Fast; import org.openfast.codec.IntegerCodec; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyStringCodec.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyStringCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,6 +1,6 @@ package org.openfast.codec.operator; -import org.lasalletech.exom.EObject; +import org.lasalletech.entity.EObject; import org.openfast.Context; import org.openfast.Fast; import org.openfast.codec.ScalarCodec; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultIntegerCodec.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultIntegerCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,14 +1,15 @@ package org.openfast.codec.operator; -import org.lasalletech.exom.EObject; +import org.lasalletech.entity.EObject; import org.openfast.Context; import org.openfast.Fast; import org.openfast.codec.IntegerCodec; import org.openfast.codec.ScalarCodec; +import org.openfast.codec.SinglePresenceMapEntryFieldCodec; import org.openfast.template.Operator; import org.openfast.template.Scalar; -public class DefaultIntegerCodec implements ScalarCodec { +public class DefaultIntegerCodec extends SinglePresenceMapEntryFieldCodec<Scalar> implements ScalarCodec { private final Operator operator; private final IntegerCodec integerCodec; private final int defaultValue; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,6 +1,6 @@ package org.openfast.codec.operator; -import org.lasalletech.exom.EObject; +import org.lasalletech.entity.EObject; import org.openfast.Context; import org.openfast.Fast; import org.openfast.codec.IntegerCodec; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,7 +1,7 @@ package org.openfast.codec.operator; import static org.openfast.Fast.NULL; -import org.lasalletech.exom.EObject; +import org.lasalletech.entity.EObject; import org.openfast.Context; import org.openfast.codec.IntegerCodec; import org.openfast.codec.ScalarCodec; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorIntegerCodec.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorIntegerCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -2,10 +2,12 @@ import org.openfast.codec.IntegerCodec; import org.openfast.codec.ScalarCodec; +import org.openfast.codec.SinglePresenceMapEntryFieldCodec; import org.openfast.dictionary.DictionaryEntry; +import org.openfast.template.Scalar; import org.openfast.template.operator.DictionaryOperator; -public abstract class DictionaryOperatorIntegerCodec implements ScalarCodec { +public abstract class DictionaryOperatorIntegerCodec extends SinglePresenceMapEntryFieldCodec<Scalar> implements ScalarCodec { protected final IntegerCodec integerCodec; protected final DictionaryOperator operator; protected final int initialValue; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorStringCodec.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorStringCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,11 +1,13 @@ package org.openfast.codec.operator; import org.openfast.codec.ScalarCodec; +import org.openfast.codec.SinglePresenceMapEntryFieldCodec; import org.openfast.codec.StringCodec; import org.openfast.dictionary.DictionaryEntry; +import org.openfast.template.Scalar; import org.openfast.template.operator.DictionaryOperator; -public abstract class DictionaryOperatorStringCodec implements ScalarCodec { +public abstract class DictionaryOperatorStringCodec extends SinglePresenceMapEntryFieldCodec<Scalar> implements ScalarCodec { protected final DictionaryOperator operator; protected final StringCodec stringCodec; protected final DictionaryEntry dictionaryEntry; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -20,7 +20,7 @@ */ package org.openfast.codec.operator; -import org.lasalletech.exom.EObject; +import org.lasalletech.entity.EObject; import org.openfast.Context; import org.openfast.codec.IntegerCodec; import org.openfast.codec.ScalarCodec; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneIntegerCodec.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneIntegerCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,13 +1,13 @@ package org.openfast.codec.operator; -import org.lasalletech.exom.EObject; +import org.lasalletech.entity.EObject; import org.openfast.Context; import org.openfast.Fast; import org.openfast.codec.IntegerCodec; import org.openfast.codec.ScalarCodec; import org.openfast.template.Scalar; -public class NoneIntegerCodec implements ScalarCodec { +public class NoneIntegerCodec extends AlwaysPresentCodec<Scalar> implements ScalarCodec { private IntegerCodec integerCodec; public NoneIntegerCodec(IntegerCodec integerCodec) { @@ -24,8 +24,6 @@ return integerCodec.getLength(buffer, offset); } - public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) {} - public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { if (!object.isDefined(index)) { buffer[offset] = Fast.NULL; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneStringCodec.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneStringCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,13 +1,13 @@ package org.openfast.codec.operator; -import org.lasalletech.exom.EObject; +import org.lasalletech.entity.EObject; import org.openfast.Context; import org.openfast.Fast; import org.openfast.codec.ScalarCodec; import org.openfast.codec.StringCodec; import org.openfast.template.Scalar; -public class NoneStringCodec implements ScalarCodec { +public class NoneStringCodec extends AlwaysPresentCodec<Scalar> implements ScalarCodec { private StringCodec stringCodec; public NoneStringCodec(StringCodec stringCodec) { @@ -24,8 +24,6 @@ return stringCodec.getLength(buffer, offset); } - public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) {} - public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { if (!object.isDefined(index)) { buffer[offset] = Fast.NULL; Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/BasicBitVectorCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/BasicBitVectorCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/BasicBitVectorCodec.java 2008-07-18 00:13:47 UTC (rev 176) @@ -0,0 +1,29 @@ +package org.openfast.codec.type; + +import static org.openfast.Fast.STOP_BIT; +import static org.openfast.Fast.VALUE_BITS; +import org.openfast.codec.BitVectorCodec; +import org.openfast.util.BitVector; + +public class BasicBitVectorCodec extends StopBitEncodedTypeCodec implements BitVectorCodec { + public BitVector decode(byte[] buffer, int offset) { + int len = getLength(buffer, offset); + byte[] newBuffer = new byte[len]; + System.arraycopy(buffer, offset, newBuffer, 0, len); + return new BitVector(newBuffer); + } + + public int encode(byte[] buffer, int offset, BitVector vector) { + byte[] bytes = vector.getBytes(); + int index = bytes.length - 1; + while (index > 0 && (bytes[index] & VALUE_BITS) == 0) + index--; + System.arraycopy(bytes, 0, buffer, offset, index + 1); + buffer[index] |= STOP_BIT; + return index+1; + } + + public boolean isNull(byte[] buffer, int offset) { + return false; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/FastTypeCodecs.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/FastTypeCodecs.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/FastTypeCodecs.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,13 +1,15 @@ package org.openfast.codec.type; +import org.openfast.codec.BitVectorCodec; import org.openfast.codec.IntegerCodec; import org.openfast.codec.StringCodec; public class FastTypeCodecs { - public static final IntegerCodec UNSIGNED_INTEGER = new UnsignedIntegerCodec(); - public static final IntegerCodec SIGNED_INTEGER = new SignedIntegerCodec(); - public static final IntegerCodec NULLABLE_UNSIGNED_INTEGER = new NullableUnsignedIntegerCodec(); - public static final IntegerCodec NULLABLE_SIGNED_INTEGER = new NullableSignedIntegerCodec(); - public static final StringCodec ASCII_STRING = new AsciiStringCodec(); - public static final StringCodec NULLABLE_ASCII_STRING = new NullableAsciiStringCodec(); + public static final IntegerCodec UNSIGNED_INTEGER = new UnsignedIntegerCodec(); + public static final IntegerCodec SIGNED_INTEGER = new SignedIntegerCodec(); + public static final IntegerCodec NULLABLE_UNSIGNED_INTEGER = new NullableUnsignedIntegerCodec(); + public static final IntegerCodec NULLABLE_SIGNED_INTEGER = new NullableSignedIntegerCodec(); + public static final StringCodec ASCII_STRING = new AsciiStringCodec(); + public static final StringCodec NULLABLE_ASCII_STRING = new NullableAsciiStringCodec(); + public static final BitVectorCodec BIT_VECTOR = new BasicBitVectorCodec(); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/AbstractDictionaryEntry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/AbstractDictionaryEntry.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/AbstractDictionaryEntry.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,6 +1,6 @@ package org.openfast.dictionary; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; public abstract class AbstractDictionaryEntry { protected final QName key; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryEntry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryEntry.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryEntry.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,6 +1,6 @@ package org.openfast.dictionary; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; public interface DictionaryEntry { void set(int value); Modified: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,6 +1,6 @@ package org.openfast.dictionary; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; import org.openfast.template.type.Type; public interface FastDictionary { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,6 +1,6 @@ package org.openfast.dictionary; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; import org.openfast.template.type.IntegerType; import org.openfast.template.type.StringType; import org.openfast.template.type.Type; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/IntegerEntry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/IntegerEntry.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/IntegerEntry.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,6 +1,6 @@ package org.openfast.dictionary; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; public class IntegerEntry extends AbstractDictionaryEntry implements DictionaryEntry { private int value; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/StringEntry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/StringEntry.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/StringEntry.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,6 +1,6 @@ package org.openfast.dictionary; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; public class StringEntry extends AbstractDictionaryEntry implements DictionaryEntry { private String value; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/TemplateDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/TemplateDictionary.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/TemplateDictionary.java 2008-07-18 00:13:47 UTC (rev 176) @@ -2,7 +2,7 @@ import java.util.HashMap; import java.util.Map; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; import org.openfast.template.Scalar; public class TemplateDictionary implements Dictionary { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/error/FastConstants.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/error/FastConstants.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/error/FastConstants.java 2008-07-18 00:13:47 UTC (rev 176) @@ -20,7 +20,7 @@ */ package org.openfast.error; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; public interface FastConstants { byte NULL_BYTE = (byte) 0x80; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastTypes.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastTypes.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastTypes.java 2008-07-18 00:13:47 UTC (rev 176) @@ -23,5 +23,8 @@ 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 final Type[] INTEGER_TYPES = new Type[] { U8, U16, U32, U64, I8, I16, I32, I64 }; + public static final Type BIT_VECTOR = new org.openfast.template.type.Type("bitVector"){ + private static final long serialVersionUID = 1L; + }; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast_1_1Implementation.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast_1_1Implementation.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast_1_1Implementation.java 2008-07-18 00:13:47 UTC (rev 176) @@ -123,6 +123,7 @@ typeCodecRegistry.register(FastTypes.U64, true, FastTypeCodecs.NULLABLE_UNSIGNED_INTEGER); typeCodecRegistry.register(FastTypes.ASCII, FastTypeCodecs.ASCII_STRING); typeCodecRegistry.register(FastTypes.ASCII, true, FastTypeCodecs.NULLABLE_ASCII_STRING); + typeCodecRegistry.register(FastTypes.BIT_VECTOR, false, FastTypeCodecs.BIT_VECTOR); } return typeCodecRegistry; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/AbstractTemplateRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/AbstractTemplateRegistry.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/AbstractTemplateRegistry.java 2008-07-18 00:13:47 UTC (rev 176) @@ -23,7 +23,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; public abstract class AbstractTemplateRegistry implements TemplateRegistry { private List<TemplateRegisteredListener> listeners = Collections.emptyList(); Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicField.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicField.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicField.java 2008-07-18 00:13:47 UTC (rev 176) @@ -22,8 +22,8 @@ import java.util.HashMap; import java.util.Map; -import org.lasalletech.exom.QName; -import org.lasalletech.exom.Type; +import org.lasalletech.entity.QName; +import org.lasalletech.entity.Type; public class BasicField implements Field { private static final long serialVersionUID = 1L; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicTemplateRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicTemplateRegistry.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicTemplateRegistry.java 2008-07-18 00:13:47 UTC (rev 176) @@ -25,7 +25,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; public class BasicTemplateRegistry extends AbstractTemplateRegistry { private Map<QName, MessageTemplate> nameMap = new HashMap<QName, MessageTemplate>(); Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java 2008-07-18 00:13:47 UTC (rev 176) @@ -20,7 +20,7 @@ */ package org.openfast.template; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; import org.openfast.template.Type; public class ComposedScalar extends BasicField { @@ -46,7 +46,7 @@ return false; } - public org.lasalletech.exom.Type getType() { + public org.lasalletech.entity.Type getType() { return type; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/DynamicTemplateReference.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/DynamicTemplateReference.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/DynamicTemplateReference.java 2008-07-18 00:13:47 UTC (rev 176) @@ -20,7 +20,7 @@ */ package org.openfast.template; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; public class DynamicTemplateReference extends BasicField { private static final long serialVersionUID = 1L; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Field.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Field.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Field.java 2008-07-18 00:13:47 UTC (rev 176) @@ -21,10 +21,10 @@ package org.openfast.template; import java.io.Serializable; -import org.lasalletech.exom.Named; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.Named; +import org.lasalletech.entity.QName; -public interface Field extends org.lasalletech.exom.Field, Named, Serializable { +public interface Field extends org.lasalletech.entity.Field, Named, Serializable { boolean isOptional(); QName getKey(); void setKey(QName key); Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Group.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Group.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Group.java 2008-07-18 00:13:47 UTC (rev 176) @@ -23,9 +23,9 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; -import org.lasalletech.exom.QName; -import org.lasalletech.exom.Type; -import org.lasalletech.exom.simple.SimpleEntity; +import org.lasalletech.entity.QName; +import org.lasalletech.entity.Type; +import org.lasalletech.entity.simple.SimpleEntity; public class Group extends SimpleEntity implements Field { private static final long serialVersionUID = 1L; @@ -46,7 +46,7 @@ for (Field field : fields) { if (field instanceof StaticTemplateReference) { StaticTemplateReference reference = (StaticTemplateReference) field; - for (org.lasalletech.exom.Field referencedField : reference.getTemplate().getFields()) + for (org.lasalletech.entity.Field referencedField : reference.getTemplate().getFields()) add(referencedField); if (staticTemplateReferences.isEmpty()) { staticTemplateReferences = new LinkedList<StaticTemplateReference>(); @@ -99,7 +99,7 @@ * @return Returns a Group object of the specified field name */ public Group getGroup(String fieldName) { - return (Group) ((GroupReference) getField(fieldName).getType()).getEntity(); + return (Group) getField(fieldName); } /** Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/template/GroupReference.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/GroupReference.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/GroupReference.java 2008-07-18 00:13:47 UTC (rev 176) @@ -1,32 +0,0 @@ -package org.openfast.template; - -import org.lasalletech.exom.EObject; -import org.lasalletech.exom.EntityType; -import org.lasalletech.exom.QName; - -public class GroupReference extends EntityType { - - public GroupReference(Group group) { - super(group); - } - - public boolean isRepeating() { - return false; - } - - public void parse(EObject object, int index, char[] data, int offset, int length) {} - - public void parse(EObject object, String fieldName, char[] data, int offset, int length) {} - - public void parse(EObject object, int index, byte[] data, int offset, int length) {} - - public void parse(EObject object, String fieldName, byte[] data, int offset, int length) {} - - public byte[] serialize(EObject message, int index) { - return null; - } - - public QName getQName() { - return null; - } -} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/MessageTemplate.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/MessageTemplate.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/MessageTemplate.java 2008-07-18 00:13:47 UTC (rev 176) @@ -20,7 +20,7 @@ */ package org.openfast.template; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; import org.openfast.Message; public class MessageTemplate extends Group implements Field { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/NullTemplateRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/NullTemplateRegistry.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/NullTemplateRegistry.java 2008-07-18 00:13:47 UTC (rev 176) @@ -23,7 +23,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; final class NullTemplateRegistry implements TemplateRegistry { public void addTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener) {} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java 2008-07-18 00:13:47 UTC (rev 176) @@ -20,7 +20,7 @@ */ package org.openfast.template; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; import org.openfast.template.type.Type; public class Scalar extends BasicField implements Cloneable { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java 2008-07-18 00:13:47 UTC (rev 176) @@ -20,7 +20,7 @@ */ package org.openfast.template; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; import org.openfast.Global; import org.openfast.template.type.Type; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/TemplateRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/TemplateRegistry.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/TemplateRegistry.java 2008-07-18 00:13:47 UTC (rev 176) @@ -21,7 +21,7 @@ package org.openfast.template; import java.util.Iterator; -import org.lasalletech.exom.QName; +import org.lasalletech.entity.QName; public interface TemplateRegistry extends Iterable<MessageTemplate> { TemplateRegistry NULL = new NullTemplateRegistry(); Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Type.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Type.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Type.java 2008-07-18 00:13:47 UTC (rev 176) @@ -22,7 +22,7 @@ import java.io.Serializable; -public interface Type extends Serializable, org.lasalletech.exom.Type { +public interface Type extends Serializable, org.lasalletech.entity.Type { String getName(); // private final static Map TYPE_NAME_MAP = new LinkedHashMap(); // private final String name; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/AbstractFieldParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/AbstractFieldParser.java 2008-07-17 13:29:42 UTC (rev 175) +++ branches/openfast-2.x/core/src/ma... [truncated message content] |
From: <ope...@li...> - 2008-07-17 13:31:53
|
Revision: 175 http://openfast.svn.sourceforge.net/openfast/?rev=175&view=rev Author: jacob_northey Date: 2008-07-17 13:29:42 +0000 (Thu, 17 Jul 2008) Log Message: ----------- Fixed all warnings Modified Paths: -------------- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableAsciiStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Dictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/TemplateDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/error/ErrorCode.java branches/openfast-2.x/core/src/main/java/org/openfast/template/AbstractTemplateRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicTemplateRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java branches/openfast-2.x/core/src/main/java/org/openfast/template/DynamicTemplateReference.java branches/openfast-2.x/core/src/main/java/org/openfast/template/NullTemplateRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/GroupParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ScalarParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/SequenceParser.java branches/openfast-2.x/core/src/main/java/org/openfast/util/ArrayIterator.java branches/openfast-2.x/core/src/main/java/org/openfast/util/Util.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/CopyIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/BasicTemplateRegistryTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/Array.java branches/openfast-2.x/core/src/test/java/org/openfast/util/ArrayIteratorTest.java branches/openfast-2.x/core/src/test/java/org/openfast/util/UtilTest.java Removed Paths: ------------- branches/openfast-2.x/core/src/main/java/org/openfast/template/type/DateType.java Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Context.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-07-17 13:29:42 UTC (rev 175) @@ -93,8 +93,8 @@ public void newMessage(MessageTemplate template) { currentApplicationType = (template.hasTypeReference()) ? template.getTypeReference() : FastConstants.ANY_TYPE; } - public void setCurrentApplicationType(QName name) { - currentApplicationType = name; + public QName getCurrentApplicationType() { + return currentApplicationType; } public TemplateRegistry getTemplateRegistry() { return templateRegistry; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java 2008-07-17 13:29:42 UTC (rev 175) @@ -1,6 +1,5 @@ package org.openfast.codec; -import org.openfast.template.Scalar; import org.openfast.template.Type; public interface TypeCodecRegistry { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java 2008-07-17 13:29:42 UTC (rev 175) @@ -21,7 +21,6 @@ package org.openfast.codec.operator; import org.lasalletech.exom.EObject; -import org.lasalletech.exom.QName; import org.openfast.Context; import org.openfast.codec.IntegerCodec; import org.openfast.codec.ScalarCodec; @@ -73,7 +72,6 @@ } public int encode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { - QName key = scalar.getKey(); if (!object.isDefined(index)) { if (!scalar.isOptional()) { // TODO - error when value is null and scalar is mandatory Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableAsciiStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableAsciiStringCodec.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableAsciiStringCodec.java 2008-07-17 13:29:42 UTC (rev 175) @@ -5,7 +5,6 @@ import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; -import java.nio.charset.CharsetEncoder; import org.openfast.ByteUtil; import org.openfast.Fast; import org.openfast.Global; @@ -14,7 +13,7 @@ public class NullableAsciiStringCodec extends StopBitEncodedTypeCodec implements StringCodec { private final CharsetDecoder decoder = Charset.forName("US-ASCII").newDecoder(); - private final CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder(); +// private final CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder(); public String decode(byte[] buffer, int offset) { CharBuffer decoded; try { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Dictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Dictionary.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Dictionary.java 2008-07-17 13:29:42 UTC (rev 175) @@ -1,7 +1,6 @@ package org.openfast.dictionary; import org.openfast.template.Scalar; -import org.openfast.template.operator.DictionaryOperator; public interface Dictionary { DictionaryEntry getEntry(Scalar scalar); Modified: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/TemplateDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/TemplateDictionary.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/TemplateDictionary.java 2008-07-17 13:29:42 UTC (rev 175) @@ -4,7 +4,6 @@ import java.util.Map; import org.lasalletech.exom.QName; import org.openfast.template.Scalar; -import org.openfast.template.operator.DictionaryOperator; public class TemplateDictionary implements Dictionary { Map<QName, FastDictionary> dictionaries = new HashMap<QName, FastDictionary>(); Modified: branches/openfast-2.x/core/src/main/java/org/openfast/error/ErrorCode.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/error/ErrorCode.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/error/ErrorCode.java 2008-07-17 13:29:42 UTC (rev 175) @@ -25,7 +25,7 @@ import org.openfast.Message; public class ErrorCode { - private static final Map ALERT_CODES = new HashMap(); + private static final Map<Integer, ErrorCode> ALERT_CODES = new HashMap<Integer, ErrorCode>(); private final int code; private final String shortName; private final String description; @@ -62,7 +62,7 @@ } public static ErrorCode getAlertCode(Message alertMsg) { - return (ErrorCode) ALERT_CODES.get(new Integer(alertMsg.getInt(2))); + return ALERT_CODES.get(new Integer(alertMsg.getInt(2))); } public ErrorType getType() { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/AbstractTemplateRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/AbstractTemplateRegistry.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/AbstractTemplateRegistry.java 2008-07-17 13:29:42 UTC (rev 175) @@ -26,7 +26,7 @@ import org.lasalletech.exom.QName; public abstract class AbstractTemplateRegistry implements TemplateRegistry { - private List listeners = Collections.EMPTY_LIST; + private List<TemplateRegisteredListener> listeners = Collections.emptyList(); public MessageTemplate get(String name) { return get(new QName(name, "")); @@ -54,12 +54,12 @@ protected void notifyTemplateRegistered(MessageTemplate template, int id) { for (int i = 0; i < listeners.size(); i++) - ((TemplateRegisteredListener) listeners.get(i)).templateRegistered(template, id); + listeners.get(i).templateRegistered(template, id); } public void addTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener) { if (this.listeners == Collections.EMPTY_LIST) - this.listeners = new ArrayList(3); + this.listeners = new ArrayList<TemplateRegisteredListener>(3); this.listeners.add(templateRegisteredListener); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicTemplateRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicTemplateRegistry.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicTemplateRegistry.java 2008-07-17 13:29:42 UTC (rev 175) @@ -28,10 +28,10 @@ import org.lasalletech.exom.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<QName, MessageTemplate> nameMap = new HashMap<QName, MessageTemplate>(); + private Map<Integer, MessageTemplate> idMap = new HashMap<Integer, MessageTemplate>(); + private Map<MessageTemplate, Integer> templateMap = new HashMap<MessageTemplate, Integer>(); + private List<MessageTemplate> templates = new ArrayList<MessageTemplate>(); public void register(int id, MessageTemplate template) { define(template); @@ -44,7 +44,7 @@ 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); + MessageTemplate template = nameMap.get(name); templateMap.put(template, tid); idMap.put(tid, template); notifyTemplateRegistered(template, id); @@ -59,18 +59,18 @@ Object template = nameMap.get(name); if (template == null || !templateMap.containsKey(template)) return -1; - return ((Integer) templateMap.get(template)).intValue(); + return templateMap.get(template).intValue(); } public MessageTemplate get(int templateId) { - return (MessageTemplate) idMap.get(new Integer(templateId)); + return idMap.get(new Integer(templateId)); } public MessageTemplate get(QName name) { - return (MessageTemplate) nameMap.get(name); + return nameMap.get(name); } public int getId(MessageTemplate template) { if (!isRegistered(template)) return -1; - return ((Integer) templateMap.get(template)).intValue(); + return templateMap.get(template).intValue(); } public boolean isRegistered(QName name) { return nameMap.containsKey(name); @@ -85,10 +85,10 @@ return nameMap.containsKey(name); } public MessageTemplate[] getTemplates() { - return (MessageTemplate[]) templates.toArray(new MessageTemplate[templateMap.size()]); + return templates.toArray(new MessageTemplate[templateMap.size()]); } public void remove(QName name) { - MessageTemplate template = (MessageTemplate) nameMap.remove(name); + MessageTemplate template = nameMap.remove(name); Object id = templateMap.remove(template); idMap.remove(id); templates.remove(template); @@ -99,7 +99,7 @@ idMap.remove(id); } public void remove(int id) { - MessageTemplate template = (MessageTemplate) idMap.remove(new Integer(id)); + MessageTemplate template = idMap.remove(new Integer(id)); templateMap.remove(template); nameMap.remove(template.getName()); } @@ -111,10 +111,10 @@ register(registry.getId(templates[i]), templates[i]); } } - public Iterator nameIterator() { + public Iterator<QName> nameIterator() { return nameMap.keySet().iterator(); } - public Iterator iterator() { + public Iterator<MessageTemplate> iterator() { return templates.iterator(); } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java 2008-07-17 13:29:42 UTC (rev 175) @@ -25,7 +25,6 @@ public class ComposedScalar extends BasicField { private static final long serialVersionUID = 1L; - private static final Class ScalarValueType = null; private Scalar[] fields; private Type type; @@ -43,10 +42,6 @@ return type.getName(); } - public Class getValueType() { - return ScalarValueType; - } - public boolean usesPresenceMapBit() { return false; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/DynamicTemplateReference.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/DynamicTemplateReference.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/DynamicTemplateReference.java 2008-07-17 13:29:42 UTC (rev 175) @@ -37,20 +37,6 @@ return null; } - /** - * @return Returns null - */ - public Class getValueType() { - return null; - } - - /** - * @return Returns false - */ - public boolean usesPresenceMapBit() { - return false; - } - public boolean equals(Object obj) { return obj != null && obj.getClass().equals(this.getClass()); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/NullTemplateRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/NullTemplateRegistry.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/NullTemplateRegistry.java 2008-07-17 13:29:42 UTC (rev 175) @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.Iterator; +import java.util.List; import org.lasalletech.exom.QName; final class NullTemplateRegistry implements TemplateRegistry { @@ -141,11 +142,13 @@ public void registerAll(TemplateRegistry registry) {} - public Iterator nameIterator() { - return Collections.EMPTY_LIST.iterator(); + public Iterator<QName> nameIterator() { + List<QName> emptyList = Collections.emptyList(); + return emptyList.iterator(); } - public Iterator iterator() { - return null; + public Iterator<MessageTemplate> iterator() { + List<MessageTemplate> emptyList = Collections.emptyList(); + return emptyList.iterator(); } } \ No newline at end of file Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java 2008-07-17 13:29:42 UTC (rev 175) @@ -192,8 +192,4 @@ return false; return true; } - - public Class getValueType() { - return null; - } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/GroupParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/GroupParser.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/GroupParser.java 2008-07-17 13:29:42 UTC (rev 175) @@ -67,7 +67,7 @@ */ protected static Field[] parseFields(Element template, ParsingContext context) { NodeList childNodes = template.getChildNodes(); - List fields = new ArrayList(); + List<Field> fields = new ArrayList<Field>(); for (int i = 0; i < childNodes.getLength(); i++) { Node item = childNodes.item(i); if (isElement(item)) { @@ -80,7 +80,7 @@ fields.add(fieldParser.parse(element, context)); } } - return (Field[]) fields.toArray(new Field[] {}); + return fields.toArray(new Field[] {}); } /** Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ScalarParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ScalarParser.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ScalarParser.java 2008-07-17 13:29:42 UTC (rev 175) @@ -50,7 +50,8 @@ if (operatorElement != null) { operator = context.getOperatorParser(operatorElement).parse(operatorElement, context); } - Type type = (Type) context.getTypeRegistry().get(getTypeName(fieldNode)); + Type type = getType(fieldNode, context); + Scalar scalar = new Scalar(getName(fieldNode, context), type, operator, optional); if (fieldNode.hasAttribute("id")) scalar.setId(fieldNode.getAttribute("id")); @@ -58,6 +59,10 @@ return scalar; } + protected Type getType(Element fieldNode, ParsingContext context) { + return (Type) context.getTypeRegistry().get(getTypeName(fieldNode)); + } + protected QName getName(Element fieldNode, ParsingContext context) { return context.getName(); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/SequenceParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/SequenceParser.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/SequenceParser.java 2008-07-17 13:29:42 UTC (rev 175) @@ -23,7 +23,6 @@ import org.lasalletech.exom.QName; import org.openfast.Global; import org.openfast.template.Field; -import org.openfast.template.Operator; import org.openfast.template.Scalar; import org.openfast.template.Sequence; import org.openfast.template.type.Type; Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/template/type/DateType.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/type/DateType.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/type/DateType.java 2008-07-17 13:29:42 UTC (rev 175) @@ -1,37 +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; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; - -public class DateType extends Type { - private static final long serialVersionUID = 1L; - private DateFormat dateFormatter; - - public DateType(String dateFormat) { - this(new SimpleDateFormat(dateFormat)); - } - public DateType(DateFormat dateFormat) { - super("date"); - this.dateFormatter = dateFormat; - } -} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/util/ArrayIterator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/util/ArrayIterator.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/util/ArrayIterator.java 2008-07-17 13:29:42 UTC (rev 175) @@ -22,11 +22,11 @@ import java.util.Iterator; -public class ArrayIterator implements Iterator { +public class ArrayIterator<T> implements Iterator<T> { private int position; - private final Object[] array; + private final T[] array; - public ArrayIterator(final Object[] array) { + public ArrayIterator(final T[] array) { this.array = array; } @@ -34,7 +34,7 @@ return position < array.length; } - public Object next() { + public T next() { return array[position++]; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/util/Util.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/util/Util.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/main/java/org/openfast/util/Util.java 2008-07-17 13:29:42 UTC (rev 175) @@ -30,13 +30,13 @@ return (value > Integer.MAX_VALUE) || (value < Integer.MIN_VALUE); } - public static String collectionToString(Collection set) { + public static String collectionToString(Collection<?> set) { return collectionToString(set, ","); } - public static String collectionToString(Collection set, String sep) { + public static String collectionToString(Collection<?> set, String sep) { StringBuffer buffer = new StringBuffer(); - Iterator iter = set.iterator(); + Iterator<?> iter = set.iterator(); buffer.append("{"); while (iter.hasNext()) { buffer.append(iter.next()).append(sep); @@ -112,4 +112,8 @@ return 0; } } + + public static <T> ArrayIterator<T> iterator(T[] values) { + return new ArrayIterator<T>(values); + } } Modified: branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/CopyIntegerCodecTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/CopyIntegerCodecTest.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/CopyIntegerCodecTest.java 2008-07-17 13:29:42 UTC (rev 175) @@ -7,9 +7,6 @@ import static org.openfast.codec.operator.FastOperatorTestHarness.UNDEFINED; import org.openfast.Context; import org.openfast.Fast; -import org.openfast.Message; -import org.openfast.codec.type.FastTypeCodecs; -import org.openfast.template.MessageTemplate; import org.openfast.template.Scalar; import org.openfast.template.operator.CopyOperator; import org.openfast.template.operator.DictionaryOperator; Modified: branches/openfast-2.x/core/src/test/java/org/openfast/template/BasicTemplateRegistryTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/template/BasicTemplateRegistryTest.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/test/java/org/openfast/template/BasicTemplateRegistryTest.java 2008-07-17 13:29:42 UTC (rev 175) @@ -58,7 +58,7 @@ } private void assertContains(MessageTemplate mt, TemplateRegistry registry) { - List templates = Arrays.asList(registry.getTemplates()); + List<MessageTemplate> templates = Arrays.asList(registry.getTemplates()); assertTrue(templates.contains(mt)); } Modified: branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/Array.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/Array.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/Array.java 2008-07-17 13:29:42 UTC (rev 175) @@ -14,10 +14,6 @@ return null; } - public Class getValueType() { - return null; - } - public boolean usesPresenceMapBit() { return false; } Modified: branches/openfast-2.x/core/src/test/java/org/openfast/util/ArrayIteratorTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/util/ArrayIteratorTest.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/test/java/org/openfast/util/ArrayIteratorTest.java 2008-07-17 13:29:42 UTC (rev 175) @@ -1,28 +1,25 @@ package org.openfast.util; +import static org.openfast.util.Util.iterator; import junit.framework.TestCase; public class ArrayIteratorTest extends TestCase { + public void testNext() { + String[] values = new String[] { "a", "b", "c" }; + ArrayIterator<String> iter = iterator(values); + assertTrue(iter.hasNext()); + assertEquals(values[0], iter.next()); + assertTrue(iter.hasNext()); + assertEquals(values[1], iter.next()); + assertTrue(iter.hasNext()); + assertEquals(values[2], iter.next()); + assertFalse(iter.hasNext()); + } - public void testNext() { - String[] values = new String[] { "a", "b", "c" }; - ArrayIterator iter = new ArrayIterator(values); - assertTrue(iter.hasNext()); - assertEquals(values[0], iter.next()); - assertTrue(iter.hasNext()); - assertEquals(values[1], iter.next()); - assertTrue(iter.hasNext()); - assertEquals(values[2], iter.next()); - assertFalse(iter.hasNext()); - - } - - public void testRemove() { - try { - new ArrayIterator(new String[] { "a" }).remove(); - fail(); - } catch (UnsupportedOperationException e) { - - } - } + public void testRemove() { + try { + iterator(new String[] { "a" }).remove(); + fail(); + } catch (UnsupportedOperationException e) {} + } } Modified: branches/openfast-2.x/core/src/test/java/org/openfast/util/UtilTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/util/UtilTest.java 2008-07-17 12:45:08 UTC (rev 174) +++ branches/openfast-2.x/core/src/test/java/org/openfast/util/UtilTest.java 2008-07-17 13:29:42 UTC (rev 175) @@ -22,7 +22,6 @@ import java.nio.ByteBuffer; import java.util.Calendar; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import junit.framework.TestCase; @@ -30,7 +29,7 @@ public class UtilTest extends TestCase { public void testCollectionToString() { - Map map = new LinkedHashMap(); + Map<String, String> map = new LinkedHashMap<String, String>(); map.put("abc", "123"); map.put("def", "456"); assertEquals("{abc,def}", Util.collectionToString(map.keySet())); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-07-17 12:47:57
|
Revision: 174 http://openfast.svn.sourceforge.net/openfast/?rev=174&view=rev Author: jacob_northey Date: 2008-07-17 12:45:08 +0000 (Thu, 17 Jul 2008) Log Message: ----------- Refactored ScalarCodecs to include dictionary entries locally instead of looking them up each time. Modified Paths: -------------- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicTypeCodecRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/CodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastEncoder.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/AsciiStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/FastTypeCodecs.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/StopBitEncodedTypeCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/IntegerEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/FastImplementation.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Operator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/ConstantOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/CopyOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DefaultOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DeltaOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DictionaryOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/IncrementOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/TailOperator.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/CopyIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/DeltaAsciiCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/DeltaIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastOperatorTestHarness.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastStringOperatorTestHarness.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/IncrementIntegerCodecTest.java Added Paths: ----------- branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableAsciiStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/AbstractDictionaryEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/BasicDictionaryRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/BasicDictionaryTypeRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Dictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryType.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryTypeRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalDictionaryType.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/StringEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/TemplateDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/TemplateDictionaryType.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/CopyOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/DeltaOperatorCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast_1_1Implementation.java branches/openfast-2.x/core/src/main/java/org/openfast/template/AbstractOperator.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/CopyStringCodecTest.java Removed Paths: ------------- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Entry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/NullEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast1_1Implementation.java Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Context.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-07-17 12:45:08 UTC (rev 174) @@ -30,7 +30,6 @@ import org.openfast.error.ErrorHandler; import org.openfast.error.FastConstants; import org.openfast.template.BasicTemplateRegistry; -import org.openfast.template.Group; import org.openfast.template.MessageTemplate; import org.openfast.template.TemplateRegisteredListener; import org.openfast.template.TemplateRegistry; @@ -80,21 +79,6 @@ public void setLastTemplateId(int templateId) { lastTemplateId = templateId; } - public int lookupInt(String dictionary, Group group, QName key) { - if (group.hasTypeReference()) - currentApplicationType = group.getTypeReference(); - return getDictionary(dictionary).lookupInt(null, key, currentApplicationType); - } - public FastDictionary getDictionary(String dictionary) { - if (!dictionaries.containsKey(dictionary)) - dictionaries.put(dictionary, new GlobalFastDictionary()); - return (FastDictionary) dictionaries.get(dictionary); - } - public void store(String dictionary, Group group, QName key, int value) { - if (group.hasTypeReference()) - currentApplicationType = group.getTypeReference(); - getDictionary(dictionary).store(null, currentApplicationType, key, value); - } public void reset() { for (FastDictionary dict : dictionaries.values()) { dict.reset(); @@ -130,7 +114,4 @@ public void discardTemporaryBuffer(byte[] buffer) { tempBuffer = buffer; } - public QName getCurrentApplicationType() { - return null; - } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java 2008-07-17 12:45:08 UTC (rev 174) @@ -3,7 +3,10 @@ public class Fast { public static final byte STOP_BIT = (byte) 0x80; public static final byte VALUE_BITS = (byte) 0x7f; - public static final String GLOBAL = "global"; public static final byte NULL = STOP_BIT; + public static final String ZERO_TERMINATOR = "\u0000"; + + public static final String GLOBAL = "global"; + public static final String TEMPLATE = "template"; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java 2008-07-17 12:45:08 UTC (rev 174) @@ -1,20 +1,27 @@ package org.openfast.codec; +import java.util.HashMap; +import java.util.Map; +import org.openfast.dictionary.DictionaryRegistry; +import org.openfast.fast.impl.FastImplementation; import org.openfast.template.MessageTemplate; import org.openfast.template.Scalar; -import org.openfast.template.Type; -import org.openfast.template.operator.DictionaryOperator; -import org.openfast.codec.operator.IncrementIntegerCodec; public class BasicCodecFactory implements CodecFactory { - public MessageCodec createCodec(int id, MessageTemplate template, TypeCodecRegistry typeCodecRegistry) { - return new BasicMessageCodec(id, template, typeCodecRegistry, this); + private Map<String, ScalarCodecFactory> codecFactories = new HashMap<String, ScalarCodecFactory>(); + + public MessageCodec createMessageCodec(int id, MessageTemplate template, FastImplementation implementation, DictionaryRegistry dictionaryRegistry) { + return new BasicMessageCodec(id, template, implementation, dictionaryRegistry, this); } - public ScalarCodec createCodec(Scalar scalar, TypeCodecRegistry typeCodecRegistry) { - if ("increment".equals(scalar.getOperator().getName())) { - return new IncrementIntegerCodec((DictionaryOperator)scalar.getOperator(), typeCodecRegistry.getIntegerCodec((Type) scalar.getType())); + public ScalarCodec createScalarCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, DictionaryRegistry dictionaryRegistry) { + if (!codecFactories.containsKey(scalar.getOperator().getName())) { + throw new IllegalArgumentException("Encountered unknown operator " + scalar.getOperator() + " in scalar " + scalar.getQName()); } - return null; + return codecFactories.get(scalar.getOperator().getName()).createCodec(template, scalar, implementation, dictionaryRegistry); } + + public void register(String operator, ScalarCodecFactory scalarCodecFactory) { + codecFactories.put(operator, scalarCodecFactory); + } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java 2008-07-17 12:45:08 UTC (rev 174) @@ -3,7 +3,9 @@ import org.lasalletech.exom.Field; import org.openfast.Context; import org.openfast.Message; +import org.openfast.dictionary.DictionaryRegistry; import org.openfast.fast.FastTypes; +import org.openfast.fast.impl.FastImplementation; import org.openfast.template.MessageTemplate; import org.openfast.template.Scalar; import org.openfast.util.BitVectorBuilder; @@ -11,22 +13,24 @@ public class BasicMessageCodec implements MessageCodec { private final int templateId; private final IntegerCodec uintCodec; + @SuppressWarnings("unchecked") private final FieldCodec[] fieldCodecs; - public BasicMessageCodec(int id, MessageTemplate template, TypeCodecRegistry codecRegistry, CodecFactory codecFactory) { + public BasicMessageCodec(int id, MessageTemplate template, FastImplementation implementation, DictionaryRegistry dictionaryRegistry, CodecFactory codecFactory) { this.templateId = id; - this.uintCodec = codecRegistry.getIntegerCodec(FastTypes.U32); + this.uintCodec = implementation.getTypeCodecRegistry().getIntegerCodec(FastTypes.U32); this.fieldCodecs = new FieldCodec[template.getFieldCount()]; int index = 0; for (Field field : template.getFields()) { if (field instanceof Scalar) { Scalar scalar = (Scalar) field; - fieldCodecs[index] = codecFactory.createCodec(scalar, codecRegistry); + fieldCodecs[index] = codecFactory.createScalarCodec(template, scalar, implementation, dictionaryRegistry); index++; } } } + @SuppressWarnings("unchecked") public int encode(byte[] buffer, int offset, Message message, Context context) { byte[] temp = context.getTemporaryBuffer(); int index = 0; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicTypeCodecRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicTypeCodecRegistry.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicTypeCodecRegistry.java 2008-07-17 12:45:08 UTC (rev 174) @@ -3,15 +3,36 @@ import java.util.HashMap; import java.util.Map; import org.openfast.template.Type; +import org.openfast.util.Key; public class BasicTypeCodecRegistry implements TypeCodecRegistry { - private Map<Type, TypeCodec> codecs = new HashMap<Type, TypeCodec>(); + private Map<Key, TypeCodec> codecs = new HashMap<Key, TypeCodec>(); - public IntegerCodec getIntegerCodec(Type intType) { - return (IntegerCodec) codecs.get(intType); + public IntegerCodec getIntegerCodec(Type type) { + return (IntegerCodec) getCodec(type, false); } + public StringCodec getStringCodec(Type type) { + return (StringCodec) getCodec(type, false); + } + + private TypeCodec getCodec(Type type, boolean nullable) { + return codecs.get(new Key(type, new Boolean(nullable))); + } + + public void register(Type type, boolean nullable, TypeCodec codec) { + codecs.put(new Key(type, new Boolean(nullable)), codec); + } + public void register(Type type, TypeCodec codec) { - codecs.put(type, codec); + register(type, false, codec); } + + public IntegerCodec getIntegerCodec(Type type, boolean nullable) { + return (IntegerCodec) getCodec(type, nullable); + } + + public StringCodec getStringCodec(Type type, boolean nullable) { + return (StringCodec) getCodec(type, nullable); + } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/CodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/CodecFactory.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/CodecFactory.java 2008-07-17 12:45:08 UTC (rev 174) @@ -1,10 +1,11 @@ package org.openfast.codec; +import org.openfast.dictionary.DictionaryRegistry; +import org.openfast.fast.impl.FastImplementation; import org.openfast.template.MessageTemplate; import org.openfast.template.Scalar; public interface CodecFactory { - MessageCodec createCodec(int id, MessageTemplate template, TypeCodecRegistry typeCodecRegistry); - - ScalarCodec createCodec(Scalar scalar, TypeCodecRegistry typeCodecRegistry); + MessageCodec createMessageCodec(int id, MessageTemplate template, FastImplementation implementation, DictionaryRegistry dictionaryRegistry); + ScalarCodec createScalarCodec(MessageTemplate template, Scalar scalar, FastImplementation fastImplementation, DictionaryRegistry dictionaryRegistry); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastEncoder.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastEncoder.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastEncoder.java 2008-07-17 12:45:08 UTC (rev 174) @@ -2,32 +2,40 @@ import org.openfast.Context; import org.openfast.Message; +import org.openfast.dictionary.BasicDictionaryRegistry; +import org.openfast.dictionary.DictionaryRegistry; import org.openfast.fast.impl.FastImplementation; import org.openfast.template.TemplateRegistry; -public class FastEncoder { +public class FastEncoder implements Coder { private final Context context = new Context(); private CodecFactory codecFactory = FastImplementation.getDefaultVersion().getCodecFactory(); private MessageCodecRegistry codecRegistry = new BasicCodecRegistry(); - private TypeCodecRegistry typeCodecRegistry = FastImplementation.getDefaultVersion().getTypeCodecRegistry(); + private FastImplementation implementation = FastImplementation.getDefaultVersion(); + private DictionaryRegistry dictionaryRegistry = new BasicDictionaryRegistry(FastImplementation.getDefaultVersion().getDictionaryTypeRegistry()); public FastEncoder(TemplateRegistry templateRegistry) { context.setTemplateRegistry(templateRegistry); } public void setFastImplementation(FastImplementation implementation) { - codecFactory = implementation.getCodecFactory(); + this.implementation = implementation; + dictionaryRegistry = new BasicDictionaryRegistry(implementation.getDictionaryTypeRegistry()); } public int encode(byte[] buffer, int offset, Message message) { MessageCodec encoder = getEncoder(message); return encoder.encode(buffer, offset, message, context); } + + public void reset() { + dictionaryRegistry.reset(); + } private MessageCodec getEncoder(Message message) { int id = context.getTemplateRegistry().getId(message.getTemplate()); if (!codecRegistry.isRegistered(id)) { - codecRegistry.register(id, codecFactory.createCodec(id, message.getTemplate(), typeCodecRegistry)); + codecRegistry.register(id, codecFactory.createMessageCodec(id, message.getTemplate(), implementation, dictionaryRegistry)); } return codecRegistry.get(id); } Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementOperatorCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementOperatorCodecFactory.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementOperatorCodecFactory.java 2008-07-17 12:45:08 UTC (rev 174) @@ -0,0 +1,19 @@ +package org.openfast.codec; + +import org.openfast.codec.operator.IncrementIntegerCodec; +import org.openfast.dictionary.DictionaryEntry; +import org.openfast.dictionary.DictionaryRegistry; +import org.openfast.fast.impl.FastImplementation; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; +import org.openfast.template.operator.DictionaryOperator; + +public class IncrementOperatorCodecFactory implements ScalarCodecFactory { + public ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, + DictionaryRegistry dictionaryRegistry) { + IntegerCodec integerCodec = implementation.getTypeCodecRegistry().getIntegerCodec(scalar.getType(), scalar.isOptional()); + DictionaryOperator operator = (DictionaryOperator) scalar.getOperator(); + DictionaryEntry entry = dictionaryRegistry.get(((DictionaryOperator)scalar.getOperator()).getDictionary()).getEntry(scalar); + return new IncrementIntegerCodec(entry, operator, integerCodec); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodecFactory.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodecFactory.java 2008-07-17 12:45:08 UTC (rev 174) @@ -0,0 +1,10 @@ +package org.openfast.codec; + +import org.openfast.dictionary.DictionaryRegistry; +import org.openfast.fast.impl.FastImplementation; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; + +public interface ScalarCodecFactory { + ScalarCodec createCodec(MessageTemplate template, Scalar scalar, FastImplementation implementation, DictionaryRegistry dictionaryRegistry); +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java 2008-07-17 12:45:08 UTC (rev 174) @@ -1,9 +1,17 @@ package org.openfast.codec; +import org.openfast.template.Scalar; import org.openfast.template.Type; public interface TypeCodecRegistry { - IntegerCodec getIntegerCodec(Type intType); + IntegerCodec getIntegerCodec(Type type); + IntegerCodec getIntegerCodec(Type type, boolean nullable); + StringCodec getStringCodec(Type type); + StringCodec getStringCodec(Type type, boolean nullable); + + void register(Type type, TypeCodec codec); + void register(Type type, boolean nullable, TypeCodec codec); + } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java 2008-07-17 12:45:08 UTC (rev 174) @@ -5,14 +5,14 @@ import org.openfast.Fast; import org.openfast.codec.IntegerCodec; import org.openfast.codec.ScalarCodec; -import org.openfast.dictionary.FastDictionary; +import org.openfast.dictionary.DictionaryEntry; import org.openfast.template.Scalar; import org.openfast.template.operator.DictionaryOperator; public class CopyIntegerCodec extends DictionaryOperatorIntegerCodec implements ScalarCodec { - public CopyIntegerCodec(DictionaryOperator operator, IntegerCodec integerCodec) { - super(operator, integerCodec); + public CopyIntegerCodec(DictionaryEntry entry, DictionaryOperator operator, IntegerCodec integerCodec) { + super(entry, operator, integerCodec); } public int getLength(byte[] buffer, int offset) { @@ -20,23 +20,21 @@ } public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { - FastDictionary dictionary = context.getDictionary(operator.getDictionary()); if (integerCodec.isNull(buffer, offset)) { - dictionary.storeNull(object.getEntity(), operator.getKey(), context.getCurrentApplicationType()); + dictionaryEntry.setNull(); return offset + 1; } int value = integerCodec.decode(buffer, offset); object.set(index, value); - dictionary.store(object.getEntity(), operator.getKey(), context.getCurrentApplicationType(), value); + dictionaryEntry.set(value); return integerCodec.getLength(buffer, offset) + offset; } public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { - FastDictionary dictionary = context.getDictionary(operator.getDictionary()); - boolean dictionaryUndefined = !dictionary.isDefined(object, operator.getKey(), context.getCurrentApplicationType()); - boolean dictionaryNull = dictionary.isNull(object, operator.getKey(), context.getCurrentApplicationType()); + boolean dictionaryUndefined = !dictionaryEntry.isDefined(); + boolean dictionaryNull = dictionaryEntry.isNull(); if (!object.isDefined(index)) { - dictionary.storeNull(object.getEntity(), operator.getKey(), context.getCurrentApplicationType()); + dictionaryEntry.setNull(); if ((dictionaryUndefined && !operator.hasDefaultValue()) || dictionaryNull) { return offset; } else { @@ -47,26 +45,25 @@ int value = object.getInt(index); if (dictionaryUndefined) { if ((operator.hasDefaultValue() && initialValue == value)) { - dictionary.store(object.getEntity(), operator.getKey(), context.getCurrentApplicationType(), value); + dictionaryEntry.set(value); return offset; } } else if (!dictionaryNull) { - if (dictionary.lookupInt(object.getEntity(), operator.getKey(), context.getCurrentApplicationType()) == value) { - dictionary.store(object.getEntity(), operator.getKey(), context.getCurrentApplicationType(), value); + if (dictionaryEntry.getInt() == value) { + dictionaryEntry.set(value); return offset; } } int newOffset = integerCodec.encode(buffer, offset, value); - dictionary.store(object.getEntity(), operator.getKey(), context.getCurrentApplicationType(), value); + dictionaryEntry.set(value); return newOffset; } public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { - FastDictionary dictionary = context.getDictionary(operator.getDictionary()); - if (dictionary.isNull(object, operator.getKey(), context.getCurrentApplicationType())) + if (dictionaryEntry.isNull()) return; - if (dictionary.isDefined(object, operator.getKey(), context.getCurrentApplicationType())) - object.set(index, dictionary.lookupInt(object.getEntity(), operator.getKey(), null)); + if (dictionaryEntry.isDefined()) + object.set(index, dictionaryEntry.getInt()); else if (operator.hasDefaultValue()) object.set(index, initialValue); } Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyStringCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyStringCodec.java 2008-07-17 12:45:08 UTC (rev 174) @@ -0,0 +1,70 @@ +package org.openfast.codec.operator; + +import org.lasalletech.exom.EObject; +import org.openfast.Context; +import org.openfast.Fast; +import org.openfast.codec.ScalarCodec; +import org.openfast.codec.StringCodec; +import org.openfast.dictionary.DictionaryEntry; +import org.openfast.template.Scalar; +import org.openfast.template.operator.DictionaryOperator; + +public class CopyStringCodec extends DictionaryOperatorStringCodec implements ScalarCodec { + + public CopyStringCodec(DictionaryEntry dictionaryEntry, DictionaryOperator operator, StringCodec stringCodec) { + super(dictionaryEntry, operator, stringCodec); + } + + public int getLength(byte[] buffer, int offset) { + throw new UnsupportedOperationException(); + } + + public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + if (stringCodec.isNull(buffer, offset)) { + dictionaryEntry.setNull(); + return offset + 1; + } + String value = stringCodec.decode(buffer, offset); + object.set(index, value); + dictionaryEntry.set(value); + return stringCodec.getLength(buffer, offset) + offset; + } + + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + boolean dictionaryUndefined = !dictionaryEntry.isDefined(); + boolean dictionaryNull = dictionaryEntry.isNull(); + if (!object.isDefined(index)) { + dictionaryEntry.setNull(); + if ((dictionaryUndefined && !operator.hasDefaultValue()) || dictionaryNull) { + return offset; + } else { + buffer[offset] = Fast.NULL; + return offset+1; + } + } + String value = object.getString(index); + if (dictionaryUndefined) { + if ((operator.hasDefaultValue() && operator.getDefaultValue().equals(value))) { + dictionaryEntry.set(value); + return offset; + } + } else if (!dictionaryNull) { + if (value.equals(dictionaryEntry.getString())) { + dictionaryEntry.set(value); + return offset; + } + } + int newOffset = stringCodec.encode(buffer, offset, value); + dictionaryEntry.set(value); + return newOffset; + } + + public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { + if (dictionaryEntry.isNull()) + return; + if (dictionaryEntry.isDefined()) + object.set(index, dictionaryEntry.getString()); + else if (operator.hasDefaultValue()) + object.set(index, operator.getDefaultValue()); + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java 2008-07-17 12:45:08 UTC (rev 174) @@ -6,7 +6,7 @@ import org.openfast.codec.IntegerCodec; import org.openfast.codec.ScalarCodec; import org.openfast.codec.StringCodec; -import org.openfast.dictionary.FastDictionary; +import org.openfast.dictionary.DictionaryEntry; import org.openfast.error.FastConstants; import org.openfast.template.Scalar; import org.openfast.template.operator.DictionaryOperator; @@ -14,8 +14,9 @@ public class DeltaAsciiCodec extends DictionaryOperatorStringCodec implements ScalarCodec { private IntegerCodec integerCodec; - public DeltaAsciiCodec(DictionaryOperator operator, IntegerCodec integerCodec, StringCodec stringCodec) { - super(operator, stringCodec); + public DeltaAsciiCodec(DictionaryEntry dictionaryEntry, DictionaryOperator operator, IntegerCodec integerCodec, StringCodec stringCodec) { + super(dictionaryEntry, operator, stringCodec); + if (integerCodec == null) throw new NullPointerException(); this.integerCodec = integerCodec; } @@ -31,23 +32,21 @@ offset = integerCodec.getLength(buffer, offset); String delta = stringCodec.decode(buffer, offset); String value = new StringDelta(subtractionLength, delta).applyTo(getPreviousValue(object, field, context)); - FastDictionary dictionary = context.getDictionary(operator.getDictionary()); - dictionary.store(object.getEntity(), operator.getKey(), context.getCurrentApplicationType(), value); + dictionaryEntry.set(value); object.set(index, value); return stringCodec.getLength(buffer, offset) + offset; } private String getPreviousValue(EObject object, Scalar field, Context context) { - FastDictionary dictionary = context.getDictionary(operator.getDictionary()); - if (!dictionary.isDefined(object, operator.getKey(), context.getCurrentApplicationType())) { + if (!dictionaryEntry.isDefined()) { if (operator.hasDefaultValue()) return operator.getDefaultValue(); return ""; - } else if (dictionary.isNull(object, operator.getKey(), context.getCurrentApplicationType())) { + } else if (dictionaryEntry.isNull()) { context.getErrorHandler().error(FastConstants.D6_MNDTRY_FIELD_NOT_PRESENT, "The field " + field + " must have a priorValue defined."); return ""; } - return dictionary.lookupString(object.getEntity(), operator.getKey(), context.getCurrentApplicationType()); + return dictionaryEntry.getString(); } public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) {} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java 2008-07-17 12:45:08 UTC (rev 174) @@ -5,15 +5,15 @@ import org.openfast.Context; import org.openfast.codec.IntegerCodec; import org.openfast.codec.ScalarCodec; -import org.openfast.dictionary.FastDictionary; +import org.openfast.dictionary.DictionaryEntry; import org.openfast.error.FastConstants; import org.openfast.template.Scalar; import org.openfast.template.operator.DictionaryOperator; public class DeltaIntegerCodec extends DictionaryOperatorIntegerCodec implements ScalarCodec { - public DeltaIntegerCodec(DictionaryOperator operator, IntegerCodec integerDeltaCodec) { - super(operator, integerDeltaCodec); + public DeltaIntegerCodec(DictionaryEntry entry, DictionaryOperator operator, IntegerCodec integerDeltaCodec) { + super(entry, operator, integerDeltaCodec); } public int getLength(byte[] buffer, int offset) { @@ -28,19 +28,18 @@ int previousValue = getPreviousValue(object, context, field); int newValue = delta + previousValue; object.set(index, newValue); - context.getDictionary(operator.getDictionary()).store(object.getEntity(), operator.getKey(), context.getCurrentApplicationType(), newValue); + dictionaryEntry.set(newValue); return integerCodec.getLength(buffer, offset) + offset; } private int getPreviousValue(EObject object, Context context, Scalar field) { - FastDictionary dictionary = context.getDictionary(operator.getDictionary()); - if (!dictionary.isDefined(object, operator.getKey(), context.getCurrentApplicationType())) { + if (!dictionaryEntry.isDefined()) { return initialValue; - } else if (dictionary.isNull(object, operator.getKey(), context.getCurrentApplicationType())) { + } else if (dictionaryEntry.isNull()) { context.getErrorHandler().error(FastConstants.D6_MNDTRY_FIELD_NOT_PRESENT, "The field " + field + " must have a priorValue defined."); return 0; } - return dictionary.lookupInt(object.getEntity(), operator.getKey(), context.getCurrentApplicationType()); + return dictionaryEntry.getInt(); } public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) {} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorIntegerCodec.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorIntegerCodec.java 2008-07-17 12:45:08 UTC (rev 174) @@ -2,14 +2,18 @@ import org.openfast.codec.IntegerCodec; import org.openfast.codec.ScalarCodec; +import org.openfast.dictionary.DictionaryEntry; import org.openfast.template.operator.DictionaryOperator; public abstract class DictionaryOperatorIntegerCodec implements ScalarCodec { protected final IntegerCodec integerCodec; protected final DictionaryOperator operator; protected final int initialValue; + protected final DictionaryEntry dictionaryEntry; - public DictionaryOperatorIntegerCodec(DictionaryOperator operator, IntegerCodec integerDeltaCodec) { + public DictionaryOperatorIntegerCodec(DictionaryEntry entry, DictionaryOperator operator, IntegerCodec integerDeltaCodec) { + if (entry == null || operator == null || integerDeltaCodec == null) throw new NullPointerException(); + this.dictionaryEntry = entry; this.integerCodec = integerDeltaCodec; this.operator = operator; this.initialValue = operator.hasDefaultValue() ? Integer.parseInt(operator.getDefaultValue()) : 0; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorStringCodec.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorStringCodec.java 2008-07-17 12:45:08 UTC (rev 174) @@ -2,13 +2,17 @@ import org.openfast.codec.ScalarCodec; import org.openfast.codec.StringCodec; +import org.openfast.dictionary.DictionaryEntry; import org.openfast.template.operator.DictionaryOperator; public abstract class DictionaryOperatorStringCodec implements ScalarCodec { protected final DictionaryOperator operator; protected final StringCodec stringCodec; + protected final DictionaryEntry dictionaryEntry; - protected DictionaryOperatorStringCodec(DictionaryOperator operator, StringCodec stringCodec) { + protected DictionaryOperatorStringCodec(DictionaryEntry dictionaryEntry, DictionaryOperator operator, StringCodec stringCodec) { + if (dictionaryEntry == null || operator == null || stringCodec == null) throw new NullPointerException(); + this.dictionaryEntry = dictionaryEntry; this.operator = operator; this.stringCodec = stringCodec; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java 2008-07-17 12:45:08 UTC (rev 174) @@ -25,52 +25,46 @@ import org.openfast.Context; import org.openfast.codec.IntegerCodec; import org.openfast.codec.ScalarCodec; -import org.openfast.dictionary.FastDictionary; +import org.openfast.dictionary.DictionaryEntry; import org.openfast.error.FastConstants; import org.openfast.template.Scalar; import org.openfast.template.operator.DictionaryOperator; -public final class IncrementIntegerCodec implements ScalarCodec { +public final class IncrementIntegerCodec extends DictionaryOperatorIntegerCodec implements ScalarCodec { private static final long serialVersionUID = 1L; - private final IntegerCodec integerCodec; - private final DictionaryOperator operator; - private final int defaultValue; - public IncrementIntegerCodec(DictionaryOperator operator, IntegerCodec integerCodec) { - this.integerCodec = integerCodec; - this.operator = operator; - this.defaultValue = operator.hasDefaultValue() ? Integer.parseInt(operator.getDefaultValue()) : 0; + public IncrementIntegerCodec(DictionaryEntry dictionaryEntry, DictionaryOperator operator, IntegerCodec integerCodec) { + super(dictionaryEntry, operator, integerCodec); } public int decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { int length = integerCodec.getLength(buffer, offset); int value = integerCodec.decode(buffer, offset); - context.getDictionary(operator.getDictionary()).store(object.getEntity(), scalar.getKey(), null, value); + dictionaryEntry.set(value); object.set(index, value); return offset + length; } public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { - FastDictionary dictionary = context.getDictionary(operator.getDictionary()); - if (dictionary.isNull(object, scalar.getKey(), null)) { + if (dictionaryEntry.isNull()) { // leave object value set to null - dictionary.storeNull(object.getEntity(), scalar.getKey(), null); - } else if (!dictionary.isDefined(object, scalar.getKey(), null)) { + dictionaryEntry.setNull(); + } else if (!dictionaryEntry.isDefined()) { if (operator.hasDefaultValue()) { - object.set(index, defaultValue); - dictionary.store(object.getEntity(), scalar.getKey(), null, defaultValue); + object.set(index, initialValue); + dictionaryEntry.set(initialValue); } else { if (!scalar.isOptional()) { throw new IllegalStateException("Field with operator increment must send a value if no previous value existed."); } else { // leave object value set to null - dictionary.storeNull(object.getEntity(), scalar.getKey(), null); + dictionaryEntry.setNull(); } } } else { - int previousValue = dictionary.lookupInt(object.getEntity(), scalar.getKey(), null); + int previousValue = dictionaryEntry.getInt(); object.set(index, previousValue + 1); - dictionary.store(object.getEntity(), scalar.getKey(), null, previousValue + 1); + dictionaryEntry.set(previousValue + 1); } } @@ -79,43 +73,42 @@ } public int encode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { - FastDictionary dictionary = context.getDictionary(operator.getDictionary()); QName key = scalar.getKey(); if (!object.isDefined(index)) { if (!scalar.isOptional()) { // TODO - error when value is null and scalar is mandatory } - if (dictionary.isNull(object, key, null)) + if (dictionaryEntry.isNull()) return offset; else { - return encodeNull(buffer, offset, dictionary, key); + return encodeNull(buffer, offset, context, scalar); } } int value = object.getInt(index); - if (dictionary.isNull(object, key, null)) { - dictionary.store(null, key, null, value); + if (dictionaryEntry.isNull()) { + dictionaryEntry.set(value); return integerCodec.encode(buffer, offset, value); } - if (!dictionary.isDefined(object, key, null)) { + if (!dictionaryEntry.isDefined()) { if (!operator.hasDefaultValue()) { - dictionary.store(null, key, null, value); + dictionaryEntry.set(value); return integerCodec.encode(buffer, offset, value); - } else if (operator.hasDefaultValue() && value == defaultValue) { + } else if (operator.hasDefaultValue() && value == initialValue) { return offset; } else { return integerCodec.encode(buffer, offset, value); } } - int previousValue = dictionary.lookupInt(null, key, null); + int previousValue = dictionaryEntry.getInt(); if (value == previousValue + 1) { return offset; } return integerCodec.encode(buffer, offset, value); } - private int encodeNull(byte[] buffer, int offset, FastDictionary dictionary, QName key) { + private int encodeNull(byte[] buffer, int offset, Context context, Scalar scalar) { buffer[offset] = FastConstants.NULL_BYTE; - dictionary.storeNull(null, key, null); + dictionaryEntry.setNull(); return offset + 1; } } \ No newline at end of file Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneStringCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneStringCodec.java 2008-07-17 12:45:08 UTC (rev 174) @@ -0,0 +1,36 @@ +package org.openfast.codec.operator; + +import org.lasalletech.exom.EObject; +import org.openfast.Context; +import org.openfast.Fast; +import org.openfast.codec.ScalarCodec; +import org.openfast.codec.StringCodec; +import org.openfast.template.Scalar; + +public class NoneStringCodec implements ScalarCodec { + private StringCodec stringCodec; + + public NoneStringCodec(StringCodec stringCodec) { + this.stringCodec = stringCodec; + } + public int getLength(byte[] buffer, int offset) { + return 0; + } + + public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + if (!stringCodec.isNull(buffer, offset)) { + object.set(index, stringCodec.decode(buffer, offset)); + } + return stringCodec.getLength(buffer, offset); + } + + public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) {} + + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + if (!object.isDefined(index)) { + buffer[offset] = Fast.NULL; + return offset + 1; + } + return stringCodec.encode(buffer, offset, object.getString(index)); + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/AsciiStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/AsciiStringCodec.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/AsciiStringCodec.java 2008-07-17 12:45:08 UTC (rev 174) @@ -19,14 +19,14 @@ CharBuffer decoded; try { int length = getLength(buffer, offset); - buffer[length + offset - 1] &= Fast.VALUE_BITS; // remove stop bit - if (buffer[offset] == 0) { + if ((buffer[offset] & Fast.VALUE_BITS) == 0) { if (!ByteUtil.isEmpty(buffer, offset, length)) Global.handleError(FastConstants.R9_STRING_OVERLONG, null); - if (length > 1 && buffer[offset+1] == 0) + if (length > 1 && (buffer[offset+1] & Fast.VALUE_BITS) == 0) return Fast.ZERO_TERMINATOR; return ""; } + buffer[length + offset - 1] &= Fast.VALUE_BITS; // remove stop bit decoded = decoder.decode(ByteBuffer.wrap(buffer, offset, length)); buffer[length + offset - 1] |= Fast.STOP_BIT; // replace stop bit to prevent side effects return decoded.toString(); Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/FastTypeCodecs.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/FastTypeCodecs.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/FastTypeCodecs.java 2008-07-17 12:45:08 UTC (rev 174) @@ -9,4 +9,5 @@ public static final IntegerCodec NULLABLE_UNSIGNED_INTEGER = new NullableUnsignedIntegerCodec(); public static final IntegerCodec NULLABLE_SIGNED_INTEGER = new NullableSignedIntegerCodec(); public static final StringCodec ASCII_STRING = new AsciiStringCodec(); + public static final StringCodec NULLABLE_ASCII_STRING = new NullableAsciiStringCodec(); } Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableAsciiStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableAsciiStringCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableAsciiStringCodec.java 2008-07-17 12:45:08 UTC (rev 174) @@ -0,0 +1,45 @@ +package org.openfast.codec.type; + +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.charset.CharacterCodingException; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CharsetEncoder; +import org.openfast.ByteUtil; +import org.openfast.Fast; +import org.openfast.Global; +import org.openfast.codec.StringCodec; +import org.openfast.error.FastConstants; + +public class NullableAsciiStringCodec extends StopBitEncodedTypeCodec implements StringCodec { + private final CharsetDecoder decoder = Charset.forName("US-ASCII").newDecoder(); + private final CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder(); + public String decode(byte[] buffer, int offset) { + CharBuffer decoded; + try { + int length = getLength(buffer, offset); + if ((buffer[offset] & Fast.VALUE_BITS) == 0) { + if (!ByteUtil.isEmpty(buffer, offset, length)) + Global.handleError(FastConstants.R9_STRING_OVERLONG, null); + if (length > 1 && (buffer[offset+1] & Fast.VALUE_BITS) == 0) + return Fast.ZERO_TERMINATOR; + return ""; + } + buffer[length + offset - 1] &= Fast.VALUE_BITS; // remove stop bit + decoded = decoder.decode(ByteBuffer.wrap(buffer, offset, length)); + buffer[length + offset - 1] |= Fast.STOP_BIT; // replace stop bit to prevent side effects + return decoded.toString(); + } catch (CharacterCodingException e) { + throw new RuntimeException(e); + } + } + + public int encode(byte[] buffer, int offset, String value) { + return 0; + } + + public boolean isNull(byte[] buffer, int offset) { + return buffer[offset] == Fast.NULL; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/StopBitEncodedTypeCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/StopBitEncodedTypeCodec.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/StopBitEncodedTypeCodec.java 2008-07-17 12:45:08 UTC (rev 174) @@ -4,7 +4,8 @@ public int getLength(byte[] buffer, int offset) { if (offset >= buffer.length) return -1; int length = 1; - while ((((int) buffer[offset++]) & 0x80) == 0) { + while ((((int) buffer[offset]) & 0x80) == 0) { + offset++; length++; } return length; Added: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/AbstractDictionaryEntry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/AbstractDictionaryEntry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/AbstractDictionaryEntry.java 2008-07-17 12:45:08 UTC (rev 174) @@ -0,0 +1,53 @@ +package org.openfast.dictionary; + +import org.lasalletech.exom.QName; + +public abstract class AbstractDictionaryEntry { + protected final QName key; + protected DictionaryEntry next; + protected boolean isNull; + protected boolean isDefined; + + public AbstractDictionaryEntry(QName key) { + if (key == null) throw new NullPointerException(); + this.key = key; + } + + public DictionaryEntry getNext() { + return next; + } + + public boolean hasNext() { + return next != null; + } + + public boolean isNull() { + return isNull; + } + + public boolean isDefined() { + return isDefined; + } + + public boolean matches(Object key) { + return this.key.equals(key); + } + + public void setNext(DictionaryEntry entry) { + next = entry; + } + + public QName getKey() { + return key; + } + + public void setNull() { + this.isNull = true; + isDefined = true; + } + + public void reset() { + isDefined = false; + isNull = false; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/BasicDictionaryRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/BasicDictionaryRegistry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/BasicDictionaryRegistry.java 2008-07-17 12:45:08 UTC (rev 174) @@ -0,0 +1,26 @@ +package org.openfast.dictionary; + +import java.util.HashMap; +import java.util.Map; + +public class BasicDictionaryRegistry implements DictionaryRegistry { + private final DictionaryTypeRegistry dictionaryTypeRegistry; + private Map<String, Dictionary> dictionaries = new HashMap<String, Dictionary>(); + + public BasicDictionaryRegistry(DictionaryTypeRegistry dictionaryTypeRegistry) { + this.dictionaryTypeRegistry = dictionaryTypeRegistry; + } + + public Dictionary get(String name) { + if (!dictionaries.containsKey(name)) { + dictionaries.put(name, dictionaryTypeRegistry.get(name).createDictionary()); + } + return dictionaries.get(name); + } + + public void reset() { + for (Dictionary dictionary : dictionaries.values()) { + dictionary.reset(); + } + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/BasicDictionaryTypeRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/BasicDictionaryTypeRegistry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/BasicDictionaryTypeRegistry.java 2008-07-17 12:45:08 UTC (rev 174) @@ -0,0 +1,17 @@ +package org.openfast.dictionary; + +import java.util.HashMap; +import java.util.Map; + +public class BasicDictionaryTypeRegistry implements DictionaryTypeRegistry { + private final Map<String, DictionaryType> dictionaryTypes = new HashMap<String, DictionaryType>(); + + public void register(String name, DictionaryType dictionaryType) { + dictionaryTypes.put(name, dictionaryType); + } + + public DictionaryType get(String name) { + return dictionaryTypes.get(name); + } + +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Dictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Dictionary.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Dictionary.java 2008-07-17 12:45:08 UTC (rev 174) @@ -0,0 +1,9 @@ +package org.openfast.dictionary; + +import org.openfast.template.Scalar; +import org.openfast.template.operator.DictionaryOperator; + +public interface Dictionary { + DictionaryEntry getEntry(Scalar scalar); + void reset(); +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryEntry.java (from rev 163, branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Entry.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryEntry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryEntry.java 2008-07-17 12:45:08 UTC (rev 174) @@ -0,0 +1,19 @@ +package org.openfast.dictionary; + +import org.lasalletech.exom.QName; + +public interface DictionaryEntry { + void set(int value); + void set(String value); + int getInt(); + String getString(); + boolean hasNext(); + DictionaryEntry getNext(); + boolean matches(Object key); + boolean isNull(); + boolean isDefined(); + void setNext(DictionaryEntry entry); + void setNull(); + QName getKey(); + void reset(); +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryRegistry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryRegistry.java 2008-07-17 12:45:08 UTC (rev 174) @@ -0,0 +1,12 @@ +package org.openfast.dictionary; + +/** + * Stores dictionaries for a given FAST Decoder or Encoder. + * + * @author Jacob Northey + * + */ +public interface DictionaryRegistry { + Dictionary get(String name); + void reset(); +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryType.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryType.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryType.java 2008-07-17 12:45:08 UTC (rev 174) @@ -0,0 +1,6 @@ +package org.openfast.dictionary; + + +public interface DictionaryType { + Dictionary createDictionary(); +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryTypeRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryTypeRegistry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/DictionaryTypeRegistry.java 2008-07-17 12:45:08 UTC (rev 174) @@ -0,0 +1,7 @@ +package org.openfast.dictionary; + +public interface DictionaryTypeRegistry { + void register(String name, DictionaryType dictionaryType); + + DictionaryType get(String name); +} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Entry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Entry.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Entry.java 2008-07-17 12:45:08 UTC (rev 174) @@ -1,12 +0,0 @@ -package org.openfast.dictionary; - -public interface Entry { - void setInt(int value); - int getInt(); - boolean hasNext(); - Entry getNext(); - boolean matches(Object key); - boolean isNull(); - void setNext(Entry entry); - void setNull(); -} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java 2008-07-17 12:12:50 UTC (rev 173) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java 2008-07-17 12:45:08 UTC (rev 174) @@ -1,20 +1,20 @@ package org.openfast.dictionary; -import org.lasalletech.exom.EObject; -import org.lasalletech.exom.Entity; import org.lasalletech.exom.QName; +import org.openfast.template.type.Type; public interface FastDictionary { - int lookupInt(Entity template, QName key, QName currentApplicationType); - String lookupString(Entity template, QName key, QNam... [truncated message content] |
From: <ope...@li...> - 2008-07-17 12:13:09
|
Revision: 173 http://openfast.svn.sourceforge.net/openfast/?rev=173&view=rev Author: jacob_northey Date: 2008-07-17 12:12:50 +0000 (Thu, 17 Jul 2008) Log Message: ----------- Modified Paths: -------------- trunk/src/test/java/org/openfast/template/operator/DeltaStringOperatorTest.java Modified: trunk/src/test/java/org/openfast/template/operator/DeltaStringOperatorTest.java =================================================================== --- trunk/src/test/java/org/openfast/template/operator/DeltaStringOperatorTest.java 2008-07-10 18:41:33 UTC (rev 172) +++ trunk/src/test/java/org/openfast/template/operator/DeltaStringOperatorTest.java 2008-07-17 12:12:50 UTC (rev 173) @@ -17,9 +17,7 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ - - + */ package org.openfast.template.operator; import org.openfast.IntegerValue; @@ -32,25 +30,24 @@ import org.openfast.template.type.Type; import org.openfast.test.OpenFastTestCase; - public class DeltaStringOperatorTest extends OpenFastTestCase { private Scalar field; public void testDecodeSubtractionLengthError() { - field = new Scalar("", Type.ASCII, Operator.DELTA, ScalarValue.UNDEFINED, false); - - try { - decode(twin(i(5), string("abc")), string("def")); - fail(); - } catch (FastException e) { - assertEquals(FastConstants.D7_SUBTRCTN_LEN_LONG, e.getCode()); - assertEquals("The string diff <5, abc> cannot be applied to the base value \"def\" because the subtraction length is too long.", e.getMessage()); - } + field = new Scalar("", Type.ASCII, Operator.DELTA, ScalarValue.UNDEFINED, false); + try { + decode(twin(i(5), string("abc")), string("def")); + fail(); + } catch (FastException e) { + assertEquals(FastConstants.D7_SUBTRCTN_LEN_LONG, e.getCode()); + assertEquals( + "The string diff <5, abc> cannot be applied to the base value \"def\" because the subtraction length is too long.", + e.getMessage()); + } } - + public void testGetValueToEncodeMandatory() { field = new Scalar("", Type.ASCII, Operator.DELTA, ScalarValue.UNDEFINED, false); - assertEquals(tv(0, "ABCD"), encode("ABCD", ScalarValue.UNDEFINED)); assertEquals(tv(1, "E"), encode("ABCE", string("ABCD"))); assertEquals(tv(-2, "Z"), encode("ZBCE", string("ABCE"))); @@ -60,9 +57,7 @@ public void testDecodeValueMandatory() { field = new Scalar("", Type.ASCII, Operator.DELTA, ScalarValue.UNDEFINED, false); - - assertEquals(new StringValue("ABCD"), - decode(tv(0, "ABCD"), ScalarValue.UNDEFINED)); + assertEquals(new StringValue("ABCD"), decode(tv(0, "ABCD"), ScalarValue.UNDEFINED)); assertEquals(new StringValue("ABCE"), decode(tv(1, "E"), string("ABCD"))); assertEquals(new StringValue("ZBCE"), decode(tv(-2, "Z"), string("ABCE"))); assertEquals(new StringValue("YZBCE"), decode(tv(-1, "Y"), string("ZBCE"))); @@ -71,7 +66,6 @@ public void testGetValueToEncodeOptional() { field = new Scalar("", Type.ASCII, Operator.DELTA, ScalarValue.UNDEFINED, true); - assertEquals(tv(0, "ABCD"), encode("ABCD", ScalarValue.UNDEFINED)); assertEquals(tv(1, "E"), encode("ABCE", string("ABCD"))); assertEquals(tv(-2, "Z"), encode("ZBCE", string("ABCE"))); @@ -82,9 +76,7 @@ public void testDecodeValueOptional() { field = new Scalar("", Type.ASCII, Operator.DELTA, ScalarValue.UNDEFINED, true); - - assertEquals(new StringValue("ABCD"), - decode(tv(0, "ABCD"), ScalarValue.UNDEFINED)); + assertEquals(new StringValue("ABCD"), decode(tv(0, "ABCD"), ScalarValue.UNDEFINED)); assertEquals(new StringValue("ABCE"), decode(tv(1, "E"), string("ABCD"))); assertEquals(new StringValue("ZBCE"), decode(tv(-2, "Z"), string("ABCE"))); assertEquals(new StringValue("YZBCE"), decode(tv(-1, "Y"), string("ZBCE"))); @@ -94,12 +86,9 @@ private ScalarValue encode(String value, ScalarValue priorValue) { if (value == null) { - return OperatorCodec.DELTA_STRING.getValueToEncode(null, priorValue, - field); + return OperatorCodec.DELTA_STRING.getValueToEncode(null, priorValue, field); } - - return OperatorCodec.DELTA_STRING.getValueToEncode(new StringValue(value), - priorValue, field); + return OperatorCodec.DELTA_STRING.getValueToEncode(new StringValue(value), priorValue, field); } private ScalarValue decode(ScalarValue diff, ScalarValue priorValue) { @@ -107,7 +96,6 @@ } private TwinValue tv(int subtraction, String diff) { - return new TwinValue(new IntegerValue(subtraction), - new StringValue(diff)); + return new TwinValue(new IntegerValue(subtraction), new StringValue(diff)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-07-10 18:41:25
|
Revision: 172 http://openfast.svn.sourceforge.net/openfast/?rev=172&view=rev Author: jacob_northey Date: 2008-07-10 11:41:33 -0700 (Thu, 10 Jul 2008) Log Message: ----------- Implemented Delta Integer, Delta String, Default Integer and Ascii codecs Modified Paths: -------------- branches/openfast-2.x/core/pom.xml branches/openfast-2.x/core/src/main/java/org/openfast/ByteUtil.java branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/FastTypeCodecs.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Operator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/ConstantOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DefaultOperator.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastOperatorTestHarness.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/IncrementIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/test/OpenFastTestCase.java branches/openfast-2.x/core/src/test/java/org/openfast/test/TestUtil.java branches/openfast-2.x/core/src/test/java/org/openfast/util/UtilTest.java Added Paths: ----------- branches/openfast-2.x/core/src/main/java/org/openfast/codec/StringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/StringDelta.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/AsciiStringCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableSignedIntegerCodec.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/DeltaAsciiCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/DeltaIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastStringOperatorTestHarness.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/AsciiStringCodecTest.java Removed Paths: ------------- branches/openfast-2.x/core/src/assembly/javadoc-jar.xml branches/openfast-2.x/core/src/assembly/sources-jar.xml Modified: branches/openfast-2.x/core/pom.xml =================================================================== --- branches/openfast-2.x/core/pom.xml 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/pom.xml 2008-07-10 18:41:33 UTC (rev 172) @@ -53,13 +53,24 @@ </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + <executions> + <execution> + <id>attach-sources</id> + <goals> + <goal>jar</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <executions> <execution> - <id>javadoc</id> - <phase>site</phase> + <id>attach-javadocs</id> <goals> - <goal>javadoc</goal> + <goal>jar</goal> </goals> </execution> </executions> @@ -68,8 +79,6 @@ <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> Deleted: branches/openfast-2.x/core/src/assembly/javadoc-jar.xml =================================================================== --- branches/openfast-2.x/core/src/assembly/javadoc-jar.xml 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/assembly/javadoc-jar.xml 2008-07-10 18:41:33 UTC (rev 172) @@ -1,13 +0,0 @@ -<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 Deleted: branches/openfast-2.x/core/src/assembly/sources-jar.xml =================================================================== --- branches/openfast-2.x/core/src/assembly/sources-jar.xml 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/assembly/sources-jar.xml 2008-07-10 18:41:33 UTC (rev 172) @@ -1,13 +0,0 @@ -<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 Modified: branches/openfast-2.x/core/src/main/java/org/openfast/ByteUtil.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/ByteUtil.java 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/main/java/org/openfast/ByteUtil.java 2008-07-10 18:41:33 UTC (rev 172) @@ -97,8 +97,8 @@ return result; } - public static boolean isEmpty(byte[] bytes) { - for (int i = 0; i < bytes.length; i++) + public static boolean isEmpty(byte[] bytes, int offset, int length) { + for (int i = offset; i < length; i++) if ((bytes[i] & 0x7f) != 0) return false; return true; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java 2008-07-10 18:41:33 UTC (rev 172) @@ -2,6 +2,8 @@ public class Fast { public static final byte STOP_BIT = (byte) 0x80; + public static final byte VALUE_BITS = (byte) 0x7f; public static final String GLOBAL = "global"; public static final byte NULL = STOP_BIT; + public static final String ZERO_TERMINATOR = "\u0000"; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java 2008-07-10 18:41:33 UTC (rev 172) @@ -13,11 +13,7 @@ public ScalarCodec createCodec(Scalar scalar, TypeCodecRegistry typeCodecRegistry) { if ("increment".equals(scalar.getOperator().getName())) { - if (((DictionaryOperator)scalar.getOperator()).getDefaultValue() != null) { - int defaultValue = Integer.parseInt(((DictionaryOperator)scalar.getOperator()).getDefaultValue()); - return new IncrementIntegerCodec(typeCodecRegistry.getIntegerCodec((Type) scalar.getType()), defaultValue); - } - return new IncrementIntegerCodec(typeCodecRegistry.getIntegerCodec((Type) scalar.getType())); + return new IncrementIntegerCodec((DictionaryOperator)scalar.getOperator(), typeCodecRegistry.getIntegerCodec((Type) scalar.getType())); } return null; } Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/StringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/StringCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/StringCodec.java 2008-07-10 18:41:33 UTC (rev 172) @@ -0,0 +1,6 @@ +package org.openfast.codec; + +public interface StringCodec extends TypeCodec { + String decode(byte[] buffer, int offset); + int encode(byte[] buffer, int offset, String value); +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java 2008-07-10 18:41:33 UTC (rev 172) @@ -9,15 +9,10 @@ import org.openfast.template.Scalar; import org.openfast.template.operator.DictionaryOperator; -public class CopyIntegerCodec implements ScalarCodec { - private final IntegerCodec integerCodec; - private final int defaultValue; - private final DictionaryOperator operator; +public class CopyIntegerCodec extends DictionaryOperatorIntegerCodec implements ScalarCodec { public CopyIntegerCodec(DictionaryOperator operator, IntegerCodec integerCodec) { - this.operator = operator; - this.integerCodec = integerCodec; - this.defaultValue = (operator.hasDefaultValue()) ? Integer.parseInt(operator.getDefaultValue()) : 0; + super(operator, integerCodec); } public int getLength(byte[] buffer, int offset) { @@ -51,7 +46,7 @@ } int value = object.getInt(index); if (dictionaryUndefined) { - if ((operator.hasDefaultValue() && defaultValue == value)) { + if ((operator.hasDefaultValue() && initialValue == value)) { dictionary.store(object.getEntity(), operator.getKey(), context.getCurrentApplicationType(), value); return offset; } @@ -73,6 +68,6 @@ if (dictionary.isDefined(object, operator.getKey(), context.getCurrentApplicationType())) object.set(index, dictionary.lookupInt(object.getEntity(), operator.getKey(), null)); else if (operator.hasDefaultValue()) - object.set(index, defaultValue); + object.set(index, initialValue); } } Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultIntegerCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DefaultIntegerCodec.java 2008-07-10 18:41:33 UTC (rev 172) @@ -0,0 +1,51 @@ +package org.openfast.codec.operator; + +import org.lasalletech.exom.EObject; +import org.openfast.Context; +import org.openfast.Fast; +import org.openfast.codec.IntegerCodec; +import org.openfast.codec.ScalarCodec; +import org.openfast.template.Operator; +import org.openfast.template.Scalar; + +public class DefaultIntegerCodec implements ScalarCodec { + private final Operator operator; + private final IntegerCodec integerCodec; + private final int defaultValue; + + public DefaultIntegerCodec(Operator operator, IntegerCodec integerCodec) { + this.operator = operator; + this.integerCodec = integerCodec; + this.defaultValue = operator.hasDefaultValue() ? Integer.parseInt(operator.getDefaultValue()) : 0; + } + public int getLength(byte[] buffer, int offset) { + return 0; + } + + public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + if (integerCodec.isNull(buffer, offset)) + return offset + 1; + int newOffset = integerCodec.decode(buffer, offset); + object.set(index, newOffset); + return newOffset; + } + + public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { + if (operator.hasDefaultValue()) + object.set(index, defaultValue); + } + + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + if (object.isDefined(index)) { + if (operator.hasDefaultValue() && object.getInt(index) == defaultValue) + return offset; + return integerCodec.encode(buffer, offset, object.getInt(index)); + } else { + if (!operator.hasDefaultValue()) + return offset; + buffer[offset] = Fast.NULL; + return offset + 1; + } + } + +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaAsciiCodec.java 2008-07-10 18:41:33 UTC (rev 172) @@ -0,0 +1,64 @@ +package org.openfast.codec.operator; + +import org.lasalletech.exom.EObject; +import org.openfast.Context; +import org.openfast.Fast; +import org.openfast.codec.IntegerCodec; +import org.openfast.codec.ScalarCodec; +import org.openfast.codec.StringCodec; +import org.openfast.dictionary.FastDictionary; +import org.openfast.error.FastConstants; +import org.openfast.template.Scalar; +import org.openfast.template.operator.DictionaryOperator; + +public class DeltaAsciiCodec extends DictionaryOperatorStringCodec implements ScalarCodec { + private IntegerCodec integerCodec; + + public DeltaAsciiCodec(DictionaryOperator operator, IntegerCodec integerCodec, StringCodec stringCodec) { + super(operator, stringCodec); + this.integerCodec = integerCodec; + } + + public int getLength(byte[] buffer, int offset) { + return 0; + } + + public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + if (integerCodec.isNull(buffer, offset)) { + return offset + 1; + } + int subtractionLength = integerCodec.decode(buffer, offset); + offset = integerCodec.getLength(buffer, offset); + String delta = stringCodec.decode(buffer, offset); + String value = new StringDelta(subtractionLength, delta).applyTo(getPreviousValue(object, field, context)); + FastDictionary dictionary = context.getDictionary(operator.getDictionary()); + dictionary.store(object.getEntity(), operator.getKey(), context.getCurrentApplicationType(), value); + object.set(index, value); + return stringCodec.getLength(buffer, offset) + offset; + } + + private String getPreviousValue(EObject object, Scalar field, Context context) { + FastDictionary dictionary = context.getDictionary(operator.getDictionary()); + if (!dictionary.isDefined(object, operator.getKey(), context.getCurrentApplicationType())) { + if (operator.hasDefaultValue()) + return operator.getDefaultValue(); + return ""; + } else if (dictionary.isNull(object, operator.getKey(), context.getCurrentApplicationType())) { + context.getErrorHandler().error(FastConstants.D6_MNDTRY_FIELD_NOT_PRESENT, "The field " + field + " must have a priorValue defined."); + return ""; + } + return dictionary.lookupString(object.getEntity(), operator.getKey(), context.getCurrentApplicationType()); + } + + public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) {} + + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + if (!object.isDefined(index)){ + buffer[offset] = Fast.NULL; + return offset + 1; + } + StringDelta diff = StringDelta.diff(object.getString(index), getPreviousValue(object, field, context)); + int newOffset = integerCodec.encode(buffer, offset, diff.getSubtractionLength()); + return stringCodec.encode(buffer, newOffset, diff.getValue()); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DeltaIntegerCodec.java 2008-07-10 18:41:33 UTC (rev 172) @@ -0,0 +1,57 @@ +package org.openfast.codec.operator; + +import static org.openfast.Fast.NULL; +import org.lasalletech.exom.EObject; +import org.openfast.Context; +import org.openfast.codec.IntegerCodec; +import org.openfast.codec.ScalarCodec; +import org.openfast.dictionary.FastDictionary; +import org.openfast.error.FastConstants; +import org.openfast.template.Scalar; +import org.openfast.template.operator.DictionaryOperator; + +public class DeltaIntegerCodec extends DictionaryOperatorIntegerCodec implements ScalarCodec { + + public DeltaIntegerCodec(DictionaryOperator operator, IntegerCodec integerDeltaCodec) { + super(operator, integerDeltaCodec); + } + + public int getLength(byte[] buffer, int offset) { + return 0; + } + + public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + if (integerCodec.isNull(buffer, offset)) { + return offset; + } + int delta = integerCodec.decode(buffer, offset); + int previousValue = getPreviousValue(object, context, field); + int newValue = delta + previousValue; + object.set(index, newValue); + context.getDictionary(operator.getDictionary()).store(object.getEntity(), operator.getKey(), context.getCurrentApplicationType(), newValue); + return integerCodec.getLength(buffer, offset) + offset; + } + + private int getPreviousValue(EObject object, Context context, Scalar field) { + FastDictionary dictionary = context.getDictionary(operator.getDictionary()); + if (!dictionary.isDefined(object, operator.getKey(), context.getCurrentApplicationType())) { + return initialValue; + } else if (dictionary.isNull(object, operator.getKey(), context.getCurrentApplicationType())) { + context.getErrorHandler().error(FastConstants.D6_MNDTRY_FIELD_NOT_PRESENT, "The field " + field + " must have a priorValue defined."); + return 0; + } + return dictionary.lookupInt(object.getEntity(), operator.getKey(), context.getCurrentApplicationType()); + } + + public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) {} + + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + if (!object.isDefined(index)) { + buffer[offset] = NULL; + return offset + 1; + } + int value = object.getInt(index); + int previousValue = getPreviousValue(object, context, field); + return integerCodec.encode(buffer, offset, value - previousValue); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorIntegerCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorIntegerCodec.java 2008-07-10 18:41:33 UTC (rev 172) @@ -0,0 +1,17 @@ +package org.openfast.codec.operator; + +import org.openfast.codec.IntegerCodec; +import org.openfast.codec.ScalarCodec; +import org.openfast.template.operator.DictionaryOperator; + +public abstract class DictionaryOperatorIntegerCodec implements ScalarCodec { + protected final IntegerCodec integerCodec; + protected final DictionaryOperator operator; + protected final int initialValue; + + public DictionaryOperatorIntegerCodec(DictionaryOperator operator, IntegerCodec integerDeltaCodec) { + this.integerCodec = integerDeltaCodec; + this.operator = operator; + this.initialValue = operator.hasDefaultValue() ? Integer.parseInt(operator.getDefaultValue()) : 0; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorStringCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/DictionaryOperatorStringCodec.java 2008-07-10 18:41:33 UTC (rev 172) @@ -0,0 +1,15 @@ +package org.openfast.codec.operator; + +import org.openfast.codec.ScalarCodec; +import org.openfast.codec.StringCodec; +import org.openfast.template.operator.DictionaryOperator; + +public abstract class DictionaryOperatorStringCodec implements ScalarCodec { + protected final DictionaryOperator operator; + protected final StringCodec stringCodec; + + protected DictionaryOperatorStringCodec(DictionaryOperator operator, StringCodec stringCodec) { + this.operator = operator; + this.stringCodec = stringCodec; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java 2008-07-10 18:41:33 UTC (rev 172) @@ -23,52 +23,40 @@ import org.lasalletech.exom.EObject; import org.lasalletech.exom.QName; import org.openfast.Context; -import org.openfast.Fast; import org.openfast.codec.IntegerCodec; import org.openfast.codec.ScalarCodec; import org.openfast.dictionary.FastDictionary; import org.openfast.error.FastConstants; import org.openfast.template.Scalar; +import org.openfast.template.operator.DictionaryOperator; public final class IncrementIntegerCodec implements ScalarCodec { private static final long serialVersionUID = 1L; private final IntegerCodec integerCodec; - private String dictionary = Fast.GLOBAL; - - public void setDictionary(String dictionary) { - this.dictionary = dictionary; - } - + private final DictionaryOperator operator; private final int defaultValue; - private final boolean hasDefaultValue; - public IncrementIntegerCodec(IntegerCodec integerCodec) { + public IncrementIntegerCodec(DictionaryOperator operator, IntegerCodec integerCodec) { this.integerCodec = integerCodec; - this.hasDefaultValue = false; - this.defaultValue = 0; + this.operator = operator; + this.defaultValue = operator.hasDefaultValue() ? Integer.parseInt(operator.getDefaultValue()) : 0; } - public IncrementIntegerCodec(IntegerCodec integerCodec, int defaultValue) { - this.integerCodec = integerCodec; - this.hasDefaultValue = true; - this.defaultValue = defaultValue; - } - public int decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { int length = integerCodec.getLength(buffer, offset); int value = integerCodec.decode(buffer, offset); - context.getDictionary(dictionary).store(object.getEntity(), scalar.getKey(), null, value); + context.getDictionary(operator.getDictionary()).store(object.getEntity(), scalar.getKey(), null, value); object.set(index, value); return offset + length; } public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { - FastDictionary dictionary = context.getDictionary(this.dictionary); + FastDictionary dictionary = context.getDictionary(operator.getDictionary()); if (dictionary.isNull(object, scalar.getKey(), null)) { // leave object value set to null dictionary.storeNull(object.getEntity(), scalar.getKey(), null); } else if (!dictionary.isDefined(object, scalar.getKey(), null)) { - if (hasDefaultValue) { + if (operator.hasDefaultValue()) { object.set(index, defaultValue); dictionary.store(object.getEntity(), scalar.getKey(), null, defaultValue); } else { @@ -91,7 +79,7 @@ } public int encode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { - FastDictionary dictionary = context.getDictionary(this.dictionary); + FastDictionary dictionary = context.getDictionary(operator.getDictionary()); QName key = scalar.getKey(); if (!object.isDefined(index)) { if (!scalar.isOptional()) { @@ -109,10 +97,10 @@ return integerCodec.encode(buffer, offset, value); } if (!dictionary.isDefined(object, key, null)) { - if (!hasDefaultValue) { + if (!operator.hasDefaultValue()) { dictionary.store(null, key, null, value); return integerCodec.encode(buffer, offset, value); - } else if (hasDefaultValue && value == defaultValue) { + } else if (operator.hasDefaultValue() && value == defaultValue) { return offset; } else { return integerCodec.encode(buffer, offset, value); Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneIntegerCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/NoneIntegerCodec.java 2008-07-10 18:41:33 UTC (rev 172) @@ -0,0 +1,36 @@ +package org.openfast.codec.operator; + +import org.lasalletech.exom.EObject; +import org.openfast.Context; +import org.openfast.Fast; +import org.openfast.codec.IntegerCodec; +import org.openfast.codec.ScalarCodec; +import org.openfast.template.Scalar; + +public class NoneIntegerCodec implements ScalarCodec { + private IntegerCodec integerCodec; + + public NoneIntegerCodec(IntegerCodec integerCodec) { + this.integerCodec = integerCodec; + } + public int getLength(byte[] buffer, int offset) { + return 0; + } + + public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + if (!integerCodec.isNull(buffer, offset)) { + object.set(index, integerCodec.decode(buffer, offset)); + } + return integerCodec.getLength(buffer, offset); + } + + public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) {} + + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + if (!object.isDefined(index)) { + buffer[offset] = Fast.NULL; + return offset + 1; + } + return integerCodec.encode(buffer, offset, object.getInt(index)); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/StringDelta.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/StringDelta.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/StringDelta.java 2008-07-10 18:41:33 UTC (rev 172) @@ -0,0 +1,56 @@ +package org.openfast.codec.operator; + +public class StringDelta { + public static final StringDelta NO_DIFF = new StringDelta(0, ""); + private final int subtractionLength; + private final String value; + + public StringDelta(int subtractionLength, String value) { + this.subtractionLength = subtractionLength; + this.value = value; + } + + public int getSubtractionLength() { + return subtractionLength; + } + + public String getValue() { + return value; + } + + public String applyTo(String previousValue) { + if (subtractionLength < 0) { + int length = (-1 * subtractionLength) - 1; + return value + previousValue.substring(length, previousValue.length()); + } + return previousValue.substring(0, previousValue.length() - subtractionLength) + value; + } + + public static StringDelta diff(String newValue, String previousValue) { + if (previousValue == null || previousValue.length() == 0) + return new StringDelta(0, newValue); + if (newValue.equals(previousValue)) + return StringDelta.NO_DIFF; + String base = previousValue; + String value = newValue; + int appendIndex = 0; + while ((appendIndex < base.length()) && (appendIndex < value.length()) + && (value.charAt(appendIndex) == base.charAt(appendIndex))) + appendIndex++; + String append = value.substring(appendIndex); + int prependIndex = 1; + while ((prependIndex <= value.length()) && (prependIndex <= base.length()) + && (value.charAt(value.length() - prependIndex) == base.charAt(base.length() - prependIndex))) + prependIndex++; + String prepend = value.substring(0, value.length() - prependIndex + 1); + if (prepend.length() < append.length()) { + return new StringDelta(prependIndex - base.length() - 2, prepend); + } + return new StringDelta(base.length() - appendIndex, append); + } + + @Override + public String toString() { + return value + "(" + subtractionLength + ")"; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/AsciiStringCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/AsciiStringCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/AsciiStringCodec.java 2008-07-10 18:41:33 UTC (rev 172) @@ -0,0 +1,62 @@ +package org.openfast.codec.type; + +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.charset.CharacterCodingException; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CharsetEncoder; +import org.openfast.ByteUtil; +import org.openfast.Fast; +import org.openfast.Global; +import org.openfast.codec.StringCodec; +import org.openfast.error.FastConstants; + +public class AsciiStringCodec extends StopBitEncodedTypeCodec implements StringCodec { + private final CharsetDecoder decoder = Charset.forName("US-ASCII").newDecoder(); + private final CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder(); + public String decode(byte[] buffer, int offset) { + CharBuffer decoded; + try { + int length = getLength(buffer, offset); + buffer[length + offset - 1] &= Fast.VALUE_BITS; // remove stop bit + if (buffer[offset] == 0) { + if (!ByteUtil.isEmpty(buffer, offset, length)) + Global.handleError(FastConstants.R9_STRING_OVERLONG, null); + if (length > 1 && buffer[offset+1] == 0) + return Fast.ZERO_TERMINATOR; + return ""; + } + decoded = decoder.decode(ByteBuffer.wrap(buffer, offset, length)); + buffer[length + offset - 1] |= Fast.STOP_BIT; // replace stop bit to prevent side effects + return decoded.toString(); + } catch (CharacterCodingException e) { + throw new RuntimeException(e); + } + } + + public int encode(byte[] buffer, int offset, String value) { + if (value.length() == 0) { + buffer[offset] = Fast.NULL; + return offset + 1; + } + if (value.startsWith(Fast.ZERO_TERMINATOR)) { + buffer[offset] = 0; + buffer[offset+1] = Fast.STOP_BIT; + return offset + 2; + } + ByteBuffer encoded; + try { + encoded = encoder.encode(CharBuffer.wrap(value)); + } catch (CharacterCodingException e) { + throw new RuntimeException(e); + } + encoded.get(buffer, offset, encoded.limit()); + buffer[encoded.limit() - 1 + offset] |= Fast.STOP_BIT; + return encoded.limit() + offset; + } + + public boolean isNull(byte[] buffer, int offset) { + return false; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/FastTypeCodecs.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/FastTypeCodecs.java 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/FastTypeCodecs.java 2008-07-10 18:41:33 UTC (rev 172) @@ -1,9 +1,12 @@ package org.openfast.codec.type; import org.openfast.codec.IntegerCodec; +import org.openfast.codec.StringCodec; public class FastTypeCodecs { - public static final IntegerCodec UNSIGNED_INTEGER = new UnsignedIntegerCodec(); - public static final IntegerCodec SIGNED_INTEGER = new SignedIntegerCodec(); - public static final IntegerCodec NULLABLE_UNSIGNED_INTEGER = new NullableUnsignedIntegerCodec(); + public static final IntegerCodec UNSIGNED_INTEGER = new UnsignedIntegerCodec(); + public static final IntegerCodec SIGNED_INTEGER = new SignedIntegerCodec(); + public static final IntegerCodec NULLABLE_UNSIGNED_INTEGER = new NullableUnsignedIntegerCodec(); + public static final IntegerCodec NULLABLE_SIGNED_INTEGER = new NullableSignedIntegerCodec(); + public static final StringCodec ASCII_STRING = new AsciiStringCodec(); } Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableSignedIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableSignedIntegerCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableSignedIntegerCodec.java 2008-07-10 18:41:33 UTC (rev 172) @@ -0,0 +1,18 @@ +package org.openfast.codec.type; + +import org.openfast.Fast; +import org.openfast.codec.IntegerCodec; + +public class NullableSignedIntegerCodec extends StopBitEncodedTypeCodec implements IntegerCodec { + public int decode(byte[] buffer, int offset) { + return FastTypeCodecs.SIGNED_INTEGER.decode(buffer, offset) - 1; + } + + public int encode(byte[] buffer, int offset, int value) { + return FastTypeCodecs.SIGNED_INTEGER.encode(buffer, offset, value + 1); + } + + public boolean isNull(byte[] buffer, int offset) { + return buffer[offset] == Fast.NULL; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java 2008-07-10 18:41:33 UTC (rev 172) @@ -6,12 +6,15 @@ public interface FastDictionary { int lookupInt(Entity template, QName key, QName currentApplicationType); + String lookupString(Entity template, QName key, QName currentApplicationType); void store(Entity template, QName key, QName currentApplicationType, int value); + void store(Entity entity, QName key, QName currentApplicationType, String value); void storeNull(Entity entity, QName key, QName currentApplicationType); boolean isDefined(EObject object, QName key, QName currentApplicationType); boolean isNull(EObject object, QName key, QName currentApplicationType); void reset(); + } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java 2008-07-10 18:41:33 UTC (rev 172) @@ -85,4 +85,10 @@ if (entry == null) return false; return entry.isNull(); } + + public String lookupString(Entity template, QName key, QName currentApplicationType) { + return null; + } + + public void store(Entity entity, QName key, QName currentApplicationType, String value) {} } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Operator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Operator.java 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Operator.java 2008-07-10 18:41:33 UTC (rev 172) @@ -26,6 +26,10 @@ Operator NONE = new Operator() { private static final long serialVersionUID = 1L; public String getName() { return "none"; } + public String getDefaultValue() { return null; } + public boolean hasDefaultValue() { return false; } }; String getName(); + String getDefaultValue(); + boolean hasDefaultValue(); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/ConstantOperator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/ConstantOperator.java 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/ConstantOperator.java 2008-07-10 18:41:33 UTC (rev 172) @@ -18,4 +18,8 @@ public String getName() { return "constant"; } + + public boolean hasDefaultValue() { + return defaultValue != null; + } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DefaultOperator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DefaultOperator.java 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DefaultOperator.java 2008-07-10 18:41:33 UTC (rev 172) @@ -17,5 +17,9 @@ public String getName() { return "default"; } + + public boolean hasDefaultValue() { + return defaultValue != null; + } } Added: branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/DeltaAsciiCodecTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/DeltaAsciiCodecTest.java (rev 0) +++ branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/DeltaAsciiCodecTest.java 2008-07-10 18:41:33 UTC (rev 172) @@ -0,0 +1,34 @@ +package org.openfast.codec.operator; + +import static org.openfast.codec.operator.FastOperatorTestHarness.KEY; +import static org.openfast.codec.operator.FastStringOperatorTestHarness.INITIAL_VALUE; +import static org.openfast.codec.operator.FastStringOperatorTestHarness.NO_INITIAL_VALUE; +import static org.openfast.codec.operator.FastStringOperatorTestHarness.UNDEFINED; +import org.openfast.Fast; +import org.openfast.codec.ScalarCodec; +import org.openfast.codec.type.FastTypeCodecs; +import org.openfast.template.operator.DeltaOperator; +import org.openfast.template.operator.DictionaryOperator; +import junit.framework.TestCase; + +public class DeltaAsciiCodecTest extends TestCase { + private DictionaryOperator noDefault = new DeltaOperator(KEY, Fast.GLOBAL, null); + private DictionaryOperator withDefault = new DeltaOperator(KEY, Fast.GLOBAL, "ABCD"); + private ScalarCodec noDefaultCodec = new DeltaAsciiCodec(noDefault, FastTypeCodecs.NULLABLE_SIGNED_INTEGER, FastTypeCodecs.ASCII_STRING); + private ScalarCodec withDefaultCodec = new DeltaAsciiCodec(withDefault, FastTypeCodecs.NULLABLE_SIGNED_INTEGER, FastTypeCodecs.ASCII_STRING);; + FastStringOperatorTestHarness harness = new FastStringOperatorTestHarness(noDefaultCodec, withDefaultCodec); + + public void testDecode() { + harness.assertDecodeNull(NO_INITIAL_VALUE, UNDEFINED, "10000000"); + harness.assertDecode("ABCD", NO_INITIAL_VALUE, UNDEFINED, "10000001 01000001 01000010 01000011 11000100"); + harness.assertDecode("ABCDEFGH", INITIAL_VALUE, UNDEFINED, "10000001 01000101 01000110 01000111 11001000"); + } + + public void testEncode() { + harness.assertEncode("10000000", NO_INITIAL_VALUE, UNDEFINED); + harness.assertEncode("10000001 01000001 01000010 01000011 11000100", NO_INITIAL_VALUE, UNDEFINED, "ABCD"); + harness.assertEncode("10000001 01000101 01000110 01000111 11001000", INITIAL_VALUE, UNDEFINED, "ABCDEFGH"); + harness.assertEncode("10000011 01000101 11000110", INITIAL_VALUE, UNDEFINED, "ABEF"); + harness.assertEncode("11111111 10000000", INITIAL_VALUE, UNDEFINED, "BCD"); + } +} Added: branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/DeltaIntegerCodecTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/DeltaIntegerCodecTest.java (rev 0) +++ branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/DeltaIntegerCodecTest.java 2008-07-10 18:41:33 UTC (rev 172) @@ -0,0 +1,32 @@ +package org.openfast.codec.operator; + +import static org.openfast.codec.operator.FastOperatorTestHarness.INITIAL_VALUE; +import static org.openfast.codec.operator.FastOperatorTestHarness.NO_INITIAL_VALUE; +import static org.openfast.codec.operator.FastOperatorTestHarness.UNDEFINED; +import org.openfast.Fast; +import org.openfast.codec.type.FastTypeCodecs; +import org.openfast.template.operator.DeltaOperator; +import org.openfast.test.OpenFastTestCase; + +public class DeltaIntegerCodecTest extends OpenFastTestCase { + DeltaOperator noDefault = new DeltaOperator(FastOperatorTestHarness.KEY, Fast.GLOBAL, null); + DeltaOperator withDefault = new DeltaOperator(FastOperatorTestHarness.KEY, Fast.GLOBAL, "15"); + DeltaIntegerCodec noDefaultCodec = new DeltaIntegerCodec(noDefault, FastTypeCodecs.NULLABLE_SIGNED_INTEGER); + DeltaIntegerCodec defaultCodec = new DeltaIntegerCodec(withDefault, FastTypeCodecs.NULLABLE_SIGNED_INTEGER); + FastOperatorTestHarness harness = new FastOperatorTestHarness(noDefaultCodec, defaultCodec); + + public void testDecode() { + harness.assertDecodeNull(NO_INITIAL_VALUE, UNDEFINED, "10000000"); + harness.assertDecode(16, INITIAL_VALUE, UNDEFINED, "10000010"); + harness.assertDecode(1, NO_INITIAL_VALUE, UNDEFINED, "10000010"); + harness.assertDecode(30, NO_INITIAL_VALUE, 25, "10000110"); + harness.assertDecode(196, NO_INITIAL_VALUE, 200, "11111101"); + } + + public void testEncode() { + harness.assertEncode("10000000", NO_INITIAL_VALUE, UNDEFINED); + harness.assertEncode("10000010", NO_INITIAL_VALUE, UNDEFINED, 1); + harness.assertEncode("10000011", INITIAL_VALUE, UNDEFINED, 17); + harness.assertEncode("11111101", INITIAL_VALUE, 200, 196); + } +} Modified: branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastOperatorTestHarness.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastOperatorTestHarness.java 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastOperatorTestHarness.java 2008-07-10 18:41:33 UTC (rev 172) @@ -10,6 +10,7 @@ import org.openfast.template.MessageTemplate; import org.openfast.template.Scalar; import org.openfast.template.type.Type; +import org.openfast.test.OpenFastTestCase; public class FastOperatorTestHarness { @@ -87,4 +88,29 @@ return codec; } + public void assertEncode(String encoded, int initialValue, int dictionaryState) { + ScalarCodec codec = getCodec(initialValue); + Context context = new Context(); + initDictionary(context, dictionaryState); + MessageTemplate template = new MessageTemplate(QName.NULL, new Field[] { new Scalar(QName.NULL, Type.U32, null, true) }); + Message message = new Message(template); + byte[] buffer = new byte[32]; + int offset = codec.encode(message, 0, buffer, 0, null, context); + byte[] encodedBytes = ByteUtil.convertBitStringToFastByteArray(encoded); + Assert.assertEquals(encodedBytes.length, offset); + OpenFastTestCase.assertEquals(encoded, buffer, offset); + } + + public void assertEncode(String encoded, int initialValue, int dictionaryState, int value) { + ScalarCodec codec = getCodec(initialValue); + Context context = new Context(); + initDictionary(context, dictionaryState); + MessageTemplate template = new MessageTemplate(QName.NULL, new Field[] { new Scalar(QName.NULL, Type.U32, null, true) }); + Message message = new Message(template); + message.set(0, value); + byte[] buffer = new byte[32]; + int offset = codec.encode(message, 0, buffer, 0, null, context); + OpenFastTestCase.assertEquals(encoded, buffer, offset); + } + } Added: branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastStringOperatorTestHarness.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastStringOperatorTestHarness.java (rev 0) +++ branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastStringOperatorTestHarness.java 2008-07-10 18:41:33 UTC (rev 172) @@ -0,0 +1,118 @@ +package org.openfast.codec.operator; + +import junit.framework.Assert; +import org.lasalletech.exom.QName; +import org.openfast.ByteUtil; +import org.openfast.Context; +import org.openfast.Message; +import org.openfast.codec.ScalarCodec; +import org.openfast.template.Field; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; +import org.openfast.template.type.Type; +import org.openfast.test.OpenFastTestCase; + +public class FastStringOperatorTestHarness { + + public static final QName KEY = new QName("any", "thing"); + public static final String UNDEFINED = "UNDEFINED"; + public static final String NULL = "NULL"; + public static final int NO_INITIAL_VALUE = Integer.MIN_VALUE + 2; + public static final int INITIAL_VALUE = Integer.MIN_VALUE + 3; + private final ScalarCodec noDefaultCodec; + private final ScalarCodec defaultCodec; + + public FastStringOperatorTestHarness(ScalarCodec noDefaultCodec, ScalarCodec defaultCodec) { + this.noDefaultCodec = noDefaultCodec; + this.defaultCodec = defaultCodec; + } + + public void assertDecodeNull(int initialValue, String dictionaryState) { + ScalarCodec codec = getCodec(initialValue); + Context context = new Context(); + initDictionary(context, dictionaryState); + MessageTemplate template = new MessageTemplate(QName.NULL, new Field[] { new Scalar(QName.NULL, Type.U32, null, true) }); + Message message = new Message(template); + codec.decodeEmpty(message, 0, null, context); + Assert.assertFalse(message.isDefined(0)); + } + + public void assertDecodeNull(int initialValue, String dictionaryState, String encoded) { + ScalarCodec codec = getCodec(initialValue); + Context context = new Context(); + initDictionary(context, dictionaryState); + MessageTemplate template = new MessageTemplate(QName.NULL, new Field[] { new Scalar(QName.NULL, Type.U32, null, true) }); + Message message = new Message(template); + byte[] encodedBytes = ByteUtil.convertBitStringToFastByteArray(encoded); + codec.decode(message, 0, encodedBytes, 0, null, context); + Assert.assertFalse(message.isDefined(0)); + } + + public void assertDecode(String expectedValue, int initialValue, String dictionaryState) { + ScalarCodec codec = getCodec(initialValue); + Context context = new Context(); + initDictionary(context, dictionaryState); + MessageTemplate template = new MessageTemplate(QName.NULL, new Field[] { new Scalar(QName.NULL, Type.U32, null, true) }); + Message message = new Message(template); + codec.decodeEmpty(message, 0, null, context); + Assert.assertEquals(expectedValue, message.getString(0)); + } + + public void assertDecode(String expectedValue, int initialValue, String dictionaryState, String encoded) { + ScalarCodec codec = getCodec(initialValue); + Context context = new Context(); + initDictionary(context, dictionaryState); + MessageTemplate template = new MessageTemplate(QName.NULL, new Field[] { new Scalar(QName.NULL, Type.U32, null, true) }); + Message message = new Message(template); + byte[] encodedBytes = ByteUtil.convertBitStringToFastByteArray(encoded); + codec.decode(message, 0, encodedBytes, 0, null, context); + Assert.assertEquals(expectedValue, message.getString(0)); + + } + + private void initDictionary(Context context, String dictionaryState) { + if (dictionaryState == NULL) { + context.getDictionary("global").storeNull(null, KEY, null); + } else if (dictionaryState != UNDEFINED) { + context.getDictionary("global").store(null, KEY, null, dictionaryState); + } + } + + private ScalarCodec getCodec(int initialValue) { + ScalarCodec codec; + if (initialValue == NO_INITIAL_VALUE) { + codec = noDefaultCodec; + } else { + codec = defaultCodec; + } + return codec; + } + + public void assertEncode(String encoded, int initialValue, String dictionaryState) { + ScalarCodec codec = getCodec(initialValue); + Context context = new Context(); + initDictionary(context, dictionaryState); + MessageTemplate template = new MessageTemplate(QName.NULL, new Field[] { new Scalar(QName.NULL, Type.U32, null, true) }); + Message message = new Message(template); + byte[] buffer = new byte[32]; + int offset = codec.encode(message, 0, buffer, 0, null, context); + byte[] encodedBytes = ByteUtil.convertBitStringToFastByteArray(encoded); + Assert.assertEquals(encodedBytes.length, offset); + OpenFastTestCase.assertEquals(encoded, buffer, offset); + } + + public void assertEncode(String encoded, int initialValue, String dictionaryState, String value) { + ScalarCodec codec = getCodec(initialValue); + Context context = new Context(); + initDictionary(context, dictionaryState); + MessageTemplate template = new MessageTemplate(QName.NULL, new Field[] { new Scalar(QName.NULL, Type.U32, null, true) }); + Message message = new Message(template); + message.set(0, value); + byte[] buffer = new byte[32]; + int offset = codec.encode(message, 0, buffer, 0, null, context); + byte[] encodedBytes = ByteUtil.convertBitStringToFastByteArray(encoded); + Assert.assertEquals(encodedBytes.length, offset); + OpenFastTestCase.assertEquals(encoded, buffer, offset); + } + +} Modified: branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/IncrementIntegerCodecTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/IncrementIntegerCodecTest.java 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/IncrementIntegerCodecTest.java 2008-07-10 18:41:33 UTC (rev 172) @@ -5,17 +5,20 @@ import org.lasalletech.exom.simple.SimpleField; import org.openfast.ByteUtil; import org.openfast.Context; -import org.openfast.codec.operator.IncrementIntegerCodec; +import org.openfast.Fast; import org.openfast.codec.type.SignedIntegerCodec; import org.openfast.dictionary.FastDictionary; import org.openfast.dictionary.GlobalFastDictionary; import org.openfast.template.Scalar; +import org.openfast.template.operator.IncrementOperator; import org.openfast.template.type.Type; import org.openfast.test.OpenFastTestCase; public class IncrementIntegerCodecTest extends OpenFastTestCase { - IncrementIntegerCodec noDefaultSignedCodec = new IncrementIntegerCodec(new SignedIntegerCodec()); - IncrementIntegerCodec default22SignedCodec = new IncrementIntegerCodec(new SignedIntegerCodec(), 22); + IncrementOperator noDefault = new IncrementOperator(FastOperatorTestHarness.KEY, Fast.GLOBAL, null); + IncrementOperator withDefault = new IncrementOperator(FastOperatorTestHarness.KEY, Fast.GLOBAL, "22"); + IncrementIntegerCodec noDefaultSignedCodec = new IncrementIntegerCodec(noDefault, new SignedIntegerCodec()); + IncrementIntegerCodec default22SignedCodec = new IncrementIntegerCodec(withDefault, new SignedIntegerCodec()); public void testEncode() { SimpleEntity entity = new SimpleEntity("yeah"); Added: branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/AsciiStringCodecTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/AsciiStringCodecTest.java (rev 0) +++ branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/AsciiStringCodecTest.java 2008-07-10 18:41:33 UTC (rev 172) @@ -0,0 +1,16 @@ +package org.openfast.codec.type; + +import org.openfast.test.OpenFastTestCase; + +public class AsciiStringCodecTest extends OpenFastTestCase { + public void testDecode() { + byte[] buffer = bytes("01000001 01000010 01000011 11000100"); + assertEquals("ABCD", FastTypeCodecs.ASCII_STRING.decode(buffer, 0)); + } + + public void testEncode() { + byte[] buffer = new byte[4]; + assertEquals(4, FastTypeCodecs.ASCII_STRING.encode(buffer, 0, "ABCD")); + assertEquals("01000001 01000010 01000011 11000100", buffer); + } +} Modified: branches/openfast-2.x/core/src/test/java/org/openfast/test/OpenFastTestCase.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/test/OpenFastTestCase.java 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/test/java/org/openfast/test/OpenFastTestCase.java 2008-07-10 18:41:33 UTC (rev 172) @@ -35,11 +35,11 @@ import org.openfast.template.loader.XMLMessageTemplateLoader; public abstract class OpenFastTestCase extends TestCase { - protected static void assertEquals(String bitString, byte[] encoding) { + public static void assertEquals(String bitString, byte[] encoding) { TestUtil.assertBitVectorEquals(bitString, encoding); } - protected static void assertEquals(String bitString, byte[] encoding, int length) { + public static void assertEquals(String bitString, byte[] encoding, int length) { TestUtil.assertBitVectorEquals(bitString, encoding, length); } Modified: branches/openfast-2.x/core/src/test/java/org/openfast/test/TestUtil.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/test/TestUtil.java 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/test/java/org/openfast/test/TestUtil.java 2008-07-10 18:41:33 UTC (rev 172) @@ -34,7 +34,6 @@ } public static void assertBitVectorEquals(String bitString, byte[] encoding, int length) { - assertByteArrayEquals(ByteUtil.convertBitStringToFastByteArray(bitString), encoding, length); } Modified: branches/openfast-2.x/core/src/test/java/org/openfast/util/UtilTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/util/UtilTest.java 2008-07-10 13:17:44 UTC (rev 171) +++ branches/openfast-2.x/core/src/test/java/org/openfast/util/UtilTest.java 2008-07-10 18:41:33 UTC (rev 172) @@ -22,6 +22,7 @@ import java.nio.ByteBuffer; import java.util.Calendar; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import junit.framework.TestCase; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-07-10 13:17:39
|
Revision: 171 http://openfast.svn.sourceforge.net/openfast/?rev=171&view=rev Author: jacob_northey Date: 2008-07-10 06:17:44 -0700 (Thu, 10 Jul 2008) Log Message: ----------- Fixed javadoc and source jar generation Modified Paths: -------------- trunk/pom.xml trunk/src/assembly/binary.xml Removed Paths: ------------- trunk/src/assembly/javadoc-jar.xml trunk/src/assembly/sources-jar.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2008-07-09 20:51:08 UTC (rev 170) +++ trunk/pom.xml 2008-07-10 13:17:44 UTC (rev 171) @@ -73,7 +73,7 @@ <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> + <url>http://openfast.svn.sourceforge.net/viewvc/openfast/trunk</url> </scm> <mailingLists> @@ -151,13 +151,24 @@ </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + <executions> + <execution> + <id>attach-sources</id> + <goals> + <goal>jar</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <executions> <execution> - <id>javadoc</id> - <phase>site</phase> + <id>attach-javadocs</id> <goals> - <goal>javadoc</goal> + <goal>jar</goal> </goals> </execution> </executions> @@ -166,8 +177,6 @@ <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> Modified: trunk/src/assembly/binary.xml =================================================================== --- trunk/src/assembly/binary.xml 2008-07-09 20:51:08 UTC (rev 170) +++ trunk/src/assembly/binary.xml 2008-07-10 13:17:44 UTC (rev 171) @@ -25,7 +25,7 @@ </includes> </fileSet> <fileSet> - <directory>target/site/apidocs</directory> + <directory>target/apidocs</directory> <outputDirectory>/docs/api</outputDirectory> </fileSet> </fileSets> Deleted: trunk/src/assembly/javadoc-jar.xml =================================================================== --- trunk/src/assembly/javadoc-jar.xml 2008-07-09 20:51:08 UTC (rev 170) +++ trunk/src/assembly/javadoc-jar.xml 2008-07-10 13:17:44 UTC (rev 171) @@ -1,13 +0,0 @@ -<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 Deleted: trunk/src/assembly/sources-jar.xml =================================================================== --- trunk/src/assembly/sources-jar.xml 2008-07-09 20:51:08 UTC (rev 170) +++ trunk/src/assembly/sources-jar.xml 2008-07-10 13:17:44 UTC (rev 171) @@ -1,13 +0,0 @@ -<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-07-09 20:52:00
|
Revision: 170 http://openfast.svn.sourceforge.net/openfast/?rev=170&view=rev Author: jacob_northey Date: 2008-07-09 13:51:08 -0700 (Wed, 09 Jul 2008) Log Message: ----------- [maven-release-plugin] prepare for next development iteration Modified Paths: -------------- trunk/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2008-07-09 20:50:20 UTC (rev 169) +++ trunk/pom.xml 2008-07-09 20:51:08 UTC (rev 170) @@ -3,7 +3,7 @@ <groupId>org.openfast</groupId> <artifactId>openfast</artifactId> <packaging>jar</packaging> - <version>1.0.0</version> + <version>1.0.1-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-1.0.0</connection> - <developerConnection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-1.0.0</developerConnection> - <url>http://openfast.svn.sourceforge.net/viewvc/openfast/tags/tags/openfast-1.0.0</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-07-09 20:51:01
|
Revision: 169 http://openfast.svn.sourceforge.net/openfast/?rev=169&view=rev Author: jacob_northey Date: 2008-07-09 13:50:20 -0700 (Wed, 09 Jul 2008) Log Message: ----------- [maven-release-plugin] copy for tag openfast-1.0.0 Added Paths: ----------- tags/openfast-1.0.0/ tags/openfast-1.0.0/pom.xml tags/openfast-1.0.0/src/main/java/org/openfast/template/ComposedScalar.java tags/openfast-1.0.0/src/site/apt/contributions.apt tags/openfast-1.0.0/src/site/apt/support.apt tags/openfast-1.0.0/src/site/site.xml tags/openfast-1.0.0/src/test/java/org/openfast/session/SCP_1_1_Test.java tags/openfast-1.0.0/src/test/java/org/openfast/submitted/SingleDecimalPmapTest.java Removed Paths: ------------- tags/openfast-1.0.0/pom.xml tags/openfast-1.0.0/src/main/java/org/openfast/template/ComposedScalar.java tags/openfast-1.0.0/src/site/apt/contributions.apt tags/openfast-1.0.0/src/site/apt/support.apt tags/openfast-1.0.0/src/site/site.xml tags/openfast-1.0.0/src/test/java/org/openfast/session/SCP_1_1_Test.java Copied: tags/openfast-1.0.0 (from rev 156, trunk) Deleted: tags/openfast-1.0.0/pom.xml =================================================================== --- trunk/pom.xml 2008-06-25 03:12:39 UTC (rev 156) +++ tags/openfast-1.0.0/pom.xml 2008-07-09 20:50:20 UTC (rev 169) @@ -1,220 +0,0 @@ -<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>1.0.0-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>jira</system> - <url>http://www.quickfixj.org/jira/browse/FAST</url> - </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> - </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> - </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> - - <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-1.0.0/pom.xml (from rev 168, trunk/pom.xml) =================================================================== --- tags/openfast-1.0.0/pom.xml (rev 0) +++ tags/openfast-1.0.0/pom.xml 2008-07-09 20:50:20 UTC (rev 169) @@ -0,0 +1,220 @@ +<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>1.0.0</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>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-1.0.0</connection> + <developerConnection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-1.0.0</developerConnection> + <url>http://openfast.svn.sourceforge.net/viewvc/openfast/tags/tags/openfast-1.0.0</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> + </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> + + <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-1.0.0/src/main/java/org/openfast/template/ComposedScalar.java =================================================================== --- trunk/src/main/java/org/openfast/template/ComposedScalar.java 2008-06-25 03:12:39 UTC (rev 156) +++ tags/openfast-1.0.0/src/main/java/org/openfast/template/ComposedScalar.java 2008-07-09 20:50:20 UTC (rev 169) @@ -1,146 +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; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import org.openfast.BitVectorBuilder; -import org.openfast.BitVectorReader; -import org.openfast.Context; -import org.openfast.FieldValue; -import org.openfast.QName; -import org.openfast.template.type.Type; - -public class ComposedScalar extends Field { - private static final long serialVersionUID = 1L; - private static final Class ScalarValueType = null; - private Scalar[] fields; - private ComposedValueConverter valueConverter; - private Type type; - - public ComposedScalar(String name, Type type, Scalar[] fields, boolean optional, ComposedValueConverter valueConverter) { - this(new QName(name), type, fields, optional, valueConverter); - } - - public ComposedScalar(QName name, Type type, Scalar[] fields, boolean optional, ComposedValueConverter valueConverter) { - super(name, optional); - this.fields = fields; - this.valueConverter = valueConverter; - this.type = type; - } - - public FieldValue createValue(String value) { - return type.getValue(value); - } - - public FieldValue decode(InputStream in, Group template, Context context, BitVectorReader presenceMapReader) { - FieldValue[] values = new FieldValue[fields.length]; - for (int i = 0; i < fields.length; i++) { - values[i] = fields[i].decode(in, template, context, presenceMapReader); - if (i == 0 && values[0] == null) - return null; - } - return valueConverter.compose(values); - } - - public byte[] encode(FieldValue value, Group template, Context context, BitVectorBuilder presenceMapBuilder) { - if (value == null) { - // Only encode null in the first field. - return fields[0].encode(null, template, context, presenceMapBuilder); - } else { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(fields.length * 8); - FieldValue[] values = valueConverter.split(value); - for (int i = 0; i < fields.length; i++) { - try { - buffer.write(fields[i].encode(values[i], template, context, presenceMapBuilder)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - return buffer.toByteArray(); - } - } - - public String getTypeName() { - return type.getName(); - } - - public Class getValueType() { - return ScalarValueType; - } - - public boolean isPresenceMapBitSet(byte[] encoding, FieldValue fieldValue) { - return false; - } - - public boolean usesPresenceMapBit() { - return false; - } - - public Type getType() { - return type; - } - - public Scalar[] getFields() { - return fields; - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null || !obj.getClass().equals(ComposedScalar.class)) - return false; - ComposedScalar other = (ComposedScalar) obj; - if (other.fields.length != fields.length) - return false; - if (!other.getName().equals(getName())) - return false; - for (int i = 0; i < fields.length; i++) { - if (!other.fields[i].getType().equals(fields[i].getType())) - return false; - if (!other.fields[i].getTypeCodec().equals(fields[i].getTypeCodec())) - return false; - if (!other.fields[i].getOperator().equals(fields[i].getOperator())) - return false; - if (!other.fields[i].getOperatorCodec().equals(fields[i].getOperatorCodec())) - return false; - if (!other.fields[i].getDefaultValue().equals(fields[i].getDefaultValue())) - return false; - if (!other.fields[i].getDictionary().equals(fields[i].getDictionary())) - return false; - } - return true; - } - - public int hashCode() { - return name.hashCode(); - } - - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("Composed {"); - for (int i = 0; i < fields.length; i++) - builder.append(fields[i].toString()).append(", "); - builder.delete(builder.length() - 2, builder.length()); - return builder.append("}").toString(); - } -} Copied: tags/openfast-1.0.0/src/main/java/org/openfast/template/ComposedScalar.java (from rev 165, trunk/src/main/java/org/openfast/template/ComposedScalar.java) =================================================================== --- tags/openfast-1.0.0/src/main/java/org/openfast/template/ComposedScalar.java (rev 0) +++ tags/openfast-1.0.0/src/main/java/org/openfast/template/ComposedScalar.java 2008-07-09 20:50:20 UTC (rev 169) @@ -0,0 +1,150 @@ +/* +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.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import org.openfast.BitVectorBuilder; +import org.openfast.BitVectorReader; +import org.openfast.Context; +import org.openfast.FieldValue; +import org.openfast.QName; +import org.openfast.template.type.Type; + +public class ComposedScalar extends Field { + private static final long serialVersionUID = 1L; + private static final Class ScalarValueType = null; + private Scalar[] fields; + private ComposedValueConverter valueConverter; + private Type type; + + public ComposedScalar(String name, Type type, Scalar[] fields, boolean optional, ComposedValueConverter valueConverter) { + this(new QName(name), type, fields, optional, valueConverter); + } + + public ComposedScalar(QName name, Type type, Scalar[] fields, boolean optional, ComposedValueConverter valueConverter) { + super(name, optional); + this.fields = fields; + this.valueConverter = valueConverter; + this.type = type; + } + + public FieldValue createValue(String value) { + return type.getValue(value); + } + + public FieldValue decode(InputStream in, Group template, Context context, BitVectorReader presenceMapReader) { + FieldValue[] values = new FieldValue[fields.length]; + for (int i = 0; i < fields.length; i++) { + values[i] = fields[i].decode(in, template, context, presenceMapReader); + if (i == 0 && values[0] == null) + return null; + } + return valueConverter.compose(values); + } + + public byte[] encode(FieldValue value, Group template, Context context, BitVectorBuilder presenceMapBuilder) { + if (value == null) { + // Only encode null in the first field. + return fields[0].encode(null, template, context, presenceMapBuilder); + } else { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(fields.length * 8); + FieldValue[] values = valueConverter.split(value); + for (int i = 0; i < fields.length; i++) { + try { + buffer.write(fields[i].encode(values[i], template, context, presenceMapBuilder)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + return buffer.toByteArray(); + } + } + + public String getTypeName() { + return type.getName(); + } + + public Class getValueType() { + return ScalarValueType; + } + + public boolean isPresenceMapBitSet(byte[] encoding, FieldValue fieldValue) { + return false; + } + + public boolean usesPresenceMapBit() { + for (int i=0; i<fields.length; i++) { + if (fields[i].usesPresenceMapBit()) + return true; + } + return false; + } + + public Type getType() { + return type; + } + + public Scalar[] getFields() { + return fields; + } + + public boolean equals(Object obj) { + if (obj == this) + return true; + if (obj == null || !obj.getClass().equals(ComposedScalar.class)) + return false; + ComposedScalar other = (ComposedScalar) obj; + if (other.fields.length != fields.length) + return false; + if (!other.getName().equals(getName())) + return false; + for (int i = 0; i < fields.length; i++) { + if (!other.fields[i].getType().equals(fields[i].getType())) + return false; + if (!other.fields[i].getTypeCodec().equals(fields[i].getTypeCodec())) + return false; + if (!other.fields[i].getOperator().equals(fields[i].getOperator())) + return false; + if (!other.fields[i].getOperatorCodec().equals(fields[i].getOperatorCodec())) + return false; + if (!other.fields[i].getDefaultValue().equals(fields[i].getDefaultValue())) + return false; + if (!other.fields[i].getDictionary().equals(fields[i].getDictionary())) + return false; + } + return true; + } + + public int hashCode() { + return name.hashCode(); + } + + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Composed {"); + for (int i = 0; i < fields.length; i++) + builder.append(fields[i].toString()).append(", "); + builder.delete(builder.length() - 2, builder.length()); + return builder.append("}").toString(); + } +} Deleted: tags/openfast-1.0.0/src/site/apt/contributions.apt =================================================================== --- trunk/src/site/apt/contributions.apt 2008-06-25 03:12:39 UTC (rev 156) +++ tags/openfast-1.0.0/src/site/apt/contributions.apt 2008-07-09 20:50:20 UTC (rev 169) @@ -1,26 +0,0 @@ - ------ - Contributing to OpenFAST - ------ - Jacob Northey - ------ - 2007. 12. 07. - -Contributing to OpenFAST - -* Becoming a Committer - - * Send an e-mail to {{{mailto:su...@op...}su...@op...}} requesting to be added to the project - - * Include some background information and what you are currently using OpenFAST for - -* Submitting bugs/patches - - * Open up a {{{issue-tracking.html}bug report}} on the SourceForge project page - - * Attach any patches and comments to the bug report - -* Documentation - - * To contribute to under-documented Javadocs, see becoming a committer above. - - * Additional documentation can be added to the {{{http://openfast.wiki.sourceforge.net/}OpenFAST Wiki}} \ No newline at end of file Copied: tags/openfast-1.0.0/src/site/apt/contributions.apt (from rev 165, trunk/src/site/apt/contributions.apt) =================================================================== --- tags/openfast-1.0.0/src/site/apt/contributions.apt (rev 0) +++ tags/openfast-1.0.0/src/site/apt/contributions.apt 2008-07-09 20:50:20 UTC (rev 169) @@ -0,0 +1,26 @@ + ------ + Contributing to OpenFAST + ------ + Jacob Northey + ------ + 2008. 07. 09. + +Contributing to OpenFAST + +* Becoming a Committer + + * Send an e-mail to {{{mailto:su...@op...}su...@op...}} requesting to be added to the project + + * Include some background information and what you are currently using OpenFAST for + +* Submitting bugs/patches + + * Open up a {{{issue-tracking.html}bug report}} in Jira + + * Attach any patches and comments to the bug report + +* Documentation + + * To contribute to under-documented Javadocs, see becoming a committer above. + + * Additional documentation can be added to the {{{http://www.quickfixj.org/confluence/display/FAST/Home}OpenFAST Wiki}} \ No newline at end of file Deleted: tags/openfast-1.0.0/src/site/apt/support.apt =================================================================== --- trunk/src/site/apt/support.apt 2008-06-25 03:12:39 UTC (rev 156) +++ tags/openfast-1.0.0/src/site/apt/support.apt 2008-07-09 20:50:20 UTC (rev 169) @@ -1,24 +0,0 @@ - ------ - Support - ------ - Jacob Northey - ------ - 2007. 12. 07. - -Getting Help - -* General help with the FAST Protocol - - * Visit the FAST Protocol discussion forum: {{http://fixprotocol.org/discuss/46/all}} - -* Support using OpenFAST - - * Read the {{{faq.html}FAQ}} - - * Subscribe to {{{mail-lists.html}ope...@li...}} and submit a message - - * Send an e-mail to {{{mailto:su...@op...}su...@op...}} - -* OpenFAST Consulting - - * {{{http://www.lasalletech.com/openfast}Lasalletech}} - Originators of OpenFAST can provide support contracts and consulting services. \ No newline at end of file Copied: tags/openfast-1.0.0/src/site/apt/support.apt (from rev 166, trunk/src/site/apt/support.apt) =================================================================== --- tags/openfast-1.0.0/src/site/apt/support.apt (rev 0) +++ tags/openfast-1.0.0/src/site/apt/support.apt 2008-07-09 20:50:20 UTC (rev 169) @@ -0,0 +1,27 @@ + ------ + Support + ------ + Jacob Northey + ------ + 2008. 07. 09. + +Getting Help + + +* Support using OpenFAST + + * Read the {{{faq.html}FAQ}} + + * Subscribe to {{{mail-lists.html}ope...@li...}} and submit a message + +* Submitting Bugs/Feature Requests + + * {{{http://www.quickfixj.org/jira/browse/FAST}Jira}} is currently being used to track issues + +* General help with the FAST Protocol + + * Visit the FAST Protocol discussion forum: {{http://fixprotocol.org/discuss/46/all}} + +* OpenFAST Consulting + + * {{{http://www.lasalletech.com/openfast.html}Lasalletech}} - Originators of OpenFAST can provide support contracts and consulting services. \ No newline at end of file Deleted: tags/openfast-1.0.0/src/site/site.xml =================================================================== --- trunk/src/site/site.xml 2008-06-25 03:12:39 UTC (rev 156) +++ tags/openfast-1.0.0/src/site/site.xml 2008-07-09 20:50:20 UTC (rev 169) @@ -1,52 +0,0 @@ -<?xml version="1.0" encoding="ISO-8859-1"?> -<project name="OpenFAST"> - <bannerLeft> - <name>OpenFAST</name> - <src>images/openfast-logo.png</src> - <href>http://www.openfast.org/</href> - </bannerLeft> - <body> - <head> - <meta name="keywords" content="openfast, open fast, fast 1.1, fix, fpl, fix adapted for streaming, lasalletech, lasalle technology group"/> - </head> - <links> - <item name="OpenFAST @ SourceForge" href="https://sourceforge.net/projects/openfast" /> - <item name="FAST Interoperability Portal" href="http://technical-fixprotocol.net/fast-portal/" /> - <item name="FPL FAST" href="http://www.fixprotocol.org/fast" /> - <item name="FAST Forum" href="http://fixprotocol.org/discuss/46/all" /> - <item name="Lasalletech" href="http://www.lasalletech.com"/> - </links> - - <menu name="OpenFAST"> - <item name="Download" href="http://sourceforge.net/project/showfiles.php?group_id=198357&package_id=240515"/> - <item name="License" href="license.html"/> - </menu> - - <menu name="About OpenFAST"> - <item name="About" href="index.html"/> - <item name="FAQ" href="faq.html"/> - </menu> - - <menu name="Documentation"> - <item name="Javadocs" href="apidocs/"/> - <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"> - <item name="How to Contribute" href="contributions.html"/> - <item name="Getting Help" href="support.html"/> - </menu> - - <menu ref="reports"/> - </body> - <skin> - <groupId>org.apache.maven.skins</groupId> - <artifactId>maven-stylus-skin</artifactId> - <version>1.0.1</version> - </skin> - <poweredBy> - <logo name="SourceForge" href="http://sourceforge.net" img="http://sflogo.sourceforge.net/sflogo.php?group_id=198357&type=1"/> - <logo name="Maven" href="http://maven.apache.org/" img="images/logos/maven-feather.png"/> - </poweredBy> -</project> \ No newline at end of file Copied: tags/openfast-1.0.0/src/site/site.xml (from rev 166, trunk/src/site/site.xml) =================================================================== --- tags/openfast-1.0.0/src/site/site.xml (rev 0) +++ tags/openfast-1.0.0/src/site/site.xml 2008-07-09 20:50:20 UTC (rev 169) @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<project name="OpenFAST"> + <bannerLeft> + <name>OpenFAST</name> + <src>images/openfast-logo.png</src> + <href>http://www.openfast.org/</href> + </bannerLeft> + <body> + <head> + <meta name="keywords" content="openfast, open fast, fast 1.1, fix, fpl, fix adapted for streaming, lasalletech, lasalle technology group"/> + </head> + <links> + <item name="OpenFAST @ SourceForge" href="https://sourceforge.net/projects/openfast" /> + <item name="FAST Interoperability Portal" href="http://technical-fixprotocol.net/fast-portal/" /> + <item name="FPL FAST" href="http://www.fixprotocol.org/fast" /> + <item name="FAST Forum" href="http://fixprotocol.org/discuss/46/all" /> + <item name="Lasalletech" href="http://www.lasalletech.com"/> + </links> + + <menu name="OpenFAST"> + <item name="Download" href="http://sourceforge.net/project/showfiles.php?group_id=198357&package_id=240515"/> + <item name="License" href="license.html"/> + </menu> + + <menu name="About OpenFAST"> + <item name="About" href="index.html"/> + <item name="FAQ" href="faq.html"/> + </menu> + + <menu name="Documentation"> + <item name="Javadocs" href="apidocs/"/> + <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"> + <item name="How to Contribute" href="contributions.html"/> + <item name="Getting Help" href="support.html"/> + </menu> + + <menu ref="reports"/> + </body> + <skin> + <groupId>org.apache.maven.skins</groupId> + <artifactId>maven-stylus-skin</artifactId> + <version>1.0.1</version> + </skin> + <poweredBy> + <logo name="SourceForge" href="http://sourceforge.net" img="http://sflogo.sourceforge.net/sflogo.php?group_id=198357&type=1"/> + <logo name="Maven" href="http://maven.apache.org/" img="images/logos/build-by-maven-white.png"/> + </poweredBy> +</project> \ No newline at end of file Deleted: tags/openfast-1.0.0/src/test/java/org/openfast/session/SCP_1_1_Test.java =================================================================== --- trunk/src/test/java/org/openfast/session/SCP_1_1_Test.java 2008-06-25 03:12:39 UTC (rev 156) +++ tags/openfast-1.0.0/src/test/java/org/openfast/session/SCP_1_1_Test.java 2008-07-09 20:50:20 UTC (rev 169) @@ -1,200 +0,0 @@ -package org.openfast.session; - -import java.io.IOException; - -import junit.framework.TestCase; - -import org.openfast.Message; -import org.openfast.error.ErrorCode; -import org.openfast.error.ErrorHandler; -import org.openfast.template.BasicTemplateRegistry; -import org.openfast.template.TemplateRegistry; -import org.openfast.test.ObjectMother; -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; - - 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(); - } -} Copied: tags/openfast-1.0.0/src/test/java/org/openfast/session/SCP_1_1_Test.java (from rev 167, trunk/src/test/java/org/openfast/session/SCP_1_1_Test.java) =================================================================== --- tags/openfast-1.0.0/src/test/java/org/openfast/session/SCP_1_1_Test.java (rev 0) +++ tags/openfast-1.0.0/src/test/java/org/openfast/session/SCP_1_1_Test.java 2008-07-09 20:50:20 UTC (rev 169) @@ -0,0 +1,201 @@ +package org.openfast.session; + +import java.io.IOException; + +import junit.framework.TestCase; + +import org.openfast.Message; +import org.openfast.error.ErrorCode; +import org.openfast.error.ErrorHandler; +import org.openfast.template.BasicTemplateRegistry; +import org.openfast.template.TemplateRegistry; +import org.openfast.test.ObjectMother; +import org.openfast.util.RecordingOutputStream; + +public class SCP_1_1_Test extends TestCase { + private static final int MAX_TIMEOUT = 5000; + 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 IGNOREtestTemplateExchange() 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); + } + // TODO - Figure out why these tests occasionally fail + public void IGNOREtestReceiveTemplateDefinitionWithTemplateId() 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(); + } +} Copied: tags/openfast-1.0.0/src/test/java/org/openfast/submitted/SingleDecimalPmapTest.java (from rev 165, trunk/src/test/java/org/openfast/submitted/SingleDecimalPmapTest.java) =================================================================== --- tags/openfast-1.0.0/src/test/java/org/openfast/submitted/SingleDecimalPmapTest.java (rev 0) +++ tags/openfast-1.0.0/src/test/java/org/openfast/submitted/SingleDecimalPmapTest.java 2008-07-09 20:50:20 UTC (rev 169) @@ -0,0 +1,28 @@ +package org.openfast.submitted; + +import org.openfast.GroupValue; +import org.openfast.Message; +import org.openfast.codec.FastEncoder; +import org.openfast.template.MessageTemplate; +import org.openfast.test.OpenFastTestCase; + +public class SingleDecimalPmapTest extends OpenFastTestCase { + public void testSingleOptionalDecimalAlwaysPresentExponent() { + MessageTemplate template = template( + "<template name=\"tmpl\">" + + " <group name=\"grp\">" + + " <decimal name=\"dcml\">" + + " <exponent><delta/></exponent>" + + " <mantissa><copy/></mantissa>" + + " </decimal>" + + " </group>" + + "</template>"); + assertTrue(template.getGroup("grp").usesPresenceMap()); + FastEncoder encoder = encoder(template); + Message message = new Message(template); + GroupValue grp = new GroupValue(template.getGroup("grp")); + message.setFieldValue("grp", grp); + grp.setDecimal(0, 2.0); + assertEquals("11000000 10000001 11000000 10000000 10000010", encoder.encode(message)); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-07-09 20:50:00
|
Revision: 168 http://openfast.svn.sourceforge.net/openfast/?rev=168&view=rev Author: jacob_northey Date: 2008-07-09 13:49:17 -0700 (Wed, 09 Jul 2008) Log Message: ----------- [maven-release-plugin] prepare release openfast-1.0.0 Modified Paths: -------------- trunk/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2008-07-09 20:44:13 UTC (rev 167) +++ trunk/pom.xml 2008-07-09 20:49:17 UTC (rev 168) @@ -3,7 +3,7 @@ <groupId>org.openfast</groupId> <artifactId>openfast</artifactId> <packaging>jar</packaging> - <version>1.0.0-SNAPSHOT</version> + <version>1.0.0</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-1.0.0</connection> + <developerConnection>scm:svn:https://openfast.svn.sourceforge.net/svnroot/openfast/tags/openfast-1.0.0</developerConnection> + <url>http://openfast.svn.sourceforge.net/viewvc/openfast/tags/tags/openfast-1.0.0</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-07-09 20:45:42
|
Revision: 167 http://openfast.svn.sourceforge.net/openfast/?rev=167&view=rev Author: jacob_northey Date: 2008-07-09 13:44:13 -0700 (Wed, 09 Jul 2008) Log Message: ----------- Ignored tests that sometimes fail Modified Paths: -------------- trunk/src/test/java/org/openfast/session/SCP_1_1_Test.java 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-07-09 20:35:48 UTC (rev 166) +++ trunk/src/test/java/org/openfast/session/SCP_1_1_Test.java 2008-07-09 20:44:13 UTC (rev 167) @@ -119,7 +119,7 @@ wait0(MAX_TIMEOUT); assertEquals(1, successfullThreadsCount); } - public void testTemplateExchange() throws Exception { + public void IGNOREtestTemplateExchange() throws Exception { server.setSessionHandler(new SessionHandler() { public void newSession(Session session) { session.setListening(true); @@ -152,7 +152,8 @@ wait0(MAX_TIMEOUT); assertEquals(1, successfullThreadsCount); } - public void testReceiveTemplateDefinitionWithTemplateId() throws Exception { + // TODO - Figure out why these tests occasionally fail + public void IGNOREtestReceiveTemplateDefinitionWithTemplateId() throws Exception { server.setSessionHandler(new SessionHandler() { public void newSession(Session session) { session.setListening(true); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-07-09 20:36:08
|
Revision: 166 http://openfast.svn.sourceforge.net/openfast/?rev=166&view=rev Author: jacob_northey Date: 2008-07-09 13:35:48 -0700 (Wed, 09 Jul 2008) Log Message: ----------- Updated support link to Lasalletech Modified Paths: -------------- trunk/src/site/apt/support.apt trunk/src/site/site.xml Modified: trunk/src/site/apt/support.apt =================================================================== --- trunk/src/site/apt/support.apt 2008-07-09 15:48:21 UTC (rev 165) +++ trunk/src/site/apt/support.apt 2008-07-09 20:35:48 UTC (rev 166) @@ -24,4 +24,4 @@ * OpenFAST Consulting - * {{{http://www.lasalletech.com/openfast}Lasalletech}} - Originators of OpenFAST can provide support contracts and consulting services. \ No newline at end of file + * {{{http://www.lasalletech.com/openfast.html}Lasalletech}} - Originators of OpenFAST can provide support contracts and consulting services. \ No newline at end of file Modified: trunk/src/site/site.xml =================================================================== --- trunk/src/site/site.xml 2008-07-09 15:48:21 UTC (rev 165) +++ trunk/src/site/site.xml 2008-07-09 20:35:48 UTC (rev 166) @@ -47,6 +47,6 @@ </skin> <poweredBy> <logo name="SourceForge" href="http://sourceforge.net" img="http://sflogo.sourceforge.net/sflogo.php?group_id=198357&type=1"/> - <logo name="Maven" href="http://maven.apache.org/" img="images/logos/maven-feather.png"/> + <logo name="Maven" href="http://maven.apache.org/" img="images/logos/build-by-maven-white.png"/> </poweredBy> </project> \ 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-07-09 15:48:18
|
Revision: 165 http://openfast.svn.sourceforge.net/openfast/?rev=165&view=rev Author: jacob_northey Date: 2008-07-09 08:48:21 -0700 (Wed, 09 Jul 2008) Log Message: ----------- [FAST-5] Fixed single decimal pmap bug; updated web site Modified Paths: -------------- trunk/src/main/java/org/openfast/template/ComposedScalar.java trunk/src/site/apt/contributions.apt trunk/src/site/apt/support.apt trunk/src/test/java/org/openfast/session/SCP_1_1_Test.java Added Paths: ----------- trunk/src/test/java/org/openfast/submitted/SingleDecimalPmapTest.java Modified: trunk/src/main/java/org/openfast/template/ComposedScalar.java =================================================================== --- trunk/src/main/java/org/openfast/template/ComposedScalar.java 2008-07-09 02:24:06 UTC (rev 164) +++ trunk/src/main/java/org/openfast/template/ComposedScalar.java 2008-07-09 15:48:21 UTC (rev 165) @@ -93,6 +93,10 @@ } public boolean usesPresenceMapBit() { + for (int i=0; i<fields.length; i++) { + if (fields[i].usesPresenceMapBit()) + return true; + } return false; } Modified: trunk/src/site/apt/contributions.apt =================================================================== --- trunk/src/site/apt/contributions.apt 2008-07-09 02:24:06 UTC (rev 164) +++ trunk/src/site/apt/contributions.apt 2008-07-09 15:48:21 UTC (rev 165) @@ -3,7 +3,7 @@ ------ Jacob Northey ------ - 2007. 12. 07. + 2008. 07. 09. Contributing to OpenFAST @@ -15,7 +15,7 @@ * Submitting bugs/patches - * Open up a {{{issue-tracking.html}bug report}} on the SourceForge project page + * Open up a {{{issue-tracking.html}bug report}} in Jira * Attach any patches and comments to the bug report @@ -23,4 +23,4 @@ * To contribute to under-documented Javadocs, see becoming a committer above. - * Additional documentation can be added to the {{{http://openfast.wiki.sourceforge.net/}OpenFAST Wiki}} \ No newline at end of file + * Additional documentation can be added to the {{{http://www.quickfixj.org/confluence/display/FAST/Home}OpenFAST Wiki}} \ No newline at end of file Modified: trunk/src/site/apt/support.apt =================================================================== --- trunk/src/site/apt/support.apt 2008-07-09 02:24:06 UTC (rev 164) +++ trunk/src/site/apt/support.apt 2008-07-09 15:48:21 UTC (rev 165) @@ -3,22 +3,25 @@ ------ Jacob Northey ------ - 2007. 12. 07. + 2008. 07. 09. Getting Help -* General help with the FAST Protocol - * Visit the FAST Protocol discussion forum: {{http://fixprotocol.org/discuss/46/all}} - * Support using OpenFAST * Read the {{{faq.html}FAQ}} - + * Subscribe to {{{mail-lists.html}ope...@li...}} and submit a message - * Send an e-mail to {{{mailto:su...@op...}su...@op...}} - +* Submitting Bugs/Feature Requests + + * {{{http://www.quickfixj.org/jira/browse/FAST}Jira}} is currently being used to track issues + +* General help with the FAST Protocol + + * Visit the FAST Protocol discussion forum: {{http://fixprotocol.org/discuss/46/all}} + * OpenFAST Consulting * {{{http://www.lasalletech.com/openfast}Lasalletech}} - Originators of OpenFAST can provide support contracts and consulting services. \ No newline at end of file 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-07-09 02:24:06 UTC (rev 164) +++ trunk/src/test/java/org/openfast/session/SCP_1_1_Test.java 2008-07-09 15:48:21 UTC (rev 165) @@ -13,7 +13,7 @@ import org.openfast.util.RecordingOutputStream; public class SCP_1_1_Test extends TestCase { - private static final int MAX_TIMEOUT = 15000; + private static final int MAX_TIMEOUT = 5000; private LocalEndpoint serverEndpoint; private RecordingEndpoint clientEndpoint; private FastServer server; Added: trunk/src/test/java/org/openfast/submitted/SingleDecimalPmapTest.java =================================================================== --- trunk/src/test/java/org/openfast/submitted/SingleDecimalPmapTest.java (rev 0) +++ trunk/src/test/java/org/openfast/submitted/SingleDecimalPmapTest.java 2008-07-09 15:48:21 UTC (rev 165) @@ -0,0 +1,28 @@ +package org.openfast.submitted; + +import org.openfast.GroupValue; +import org.openfast.Message; +import org.openfast.codec.FastEncoder; +import org.openfast.template.MessageTemplate; +import org.openfast.test.OpenFastTestCase; + +public class SingleDecimalPmapTest extends OpenFastTestCase { + public void testSingleOptionalDecimalAlwaysPresentExponent() { + MessageTemplate template = template( + "<template name=\"tmpl\">" + + " <group name=\"grp\">" + + " <decimal name=\"dcml\">" + + " <exponent><delta/></exponent>" + + " <mantissa><copy/></mantissa>" + + " </decimal>" + + " </group>" + + "</template>"); + assertTrue(template.getGroup("grp").usesPresenceMap()); + FastEncoder encoder = encoder(template); + Message message = new Message(template); + GroupValue grp = new GroupValue(template.getGroup("grp")); + message.setFieldValue("grp", grp); + grp.setDecimal(0, 2.0); + assertEquals("11000000 10000001 11000000 10000000 10000010", encoder.encode(message)); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-07-09 02:23:59
|
Revision: 164 http://openfast.svn.sourceforge.net/openfast/?rev=164&view=rev Author: jacob_northey Date: 2008-07-08 19:24:06 -0700 (Tue, 08 Jul 2008) Log Message: ----------- Implemented ConstantIntegerCodec and CopyIntegerCodec Modified Paths: -------------- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast1_1Implementation.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DictionaryOperator.java branches/openfast-2.x/core/src/test/java/org/openfast/test/OpenFastTestCase.java Added Paths: ----------- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/FastTypeCodecs.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableUnsignedIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/SignedIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/StopBitEncodedTypeCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/UnsignedIntegerCodec.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/ branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/CopyIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastOperatorTestHarness.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/IncrementIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/ branches/openfast-2.x/core/src/test/java/org/openfast/codec/type/SignedIntegerCodecTest.java Removed Paths: ------------- branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/StopBitEncodedTypeCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/UnsignedIntegerCodec.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/SignedIntegerCodecTest.java Property Changed: ---------------- branches/openfast-2.x/core/ Property changes on: branches/openfast-2.x/core ___________________________________________________________________ Name: svn:ignore - target .classpath .project .settings + target .classpath .project .settings bin Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Context.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-07-08 12:25:27 UTC (rev 163) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-07-09 02:24:06 UTC (rev 164) @@ -22,7 +22,6 @@ import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import org.lasalletech.exom.QName; @@ -44,10 +43,10 @@ public class Context { private TemplateRegistry templateRegistry = new BasicTemplateRegistry(); private int lastTemplateId; - private Map dictionaries = new HashMap(); + private Map<String, FastDictionary> dictionaries = new HashMap<String, FastDictionary>(); private ErrorHandler errorHandler = ErrorHandler.DEFAULT; private QName currentApplicationType; - private List listeners = Collections.EMPTY_LIST; + private List<TemplateRegisteredListener> listeners = Collections.emptyList(); private boolean traceEnabled; private byte[] tempBuffer = new byte[1024 * 32]; // max 32 kB message size @@ -71,9 +70,8 @@ } public void registerTemplate(int templateId, MessageTemplate template) { templateRegistry.register(templateId, template); - Iterator iter = listeners.iterator(); - while (iter.hasNext()) { - ((TemplateRegisteredListener) iter.next()).templateRegistered(template, templateId); + for (TemplateRegisteredListener listener : listeners) { + listener.templateRegistered(template, templateId); } } public int getLastTemplateId() { @@ -98,14 +96,16 @@ getDictionary(dictionary).store(null, currentApplicationType, key, value); } public void reset() { - for (Iterator iter = dictionaries.values().iterator(); iter.hasNext();) { - FastDictionary dict = (FastDictionary) iter.next(); + for (FastDictionary dict : dictionaries.values()) { dict.reset(); } } public void setErrorHandler(ErrorHandler errorHandler) { this.errorHandler = errorHandler; } + public ErrorHandler getErrorHandler() { + return errorHandler; + } public void newMessage(MessageTemplate template) { currentApplicationType = (template.hasTypeReference()) ? template.getTypeReference() : FastConstants.ANY_TYPE; } @@ -130,4 +130,7 @@ public void discardTemporaryBuffer(byte[] buffer) { tempBuffer = buffer; } + public QName getCurrentApplicationType() { + return null; + } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java 2008-07-08 12:25:27 UTC (rev 163) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java 2008-07-09 02:24:06 UTC (rev 164) @@ -3,4 +3,5 @@ public class Fast { public static final byte STOP_BIT = (byte) 0x80; public static final String GLOBAL = "global"; + public static final byte NULL = STOP_BIT; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java 2008-07-08 12:25:27 UTC (rev 163) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java 2008-07-09 02:24:06 UTC (rev 164) @@ -4,6 +4,7 @@ import org.openfast.template.Scalar; import org.openfast.template.Type; import org.openfast.template.operator.DictionaryOperator; +import org.openfast.codec.operator.IncrementIntegerCodec; public class BasicCodecFactory implements CodecFactory { public MessageCodec createCodec(int id, MessageTemplate template, TypeCodecRegistry typeCodecRegistry) { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java 2008-07-08 12:25:27 UTC (rev 163) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java 2008-07-09 02:24:06 UTC (rev 164) @@ -2,8 +2,10 @@ import org.lasalletech.exom.EObject; import org.openfast.Context; +import org.openfast.template.Scalar; public interface FieldCodec<T> { int decode(EObject object, int index, byte[] buffer, int offset, T field, Context context); + void decodeEmpty(EObject object, int index, Scalar scalar, Context context); int encode(EObject object, int index, byte[] buffer, int offset, T field, Context context); } Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java 2008-07-08 12:25:27 UTC (rev 163) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java 2008-07-09 02:24:06 UTC (rev 164) @@ -1,131 +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.codec; - -import org.lasalletech.exom.EObject; -import org.lasalletech.exom.QName; -import org.openfast.Context; -import org.openfast.Fast; -import org.openfast.dictionary.FastDictionary; -import org.openfast.error.FastConstants; -import org.openfast.template.Scalar; - -final class IncrementIntegerCodec implements ScalarCodec { - private static final long serialVersionUID = 1L; - private final IntegerCodec integerCodec; - private String dictionary = Fast.GLOBAL; - - public void setDictionary(String dictionary) { - this.dictionary = dictionary; - } - - private final int defaultValue; - private final boolean hasDefaultValue; - - public IncrementIntegerCodec(IntegerCodec integerCodec) { - this.integerCodec = integerCodec; - this.hasDefaultValue = false; - this.defaultValue = 0; - } - - public IncrementIntegerCodec(IntegerCodec integerCodec, int defaultValue) { - this.integerCodec = integerCodec; - this.hasDefaultValue = true; - this.defaultValue = defaultValue; - } - - public int decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { - int length = integerCodec.getLength(buffer, offset); - int value = integerCodec.decode(buffer, offset); - context.getDictionary(dictionary).store(object.getEntity(), scalar.getKey(), null, value); - object.set(index, value); - return offset + length; - } - - public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { - FastDictionary dictionary = context.getDictionary(this.dictionary); - if (dictionary.isNull(object, scalar.getKey(), null)) { - // leave object value set to null - dictionary.storeNull(object.getEntity(), scalar.getKey(), null); - } else if (!dictionary.isDefined(object, scalar.getKey(), null)) { - if (hasDefaultValue) { - object.set(index, defaultValue); - dictionary.store(object.getEntity(), scalar.getKey(), null, defaultValue); - } else { - if (!scalar.isOptional()) { - throw new IllegalStateException("Field with operator increment must send a value if no previous value existed."); - } else { - // leave object value set to null - dictionary.storeNull(object.getEntity(), scalar.getKey(), null); - } - } - } else { - int previousValue = dictionary.lookupInt(object.getEntity(), scalar.getKey(), null); - object.set(index, previousValue + 1); - dictionary.store(object.getEntity(), scalar.getKey(), null, previousValue + 1); - } - } - - public int getLength(byte[] buffer, int offset) { - return integerCodec.getLength(buffer, offset); - } - - public int encode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { - FastDictionary dictionary = context.getDictionary(this.dictionary); - QName key = scalar.getKey(); - if (!object.isDefined(index)) { - if (!scalar.isOptional()) { - // TODO - error when value is null and scalar is mandatory - } - if (dictionary.isNull(object, key, null)) - return offset; - else { - return encodeNull(buffer, offset, dictionary, key); - } - } - int value = object.getInt(index); - if (dictionary.isNull(object, key, null)) { - dictionary.store(null, key, null, value); - return integerCodec.encode(buffer, offset, value); - } - if (!dictionary.isDefined(object, key, null)) { - if (!hasDefaultValue) { - dictionary.store(null, key, null, value); - return integerCodec.encode(buffer, offset, value); - } else if (hasDefaultValue && value == defaultValue) { - return offset; - } else { - return integerCodec.encode(buffer, offset, value); - } - } - int previousValue = dictionary.lookupInt(null, key, null); - if (value == previousValue + 1) { - return offset; - } - return integerCodec.encode(buffer, offset, value); - } - - private int encodeNull(byte[] buffer, int offset, FastDictionary dictionary, QName key) { - buffer[offset] = FastConstants.NULL_BYTE; - dictionary.storeNull(null, key, null); - return offset + 1; - } -} \ No newline at end of file Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodec.java 2008-07-08 12:25:27 UTC (rev 163) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodec.java 2008-07-09 02:24:06 UTC (rev 164) @@ -1,76 +0,0 @@ -package org.openfast.codec; - -import org.openfast.Fast; - - - -public class SignedIntegerCodec extends StopBitEncodedTypeCodec implements IntegerCodec { - - public int decode(byte[] buffer, int offset) { - int value = 0; - int byt = buffer[offset]; - if ((byt & 0x40) > 0) { - value = -1; - } - value = (value << 7) | (byt & 0x7f); - while ((byt & 0x80) == 0) { - byt = buffer[++offset]; - value = (value << 7) | (byt & 0x7f); - } - return value; - } - - public int encode(byte[] buffer, int offset, int value) { - int index = offset; - int size = getSignedIntegerSize(value); - for (int factor = 0; factor < size; factor++) { - int bitMask = (factor == (size - 1)) ? 0x3f : 0x7f; - buffer[offset + size - factor - 1] = (byte) ((value >> (factor * 7)) & bitMask); - index++; - } - // Get the sign bit from the long value and set it on the first byte - // 01000000 00000000 ... 00000000 - // ^----SIGN BIT - buffer[offset] |= (0x40 & (value >> 57)); - buffer[index - 1] |= Fast.STOP_BIT; - return index; - } - - /** - * Find the signed integer size for the passed long value - * - * @param value - * The long value to be used to get the signed integer size - * @return Returns an integer of the appropriate signed integer - */ - public static int getSignedIntegerSize(long value) { - if ((value >= -64) && (value <= 63)) { - return 1; // - 2 ^ 6 ... 2 ^ 6 -1 - } - if ((value >= -8192) && (value <= 8191)) { - return 2; // - 2 ^ 13 ... 2 ^ 13 -1 - } - if ((value >= -1048576) && (value <= 1048575)) { - return 3; // - 2 ^ 20 ... 2 ^ 20 -1 - } - if ((value >= -134217728) && (value <= 134217727)) { - return 4; // - 2 ^ 27 ... 2 ^ 27 -1 - } - if ((value >= -17179869184L) && (value <= 17179869183L)) { - return 5; // - 2 ^ 34 ... 2 ^ 34 -1 - } - if ((value >= -2199023255552L) && (value <= 2199023255551L)) { - return 6; // - 2 ^ 41 ... 2 ^ 41 -1 - } - if ((value >= -281474976710656L) && (value <= 281474976710655L)) { - return 7; // - 2 ^ 48 ... 2 ^ 48 -1 - } - if ((value >= -36028797018963968L) && (value <= 36028797018963967L)) { - return 8; // - 2 ^ 55 ... 2 ^ 55 -1 - } - if ((value >= -4611686018427387904L && value <= 4611686018427387903L)) { - return 9; - } - return 10; - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/codec/StopBitEncodedTypeCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/StopBitEncodedTypeCodec.java 2008-07-08 12:25:27 UTC (rev 163) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/StopBitEncodedTypeCodec.java 2008-07-09 02:24:06 UTC (rev 164) @@ -1,12 +0,0 @@ -package org.openfast.codec; - -public class StopBitEncodedTypeCodec { - public int getLength(byte[] buffer, int offset) { - if (offset >= buffer.length) return -1; - int length = 1; - while ((((int) buffer[offset++]) & 0x80) == 0) { - length++; - } - return length; - } -} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodec.java 2008-07-08 12:25:27 UTC (rev 163) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodec.java 2008-07-09 02:24:06 UTC (rev 164) @@ -2,4 +2,5 @@ public interface TypeCodec { int getLength(byte[] buffer, int offset); + boolean isNull(byte[] buffer, int offset); } Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/codec/UnsignedIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/UnsignedIntegerCodec.java 2008-07-08 12:25:27 UTC (rev 163) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/UnsignedIntegerCodec.java 2008-07-09 02:24:06 UTC (rev 164) @@ -1,58 +0,0 @@ -package org.openfast.codec; - -import org.openfast.Fast; - - -public class UnsignedIntegerCodec extends StopBitEncodedTypeCodec implements IntegerCodec { - public int decode(byte[] buffer, int offset) { - int value = 0; - int index = offset; - do { - value = (value << 7) | (buffer[index] & 0x7f); - } while ((buffer[index] & 0x80) == 0); - return value; - } - - public int encode(byte[] buffer, int offset, int value) { - int size = getUnsignedIntegerSize(value); - for (int factor = 0; factor < size; factor++) { - buffer[size - factor - 1 + offset] = (byte) ((value >> (factor * 7)) & 0x7f); - } - buffer[offset + size - 1] |= Fast.STOP_BIT; - return offset + size; - } - - /** - * - * @param value - * The long to determine the unsigned integer - * @return Returns an unsigned integer - */ - public static int getUnsignedIntegerSize(long value) { - if (value < 128) { - return 1; // 2 ^ 7 - } - if (value <= 16384) { - return 2; // 2 ^ 14 - } - if (value <= 2097152) { - return 3; // 2 ^ 21 - } - if (value <= 268435456) { - return 4; // 2 ^ 28 - } - if (value <= 34359738368L) { - return 5; // 2 ^ 35 - } - if (value <= 4398046511104L) { - return 6; // 2 ^ 42 - } - if (value <= 562949953421312L) { - return 7; // 2 ^ 49 - } - if (value <= 72057594037927936L) { - return 8; // 2 ^ 56 - } - return 9; - } -} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantIntegerCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/ConstantIntegerCodec.java 2008-07-09 02:24:06 UTC (rev 164) @@ -0,0 +1,29 @@ +package org.openfast.codec.operator; + +import org.lasalletech.exom.EObject; +import org.openfast.Context; +import org.openfast.codec.ScalarCodec; +import org.openfast.template.Scalar; + +public class ConstantIntegerCodec implements ScalarCodec { + private final int defaultValue; + + public ConstantIntegerCodec(int defaultValue) { + this.defaultValue = defaultValue; + } + public int getLength(byte[] buffer, int offset) { + return 0; + } + + public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + object.set(index, defaultValue); + return offset; + } + + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + return offset; + } + public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { + object.set(index, defaultValue); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/CopyIntegerCodec.java 2008-07-09 02:24:06 UTC (rev 164) @@ -0,0 +1,78 @@ +package org.openfast.codec.operator; + +import org.lasalletech.exom.EObject; +import org.openfast.Context; +import org.openfast.Fast; +import org.openfast.codec.IntegerCodec; +import org.openfast.codec.ScalarCodec; +import org.openfast.dictionary.FastDictionary; +import org.openfast.template.Scalar; +import org.openfast.template.operator.DictionaryOperator; + +public class CopyIntegerCodec implements ScalarCodec { + private final IntegerCodec integerCodec; + private final int defaultValue; + private final DictionaryOperator operator; + + public CopyIntegerCodec(DictionaryOperator operator, IntegerCodec integerCodec) { + this.operator = operator; + this.integerCodec = integerCodec; + this.defaultValue = (operator.hasDefaultValue()) ? Integer.parseInt(operator.getDefaultValue()) : 0; + } + + public int getLength(byte[] buffer, int offset) { + throw new UnsupportedOperationException(); + } + + public int decode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + FastDictionary dictionary = context.getDictionary(operator.getDictionary()); + if (integerCodec.isNull(buffer, offset)) { + dictionary.storeNull(object.getEntity(), operator.getKey(), context.getCurrentApplicationType()); + return offset + 1; + } + int value = integerCodec.decode(buffer, offset); + object.set(index, value); + dictionary.store(object.getEntity(), operator.getKey(), context.getCurrentApplicationType(), value); + return integerCodec.getLength(buffer, offset) + offset; + } + + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar field, Context context) { + FastDictionary dictionary = context.getDictionary(operator.getDictionary()); + boolean dictionaryUndefined = !dictionary.isDefined(object, operator.getKey(), context.getCurrentApplicationType()); + boolean dictionaryNull = dictionary.isNull(object, operator.getKey(), context.getCurrentApplicationType()); + if (!object.isDefined(index)) { + dictionary.storeNull(object.getEntity(), operator.getKey(), context.getCurrentApplicationType()); + if ((dictionaryUndefined && !operator.hasDefaultValue()) || dictionaryNull) { + return offset; + } else { + buffer[offset] = Fast.NULL; + return offset+1; + } + } + int value = object.getInt(index); + if (dictionaryUndefined) { + if ((operator.hasDefaultValue() && defaultValue == value)) { + dictionary.store(object.getEntity(), operator.getKey(), context.getCurrentApplicationType(), value); + return offset; + } + } else if (!dictionaryNull) { + if (dictionary.lookupInt(object.getEntity(), operator.getKey(), context.getCurrentApplicationType()) == value) { + dictionary.store(object.getEntity(), operator.getKey(), context.getCurrentApplicationType(), value); + return offset; + } + } + int newOffset = integerCodec.encode(buffer, offset, value); + dictionary.store(object.getEntity(), operator.getKey(), context.getCurrentApplicationType(), value); + return newOffset; + } + + public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { + FastDictionary dictionary = context.getDictionary(operator.getDictionary()); + if (dictionary.isNull(object, operator.getKey(), context.getCurrentApplicationType())) + return; + if (dictionary.isDefined(object, operator.getKey(), context.getCurrentApplicationType())) + object.set(index, dictionary.lookupInt(object.getEntity(), operator.getKey(), null)); + else if (operator.hasDefaultValue()) + object.set(index, defaultValue); + } +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java (from rev 163, branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/operator/IncrementIntegerCodec.java 2008-07-09 02:24:06 UTC (rev 164) @@ -0,0 +1,133 @@ +/* +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.codec.operator; + +import org.lasalletech.exom.EObject; +import org.lasalletech.exom.QName; +import org.openfast.Context; +import org.openfast.Fast; +import org.openfast.codec.IntegerCodec; +import org.openfast.codec.ScalarCodec; +import org.openfast.dictionary.FastDictionary; +import org.openfast.error.FastConstants; +import org.openfast.template.Scalar; + +public final class IncrementIntegerCodec implements ScalarCodec { + private static final long serialVersionUID = 1L; + private final IntegerCodec integerCodec; + private String dictionary = Fast.GLOBAL; + + public void setDictionary(String dictionary) { + this.dictionary = dictionary; + } + + private final int defaultValue; + private final boolean hasDefaultValue; + + public IncrementIntegerCodec(IntegerCodec integerCodec) { + this.integerCodec = integerCodec; + this.hasDefaultValue = false; + this.defaultValue = 0; + } + + public IncrementIntegerCodec(IntegerCodec integerCodec, int defaultValue) { + this.integerCodec = integerCodec; + this.hasDefaultValue = true; + this.defaultValue = defaultValue; + } + + public int decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { + int length = integerCodec.getLength(buffer, offset); + int value = integerCodec.decode(buffer, offset); + context.getDictionary(dictionary).store(object.getEntity(), scalar.getKey(), null, value); + object.set(index, value); + return offset + length; + } + + public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { + FastDictionary dictionary = context.getDictionary(this.dictionary); + if (dictionary.isNull(object, scalar.getKey(), null)) { + // leave object value set to null + dictionary.storeNull(object.getEntity(), scalar.getKey(), null); + } else if (!dictionary.isDefined(object, scalar.getKey(), null)) { + if (hasDefaultValue) { + object.set(index, defaultValue); + dictionary.store(object.getEntity(), scalar.getKey(), null, defaultValue); + } else { + if (!scalar.isOptional()) { + throw new IllegalStateException("Field with operator increment must send a value if no previous value existed."); + } else { + // leave object value set to null + dictionary.storeNull(object.getEntity(), scalar.getKey(), null); + } + } + } else { + int previousValue = dictionary.lookupInt(object.getEntity(), scalar.getKey(), null); + object.set(index, previousValue + 1); + dictionary.store(object.getEntity(), scalar.getKey(), null, previousValue + 1); + } + } + + public int getLength(byte[] buffer, int offset) { + return integerCodec.getLength(buffer, offset); + } + + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { + FastDictionary dictionary = context.getDictionary(this.dictionary); + QName key = scalar.getKey(); + if (!object.isDefined(index)) { + if (!scalar.isOptional()) { + // TODO - error when value is null and scalar is mandatory + } + if (dictionary.isNull(object, key, null)) + return offset; + else { + return encodeNull(buffer, offset, dictionary, key); + } + } + int value = object.getInt(index); + if (dictionary.isNull(object, key, null)) { + dictionary.store(null, key, null, value); + return integerCodec.encode(buffer, offset, value); + } + if (!dictionary.isDefined(object, key, null)) { + if (!hasDefaultValue) { + dictionary.store(null, key, null, value); + return integerCodec.encode(buffer, offset, value); + } else if (hasDefaultValue && value == defaultValue) { + return offset; + } else { + return integerCodec.encode(buffer, offset, value); + } + } + int previousValue = dictionary.lookupInt(null, key, null); + if (value == previousValue + 1) { + return offset; + } + return integerCodec.encode(buffer, offset, value); + } + + private int encodeNull(byte[] buffer, int offset, FastDictionary dictionary, QName key) { + buffer[offset] = FastConstants.NULL_BYTE; + dictionary.storeNull(null, key, null); + return offset + 1; + } +} \ No newline at end of file Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/FastTypeCodecs.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/FastTypeCodecs.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/FastTypeCodecs.java 2008-07-09 02:24:06 UTC (rev 164) @@ -0,0 +1,9 @@ +package org.openfast.codec.type; + +import org.openfast.codec.IntegerCodec; + +public class FastTypeCodecs { + public static final IntegerCodec UNSIGNED_INTEGER = new UnsignedIntegerCodec(); + public static final IntegerCodec SIGNED_INTEGER = new SignedIntegerCodec(); + public static final IntegerCodec NULLABLE_UNSIGNED_INTEGER = new NullableUnsignedIntegerCodec(); +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableUnsignedIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableUnsignedIntegerCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/NullableUnsignedIntegerCodec.java 2008-07-09 02:24:06 UTC (rev 164) @@ -0,0 +1,18 @@ +package org.openfast.codec.type; + +import org.openfast.Fast; +import org.openfast.codec.IntegerCodec; + +public class NullableUnsignedIntegerCodec extends StopBitEncodedTypeCodec implements IntegerCodec { + public int decode(byte[] buffer, int offset) { + return FastTypeCodecs.UNSIGNED_INTEGER.decode(buffer, offset) - 1; + } + + public int encode(byte[] buffer, int offset, int value) { + return FastTypeCodecs.UNSIGNED_INTEGER.encode(buffer, offset, value + 1); + } + + public boolean isNull(byte[] buffer, int offset) { + return buffer[offset] == Fast.NULL; + } +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/SignedIntegerCodec.java (from rev 163, branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodec.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/SignedIntegerCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/SignedIntegerCodec.java 2008-07-09 02:24:06 UTC (rev 164) @@ -0,0 +1,80 @@ +package org.openfast.codec.type; + +import org.openfast.Fast; +import org.openfast.codec.IntegerCodec; + + + +public class SignedIntegerCodec extends StopBitEncodedTypeCodec implements IntegerCodec { + public int decode(byte[] buffer, int offset) { + int value = 0; + int byt = buffer[offset]; + if ((byt & 0x40) > 0) { + value = -1; + } + value = (value << 7) | (byt & 0x7f); + while ((byt & 0x80) == 0) { + byt = buffer[++offset]; + value = (value << 7) | (byt & 0x7f); + } + return value; + } + + public int encode(byte[] buffer, int offset, int value) { + int index = offset; + int size = getSignedIntegerSize(value); + for (int factor = 0; factor < size; factor++) { + int bitMask = (factor == (size - 1)) ? 0x3f : 0x7f; + buffer[offset + size - factor - 1] = (byte) ((value >> (factor * 7)) & bitMask); + index++; + } + // Get the sign bit from the long value and set it on the first byte + // 01000000 00000000 ... 00000000 + // ^----SIGN BIT + buffer[offset] |= (0x40 & (value >> 57)); + buffer[index - 1] |= Fast.STOP_BIT; + return index; + } + + /** + * Find the signed integer size for the passed long value + * + * @param value + * The long value to be used to get the signed integer size + * @return Returns an integer of the appropriate signed integer + */ + public static int getSignedIntegerSize(long value) { + if ((value >= -64) && (value <= 63)) { + return 1; // - 2 ^ 6 ... 2 ^ 6 -1 + } + if ((value >= -8192) && (value <= 8191)) { + return 2; // - 2 ^ 13 ... 2 ^ 13 -1 + } + if ((value >= -1048576) && (value <= 1048575)) { + return 3; // - 2 ^ 20 ... 2 ^ 20 -1 + } + if ((value >= -134217728) && (value <= 134217727)) { + return 4; // - 2 ^ 27 ... 2 ^ 27 -1 + } + if ((value >= -17179869184L) && (value <= 17179869183L)) { + return 5; // - 2 ^ 34 ... 2 ^ 34 -1 + } + if ((value >= -2199023255552L) && (value <= 2199023255551L)) { + return 6; // - 2 ^ 41 ... 2 ^ 41 -1 + } + if ((value >= -281474976710656L) && (value <= 281474976710655L)) { + return 7; // - 2 ^ 48 ... 2 ^ 48 -1 + } + if ((value >= -36028797018963968L) && (value <= 36028797018963967L)) { + return 8; // - 2 ^ 55 ... 2 ^ 55 -1 + } + if ((value >= -4611686018427387904L && value <= 4611686018427387903L)) { + return 9; + } + return 10; + } + + public boolean isNull(byte[] buffer, int offset) { + return false; + } +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/StopBitEncodedTypeCodec.java (from rev 159, branches/openfast-2.x/core/src/main/java/org/openfast/codec/StopBitEncodedTypeCodec.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/StopBitEncodedTypeCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/StopBitEncodedTypeCodec.java 2008-07-09 02:24:06 UTC (rev 164) @@ -0,0 +1,12 @@ +package org.openfast.codec.type; + +public class StopBitEncodedTypeCodec { + public int getLength(byte[] buffer, int offset) { + if (offset >= buffer.length) return -1; + int length = 1; + while ((((int) buffer[offset++]) & 0x80) == 0) { + length++; + } + return length; + } +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/UnsignedIntegerCodec.java (from rev 163, branches/openfast-2.x/core/src/main/java/org/openfast/codec/UnsignedIntegerCodec.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/UnsignedIntegerCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/type/UnsignedIntegerCodec.java 2008-07-09 02:24:06 UTC (rev 164) @@ -0,0 +1,63 @@ +package org.openfast.codec.type; + +import org.openfast.Fast; +import org.openfast.codec.IntegerCodec; + + +public class UnsignedIntegerCodec extends StopBitEncodedTypeCodec implements IntegerCodec { + public int decode(byte[] buffer, int offset) { + int value = 0; + int index = offset; + do { + value = (value << 7) | (buffer[index] & 0x7f); + } while ((buffer[index] & 0x80) == 0); + return value; + } + + public int encode(byte[] buffer, int offset, int value) { + int size = getUnsignedIntegerSize(value); + for (int factor = 0; factor < size; factor++) { + buffer[size - factor - 1 + offset] = (byte) ((value >> (factor * 7)) & 0x7f); + } + buffer[offset + size - 1] |= Fast.STOP_BIT; + return offset + size; + } + + /** + * + * @param value + * The long to determine the unsigned integer + * @return Returns an unsigned integer + */ + public static int getUnsignedIntegerSize(long value) { + if (value < 128) { + return 1; // 2 ^ 7 + } + if (value <= 16384) { + return 2; // 2 ^ 14 + } + if (value <= 2097152) { + return 3; // 2 ^ 21 + } + if (value <= 268435456) { + return 4; // 2 ^ 28 + } + if (value <= 34359738368L) { + return 5; // 2 ^ 35 + } + if (value <= 4398046511104L) { + return 6; // 2 ^ 42 + } + if (value <= 562949953421312L) { + return 7; // 2 ^ 49 + } + if (value <= 72057594037927936L) { + return 8; // 2 ^ 56 + } + return 9; + } + + public boolean isNull(byte[] buffer, int offset) { + return false; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java 2008-07-08 12:25:27 UTC (rev 163) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java 2008-07-09 02:24:06 UTC (rev 164) @@ -28,9 +28,20 @@ entry.setNext(new IntegerEntry(key, value)); return; } - entry = entry.getNext(); + Entry next = entry.getNext(); + if (next.matches(key) && next instanceof NullEntry) { + entry.setNext(new IntegerEntry(key, value)); + entry.getNext().setNext(next.getNext()); + return; + } + entry = next; } - entry.setInt(value); + if (entry instanceof NullEntry) { + entry = new IntegerEntry(key, value); + entries[index] = entry; + } else { + entry.setInt(value); + } } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast1_1Implementation.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast1_1Implementation.java 2008-07-08 12:25:27 UTC (rev 163) +++ branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast1_1Implementation.java 2008-07-09 02:24:06 UTC (rev 164) @@ -5,9 +5,8 @@ import org.openfast.codec.BasicCodecFactory; import org.openfast.codec.BasicTypeCodecRegistry; import org.openfast.codec.CodecFactory; -import org.openfast.codec.SignedIntegerCodec; import org.openfast.codec.TypeCodecRegistry; -import org.openfast.codec.UnsignedIntegerCodec; +import org.openfast.codec.type.FastTypeCodecs; import org.openfast.fast.FastTypes; import org.openfast.template.BasicTypeRegistry; import org.openfast.template.TypeRegistry; @@ -92,14 +91,14 @@ public TypeCodecRegistry getTypeCodecRegistry() { if (typeCodecRegistry == null) { typeCodecRegistry = new BasicTypeCodecRegistry(); - typeCodecRegistry.register(FastTypes.I8, new SignedIntegerCodec()); - typeCodecRegistry.register(FastTypes.I16, new SignedIntegerCodec()); - typeCodecRegistry.register(FastTypes.I32, new SignedIntegerCodec()); - typeCodecRegistry.register(FastTypes.I64, new SignedIntegerCodec()); - typeCodecRegistry.register(FastTypes.U8, new UnsignedIntegerCodec()); - typeCodecRegistry.register(FastTypes.U16, new UnsignedIntegerCodec()); - typeCodecRegistry.register(FastTypes.U32, new UnsignedIntegerCodec()); - typeCodecRegistry.register(FastTypes.U64, new UnsignedIntegerCodec()); + typeCodecRegistry.register(FastTypes.I8, FastTypeCodecs.SIGNED_INTEGER); + typeCodecRegistry.register(FastTypes.I16, FastTypeCodecs.SIGNED_INTEGER); + typeCodecRegistry.register(FastTypes.I32, FastTypeCodecs.SIGNED_INTEGER); + typeCodecRegistry.register(FastTypes.I64, FastTypeCodecs.SIGNED_INTEGER); + typeCodecRegistry.register(FastTypes.U8, FastTypeCodecs.UNSIGNED_INTEGER); + typeCodecRegistry.register(FastTypes.U16, FastTypeCodecs.UNSIGNED_INTEGER); + typeCodecRegistry.register(FastTypes.U32, FastTypeCodecs.UNSIGNED_INTEGER); + typeCodecRegistry.register(FastTypes.U64, FastTypeCodecs.UNSIGNED_INTEGER); } return typeCodecRegistry; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java 2008-07-08 12:25:27 UTC (rev 163) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java 2008-07-09 02:24:06 UTC (rev 164) @@ -52,27 +52,7 @@ this.type = type; } /** - * 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, boolean optional) { - super(name, optional); - this.type = type; - this.operator = null; - } - /** - * * @return Returns the type as a string */ public org.lasalletech.exom.Type getType() { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DictionaryOperator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DictionaryOperator.java 2008-07-08 12:25:27 UTC (rev 163) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DictionaryOperator.java 2008-07-09 02:24:06 UTC (rev 164) @@ -26,4 +26,8 @@ public String getDefaultValue() { return defaultValue; } + + public boolean hasDefaultValue() { + return defaultValue != null; + } } Deleted: branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java 2008-07-08 12:25:27 UTC (rev 163) +++ branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java 2008-07-09 02:24:06 UTC (rev 164) @@ -1,83 +0,0 @@ -package org.openfast.codec; - -import org.lasalletech.exom.EObject; -import org.lasalletech.exom.simple.SimpleEntity; -import org.lasalletech.exom.simple.SimpleField; -import org.openfast.ByteUtil; -import org.openfast.Context; -import org.openfast.dictionary.FastDictionary; -import org.openfast.dictionary.GlobalFastDictionary; -import org.openfast.template.Scalar; -import org.openfast.template.type.Type; -import org.openfast.test.OpenFastTestCase; - -public class IncrementIntegerCodecTest extends OpenFastTestCase { - IncrementIntegerCodec noDefaultSignedCodec = new IncrementIntegerCodec(new SignedIntegerCodec()); - IncrementIntegerCodec default22SignedCodec = new IncrementIntegerCodec(new SignedIntegerCodec(), 22); - - public void testEncode() { - SimpleEntity entity = new SimpleEntity("yeah"); - entity.add(new SimpleField("anything", null)); - EObject object = entity.newObject(); - Scalar scalar = new Scalar("1", Type.U32, null, true); - Context context = new Context(); - byte[] buffer = new byte[1]; - - object.set(0, 22); - int newOffset = default22SignedCodec.encode(object, 0, buffer, 0, scalar, context); - assertEquals(0, newOffset); - - context.reset(); - newOffset = noDefaultSignedCodec.encode(object, 0, buffer, 0, scalar, context); - assertEquals(1, newOffset); - assertEquals("10010110", buffer); - - object.set(0, 23); - newOffset = noDefaultSignedCodec.encode(object, 0, buffer, 0, scalar, context); - assertEquals(0, newOffset); - - object.set(0, 25); - newOffset = noDefaultSignedCodec.encode(object, 0, buffer, 0, scalar, context); - assertEquals(1, newOffset); - assertEquals("10011001", buffer); - - object.clear(0); - newOffset = noDefaultSignedCodec.encode(object, 0, buffer, 0, scalar, context); - assertEquals(1, newOffset); - assertEquals("10000000", buffer); - } - - public void testDecodeEmpty() { - SimpleEntity entity = new SimpleEntity("yeah"); - entity.add(new SimpleField("anything", null)); - EObject object = entity.newObject(); - Scalar scalar = new Scalar("1", Type.U32, null, true); - Context context = new Context(); - - noDefaultSignedCodec.decodeEmpty(object, 0, scalar, context); - assertFalse(object.isDefined(0)); - - context.reset(); - default22SignedCodec.decodeEmpty(object, 0, scalar, context); - assertEquals(22, object.getInt(0)); - - default22SignedCodec.decodeEmpty(object, 0, scalar, context); - assertEquals(23, object.getInt(0)); - } - - public void testDecode() { - SimpleEntity entity = new SimpleEntity("yeah"); - entity.add(new SimpleField("anything", null)); - EObject object = entity.newObject(); - Scalar scalar = new Scalar("1", Type.U32, null, true); - FastDictionary dictionary = new GlobalFastDictionary(); - - noDefaultSignedCodec.decode(object, 0, bytes("10000001"), 0, scalar, new Context()); - assertEquals(1, object.getInt(0)); - } - - public void testGetLength() { - byte[] buffer = ByteUtil.convertBitStringToFastByteArray("01000000 10000000"); - assertEquals(2, noDefaultSignedCodec.getLength(buffer, 0)); - } -} Deleted: branches/openfast-2.x/core/src/test/java/org/openfast/codec/SignedIntegerCodecTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/codec/SignedIntegerCodecTest.java 2008-07-08 12:25:27 UTC (rev 163) +++ branches/openfast-2.x/core/src/test/java/org/openfast/codec/SignedIntegerCodecTest.java 2008-07-09 02:24:06 UTC (rev 164) @@ -1,49 +0,0 @@ -package org.openfast.codec; - -import java.util.Arrays; -import org.openfast.test.OpenFastTestCase; - -public class SignedIntegerCodecTest extends OpenFastTestCase { - SignedIntegerCodec codec = new SignedIntegerCodec(); - - public void testDecode() { - assertEquals(63, codec.decode(bytes("10111111"), 0)); - assertEquals(64, codec.decode(bytes("00000000 11000000"), 0)); - assertEquals(-1, codec.decode(bytes("11111111"), 0)); - assertEquals(-2, codec.decode(bytes("11111110"), 0)); - assertEquals(-64, codec.decode(bytes("11000000"), 0)); - assertEquals(-65, codec.decode(bytes("01111111 10111111"), 0)); - assertEquals(639, codec.decode(bytes("00000100 11111111"), 0)); - assertEquals(942755, codec.decode(bytes("00111001 01000101 10100011"), 0)); - assertEquals(-942755, codec.decode(bytes("01000110 00111010 11011101"), 0)); - assertEquals(8193, codec.decode(bytes("00000000 01000000 10000001"), 0)); - assertEquals(-8193, codec.decode(bytes("01111111 00111111 11111111"), 0)); - } - - public void testEncode() { - byte[] buffer = new byte[4]; - assertEncode(buffer, "00000000 10111111 00000000 00000000", 63, 2); - assertEncode(buffer, "00000000 00000000 11000000 00000000", 64, 3); - assertEncode(buffer, "00000000 11111111 00000000 00000000", -1, 2); - assertEncode(buffer, "00000000 11111110 00000000 00000000", -2, 2); - assertEncode(buffer, "00000000 11000000 00000000 00000000", -64, 2); - assertEncode(buffer, "00000000 01111111 10111111 00000000", -65, 3); - assertEncode(buffer, "00000000 00000100 11111111 00000000", 639, 3); - assertEncode(buffer, "00000000 00111001 01000101 10100011", 942755, 4); - assertEncode(buffer, "00000000 01000110 00111010 11011101", -942755, 4); - assertEncode(buffer, "00000000 00000000 01000000 10000001", 8193, 4); - assertEncode(buffer, "00000000 01111111 00111111 11111111", -8193, 4); - } - - private void assertEncode(byte[] buffer, String bitstring, int value, int expectedOffset) { - int newOffset = codec.encode(buffer, 1, value); - assertEquals(bitstring, buffer); - assertEquals(expectedOffset, newOffset); - Arrays.fill(buffer, (byte) 0); - } - - public void testGetLength() { - assertEquals(1, codec.getLength(bytes("10000000 01010101 10000000"), 0)); - assertEquals(2, codec.getLength(bytes("00100000 10000000 00001111"), 0)); - } -} Added: branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/CopyIntegerCodecTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/CopyIntegerCodecTest.java (rev 0) +++ branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/CopyIntegerCodecTest.java 2008-07-09 02:24:06 UTC (rev 164) @@ -0,0 +1,112 @@ +package org.openfast.codec.operator; + +import static org.openfast.codec.operator.FastOperatorTestHarness.INITIAL_VALUE; +import static org.openfast.codec.operator.FastOperatorTestHarness.KEY; +import static org.openfast.codec.operator.FastOperatorTestHarness.NO_INITIAL_VALUE; +import static org.openfast.codec.operator.FastOperatorTestHarness.NULL; +import static org.openfast.codec.operator.FastOperatorTestHarness.UNDEFINED; +import org.openfast.Context; +import org.openfast.Fast; +import org.openfast.Message; +import org.openfast.codec.type.FastTypeCodecs; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; +import org.openfast.template.operator.CopyOperator; +import org.openfast.template.operator.DictionaryOperator; +import org.openfast.template.type.Type; +import org.openfast.test.OpenFastTestCase; + +public class CopyIntegerCodecTest extends OpenFastTestCase { + DictionaryOperator noDefaultOp = new CopyOperator(KEY, Fast.GLOBAL, null); + CopyIntegerCodec copyNoDefaultCodec = new CopyIntegerCodec(noDefaultOp, FastTypeCodecs.NULLABLE_UNSIGNED_INTEGER); + Scalar noDefault = new Scalar("", Type.U32, noDefaultOp, true); + + DictionaryOperator defaultOp = new CopyOperator(FastOperatorTestHarness.KEY, Fast.GLOBAL, "22"); + CopyIntegerCodec copyDefaultCodec = new CopyIntegerCodec(defaultOp, FastTypeCodecs.NULLABLE_UNSIGNED_INTEGER); + Scalar defaultScalar = new Scalar("", Type.U32, defaultOp, true); + + byte[] buffer = new byte[4]; + Context context = new Context(); + + public void testDecode() { + FastOperatorTestHarness harness = new FastOperatorTestHarness(copyNoDefaultCodec, copyDefaultCodec); + harness.assertDecodeNull( NO_INITIAL_VALUE, UNDEFINED); + harness.assertDecodeNull( INITIAL_VALUE, UNDEFINED, "10000000"); + harness.assertDecodeNull( INITIAL_VALUE, NULL); + harness.assertDecodeNull( INITIAL_VALUE, 22, "10000000"); + harness.assertDecode (6, NO_INITIAL_VALUE, UNDEFINED, "10000111"); + harness.assertDecode (22, INITIAL_VALUE, UNDEFINED); + harness.assertDecode (23, INITIAL_VALUE, UNDEFINED, "10011000"); + harness.assertDecode (23, INITIAL_VALUE, NULL, "10011000"); + harness.assertDecode (23, INITIAL_VALUE, 22, "10011000"); + harness.assertDecode (24, INITIAL_VALUE, 24); + } + + public void testEncodeNoDefault() { + MessageTemplate template = template(noDefault); + Message message = new Message(template); + + // Default? | Dictionary State | Field Value + // NO UNDEFINED NULL + int size = copyNoDefaultCodec.encode(message, 0, buffer, 0, noDefault, context); + assertEquals("00000000", buffer, 1); + assertEquals(0, size); + + // NO NULL NULL + size = copyNoDefaultCodec.encode(message, 0, buffer, 0, noDefault, context); + assertEquals(0, size); + + // NO DEFINED NULL + context.getDictionary(Fast.GLOBAL).store(null, KEY, null, 2); + size = copyNoDefaultCodec.encode(message, 0, buffer, 0, noDefault, context); + assertEquals(1, size); + assertEquals("10000000", buffer, 1); + + // NO UNDEFINED DEFINED + context.reset(); + message.set(0, 5); + size = copyNoDefaultCodec.encode(message, 0, buffer, 0, noDefault, context); + assertEquals(1, size); + assertEquals("10000110", buffer, 1); + + // NO DEFINED EQUAL DICTIONARY + size = copyNoDefaultCodec.encode(message, 0, buffer, 0, noDefault, context); + assertEquals(0, size); + + // NO DEFINED NOT EQUAL DICTIONARY + message.set(0, 6); + size = copyNoDefaultCodec.encode(message, 0, buffer, 0, noDefault, context); + assertEquals(1, size); + assertEquals("10000111", buffer, 1); + } + + public void testEncodeWithDefault() { + MessageTemplate template = template(defaultScalar); + Message message = new Message(template); + + // YES UNDEFINED NULL + int size = copyDefaultCodec.encode(message, 0, buffer, 0, defaultScalar, context); + assertEquals("10000000", buffer, 1); + assertEquals(1, size); + + // YES UNDEFINED EQUAL DEFAULT VALUE + context.reset(); + message.set(0, 22); + size = copyDefaultCodec.encode(message, 0, buffer, 0, defaultScalar, context); + assertEquals(0, size); + + // YES UNDEFINED NOT EQUAL DEFAULT VALUE + context.reset(); + message.set(0, 24); + size = copyDefaultCodec.encode(message, 0, buffer, 0, defaultScalar, context); + assertEquals(1, size); + assertEquals("10011001", buffer, 1); + + // YES NULL DEFINED + context.getDictionary(defaultOp.getDictionary()).storeNull(null, KEY, null); + size = copyDefaultCodec.encode(message, 0, buffer, 0, defaultScalar, context); + assertEquals(1, size); + assertEquals("10011001", buffer, 1); + + } +} Added: branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastOperatorTestHarness.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastOperatorTestHarness.java (rev 0) +++ branches/openfast-2.x/core/src/test/java/org/openfast/codec/operator/FastOperatorTestHarness.java 2008-07-09 02:24:06 UTC (rev 164) @@ -0,0 +1,90 @@ +package org.openfast.codec.operator; + +import junit.framework.Assert; +import org.lasalletech.exom.QName; +import org.openfast.ByteUtil; +import org.openfast.Context; +import org.openfast.Message; +import org.openfast.codec.ScalarCodec; +import org.openfast.template.Field; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; +import org.openfast.template.type.Type; + +public class FastOperatorTestHarness { + + public static final QName KEY = new QName("any", "thing"); + public static final int UNDEFINED = Integer.MIN_VALUE; + public static final int NULL = Integer.MIN_VALUE + 1; + public static final int NO_INITIAL_VALUE = Integer.MIN_VALUE + 2; + public static final int INITIAL_VALUE = Integer.MIN_VALUE + 3; + private final ScalarCodec noDefaultCodec; + private final ScalarCodec defaultCodec; + + public FastOperatorTestHarness(ScalarCodec noDefaultCodec, ScalarCodec defaultCodec) { + this.noDefaultCodec = n... [truncated message content] |
From: <ope...@li...> - 2008-07-08 12:25:18
|
Revision: 163 http://openfast.svn.sourceforge.net/openfast/?rev=163&view=rev Author: jacob_northey Date: 2008-07-08 05:25:27 -0700 (Tue, 08 Jul 2008) Log Message: ----------- Implemented simple FastEncoder. Codecs implemented: (SignedIntegerCodec, BasicMessageCodec, UnsignedIntegerCodec, IncrementIntegerCodec Modified Paths: -------------- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast1_1Implementation.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/FastImplementation.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ConstantOperatorParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/CopyOperatorParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DefaultOperatorParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DeltaOperatorParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/IncrementOperatorParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TailOperatorParser.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/XMLMessageTemplateLoaderTest.java branches/openfast-2.x/core/src/test/java/org/openfast/test/OpenFastTestCase.java branches/openfast-2.x/core/src/test/java/org/openfast/test/TestUtil.java Added Paths: ----------- branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicTypeCodecRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/CodecFactory.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastEncoder.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/MessageCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/MessageCodecRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/UnsignedIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/ branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/ConstantOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/CopyOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DefaultOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DeltaOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DictionaryOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/IncrementOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/TailOperator.java branches/openfast-2.x/core/src/test/java/org/openfast/CustomFastImplementationAcceptanceTest.java branches/openfast-2.x/core/src/test/java/org/openfast/GeneralAcceptanceTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/SignedIntegerCodecTest.java branches/openfast-2.x/core/src/test/resources/acceptance/ branches/openfast-2.x/core/src/test/resources/acceptance/integerTemplates.xml Removed Paths: ------------- branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodecTest.java branches/openfast-2.x/core/src/main/java/org/openfast/template/ConstantOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/CopyOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/DefaultOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/DeltaOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/DictionaryOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/IncrementOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/OperatorRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/template/TailOperator.java Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Context.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-07-08 12:25:27 UTC (rev 163) @@ -49,6 +49,7 @@ private QName currentApplicationType; private List listeners = Collections.EMPTY_LIST; private boolean traceEnabled; + private byte[] tempBuffer = new byte[1024 * 32]; // max 32 kB message size public Context() { dictionaries.put("global", new GlobalFastDictionary()); @@ -86,7 +87,7 @@ currentApplicationType = group.getTypeReference(); return getDictionary(dictionary).lookupInt(null, key, currentApplicationType); } - private FastDictionary getDictionary(String dictionary) { + public FastDictionary getDictionary(String dictionary) { if (!dictionaries.containsKey(dictionary)) dictionaries.put(dictionary, new GlobalFastDictionary()); return (FastDictionary) dictionaries.get(dictionary); @@ -120,4 +121,13 @@ public boolean isTraceEnabled() { return traceEnabled; } + public byte[] getTemporaryBuffer() { + byte[] pointer = tempBuffer; + tempBuffer = null; + return pointer; + } + + public void discardTemporaryBuffer(byte[] buffer) { + tempBuffer = buffer; + } } Added: branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Fast.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,6 @@ +package org.openfast; + +public class Fast { + public static final byte STOP_BIT = (byte) 0x80; + public static final String GLOBAL = "global"; +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecFactory.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,23 @@ +package org.openfast.codec; + +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; +import org.openfast.template.Type; +import org.openfast.template.operator.DictionaryOperator; + +public class BasicCodecFactory implements CodecFactory { + public MessageCodec createCodec(int id, MessageTemplate template, TypeCodecRegistry typeCodecRegistry) { + return new BasicMessageCodec(id, template, typeCodecRegistry, this); + } + + public ScalarCodec createCodec(Scalar scalar, TypeCodecRegistry typeCodecRegistry) { + if ("increment".equals(scalar.getOperator().getName())) { + if (((DictionaryOperator)scalar.getOperator()).getDefaultValue() != null) { + int defaultValue = Integer.parseInt(((DictionaryOperator)scalar.getOperator()).getDefaultValue()); + return new IncrementIntegerCodec(typeCodecRegistry.getIntegerCodec((Type) scalar.getType()), defaultValue); + } + return new IncrementIntegerCodec(typeCodecRegistry.getIntegerCodec((Type) scalar.getType())); + } + return null; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecRegistry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicCodecRegistry.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,52 @@ +package org.openfast.codec; + +public class BasicCodecRegistry implements MessageCodecRegistry { + private Entry[] codecEntries = new Entry[256]; + public BasicCodecRegistry() { + + } + public MessageCodec get(int id) { + int index = id & 0xff; + if (codecEntries[index] == null) return null; + Entry entry = codecEntries[index]; + while (entry.id != id) { + if (entry.next == null) return null; + entry = entry.next; + } + return entry.codec; + } + + public boolean isRegistered(int id) { + int index = id & 0xff; + if (codecEntries[index] == null) return false; + Entry entry = codecEntries[index]; + while (entry.id != id) { + if (entry.next == null) return false; + entry = entry.next; + } + return true; + } + + public void register(int id, MessageCodec codec) { + int index = id & 0xff; + if (codecEntries[index] != null) { + codecEntries[index] = new Entry(id, codec); + } else { + codecEntries[index] = new Entry(id, codec, codecEntries[index]); + } + } + + private class Entry { + int id; + Entry next; + MessageCodec codec; + public Entry(int id, MessageCodec codec) { + this(id, codec, null); + } + public Entry(int id, MessageCodec codec, Entry entry) { + this.id = id; + this.codec = codec; + this.next = entry; + } + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicMessageCodec.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,54 @@ +package org.openfast.codec; + +import org.lasalletech.exom.Field; +import org.openfast.Context; +import org.openfast.Message; +import org.openfast.fast.FastTypes; +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; +import org.openfast.util.BitVectorBuilder; + +public class BasicMessageCodec implements MessageCodec { + private final int templateId; + private final IntegerCodec uintCodec; + private final FieldCodec[] fieldCodecs; + + public BasicMessageCodec(int id, MessageTemplate template, TypeCodecRegistry codecRegistry, CodecFactory codecFactory) { + this.templateId = id; + this.uintCodec = codecRegistry.getIntegerCodec(FastTypes.U32); + this.fieldCodecs = new FieldCodec[template.getFieldCount()]; + int index = 0; + for (Field field : template.getFields()) { + if (field instanceof Scalar) { + Scalar scalar = (Scalar) field; + fieldCodecs[index] = codecFactory.createCodec(scalar, codecRegistry); + index++; + } + } + } + + public int encode(byte[] buffer, int offset, Message message, Context context) { + byte[] temp = context.getTemporaryBuffer(); + int index = 0; + BitVectorBuilder pmapBuilder = new BitVectorBuilder(7); // TODO - calculate size of pmap builder + if (context.getLastTemplateId() != templateId) { + index = uintCodec.encode(temp, offset, templateId); + context.setLastTemplateId(templateId); + pmapBuilder.set(); + } + int previousIndex; + for (int i=0; i<fieldCodecs.length; i++) { + previousIndex = index; + index = fieldCodecs[i].encode(message, i, temp, index, message.getTemplate().getField(i), context); + if (index != previousIndex) + pmapBuilder.set(); + else + pmapBuilder.skip(); + } + byte[] pmap = pmapBuilder.getBitVector().getBytes(); + System.arraycopy(pmap, 0, buffer, offset, pmap.length); + System.arraycopy(temp, 0, buffer, offset + pmap.length, index); + context.discardTemporaryBuffer(temp); + return offset + pmap.length + index; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicTypeCodecRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicTypeCodecRegistry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/BasicTypeCodecRegistry.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,17 @@ +package org.openfast.codec; + +import java.util.HashMap; +import java.util.Map; +import org.openfast.template.Type; + +public class BasicTypeCodecRegistry implements TypeCodecRegistry { + private Map<Type, TypeCodec> codecs = new HashMap<Type, TypeCodec>(); + + public IntegerCodec getIntegerCodec(Type intType) { + return (IntegerCodec) codecs.get(intType); + } + + public void register(Type type, TypeCodec codec) { + codecs.put(type, codec); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/CodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/CodecFactory.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/CodecFactory.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,10 @@ +package org.openfast.codec; + +import org.openfast.template.MessageTemplate; +import org.openfast.template.Scalar; + +public interface CodecFactory { + MessageCodec createCodec(int id, MessageTemplate template, TypeCodecRegistry typeCodecRegistry); + + ScalarCodec createCodec(Scalar scalar, TypeCodecRegistry typeCodecRegistry); +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastEncoder.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastEncoder.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastEncoder.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,34 @@ +package org.openfast.codec; + +import org.openfast.Context; +import org.openfast.Message; +import org.openfast.fast.impl.FastImplementation; +import org.openfast.template.TemplateRegistry; + +public class FastEncoder { + private final Context context = new Context(); + private CodecFactory codecFactory = FastImplementation.getDefaultVersion().getCodecFactory(); + private MessageCodecRegistry codecRegistry = new BasicCodecRegistry(); + private TypeCodecRegistry typeCodecRegistry = FastImplementation.getDefaultVersion().getTypeCodecRegistry(); + + public FastEncoder(TemplateRegistry templateRegistry) { + context.setTemplateRegistry(templateRegistry); + } + + public void setFastImplementation(FastImplementation implementation) { + codecFactory = implementation.getCodecFactory(); + } + + public int encode(byte[] buffer, int offset, Message message) { + MessageCodec encoder = getEncoder(message); + return encoder.encode(buffer, offset, message, context); + } + + private MessageCodec getEncoder(Message message) { + int id = context.getTemplateRegistry().getId(message.getTemplate()); + if (!codecRegistry.isRegistered(id)) { + codecRegistry.register(id, codecFactory.createCodec(id, message.getTemplate(), typeCodecRegistry)); + } + return codecRegistry.get(id); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/FieldCodec.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,9 @@ +package org.openfast.codec; + +import org.lasalletech.exom.EObject; +import org.openfast.Context; + +public interface FieldCodec<T> { + int decode(EObject object, int index, byte[] buffer, int offset, T field, Context context); + int encode(EObject object, int index, byte[] buffer, int offset, T field, Context context); +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java 2008-07-08 12:25:27 UTC (rev 163) @@ -22,6 +22,8 @@ import org.lasalletech.exom.EObject; import org.lasalletech.exom.QName; +import org.openfast.Context; +import org.openfast.Fast; import org.openfast.dictionary.FastDictionary; import org.openfast.error.FastConstants; import org.openfast.template.Scalar; @@ -29,6 +31,12 @@ final class IncrementIntegerCodec implements ScalarCodec { private static final long serialVersionUID = 1L; private final IntegerCodec integerCodec; + private String dictionary = Fast.GLOBAL; + + public void setDictionary(String dictionary) { + this.dictionary = dictionary; + } + private final int defaultValue; private final boolean hasDefaultValue; @@ -44,15 +52,16 @@ this.defaultValue = defaultValue; } - public int decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, FastDictionary dictionary) { + public int decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { int length = integerCodec.getLength(buffer, offset); int value = integerCodec.decode(buffer, offset); - dictionary.store(object.getEntity(), scalar.getKey(), null, value); + context.getDictionary(dictionary).store(object.getEntity(), scalar.getKey(), null, value); object.set(index, value); return offset + length; } - public void decodeEmpty(EObject object, int index, Scalar scalar, FastDictionary dictionary) { + public void decodeEmpty(EObject object, int index, Scalar scalar, Context context) { + FastDictionary dictionary = context.getDictionary(this.dictionary); if (dictionary.isNull(object, scalar.getKey(), null)) { // leave object value set to null dictionary.storeNull(object.getEntity(), scalar.getKey(), null); @@ -79,7 +88,8 @@ return integerCodec.getLength(buffer, offset); } - public int encode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, FastDictionary dictionary) { + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, Context context) { + FastDictionary dictionary = context.getDictionary(this.dictionary); QName key = scalar.getKey(); if (!object.isDefined(index)) { if (!scalar.isOptional()) { Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/MessageCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/MessageCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/MessageCodec.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,10 @@ +package org.openfast.codec; + +import org.openfast.Context; +import org.openfast.Message; + +public interface MessageCodec { + + int encode(byte[] buffer, int offset, Message message, Context context); + +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/MessageCodecRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/MessageCodecRegistry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/MessageCodecRegistry.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,7 @@ +package org.openfast.codec; + +public interface MessageCodecRegistry { + boolean isRegistered(int id); + void register(int id, MessageCodec createCodec); + MessageCodec get(int id); +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java 2008-07-08 12:25:27 UTC (rev 163) @@ -20,13 +20,8 @@ */ package org.openfast.codec; -import java.io.Serializable; -import org.lasalletech.exom.EObject; -import org.openfast.dictionary.FastDictionary; import org.openfast.template.Scalar; -public interface ScalarCodec extends Serializable { - int decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, FastDictionary dictionary); - int encode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, FastDictionary dictionary); +public interface ScalarCodec extends FieldCodec<Scalar> { int getLength(byte[] buffer, int offset); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodec.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodec.java 2008-07-08 12:25:27 UTC (rev 163) @@ -1,9 +1,10 @@ package org.openfast.codec; +import org.openfast.Fast; + public class SignedIntegerCodec extends StopBitEncodedTypeCodec implements IntegerCodec { - protected static final byte STOP_BIT = (byte) 0x80; public int decode(byte[] buffer, int offset) { int value = 0; @@ -31,7 +32,7 @@ // 01000000 00000000 ... 00000000 // ^----SIGN BIT buffer[offset] |= (0x40 & (value >> 57)); - buffer[index - 1] |= STOP_BIT; + buffer[index - 1] |= Fast.STOP_BIT; return index; } Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodecTest.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodecTest.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodecTest.java 2008-07-08 12:25:27 UTC (rev 163) @@ -1,49 +0,0 @@ -package org.openfast.codec; - -import java.util.Arrays; -import org.openfast.test.OpenFastTestCase; - -public class SignedIntegerCodecTest extends OpenFastTestCase { - SignedIntegerCodec codec = new SignedIntegerCodec(); - - public void testDecode() { - assertEquals(63, codec.decode(bytes("10111111"), 0)); - assertEquals(64, codec.decode(bytes("00000000 11000000"), 0)); - assertEquals(-1, codec.decode(bytes("11111111"), 0)); - assertEquals(-2, codec.decode(bytes("11111110"), 0)); - assertEquals(-64, codec.decode(bytes("11000000"), 0)); - assertEquals(-65, codec.decode(bytes("01111111 10111111"), 0)); - assertEquals(639, codec.decode(bytes("00000100 11111111"), 0)); - assertEquals(942755, codec.decode(bytes("00111001 01000101 10100011"), 0)); - assertEquals(-942755, codec.decode(bytes("01000110 00111010 11011101"), 0)); - assertEquals(8193, codec.decode(bytes("00000000 01000000 10000001"), 0)); - assertEquals(-8193, codec.decode(bytes("01111111 00111111 11111111"), 0)); - } - - public void testEncode() { - byte[] buffer = new byte[4]; - assertEncode(buffer, "00000000 10111111 00000000 00000000", 63, 2); - assertEncode(buffer, "00000000 00000000 11000000 00000000", 64, 3); - assertEncode(buffer, "00000000 11111111 00000000 00000000", -1, 2); - assertEncode(buffer, "00000000 11111110 00000000 00000000", -2, 2); - assertEncode(buffer, "00000000 11000000 00000000 00000000", -64, 2); - assertEncode(buffer, "00000000 01111111 10111111 00000000", -65, 3); - assertEncode(buffer, "00000000 00000100 11111111 00000000", 639, 3); - assertEncode(buffer, "00000000 00111001 01000101 10100011", 942755, 4); - assertEncode(buffer, "00000000 01000110 00111010 11011101", -942755, 4); - assertEncode(buffer, "00000000 00000000 01000000 10000001", 8193, 4); - assertEncode(buffer, "00000000 01111111 00111111 11111111", -8193, 4); - } - - private void assertEncode(byte[] buffer, String bitstring, int value, int expectedOffset) { - int newOffset = codec.encode(buffer, 1, value); - assertEquals(bitstring, buffer); - assertEquals(expectedOffset, newOffset); - Arrays.fill(buffer, (byte) 0); - } - - public void testGetLength() { - assertEquals(1, codec.getLength(bytes("10000000 01010101 10000000"), 0)); - assertEquals(2, codec.getLength(bytes("00100000 10000000 00001111"), 0)); - } -} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodecRegistry.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,9 @@ +package org.openfast.codec; + +import org.openfast.template.Type; + +public interface TypeCodecRegistry { + + IntegerCodec getIntegerCodec(Type intType); + +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/UnsignedIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/UnsignedIntegerCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/UnsignedIntegerCodec.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,58 @@ +package org.openfast.codec; + +import org.openfast.Fast; + + +public class UnsignedIntegerCodec extends StopBitEncodedTypeCodec implements IntegerCodec { + public int decode(byte[] buffer, int offset) { + int value = 0; + int index = offset; + do { + value = (value << 7) | (buffer[index] & 0x7f); + } while ((buffer[index] & 0x80) == 0); + return value; + } + + public int encode(byte[] buffer, int offset, int value) { + int size = getUnsignedIntegerSize(value); + for (int factor = 0; factor < size; factor++) { + buffer[size - factor - 1 + offset] = (byte) ((value >> (factor * 7)) & 0x7f); + } + buffer[offset + size - 1] |= Fast.STOP_BIT; + return offset + size; + } + + /** + * + * @param value + * The long to determine the unsigned integer + * @return Returns an unsigned integer + */ + public static int getUnsignedIntegerSize(long value) { + if (value < 128) { + return 1; // 2 ^ 7 + } + if (value <= 16384) { + return 2; // 2 ^ 14 + } + if (value <= 2097152) { + return 3; // 2 ^ 21 + } + if (value <= 268435456) { + return 4; // 2 ^ 28 + } + if (value <= 34359738368L) { + return 5; // 2 ^ 35 + } + if (value <= 4398046511104L) { + return 6; // 2 ^ 42 + } + if (value <= 562949953421312L) { + return 7; // 2 ^ 49 + } + if (value <= 72057594037927936L) { + return 8; // 2 ^ 56 + } + return 9; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java 2008-07-08 12:25:27 UTC (rev 163) @@ -18,7 +18,7 @@ } public void store(Entity template, QName key, QName currentApplicationType, int value) { - int index = key.hashCode() % entries.length; + int index = key.hashCode() & (entries.length - 1); Entry entry = entries[index]; if (entry == null) { entries[index] = new IntegerEntry(key, value); @@ -57,7 +57,7 @@ } private Entry getEntry(QName key) { - int index = key.hashCode() % entries.length; + int index = key.hashCode() & (entries.length - 1); Entry entry = entries[index]; if (entry == null) return null; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast1_1Implementation.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast1_1Implementation.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast1_1Implementation.java 2008-07-08 12:25:27 UTC (rev 163) @@ -2,6 +2,12 @@ import java.util.ArrayList; import java.util.List; +import org.openfast.codec.BasicCodecFactory; +import org.openfast.codec.BasicTypeCodecRegistry; +import org.openfast.codec.CodecFactory; +import org.openfast.codec.SignedIntegerCodec; +import org.openfast.codec.TypeCodecRegistry; +import org.openfast.codec.UnsignedIntegerCodec; import org.openfast.fast.FastTypes; import org.openfast.template.BasicTypeRegistry; import org.openfast.template.TypeRegistry; @@ -25,6 +31,7 @@ private List<FieldParser> parsers; private TypeRegistry typeRegistry; private List<OperatorParser> operatorParsers; + private BasicTypeCodecRegistry typeCodecRegistry; @Override public List<FieldParser> getFieldParsers() { @@ -75,4 +82,25 @@ } return typeRegistry; } + + @Override + public CodecFactory getCodecFactory() { + return new BasicCodecFactory(); + } + + @Override + public TypeCodecRegistry getTypeCodecRegistry() { + if (typeCodecRegistry == null) { + typeCodecRegistry = new BasicTypeCodecRegistry(); + typeCodecRegistry.register(FastTypes.I8, new SignedIntegerCodec()); + typeCodecRegistry.register(FastTypes.I16, new SignedIntegerCodec()); + typeCodecRegistry.register(FastTypes.I32, new SignedIntegerCodec()); + typeCodecRegistry.register(FastTypes.I64, new SignedIntegerCodec()); + typeCodecRegistry.register(FastTypes.U8, new UnsignedIntegerCodec()); + typeCodecRegistry.register(FastTypes.U16, new UnsignedIntegerCodec()); + typeCodecRegistry.register(FastTypes.U32, new UnsignedIntegerCodec()); + typeCodecRegistry.register(FastTypes.U64, new UnsignedIntegerCodec()); + } + return typeCodecRegistry; + } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/FastImplementation.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/FastImplementation.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/FastImplementation.java 2008-07-08 12:25:27 UTC (rev 163) @@ -1,6 +1,8 @@ package org.openfast.fast.impl; import java.util.List; +import org.openfast.codec.CodecFactory; +import org.openfast.codec.TypeCodecRegistry; import org.openfast.template.TypeRegistry; import org.openfast.template.loader.FieldParser; import org.openfast.template.loader.OperatorParser; @@ -8,9 +10,13 @@ public abstract class FastImplementation { public static final String FAST_1_1 = "FAST 1.1"; private static FastImplementation fast1x1; + + public abstract TypeCodecRegistry getTypeCodecRegistry(); + public abstract CodecFactory getCodecFactory(); public abstract TypeRegistry getTypeRegistry(); public abstract List<OperatorParser> getOperatorParsers(); public abstract List<FieldParser> getFieldParsers(); + public static FastImplementation getVersion(String version) { if (FAST_1_1.equals(version)) { return getDefaultVersion(); Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/template/ConstantOperator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/ConstantOperator.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/ConstantOperator.java 2008-07-08 12:25:27 UTC (rev 163) @@ -1,19 +0,0 @@ -package org.openfast.template; - -public class ConstantOperator implements Operator { - private static final long serialVersionUID = 1L; - - private final String defaultValue; - - public String getDefaultValue() { - return defaultValue; - } - - public ConstantOperator(String defaultValue) { - this.defaultValue = defaultValue; - } - - public String getName() { - return "constant"; - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/template/CopyOperator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/CopyOperator.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/CopyOperator.java 2008-07-08 12:25:27 UTC (rev 163) @@ -1,15 +0,0 @@ -package org.openfast.template; - -import org.lasalletech.exom.QName; - -public class CopyOperator extends DictionaryOperator implements Operator { - private static final long serialVersionUID = 1L; - - public CopyOperator(QName key, String dictionary, String defaultValue) { - super(key, dictionary, defaultValue); - } - - public String getName() { - return "copy"; - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/template/DefaultOperator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/DefaultOperator.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/DefaultOperator.java 2008-07-08 12:25:27 UTC (rev 163) @@ -1,19 +0,0 @@ -package org.openfast.template; - -public class DefaultOperator implements Operator { - private static final long serialVersionUID = 1L; - private String defaultValue; - - public DefaultOperator(String defaultValue) { - this.defaultValue = defaultValue; - } - - public String getDefaultValue() { - return defaultValue; - } - - public String getName() { - return "default"; - } - -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/template/DeltaOperator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/DeltaOperator.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/DeltaOperator.java 2008-07-08 12:25:27 UTC (rev 163) @@ -1,16 +0,0 @@ -package org.openfast.template; - -import org.lasalletech.exom.QName; - -public class DeltaOperator extends DictionaryOperator { - private static final long serialVersionUID = 1L; - - public DeltaOperator(QName key, String dictionary, String defaultValue) { - super(key, dictionary, defaultValue); - } - - - public String getName() { - return "delta"; - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/template/DictionaryOperator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/DictionaryOperator.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/DictionaryOperator.java 2008-07-08 12:25:27 UTC (rev 163) @@ -1,28 +0,0 @@ -package org.openfast.template; - -import org.lasalletech.exom.QName; - -public abstract class DictionaryOperator implements Operator { - private static final long serialVersionUID = 1L; - private final QName key; - private final String dictionary; - private final String defaultValue; - - protected DictionaryOperator(QName key, String dictionary, String defaultValue) { - this.key = key; - this.dictionary = dictionary; - this.defaultValue = defaultValue; - } - - public QName getKey() { - return key; - } - - public String getDictionary() { - return dictionary; - } - - public String getDefaultValue() { - return defaultValue; - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/template/IncrementOperator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/IncrementOperator.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/IncrementOperator.java 2008-07-08 12:25:27 UTC (rev 163) @@ -1,16 +0,0 @@ -package org.openfast.template; - -import org.lasalletech.exom.QName; - -public class IncrementOperator extends DictionaryOperator { - private static final long serialVersionUID = 1L; - - public IncrementOperator(QName key, String dictionary, String defaultValue) { - super(key, dictionary, defaultValue); - } - - - public String getName() { - return "increment"; - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/template/OperatorRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/OperatorRegistry.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/OperatorRegistry.java 2008-07-08 12:25:27 UTC (rev 163) @@ -1,8 +0,0 @@ -package org.openfast.template; - -public interface OperatorRegistry { - Operator getDefault(); - Operator get(String name); - void register(String name, Operator operator); - boolean isDefined(String name); -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/template/TailOperator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/TailOperator.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/TailOperator.java 2008-07-08 12:25:27 UTC (rev 163) @@ -1,15 +0,0 @@ -package org.openfast.template; - -import org.lasalletech.exom.QName; - -public class TailOperator extends DictionaryOperator { - private static final long serialVersionUID = 1L; - - public TailOperator(QName key, String dictionary, String defaultValue) { - super(key, dictionary, defaultValue); - } - - public String getName() { - return "tail"; - } -} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ConstantOperatorParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ConstantOperatorParser.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ConstantOperatorParser.java 2008-07-08 12:25:27 UTC (rev 163) @@ -1,7 +1,7 @@ package org.openfast.template.loader; -import org.openfast.template.ConstantOperator; import org.openfast.template.Operator; +import org.openfast.template.operator.ConstantOperator; import org.w3c.dom.Element; public class ConstantOperatorParser implements OperatorParser { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/CopyOperatorParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/CopyOperatorParser.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/CopyOperatorParser.java 2008-07-08 12:25:27 UTC (rev 163) @@ -1,8 +1,8 @@ package org.openfast.template.loader; import org.lasalletech.exom.QName; -import org.openfast.template.CopyOperator; import org.openfast.template.Operator; +import org.openfast.template.operator.CopyOperator; import org.w3c.dom.Element; public class CopyOperatorParser extends DictionaryOperatorParser { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DefaultOperatorParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DefaultOperatorParser.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DefaultOperatorParser.java 2008-07-08 12:25:27 UTC (rev 163) @@ -1,7 +1,7 @@ package org.openfast.template.loader; -import org.openfast.template.DefaultOperator; import org.openfast.template.Operator; +import org.openfast.template.operator.DefaultOperator; import org.w3c.dom.Element; public class DefaultOperatorParser implements OperatorParser { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DeltaOperatorParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DeltaOperatorParser.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DeltaOperatorParser.java 2008-07-08 12:25:27 UTC (rev 163) @@ -1,8 +1,8 @@ package org.openfast.template.loader; import org.lasalletech.exom.QName; -import org.openfast.template.DeltaOperator; import org.openfast.template.Operator; +import org.openfast.template.operator.DeltaOperator; import org.w3c.dom.Element; public class DeltaOperatorParser extends DictionaryOperatorParser { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/IncrementOperatorParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/IncrementOperatorParser.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/IncrementOperatorParser.java 2008-07-08 12:25:27 UTC (rev 163) @@ -1,8 +1,8 @@ package org.openfast.template.loader; import org.lasalletech.exom.QName; -import org.openfast.template.IncrementOperator; import org.openfast.template.Operator; +import org.openfast.template.operator.IncrementOperator; import org.w3c.dom.Element; public class IncrementOperatorParser extends DictionaryOperatorParser { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TailOperatorParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TailOperatorParser.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TailOperatorParser.java 2008-07-08 12:25:27 UTC (rev 163) @@ -2,7 +2,7 @@ import org.lasalletech.exom.QName; import org.openfast.template.Operator; -import org.openfast.template.TailOperator; +import org.openfast.template.operator.TailOperator; import org.w3c.dom.Element; public class TailOperatorParser extends DictionaryOperatorParser { Copied: branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/ConstantOperator.java (from rev 162, branches/openfast-2.x/core/src/main/java/org/openfast/template/ConstantOperator.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/ConstantOperator.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/ConstantOperator.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,21 @@ +package org.openfast.template.operator; + +import org.openfast.template.Operator; + +public class ConstantOperator implements Operator { + private static final long serialVersionUID = 1L; + + private final String defaultValue; + + public String getDefaultValue() { + return defaultValue; + } + + public ConstantOperator(String defaultValue) { + this.defaultValue = defaultValue; + } + + public String getName() { + return "constant"; + } +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/CopyOperator.java (from rev 162, branches/openfast-2.x/core/src/main/java/org/openfast/template/CopyOperator.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/CopyOperator.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/CopyOperator.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,16 @@ +package org.openfast.template.operator; + +import org.lasalletech.exom.QName; +import org.openfast.template.Operator; + +public class CopyOperator extends DictionaryOperator implements Operator { + private static final long serialVersionUID = 1L; + + public CopyOperator(QName key, String dictionary, String defaultValue) { + super(key, dictionary, defaultValue); + } + + public String getName() { + return "copy"; + } +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DefaultOperator.java (from rev 162, branches/openfast-2.x/core/src/main/java/org/openfast/template/DefaultOperator.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DefaultOperator.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DefaultOperator.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,21 @@ +package org.openfast.template.operator; + +import org.openfast.template.Operator; + +public class DefaultOperator implements Operator { + private static final long serialVersionUID = 1L; + private String defaultValue; + + public DefaultOperator(String defaultValue) { + this.defaultValue = defaultValue; + } + + public String getDefaultValue() { + return defaultValue; + } + + public String getName() { + return "default"; + } + +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DeltaOperator.java (from rev 162, branches/openfast-2.x/core/src/main/java/org/openfast/template/DeltaOperator.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DeltaOperator.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DeltaOperator.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,16 @@ +package org.openfast.template.operator; + +import org.lasalletech.exom.QName; + +public class DeltaOperator extends DictionaryOperator { + private static final long serialVersionUID = 1L; + + public DeltaOperator(QName key, String dictionary, String defaultValue) { + super(key, dictionary, defaultValue); + } + + + public String getName() { + return "delta"; + } +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DictionaryOperator.java (from rev 162, branches/openfast-2.x/core/src/main/java/org/openfast/template/DictionaryOperator.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DictionaryOperator.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/DictionaryOperator.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,29 @@ +package org.openfast.template.operator; + +import org.lasalletech.exom.QName; +import org.openfast.template.Operator; + +public abstract class DictionaryOperator implements Operator { + private static final long serialVersionUID = 1L; + private final QName key; + private final String dictionary; + private final String defaultValue; + + protected DictionaryOperator(QName key, String dictionary, String defaultValue) { + this.key = key; + this.dictionary = dictionary; + this.defaultValue = defaultValue; + } + + public QName getKey() { + return key; + } + + public String getDictionary() { + return dictionary; + } + + public String getDefaultValue() { + return defaultValue; + } +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/IncrementOperator.java (from rev 162, branches/openfast-2.x/core/src/main/java/org/openfast/template/IncrementOperator.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/IncrementOperator.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/IncrementOperator.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,16 @@ +package org.openfast.template.operator; + +import org.lasalletech.exom.QName; + +public class IncrementOperator extends DictionaryOperator { + private static final long serialVersionUID = 1L; + + public IncrementOperator(QName key, String dictionary, String defaultValue) { + super(key, dictionary, defaultValue); + } + + + public String getName() { + return "increment"; + } +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/TailOperator.java (from rev 162, branches/openfast-2.x/core/src/main/java/org/openfast/template/TailOperator.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/TailOperator.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/TailOperator.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,15 @@ +package org.openfast.template.operator; + +import org.lasalletech.exom.QName; + +public class TailOperator extends DictionaryOperator { + private static final long serialVersionUID = 1L; + + public TailOperator(QName key, String dictionary, String defaultValue) { + super(key, dictionary, defaultValue); + } + + public String getName() { + return "tail"; + } +} Added: branches/openfast-2.x/core/src/test/java/org/openfast/CustomFastImplementationAcceptanceTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/CustomFastImplementationAcceptanceTest.java (rev 0) +++ branches/openfast-2.x/core/src/test/java/org/openfast/CustomFastImplementationAcceptanceTest.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,9 @@ +package org.openfast; + +import junit.framework.TestCase; + +public class CustomFastImplementationAcceptanceTest extends TestCase { + public void testCustomFieldParser() { + + } +} Added: branches/openfast-2.x/core/src/test/java/org/openfast/GeneralAcceptanceTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/GeneralAcceptanceTest.java (rev 0) +++ branches/openfast-2.x/core/src/test/java/org/openfast/GeneralAcceptanceTest.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,28 @@ +package org.openfast; + +import org.openfast.codec.FastEncoder; +import org.openfast.template.MessageTemplate; +import org.openfast.template.loader.XMLMessageTemplateLoader; +import org.openfast.test.OpenFastTestCase; + +public class GeneralAcceptanceTest extends OpenFastTestCase { + public void testBasicFastImplementation() throws Exception { + XMLMessageTemplateLoader loader = new XMLMessageTemplateLoader(); + loader.setLoadTemplateIdFromAuxId(true); + loader.load(resource("acceptance/integerTemplates.xml")); + MessageTemplate template = loader.getTemplateRegistry().get("incrementInteger"); + + FastEncoder encoder = new FastEncoder(loader.getTemplateRegistry()); + byte[] buffer = new byte[256]; + Message message = new Message(template); + message.set(0, 24); + int size = encoder.encode(buffer, 0, message); + assertEquals("11100000 10000001 10011000", buffer, 3); + assertEquals(3, size); + + message.set(0, 25); + size = encoder.encode(buffer, 0, message); + assertEquals("10000000", buffer, 1); + assertEquals(1, size); + } +} Modified: branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java 2008-07-07 19:34:20 UTC (rev 162) +++ branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java 2008-07-08 12:25:27 UTC (rev 163) @@ -4,6 +4,7 @@ import org.lasalletech.exom.simple.SimpleEntity; import org.lasalletech.exom.simple.SimpleField; import org.openfast.ByteUtil; +import org.openfast.Context; import org.openfast.dictionary.FastDictionary; import org.openfast.dictionary.GlobalFastDictionary; import org.openfast.template.Scalar; @@ -19,29 +20,29 @@ entity.add(new SimpleField("anything", null)); EObject object = entity.newObject(); Scalar scalar = new Scalar("1", Type.U32, null, true); - FastDictionary dictionary = new GlobalFastDictionary(); + Context context = new Context(); byte[] buffer = new byte[1]; object.set(0, 22); - int newOffset = default22SignedCodec.encode(object, 0, buffer, 0, scalar, dictionary); + int newOffset = default22SignedCodec.encode(object, 0, buffer, 0, scalar, context); assertEquals(0, newOffset); - dictionary.reset(); - newOffset = noDefaultSignedCodec.encode(object, 0, buffer, 0, scalar, dictionary); + context.reset(); + newOffset = noDefaultSignedCodec.encode(object, 0, buffer, 0, scalar, context); assertEquals(1, newOffset); assertEquals("10010110", buffer); object.set(0, 23); - newOffset = noDefaultSignedCodec.encode(object, 0, buffer, 0, scalar, dictionary); + newOffset = noDefaultSignedCodec.encode(object, 0, buffer, 0, scalar, context); assertEquals(0, newOffset); object.set(0, 25); - newOffset = noDefaultSignedCodec.encode(object, 0, buffer, 0, scalar, dictionary); + newOffset = noDefaultSignedCodec.encode(object, 0, buffer, 0, scalar, context); assertEquals(1, newOffset); assertEquals("10011001", buffer); object.clear(0); - newOffset = noDefaultSignedCodec.encode(object, 0, buffer, 0, scalar, dictionary); + newOffset = noDefaultSignedCodec.encode(object, 0, buffer, 0, scalar, context); assertEquals(1, newOffset); assertEquals("10000000", buffer); } @@ -51,16 +52,16 @@ entity.add(new SimpleField("anything", null)); EObject object = entity.newObject(); Scalar scalar = new Scalar("1", Type.U32, null, true); - FastDictionary dictionary = new GlobalFastDictionary(); + Context context = new Context(); - noDefaultSignedCodec.decodeEmpty(object, 0, scalar, dictionary); + noDefaultSignedCodec.decodeEmpty(object, 0, scalar, context); assertFalse(object.isDefined(0)); - dictionary.reset(); - default22SignedCodec.decodeEmpty(object, 0, scalar, dictionary); + context.reset(); + default22SignedCodec.decodeEmpty(object, 0, scalar, context); assertEquals(22, object.getInt(0)); - default22SignedCodec.decodeEmpty(object, 0, scalar, dictionary); + default22SignedCodec.decodeEmpty(object, 0, scalar, context); assertEquals(23, object.getInt(0)); } @@ -71,7 +72,7 @@ Scalar scalar = new Scalar("1", Type.U32, null, true); FastDictionary dictionary = new GlobalFastDictionary(); - noDefaultSignedCodec.decode(object, 0, bytes("10000001"), 0, scalar, dictionary); + noDefaultSignedCodec.decode(object, 0, bytes("10000001"), 0, scalar, new Context()); assertEquals(1, object.getInt(0)); } Copied: branches/openfast-2.x/core/src/test/java/org/openfast/codec/SignedIntegerCodecTest.java (from rev 159, branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodecTest.java) =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/codec/SignedIntegerCodecTest.java (rev 0) +++ branches/openfast-2.x/core/src/test/java/org/openfast/codec/SignedIntegerCodecTest.java 2008-07-08 12:25:27 UTC (rev 163) @@ -0,0 +1,49 @@ +package org.openfast.codec; + +import java.util.Arrays; +import org.openfast.test.OpenFastTestCase; + +public class SignedIntegerCodecTest extends OpenFastTestCase { + SignedIntegerCodec codec = new SignedIntegerCodec(); + + public void testDecode() { + assertEquals(63, codec.decode(bytes("10111111"), 0)); + assertEquals(64, codec.decode(bytes("00000000 11000000"), 0)); + assertEquals(-1, codec.decode(bytes("11111111"), 0)); + assertEquals(-2, codec.decode(bytes("11111110"), 0)); + assertEquals(-64, codec.decode(bytes("11000000"), 0)); + assertEquals(-65, codec.decode(bytes("01111111 10111111"), 0)); + assertEquals(639, codec.decode(bytes("00000100 11111111"), 0)); + assertEquals(942755, codec.decode(bytes("00111001 01000101 10100011"), 0)); + assertEquals(-942755, codec.decode(bytes("01000110 00111010 11011101"), 0)); + assertEquals(8193, codec.decode(bytes("00000000 01000000 10000001"), 0)); + assertEquals(-8193, codec.decode(bytes("01111111 00111111 11111111"), 0)); + } + + public void testEncode() { + byte[] buffer = new byte[4]; + assertEncode(buffer, "00000000 10111111 00000000 00000000", 63, 2); + assertEncode(buffer, "00000000 00000000 11000000 00000000", 64, 3); + assertEncode(buffer, "00000000 11111111 00000000 00000000", -1, 2); + assertEncode(buffer, "00000000 11111110 00000000 00000000", -2, 2); + assertEncode(buffer, "00000000 11000000 00000000 00000000", -64, 2); + assertEncode(buffer, "00000000 01111111 10111111 00000000", -65, 3); + assertEncode(buffer, "00000000 00000100 11111111 00000000", 639, 3); + assertEncode(buffer, "00000000 00111001 01000101 10100011", 942755, 4); + assertEncode(buffer, "00000000 01000110 00111010 11011101", -942755, 4); + assertEncode(buffer, "0... [truncated message content] |
From: <ope...@li...> - 2008-07-07 19:34:23
|
Revision: 162 http://openfast.svn.sourceforge.net/openfast/?rev=162&view=rev Author: jacob_northey Date: 2008-07-07 12:34:20 -0700 (Mon, 07 Jul 2008) Log Message: ----------- Refactored operator from singleton to POJO implementation. Dictionary, default value and key are now properties of the operator, not the scalar. Modified Paths: -------------- branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast1_1Implementation.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/FastImplementation.java branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Operator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ComposedDecimalParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ParsingContext.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ScalarParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/SequenceParser.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/XMLMessageTemplateLoaderTest.java Added Paths: ----------- branches/openfast-2.x/core/src/main/java/org/openfast/template/ConstantOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/CopyOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/DefaultOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/DeltaOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/DictionaryOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/IncrementOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/TailOperator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ConstantOperatorParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/CopyOperatorParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DefaultOperatorParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DeltaOperatorParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DictionaryOperatorParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/IncrementOperatorParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/OperatorParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TailOperatorParser.java Removed Paths: ------------- branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastOperators.java branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicOperatorRegistry.java Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastOperators.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastOperators.java 2008-07-07 17:34:45 UTC (rev 161) +++ branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastOperators.java 2008-07-07 19:34:20 UTC (rev 162) @@ -1,13 +0,0 @@ -package org.openfast.fast; - -import org.openfast.template.Operator; - -public interface FastOperators { - Operator CONSTANT = null; - Operator DEFAULT = null; - Operator COPY = null; - Operator INCREMENT = null; - Operator DELTA = null; - Operator TAIL = null; - Operator NONE = null; -} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast1_1Implementation.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast1_1Implementation.java 2008-07-07 17:34:45 UTC (rev 161) +++ branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast1_1Implementation.java 2008-07-07 19:34:20 UTC (rev 162) @@ -2,25 +2,29 @@ import java.util.ArrayList; import java.util.List; -import org.openfast.fast.FastOperators; import org.openfast.fast.FastTypes; -import org.openfast.template.BasicOperatorRegistry; import org.openfast.template.BasicTypeRegistry; -import org.openfast.template.OperatorRegistry; import org.openfast.template.TypeRegistry; import org.openfast.template.loader.ByteVectorParser; import org.openfast.template.loader.ComposedDecimalParser; +import org.openfast.template.loader.ConstantOperatorParser; +import org.openfast.template.loader.CopyOperatorParser; +import org.openfast.template.loader.DefaultOperatorParser; +import org.openfast.template.loader.DeltaOperatorParser; import org.openfast.template.loader.FieldParser; import org.openfast.template.loader.GroupParser; +import org.openfast.template.loader.IncrementOperatorParser; +import org.openfast.template.loader.OperatorParser; import org.openfast.template.loader.ScalarParser; import org.openfast.template.loader.SequenceParser; import org.openfast.template.loader.StringParser; +import org.openfast.template.loader.TailOperatorParser; import org.openfast.template.loader.TemplateRefParser; public class Fast1_1Implementation extends FastImplementation { private List<FieldParser> parsers; private TypeRegistry typeRegistry; - private OperatorRegistry operatorRegistry; + private List<OperatorParser> operatorParsers; @Override public List<FieldParser> getFieldParsers() { @@ -38,18 +42,17 @@ } @Override - public OperatorRegistry getOperatorRegistry() { - if (operatorRegistry == null) { - operatorRegistry = new BasicOperatorRegistry(); - operatorRegistry.register("none", FastOperators.NONE); - operatorRegistry.register("tail", FastOperators.TAIL); - operatorRegistry.register("delta", FastOperators.DELTA); - operatorRegistry.register("default", FastOperators.DEFAULT); - operatorRegistry.register("constant", FastOperators.CONSTANT); - operatorRegistry.register("increment", FastOperators.INCREMENT); - operatorRegistry.register("copy", FastOperators.COPY); + public List<OperatorParser> getOperatorParsers() { + if (operatorParsers == null) { + operatorParsers = new ArrayList<OperatorParser>(); + operatorParsers.add(new DefaultOperatorParser()); + operatorParsers.add(new TailOperatorParser()); + operatorParsers.add(new DeltaOperatorParser()); + operatorParsers.add(new ConstantOperatorParser()); + operatorParsers.add(new IncrementOperatorParser()); + operatorParsers.add(new CopyOperatorParser()); } - return operatorRegistry; + return operatorParsers; } @Override Modified: branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/FastImplementation.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/FastImplementation.java 2008-07-07 17:34:45 UTC (rev 161) +++ branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/FastImplementation.java 2008-07-07 19:34:20 UTC (rev 162) @@ -1,15 +1,15 @@ package org.openfast.fast.impl; import java.util.List; -import org.openfast.template.OperatorRegistry; import org.openfast.template.TypeRegistry; import org.openfast.template.loader.FieldParser; +import org.openfast.template.loader.OperatorParser; public abstract class FastImplementation { public static final String FAST_1_1 = "FAST 1.1"; private static FastImplementation fast1x1; public abstract TypeRegistry getTypeRegistry(); - public abstract OperatorRegistry getOperatorRegistry(); + public abstract List<OperatorParser> getOperatorParsers(); public abstract List<FieldParser> getFieldParsers(); public static FastImplementation getVersion(String version) { if (FAST_1_1.equals(version)) { Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicOperatorRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicOperatorRegistry.java 2008-07-07 17:34:45 UTC (rev 161) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicOperatorRegistry.java 2008-07-07 19:34:20 UTC (rev 162) @@ -1,25 +0,0 @@ -package org.openfast.template; - -import java.util.HashMap; -import java.util.Map; -import org.openfast.fast.FastOperators; - -public class BasicOperatorRegistry implements OperatorRegistry { - private Map<String, Operator> operators = new HashMap<String, Operator>(); - - public Operator get(String name) { - return operators.get(name); - } - - public Operator getDefault() { - return FastOperators.NONE; - } - - public void register(String name, Operator operator) { - operators.put(name, operator); - } - - public boolean isDefined(String name) { - return operators.containsKey(name); - } -} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java 2008-07-07 17:34:45 UTC (rev 161) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java 2008-07-07 19:34:20 UTC (rev 162) @@ -74,8 +74,6 @@ return false; if (!other.fields[i].getOperator().equals(fields[i].getOperator())) return false; - if (!other.fields[i].getDictionary().equals(fields[i].getDictionary())) - return false; } return true; } Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/ConstantOperator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/ConstantOperator.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/ConstantOperator.java 2008-07-07 19:34:20 UTC (rev 162) @@ -0,0 +1,19 @@ +package org.openfast.template; + +public class ConstantOperator implements Operator { + private static final long serialVersionUID = 1L; + + private final String defaultValue; + + public String getDefaultValue() { + return defaultValue; + } + + public ConstantOperator(String defaultValue) { + this.defaultValue = defaultValue; + } + + public String getName() { + return "constant"; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/CopyOperator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/CopyOperator.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/CopyOperator.java 2008-07-07 19:34:20 UTC (rev 162) @@ -0,0 +1,15 @@ +package org.openfast.template; + +import org.lasalletech.exom.QName; + +public class CopyOperator extends DictionaryOperator implements Operator { + private static final long serialVersionUID = 1L; + + public CopyOperator(QName key, String dictionary, String defaultValue) { + super(key, dictionary, defaultValue); + } + + public String getName() { + return "copy"; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/DefaultOperator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/DefaultOperator.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/DefaultOperator.java 2008-07-07 19:34:20 UTC (rev 162) @@ -0,0 +1,19 @@ +package org.openfast.template; + +public class DefaultOperator implements Operator { + private static final long serialVersionUID = 1L; + private String defaultValue; + + public DefaultOperator(String defaultValue) { + this.defaultValue = defaultValue; + } + + public String getDefaultValue() { + return defaultValue; + } + + public String getName() { + return "default"; + } + +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/DeltaOperator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/DeltaOperator.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/DeltaOperator.java 2008-07-07 19:34:20 UTC (rev 162) @@ -0,0 +1,16 @@ +package org.openfast.template; + +import org.lasalletech.exom.QName; + +public class DeltaOperator extends DictionaryOperator { + private static final long serialVersionUID = 1L; + + public DeltaOperator(QName key, String dictionary, String defaultValue) { + super(key, dictionary, defaultValue); + } + + + public String getName() { + return "delta"; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/DictionaryOperator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/DictionaryOperator.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/DictionaryOperator.java 2008-07-07 19:34:20 UTC (rev 162) @@ -0,0 +1,28 @@ +package org.openfast.template; + +import org.lasalletech.exom.QName; + +public abstract class DictionaryOperator implements Operator { + private static final long serialVersionUID = 1L; + private final QName key; + private final String dictionary; + private final String defaultValue; + + protected DictionaryOperator(QName key, String dictionary, String defaultValue) { + this.key = key; + this.dictionary = dictionary; + this.defaultValue = defaultValue; + } + + public QName getKey() { + return key; + } + + public String getDictionary() { + return dictionary; + } + + public String getDefaultValue() { + return defaultValue; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/IncrementOperator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/IncrementOperator.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/IncrementOperator.java 2008-07-07 19:34:20 UTC (rev 162) @@ -0,0 +1,16 @@ +package org.openfast.template; + +import org.lasalletech.exom.QName; + +public class IncrementOperator extends DictionaryOperator { + private static final long serialVersionUID = 1L; + + public IncrementOperator(QName key, String dictionary, String defaultValue) { + super(key, dictionary, defaultValue); + } + + + public String getName() { + return "increment"; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Operator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Operator.java 2008-07-07 17:34:45 UTC (rev 161) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Operator.java 2008-07-07 19:34:20 UTC (rev 162) @@ -23,5 +23,9 @@ import java.io.Serializable; public interface Operator extends Serializable { + Operator NONE = new Operator() { + private static final long serialVersionUID = 1L; + public String getName() { return "none"; } + }; String getName(); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java 2008-07-07 17:34:45 UTC (rev 161) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java 2008-07-07 19:34:20 UTC (rev 162) @@ -27,7 +27,6 @@ private static final long serialVersionUID = 1L; private final Operator operator; private final Type type; - private String dictionary; /** * Scalar constructor - sets the dictionary as global and validates the @@ -50,7 +49,6 @@ public Scalar(QName name, Type type, Operator operator, boolean optional) { super(name, optional); this.operator = operator; - this.dictionary = "global"; this.type = type; } /** @@ -70,7 +68,6 @@ */ public Scalar(QName name, Type type, boolean optional) { super(name, optional); - this.dictionary = "global"; this.type = type; this.operator = null; } @@ -90,29 +87,10 @@ } /** - * - * @return Returns the dictionary as a string - */ - public String getDictionary() { - return dictionary; - } - - /** - * Sets the dictionary to the passed string - * - * @param dictionary - * The string to be stored as the dictionary - */ - public void setDictionary(String dictionary) { - 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 + "]"; } /** * @return Returns the string 'scalar' Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/TailOperator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/TailOperator.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/TailOperator.java 2008-07-07 19:34:20 UTC (rev 162) @@ -0,0 +1,15 @@ +package org.openfast.template; + +import org.lasalletech.exom.QName; + +public class TailOperator extends DictionaryOperator { + private static final long serialVersionUID = 1L; + + public TailOperator(QName key, String dictionary, String defaultValue) { + super(key, dictionary, defaultValue); + } + + public String getName() { + return "tail"; + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ComposedDecimalParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ComposedDecimalParser.java 2008-07-07 17:34:45 UTC (rev 161) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ComposedDecimalParser.java 2008-07-07 19:34:20 UTC (rev 162) @@ -80,51 +80,19 @@ */ private Field createComposedDecimal(Element fieldNode, QName name, boolean optional, Node mantissaNode, Node exponentNode, ParsingContext context) { - String mantissaOperator = "none"; - String exponentOperator = "none"; - QName mantissaKey = null; - QName exponentKey = null; - String mantissaDictionary = context.getDictionary(); - String exponentDictionary = context.getDictionary(); - String mantissaNamespace = context.getNamespace(); - String exponentNamespace = context.getNamespace(); + Operator mantissaOp = Operator.NONE; if ((mantissaNode != null) && mantissaNode.hasChildNodes()) { Element operatorElement = getElement((Element) mantissaNode, 1); - mantissaOperator = operatorElement.getNodeName(); -// if (operatorElement.hasAttribute("value")) -// mantissaDefaultValue = Type.I64.getValue(operatorElement.getAttribute("value")); - if (operatorElement.hasAttribute("ns")) - mantissaNamespace = operatorElement.getAttribute("ns"); - if (operatorElement.hasAttribute("key")) - mantissaKey = new QName(operatorElement.getAttribute("key"), mantissaNamespace); - if (operatorElement.hasAttribute("dictionary")) - mantissaDictionary = operatorElement.getAttribute("dictionary"); + mantissaOp = context.getOperatorParser(operatorElement).parse(operatorElement, context); } + Operator exponentOp = Operator.NONE; if ((exponentNode != null) && exponentNode.hasChildNodes()) { Element operatorElement = getElement((Element) exponentNode, 1); - exponentOperator = operatorElement.getNodeName(); -// if (operatorElement.hasAttribute("value")) -// exponentDefaultValue = Type.I32.getValue(operatorElement.getAttribute("value")); - if (operatorElement.hasAttribute("ns")) - exponentNamespace = operatorElement.getAttribute("ns"); - if (operatorElement.hasAttribute("key")) - exponentKey = new QName(operatorElement.getAttribute("key"), exponentNamespace); - if (operatorElement.hasAttribute("dictionary")) - exponentDictionary = operatorElement.getAttribute("dictionary"); + exponentOp = context.getOperatorParser(operatorElement).parse(operatorElement, context); } - Operator exponentOp = context.getOperatorRegistry().get(exponentOperator); - Operator mantissaOp = context.getOperatorRegistry().get(mantissaOperator); Scalar exponentScalar = new Scalar(Global.createImplicitName(name), Type.I32, exponentOp, optional); Scalar mantissaScalar = new Scalar(Global.createImplicitName(name), Type.I64, mantissaOp, false); ComposedScalar scalar = new ComposedScalar(name, Type.DECIMAL, new Scalar[] { exponentScalar, mantissaScalar }, optional); - Scalar exponent = scalar.getFields()[0]; - exponent.setDictionary(exponentDictionary); - if (exponentKey != null) - exponent.setKey(exponentKey); - Scalar mantissa = scalar.getFields()[1]; - mantissa.setDictionary(mantissaDictionary); - if (mantissaKey != null) - mantissa.setKey(mantissaKey); if (fieldNode.hasAttribute("id")) scalar.setId(fieldNode.getAttribute("id")); return scalar; Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ConstantOperatorParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ConstantOperatorParser.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ConstantOperatorParser.java 2008-07-07 19:34:20 UTC (rev 162) @@ -0,0 +1,18 @@ +package org.openfast.template.loader; + +import org.openfast.template.ConstantOperator; +import org.openfast.template.Operator; +import org.w3c.dom.Element; + +public class ConstantOperatorParser implements OperatorParser { + public boolean canParse(Element element, ParsingContext context) { + return "constant".equals(element.getNodeName()); + } + + public Operator parse(Element operatorNode, ParsingContext context) { + String defaultValue = null; + if (operatorNode.hasAttribute("value")) + defaultValue = operatorNode.getAttribute("value"); + return new ConstantOperator(defaultValue); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/CopyOperatorParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/CopyOperatorParser.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/CopyOperatorParser.java 2008-07-07 19:34:20 UTC (rev 162) @@ -0,0 +1,17 @@ +package org.openfast.template.loader; + +import org.lasalletech.exom.QName; +import org.openfast.template.CopyOperator; +import org.openfast.template.Operator; +import org.w3c.dom.Element; + +public class CopyOperatorParser extends DictionaryOperatorParser { + public boolean canParse(Element element, ParsingContext context) { + return "copy".equals(element.getNodeName()); + } + + @Override + public Operator doParse(Element operatorNode, String dictionary, QName key, String defaultValue) { + return new CopyOperator(key, dictionary, defaultValue); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DefaultOperatorParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DefaultOperatorParser.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DefaultOperatorParser.java 2008-07-07 19:34:20 UTC (rev 162) @@ -0,0 +1,18 @@ +package org.openfast.template.loader; + +import org.openfast.template.DefaultOperator; +import org.openfast.template.Operator; +import org.w3c.dom.Element; + +public class DefaultOperatorParser implements OperatorParser { + public boolean canParse(Element element, ParsingContext context) { + return "default".equals(element.getNodeName()); + } + + public Operator parse(Element operatorElement, ParsingContext context) { + String defaultValue = null; + if (operatorElement.hasAttribute("value")) + defaultValue = operatorElement.getAttribute("value"); + return new DefaultOperator(defaultValue); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DeltaOperatorParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DeltaOperatorParser.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DeltaOperatorParser.java 2008-07-07 19:34:20 UTC (rev 162) @@ -0,0 +1,17 @@ +package org.openfast.template.loader; + +import org.lasalletech.exom.QName; +import org.openfast.template.DeltaOperator; +import org.openfast.template.Operator; +import org.w3c.dom.Element; + +public class DeltaOperatorParser extends DictionaryOperatorParser { + public boolean canParse(Element element, ParsingContext context) { + return "delta".equals(element.getNodeName()); + } + + @Override + public Operator doParse(Element operatorNode, String dictionary, QName key, String defaultValue) { + return new DeltaOperator(key, dictionary, defaultValue); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DictionaryOperatorParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DictionaryOperatorParser.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/DictionaryOperatorParser.java 2008-07-07 19:34:20 UTC (rev 162) @@ -0,0 +1,23 @@ +package org.openfast.template.loader; + +import org.lasalletech.exom.QName; +import org.openfast.template.Operator; +import org.w3c.dom.Element; + +public abstract class DictionaryOperatorParser implements OperatorParser { + public Operator parse(Element operatorElement, ParsingContext context) { + String defaultValue = null; + String key = context.getName().getName(); + String ns = context.getNamespace(); + String dictionary = operatorElement.hasAttribute("dictionary") ? operatorElement.getAttribute("dictionary") : context.getDictionary(); + if (operatorElement.hasAttribute("value")) + defaultValue = operatorElement.getAttribute("value"); + if (operatorElement.hasAttribute("key")) + key = operatorElement.getAttribute("key"); + if (operatorElement.hasAttribute("ns")) + ns = operatorElement.getAttribute("ns"); + return doParse(operatorElement, dictionary, new QName(key, ns), defaultValue); + } + + public abstract Operator doParse(Element operatorNode, String dictionary, QName key, String defaultValue); +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/IncrementOperatorParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/IncrementOperatorParser.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/IncrementOperatorParser.java 2008-07-07 19:34:20 UTC (rev 162) @@ -0,0 +1,17 @@ +package org.openfast.template.loader; + +import org.lasalletech.exom.QName; +import org.openfast.template.IncrementOperator; +import org.openfast.template.Operator; +import org.w3c.dom.Element; + +public class IncrementOperatorParser extends DictionaryOperatorParser { + public boolean canParse(Element element, ParsingContext context) { + return "increment".equals(element.getNodeName()); + } + + @Override + public Operator doParse(Element operatorNode, String dictionary, QName key, String defaultValue) { + return new IncrementOperator(key, dictionary, defaultValue); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/OperatorParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/OperatorParser.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/OperatorParser.java 2008-07-07 19:34:20 UTC (rev 162) @@ -0,0 +1,9 @@ +package org.openfast.template.loader; + +import org.openfast.template.Operator; +import org.w3c.dom.Element; + +public interface OperatorParser { + Operator parse(Element operatorNode, ParsingContext context); + boolean canParse(Element element, ParsingContext context); +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ParsingContext.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ParsingContext.java 2008-07-07 17:34:45 UTC (rev 161) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ParsingContext.java 2008-07-07 19:34:20 UTC (rev 162) @@ -24,7 +24,6 @@ import org.lasalletech.exom.QName; import org.openfast.error.ErrorHandler; import org.openfast.fast.impl.FastImplementation; -import org.openfast.template.OperatorRegistry; import org.openfast.template.TemplateRegistry; import org.openfast.template.TypeRegistry; import org.w3c.dom.Element; @@ -158,16 +157,23 @@ public void addFieldParser(FieldParser parser) { getFieldParsers().add(parser); } - - public OperatorRegistry getOperatorRegistry() { - if (implementation != null) - return implementation.getOperatorRegistry(); - return parent.getOperatorRegistry(); - } public TypeRegistry getTypeRegistry() { if (implementation != null) return implementation.getTypeRegistry(); return parent.getTypeRegistry(); } + + public OperatorParser getOperatorParser(Element operatorElement) { + if (implementation != null) { + List<OperatorParser> parsers = implementation.getOperatorParsers(); + for (int i = parsers.size() - 1; i >= 0; i--) { + OperatorParser parser = ((OperatorParser) parsers.get(i)); + if (parser.canParse(operatorElement, this)) + return parser; + } + return null; + } + return parent.getOperatorParser(operatorElement); + } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ScalarParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ScalarParser.java 2008-07-07 17:34:45 UTC (rev 161) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ScalarParser.java 2008-07-07 19:34:20 UTC (rev 162) @@ -45,29 +45,15 @@ } public Field parse(Element fieldNode, boolean optional, ParsingContext context) { - Operator operator = context.getOperatorRegistry().getDefault();//Operator.NONE; - String defaultValue = null; - String key = null; - String ns = ""; + Operator operator = Operator.NONE; Element operatorElement = getOperatorElement(fieldNode); if (operatorElement != null) { - if (operatorElement.hasAttribute("value")) - defaultValue = operatorElement.getAttribute("value"); - operator = context.getOperatorRegistry().get(operatorElement.getNodeName()); - if (operatorElement.hasAttribute("key")) - key = operatorElement.getAttribute("key"); - if (operatorElement.hasAttribute("ns")) - ns = operatorElement.getAttribute("ns"); - if (operatorElement.hasAttribute("dictionary")) - context.setDictionary(operatorElement.getAttribute("dictionary")); + operator = context.getOperatorParser(operatorElement).parse(operatorElement, context); } Type type = (Type) context.getTypeRegistry().get(getTypeName(fieldNode)); Scalar scalar = new Scalar(getName(fieldNode, context), type, operator, optional); if (fieldNode.hasAttribute("id")) scalar.setId(fieldNode.getAttribute("id")); - if (key != null) - scalar.setKey(new QName(key, ns)); - scalar.setDictionary(context.getDictionary()); parseExternalAttributes(fieldNode, scalar); return scalar; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/SequenceParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/SequenceParser.java 2008-07-07 17:34:45 UTC (rev 161) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/SequenceParser.java 2008-07-07 19:34:20 UTC (rev 162) @@ -70,7 +70,6 @@ NodeList lengthElements = sequence.getElementsByTagName("length"); if (lengthElements.getLength() == 0) { Scalar implicitLength = new Scalar(Global.createImplicitName(name), Type.U32, null, optional); - implicitLength.setDictionary(parent.getDictionary()); return implicitLength; } Element length = (Element) lengthElements.item(0); Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TailOperatorParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TailOperatorParser.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TailOperatorParser.java 2008-07-07 19:34:20 UTC (rev 162) @@ -0,0 +1,17 @@ +package org.openfast.template.loader; + +import org.lasalletech.exom.QName; +import org.openfast.template.Operator; +import org.openfast.template.TailOperator; +import org.w3c.dom.Element; + +public class TailOperatorParser extends DictionaryOperatorParser { + public boolean canParse(Element element, ParsingContext context) { + return "tail".equals(element.getNodeName()); + } + + @Override + public Operator doParse(Element operatorNode, String dictionary, QName key, String defaultValue) { + return new TailOperator(key, dictionary, defaultValue); + } +} Modified: branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/XMLMessageTemplateLoaderTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/XMLMessageTemplateLoaderTest.java 2008-07-07 17:34:45 UTC (rev 161) +++ branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/XMLMessageTemplateLoaderTest.java 2008-07-07 19:34:20 UTC (rev 162) @@ -25,14 +25,13 @@ import org.openfast.error.ErrorHandler; import org.openfast.error.FastConstants; import org.openfast.error.FastException; -import org.openfast.fast.FastOperators; import org.openfast.fast.FastTypes; import org.openfast.template.ComposedScalar; +import org.openfast.template.DictionaryOperator; import org.openfast.template.DynamicTemplateReference; import org.openfast.template.Field; import org.openfast.template.Group; import org.openfast.template.MessageTemplate; -import org.openfast.template.Operator; import org.openfast.template.Scalar; import org.openfast.template.Sequence; import org.openfast.template.Type; @@ -47,8 +46,8 @@ + " ns=\"http://www.fixprotocol.org/ns/templates/sample\">" + " <template name=\"SampleTemplate\">" + " <uInt32 name=\"value\"><copy key=\"integer\" /></uInt32>" + " </template>" + "</templates>"; MessageTemplate messageTemplate = template(templateXml); - assertScalarField(messageTemplate, 0, FastTypes.U32, "value", FastOperators.COPY, - "http://www.fixprotocol.org/ns/templates/sample"); + assertScalarField(messageTemplate, 0, FastTypes.U32, "value", NS); + assertOperator(messageTemplate, 0, "copy", "integer", NS, null, "global"); } public void testLoadTemplateThatContainsDecimalWithTwinOperators() { @@ -59,23 +58,21 @@ + " <decimal name=\"ask\"><mantissa><delta /></mantissa></decimal>" + " <decimal name=\"high\"><exponent><copy/></exponent></decimal>" + " <decimal name=\"low\"><mantissa><delta value=\"10\"/></mantissa><exponent><copy value=\"-2\" /></exponent></decimal>" - + " <decimal name=\"open\"><copy /></decimal>" + " <decimal name=\"close\"><copy /></decimal>" + " </template>" + + " <decimal name=\"open\"><copy /></decimal>" + + " <decimal name=\"close\"><copy /></decimal>" + + " </template>" + "</templates>"; MessageTemplate messageTemplate = template(templateXml); assertEquals("SampleTemplate", messageTemplate.getName()); assertEquals(6, messageTemplate.getFieldCount()); - assertComposedScalarField(messageTemplate, 0, FastTypes.DECIMAL, "bid", FastOperators.COPY, "-2", FastOperators.DELTA, null, - "http://www.fixprotocol.org/ns/templates/sample"); - assertComposedScalarField(messageTemplate, 1, FastTypes.DECIMAL, "ask", FastOperators.NONE, null, FastOperators.DELTA, null, - "http://www.fixprotocol.org/ns/templates/sample"); - assertComposedScalarField(messageTemplate, 2, FastTypes.DECIMAL, "high", FastOperators.COPY, null, FastOperators.NONE, null, - "http://www.fixprotocol.org/ns/templates/sample"); - assertComposedScalarField(messageTemplate, 3, FastTypes.DECIMAL, "low", FastOperators.COPY, "-2", FastOperators.DELTA, "10", - "http://www.fixprotocol.org/ns/templates/sample"); - assertScalarField(messageTemplate, 4, FastTypes.DECIMAL, "open", FastOperators.COPY, - "http://www.fixprotocol.org/ns/templates/sample"); - assertScalarField(messageTemplate, 5, FastTypes.DECIMAL, "close", FastOperators.COPY, - "http://www.fixprotocol.org/ns/templates/sample"); + assertComposedScalarField(messageTemplate, 0, FastTypes.DECIMAL, "bid", NS, "delta", null, null, "global", "copy", null, "-2", "global"); + assertComposedScalarField(messageTemplate, 1, FastTypes.DECIMAL, "ask", NS, "delta", null, null, "global", "none", null, null, null); + assertComposedScalarField(messageTemplate, 2, FastTypes.DECIMAL, "high", NS, "none", null, null, null, "copy", null, null, "global"); + assertComposedScalarField(messageTemplate, 3, FastTypes.DECIMAL, "low", NS, "delta", null, "10", "global", "copy", null, "-2", "global"); + assertScalarField(messageTemplate, 4, FastTypes.DECIMAL, "open", NS); + assertOperator(messageTemplate, 4, "copy", "open", NS, null, "global"); + assertScalarField(messageTemplate, 5, FastTypes.DECIMAL, "close", NS); + assertOperator(messageTemplate, 5, "copy", "close", NS, null, "global"); } public void testLoadTemplateThatContainsGroups() { @@ -97,14 +94,10 @@ + " <string name=\"location\" charset=\"ascii\" presence=\"mandatory\"><copy /></string>" + " <string name=\"id2\" charset=\"ascii\" presence=\"optional\"><copy /></string>" + " </template>" + "</templates>"; MessageTemplate messageTemplate = template(templateXml); - assertScalarField(messageTemplate, 0, FastTypes.UNICODE, "name", FastOperators.COPY, - "http://www.fixprotocol.org/ns/templates/sample"); - assertOptionalScalarField(messageTemplate, 1, FastTypes.UNICODE, "id", FastOperators.COPY, - "http://www.fixprotocol.org/ns/templates/sample"); - assertScalarField(messageTemplate, 2, FastTypes.ASCII, "location", FastOperators.COPY, - "http://www.fixprotocol.org/ns/templates/sample"); - assertOptionalScalarField(messageTemplate, 3, FastTypes.ASCII, "id2", FastOperators.COPY, - "http://www.fixprotocol.org/ns/templates/sample"); + assertScalarField(messageTemplate, 0, FastTypes.UNICODE, "name", NS); + assertOptionalScalarField(messageTemplate, 1, FastTypes.UNICODE, "id", NS); + assertScalarField(messageTemplate, 2, FastTypes.ASCII, "location", NS); + assertOptionalScalarField(messageTemplate, 3, FastTypes.ASCII, "id2", NS); } public void testLoadMdIncrementalRefreshTemplate() { @@ -116,37 +109,37 @@ assertEquals(9, messageTemplate.getFieldCount()); /********************************** TEMPLATE FIELDS **********************************/ int index = 0; - assertScalarField(messageTemplate, index++, FastTypes.ASCII, "8", FastOperators.CONSTANT, NS); - assertScalarField(messageTemplate, index++, FastTypes.U32, "9", FastOperators.CONSTANT, NS); - assertScalarField(messageTemplate, index++, FastTypes.ASCII, "35", FastOperators.CONSTANT, NS); - assertScalarField(messageTemplate, index++, FastTypes.ASCII, "49", FastOperators.CONSTANT, NS); - assertScalarField(messageTemplate, index++, FastTypes.U32, "34", FastOperators.INCREMENT, NS); - assertScalarField(messageTemplate, index++, FastTypes.ASCII, "52", FastOperators.DELTA, NS); - assertScalarField(messageTemplate, index++, FastTypes.U32, "75", FastOperators.COPY, NS); + assertScalarField(messageTemplate, index++, FastTypes.ASCII, "8", NS); + assertScalarField(messageTemplate, index++, FastTypes.U32, "9", NS); + assertScalarField(messageTemplate, index++, FastTypes.ASCII, "35", NS); + assertScalarField(messageTemplate, index++, FastTypes.ASCII, "49", NS); + assertScalarField(messageTemplate, index++, FastTypes.U32, "34", NS); + assertScalarField(messageTemplate, index++, FastTypes.ASCII, "52", NS); + assertScalarField(messageTemplate, index++, FastTypes.U32, "75", NS); /************************************* SEQUENCE **************************************/ - assertSequence(messageTemplate, index, "MDEntries", 17, "268", FastOperators.NONE, NS); + assertSequence(messageTemplate, index, "MDEntries", 17, "268", NS); Sequence sequence = (Sequence) messageTemplate.getField(index++); assertEquals("MDEntries", sequence.getTypeReference().getName()); /********************************** SEQUENCE FIELDS **********************************/ int seqIndex = 0; - assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.DECIMAL, "270", FastOperators.DELTA, NS); - assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.I32, "271", FastOperators.DELTA, NS); - assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.U32, "273", FastOperators.DELTA, NS); - assertOptionalScalarField(sequence.getGroup(), seqIndex++, FastTypes.U32, "346", FastOperators.NONE, NS); - assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.U32, "1023", FastOperators.INCREMENT, NS); - assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "279", FastOperators.COPY, NS); - assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "269", FastOperators.COPY, NS); - assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "107", FastOperators.COPY, NS); - assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "48", FastOperators.DELTA, NS); - assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "276", FastOperators.COPY, NS); - assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "274", FastOperators.COPY, NS); - assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.DECIMAL, "451", FastOperators.COPY, NS); - assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "277", FastOperators.DEFAULT, NS); - assertOptionalScalarField(sequence.getGroup(), seqIndex++, FastTypes.U32, "1020", FastOperators.NONE, NS); - assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.I32, "537", FastOperators.DEFAULT, NS); - assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "1024", FastOperators.DEFAULT, NS); - assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "336", FastOperators.DEFAULT, NS); - assertScalarField(messageTemplate, index++, FastTypes.ASCII, "10", FastOperators.NONE, NS); + assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.DECIMAL, "270", NS); + assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.I32, "271", NS); + assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.U32, "273", NS); + assertOptionalScalarField(sequence.getGroup(), seqIndex++, FastTypes.U32, "346", NS); + assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.U32, "1023", NS); + assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "279", NS); + assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "269", NS); + assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "107", NS); + assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "48", NS); + assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "276", NS); + assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "274", NS); + assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.DECIMAL, "451", NS); + assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "277", NS); + assertOptionalScalarField(sequence.getGroup(), seqIndex++, FastTypes.U32, "1020", NS); + assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.I32, "537", NS); + assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "1024", NS); + assertScalarField(sequence.getGroup(), seqIndex++, FastTypes.ASCII, "336", NS); + assertScalarField(messageTemplate, index++, FastTypes.ASCII, "10", NS); } public void testStaticTemplateReference() { @@ -162,9 +155,9 @@ "</templates>"; MessageTemplate[] templates = new XMLMessageTemplateLoader().load(stream(templateXml)); assertEquals(3, templates[1].getFieldCount()); - assertScalarField(templates[1], 0, FastTypes.U32, "quantity", FastOperators.NONE, ""); - assertScalarField(templates[1], 1, FastTypes.ASCII, "string", FastOperators.NONE, ""); - assertScalarField(templates[1], 2, FastTypes.DECIMAL, "price", FastOperators.NONE, ""); + assertScalarField(templates[1], 0, FastTypes.U32, "quantity", ""); + assertScalarField(templates[1], 1, FastTypes.ASCII, "string", ""); + assertScalarField(templates[1], 2, FastTypes.DECIMAL, "price", ""); } public void testNonExistantTemplateReference() { @@ -188,9 +181,9 @@ MessageTemplate[] templates = loader2.load(stream(template2Xml)); assertEquals(3, templates[0].getFieldCount()); - assertScalarField(templates[0], 0, FastTypes.U32, "quantity", FastOperators.NONE, ""); - assertScalarField(templates[0], 1, FastTypes.ASCII, "string", FastOperators.NONE, ""); - assertScalarField(templates[0], 2, FastTypes.DECIMAL, "price", FastOperators.NONE, ""); + assertScalarField(templates[0], 0, FastTypes.U32, "quantity", ""); + assertScalarField(templates[0], 1, FastTypes.ASCII, "string", ""); + assertScalarField(templates[0], 2, FastTypes.DECIMAL, "price", ""); } public void testTemplateReferencedFromPreviousLoad() { @@ -201,9 +194,9 @@ loader.load(stream(template1Xml)); MessageTemplate[] templates = loader.load(stream(template2Xml)); assertEquals(3, templates[0].getFieldCount()); - assertScalarField(templates[0], 0, FastTypes.U32, "quantity", FastOperators.NONE, ""); - assertScalarField(templates[0], 1, FastTypes.ASCII, "string", FastOperators.NONE, ""); - assertScalarField(templates[0], 2, FastTypes.DECIMAL, "price", FastOperators.NONE, ""); + assertScalarField(templates[0], 0, FastTypes.U32, "quantity", ""); + assertScalarField(templates[0], 1, FastTypes.ASCII, "string", ""); + assertScalarField(templates[0], 2, FastTypes.DECIMAL, "price", ""); } public void testDynamicTemplateReference() { @@ -214,8 +207,8 @@ loader.load(stream(template1Xml)); MessageTemplate[] templates = loader.load(stream(template2Xml)); assertEquals(3, templates[0].getFieldCount()); - assertScalarField(templates[0], 0, FastTypes.U32, "quantity", FastOperators.NONE, ""); - assertScalarField(templates[0], 2, FastTypes.DECIMAL, "price", FastOperators.NONE, ""); + assertScalarField(templates[0], 0, FastTypes.U32, "quantity", ""); + assertScalarField(templates[0], 2, FastTypes.DECIMAL, "price", ""); assertTrue(templates[0].getField(1) instanceof DynamicTemplateReference); } @@ -223,7 +216,7 @@ String templateXml = "<template name=\"bvt\">" + " <byteVector name=\"data\">" + " <length name=\"dataLength\"/>" + " <tail/>" + " </byteVector>" + "</template>"; MessageTemplate bvt = template(templateXml); - assertScalarField(bvt, 0, FastTypes.BYTE_VECTOR, "data", FastOperators.TAIL, ""); + assertScalarField(bvt, 0, FastTypes.BYTE_VECTOR, "data", ""); } public void testNullDocument() { @@ -254,30 +247,44 @@ assertEquals(new Array(new QName("intArr", ""), false), template.getField(0)); } - private void assertComposedScalarField(MessageTemplate tmpl, int index, Type type, String name, Operator mantissaOperator, - String mantissaDefaultValue, Operator exponentOperator, String exponentDefaultValue, String namespace) { + private void assertComposedScalarField(MessageTemplate tmpl, int index, Type type, String name, String namespace, String mantissaOperator, String mantissaKey, String mantissaDefault, String mantissaDictionary, String exponentOperator, String exponentKey, String exponentDefault, String exponentDictionary) { ComposedScalar scalar = (ComposedScalar) tmpl.getField(index); assertEquals(new QName(name, namespace), scalar.getQName()); assertEquals(type, scalar.getType()); Scalar exponent = scalar.getFields()[0]; - assertEquals(exponentOperator, exponent.getOperator()); + assertOperator(exponent, exponentOperator, exponentKey, "", exponentDefault, exponentDictionary); Scalar mantissa = scalar.getFields()[1]; - assertEquals(mantissaOperator, mantissa.getOperator()); + assertOperator(mantissa, mantissaOperator, mantissaKey, "", mantissaDefault, mantissaDictionary); } - private void assertScalarField(Group messageTemplate, int index, Type type, String name, Operator operator, String namespace) { + private void assertScalarField(Group messageTemplate, int index, Type type, String name, String namespace) { Scalar scalar = messageTemplate.getScalar(index); assertEquals(new QName(name, namespace), scalar.getQName()); - assertEquals(operator, scalar.getOperator()); assertEquals(type, scalar.getType()); assertFalse(scalar.isOptional()); } + + private void assertOperator(Group group, int index, String operator, String key, String namespace, String defaultValue, String dictionary) { + Scalar scalar = group.getScalar(index); + assertOperator(scalar, operator, key, namespace, defaultValue, dictionary); + } - private void assertOptionalScalarField(Group messageTemplate, int index, Type type, String name, Operator operator, - String namespace) { + private void assertOperator(Scalar scalar, String operator, String key, String namespace, String defaultValue, String dictionary) { + assertEquals(operator, scalar.getOperator().getName()); + if (key != null) { + assertEquals(new QName(key, namespace), ((DictionaryOperator) scalar.getOperator()).getKey()); + } + if (defaultValue != null) { + assertEquals(defaultValue, ((DictionaryOperator) scalar.getOperator()).getDefaultValue()); + } + if (dictionary != null) { + assertEquals(dictionary, ((DictionaryOperator) scalar.getOperator()).getDictionary()); + } + } + + private void assertOptionalScalarField(Group messageTemplate, int index, Type type, String name, String namespace) { Scalar scalar = messageTemplate.getScalar(index); assertEquals(new QName(name, namespace), scalar.getQName()); - assertEquals(operator, scalar.getOperator()); assertEquals(type, scalar.getType()); assertTrue(scalar.isOptional()); } @@ -287,14 +294,12 @@ assertEquals(name, group.getName()); } - private void assertSequence(MessageTemplate messageTemplate, int index, String name, int fieldCount, String lengthFieldName, - Operator lengthOperator, String namespace) { + private void assertSequence(MessageTemplate messageTemplate, int index, String name, int fieldCount, String lengthFieldName, String namespace) { Sequence sequence = (Sequence) messageTemplate.getField(index); assertEquals(fieldCount, sequence.getFieldCount()); assertEquals(new QName(name, namespace), sequence.getQName()); if (lengthFieldName != null) { assertEquals(lengthFieldName, sequence.getLength().getName()); - assertEquals(lengthOperator, sequence.getLength().getOperator()); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-07-07 17:35:16
|
Revision: 161 http://openfast.svn.sourceforge.net/openfast/?rev=161&view=rev Author: jacob_northey Date: 2008-07-07 10:34:45 -0700 (Mon, 07 Jul 2008) Log Message: ----------- Fixed all broken XMLMessageTemplateLoaderTest tests. Still need to handle default values for operators in XML template definition loading. Modified Paths: -------------- branches/openfast-2.x/core/pom.xml branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java branches/openfast-2.x/core/src/main/java/org/openfast/template/DynamicTemplateReference.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Field.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Group.java branches/openfast-2.x/core/src/main/java/org/openfast/template/MessageTemplate.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java branches/openfast-2.x/core/src/main/java/org/openfast/template/StaticTemplateReference.java branches/openfast-2.x/core/src/main/java/org/openfast/template/TemplateRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Type.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ComposedDecimalParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/GroupParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ParsingContext.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ScalarParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TemplateParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/XMLMessageTemplateLoader.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/Type.java branches/openfast-2.x/core/src/test/java/org/openfast/template/TypeTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/Array.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/XMLMessageTemplateLoaderTest.java branches/openfast-2.x/core/src/test/java/org/openfast/test/OpenFastTestCase.java Added Paths: ----------- branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/ branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast1_1Implementation.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/FastImplementation.java branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicField.java branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicOperatorRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicTypeRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/template/OperatorRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/template/TypeRegistry.java Modified: branches/openfast-2.x/core/pom.xml =================================================================== --- branches/openfast-2.x/core/pom.xml 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/pom.xml 2008-07-07 17:34:45 UTC (rev 161) @@ -39,8 +39,8 @@ <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> - <source>1.4</source> - <target>1.4</target> + <source>1.5</source> + <target>1.5</target> </configuration> </plugin> <plugin> Added: branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast1_1Implementation.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast1_1Implementation.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/Fast1_1Implementation.java 2008-07-07 17:34:45 UTC (rev 161) @@ -0,0 +1,75 @@ +package org.openfast.fast.impl; + +import java.util.ArrayList; +import java.util.List; +import org.openfast.fast.FastOperators; +import org.openfast.fast.FastTypes; +import org.openfast.template.BasicOperatorRegistry; +import org.openfast.template.BasicTypeRegistry; +import org.openfast.template.OperatorRegistry; +import org.openfast.template.TypeRegistry; +import org.openfast.template.loader.ByteVectorParser; +import org.openfast.template.loader.ComposedDecimalParser; +import org.openfast.template.loader.FieldParser; +import org.openfast.template.loader.GroupParser; +import org.openfast.template.loader.ScalarParser; +import org.openfast.template.loader.SequenceParser; +import org.openfast.template.loader.StringParser; +import org.openfast.template.loader.TemplateRefParser; + +public class Fast1_1Implementation extends FastImplementation { + private List<FieldParser> parsers; + private TypeRegistry typeRegistry; + private OperatorRegistry operatorRegistry; + + @Override + public List<FieldParser> getFieldParsers() { + if (parsers == null) { + parsers = new ArrayList<FieldParser>(); + parsers.add(new ScalarParser()); + parsers.add(new GroupParser()); + parsers.add(new SequenceParser()); + parsers.add(new ComposedDecimalParser()); + parsers.add(new StringParser()); + parsers.add(new ByteVectorParser()); + parsers.add(new TemplateRefParser()); + } + return parsers; + } + + @Override + public OperatorRegistry getOperatorRegistry() { + if (operatorRegistry == null) { + operatorRegistry = new BasicOperatorRegistry(); + operatorRegistry.register("none", FastOperators.NONE); + operatorRegistry.register("tail", FastOperators.TAIL); + operatorRegistry.register("delta", FastOperators.DELTA); + operatorRegistry.register("default", FastOperators.DEFAULT); + operatorRegistry.register("constant", FastOperators.CONSTANT); + operatorRegistry.register("increment", FastOperators.INCREMENT); + operatorRegistry.register("copy", FastOperators.COPY); + } + return operatorRegistry; + } + + @Override + public TypeRegistry getTypeRegistry() { + if (typeRegistry == null) { + typeRegistry = new BasicTypeRegistry(); + typeRegistry.register("ascii", FastTypes.ASCII); + typeRegistry.register("byteVector", FastTypes.BYTE_VECTOR); + typeRegistry.register("decimal", FastTypes.DECIMAL); + typeRegistry.register("int8", FastTypes.I8); + typeRegistry.register("int16", FastTypes.I16); + typeRegistry.register("int32", FastTypes.I32); + typeRegistry.register("int64", FastTypes.I64); + typeRegistry.register("string", FastTypes.STRING); + typeRegistry.register("uInt8", FastTypes.U8); + typeRegistry.register("uInt16", FastTypes.U16); + typeRegistry.register("uInt32", FastTypes.U32); + typeRegistry.register("uInt64", FastTypes.U64); + typeRegistry.register("unicode", FastTypes.UNICODE); + } + return typeRegistry; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/FastImplementation.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/FastImplementation.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/fast/impl/FastImplementation.java 2008-07-07 17:34:45 UTC (rev 161) @@ -0,0 +1,27 @@ +package org.openfast.fast.impl; + +import java.util.List; +import org.openfast.template.OperatorRegistry; +import org.openfast.template.TypeRegistry; +import org.openfast.template.loader.FieldParser; + +public abstract class FastImplementation { + public static final String FAST_1_1 = "FAST 1.1"; + private static FastImplementation fast1x1; + public abstract TypeRegistry getTypeRegistry(); + public abstract OperatorRegistry getOperatorRegistry(); + public abstract List<FieldParser> getFieldParsers(); + public static FastImplementation getVersion(String version) { + if (FAST_1_1.equals(version)) { + return getDefaultVersion(); + } + throw new IllegalArgumentException("The version " + version + " is not defined."); + } + public static FastImplementation getDefaultVersion() { + synchronized(FAST_1_1) { + if (fast1x1 == null) + fast1x1 = new Fast1_1Implementation(); + } + return fast1x1; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicField.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicField.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicField.java 2008-07-07 17:34:45 UTC (rev 161) @@ -0,0 +1,166 @@ +/* +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.HashMap; +import java.util.Map; +import org.lasalletech.exom.QName; +import org.lasalletech.exom.Type; + +public class BasicField implements Field { + private static final long serialVersionUID = 1L; + protected final QName name; + protected QName key; + protected final boolean optional; + protected String id; + private Map<QName, String> attributes; + + /** + * Field Constructor + * + * @param name + * The name of the Field, a string + * @param optional + * Determines if the Field is required or not for the data + */ + public BasicField(QName name, boolean optional) { + this.name = name; + this.key = name; + this.optional = optional; + } + + /** + * Field Constructor + * + * @param name + * The name of the Field, a string + * @param key + * The key of the Field, a string + * @param optional + * Determines if the Field is required or not for the data + */ + public BasicField(QName name, QName key, boolean optional) { + this.name = name; + this.key = key; + this.optional = optional; + } + + /** + * Field Constructor + * + * @param name + * The name of the Field, a string + * @param key + * The key of the Field, a string + * @param optional + * Determines if the Field is required or not for the data + * @param id + * The id string + */ + public BasicField(String name, String key, boolean optional, String id) { + this.name = new QName(name); + this.key = new QName(key); + this.optional = optional; + this.id = id; + } + + /** + * Find the name + * + * @return Returns the name of the Field as a string + */ + public String getName() { + return name.getName(); + } + + public QName getQName() { + return name; + } + + /** + * Check to see if the Field is required + * + * @return Returns true if the Field isn't required, false otherwise + */ + public boolean isOptional() { + return optional; + } + + /** + * Find the key + * + * @return Returns the Key as a string + */ + public QName getKey() { + return key; + } + + /** + * Sets the passed key to the current field key + * + * @param key + * The key to be set + */ + public void setKey(QName key) { + this.key = key; + } + + /** + * Find the ID + * + * @return Returns the ID as a string + */ + public String getId() { + return id; + } + + /** + * Set the ID + * + * @param id + * The new ID to set the Field's ID to + */ + public void setId(String id) { + this.id = id; + } + + public boolean hasAttribute(QName attributeName) { + return attributes != null && attributes.containsKey(attributeName); + } + + public void addAttribute(QName name, String value) { + if (attributes == null) + attributes = new HashMap<QName, String>(4); + attributes.put(name, value); + } + + public String getAttribute(QName name) { + return (String) attributes.get(name); + } + + public Type getType() { + throw new UnsupportedOperationException(); + } + + public boolean isRequired() { + return !optional; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicOperatorRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicOperatorRegistry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicOperatorRegistry.java 2008-07-07 17:34:45 UTC (rev 161) @@ -0,0 +1,25 @@ +package org.openfast.template; + +import java.util.HashMap; +import java.util.Map; +import org.openfast.fast.FastOperators; + +public class BasicOperatorRegistry implements OperatorRegistry { + private Map<String, Operator> operators = new HashMap<String, Operator>(); + + public Operator get(String name) { + return operators.get(name); + } + + public Operator getDefault() { + return FastOperators.NONE; + } + + public void register(String name, Operator operator) { + operators.put(name, operator); + } + + public boolean isDefined(String name) { + return operators.containsKey(name); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicTypeRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicTypeRegistry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicTypeRegistry.java 2008-07-07 17:34:45 UTC (rev 161) @@ -0,0 +1,20 @@ +package org.openfast.template; + +import java.util.HashMap; +import java.util.Map; + +public class BasicTypeRegistry implements TypeRegistry { + private Map<String, Type> types = new HashMap<String, Type>(); + + public Type get(String name) { + return types.get(name); + } + + public boolean isDefined(String typeName) { + return types.containsKey(typeName); + } + + public void register(String name, Type type) { + types.put(name, type); + } +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java 2008-07-07 17:34:45 UTC (rev 161) @@ -21,9 +21,9 @@ package org.openfast.template; import org.lasalletech.exom.QName; -import org.openfast.template.type.Type; +import org.openfast.template.Type; -public class ComposedScalar extends Field { +public class ComposedScalar extends BasicField { private static final long serialVersionUID = 1L; private static final Class ScalarValueType = null; private Scalar[] fields; @@ -51,7 +51,7 @@ return false; } - public Type getType() { + public org.lasalletech.exom.Type getType() { return type; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/DynamicTemplateReference.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/DynamicTemplateReference.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/DynamicTemplateReference.java 2008-07-07 17:34:45 UTC (rev 161) @@ -22,7 +22,7 @@ import org.lasalletech.exom.QName; -public class DynamicTemplateReference extends Field { +public class DynamicTemplateReference extends BasicField { private static final long serialVersionUID = 1L; public static final DynamicTemplateReference INSTANCE = new DynamicTemplateReference(); Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Field.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Field.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Field.java 2008-07-07 17:34:45 UTC (rev 161) @@ -21,156 +21,16 @@ package org.openfast.template; import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; +import org.lasalletech.exom.Named; import org.lasalletech.exom.QName; -import org.openfast.util.BitVectorReader; -public abstract class Field implements Serializable { - private static final long serialVersionUID = 1L; - protected final QName name; - protected QName key; - protected final boolean optional; - protected String id; - private Map attributes; - - /** - * Field Constructor - * - * @param name - * The name of the Field, a string - * @param optional - * Determines if the Field is required or not for the data - */ - public Field(QName name, boolean optional) { - this.name = name; - this.key = name; - this.optional = optional; - } - - /** - * Field Constructor - * - * @param name - * The name of the Field, a string - * @param key - * The key of the Field, a string - * @param optional - * Determines if the Field is required or not for the data - */ - public Field(QName name, QName key, boolean optional) { - this.name = name; - this.key = key; - this.optional = optional; - } - - /** - * Field Constructor - * - * @param name - * The name of the Field, a string - * @param key - * The key of the Field, a string - * @param optional - * Determines if the Field is required or not for the data - * @param id - * The id string - */ - public Field(String name, String key, boolean optional, String id) { - this.name = new QName(name); - this.key = new QName(key); - this.optional = optional; - this.id = id; - } - - /** - * Find the name - * - * @return Returns the name of the Field as a string - */ - public String getName() { - return name.getName(); - } - - public QName getQName() { - return name; - } - - /** - * Check to see if the Field is required - * - * @return Returns true if the Field isn't required, false otherwise - */ - public boolean isOptional() { - return optional; - } - - /** - * Find the key - * - * @return Returns the Key as a string - */ - public QName getKey() { - return key; - } - - /** - * Sets the passed key to the current field key - * - * @param key - * The key to be set - */ - public void setKey(QName key) { - this.key = key; - } - - /** - * Find the ID - * - * @return Returns the ID as a string - */ - public String getId() { - return id; - } - - /** - * Set the ID - * - * @param id - * The new ID to set the Field's ID to - */ - public void setId(String id) { - this.id = id; - } - - public boolean hasAttribute(QName attributeName) { - return attributes != null && attributes.containsKey(attributeName); - } - - public void addAttribute(QName name, String value) { - if (attributes == null) - attributes = new HashMap(4); - attributes.put(name, value); - } - - public String getAttribute(QName name) { - return (String) attributes.get(name); - } - - protected boolean isPresent(BitVectorReader presenceMapReader) { - return (!usesPresenceMapBit()) || presenceMapReader.read(); - } - - /** - * - * usesPresenceMapBit method declaration - * - */ - public abstract boolean usesPresenceMapBit(); - - - /** - * getTypeName method declaration - */ - public abstract String getTypeName(); +public interface Field extends org.lasalletech.exom.Field, Named, Serializable { + boolean isOptional(); + QName getKey(); + void setKey(QName key); + String getId(); + void setId(String id); + boolean hasAttribute(QName attributeName); + void addAttribute(QName name, String value); + String getAttribute(QName name); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Group.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Group.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Group.java 2008-07-07 17:34:45 UTC (rev 161) @@ -20,29 +20,20 @@ */ package org.openfast.template; -import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; +import java.util.LinkedList; import java.util.List; -import java.util.Map; import org.lasalletech.exom.QName; import org.lasalletech.exom.Type; import org.lasalletech.exom.simple.SimpleEntity; -import org.openfast.error.FastConstants; -public class Group extends SimpleEntity implements org.lasalletech.exom.Field { +public class Group extends SimpleEntity implements Field { private static final long serialVersionUID = 1L; - private QName typeReference = null; + protected 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 boolean optional; + protected final Field field; + protected List<StaticTemplateReference> staticTemplateReferences = Collections.emptyList(); public Group(String name, Field[] fields, boolean optional) { this(new QName(name), fields, optional); @@ -50,86 +41,24 @@ public Group(QName name, Field[] fields, boolean optional) { super(name.getName()); + field = new BasicField(name, optional); this.optional = optional; - List expandedFields = new ArrayList(); - List staticTemplateReferences = new ArrayList(); - for (int i = 0; i < fields.length; i++) { - if (fields[i] instanceof StaticTemplateReference) { - Field[] referenceFields = null;// ((StaticTemplateReference) fields[i]).getTemplate().getFields(); - for (int j = 1; j < referenceFields.length; j++) - expandedFields.add(referenceFields[j]); - staticTemplateReferences.add(fields[i]); + for (Field field : fields) { + if (field instanceof StaticTemplateReference) { + StaticTemplateReference reference = (StaticTemplateReference) field; + for (org.lasalletech.exom.Field referencedField : reference.getTemplate().getFields()) + add(referencedField); + if (staticTemplateReferences.isEmpty()) { + staticTemplateReferences = new LinkedList<StaticTemplateReference>(); + } + staticTemplateReferences.add(reference); } else { - expandedFields.add(fields[i]); + add(field); } } - this.fields = (Field[]) expandedFields.toArray(new Field[expandedFields.size()]); - this.fieldDefinitions = fields; - this.fieldIndexMap = constructFieldIndexMap(this.fields); - this.fieldNameMap = constructFieldNameMap(this.fields); - this.fieldIdMap = constructFieldIdMap(this.fields); - this.introspectiveFieldMap = constructInstrospectiveFields(this.fields); - this.usesPresenceMap = determinePresenceMapUsage(this.fields); - 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; - } - /** - * 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; - } - - private int getMaxPresenceMapSize() { - return fields.length * 2; - } - - /** - * @return Returns the optional boolean of the MapBit - */ - public boolean usesPresenceMapBit() { - return optional; - } - - public boolean usesPresenceMap() { - return usesPresenceMap; - } - - /** - * Find the number of total fields - * - * @return Returns the number of fields - */ - public int getFieldCount() { - return fields.length; - } - - /** * @return Returns the string 'group' */ public String getTypeName() { @@ -137,60 +66,6 @@ } /** - * 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) { - Map map = new HashMap(); - for (int i = 0; i < fields.length; i++) - map.put(fields[i].getQName(), fields[i]); - return map; - } - - private static Map constructFieldIdMap(Field[] fields) { - Map map = new HashMap(); - for (int i = 0; i < fields.length; i++) - 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 - * @return Returns a map object of the field array passed to it - */ - private static Map constructFieldIndexMap(Field[] fields) { - Map map = new HashMap(); - for (int i = 0; i < fields.length; i++) - map.put(fields[i], new Integer(i)); - return map; - } - - /** - * Find the index of the passed field name as an integer - * - * @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(); - } - - /** * Get the Sequence of the passed fieldName * * @param fieldName @@ -228,22 +103,6 @@ } /** - * 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); - } - - /** * Set the name of the type referenced by this group * * @param typeReference @@ -272,47 +131,6 @@ return getName(); } - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + Group.hashCode(fields); - 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; - 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; - } - - public boolean hasFieldWithId(String id) { - return fieldIdMap.containsKey(id); - } - - public Field getFieldById(String id) { - return (Field) fieldIdMap.get(id); - } - public String getChildNamespace() { return childNamespace; } @@ -321,39 +139,43 @@ this.childNamespace = childNamespace; } - public StaticTemplateReference[] getStaticTemplateReferences() { - return staticTemplateReferences; + public Type getType() { + return null; } - public StaticTemplateReference getStaticTemplateReference(String name) { - return getStaticTemplateReference(new QName(name, "")); + public boolean isRequired() { + return !optional; } - 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 void addAttribute(QName name, String value) { + field.addAttribute(name, value); } - public Field[] getFieldDefinitions() { - return fieldDefinitions; + public String getAttribute(QName name) { + return field.getAttribute(name); } - public boolean hasIntrospectiveField(String fieldName) { - return introspectiveFieldMap.containsKey(fieldName); + public String getId() { + return field.getId(); } - public Scalar getIntrospectiveField(String fieldName) { - return (Scalar) introspectiveFieldMap.get(fieldName); + public QName getKey() { + return field.getKey(); } - public Type getType() { - return null; + public boolean hasAttribute(QName attributeName) { + return field.hasAttribute(attributeName); } - public String getName() { - return null; + public boolean isOptional() { + return false; } -} + + public void setId(String id) { + field.setId(id); + } + + public void setKey(QName key) { + field.setKey(key); + } +} \ No newline at end of file Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/MessageTemplate.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/MessageTemplate.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/MessageTemplate.java 2008-07-07 17:34:45 UTC (rev 161) @@ -22,82 +22,26 @@ import org.lasalletech.exom.QName; import org.openfast.Message; -import org.openfast.template.type.Type; -public class MessageTemplate extends Group { +public class MessageTemplate extends Group implements Field { private static final long serialVersionUID = 1L; public MessageTemplate(QName name, Field[] fields) { - super(name, addTemplateIdField(fields), false); + super(name, fields, false); } - public boolean usesPresenceMap() { - return true; - } - public MessageTemplate(String name, Field[] fields) { this(new QName(name), fields); } /** - * Take an existing field array and add TemplateID information to it - * - * @param fields - * The field array that needs the TemplateID added to it - * @return Returns a new array with the passed field information and - * TemplateID - */ - private static Field[] addTemplateIdField(Field[] fields) { - Field[] newFields = new Field[fields.length + 1]; - newFields[0] = new Scalar("templateId", Type.U32, null, false); - System.arraycopy(fields, 0, newFields, 1, fields.length); - return newFields; - } - - /** - * @return Returns the length of the fields as an int - */ - public int getFieldCount() { - return fields.length; - } - - /** * @return Returns the class of the message */ - public Class getValueType() { + public Class<?> getValueType() { return Message.class; } public String toString() { return getName(); } - - /** - * Returns a field array of the current stored fields - * - * @return Returns a field array - */ - public Field[] getTemplateFields() { - Field[] f = new Field[fields.length - 1]; - System.arraycopy(fields, 1, f, 0, fields.length - 1); - return f; - } - - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null || !(obj instanceof MessageTemplate)) - return false; - return equals((MessageTemplate) obj); - } - - private boolean equals(MessageTemplate other) { - if (fields.length != other.fields.length) - return false; - for (int i = 0; i < fields.length; i++) { - if (!fields[i].equals(other.fields[i])) - return false; - } - return true; - } } Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/OperatorRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/OperatorRegistry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/OperatorRegistry.java 2008-07-07 17:34:45 UTC (rev 161) @@ -0,0 +1,8 @@ +package org.openfast.template; + +public interface OperatorRegistry { + Operator getDefault(); + Operator get(String name); + void register(String name, Operator operator); + boolean isDefined(String name); +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java 2008-07-07 17:34:45 UTC (rev 161) @@ -23,7 +23,7 @@ import org.lasalletech.exom.QName; import org.openfast.template.type.Type; -public class Scalar extends Field { +public class Scalar extends BasicField { private static final long serialVersionUID = 1L; private final Operator operator; private final Type type; @@ -78,7 +78,7 @@ * * @return Returns the type as a string */ - public Type getType() { + public org.lasalletech.exom.Type getType() { return type; } /** @@ -120,10 +120,7 @@ public String getTypeName() { return "scalar"; } - public Class getValueType() { + public Class<?> getValueType() { return null; } - public boolean usesPresenceMapBit() { - return false; - } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java 2008-07-07 17:34:45 UTC (rev 161) @@ -24,7 +24,7 @@ import org.openfast.Global; import org.openfast.template.type.Type; -public class Sequence extends Field { +public class Sequence extends BasicField { private static final long serialVersionUID = 1L; private final Group group; private final Scalar length; @@ -107,14 +107,6 @@ } /** - * - * @return True if there is a current MapBit, false otherwise - */ - public boolean usesPresenceMapBit() { - return length.usesPresenceMapBit(); - } - - /** * @return Returns the string 'sequence' */ public String getTypeName() { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/StaticTemplateReference.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/StaticTemplateReference.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/StaticTemplateReference.java 2008-07-07 17:34:45 UTC (rev 161) @@ -21,7 +21,7 @@ package org.openfast.template; -public class StaticTemplateReference extends Field { +public class StaticTemplateReference extends BasicField { private static final long serialVersionUID = 1L; private MessageTemplate template; @@ -30,18 +30,6 @@ this.template = template; } - public String getTypeName() { - return null; - } - - public Class getValueType() { - return null; - } - - public boolean usesPresenceMapBit() { - return false; - } - public MessageTemplate getTemplate() { return template; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/TemplateRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/TemplateRegistry.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/TemplateRegistry.java 2008-07-07 17:34:45 UTC (rev 161) @@ -23,7 +23,7 @@ import java.util.Iterator; import org.lasalletech.exom.QName; -public interface TemplateRegistry extends Iterable { +public interface TemplateRegistry extends Iterable<MessageTemplate> { TemplateRegistry NULL = new NullTemplateRegistry(); void registerAll(TemplateRegistry registry); @@ -56,7 +56,7 @@ * * @return an iterator over the qualified names each item is of type QName */ - Iterator/* <QName> */nameIterator(); + Iterator<QName> nameIterator(); /** * Iterator over the set of templates (defined or registered) in this * registry @@ -64,5 +64,5 @@ * @return an iterator over the set of templates each item is an instance of * MessageTemplate */ - Iterator/* <MessageTemplate> */iterator(); + Iterator<MessageTemplate> iterator(); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Type.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Type.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Type.java 2008-07-07 17:34:45 UTC (rev 161) @@ -22,7 +22,7 @@ import java.io.Serializable; -public interface Type extends Serializable { +public interface Type extends Serializable, org.lasalletech.exom.Type { String getName(); // private final static Map TYPE_NAME_MAP = new LinkedHashMap(); // private final String name; Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/TypeRegistry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/TypeRegistry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/TypeRegistry.java 2008-07-07 17:34:45 UTC (rev 161) @@ -0,0 +1,7 @@ +package org.openfast.template; + +public interface TypeRegistry { + Type get(String name); + void register(String name, Type type); + boolean isDefined(String typeName); +} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ComposedDecimalParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ComposedDecimalParser.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ComposedDecimalParser.java 2008-07-07 17:34:45 UTC (rev 161) @@ -21,12 +21,12 @@ package org.openfast.template.loader; import org.lasalletech.exom.QName; +import org.openfast.Global; import org.openfast.template.ComposedScalar; import org.openfast.template.Field; import org.openfast.template.Operator; import org.openfast.template.Scalar; import org.openfast.template.type.Type; -import org.openfast.util.Util; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -112,18 +112,21 @@ if (operatorElement.hasAttribute("dictionary")) exponentDictionary = operatorElement.getAttribute("dictionary"); } -// ComposedScalar scalar = Util.composedDecimal(name, null, null, optional); -// Scalar exponent = scalar.getFields()[0]; -// exponent.setDictionary(exponentDictionary); -// if (exponentKey != null) -// exponent.setKey(exponentKey); -// Scalar mantissa = scalar.getFields()[1]; -// mantissa.setDictionary(mantissaDictionary); -// if (mantissaKey != null) -// mantissa.setKey(mantissaKey); -// if (fieldNode.hasAttribute("id")) -// scalar.setId(fieldNode.getAttribute("id")); -// return scalar; - return null; + Operator exponentOp = context.getOperatorRegistry().get(exponentOperator); + Operator mantissaOp = context.getOperatorRegistry().get(mantissaOperator); + Scalar exponentScalar = new Scalar(Global.createImplicitName(name), Type.I32, exponentOp, optional); + Scalar mantissaScalar = new Scalar(Global.createImplicitName(name), Type.I64, mantissaOp, false); + ComposedScalar scalar = new ComposedScalar(name, Type.DECIMAL, new Scalar[] { exponentScalar, mantissaScalar }, optional); + Scalar exponent = scalar.getFields()[0]; + exponent.setDictionary(exponentDictionary); + if (exponentKey != null) + exponent.setKey(exponentKey); + Scalar mantissa = scalar.getFields()[1]; + mantissa.setDictionary(mantissaDictionary); + if (mantissaKey != null) + mantissa.setKey(mantissaKey); + if (fieldNode.hasAttribute("id")) + scalar.setId(fieldNode.getAttribute("id")); + return scalar; } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/GroupParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/GroupParser.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/GroupParser.java 2008-07-07 17:34:45 UTC (rev 161) @@ -47,7 +47,7 @@ protected Field parse(Element groupElement, boolean optional, ParsingContext context) { Group group = new Group(context.getName(), parseFields(groupElement, context), optional); parseMore(groupElement, group, context); - return null/*group*/; + return group; } protected static void parseMore(Element groupElement, Group group, ParsingContext context) { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ParsingContext.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ParsingContext.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ParsingContext.java 2008-07-07 17:34:45 UTC (rev 161) @@ -21,10 +21,12 @@ package org.openfast.template.loader; import java.util.List; -import java.util.Map; import org.lasalletech.exom.QName; import org.openfast.error.ErrorHandler; +import org.openfast.fast.impl.FastImplementation; +import org.openfast.template.OperatorRegistry; import org.openfast.template.TemplateRegistry; +import org.openfast.template.TypeRegistry; import org.w3c.dom.Element; class ParsingContext { @@ -40,14 +42,19 @@ private String dictionary = null; private ErrorHandler errorHandler; private TemplateRegistry templateRegistry; - private Map typeMap; - private List fieldParsers; + private List<FieldParser> fieldParsers; private QName name; + private FastImplementation implementation; public ParsingContext() { this(NULL); } + public ParsingContext(FastImplementation implementation) { + this(NULL); + this.implementation = implementation; + } + public ParsingContext(ParsingContext parent) { this.parent = parent; } @@ -118,28 +125,20 @@ this.templateRegistry = templateRegistry; } - public void setTypeMap(Map typeMap) { - this.typeMap = typeMap; - } - - public Map getTypeMap() { - if (typeMap == null) - return parent.getTypeMap(); - return typeMap; - } - - public List getFieldParsers() { + public List<FieldParser> getFieldParsers() { + if (implementation != null) + return implementation.getFieldParsers(); if (fieldParsers == null) return parent.getFieldParsers(); return fieldParsers; } - public void setFieldParsers(List list) { + public void setFieldParsers(List<FieldParser> list) { this.fieldParsers = list; } public FieldParser getFieldParser(Element element) { - List parsers = getFieldParsers(); + List<FieldParser> parsers = getFieldParsers(); for (int i = parsers.size() - 1; i >= 0; i--) { FieldParser fieldParser = ((FieldParser) parsers.get(i)); if (fieldParser.canParse(element, this)) @@ -159,4 +158,16 @@ public void addFieldParser(FieldParser parser) { getFieldParsers().add(parser); } + + public OperatorRegistry getOperatorRegistry() { + if (implementation != null) + return implementation.getOperatorRegistry(); + return parent.getOperatorRegistry(); + } + + public TypeRegistry getTypeRegistry() { + if (implementation != null) + return implementation.getTypeRegistry(); + return parent.getTypeRegistry(); + } } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ScalarParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ScalarParser.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ScalarParser.java 2008-07-07 17:34:45 UTC (rev 161) @@ -25,7 +25,6 @@ import org.openfast.template.Operator; import org.openfast.template.Scalar; import org.openfast.template.type.Type; -import org.openfast.util.Util; import org.w3c.dom.Element; public class ScalarParser extends AbstractFieldParser { @@ -42,11 +41,11 @@ } public boolean canParse(Element element, ParsingContext context) { - return context.getTypeMap().containsKey(getTypeName(element)); + return context.getTypeRegistry().isDefined(getTypeName(element)); } public Field parse(Element fieldNode, boolean optional, ParsingContext context) { - Operator operator = null;//Operator.NONE; + Operator operator = context.getOperatorRegistry().getDefault();//Operator.NONE; String defaultValue = null; String key = null; String ns = ""; @@ -54,7 +53,7 @@ if (operatorElement != null) { if (operatorElement.hasAttribute("value")) defaultValue = operatorElement.getAttribute("value"); -// operator = Operator.getOperator(operatorElement.getNodeName()); + operator = context.getOperatorRegistry().get(operatorElement.getNodeName()); if (operatorElement.hasAttribute("key")) key = operatorElement.getAttribute("key"); if (operatorElement.hasAttribute("ns")) @@ -62,7 +61,7 @@ if (operatorElement.hasAttribute("dictionary")) context.setDictionary(operatorElement.getAttribute("dictionary")); } - Type type = getType(fieldNode, context); + Type type = (Type) context.getTypeRegistry().get(getTypeName(fieldNode)); Scalar scalar = new Scalar(getName(fieldNode, context), type, operator, optional); if (fieldNode.hasAttribute("id")) scalar.setId(fieldNode.getAttribute("id")); @@ -77,17 +76,6 @@ return context.getName(); } - protected Type getType(Element fieldNode, ParsingContext context) { - String typeName = getTypeName(fieldNode); - if (!context.getTypeMap().containsKey(typeName)) { - context.getErrorHandler().error( - XMLMessageTemplateLoader.INVALID_TYPE, - "The type " + typeName + " is not defined. Possible types: " - + Util.collectionToString(context.getTypeMap().keySet(), ", ")); - } - return (Type) context.getTypeMap().get(typeName); - } - protected String getTypeName(Element fieldNode) { return fieldNode.getNodeName(); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TemplateParser.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TemplateParser.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TemplateParser.java 2008-07-07 17:34:45 UTC (rev 161) @@ -53,8 +53,7 @@ } } else context.getTemplateRegistry().define(messageTemplate); - return null; -// return messageTemplate; + return messageTemplate; } private QName getTemplateName(Element templateElement, ParsingContext context) { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/XMLMessageTemplateLoader.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/XMLMessageTemplateLoader.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/XMLMessageTemplateLoader.java 2008-07-07 17:34:45 UTC (rev 161) @@ -22,20 +22,16 @@ import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; -import java.util.Map; - import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; - import org.openfast.error.ErrorCode; import org.openfast.error.ErrorHandler; import org.openfast.error.FastAlertSeverity; import org.openfast.error.FastConstants; +import org.openfast.fast.impl.FastImplementation; import org.openfast.template.BasicTemplateRegistry; import org.openfast.template.MessageTemplate; import org.openfast.template.TemplateRegistry; -import org.openfast.template.type.Type; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -60,6 +56,8 @@ private final ParsingContext initialContext; private boolean loadTemplateIdFromAuxId; + + private final FastImplementation implementation; public XMLMessageTemplateLoader() { this(false); @@ -67,22 +65,22 @@ public XMLMessageTemplateLoader(boolean namespaceAwareness) { this.namespaceAwareness = namespaceAwareness; - this.initialContext = createInitialContext(); + this.implementation = FastImplementation.getDefaultVersion(); + this.initialContext = createInitialContext(implementation); } - public static ParsingContext createInitialContext() { - ParsingContext initialContext = new ParsingContext(); + public static ParsingContext createInitialContext(FastImplementation implementation) { + ParsingContext initialContext = new ParsingContext(implementation); 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()); +// 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; } @@ -108,7 +106,7 @@ TemplateParser templateParser = new TemplateParser(loadTemplateIdFromAuxId); if (root.getNodeName().equals("template")) { - return new MessageTemplate[] { /*(MessageTemplate) templateParser.parse(root, initialContext)*/ }; + return new MessageTemplate[] { (MessageTemplate) templateParser.parse(root, initialContext) }; } else if (root.getNodeName().equals("templates")) { ParsingContext context = new ParsingContext(root, initialContext); @@ -116,7 +114,7 @@ MessageTemplate[] templates = new MessageTemplate[templateTags.getLength()]; for (int i = 0; i < templateTags.getLength(); i++) { Element templateTag = (Element) templateTags.item(i); - templates[i] = null/*(MessageTemplate) templateParser.parse(templateTag, context)*/; + templates[i] = (MessageTemplate) templateParser.parse(templateTag, context); } return templates; } else { @@ -187,10 +185,6 @@ return initialContext.getTemplateRegistry(); } - public void setTypeMap(Map typeMap) { - initialContext.setTypeMap(typeMap); - } - public void setLoadTemplateIdFromAuxId(boolean loadTempalteIdFromAuxId) { this.loadTemplateIdFromAuxId = loadTempalteIdFromAuxId; } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/type/Type.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/type/Type.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/type/Type.java 2008-07-07 17:34:45 UTC (rev 161) @@ -21,43 +21,39 @@ package org.openfast.template.type; import java.io.Serializable; -import java.util.LinkedHashMap; -import java.util.Map; -import org.openfast.util.Util; +import org.lasalletech.exom.QName; public abstract class Type implements org.openfast.template.Type, Serializable { private static final long serialVersionUID = 1L; - private final static Map TYPE_NAME_MAP = new LinkedHashMap(); - private final String name; + private final QName name; public Type(String typeName) { - this.name = typeName; - TYPE_NAME_MAP.put(typeName, this); + this.name = new QName(typeName); } - /** - * 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); + + public boolean isRepeating() { + return false; } + + public boolean isPrimitive() { + return true; + } + /** * * @return Returns name as a string */ public String getName() { - return name; + return name.getName(); } /** * @return Returns the name as a string */ public String toString() { + return name.getName(); + } + + public QName getQName() { return name; } public final static Type U8 = new UnsignedIntegerType(8, 256); @@ -77,9 +73,6 @@ 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; Modified: branches/openfast-2.x/core/src/test/java/org/openfast/template/TypeTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/template/TypeTest.java 2008-06-26 15:32:01 UTC (rev 160) +++ branches/openfast-2.x/core/src/test/java/org/openfast/template/TypeTest.java 2008-07-07 17:34:45 UTC (rev 161) @@ -17,25 +17,13 @@ Contributor(s): Jacob Northey <ja...@la...> Craig Otis <co...@la...> -*/ + */ package org.openfast.template; -import org.openfast.template.type.Type; i... [truncated message content] |
From: <ope...@li...> - 2008-06-26 15:31:55
|
Revision: 160 http://openfast.svn.sourceforge.net/openfast/?rev=160&view=rev Author: jacob_northey Date: 2008-06-26 08:32:01 -0700 (Thu, 26 Jun 2008) Log Message: ----------- Removed many tests and classes from OpenFAST 1.0. Only the core object model remains. Modified Paths: -------------- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java branches/openfast-2.x/core/src/main/java/org/openfast/Global.java branches/openfast-2.x/core/src/main/java/org/openfast/Message.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/IntegerEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/NullEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/error/FastConstants.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastTypes.java branches/openfast-2.x/core/src/main/java/org/openfast/template/AbstractTemplateRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/template/BasicTemplateRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java branches/openfast-2.x/core/src/main/java/org/openfast/template/DynamicTemplateReference.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Field.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Group.java branches/openfast-2.x/core/src/main/java/org/openfast/template/MessageTemplate.java branches/openfast-2.x/core/src/main/java/org/openfast/template/NullTemplateRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java branches/openfast-2.x/core/src/main/java/org/openfast/template/StaticTemplateReference.java branches/openfast-2.x/core/src/main/java/org/openfast/template/TemplateRegistry.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/AbstractFieldParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ComposedDecimalParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/GroupParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ParsingContext.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/ScalarParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/SequenceParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TemplateParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/TemplateRefParser.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/XMLMessageTemplateLoader.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/ByteVectorType.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/DateType.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/DecimalType.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/IntegerType.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/SignedIntegerType.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/StringType.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/Type.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/UnsignedIntegerType.java branches/openfast-2.x/core/src/main/java/org/openfast/util/Util.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/TypeTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/Array.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/XMLMessageTemplateLoaderTest.java branches/openfast-2.x/core/src/test/java/org/openfast/test/OpenFastTestCase.java branches/openfast-2.x/core/src/test/java/org/openfast/util/UtilTest.java Added Paths: ----------- branches/openfast-2.x/core/src/main/java/org/openfast/template/GroupReference.java Removed Paths: ------------- branches/openfast-2.x/core/src/main/java/org/openfast/BitVectorValue.java branches/openfast-2.x/core/src/main/java/org/openfast/ByteVectorValue.java branches/openfast-2.x/core/src/main/java/org/openfast/DateValue.java branches/openfast-2.x/core/src/main/java/org/openfast/DecimalValue.java branches/openfast-2.x/core/src/main/java/org/openfast/FieldValue.java branches/openfast-2.x/core/src/main/java/org/openfast/GroupValue.java branches/openfast-2.x/core/src/main/java/org/openfast/IntegerValue.java branches/openfast-2.x/core/src/main/java/org/openfast/MessageInputStream.java branches/openfast-2.x/core/src/main/java/org/openfast/MessageOutputStream.java branches/openfast-2.x/core/src/main/java/org/openfast/NumericValue.java branches/openfast-2.x/core/src/main/java/org/openfast/QName.java branches/openfast-2.x/core/src/main/java/org/openfast/ScalarValue.java branches/openfast-2.x/core/src/main/java/org/openfast/SequenceValue.java branches/openfast-2.x/core/src/main/java/org/openfast/StringValue.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastEncoder.java branches/openfast-2.x/core/src/main/java/org/openfast/debug/ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/ApplicationTypeDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Dictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/TemplateDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/session/ branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedValueConverter.java branches/openfast-2.x/core/src/main/java/org/openfast/template/FieldSet.java branches/openfast-2.x/core/src/main/java/org/openfast/template/LongValue.java branches/openfast-2.x/core/src/main/java/org/openfast/template/TwinValue.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/ branches/openfast-2.x/core/src/main/java/org/openfast/template/type/DecimalConverter.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/SimpleType.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/codec/ branches/openfast-2.x/core/src/test/java/org/openfast/ApplicationTypeDictionaryTest.java branches/openfast-2.x/core/src/test/java/org/openfast/BitVectorValueTest.java branches/openfast-2.x/core/src/test/java/org/openfast/ByteVectorValueTest.java branches/openfast-2.x/core/src/test/java/org/openfast/DecimalValueTest.java branches/openfast-2.x/core/src/test/java/org/openfast/DictionaryTest.java branches/openfast-2.x/core/src/test/java/org/openfast/EncodeDecodeTest.java branches/openfast-2.x/core/src/test/java/org/openfast/ExhaustiveOperatorTest.java branches/openfast-2.x/core/src/test/java/org/openfast/GroupValueTest.java branches/openfast-2.x/core/src/test/java/org/openfast/IntegerValueTest.java branches/openfast-2.x/core/src/test/java/org/openfast/MessageInputStreamTest.java branches/openfast-2.x/core/src/test/java/org/openfast/MessageOutputStreamTest.java branches/openfast-2.x/core/src/test/java/org/openfast/MessageTest.java branches/openfast-2.x/core/src/test/java/org/openfast/StringValueTest.java branches/openfast-2.x/core/src/test/java/org/openfast/TemplateDictionaryTest.java branches/openfast-2.x/core/src/test/java/org/openfast/TemplateTest.java branches/openfast-2.x/core/src/test/java/org/openfast/TypeConversionTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/FastDecoderTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/FastEncoderTest.java branches/openfast-2.x/core/src/test/java/org/openfast/scenario/ branches/openfast-2.x/core/src/test/java/org/openfast/session/ branches/openfast-2.x/core/src/test/java/org/openfast/submitted/ branches/openfast-2.x/core/src/test/java/org/openfast/template/DynamicTemplateReferenceTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/GroupTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/MessageTemplateTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/ScalarTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/SequenceTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/ComposedDecimalParserTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/ScalarParserTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/SequenceParserTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/StringParserTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/TemplateRefParserTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/operator/ branches/openfast-2.x/core/src/test/java/org/openfast/template/type/IntegerTypeTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/type/StringTypeTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/type/codec/ branches/openfast-2.x/core/src/test/java/org/openfast/test/ObjectMother.java Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/BitVectorValue.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/BitVectorValue.java 2008-06-26 13:40:19 UTC (rev 159) +++ branches/openfast-2.x/core/src/main/java/org/openfast/BitVectorValue.java 2008-06-26 15:32:01 UTC (rev 160) @@ -1,48 +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 org.openfast.util.BitVector; - -public class BitVectorValue extends ScalarValue { - private static final long serialVersionUID = 1L; - public BitVector value; - - public BitVectorValue(BitVector value) { - this.value = value; - } - - public boolean equals(Object obj) { - if ((obj == null) || !(obj instanceof BitVectorValue)) { - return false; - } - - return equals((BitVectorValue) obj); - } - - public boolean equals(BitVectorValue other) { - return other.value.equals(this.value); - } - - public int hashCode() { - return value.hashCode(); - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/ByteVectorValue.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/ByteVectorValue.java 2008-06-26 13:40:19 UTC (rev 159) +++ branches/openfast-2.x/core/src/main/java/org/openfast/ByteVectorValue.java 2008-06-26 15:32:01 UTC (rev 160) @@ -1,67 +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; - -public class ByteVectorValue extends ScalarValue { - private static final long serialVersionUID = 1L; - public final byte[] value; - - public ByteVectorValue(byte[] value) { - this.value = value; - } - - public byte[] getBytes() { - 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(); - } - - public boolean equals(Object obj) { - if ((obj == null) || !(obj instanceof ByteVectorValue)) { - return false; - } - return equals((ByteVectorValue) obj); - } - - public boolean equals(ByteVectorValue other) { - 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(); - } -} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Context.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-06-26 13:40:19 UTC (rev 159) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-06-26 15:32:01 UTC (rev 160) @@ -25,14 +25,9 @@ import java.util.Iterator; import java.util.List; import java.util.Map; - -import org.openfast.debug.BasicDecodeTrace; -import org.openfast.debug.BasicEncodeTrace; -import org.openfast.debug.Trace; -import org.openfast.dictionary.ApplicationTypeDictionary; -import org.openfast.dictionary.Dictionary; -import org.openfast.dictionary.GlobalDictionary; -import org.openfast.dictionary.TemplateDictionary; +import org.lasalletech.exom.QName; +import org.openfast.dictionary.FastDictionary; +import org.openfast.dictionary.GlobalFastDictionary; import org.openfast.error.ErrorHandler; import org.openfast.error.FastConstants; import org.openfast.template.BasicTemplateRegistry; @@ -54,13 +49,9 @@ 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()); + dictionaries.put("global", new GlobalFastDictionary()); } public int getTemplateId(MessageTemplate template) { if (!templateRegistry.isRegistered(template)) { @@ -90,24 +81,24 @@ public void setLastTemplateId(int templateId) { lastTemplateId = templateId; } - public ScalarValue lookup(String dictionary, Group group, QName key) { + public int lookupInt(String dictionary, Group group, QName key) { if (group.hasTypeReference()) currentApplicationType = group.getTypeReference(); - return getDictionary(dictionary).lookup(group, key, currentApplicationType); + return getDictionary(dictionary).lookupInt(null, key, currentApplicationType); } - private Dictionary getDictionary(String dictionary) { + private FastDictionary getDictionary(String dictionary) { if (!dictionaries.containsKey(dictionary)) - dictionaries.put(dictionary, new GlobalDictionary()); - return (Dictionary) dictionaries.get(dictionary); + dictionaries.put(dictionary, new GlobalFastDictionary()); + return (FastDictionary) dictionaries.get(dictionary); } - public void store(String dictionary, Group group, QName key, ScalarValue valueToEncode) { + public void store(String dictionary, Group group, QName key, int value) { if (group.hasTypeReference()) currentApplicationType = group.getTypeReference(); - getDictionary(dictionary).store(group, currentApplicationType, key, valueToEncode); + getDictionary(dictionary).store(null, currentApplicationType, key, value); } public void reset() { for (Iterator iter = dictionaries.values().iterator(); iter.hasNext();) { - Dictionary dict = (Dictionary) iter.next(); + FastDictionary dict = (FastDictionary) iter.next(); dict.reset(); } } @@ -129,23 +120,4 @@ 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; - } } Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/DateValue.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/DateValue.java 2008-06-26 13:40:19 UTC (rev 159) +++ branches/openfast-2.x/core/src/main/java/org/openfast/DateValue.java 2008-06-26 15:32:01 UTC (rev 160) @@ -1,56 +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.util.Date; - -public class DateValue extends ScalarValue { - private static final long serialVersionUID = 1L; - public final Date value; - - 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 int hashCode() { - return value.hashCode(); - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/DecimalValue.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/DecimalValue.java 2008-06-26 13:40:19 UTC (rev 159) +++ branches/openfast-2.x/core/src/main/java/org/openfast/DecimalValue.java 2008-06-26 15:32:01 UTC (rev 160) @@ -1,155 +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 java.math.BigInteger; - -import org.openfast.error.FastConstants; - -public class DecimalValue extends NumericValue { - private static final long serialVersionUID = 1L; - - public final int exponent; - public final long mantissa; - - public DecimalValue(double value) { - if (value == 0.0) { - this.exponent = 0; - this.mantissa = 0; - - return; - } - - 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; - } - - public DecimalValue(BigDecimal bigDecimal) { - this.mantissa = bigDecimal.unscaledValue().longValue(); - this.exponent = bigDecimal.scale(); - } - - 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.mantissa == this.mantissa && other.exponent == this.exponent; - } - - public NumericValue subtract(NumericValue subtrahend) { - return new DecimalValue(toBigDecimal().subtract(((DecimalValue)subtrahend).toBigDecimal())); - } - - public NumericValue add(NumericValue addend) { - return new DecimalValue(toBigDecimal().add(((DecimalValue)addend).toBigDecimal())); - } - - public String serialize() { - return toString(); - } - - public boolean equals(int value) { - return false; - } - - public long toLong() { - if (exponent < 0) - Global.handleError(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, ""); - return (long) (getValue()); - } - - public int toInt() { - long value = getValue(); - if (exponent < 0 || (value) > Integer.MAX_VALUE) - Global.handleError(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, ""); - return (int) (value); - } - - public short toShort() { - long value = getValue(); - if (exponent < 0 || (value) > Short.MAX_VALUE) - Global.handleError(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, ""); - return (short) (value); - } - - public byte toByte() { - long value = getValue(); - if (exponent < 0 || (value) > Byte.MAX_VALUE) - Global.handleError(FastConstants.R5_DECIMAL_CANT_CONVERT_TO_INT, ""); - return (byte) (value); - } - - private long getValue() { - 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.0, exponent); - } - - public BigDecimal toBigDecimal() { - return new BigDecimal(BigInteger.valueOf(mantissa), -exponent); - } - - public String toString() { - return toBigDecimal().toPlainString(); - } - - public int hashCode() { - return exponent * 37 + (int) mantissa; - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/FieldValue.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/FieldValue.java 2008-06-26 13:40:19 UTC (rev 159) +++ branches/openfast-2.x/core/src/main/java/org/openfast/FieldValue.java 2008-06-26 15:32:01 UTC (rev 160) @@ -1,27 +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.io.Serializable; - -public interface FieldValue extends Serializable { - FieldValue copy(); -} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Global.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Global.java 2008-06-26 13:40:19 UTC (rev 159) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Global.java 2008-06-26 15:32:01 UTC (rev 160) @@ -20,6 +20,7 @@ */ package org.openfast; +import org.lasalletech.exom.QName; import org.openfast.error.ErrorCode; import org.openfast.error.ErrorHandler; Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/GroupValue.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/GroupValue.java 2008-06-26 13:40:19 UTC (rev 159) +++ branches/openfast-2.x/core/src/main/java/org/openfast/GroupValue.java 2008-06-26 15:32:01 UTC (rev 160) @@ -1,340 +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 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 org.openfast.util.BitVector; - -public class GroupValue implements FieldValue { - private static final long serialVersionUID = 1L; - - protected final FieldValue[] values; - - private final Group group; - - public GroupValue(Group group, FieldValue[] values) { - if (group == null) { - throw new NullPointerException(); - } - - 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) { - this(group, new FieldValue[group.getFieldCount()]); - } - - public Iterator iterator() { - return new ArrayIterator(values); - } - - 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(); - } - - 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(); - } - - public byte getByte(int fieldIndex) { - return getScalar(fieldIndex).toByte(); - } - - public byte getByte(String fieldName) { - return getScalar(fieldName).toByte(); - } - - public short getShort(int fieldIndex) { - return getScalar(fieldIndex).toShort(); - } - - public short getShort(String fieldName) { - return getScalar(fieldName).toShort(); - } - - public String getString(int index) { - return getValue(index).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(); - } - - public double getDouble(String fieldName) { - return getScalar(fieldName).toDouble(); - } - - public BigDecimal getBigDecimal(int fieldIndex) { - return getScalar(fieldIndex).toBigDecimal(); - } - - public BigDecimal getBigDecimal(String fieldName) { - return getScalar(fieldName).toBigDecimal(); - } - - public byte[] getBytes(int fieldIndex) { - return getScalar(fieldIndex).getBytes(); - } - - public byte[] getBytes(String fieldName) { - return getScalar(fieldName).getBytes(); - } - - public SequenceValue getSequence(int fieldIndex) { - return (SequenceValue) getValue(fieldIndex); - } - - public SequenceValue getSequence(String fieldName) { - return (SequenceValue) getValue(fieldName); - } - - public ScalarValue getScalar(int fieldIndex) { - return (ScalarValue) getValue(fieldIndex); - } - - public ScalarValue getScalar(String fieldName) { - return (ScalarValue) getValue(fieldName); - } - - public GroupValue getGroup(int fieldIndex) { - return (GroupValue) getValue(fieldIndex); - } - - public GroupValue getGroup(String fieldName) { - return (GroupValue) getValue(fieldName); - } - - public FieldValue getValue(int fieldIndex) { - return values[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 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; - } - - public void setBitVector(int fieldIndex, BitVector vector) { - values[fieldIndex] = new BitVectorValue(vector); - } - - public void setByteVector(int fieldIndex, byte[] bytes) { - values[fieldIndex] = 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(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); - } - - 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(int fieldIndex, long value) { - values[fieldIndex] = new LongValue(value); - } - - public void setString(int fieldIndex, String value) { - values[fieldIndex] = new StringValue(value); - } - - public void setString(String fieldName, String value) { - setFieldValue(fieldName, group.getField(fieldName).createValue(value)); - } - - public boolean equals(Object other) { - if (other == this) { - return true; - } - - if ((other == null) || !(other instanceof GroupValue)) { - return false; - } - - return equals((GroupValue) other); - } - - private boolean equals(GroupValue other) { - if (values.length != other.values.length) { - return false; - } - - 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])) { - return false; - } - } - - return true; - } - - public int hashCode() { - return values.hashCode(); - } - - public String toString() { - StringBuilder builder = new StringBuilder(); - - builder.append(group).append(" -> {"); - for (int i = 0; i < values.length; i++) { - builder.append(values[i]).append(", "); - } - - if (values.length > 0) { - builder.delete(builder.length() - 2, builder.length()); - } - - builder.append("}"); - return builder.toString(); - } - - public void setFieldValue(String fieldName, FieldValue value) { - if (!group.hasField(fieldName)) - throw new IllegalArgumentException("The field " + fieldName + " does not exist in group " + group); - int index = group.getFieldIndex(fieldName); - setFieldValue(index, value); - } - - public int getFieldCount() { - return values.length; - } - - public void setFieldValue(String fieldName, String value) { - setFieldValue(fieldName, group.getField(fieldName).createValue(value)); - } - - public boolean isDefined(int fieldIndex) { - return fieldIndex < values.length && values[fieldIndex] != null; - } - - 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); - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/IntegerValue.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/IntegerValue.java 2008-06-26 13:40:19 UTC (rev 159) +++ branches/openfast-2.x/core/src/main/java/org/openfast/IntegerValue.java 2008-06-26 15:32:01 UTC (rev 160) @@ -1,115 +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; -import org.openfast.template.LongValue; - -public class IntegerValue extends NumericValue { - private static final long serialVersionUID = 1L; - public final int value; - - public IntegerValue(int value) { - this.value = value; - } - - public boolean equals(Object obj) { - 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; - } - - public boolean equalsValue(String defaultValue) { - return Integer.parseInt(defaultValue) == value; - } - - public NumericValue increment() { - return new IntegerValue(value + 1); - } - - public NumericValue decrement() { - return new IntegerValue(value - 1); - } - - public NumericValue subtract(NumericValue subend) { - if (subend instanceof LongValue) { - return new LongValue(this.value - subend.toLong()); - } - return new IntegerValue(this.value - subend.toInt()); - } - - public NumericValue add(NumericValue addend) { - if (addend instanceof LongValue) { - return addend.add(this); - } - return new IntegerValue(this.value + addend.toInt()); - } - - public String serialize() { - return String.valueOf(value); - } - - public boolean equals(int value) { - return value == this.value; - } - - public long toLong() { - return value; - } - - public int toInt() { - return value; - } - - 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; - } - - 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; - } - - public double toDouble() { - return value; - } - - public BigDecimal toBigDecimal() { - return new BigDecimal(value); - } -} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Message.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Message.java 2008-06-26 13:40:19 UTC (rev 159) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Message.java 2008-06-26 15:32:01 UTC (rev 160) @@ -20,58 +20,18 @@ */ package org.openfast; +import org.lasalletech.exom.simple.SimpleEObject; import org.openfast.template.MessageTemplate; -public class Message extends GroupValue { +public class Message extends SimpleEObject { private static final long serialVersionUID = 1L; private final MessageTemplate template; - public Message(MessageTemplate template, FieldValue[] fieldValues) { - super(template, fieldValues); + public Message(MessageTemplate template) { + super(template); this.template = template; } - public Message(MessageTemplate template) { - this(template, initializeFieldValues(template.getFieldCount())); - } - 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; - for (int i = 1; i < message.getFieldCount(); i++) - if (message.getValue(i) == null) { - if (this.getValue(i) == null) { - continue; - } else { - return false; - } - } else if (!message.getValue(i).equals(this.getValue(i))) { - return false; - } - return true; - } - public int 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); - } } Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/MessageInputStream.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/MessageInputStream.java 2008-06-26 13:40:19 UTC (rev 159) +++ branches/openfast-2.x/core/src/main/java/org/openfast/MessageInputStream.java 2008-06-26 15:32:01 UTC (rev 160) @@ -1,132 +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.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collections; -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; - - public MessageInputStream(InputStream inputStream) { - this(inputStream, new Context()); - } - - public MessageInputStream(InputStream inputStream, Context context) { - this.in = inputStream; - this.context = context; - this.decoder = new FastDecoder(context, in); - } - - /** - * @throws java.io.EOFException - * @return the next message in the stream - */ - public Message readMessage() { - if (context.isTraceEnabled()) - context.startTrace(); - boolean keepReading = blockReader.readBlock(in); - 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); - } - } - if (templateHandlers.containsKey(message.getTemplate())) { - MessageHandler handler = (MessageHandler) templateHandlers.get(message.getTemplate()); - handler.handleMessage(message, context, decoder); - return readMessage(); - } - return message; - } - - public void registerTemplate(int templateId, MessageTemplate template) { - context.registerTemplate(templateId, template); - } - - public void close() { - try { - in.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public InputStream getUnderlyingStream() { - return in; - } - - 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 void addTemplateRegisteredListener(TemplateRegisteredListener templateRegisteredListener) {} - - public void reset() { - decoder.reset(); - } - - public Context getContext() { - return context; - } - - public void setBlockReader(MessageBlockReader messageBlockReader) { - this.blockReader = messageBlockReader; - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/MessageOutputStream.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/MessageOutputStream.java 2008-06-26 13:40:19 UTC (rev 159) +++ branches/openfast-2.x/core/src/main/java/org/openfast/MessageOutputStream.java 2008-06-26 15:32:01 UTC (rev 160) @@ -1,114 +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.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.openfast.codec.FastEncoder; -import org.openfast.error.FastConstants; -import org.openfast.template.MessageTemplate; -import org.openfast.template.TemplateRegistry; - -public class MessageOutputStream implements MessageStream { - private final OutputStream out; - private final FastEncoder encoder; - private final Context context; - private List handlers = Collections.EMPTY_LIST; - private Map templateHandlers = Collections.EMPTY_MAP; - - 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); - } - 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); - } - } - if (templateHandlers.containsKey(message.getTemplate())) { - ((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(); - } catch (IOException 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(); - } catch (IOException e) { - 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; - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/NumericValue.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/NumericValue.java 2008-06-26 13:40:19 UTC (rev 159) +++ branches/openfast-2.x/core/src/main/java/org/openfast/NumericValue.java 2008-06-26 15:32:01 UTC (rev 160) @@ -1,31 +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; - -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(); -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/QName.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/QName.java 2008-06-26 13:40:19 UTC (rev 159) +++ branches/openfast-2.x/core/src/main/java/org/openfast/QName.java 2008-06-26 15:32:01 UTC (rev 160) @@ -1,71 +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.io.Serializable; - -public class QName implements Serializable { - private static final long serialVersionUID = 1L; - - public static final QName NULL = new QName("", ""); - - 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 + "]"; - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/ScalarValue.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/ScalarValue.java 2008-06-26 13:40:19 UTC (rev 159) +++ branches/openfast-2.x/core/src/main/java/org/openfast/ScalarValue.java 2008-06-26 15:32:01 UTC (rev 160) @@ -1,109 +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; - -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 boolean isUndefined() { - return true; - } - - public String toString() { - return "UNDEFINED"; - } - }; - static public final ScalarValue NULL = new ScalarValue() { - private static final long serialVersionUID = 1L; - - public boolean isNull() { - return true; - } - - 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 Returns false - */ - public boolean isUndefined() { - return false; - } - - /** - * - * @return Returns false - */ - public boolean isNull() { - return false; - } - - public byte toByte() { - throw new UnsupportedOperationException(); - } - - public short toShort() { - throw new UnsupportedOperationException(); - } - - public int toInt() { - throw new UnsupportedOperationException(); - } - - public long toLong() { - throw new UnsupportedOperationException(); - } - - public String toString() { - throw new UnsupportedOperationException(); ... [truncated message content] |
From: <ope...@li...> - 2008-06-26 13:40:24
|
Revision: 159 http://openfast.svn.sourceforge.net/openfast/?rev=159&view=rev Author: jacob_northey Date: 2008-06-26 06:40:19 -0700 (Thu, 26 Jun 2008) Log Message: ----------- Restructured packages Modified Paths: -------------- branches/openfast-2.x/core/src/main/java/org/openfast/BitVectorValue.java branches/openfast-2.x/core/src/main/java/org/openfast/Context.java branches/openfast-2.x/core/src/main/java/org/openfast/GroupValue.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/session/template/exchange/AbstractFieldInstructionConverter.java branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java branches/openfast-2.x/core/src/main/java/org/openfast/template/DynamicTemplateReference.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Field.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Group.java branches/openfast-2.x/core/src/main/java/org/openfast/template/MessageTemplate.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java branches/openfast-2.x/core/src/main/java/org/openfast/template/StaticTemplateReference.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/AlwaysPresentOperatorCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/ConstantOperatorCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/template/operator/OperatorCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/codec/BitVectorType.java branches/openfast-2.x/core/src/test/java/org/openfast/BitVectorReaderTest.java branches/openfast-2.x/core/src/test/java/org/openfast/BitVectorTest.java branches/openfast-2.x/core/src/test/java/org/openfast/BitVectorValueTest.java branches/openfast-2.x/core/src/test/java/org/openfast/DictionaryTest.java branches/openfast-2.x/core/src/test/java/org/openfast/TemplateDictionaryTest.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/GroupTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/ScalarTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/SequenceTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/Array.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/ScalarParserTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/loader/StringParserTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/operator/OperatorTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/type/codec/ComposedDecimalTest.java branches/openfast-2.x/core/src/test/java/org/openfast/template/type/codec/StringDeltaTest.java Added Paths: ----------- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/ApplicationTypeDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Dictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Entry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/IntegerEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/NullEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/TemplateDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/util/BitVector.java branches/openfast-2.x/core/src/main/java/org/openfast/util/BitVectorBuilder.java branches/openfast-2.x/core/src/main/java/org/openfast/util/BitVectorReader.java Removed Paths: ------------- branches/openfast-2.x/core/src/main/java/org/openfast/ApplicationTypeDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/BitVector.java branches/openfast-2.x/core/src/main/java/org/openfast/BitVectorBuilder.java branches/openfast-2.x/core/src/main/java/org/openfast/BitVectorReader.java branches/openfast-2.x/core/src/main/java/org/openfast/Dictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/Entry.java branches/openfast-2.x/core/src/main/java/org/openfast/FastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/GlobalDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/GlobalFastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/IntegerEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/NullEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/TemplateDictionary.java Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/ApplicationTypeDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/ApplicationTypeDictionary.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/ApplicationTypeDictionary.java 2008-06-26 13:40:19 UTC (rev 159) @@ -1,70 +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.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(); - - 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 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(); - } - -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/BitVector.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/BitVector.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/BitVector.java 2008-06-26 13:40:19 UTC (rev 159) @@ -1,107 +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; - -public class BitVector { - private static final int VALUE_BITS_SET = 0x7F; - private static final int STOP_BIT = 0x80; - private byte[] bytes; - private int size; - - public BitVector(int size) { - this(new byte[((size - 1) / 7) + 1]); - } - - public BitVector(byte[] bytes) { - this.bytes = bytes; - this.size = bytes.length * 7; - bytes[bytes.length - 1] |= STOP_BIT; - } - - public byte[] getBytes() { - return bytes; - } - - public byte[] getTruncatedBytes() { - int index = bytes.length - 1; - 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; - } - - public int getSize() { - return this.size; - } - - public void set(int fieldIndex) { - bytes[fieldIndex / 7] |= (1 << (6 - (fieldIndex % 7))); - } - - public boolean isSet(int fieldIndex) { - if (fieldIndex >= bytes.length * 7) - return false; - return ((bytes[fieldIndex / 7] & (1 << (6 - (fieldIndex % 7)))) > 0); - } - - public boolean equals(Object obj) { - if ((obj == null) || !(obj instanceof BitVector)) { - return false; - } - return equals((BitVector) obj); - } - - public boolean equals(BitVector other) { - 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(); - } - - public boolean isOverlong() { - return (bytes.length > 1) && ((bytes[bytes.length - 1] & VALUE_BITS_SET) == 0); - } - - public String toString() { - return "BitVector [" + ByteUtil.convertByteArrayToBitString(bytes) + "]"; - } - - public int indexOfLastSet() { - int index = bytes.length * 7 - 1; - while (index >= 0 && !isSet(index)) - index--; - return index; - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/BitVectorBuilder.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/BitVectorBuilder.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/BitVectorBuilder.java 2008-06-26 13:40:19 UTC (rev 159) @@ -1,49 +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; - -public class BitVectorBuilder { - private final BitVector vector; - private int index = 0; - - 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; - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/BitVectorReader.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/BitVectorReader.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/BitVectorReader.java 2008-06-26 13:40:19 UTC (rev 159) @@ -1,68 +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; - -public class BitVectorReader { - public static final BitVectorReader NULL = new BitVectorReader(null) { - public boolean read() { - throw new IllegalStateException(); - } - - 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 BitVectorReader(BitVector vector) { - this.vector = vector; - } - - public boolean read() { - return vector.isSet(index++); - } - - public BitVector getBitVector() { - return vector; - } - - public boolean hasMoreBitsSet() { - return vector.indexOfLastSet() > index; - } - - public String toString() { - return vector.toString(); - } - - public boolean peek() { - return vector.isSet(index); - } - - public int getIndex() { - return index; - } -} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/BitVectorValue.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/BitVectorValue.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/BitVectorValue.java 2008-06-26 13:40:19 UTC (rev 159) @@ -20,6 +20,8 @@ */ package org.openfast; +import org.openfast.util.BitVector; + public class BitVectorValue extends ScalarValue { private static final long serialVersionUID = 1L; public BitVector value; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/Context.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Context.java 2008-06-26 13:40:19 UTC (rev 159) @@ -29,6 +29,10 @@ import org.openfast.debug.BasicDecodeTrace; import org.openfast.debug.BasicEncodeTrace; import org.openfast.debug.Trace; +import org.openfast.dictionary.ApplicationTypeDictionary; +import org.openfast.dictionary.Dictionary; +import org.openfast.dictionary.GlobalDictionary; +import org.openfast.dictionary.TemplateDictionary; import org.openfast.error.ErrorHandler; import org.openfast.error.FastConstants; import org.openfast.template.BasicTemplateRegistry; Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/Dictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Dictionary.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Dictionary.java 2008-06-26 13:40:19 UTC (rev 159) @@ -1,35 +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 org.openfast.template.Group; - - -public interface Dictionary { - public static final String TEMPLATE = "template"; - public static final String GLOBAL = "global"; - - ScalarValue lookup(Group template, QName key, QName currentApplicationType); - - void store(Group group, QName applicationType, QName key, ScalarValue valueToEncode); - - void reset(); -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/Entry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Entry.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Entry.java 2008-06-26 13:40:19 UTC (rev 159) @@ -1,12 +0,0 @@ -package org.openfast; - -public interface Entry { - void setInt(int value); - int getInt(); - boolean hasNext(); - Entry getNext(); - boolean matches(Object key); - boolean isNull(); - void setNext(Entry entry); - void setNull(); -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/FastDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/FastDictionary.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/FastDictionary.java 2008-06-26 13:40:19 UTC (rev 159) @@ -1,16 +0,0 @@ -package org.openfast; - -import org.lasalletech.exom.EObject; -import org.lasalletech.exom.Entity; - -public interface FastDictionary { - int lookupInt(Entity template, QName key, QName currentApplicationType); - - void store(Entity template, QName key, QName currentApplicationType, int value); - void storeNull(Entity entity, QName key, QName currentApplicationType); - - boolean isDefined(EObject object, QName key, QName currentApplicationType); - boolean isNull(EObject object, QName key, QName currentApplicationType); - - void reset(); -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/GlobalDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/GlobalDictionary.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/GlobalDictionary.java 2008-06-26 13:40:19 UTC (rev 159) @@ -1,59 +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 org.openfast.template.Group; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - - -public class GlobalDictionary implements Dictionary { - protected Map table = new HashMap(); - - public ScalarValue lookup(Group template, QName key, QName applicationType) { - if (!table.containsKey(key)) { - return ScalarValue.UNDEFINED; - } - - return (ScalarValue) table.get(key); - } - - public void store(Group group, QName applicationType, QName key, ScalarValue value) { - table.put(key, value); - } - - 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(); - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/GlobalFastDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/GlobalFastDictionary.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/GlobalFastDictionary.java 2008-06-26 13:40:19 UTC (rev 159) @@ -1,76 +0,0 @@ -package org.openfast; - -import java.util.Arrays; -import org.lasalletech.exom.EObject; -import org.lasalletech.exom.Entity; - -public class GlobalFastDictionary implements FastDictionary { - // Use power of 2 for size so that hashes can be calculated quickly - private Entry[] entries = new Entry[256]; - - public int lookupInt(Entity template, QName key, QName currentApplicationType) { - return getEntry(key).getInt(); - } - - public void reset() { - Arrays.fill(entries, null); - } - - public void store(Entity template, QName key, QName currentApplicationType, int value) { - int index = key.hashCode() % entries.length; - Entry entry = entries[index]; - if (entry == null) { - entries[index] = new IntegerEntry(key, value); - } else { - while (!entry.matches(key)) { - if (!entry.hasNext()) { - entry.setNext(new IntegerEntry(key, value)); - return; - } - entry = entry.getNext(); - } - entry.setInt(value); - } - } - - public void storeNull(Entity entity, QName key, QName currentApplicationType) { - int index = key.hashCode() & (entries.length - 1); - Entry entry = entries[index]; - if (entry == null) { - entries[index] = new NullEntry(key); - } else { - while (!entry.matches(key)) { - if (!entry.hasNext()) { - entry.setNext(new NullEntry(key)); - return; - } - entry = entry.getNext(); - } - entry.setNull(); - } - } - - public boolean isDefined(EObject object, QName key, QName currentApplicationType) { - Entry entry = getEntry(key); - return entry != null; - } - - private Entry getEntry(QName key) { - int index = key.hashCode() % entries.length; - Entry entry = entries[index]; - if (entry == null) - return null; - while (!entry.matches(key)) { - if (!entry.hasNext()) - return null; - entry = entry.getNext(); - } - return entry; - } - - public boolean isNull(EObject object, QName key, QName currentApplicationType) { - Entry entry = getEntry(key); - if (entry == null) return false; - return entry.isNull(); - } -} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/GroupValue.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/GroupValue.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/GroupValue.java 2008-06-26 13:40:19 UTC (rev 159) @@ -30,6 +30,7 @@ import org.openfast.template.operator.Operator; import org.openfast.template.type.Type; import org.openfast.util.ArrayIterator; +import org.openfast.util.BitVector; public class GroupValue implements FieldValue { private static final long serialVersionUID = 1L; Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/IntegerEntry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/IntegerEntry.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/IntegerEntry.java 2008-06-26 13:40:19 UTC (rev 159) @@ -1,47 +0,0 @@ -package org.openfast; - -public class IntegerEntry implements Entry { - private final QName key; - private int value; - private Entry next; - private boolean isNull; - - public IntegerEntry(QName key, int value) { - if (key == null) throw new NullPointerException(); - this.key = key; - this.value = value; - } - - public int getInt() { - return value; - } - - public Entry getNext() { - return next; - } - - public boolean hasNext() { - return next != null; - } - - public boolean isNull() { - return isNull; - } - - public boolean matches(Object key) { - return this.key.equals(key); - } - - public void setInt(int value) { - this.value = value; - isNull = false; - } - - public void setNext(Entry entry) { - next = entry; - } - - public void setNull() { - isNull = true; - } -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/NullEntry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/NullEntry.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/NullEntry.java 2008-06-26 13:40:19 UTC (rev 159) @@ -1,40 +0,0 @@ -package org.openfast; - -public class NullEntry implements Entry { - private final QName key; - private Entry next; - - public NullEntry(QName key) { - this.key = key; - } - - public int getInt() { - throw new UnsupportedOperationException(); - } - - public Entry getNext() { - return next; - } - - public boolean hasNext() { - return next != null; - } - - public boolean isNull() { - return true; - } - - public boolean matches(Object key) { - return this.key.equals(key); - } - - public void setInt(int value) { - throw new UnsupportedOperationException(); - } - - public void setNext(Entry entry) { - next = entry; - } - - public void setNull() {} -} Deleted: branches/openfast-2.x/core/src/main/java/org/openfast/TemplateDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/TemplateDictionary.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/TemplateDictionary.java 2008-06-26 13:40:19 UTC (rev 159) @@ -1,72 +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 org.openfast.template.Group; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - - -public class TemplateDictionary implements Dictionary { - protected Map table = new HashMap(); - - public ScalarValue lookup(Group template, QName key, QName applicationType) { - if (!table.containsKey(template)) { - return ScalarValue.UNDEFINED; - } - - if (((Map) table.get(template)).containsKey(key)) { - return (ScalarValue) ((Map) table.get(template)).get(key); - } - - return ScalarValue.UNDEFINED; - } - - public void reset() { - table.clear(); - } - - public void store(Group group, QName applicationType, QName key, ScalarValue valueToEncode) { - if (!table.containsKey(group)) { - table.put(group, new HashMap()); - } - - ((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: branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/FastDecoder.java 2008-06-26 13:40:19 UTC (rev 159) @@ -20,8 +20,6 @@ */ package org.openfast.codec; -import org.openfast.BitVector; -import org.openfast.BitVectorReader; import org.openfast.BitVectorValue; import org.openfast.Context; import org.openfast.IntegerValue; @@ -29,6 +27,8 @@ import org.openfast.template.MessageTemplate; import org.openfast.template.type.codec.TypeCodec; +import org.openfast.util.BitVector; +import org.openfast.util.BitVectorReader; import java.io.InputStream; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java 2008-06-26 13:40:19 UTC (rev 159) @@ -21,10 +21,10 @@ package org.openfast.codec; import org.lasalletech.exom.EObject; -import org.openfast.FastDictionary; import org.openfast.NumericValue; import org.openfast.QName; import org.openfast.ScalarValue; +import org.openfast.dictionary.FastDictionary; import org.openfast.error.FastConstants; import org.openfast.template.Scalar; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java 2008-06-26 13:40:19 UTC (rev 159) @@ -22,7 +22,7 @@ import java.io.Serializable; import org.lasalletech.exom.EObject; -import org.openfast.FastDictionary; +import org.openfast.dictionary.FastDictionary; import org.openfast.template.Scalar; public interface ScalarCodec extends Serializable { Copied: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/ApplicationTypeDictionary.java (from rev 157, branches/openfast-2.x/core/src/main/java/org/openfast/ApplicationTypeDictionary.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/ApplicationTypeDictionary.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/ApplicationTypeDictionary.java 2008-06-26 13:40:19 UTC (rev 159) @@ -0,0 +1,72 @@ +/* +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.dictionary; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.openfast.QName; +import org.openfast.ScalarValue; +import org.openfast.template.Group; + +public class ApplicationTypeDictionary implements Dictionary { + + 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 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 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(); + } + +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Dictionary.java (from rev 157, branches/openfast-2.x/core/src/main/java/org/openfast/Dictionary.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Dictionary.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Dictionary.java 2008-06-26 13:40:19 UTC (rev 159) @@ -0,0 +1,37 @@ +/* +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.dictionary; + +import org.openfast.QName; +import org.openfast.ScalarValue; +import org.openfast.template.Group; + + +public interface Dictionary { + public static final String TEMPLATE = "template"; + public static final String GLOBAL = "global"; + + ScalarValue lookup(Group template, QName key, QName currentApplicationType); + + void store(Group group, QName applicationType, QName key, ScalarValue valueToEncode); + + void reset(); +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Entry.java (from rev 157, branches/openfast-2.x/core/src/main/java/org/openfast/Entry.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Entry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/Entry.java 2008-06-26 13:40:19 UTC (rev 159) @@ -0,0 +1,12 @@ +package org.openfast.dictionary; + +public interface Entry { + void setInt(int value); + int getInt(); + boolean hasNext(); + Entry getNext(); + boolean matches(Object key); + boolean isNull(); + void setNext(Entry entry); + void setNull(); +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java (from rev 157, branches/openfast-2.x/core/src/main/java/org/openfast/FastDictionary.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/FastDictionary.java 2008-06-26 13:40:19 UTC (rev 159) @@ -0,0 +1,17 @@ +package org.openfast.dictionary; + +import org.lasalletech.exom.EObject; +import org.lasalletech.exom.Entity; +import org.openfast.QName; + +public interface FastDictionary { + int lookupInt(Entity template, QName key, QName currentApplicationType); + + void store(Entity template, QName key, QName currentApplicationType, int value); + void storeNull(Entity entity, QName key, QName currentApplicationType); + + boolean isDefined(EObject object, QName key, QName currentApplicationType); + boolean isNull(EObject object, QName key, QName currentApplicationType); + + void reset(); +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalDictionary.java (from rev 157, branches/openfast-2.x/core/src/main/java/org/openfast/GlobalDictionary.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalDictionary.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalDictionary.java 2008-06-26 13:40:19 UTC (rev 159) @@ -0,0 +1,61 @@ +/* +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.dictionary; + +import org.openfast.QName; +import org.openfast.ScalarValue; +import org.openfast.template.Group; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + + +public class GlobalDictionary implements Dictionary { + protected Map table = new HashMap(); + + public ScalarValue lookup(Group template, QName key, QName applicationType) { + if (!table.containsKey(key)) { + return ScalarValue.UNDEFINED; + } + + return (ScalarValue) table.get(key); + } + + public void store(Group group, QName applicationType, QName key, ScalarValue value) { + table.put(key, value); + } + + 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(); + } +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java (from rev 157, branches/openfast-2.x/core/src/main/java/org/openfast/GlobalFastDictionary.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/GlobalFastDictionary.java 2008-06-26 13:40:19 UTC (rev 159) @@ -0,0 +1,77 @@ +package org.openfast.dictionary; + +import java.util.Arrays; +import org.lasalletech.exom.EObject; +import org.lasalletech.exom.Entity; +import org.openfast.QName; + +public class GlobalFastDictionary implements FastDictionary { + // Use power of 2 for size so that hashes can be calculated quickly + private Entry[] entries = new Entry[256]; + + public int lookupInt(Entity template, QName key, QName currentApplicationType) { + return getEntry(key).getInt(); + } + + public void reset() { + Arrays.fill(entries, null); + } + + public void store(Entity template, QName key, QName currentApplicationType, int value) { + int index = key.hashCode() % entries.length; + Entry entry = entries[index]; + if (entry == null) { + entries[index] = new IntegerEntry(key, value); + } else { + while (!entry.matches(key)) { + if (!entry.hasNext()) { + entry.setNext(new IntegerEntry(key, value)); + return; + } + entry = entry.getNext(); + } + entry.setInt(value); + } + } + + public void storeNull(Entity entity, QName key, QName currentApplicationType) { + int index = key.hashCode() & (entries.length - 1); + Entry entry = entries[index]; + if (entry == null) { + entries[index] = new NullEntry(key); + } else { + while (!entry.matches(key)) { + if (!entry.hasNext()) { + entry.setNext(new NullEntry(key)); + return; + } + entry = entry.getNext(); + } + entry.setNull(); + } + } + + public boolean isDefined(EObject object, QName key, QName currentApplicationType) { + Entry entry = getEntry(key); + return entry != null; + } + + private Entry getEntry(QName key) { + int index = key.hashCode() % entries.length; + Entry entry = entries[index]; + if (entry == null) + return null; + while (!entry.matches(key)) { + if (!entry.hasNext()) + return null; + entry = entry.getNext(); + } + return entry; + } + + public boolean isNull(EObject object, QName key, QName currentApplicationType) { + Entry entry = getEntry(key); + if (entry == null) return false; + return entry.isNull(); + } +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/IntegerEntry.java (from rev 157, branches/openfast-2.x/core/src/main/java/org/openfast/IntegerEntry.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/IntegerEntry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/IntegerEntry.java 2008-06-26 13:40:19 UTC (rev 159) @@ -0,0 +1,49 @@ +package org.openfast.dictionary; + +import org.openfast.QName; + +public class IntegerEntry implements Entry { + private final QName key; + private int value; + private Entry next; + private boolean isNull; + + public IntegerEntry(QName key, int value) { + if (key == null) throw new NullPointerException(); + this.key = key; + this.value = value; + } + + public int getInt() { + return value; + } + + public Entry getNext() { + return next; + } + + public boolean hasNext() { + return next != null; + } + + public boolean isNull() { + return isNull; + } + + public boolean matches(Object key) { + return this.key.equals(key); + } + + public void setInt(int value) { + this.value = value; + isNull = false; + } + + public void setNext(Entry entry) { + next = entry; + } + + public void setNull() { + isNull = true; + } +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/NullEntry.java (from rev 157, branches/openfast-2.x/core/src/main/java/org/openfast/NullEntry.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/NullEntry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/NullEntry.java 2008-06-26 13:40:19 UTC (rev 159) @@ -0,0 +1,42 @@ +package org.openfast.dictionary; + +import org.openfast.QName; + +public class NullEntry implements Entry { + private final QName key; + private Entry next; + + public NullEntry(QName key) { + this.key = key; + } + + public int getInt() { + throw new UnsupportedOperationException(); + } + + public Entry getNext() { + return next; + } + + public boolean hasNext() { + return next != null; + } + + public boolean isNull() { + return true; + } + + public boolean matches(Object key) { + return this.key.equals(key); + } + + public void setInt(int value) { + throw new UnsupportedOperationException(); + } + + public void setNext(Entry entry) { + next = entry; + } + + public void setNull() {} +} Copied: branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/TemplateDictionary.java (from rev 157, branches/openfast-2.x/core/src/main/java/org/openfast/TemplateDictionary.java) =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/TemplateDictionary.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/dictionary/TemplateDictionary.java 2008-06-26 13:40:19 UTC (rev 159) @@ -0,0 +1,74 @@ +/* +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.dictionary; + +import org.openfast.QName; +import org.openfast.ScalarValue; +import org.openfast.template.Group; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + + +public class TemplateDictionary implements Dictionary { + protected Map table = new HashMap(); + + public ScalarValue lookup(Group template, QName key, QName applicationType) { + if (!table.containsKey(template)) { + return ScalarValue.UNDEFINED; + } + + if (((Map) table.get(template)).containsKey(key)) { + return (ScalarValue) ((Map) table.get(template)).get(key); + } + + return ScalarValue.UNDEFINED; + } + + public void reset() { + table.clear(); + } + + public void store(Group group, QName applicationType, QName key, ScalarValue valueToEncode) { + if (!table.containsKey(group)) { + table.put(group, new HashMap()); + } + + ((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: branches/openfast-2.x/core/src/main/java/org/openfast/session/template/exchange/AbstractFieldInstructionConverter.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/session/template/exchange/AbstractFieldInstructionConverter.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/session/template/exchange/AbstractFieldInstructionConverter.java 2008-06-26 13:40:19 UTC (rev 159) @@ -22,9 +22,9 @@ import java.util.HashMap; import java.util.Map; -import org.openfast.Dictionary; import org.openfast.GroupValue; import org.openfast.Message; +import org.openfast.dictionary.Dictionary; import org.openfast.session.SessionControlProtocol_1_1; import org.openfast.template.Field; import org.openfast.template.Group; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/ComposedScalar.java 2008-06-26 13:40:19 UTC (rev 159) @@ -23,12 +23,12 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import org.openfast.BitVectorBuilder; -import org.openfast.BitVectorReader; import org.openfast.Context; import org.openfast.FieldValue; import org.openfast.QName; import org.openfast.template.type.Type; +import org.openfast.util.BitVectorBuilder; +import org.openfast.util.BitVectorReader; public class ComposedScalar extends Field { private static final long serialVersionUID = 1L; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/DynamicTemplateReference.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/DynamicTemplateReference.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/DynamicTemplateReference.java 2008-06-26 13:40:19 UTC (rev 159) @@ -21,13 +21,13 @@ package org.openfast.template; import java.io.InputStream; -import org.openfast.BitVectorBuilder; -import org.openfast.BitVectorReader; import org.openfast.Context; import org.openfast.FieldValue; import org.openfast.Message; import org.openfast.QName; import org.openfast.codec.FastDecoder; +import org.openfast.util.BitVectorBuilder; +import org.openfast.util.BitVectorReader; public class DynamicTemplateReference extends Field { private static final long serialVersionUID = 1L; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Field.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Field.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Field.java 2008-06-26 13:40:19 UTC (rev 159) @@ -24,11 +24,11 @@ import java.io.Serializable; import java.util.HashMap; import java.util.Map; -import org.openfast.BitVectorBuilder; -import org.openfast.BitVectorReader; import org.openfast.Context; import org.openfast.FieldValue; import org.openfast.QName; +import org.openfast.util.BitVectorBuilder; +import org.openfast.util.BitVectorReader; public abstract class Field implements Serializable { protected final QName name; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Group.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Group.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Group.java 2008-06-26 13:40:19 UTC (rev 159) @@ -28,9 +28,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.openfast.BitVector; -import org.openfast.BitVectorBuilder; -import org.openfast.BitVectorReader; import org.openfast.BitVectorValue; import org.openfast.Context; import org.openfast.FieldValue; @@ -40,6 +37,9 @@ import org.openfast.error.FastConstants; import org.openfast.error.FastException; import org.openfast.template.type.codec.TypeCodec; +import org.openfast.util.BitVector; +import org.openfast.util.BitVectorBuilder; +import org.openfast.util.BitVectorReader; public class Group extends Field { private static final long serialVersionUID = 1L; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/MessageTemplate.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/MessageTemplate.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/MessageTemplate.java 2008-06-26 13:40:19 UTC (rev 159) @@ -21,7 +21,6 @@ package org.openfast.template; import java.io.InputStream; -import org.openfast.BitVectorReader; import org.openfast.Context; import org.openfast.FieldValue; import org.openfast.IntegerValue; @@ -32,6 +31,7 @@ import org.openfast.error.FastException; import org.openfast.template.operator.Operator; import org.openfast.template.type.Type; +import org.openfast.util.BitVectorReader; public class MessageTemplate extends Group implements FieldSet { private static final long serialVersionUID = 1L; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Scalar.java 2008-06-26 13:40:19 UTC (rev 159) @@ -22,20 +22,20 @@ import java.io.InputStream; -import org.openfast.BitVectorBuilder; -import org.openfast.BitVectorReader; import org.openfast.Context; -import org.openfast.Dictionary; import org.openfast.FieldValue; import org.openfast.Global; import org.openfast.QName; import org.openfast.ScalarValue; +import org.openfast.dictionary.Dictionary; import org.openfast.error.FastConstants; import org.openfast.error.FastException; import org.openfast.template.operator.Operator; import org.openfast.template.operator.OperatorCodec; import org.openfast.template.type.Type; import org.openfast.template.type.codec.TypeCodec; +import org.openfast.util.BitVectorBuilder; +import org.openfast.util.BitVectorReader; import org.openfast.util.RecordingInputStream; public class Scalar extends Field { Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java 2008-06-26 13:27:57 UTC (rev 158) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Sequence.java 2008-06-26 13:40:19 UTC (rev 159) @@ -24,9 +24,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.Iterator; -import org.openfast.BitVectorReader; import org.openfast.QName; -import org.openfast.BitVectorBuilder; import org.openfast.Context; import org.openfast.FieldValue; import org.openfast.Global; @@ -37,6 +35,8 @@ import org.openfast.error.FastConstants; import org.openfast.template.operator.Operator; import org.openfast.template.type.Type; +import org.openfast.util.BitVectorBuilder; +import org.openfast.util.BitVectorReader; public class Sequence extends Field implements FieldSet { private static final long serialVersionUID = 1L; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/StaticTemplateReference.java ===========================================================... [truncated message content] |
From: <ope...@li...> - 2008-06-26 13:27:48
|
Revision: 158 http://openfast.svn.sourceforge.net/openfast/?rev=158&view=rev Author: jacob_northey Date: 2008-06-26 06:27:57 -0700 (Thu, 26 Jun 2008) Log Message: ----------- Refactored IncrementIntegerCodec Modified Paths: -------------- branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/IntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/error/FastConstants.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java Property Changed: ---------------- branches/openfast-2.x/core/ Property changes on: branches/openfast-2.x/core ___________________________________________________________________ Name: svn:ignore - target + target .classpath .project .settings Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java 2008-06-25 21:22:57 UTC (rev 157) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java 2008-06-26 13:27:57 UTC (rev 158) @@ -23,7 +23,9 @@ import org.lasalletech.exom.EObject; import org.openfast.FastDictionary; import org.openfast.NumericValue; +import org.openfast.QName; import org.openfast.ScalarValue; +import org.openfast.error.FastConstants; import org.openfast.template.Scalar; final class IncrementIntegerCodec implements ScalarCodec { @@ -31,25 +33,27 @@ private final IntegerCodec integerCodec; private final int defaultValue; private final boolean hasDefaultValue; - + public IncrementIntegerCodec(IntegerCodec integerCodec) { this.integerCodec = integerCodec; this.hasDefaultValue = false; this.defaultValue = 0; } - + public IncrementIntegerCodec(IntegerCodec integerCodec, int defaultValue) { this.integerCodec = integerCodec; this.hasDefaultValue = true; this.defaultValue = defaultValue; } - - public void decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, FastDictionary dictionary) { + + public int decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, FastDictionary dictionary) { + int length = integerCodec.getLength(buffer, offset); int value = integerCodec.decode(buffer, offset); dictionary.store(object.getEntity(), scalar.getKey(), null, value); object.set(index, value); + return offset + length; } - + public void decodeEmpty(EObject object, int index, Scalar scalar, FastDictionary dictionary) { if (dictionary.isNull(object, scalar.getKey(), null)) { // leave object value set to null @@ -66,25 +70,57 @@ dictionary.storeNull(object.getEntity(), scalar.getKey(), null); } } - } else { + } else { int previousValue = dictionary.lookupInt(object.getEntity(), scalar.getKey(), null); - object.set(index, previousValue+1); + object.set(index, previousValue + 1); dictionary.store(object.getEntity(), scalar.getKey(), null, previousValue + 1); } } - + public int getLength(byte[] buffer, int offset) { return integerCodec.getLength(buffer, offset); } - public void encode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, FastDictionary dictionary) { - if (dictionary.isDefined(object, scalar.getKey(), null)) { -// int previousValue = dictionary.lookupInt(object.getEntity(), scalar.getKey(), null); - } else { - + public int encode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, FastDictionary dictionary) { + QName key = scalar.getKey(); + if (!object.isDefined(index)) { + if (!scalar.isOptional()) { + // TODO - error when value is null and scalar is mandatory + } + if (dictionary.isNull(object, key, null)) + return offset; + else { + return encodeNull(buffer, offset, dictionary, key); + } } + int value = object.getInt(index); + if (dictionary.isNull(object, key, null)) { + dictionary.store(null, key, null, value); + return integerCodec.encode(buffer, offset, value); + } + if (!dictionary.isDefined(object, key, null)) { + if (!hasDefaultValue) { + dictionary.store(null, key, null, value); + return integerCodec.encode(buffer, offset, value); + } else if (hasDefaultValue && value == defaultValue) { + return offset; + } else { + return integerCodec.encode(buffer, offset, value); + } + } + int previousValue = dictionary.lookupInt(null, key, null); + if (value == previousValue + 1) { + return offset; + } + return integerCodec.encode(buffer, offset, value); } + private int encodeNull(byte[] buffer, int offset, FastDictionary dictionary, QName key) { + buffer[offset] = FastConstants.NULL_BYTE; + dictionary.storeNull(null, key, null); + return offset + 1; + } + public ScalarValue getValueToEncode(ScalarValue value, ScalarValue priorValue, Scalar field) { if (priorValue == null) { return value; Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/IntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/IntegerCodec.java 2008-06-25 21:22:57 UTC (rev 157) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/IntegerCodec.java 2008-06-26 13:27:57 UTC (rev 158) @@ -2,4 +2,5 @@ public interface IntegerCodec extends TypeCodec { int decode(byte[] buffer, int offset); + int encode(byte[] buffer, int offset, int value); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java 2008-06-25 21:22:57 UTC (rev 157) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java 2008-06-26 13:27:57 UTC (rev 158) @@ -26,7 +26,7 @@ import org.openfast.template.Scalar; public interface ScalarCodec extends Serializable { - void decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, FastDictionary dictionary); - void encode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, FastDictionary dictionary); + int decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, FastDictionary dictionary); + int encode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, FastDictionary dictionary); int getLength(byte[] buffer, int offset); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/error/FastConstants.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/error/FastConstants.java 2008-06-25 21:22:57 UTC (rev 157) +++ branches/openfast-2.x/core/src/main/java/org/openfast/error/FastConstants.java 2008-06-26 13:27:57 UTC (rev 158) @@ -23,6 +23,7 @@ import org.openfast.QName; public interface FastConstants { + byte NULL_BYTE = (byte) 0x80; QName ANY_TYPE = new QName("any"); FastAlertSeverity ERROR = FastAlertSeverity.ERROR; FastAlertSeverity WARN = FastAlertSeverity.WARN; Modified: branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java 2008-06-25 21:22:57 UTC (rev 157) +++ branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java 2008-06-26 13:27:57 UTC (rev 158) @@ -15,6 +15,38 @@ public class IncrementIntegerCodecTest extends OpenFastTestCase { IncrementIntegerCodec noDefaultSignedCodec = new IncrementIntegerCodec(new SignedIntegerCodec()); IncrementIntegerCodec default22SignedCodec = new IncrementIntegerCodec(new SignedIntegerCodec(), 22); + + public void testEncode() { + SimpleEntity entity = new SimpleEntity("yeah"); + entity.add(new SimpleField("anything", null)); + EObject object = entity.newObject(); + Scalar scalar = new Scalar("1", Type.U32, Operator.INCREMENT, ScalarValue.UNDEFINED, true); + FastDictionary dictionary = new GlobalFastDictionary(); + byte[] buffer = new byte[1]; + + object.set(0, 22); + int newOffset = default22SignedCodec.encode(object, 0, buffer, 0, scalar, dictionary); + assertEquals(0, newOffset); + + dictionary.reset(); + newOffset = noDefaultSignedCodec.encode(object, 0, buffer, 0, scalar, dictionary); + assertEquals(1, newOffset); + assertEquals("10010110", buffer); + + object.set(0, 23); + newOffset = noDefaultSignedCodec.encode(object, 0, buffer, 0, scalar, dictionary); + assertEquals(0, newOffset); + + object.set(0, 25); + newOffset = noDefaultSignedCodec.encode(object, 0, buffer, 0, scalar, dictionary); + assertEquals(1, newOffset); + assertEquals("10011001", buffer); + + object.clear(0); + newOffset = noDefaultSignedCodec.encode(object, 0, buffer, 0, scalar, dictionary); + assertEquals(1, newOffset); + assertEquals("10000000", buffer); + } public void testDecodeEmpty() { SimpleEntity entity = new SimpleEntity("yeah"); @@ -35,14 +67,18 @@ } public void testDecode() { + SimpleEntity entity = new SimpleEntity("yeah"); + entity.add(new SimpleField("anything", null)); + EObject object = entity.newObject(); + Scalar scalar = new Scalar("1", Type.U32, Operator.INCREMENT, ScalarValue.UNDEFINED, true); + FastDictionary dictionary = new GlobalFastDictionary(); + + noDefaultSignedCodec.decode(object, 0, bytes("10000001"), 0, scalar, dictionary); + assertEquals(1, object.getInt(0)); } public void testGetLength() { byte[] buffer = ByteUtil.convertBitStringToFastByteArray("01000000 10000000"); assertEquals(2, noDefaultSignedCodec.getLength(buffer, 0)); } - - public void testEncode() { - - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ope...@li...> - 2008-06-25 21:22:52
|
Revision: 157 http://openfast.svn.sourceforge.net/openfast/?rev=157&view=rev Author: jacob_northey Date: 2008-06-25 14:22:57 -0700 (Wed, 25 Jun 2008) Log Message: ----------- Proof of Concept: Created new primitive-based IncrementIntegerCodec and GlobalFastDictionary Modified Paths: -------------- branches/openfast-2.x/core/pom.xml branches/openfast-2.x/core/src/main/java/org/openfast/template/type/ByteVectorType.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/DecimalType.java branches/openfast-2.x/core/src/main/java/org/openfast/template/type/Type.java Added Paths: ----------- branches/openfast-2.x/core/src/main/java/org/openfast/Entry.java branches/openfast-2.x/core/src/main/java/org/openfast/FastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/GlobalFastDictionary.java branches/openfast-2.x/core/src/main/java/org/openfast/IntegerEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/NullEntry.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/IntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodecTest.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/StopBitEncodedTypeCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodec.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/ branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastOperators.java branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastTypes.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Operator.java branches/openfast-2.x/core/src/main/java/org/openfast/template/Type.java branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/FieldCodecFactory.java branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java Modified: branches/openfast-2.x/core/pom.xml =================================================================== --- branches/openfast-2.x/core/pom.xml 2008-06-25 03:12:39 UTC (rev 156) +++ branches/openfast-2.x/core/pom.xml 2008-06-25 21:22:57 UTC (rev 157) @@ -86,4 +86,12 @@ </plugin> </plugins> </build> + + <dependencies> + <dependency> + <groupId>com.lasalletech.exom</groupId> + <artifactId>exom</artifactId> + <version>0.2.0-SNAPSHOT</version> + </dependency> + </dependencies> </project> \ No newline at end of file Added: branches/openfast-2.x/core/src/main/java/org/openfast/Entry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/Entry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/Entry.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,12 @@ +package org.openfast; + +public interface Entry { + void setInt(int value); + int getInt(); + boolean hasNext(); + Entry getNext(); + boolean matches(Object key); + boolean isNull(); + void setNext(Entry entry); + void setNull(); +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/FastDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/FastDictionary.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/FastDictionary.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,16 @@ +package org.openfast; + +import org.lasalletech.exom.EObject; +import org.lasalletech.exom.Entity; + +public interface FastDictionary { + int lookupInt(Entity template, QName key, QName currentApplicationType); + + void store(Entity template, QName key, QName currentApplicationType, int value); + void storeNull(Entity entity, QName key, QName currentApplicationType); + + boolean isDefined(EObject object, QName key, QName currentApplicationType); + boolean isNull(EObject object, QName key, QName currentApplicationType); + + void reset(); +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/GlobalFastDictionary.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/GlobalFastDictionary.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/GlobalFastDictionary.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,76 @@ +package org.openfast; + +import java.util.Arrays; +import org.lasalletech.exom.EObject; +import org.lasalletech.exom.Entity; + +public class GlobalFastDictionary implements FastDictionary { + // Use power of 2 for size so that hashes can be calculated quickly + private Entry[] entries = new Entry[256]; + + public int lookupInt(Entity template, QName key, QName currentApplicationType) { + return getEntry(key).getInt(); + } + + public void reset() { + Arrays.fill(entries, null); + } + + public void store(Entity template, QName key, QName currentApplicationType, int value) { + int index = key.hashCode() % entries.length; + Entry entry = entries[index]; + if (entry == null) { + entries[index] = new IntegerEntry(key, value); + } else { + while (!entry.matches(key)) { + if (!entry.hasNext()) { + entry.setNext(new IntegerEntry(key, value)); + return; + } + entry = entry.getNext(); + } + entry.setInt(value); + } + } + + public void storeNull(Entity entity, QName key, QName currentApplicationType) { + int index = key.hashCode() & (entries.length - 1); + Entry entry = entries[index]; + if (entry == null) { + entries[index] = new NullEntry(key); + } else { + while (!entry.matches(key)) { + if (!entry.hasNext()) { + entry.setNext(new NullEntry(key)); + return; + } + entry = entry.getNext(); + } + entry.setNull(); + } + } + + public boolean isDefined(EObject object, QName key, QName currentApplicationType) { + Entry entry = getEntry(key); + return entry != null; + } + + private Entry getEntry(QName key) { + int index = key.hashCode() % entries.length; + Entry entry = entries[index]; + if (entry == null) + return null; + while (!entry.matches(key)) { + if (!entry.hasNext()) + return null; + entry = entry.getNext(); + } + return entry; + } + + public boolean isNull(EObject object, QName key, QName currentApplicationType) { + Entry entry = getEntry(key); + if (entry == null) return false; + return entry.isNull(); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/IntegerEntry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/IntegerEntry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/IntegerEntry.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,47 @@ +package org.openfast; + +public class IntegerEntry implements Entry { + private final QName key; + private int value; + private Entry next; + private boolean isNull; + + public IntegerEntry(QName key, int value) { + if (key == null) throw new NullPointerException(); + this.key = key; + this.value = value; + } + + public int getInt() { + return value; + } + + public Entry getNext() { + return next; + } + + public boolean hasNext() { + return next != null; + } + + public boolean isNull() { + return isNull; + } + + public boolean matches(Object key) { + return this.key.equals(key); + } + + public void setInt(int value) { + this.value = value; + isNull = false; + } + + public void setNext(Entry entry) { + next = entry; + } + + public void setNull() { + isNull = true; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/NullEntry.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/NullEntry.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/NullEntry.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,40 @@ +package org.openfast; + +public class NullEntry implements Entry { + private final QName key; + private Entry next; + + public NullEntry(QName key) { + this.key = key; + } + + public int getInt() { + throw new UnsupportedOperationException(); + } + + public Entry getNext() { + return next; + } + + public boolean hasNext() { + return next != null; + } + + public boolean isNull() { + return true; + } + + public boolean matches(Object key) { + return this.key.equals(key); + } + + public void setInt(int value) { + throw new UnsupportedOperationException(); + } + + public void setNext(Entry entry) { + next = entry; + } + + public void setNull() {} +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/IncrementIntegerCodec.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,114 @@ +/* +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.codec; + +import org.lasalletech.exom.EObject; +import org.openfast.FastDictionary; +import org.openfast.NumericValue; +import org.openfast.ScalarValue; +import org.openfast.template.Scalar; + +final class IncrementIntegerCodec implements ScalarCodec { + private static final long serialVersionUID = 1L; + private final IntegerCodec integerCodec; + private final int defaultValue; + private final boolean hasDefaultValue; + + public IncrementIntegerCodec(IntegerCodec integerCodec) { + this.integerCodec = integerCodec; + this.hasDefaultValue = false; + this.defaultValue = 0; + } + + public IncrementIntegerCodec(IntegerCodec integerCodec, int defaultValue) { + this.integerCodec = integerCodec; + this.hasDefaultValue = true; + this.defaultValue = defaultValue; + } + + public void decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, FastDictionary dictionary) { + int value = integerCodec.decode(buffer, offset); + dictionary.store(object.getEntity(), scalar.getKey(), null, value); + object.set(index, value); + } + + public void decodeEmpty(EObject object, int index, Scalar scalar, FastDictionary dictionary) { + if (dictionary.isNull(object, scalar.getKey(), null)) { + // leave object value set to null + dictionary.storeNull(object.getEntity(), scalar.getKey(), null); + } else if (!dictionary.isDefined(object, scalar.getKey(), null)) { + if (hasDefaultValue) { + object.set(index, defaultValue); + dictionary.store(object.getEntity(), scalar.getKey(), null, defaultValue); + } else { + if (!scalar.isOptional()) { + throw new IllegalStateException("Field with operator increment must send a value if no previous value existed."); + } else { + // leave object value set to null + dictionary.storeNull(object.getEntity(), scalar.getKey(), null); + } + } + } else { + int previousValue = dictionary.lookupInt(object.getEntity(), scalar.getKey(), null); + object.set(index, previousValue+1); + dictionary.store(object.getEntity(), scalar.getKey(), null, previousValue + 1); + } + } + + public int getLength(byte[] buffer, int offset) { + return integerCodec.getLength(buffer, offset); + } + + public void encode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, FastDictionary dictionary) { + if (dictionary.isDefined(object, scalar.getKey(), null)) { +// int previousValue = dictionary.lookupInt(object.getEntity(), scalar.getKey(), null); + } else { + + } + } + + 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; + } +} \ No newline at end of file Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/IntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/IntegerCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/IntegerCodec.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,5 @@ +package org.openfast.codec; + +public interface IntegerCodec extends TypeCodec { + int decode(byte[] buffer, int offset); +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/ScalarCodec.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,32 @@ +/* +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.codec; + +import java.io.Serializable; +import org.lasalletech.exom.EObject; +import org.openfast.FastDictionary; +import org.openfast.template.Scalar; + +public interface ScalarCodec extends Serializable { + void decode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, FastDictionary dictionary); + void encode(EObject object, int index, byte[] buffer, int offset, Scalar scalar, FastDictionary dictionary); + int getLength(byte[] buffer, int offset); +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodec.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,75 @@ +package org.openfast.codec; + + + +public class SignedIntegerCodec extends StopBitEncodedTypeCodec implements IntegerCodec { + protected static final byte STOP_BIT = (byte) 0x80; + + public int decode(byte[] buffer, int offset) { + int value = 0; + int byt = buffer[offset]; + if ((byt & 0x40) > 0) { + value = -1; + } + value = (value << 7) | (byt & 0x7f); + while ((byt & 0x80) == 0) { + byt = buffer[++offset]; + value = (value << 7) | (byt & 0x7f); + } + return value; + } + + public int encode(byte[] buffer, int offset, int value) { + int index = offset; + int size = getSignedIntegerSize(value); + for (int factor = 0; factor < size; factor++) { + int bitMask = (factor == (size - 1)) ? 0x3f : 0x7f; + buffer[offset + size - factor - 1] = (byte) ((value >> (factor * 7)) & bitMask); + index++; + } + // Get the sign bit from the long value and set it on the first byte + // 01000000 00000000 ... 00000000 + // ^----SIGN BIT + buffer[offset] |= (0x40 & (value >> 57)); + buffer[index - 1] |= STOP_BIT; + return index; + } + + /** + * Find the signed integer size for the passed long value + * + * @param value + * The long value to be used to get the signed integer size + * @return Returns an integer of the appropriate signed integer + */ + public static int getSignedIntegerSize(long value) { + if ((value >= -64) && (value <= 63)) { + return 1; // - 2 ^ 6 ... 2 ^ 6 -1 + } + if ((value >= -8192) && (value <= 8191)) { + return 2; // - 2 ^ 13 ... 2 ^ 13 -1 + } + if ((value >= -1048576) && (value <= 1048575)) { + return 3; // - 2 ^ 20 ... 2 ^ 20 -1 + } + if ((value >= -134217728) && (value <= 134217727)) { + return 4; // - 2 ^ 27 ... 2 ^ 27 -1 + } + if ((value >= -17179869184L) && (value <= 17179869183L)) { + return 5; // - 2 ^ 34 ... 2 ^ 34 -1 + } + if ((value >= -2199023255552L) && (value <= 2199023255551L)) { + return 6; // - 2 ^ 41 ... 2 ^ 41 -1 + } + if ((value >= -281474976710656L) && (value <= 281474976710655L)) { + return 7; // - 2 ^ 48 ... 2 ^ 48 -1 + } + if ((value >= -36028797018963968L) && (value <= 36028797018963967L)) { + return 8; // - 2 ^ 55 ... 2 ^ 55 -1 + } + if ((value >= -4611686018427387904L && value <= 4611686018427387903L)) { + return 9; + } + return 10; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodecTest.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodecTest.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/SignedIntegerCodecTest.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,49 @@ +package org.openfast.codec; + +import java.util.Arrays; +import org.openfast.test.OpenFastTestCase; + +public class SignedIntegerCodecTest extends OpenFastTestCase { + SignedIntegerCodec codec = new SignedIntegerCodec(); + + public void testDecode() { + assertEquals(63, codec.decode(bytes("10111111"), 0)); + assertEquals(64, codec.decode(bytes("00000000 11000000"), 0)); + assertEquals(-1, codec.decode(bytes("11111111"), 0)); + assertEquals(-2, codec.decode(bytes("11111110"), 0)); + assertEquals(-64, codec.decode(bytes("11000000"), 0)); + assertEquals(-65, codec.decode(bytes("01111111 10111111"), 0)); + assertEquals(639, codec.decode(bytes("00000100 11111111"), 0)); + assertEquals(942755, codec.decode(bytes("00111001 01000101 10100011"), 0)); + assertEquals(-942755, codec.decode(bytes("01000110 00111010 11011101"), 0)); + assertEquals(8193, codec.decode(bytes("00000000 01000000 10000001"), 0)); + assertEquals(-8193, codec.decode(bytes("01111111 00111111 11111111"), 0)); + } + + public void testEncode() { + byte[] buffer = new byte[4]; + assertEncode(buffer, "00000000 10111111 00000000 00000000", 63, 2); + assertEncode(buffer, "00000000 00000000 11000000 00000000", 64, 3); + assertEncode(buffer, "00000000 11111111 00000000 00000000", -1, 2); + assertEncode(buffer, "00000000 11111110 00000000 00000000", -2, 2); + assertEncode(buffer, "00000000 11000000 00000000 00000000", -64, 2); + assertEncode(buffer, "00000000 01111111 10111111 00000000", -65, 3); + assertEncode(buffer, "00000000 00000100 11111111 00000000", 639, 3); + assertEncode(buffer, "00000000 00111001 01000101 10100011", 942755, 4); + assertEncode(buffer, "00000000 01000110 00111010 11011101", -942755, 4); + assertEncode(buffer, "00000000 00000000 01000000 10000001", 8193, 4); + assertEncode(buffer, "00000000 01111111 00111111 11111111", -8193, 4); + } + + private void assertEncode(byte[] buffer, String bitstring, int value, int expectedOffset) { + int newOffset = codec.encode(buffer, 1, value); + assertEquals(bitstring, buffer); + assertEquals(expectedOffset, newOffset); + Arrays.fill(buffer, (byte) 0); + } + + public void testGetLength() { + assertEquals(1, codec.getLength(bytes("10000000 01010101 10000000"), 0)); + assertEquals(2, codec.getLength(bytes("00100000 10000000 00001111"), 0)); + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/StopBitEncodedTypeCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/StopBitEncodedTypeCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/StopBitEncodedTypeCodec.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,12 @@ +package org.openfast.codec; + +public class StopBitEncodedTypeCodec { + public int getLength(byte[] buffer, int offset) { + if (offset >= buffer.length) return -1; + int length = 1; + while ((((int) buffer[offset++]) & 0x80) == 0) { + length++; + } + return length; + } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodec.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodec.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/codec/TypeCodec.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,5 @@ +package org.openfast.codec; + +public interface TypeCodec { + int getLength(byte[] buffer, int offset); +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastOperators.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastOperators.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastOperators.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,13 @@ +package org.openfast.fast; + +import org.openfast.template.Operator; + +public interface FastOperators { + Operator CONSTANT = null; + Operator DEFAULT = null; + Operator COPY = null; + Operator INCREMENT = null; + Operator DELTA = null; + Operator TAIL = null; + Operator NONE = null; +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastTypes.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastTypes.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/fast/FastTypes.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,27 @@ +package org.openfast.fast; + +import org.openfast.template.Type; +import org.openfast.template.type.ByteVectorType; +import org.openfast.template.type.DecimalType; +import org.openfast.template.type.SignedIntegerType; +import org.openfast.template.type.StringType; +import org.openfast.template.type.UnsignedIntegerType; + +public interface FastTypes { + 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", null, null); + public final static Type ASCII = new StringType("ascii", null, null); + public final static Type UNICODE = new StringType("unicode", null, null); + 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 }; +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/Operator.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Operator.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Operator.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,27 @@ +/* +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.io.Serializable; + +public interface Operator extends Serializable { + String getName(); +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/Type.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/Type.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/Type.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,97 @@ +/* +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.io.Serializable; + +public interface Type extends Serializable { + String getName(); +// 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, 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(); +// } +} Added: branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/FieldCodecFactory.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/FieldCodecFactory.java (rev 0) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/loader/FieldCodecFactory.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,3 @@ +package org.openfast.template.loader; + +public interface FieldCodecFactory {} Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/type/ByteVectorType.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/type/ByteVectorType.java 2008-06-25 03:12:39 UTC (rev 156) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/type/ByteVectorType.java 2008-06-25 21:22:57 UTC (rev 157) @@ -24,10 +24,10 @@ import org.openfast.ScalarValue; import org.openfast.template.type.codec.TypeCodec; -final class ByteVectorType extends SimpleType { +public final class ByteVectorType extends SimpleType { private static final long serialVersionUID = 1L; - ByteVectorType() { + public ByteVectorType() { super("byteVector", TypeCodec.BYTE_VECTOR, TypeCodec.NULLABLE_BYTE_VECTOR_TYPE); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/type/DecimalType.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/type/DecimalType.java 2008-06-25 03:12:39 UTC (rev 156) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/type/DecimalType.java 2008-06-25 21:22:57 UTC (rev 157) @@ -27,10 +27,10 @@ import org.openfast.template.operator.Operator; import org.openfast.template.type.codec.TypeCodec; -final class DecimalType extends SimpleType { +public final class DecimalType extends SimpleType { private static final long serialVersionUID = 1L; - DecimalType() { + public DecimalType() { super("decimal", TypeCodec.SF_SCALED_NUMBER, TypeCodec.NULLABLE_SF_SCALED_NUMBER); } Modified: branches/openfast-2.x/core/src/main/java/org/openfast/template/type/Type.java =================================================================== --- branches/openfast-2.x/core/src/main/java/org/openfast/template/type/Type.java 2008-06-25 03:12:39 UTC (rev 156) +++ branches/openfast-2.x/core/src/main/java/org/openfast/template/type/Type.java 2008-06-25 21:22:57 UTC (rev 157) @@ -29,7 +29,7 @@ import org.openfast.template.type.codec.TypeCodec; import org.openfast.util.Util; -public abstract class Type implements Serializable { +public abstract class Type implements org.openfast.template.Type, Serializable { private final static Map TYPE_NAME_MAP = new LinkedHashMap(); private final String name; Added: branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java =================================================================== --- branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java (rev 0) +++ branches/openfast-2.x/core/src/test/java/org/openfast/codec/IncrementIntegerCodecTest.java 2008-06-25 21:22:57 UTC (rev 157) @@ -0,0 +1,48 @@ +package org.openfast.codec; + +import org.lasalletech.exom.EObject; +import org.lasalletech.exom.simple.SimpleEntity; +import org.lasalletech.exom.simple.SimpleField; +import org.openfast.ByteUtil; +import org.openfast.FastDictionary; +import org.openfast.GlobalFastDictionary; +import org.openfast.ScalarValue; +import org.openfast.template.Scalar; +import org.openfast.template.operator.Operator; +import org.openfast.template.type.Type; +import org.openfast.test.OpenFastTestCase; + +public class IncrementIntegerCodecTest extends OpenFastTestCase { + IncrementIntegerCodec noDefaultSignedCodec = new IncrementIntegerCodec(new SignedIntegerCodec()); + IncrementIntegerCodec default22SignedCodec = new IncrementIntegerCodec(new SignedIntegerCodec(), 22); + + public void testDecodeEmpty() { + SimpleEntity entity = new SimpleEntity("yeah"); + entity.add(new SimpleField("anything", null)); + EObject object = entity.newObject(); + Scalar scalar = new Scalar("1", Type.U32, Operator.INCREMENT, ScalarValue.UNDEFINED, true); + FastDictionary dictionary = new GlobalFastDictionary(); + + noDefaultSignedCodec.decodeEmpty(object, 0, scalar, dictionary); + assertFalse(object.isDefined(0)); + + dictionary.reset(); + default22SignedCodec.decodeEmpty(object, 0, scalar, dictionary); + assertEquals(22, object.getInt(0)); + + default22SignedCodec.decodeEmpty(object, 0, scalar, dictionary); + assertEquals(23, object.getInt(0)); + } + + public void testDecode() { + } + + public void testGetLength() { + byte[] buffer = ByteUtil.convertBitStringToFastByteArray("01000000 10000000"); + assertEquals(2, noDefaultSignedCodec.getLength(buffer, 0)); + } + + public void testEncode() { + + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |