Skip to Content.
Sympa Menu

notify-dpml - svn commit: r1899 - in development/laboratory/planet/components: protocol protocol/packetapi protocol/packetapi/src protocol/packetapi/src/main protocol/packetapi/src/main/net protocol/packetapi/src/main/net/dpml protocol/packetapi/src/main/net/dpml/protocol protocol/packetapi/src/main/net/dpml/protocol/packet protocol/packetimpl protocol/packetimpl/src protocol/packetimpl/src/main protocol/packetimpl/src/main/net protocol/packetimpl/src/main/net/dpml protocol/packetimpl/src/main/net/dpml/protocol protocol/packetimpl/src/main/net/dpml/protocol/packet protocol/packetimpl/src/main/net/dpml/protocol/packet/impl protocol/packetimpl/src/test protocol/packetimpl/src/test/net protocol/packetimpl/src/test/net/dpml protocol/packetimpl/src/test/net/dpml/protocol protocol/packetimpl/src/test/net/dpml/protocol/packet protocol/packetimpl/src/test/net/dpml/protocol/packet/test space

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: niclas AT netcompartner.com
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r1899 - in development/laboratory/planet/components: protocol protocol/packetapi protocol/packetapi/src protocol/packetapi/src/main protocol/packetapi/src/main/net protocol/packetapi/src/main/net/dpml protocol/packetapi/src/main/net/dpml/protocol protocol/packetapi/src/main/net/dpml/protocol/packet protocol/packetimpl protocol/packetimpl/src protocol/packetimpl/src/main protocol/packetimpl/src/main/net protocol/packetimpl/src/main/net/dpml protocol/packetimpl/src/main/net/dpml/protocol protocol/packetimpl/src/main/net/dpml/protocol/packet protocol/packetimpl/src/main/net/dpml/protocol/packet/impl protocol/packetimpl/src/test protocol/packetimpl/src/test/net protocol/packetimpl/src/test/net/dpml protocol/packetimpl/src/test/net/dpml/protocol protocol/packetimpl/src/test/net/dpml/protocol/packet protocol/packetimpl/src/test/net/dpml/protocol/packet/test space
  • Date: Fri, 25 Feb 2005 10:47:24 +0100

Author: niclas
Date: Fri Feb 25 10:47:22 2005
New Revision: 1899

Added:
development/laboratory/planet/components/protocol/
development/laboratory/planet/components/protocol/build.xml (contents,
props changed)
development/laboratory/planet/components/protocol/index.xml (contents,
props changed)
development/laboratory/planet/components/protocol/packetapi/
development/laboratory/planet/components/protocol/packetapi/build.xml
(contents, props changed)
development/laboratory/planet/components/protocol/packetapi/src/
development/laboratory/planet/components/protocol/packetapi/src/main/
development/laboratory/planet/components/protocol/packetapi/src/main/net/

development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/

development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/

development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/

development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/FieldDescriptor.java
(contents, props changed)

development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/FieldType.java
(contents, props changed)

development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/IllegalPacketFormatException.java
(contents, props changed)

development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/Packet.java
(contents, props changed)

development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/PacketDescriptor.java
(contents, props changed)

development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/PacketException.java
(contents, props changed)

development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/PacketType.java
(contents, props changed)
development/laboratory/planet/components/protocol/packetimpl/
development/laboratory/planet/components/protocol/packetimpl/build.xml
(contents, props changed)
development/laboratory/planet/components/protocol/packetimpl/src/
development/laboratory/planet/components/protocol/packetimpl/src/main/
development/laboratory/planet/components/protocol/packetimpl/src/main/net/

development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/

development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/protocol/

development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/protocol/packet/

development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/protocol/packet/impl/

development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/protocol/packet/impl/DefaultPacket.java
(contents, props changed)
development/laboratory/planet/components/protocol/packetimpl/src/test/
development/laboratory/planet/components/protocol/packetimpl/src/test/net/

development/laboratory/planet/components/protocol/packetimpl/src/test/net/dpml/

development/laboratory/planet/components/protocol/packetimpl/src/test/net/dpml/protocol/

development/laboratory/planet/components/protocol/packetimpl/src/test/net/dpml/protocol/packet/

