You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2012/01/30 21:35:27 UTC
svn commit: r1237973 - in
/directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber:
grammar/ tlv/
Author: elecharny
Date: Mon Jan 30 20:35:27 2012
New Revision: 1237973
URL: http://svn.apache.org/viewvc?rev=1237973&view=rev
Log:
Update the Javadoc
Modified:
directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/grammar/GrammarTransition.java
directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/BooleanDecoder.java
directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/BooleanDecoderException.java
directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/IntegerDecoder.java
directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/LongDecoder.java
directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/TLV.java
Modified: directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/grammar/GrammarTransition.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/grammar/GrammarTransition.java?rev=1237973&r1=1237972&r2=1237973&view=diff
==============================================================================
--- directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/grammar/GrammarTransition.java (original)
+++ directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/grammar/GrammarTransition.java Mon Jan 30 20:35:27 2012
@@ -28,13 +28,15 @@ import org.apache.directory.shared.asn1.
/**
* Define a transition between two states of a grammar. It stores the next
* state, and the action to execute while executing the transition.
+ *
+ * @param C The container type
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class GrammarTransition<E extends Asn1Container>
+public class GrammarTransition<C extends Asn1Container>
{
/** The action associated to the transition */
- private Action<E> action;
+ private Action<C> action;
/** The previous state */
private Enum<?> previousState;
@@ -54,7 +56,7 @@ public class GrammarTransition<E extends
* @param currentTag the current TLV's tag
* @param action The action to execute. It could be null.
*/
- public GrammarTransition( Enum<?> previousState, Enum<?> currentState, int currentTag, Action<E> action )
+ public GrammarTransition( Enum<?> previousState, Enum<?> currentState, int currentTag, Action<C> action )
{
this.previousState = previousState;
this.currentState = currentState;
@@ -86,7 +88,7 @@ public class GrammarTransition<E extends
* @param currentTag the current TLV's tag
* @param action The action to execute. It could be null.
*/
- public GrammarTransition( Enum<?> previousState, Enum<?> currentState, UniversalTag currentTag, Action<E> action )
+ public GrammarTransition( Enum<?> previousState, Enum<?> currentState, UniversalTag currentTag, Action<C> action )
{
this.previousState = previousState;
this.currentState = currentState;
@@ -124,7 +126,7 @@ public class GrammarTransition<E extends
/**
* @return Returns the action associated with the transition
*/
- public Action<E> getAction()
+ public Action<C> getAction()
{
return action;
}
@@ -149,7 +151,6 @@ public class GrammarTransition<E extends
/**
- * @param statesEnum Starting state.
* @return A representation of the transition as a string.
*/
@Override
Modified: directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/BooleanDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/BooleanDecoder.java?rev=1237973&r1=1237972&r2=1237973&view=diff
==============================================================================
--- directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/BooleanDecoder.java (original)
+++ directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/BooleanDecoder.java Mon Jan 30 20:35:27 2012
@@ -21,6 +21,7 @@ package org.apache.directory.shared.asn1
import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,17 +38,17 @@ public final class BooleanDecoder
/**
- * Parse a byte buffer and send back a booelan.
+ * Parse a Value containing a byte[] and send back a boolean.
*
- * @param value The byte buffer to parse
+ * @param value The Value to parse
* @return A boolean.
- * @throws BooleanDecoderException Thrown if the byte stream does not contains a boolean
+ * @throws BooleanDecoderException Thrown if the Value does not contains a boolean
*/
public static boolean parse( Value value ) throws BooleanDecoderException
{
byte[] bytes = value.getData();
- if ( ( bytes == null ) || ( bytes.length == 0 ) )
+ if ( Strings.isEmpty( bytes ) )
{
throw new BooleanDecoderException( I18n.err( I18n.ERR_00034_0_BYTES_LONG_BOOLEAN ) );
}
Modified: directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/BooleanDecoderException.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/BooleanDecoderException.java?rev=1237973&r1=1237972&r2=1237973&view=diff
==============================================================================
--- directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/BooleanDecoderException.java (original)
+++ directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/BooleanDecoderException.java Mon Jan 30 20:35:27 2012
@@ -6,23 +6,23 @@
* to you 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.
- *
+ * under the License.
+ *
*/
package org.apache.directory.shared.asn1.ber.tlv;
/**
- * Thrown when a BooleanDecoderException has encountered a failure condition
+ * Thrown when a BooleanDecoder has encountered a failure condition
* during a decode.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
Modified: directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/IntegerDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/IntegerDecoder.java?rev=1237973&r1=1237972&r2=1237973&view=diff
==============================================================================
--- directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/IntegerDecoder.java (original)
+++ directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/IntegerDecoder.java Mon Jan 30 20:35:27 2012
@@ -21,6 +21,7 @@ package org.apache.directory.shared.asn1
import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.util.Strings;
/**
@@ -39,20 +40,51 @@ public final class IntegerDecoder
* Parse a byte buffer and send back an integer, controlling that this number
* is in a specified interval.
*
- * @param value The byte buffer to parse
+ * @param value The Value containing the byte[] to parse
* @param min Lowest value allowed, included
* @param max Highest value allowed, included
* @return An integer
- * @throws IntegerDecoderException Thrown if the byte stream does not contains an integer
+ * @throws IntegerDecoderException Thrown if the byte[] does not contains an integer
*/
public static int parse( Value value, int min, int max ) throws IntegerDecoderException
{
+ int result = parseInt( value );
+
+ if ( ( result >= min ) && ( result <= max ) )
+ {
+ return result;
+ }
+ else
+ {
+ throw new IntegerDecoderException( I18n.err( I18n.ERR_00038_VALUE_NOT_IN_RANGE, min, max ) );
+ }
+ }
+
+ /**
+ * Parse a byte buffer and send back an integer
+ *
+ * @param value The byte buffer to parse
+ * @return An integer
+ * @throws IntegerDecoderException Thrown if the byte stream does not contains an integer
+ */
+ public static int parse( Value value ) throws IntegerDecoderException
+ {
+ return parseInt( value );
+ }
+
+
+ /**
+ * Helper method used to parse the integer. We don't check any minimal or maximal
+ * bound.
+ */
+ private static int parseInt( Value value ) throws IntegerDecoderException
+ {
int result = 0;
byte[] bytes = value.getData();
- if ( ( bytes == null ) || ( bytes.length == 0 ) )
+ if ( Strings.isEmpty( bytes ) )
{
throw new IntegerDecoderException( I18n.err( I18n.ERR_00036_0_BYTES_LONG_INTEGER ) );
}
@@ -62,7 +94,7 @@ public final class IntegerDecoder
throw new IntegerDecoderException( I18n.err( I18n.ERR_00037_ABOVE_4_BYTES_INTEGER ) );
}
- for ( int i = 0; ( i < bytes.length ) && ( i < 5 ); i++ )
+ for ( int i = 0; ( i < bytes.length ); i++ )
{
result = ( result << 8 ) | ( bytes[i] & 0x00FF );
}
@@ -71,27 +103,7 @@ public final class IntegerDecoder
{
result = -( ( ( ~result ) + 1 ) & MASK[bytes.length - 1] );
}
-
- if ( ( result >= min ) && ( result <= max ) )
- {
- return result;
- }
- else
- {
- throw new IntegerDecoderException( I18n.err( I18n.ERR_00038_VALUE_NOT_IN_RANGE, min, max ) );
- }
- }
-
-
- /**
- * Parse a byte buffer and send back an integer
- *
- * @param value The byte buffer to parse
- * @return An integer
- * @throws IntegerDecoderException Thrown if the byte stream does not contains an integer
- */
- public static int parse( Value value ) throws IntegerDecoderException
- {
- return parse( value, Integer.MIN_VALUE, Integer.MAX_VALUE );
+
+ return result;
}
}
Modified: directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/LongDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/LongDecoder.java?rev=1237973&r1=1237972&r2=1237973&view=diff
==============================================================================
--- directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/LongDecoder.java (original)
+++ directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/LongDecoder.java Mon Jan 30 20:35:27 2012
@@ -48,6 +48,38 @@ public final class LongDecoder
*/
public static long parse( Value value, long min, long max ) throws LongDecoderException
{
+ long result = parseLong( value );
+
+ if ( ( result >= min ) && ( result <= max ) )
+ {
+ return result;
+ }
+ else
+ {
+ throw new LongDecoderException( I18n.err( I18n.ERR_00038_VALUE_NOT_IN_RANGE, min, max ) );
+ }
+ }
+
+
+ /**
+ * Parse a byte buffer and send back an integer
+ *
+ * @param value The byte buffer to parse
+ * @return An integer
+ * @throws LongDecoderException Thrown if the byte stream does not contains an integer
+ */
+ public static long parse( Value value ) throws LongDecoderException
+ {
+ return parseLong( value );
+ }
+
+
+ /**
+ * Helper method used to parse the long. We don't check any minimal or maximal
+ * bound.
+ */
+ public static long parseLong( Value value ) throws LongDecoderException
+ {
long result = 0;
byte[] bytes = value.getData();
@@ -71,27 +103,7 @@ public final class LongDecoder
{
result = -( ( ( ~result ) + 1 ) & MASK[bytes.length - 1] );
}
-
- if ( ( result >= min ) && ( result <= max ) )
- {
- return result;
- }
- else
- {
- throw new LongDecoderException( I18n.err( I18n.ERR_00038_VALUE_NOT_IN_RANGE, min, max ) );
- }
- }
-
-
- /**
- * Parse a byte buffer and send back an integer
- *
- * @param value The byte buffer to parse
- * @return An integer
- * @throws LongDecoderException Thrown if the byte stream does not contains an integer
- */
- public static long parse( Value value ) throws LongDecoderException
- {
- return parse( value, Long.MIN_VALUE, Long.MAX_VALUE );
+
+ return result;
}
}
Modified: directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/TLV.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/TLV.java?rev=1237973&r1=1237972&r2=1237973&view=diff
==============================================================================
--- directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/TLV.java (original)
+++ directory/shared/trunk/asn1/ber/src/main/java/org/apache/directory/shared/asn1/ber/tlv/TLV.java Mon Jan 30 20:35:27 2012
@@ -6,16 +6,16 @@
* to you 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.
- *
+ * under the License.
+ *
*/
package org.apache.directory.shared.asn1.ber.tlv;
@@ -24,7 +24,7 @@ import org.apache.directory.shared.asn1.
/**
- * This class is used to store Tag, Length and Value decoded from a PDU.
+ * This class is used to store Tags, Lengths and Values decoded from a PDU.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@@ -85,6 +85,7 @@ public class TLV
/** A speedup for single bytes length */
private static final byte[][] ONE_BYTE = new byte[256][];
+ // Initialize an array of byte[] used for encoding lengths below 128
static
{
for ( int i = 0; i < 256; i++ )
@@ -115,7 +116,7 @@ public class TLV
/**
* Checks to see if the tag is constructed.
*
- * @param tag the TLV's tag
+ * @param tag the TLV's tag
* @return true if constructed, false if primitive
*/
public static boolean isConstructed( byte tag )
@@ -139,7 +140,7 @@ public class TLV
* Checks to see if the tag represented by this Tag is primitive or
* constructed.
*
- * @param tag the tag to be checked
+ * @param tag the tag to be checked
* @return true if it is primitive, false if it is constructed
*/
public static boolean isPrimitive( byte tag )
@@ -318,7 +319,7 @@ public class TLV
/**
- * @return Returns the parent.
+ * @return The parent.
*/
public TLV getParent()
{
@@ -338,7 +339,7 @@ public class TLV
/**
* Get the TLV expected length.
*
- * @return Returns the expectedLength.
+ * @return The expectedLength.
*/
public int getExpectedLength()
{
@@ -358,7 +359,7 @@ public class TLV
/**
- * @return the number of bytes necessary to store the TLV's length
+ * @return The number of bytes necessary to store the TLV's length
*/
public int getLengthNbBytes()
{
@@ -367,8 +368,9 @@ public class TLV
/**
- * Set the number of bytes we should use to store the TLV's length
- * @param lengthNbBytes the number of bytes necessary to store the TLV's length
+ * Set the number of bytes we should use to store the TLV's length.
+ *
+ * @param lengthNbBytes The number of bytes necessary to store the TLV's length
*/
public void setLengthNbBytes( int lengthNbBytes )
{
@@ -377,7 +379,7 @@ public class TLV
/**
- * @return the tLV's length
+ * @return the TLV's length
*/
public int getLength()
{
@@ -397,7 +399,7 @@ public class TLV
/**
- * @return the currently read TLV's length bytes
+ * @return The currently read TLV's length bytes
*/
public int getLengthBytesRead()
{
@@ -427,7 +429,7 @@ public class TLV
/**
- * @return the TLV's ID
+ * @return The TLV's ID
*/
public int getId()
{