development/laboratory/planet/components/protocol/packetimpl/src/test/net/dpml/protocol/packet/test/

development/laboratory/planet/components/protocol/packetimpl/src/test/net/dpml/protocol/packet/test/DefaultPacketTest.java
(contents, props changed)
Modified:
development/laboratory/planet/components/space/build.xml
Log:
Starting on a generalized 'legacy protocol' handling system for protocols
that are packet oriented in nature. This package should be able to handle
stuff like process control protocols, banking protocols and instrumentation
protocols.

Added: development/laboratory/planet/components/protocol/build.xml
==============================================================================
--- (empty file)
+++ development/laboratory/planet/components/protocol/build.xml Fri Feb 25
10:47:22 2005
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ Copyright 2004 Niclas Hedhman
+
+ Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied.
+
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<project name="dpml-protocol" default="default" basedir="."
+ xmlns:transit="antlib:net.dpml.transit">
+
+ <transit:import uri="artifact:template:dpml/magic/reactor"/>
+
+</project>

Added: development/laboratory/planet/components/protocol/index.xml
==============================================================================
--- (empty file)
+++ development/laboratory/planet/components/protocol/index.xml Fri Feb 25
10:47:22 2005
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ Copyright 2005 Niclas Hedhman
+
+ Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied.
+
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<index>
+ <import uri="artifact:module:dpml/metro/dpml-metro#SNAPSHOT" />
+
+ <project basedir="packetapi" >
+ <info>
+ <name>dpml-protocol-packetapi</name>
+ <group>dpml/protocol/packet</group>
+ <version>1.0</version>
+ </info>
+ <plugins>
+ <include key="dpml-meta-tools" />
+ </plugins>
+ </project>
+
+ <project basedir="packetimpl" >
+ <info>
+ <name>dpml-protocol-packetimpl</name>
+ <group>dpml/protocol/packet</group>
+ <version>1.0.0</version>
+ </info>
+ <dependencies>
+ <include key="dpml-activity-api" />
+ <include key="dpml-logging-api" />
+ <include key="dpml-context-api" />
+ <include key="dpml-parameters-api"/>
+ <include key="dpml-service-api" />
+ <include key="dpml-protocol-packetapi" />
+ </dependencies>
+ <plugins>
+ <include key="dpml-meta-tools" />
+ </plugins>
+ </project>
+</index>

Added: development/laboratory/planet/components/protocol/packetapi/build.xml
==============================================================================
--- (empty file)
+++ development/laboratory/planet/components/protocol/packetapi/build.xml
Fri Feb 25 10:47:22 2005
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ Copyright 2005 Niclas Hedhman
+
+ Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied.
+
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<project name="dpml-protocol-packetapi" default="install" basedir="."
+ xmlns:transit="antlib:net.dpml.transit"
+>
+
+ <transit:import uri="artifact:template:dpml/magic/standard"/>
+</project>

Added:
development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/FieldDescriptor.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/FieldDescriptor.java
Fri Feb 25 10:47:22 2005
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2005, Niclas Hedhman
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.protocol.packet;
+
+import java.util.Locale;
+
+/** The FieldDescriptor contains the generic information about a field in the
+ * packet composition.
+ */
+public interface FieldDescriptor
+{
+ /** Returns the name of the field.
+ * The name of the field of the protocol should be returned by this
+ * method.
+ * @return the name in english of the field.
+ */
+ String getName();
+
+ /** Returns a human-readable description of the FieldType.
+ * @return a description of the field descriptor in the locale provided.
+ */
+ String getDescriptor( Locale locale );
+
+ /** Query if the field is mandatory or optional in the packet.
+ * The <code>Packet</code> implementation needs to provide the
+ * algorithm for determining whether the field actually exist in the
+ * packet or not.
+ * @return true if the field is required, false if the field is optional.
+ */
+ boolean isMandatory();
+
+ /** Returns the <code>FieldType</code> of this field.
+ * The FieldType is responsible for the formatting of the actual bits
+ * within the field.
+ * @return the <code>FieldType</code> of this field.
+ */
+ FieldType getType();
+}
+

Added:
development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/FieldType.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/FieldType.java
Fri Feb 25 10:47:22 2005
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2005, Niclas Hedhman
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.protocol.packet;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import java.util.Locale;
+
+/** The FieldType interface defines how the data of fields are serialized
+ * and deserialized into the byte stream.
+ */
+public interface FieldType
+{
+ /** Returns the FieldType name.
+ * This method should return the name of the implementation that
+ * handles the serialization/deserialization of the byte stream.
+ * @return the name in english of the FieldType.
+ */
+ String getName();
+
+ /** Returns a human-readable description of the FieldType.
+ * @return a description of the field type in the locale provided.
+ */
+ String getDescription( Locale locale );
+
+ /** Returns the size of the field.
+ * This method returns how many bytes that the field type consists of at
a
+ * minimum. Zero-length is not possible, as the field type would then not
+ * be able to deserialize properly. Furher constraint is that the minimum
+ * size of the field type can not be larger than the maximum field size,
and
+ * if the <code>isVariableSize</code> method returns false, then both the
+ * <code>getMinimumSize</code> and <code>getMaximumSize</code> methods
+ * must return the same number.
+ *
+ * @return the minimum number of bytes that the serialized field can
+ * consist of.
+ */
+ int getMinimumSize();
+
+ /** Returns the size of the field.
+ * This method returns how many bytes that the field type consists of at
a
+ * maximum. A constraint is that the minimum
+ * size of the field type can not be larger than the maximum field size,
and
+ * if the <code>isVariableSize</code> method returns false, then both the
+ * <code>getMinimumSize</code> and <code>getMaximumSize</code> methods
+ * must return the same number.
+ * @return the minimum number of bytes that the serialized field can
+ * consist of.
+ */
+ int getMaximumSize();
+
+ /** Query whether this field can be varied in length.
+ * If this method returns false, then both the
+ * <code>getMinimumSize</code> and <code>getMaximumSize</code> methods
+ * must return the same number.
+ * @return true if the field is not a fixed length field.
+ */
+ boolean isVariableSize();
+
+ /** Serialize the content.
+ * @param content the data to be stored in the field.
+ * @return the resulting byte array of the serialized data. This byte
array
+ * must be of the exact size and may not contain any
+ * non-significant bytes at the beginning or end of the array.
+ */
+ byte[] serialize( String content )
+ throws IllegalPacketFormatException;
+
+ /** Deserializes the content from the input stream.
+ * @param input the byte[] that contains the content.
+ * @return the deserialized content from the input stream.
+ */
+ String deserialize( byte[] input )
+ throws IllegalPacketFormatException;
+}
+
+

Added:
development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/IllegalPacketFormatException.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/IllegalPacketFormatException.java
Fri Feb 25 10:47:22 2005
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2005, Niclas Hedhman
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.protocol.packet;
+
+/** This exception is thrown when the serialized data within a field
contains any
+ * inconsistencies, checksum errors, data integrity errors, data range
errors
+ * or any other malformations of the content.
+ */
+public class IllegalPacketFormatException extends PacketException
+{
+ private FieldType m_Type;
+
+ public IllegalPacketFormatException( String message, FieldType type )
+ {
+ super( message );
+ m_Type = type;
+ }
+
+ public FieldType getFieldType()
+ {
+ return m_Type;
+ }
+}
\ No newline at end of file

Added:
development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/Packet.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/Packet.java
Fri Feb 25 10:47:22 2005
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2005, Niclas Hedhman
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.protocol.packet;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public interface Packet
+{
+ /** Sets the byte at a particular position to the given value.
+ * Values are passed in the range of 0-255, and converted internally
+ * to Java <code>byte</code> values to the same bit by bit
representation.
+ * @param position the position within the packet where the value should
+ * be stored. If the position is beyond the current
length
+ * of the <code>Packet</code> then the length is extended
+ * to include this value as the last entry.
+ * @param value The value of the byte to be written in the range of
+ * 0 to 255, which is converted bitwise to a Java byte
+ * before storing it internally.
+ */
+ void setByte( int position, short value );
+
+ /** Sets the byte at a particular position to the given value.
+ * @param position the position within the packet where the value should
+ * be stored. If the position is beyond the current
length
+ * of the <code>Packet</code> then the length is extended
+ * to include this value as the last entry.
+ * @param value The value of the byte to be written in the range of
+ * -128 to 127. The internal Java two-complements
+ * representation of the byte, will map to the binary of
+ * external representation at bit level.
+ */
+ void setByte( int position, byte value );
+
+ /** Writes all the bytes in the given byte array to the Packet at the
+ * given position.
+ *
+ * @param position the position within the packet where the values should
+ * be stored.If any of the bytes are to be stored
outside the current length of the
+ * <code>Packet</code> the length of the packet is
extended
+ * so that the last byte in the values argument array
will
+ * become the last element in the internal buffer of the
+ * <code>Packet</code>.
+ * @param values The values to be written into the Packet.
+ */
+ void setBytes( int position, byte[] values );
+
+ /** Returns the raw data in the Packet.
+ * The returned data must be a clone, and the caller is free to
manipulate
+ * the array without affecting any internal buffers of the Packet.
+ * @return the raw data of the packet.
+ */
+ byte[] getData();
+
+ /** Writes the composed packet into the provided
<code>OutputStream</code>.
+ * This method will flush the output stream prior to returning, but will
+ * not close the stream, which is the responsibility of the caller.
+ *
+ * @param out the output stream to write the packet to.
+ * @exception IOException if any underlying I/O problems occurs.
+ */
+ void writeTo( OutputStream out )
+ throws IOException;
+}

Added:
development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/PacketDescriptor.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/PacketDescriptor.java
Fri Feb 25 10:47:22 2005
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2005, Niclas Hedhman
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.protocol.packet;
+
+import java.util.List;
+import java.util.Locale;
+
+public interface PacketDescriptor
+{
+ /** Returns the packet descriptor name.
+ * This method should return the name of the implementation that
+ * handles the composition of the packets.
+ *
+ * @return the name in english of the PacketDescriptor.
+ */
+ String getName();
+
+ /** Returns a human-readable description of the FieldType.
+ * @return a description of the field type in the locale provided.
+ */
+ String getDescription( Locale locale );
+
+ /** Returns the PacketType used to parse this packet.
+ */
+ PacketType getType();
+
+ List getFieldDescriptors();
+}
+

Added:
development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/PacketException.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/PacketException.java
Fri Feb 25 10:47:22 2005
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2005, Niclas Hedhman
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.protocol.packet;
+
+/** An abstract parent exception class for all exceptions that are part
+ * of this package.
+ */
+public abstract class PacketException extends Exception
+{
+ protected PacketException( String message )
+ {
+ super( message );
+ }
+
+ protected PacketException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+}
+
+

Added:
development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/PacketType.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/protocol/packetapi/src/main/net/dpml/protocol/packet/PacketType.java
Fri Feb 25 10:47:22 2005
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2005, Niclas Hedhman
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.protocol.packet;
+
+import java.util.Locale;
+
+public interface PacketType
+{
+ /** Returns the packet type name.
+ * This method should return the name of the implementation that
+ * handles the composition of the packets.
+ *
+ * @return the name in english of the PacketType.
+ */
+ String getName();
+
+ /** Returns a human-readable description of the <code>PacketType</code>.
+ * @return a description of the packet type in the locale provided.
+ */
+ String getDescription( Locale locale );
+
+ /** Parses the content of the Packet and construct the implementation
+ * dependent representation of such packet.
+ * @param packet the packet to be parsed, typically received over the
+ * external communication medium.
+ * @return a object that represents the content of the packet in a
+ * Object-Oriented and Java friendly manner.
+ */
+ Object parse( Packet packet )
+ throws IllegalPacketFormatException;
+
+ Packet construct( Object data )
+ throws PacketException;
+}
+
+

Added: development/laboratory/planet/components/protocol/packetimpl/build.xml
==============================================================================
--- (empty file)
+++ development/laboratory/planet/components/protocol/packetimpl/build.xml
Fri Feb 25 10:47:22 2005
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ Copyright 2005 Niclas Hedhman
+
+ Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied.
+
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<project name="dpml-protocol-packetimpl" default="install" basedir="."
+ xmlns:transit="antlib:net.dpml.transit"
+>
+
+ <transit:import uri="artifact:template:dpml/magic/standard"/>
+</project>

Added:
development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/protocol/packet/impl/DefaultPacket.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/protocol/packetimpl/src/main/net/dpml/protocol/packet/impl/DefaultPacket.java
Fri Feb 25 10:47:22 2005
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2005, Niclas Hedhman
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.protocol.packet.impl;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import net.dpml.protocol.packet.Packet;
+
+/** This Packet implementation is a pure content holder of bytes that
+ * gets written into it, and can be later extracted either as a byte array
+ * or written to an output stream.
+ *
+ * @metro.component name="protocol-packet" lifestyle="transient"
+ * @metro.service type="net.dpml.protocol.packet.Packet"
+ */
+public class DefaultPacket
+ implements Packet
+{
+ /** The data buffer of the packet. */
+ private byte[] m_buffer;
+
+ /** The current size of the data packet. */
+ private int m_size;
+
+ /** Default constructor for the default packet.
+ */
+ public DefaultPacket()
+ {
+ m_buffer = new byte[ 500 ];
+ m_size = 0;
+ }
+
+ /** Sets the byte at a particular position to the given value.
+ * Values are passed in the range of 0-255, and converted internally
+ * to Java <code>byte</code> values to the same bit by bit
representation.
+ * @param position the position within the packet where the value should
+ * be stored. If the position is beyond the current
length
+ * of the <code>Packet</code> then the length is extended
+ * to include this value as the last entry.
+ * @param value The value of the byte to be written in the range of
+ * 0 to 255, which is converted bitwise to a Java byte
+ * before storing it internally.
+ */
+ public void setByte( int position, short value )
+ {
+ synchronized( this )
+ {
+ if( position >= m_buffer.length )
+ adjustSize();
+ m_buffer[ position ] = (byte) value;
+ m_size++;
+ }
+ }
+
+ /** Sets the byte at a particular position to the given value.
+ * @param position the position within the packet where the value should
+ * be stored. If the position is beyond the current
length
+ * of the <code>Packet</code> then the length is extended
+ * to include this value as the last entry.
+ * @param value The value of the byte to be written in the range of
+ * -128 to 127. The internal Java two-complements
+ * representation of the byte, will map to the binary of
+ * external representation at bit level.
+ */
+ public void setByte( int position, byte value )
+ {
+ synchronized( this )
+ {
+ if( position >= m_buffer.length )
+ adjustSize();
+ m_buffer[ position ] = value;
+ m_size++;
+ }
+ }
+
+ /** Writes all the bytes in the given byte array to the Packet at the
+ * given position.
+ *
+ * @param position the position within the packet where the values should
+ * be stored.If any of the bytes are to be stored
outside the current length of the
+ * <code>Packet</code> the length of the packet is
extended
+ * so that the last byte in the values argument array
will
+ * become the last element in the internal buffer of the
+ * <code>Packet</code>.
+ * @param values The values to be written into the Packet.
+ */
+ public void setBytes( int position, byte[] values )
+ {
+ synchronized( this )
+ {
+ for( int i = 0; i < values.length ; i++ )
+ {
+ setByte( position + i, values[ i ] );
+ }
+ }
+ }
+
+ /** Returns the raw data in the Packet.
+ * The returned data must be a clone, and the caller is free to
manipulate
+ * the array without affecting any internal buffers of the Packet.
+ * @return the raw data of the packet.
+ */
+ public byte[] getData()
+ {
+ synchronized( this )
+ {
+ byte[] result = new byte[ m_size ];
+ System.arraycopy( m_buffer, 0, result, 0, m_size );
+ return result;
+ }
+ }
+
+ /** Writes the composed packet into the provided
<code>OutputStream</code>.
+ * This method will flush the output stream prior to returning, but will
+ * not close the stream, which is the responsibility of the caller.
+ *
+ * @param out the output stream to write the packet to.
+ * @exception IOException if any underlying I/O problems occurs.
+ */
+ public void writeTo( OutputStream out )
+ throws IOException
+ {
+ synchronized( this )
+ {
+ for( int i=0 ; i < m_size ; i++ )
+ {
+ out.write( m_buffer[ i ] );
+ }
+ out.flush();
+ }
+ }
+
+ /** Adjust the buffer to twice the size, by copy the current buffer
+ * into a twice as large new array.
+ */
+ private void adjustSize()
+ {
+ int newSize = m_buffer.length * 2;
+ byte[] newArray = new byte[ newSize ];
+ System.arraycopy( m_buffer, 0, newArray, 0, m_buffer.length );
+ m_buffer = newArray;
+ }
+}
+

Added:
development/laboratory/planet/components/protocol/packetimpl/src/test/net/dpml/protocol/packet/test/DefaultPacketTest.java
==============================================================================
--- (empty file)
+++
development/laboratory/planet/components/protocol/packetimpl/src/test/net/dpml/protocol/packet/test/DefaultPacketTest.java
Fri Feb 25 10:47:22 2005
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2005, Niclas Hedhman
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.protocol.packet.test;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import junit.framework.TestCase;
+
+import net.dpml.protocol.packet.impl.DefaultPacket;
+
+public class DefaultPacketTest extends TestCase
+{
+ private byte[] m_buffer;
+
+ public void setUp()
+ throws Exception
+ {
+ int size = (int) (Math.random() * 1000);
+ m_buffer = new byte[ size ];
+ for( int i = 0 ; i < size ; i++ )
+ {
+ m_buffer[ i ] = (byte) (Math.random() * 65536);
+ }
+ }
+
+ public void testSetByte()
+ {
+ DefaultPacket packet = new DefaultPacket();
+
+ for( int i = 0 ; i < m_buffer.length ; i++ )
+ {
+ packet.setByte( i, m_buffer[ i ] );
+ }
+ byte[] result = packet.getData();
+ checkArrays( result );
+ }
+
+ public void testSetByteShort()
+ {
+ DefaultPacket packet = new DefaultPacket();
+
+ for( int i = 0 ; i < m_buffer.length ; i++ )
+ {
+ short value = m_buffer[ i ];
+ if( value < 0 )
+ {
+ value = (short) (256 + value);
+ }
+ packet.setByte( i, value );
+ }
+ byte[] result = packet.getData();
+ checkArrays( result );
+ }
+
+ public void testSetByteArray()
+ {
+ DefaultPacket packet = new DefaultPacket();
+ packet.setBytes( 0, m_buffer );
+ byte[] result = packet.getData();
+ checkArrays( result );
+ }
+
+ private void checkArrays( byte[] result )
+ {
+ assertEquals( "array size", m_buffer.length, result.length );
+ for( int i = 0; i < result.length ; i++ )
+ {
+ assertEquals( "pos[" + i + "]", m_buffer[ i ], result[ i ] );
+ }
+ }
+}
+

Modified: development/laboratory/planet/components/space/build.xml
==============================================================================
--- development/laboratory/planet/components/space/build.xml (original)
+++ development/laboratory/planet/components/space/build.xml Fri Feb 25
10:47:22 2005
@@ -17,7 +17,7 @@
limitations under the License.
-->

-<project name="jpos-space" default="default" basedir="."
+<project name="dpml-space" default="default" basedir="."
xmlns:transit="antlib:net.dpml.transit">

<transit:import uri="artifact:template:dpml/magic/reactor"/>



  • svn commit: r1899 - in development/laboratory/planet/components: protocol protocol/packetapi protocol/packetapi/src protocol/packetapi/src/main protocol/packetapi/src/main/net protocol/packetapi/src/main/net/dpml protocol/packetapi/src/main/net/dpml/protocol protocol/packetapi/src/main/net/dpml/protocol/packet protocol/packetimpl protocol/packetimpl/src protocol/packetimpl/src/main protocol/packetimpl/src/main/net protocol/packetimpl/src/main/net/dpml protocol/packetimpl/src/main/net/dpml/protocol protocol/packetimpl/src/main/net/dpml/protocol/packet protocol/packetimpl/src/main/net/dpml/protocol/packet/impl protocol/packetimpl/src/test protocol/packetimpl/src/test/net protocol/packetimpl/src/test/net/dpml protocol/packetimpl/src/test/net/dpml/protocol protocol/packetimpl/src/test/net/dpml/protocol/packet protocol/packetimpl/src/test/net/dpml/protocol/packet/test space, niclas, 02/25/2005

Archive powered by MHonArc 2.6.24.

Top of Page