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/09/24 04:13:16 UTC
svn commit: r1389183 - in /directory/shared/trunk:
dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/
ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/
ldap/model/src/main/java/org/apache/directory/shar...
Author: elecharny
Date: Mon Sep 24 02:13:15 2012
New Revision: 1389183
URL: http://svn.apache.org/viewvc?rev=1389183&view=rev
Log:
Merged the mvbt branch into trunk
Added:
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/SetCursor.java
directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou=schema/cn=adsconfig/ou=attributetypes/m-oid=1.3.6.1.4.1.18060.0.4.1.2.165.ldif
Modified:
directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/LdapResultDsml.java
directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/LdapResultDecorator.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/AbstractCursor.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/Cursor.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/AbstractExprNode.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/ScopeNode.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResult.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResultImpl.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/comparators/UuidComparator.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/syntaxCheckers/UuidSyntaxChecker.java
directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/message/LdapResultImplTest.java
directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou=schema/cn=adsconfig/ou=objectclasses/m-oid=1.3.6.1.4.1.18060.0.4.1.3.160.ldif
directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou=schema/cn=apache/ou=attributetypes/m-oid=1.3.6.1.4.1.18060.0.4.1.2.5.ldif
directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou=schema/cn=apache/ou=attributetypes/m-oid=1.3.6.1.4.1.18060.0.4.1.2.6.ldif
directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/shared/ldap/schemaloader/SchemaManagerEnableDisableLoadTest.java
directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java
Modified: directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/LdapResultDsml.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/LdapResultDsml.java?rev=1389183&r1=1389182&r2=1389183&view=diff
==============================================================================
--- directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/LdapResultDsml.java (original)
+++ directory/shared/trunk/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/LdapResultDsml.java Mon Sep 24 02:13:15 2012
@@ -243,4 +243,13 @@ public class LdapResultDsml implements D
{
getDecorated().setReferral( referral );
}
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isDefaultSuccess()
+ {
+ return false;
+ }
}
Modified: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/LdapResultDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/LdapResultDecorator.java?rev=1389183&r1=1389182&r2=1389183&view=diff
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/LdapResultDecorator.java (original)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/LdapResultDecorator.java Mon Sep 24 02:13:15 2012
@@ -24,8 +24,8 @@ import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import org.apache.directory.shared.asn1.EncoderException;
-import org.apache.directory.shared.asn1.ber.tlv.TLV;
import org.apache.directory.shared.asn1.ber.tlv.BerValue;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
import org.apache.directory.shared.i18n.I18n;
import org.apache.directory.shared.ldap.codec.api.Decorator;
import org.apache.directory.shared.ldap.codec.api.LdapApiService;
@@ -56,6 +56,9 @@ public class LdapResultDecorator impleme
/** The codec responsible for encoding and decoding this object. */
private LdapApiService codec;
+ private static final byte[] DEFAULT_SUCCESS = new byte[]
+ { 0x0A, 0x01, 0x00, 0x04, 0x00, 0x04, 0x00 };
+
/**
* Makes a LdapResult encodable.
@@ -208,7 +211,7 @@ public class LdapResultDecorator impleme
* Compute the LdapResult length
*
* LdapResult :
- * 0x0A 01 resultCode (0..80)
+ * 0x0A 01 resultCode (0..80)
* 0x04 L1 matchedDN (L1 = Length(matchedDN))
* 0x04 L2 errorMessage (L2 = Length(errorMessage))
* [0x83 L3] referrals
@@ -230,6 +233,12 @@ public class LdapResultDecorator impleme
*/
public int computeLength()
{
+ if ( decoratedLdapResult.isDefaultSuccess() )
+ {
+ // The length of a default success PDU : 0xA0 0x01 0x00 0x04 0x00 0x04 0x00
+ return DEFAULT_SUCCESS.length;
+ }
+
int ldapResultLength = 0;
// The result code
@@ -242,13 +251,13 @@ public class LdapResultDecorator impleme
}
else
{
- byte[] matchedDNBytes = Strings.getBytesUtf8( Strings.trimLeft( getMatchedDn().getName() ) );
+ byte[] matchedDNBytes = Strings.getBytesUtf8Ascii( Strings.trimLeft( getMatchedDn().getName() ) );
ldapResultLength += 1 + TLV.getNbBytes( matchedDNBytes.length ) + matchedDNBytes.length;
setMatchedDnBytes( matchedDNBytes );
}
// The errorMessage length
- byte[] errorMessageBytes = Strings.getBytesUtf8( getDiagnosticMessage() );
+ byte[] errorMessageBytes = Strings.getBytesUtf8Ascii( getDiagnosticMessage() );
ldapResultLength += 1 + TLV.getNbBytes( errorMessageBytes.length ) + errorMessageBytes.length;
setErrorMessageBytes( errorMessageBytes );
@@ -277,6 +286,14 @@ public class LdapResultDecorator impleme
throw new EncoderException( I18n.err( I18n.ERR_04023 ) );
}
+ if ( decoratedLdapResult.isDefaultSuccess() )
+ {
+ // The length of a default success PDU : 0xA0 0x01 0x00 0x04 0x00 0x04 0x00
+ buffer.put( DEFAULT_SUCCESS );
+
+ return buffer;
+ }
+
try
{
// The result code
@@ -321,4 +338,13 @@ public class LdapResultDecorator impleme
{
return codec;
}
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isDefaultSuccess()
+ {
+ return decoratedLdapResult.isDefaultSuccess();
+ }
}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/AbstractCursor.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/AbstractCursor.java?rev=1389183&r1=1389182&r2=1389183&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/AbstractCursor.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/AbstractCursor.java Mon Sep 24 02:13:15 2012
@@ -136,4 +136,13 @@ public abstract class AbstractCursor<E>
throw new UnsupportedOperationException( I18n.err( I18n.ERR_02014_UNSUPPORTED_OPERATION, getClass().getName()
.concat( "." ).concat( "isLast()" ) ) );
}
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString( String tabs )
+ {
+ return tabs;
+ }
}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/Cursor.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/Cursor.java?rev=1389183&r1=1389182&r2=1389183&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/Cursor.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/Cursor.java Mon Sep 24 02:13:15 2012
@@ -243,4 +243,12 @@ public interface Cursor<E> extends Itera
* @param monitor the monitor to use for detecting Cursor close events
*/
void setClosureMonitor( ClosureMonitor monitor );
+
+
+ /**
+ * Pretty-print a cursor and its wrapped cursor.
+ * @param tabs The spaces to add at each level
+ * @return The cursor and all it's wrapped elements, recursively printed
+ */
+ String toString( String tabs );
}
Added: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/SetCursor.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/SetCursor.java?rev=1389183&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/SetCursor.java (added)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/SetCursor.java Mon Sep 24 02:13:15 2012
@@ -0,0 +1,405 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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.
+ */
+package org.apache.directory.shared.ldap.model.cursor;
+
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Set;
+
+import org.apache.directory.shared.i18n.I18n;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A simple implementation of a Cursor on a {@link Set}. Optionally, the
+ * Cursor may be limited to a specific range within the list.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @param <E> The element on which this cursor will iterate
+ */
+public class SetCursor<E> extends AbstractCursor<E>
+{
+ /** A dedicated log for cursors */
+ private static final Logger LOG_CURSOR = LoggerFactory.getLogger( "CURSOR" );
+
+ /** The inner Set */
+ private final E[] set;
+
+ /** The associated comparator */
+ private final Comparator<E> comparator;
+
+ /** The current position in the list */
+ private int index = -1;
+
+
+ /**
+ * Creates a new SetCursor.
+ *
+ * As with all Cursors, this SetCursor requires a successful return from
+ * advance operations (next() or previous()) to properly return values
+ * using the get() operation.
+ *
+ * @param comparator an optional comparator to use for ordering
+ * @param set the Set this StCursor operates on
+ */
+ public SetCursor( Comparator<E> comparator, Set<E> set )
+ {
+ if ( set == null )
+ {
+ set = Collections.EMPTY_SET;
+ }
+
+ LOG_CURSOR.debug( "Creating SetCursor {}", this );
+ this.comparator = comparator;
+ this.set = ( E[] ) set.toArray();
+ }
+
+
+ /**
+ * Creates a new SetCursor
+ *
+ * As with all Cursors, this SetCursor requires a successful return from
+ * advance operations (next() or previous()) to properly return values
+ * using the get() operation.
+ *
+ * @param set the Set this SetCursor operates on
+ */
+ public SetCursor( Set<E> set )
+ {
+ this( null, set );
+ }
+
+
+ /**
+ * Creates a new SetCursor without any elements.
+ */
+ public SetCursor()
+ {
+ this( null, Collections.EMPTY_SET );
+ }
+
+
+ /**
+ * Creates a new SetCursor without any elements. We also provide
+ * a comparator.
+ *
+ * @param comparator The comparator to use for the <E> elements
+ */
+ @SuppressWarnings("unchecked")
+ public SetCursor( Comparator<E> comparator )
+ {
+ this( comparator, Collections.EMPTY_SET );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean available()
+ {
+ return ( index >= 0 ) && ( index < set.length );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void before( E element ) throws Exception
+ {
+ checkNotClosed( "before()" );
+
+ if ( comparator == null )
+ {
+ throw new IllegalStateException();
+ }
+
+ // handle some special cases
+ if ( set.length == 0 )
+ {
+ return;
+ }
+ else if ( set.length == 1 )
+ {
+ if ( comparator.compare( element, set[0] ) <= 0 )
+ {
+ beforeFirst();
+ }
+ else
+ {
+ afterLast();
+ }
+ }
+
+ throw new UnsupportedOperationException( I18n.err( I18n.ERR_02008_LIST_MAY_BE_SORTED ) );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void after( E element ) throws Exception
+ {
+ checkNotClosed( "after()" );
+
+ if ( comparator == null )
+ {
+ throw new IllegalStateException();
+ }
+
+ // handle some special cases
+ if ( set.length == 0 )
+ {
+ return;
+ }
+ else if ( set.length == 1 )
+ {
+ if ( comparator.compare( element, set[0] ) >= 0 )
+ {
+ afterLast();
+ }
+ else
+ {
+ beforeFirst();
+ }
+ }
+
+ throw new UnsupportedOperationException( I18n.err( I18n.ERR_02008_LIST_MAY_BE_SORTED ) );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void beforeFirst() throws Exception
+ {
+ checkNotClosed( "beforeFirst()" );
+ this.index = -1;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void afterLast() throws Exception
+ {
+ checkNotClosed( "afterLast()" );
+ this.index = set.length;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean first() throws Exception
+ {
+ checkNotClosed( "first()" );
+
+ if ( set.length > 0 )
+ {
+ index = 0;
+
+ return true;
+ }
+
+ return false;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean last() throws Exception
+ {
+ checkNotClosed( "last()" );
+
+ if ( set.length > 0 )
+ {
+ index = set.length - 1;
+
+ return true;
+ }
+
+ return false;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isFirst() throws Exception
+ {
+ checkNotClosed( "isFirst()" );
+
+ return ( set.length > 0 ) && ( index == 0 );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isLast() throws Exception
+ {
+ checkNotClosed( "isLast()" );
+
+ return ( set.length > 0 ) && ( index == set.length - 1 );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isAfterLast() throws Exception
+ {
+ checkNotClosed( "isAfterLast()" );
+ return index == set.length;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isBeforeFirst() throws Exception
+ {
+ checkNotClosed( "isBeforeFirst()" );
+ return index == -1;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean previous() throws Exception
+ {
+ checkNotClosed( "previous()" );
+
+ // if parked at -1 we cannot go backwards
+ if ( index == -1 )
+ {
+ return false;
+ }
+
+ // if the index moved back is still greater than or eq to start then OK
+ if ( index - 1 >= 0 )
+ {
+ index--;
+
+ return true;
+ }
+
+ // if the index currently less than or equal to start we need to park it at -1 and return false
+ if ( index <= 0 )
+ {
+ index = -1;
+
+ return false;
+ }
+
+ if ( set.length <= 0 )
+ {
+ index = -1;
+ }
+
+ return false;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean next() throws Exception
+ {
+ checkNotClosed( "next()" );
+
+ // if parked at -1 we advance to the start index and return true
+ if ( ( set.length > 0 ) && ( index == -1 ) )
+ {
+ index = 0;
+
+ return true;
+ }
+
+ // if the index plus one is less than the end then increment and return true
+ if ( ( set.length > 0 ) && ( index + 1 < set.length ) )
+ {
+ index++;
+
+ return true;
+ }
+
+ // if the index plus one is equal to the end then increment and return false
+ if ( ( set.length > 0 ) && ( index + 1 == set.length ) )
+ {
+ index++;
+
+ return false;
+ }
+
+ if ( set.length <= 0 )
+ {
+ index = set.length;
+ }
+
+ return false;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public E get() throws Exception
+ {
+ checkNotClosed( "get()" );
+
+ if ( ( index < 0 ) || ( index >= set.length ) )
+ {
+ throw new IOException( I18n.err( I18n.ERR_02009_CURSOR_NOT_POSITIONED ) );
+ }
+
+ return set[index];
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void close() throws Exception
+ {
+ LOG_CURSOR.debug( "Closing ListCursor {}", this );
+ super.close();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void close( Exception cause ) throws Exception
+ {
+ LOG_CURSOR.debug( "Closing ListCursor {}", this );
+ super.close( cause );
+ }
+}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/AbstractExprNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/AbstractExprNode.java?rev=1389183&r1=1389182&r2=1389183&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/AbstractExprNode.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/AbstractExprNode.java Mon Sep 24 02:13:15 2012
@@ -190,7 +190,7 @@ public abstract class AbstractExprNode i
else
{
sb.append( '\\' );
- String digit = Integer.toHexString( ( ( byte ) b ) & 0x00FF );
+ String digit = Integer.toHexString( b & 0x00FF );
if ( digit.length() == 1 )
{
@@ -379,7 +379,14 @@ public abstract class AbstractExprNode i
{
if ( ( null != annotations ) && annotations.containsKey( "count" ) )
{
- return ":[" + annotations.get( "count" ) + "]";
+ Long count = ( Long ) annotations.get( "count" );
+
+ if ( count == Long.MAX_VALUE )
+ {
+ return ":[\u221E]";
+ }
+
+ return ":[" + count + "]";
}
else
{
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/ScopeNode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/ScopeNode.java?rev=1389183&r1=1389182&r2=1389183&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/ScopeNode.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/filter/ScopeNode.java Mon Sep 24 02:13:15 2012
@@ -31,7 +31,7 @@ import org.apache.directory.shared.ldap.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class ScopeNode<ID> extends AbstractExprNode
+public class ScopeNode extends AbstractExprNode
{
/** the scope of this node */
private final SearchScope scope;
@@ -40,7 +40,7 @@ public class ScopeNode<ID> extends Abstr
private final Dn baseDn;
/** the search ID */
- private final ID baseId;
+ private final String baseId;
/** the alias dereferencing mode */
private final AliasDerefMode aliasDerefAliases;
@@ -53,7 +53,7 @@ public class ScopeNode<ID> extends Abstr
* @param baseDn the search base
* @param scope the search scope
*/
- public ScopeNode( AliasDerefMode aliasDerefAliases, Dn baseDn, ID baseId, SearchScope scope )
+ public ScopeNode( AliasDerefMode aliasDerefAliases, Dn baseDn, String baseId, SearchScope scope )
{
super( AssertionType.SCOPE );
this.scope = scope;
@@ -103,7 +103,7 @@ public class ScopeNode<ID> extends Abstr
*
* @return the base ID
*/
- public ID getBaseId()
+ public String getBaseId()
{
return baseId;
}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResult.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResult.java?rev=1389183&r1=1389182&r2=1389183&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResult.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResult.java Mon Sep 24 02:13:15 2012
@@ -184,4 +184,14 @@ public interface LdapResult
* @param referral optional referral on REFERRAL errors.
*/
void setReferral( Referral referral );
+
+
+ /**
+ * Tells if the LdapResult is a success, with no added information. The
+ * MatchedDn will be empty, as the diagnostic message and the referral.
+ * The ResultCode will always be 0.
+ *
+ * @return True if the LdapResult is SUCCESS.
+ */
+ boolean isDefaultSuccess();
}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResultImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResultImpl.java?rev=1389183&r1=1389182&r2=1389183&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResultImpl.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResultImpl.java Mon Sep 24 02:13:15 2012
@@ -43,6 +43,9 @@ public class LdapResultImpl implements L
/** Resultant operation error code - defaults to SUCCESS */
private ResultCodeEnum resultCode = ResultCodeEnum.SUCCESS;
+ /** A flag set when the LdapResult is a SUCESS with no additional information */
+ private boolean isDefaultSuccess = true;
+
// ------------------------------------------------------------------------
// LdapResult Interface Method Implementations
@@ -62,6 +65,7 @@ public class LdapResultImpl implements L
public void setDiagnosticMessage( String diagnosticMessage )
{
this.diagnosticMessage = diagnosticMessage;
+ isDefaultSuccess = false;
}
@@ -80,6 +84,7 @@ public class LdapResultImpl implements L
public void setMatchedDn( Dn matchedDn )
{
this.matchedDn = matchedDn;
+ isDefaultSuccess = false;
}
@@ -98,6 +103,8 @@ public class LdapResultImpl implements L
public void setResultCode( ResultCodeEnum resultCode )
{
this.resultCode = resultCode;
+
+ isDefaultSuccess = isDefaultSuccess & ( resultCode == ResultCodeEnum.SUCCESS );
}
@@ -125,6 +132,16 @@ public class LdapResultImpl implements L
public void setReferral( Referral referral )
{
this.referral = referral;
+ isDefaultSuccess = false;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isDefaultSuccess()
+ {
+ return isDefaultSuccess;
}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java?rev=1389183&r1=1389182&r2=1389183&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Dn.java Mon Sep 24 02:13:15 2012
@@ -303,7 +303,7 @@ public class Dn implements Iterable<Rdn>
this.schemaManager = schemaManager;
this.upName = upName;
this.normName = normName;
- bytes = Strings.getBytesUtf8( upName );
+ bytes = Strings.getBytesUtf8Ascii( upName );
this.rdns = Arrays.asList( rdns );
}
@@ -782,7 +782,7 @@ public class Dn implements Iterable<Rdn>
}
newDn.toUpName();
- newDn.apply( schemaManager );
+ newDn.apply( schemaManager, true );
return newDn;
}
@@ -864,7 +864,7 @@ public class Dn implements Iterable<Rdn>
}
newDn.toUpName();
- newDn.apply( schemaManager );
+ newDn.apply( schemaManager, true );
return newDn;
}
@@ -891,13 +891,13 @@ public class Dn implements Iterable<Rdn>
if ( clonedDn.size() != 0 )
{
clonedDn.normName = suffix.getNormName() + "," + normName;
- clonedDn.bytes = Strings.getBytesUtf8( normName );
+ clonedDn.bytes = Strings.getBytesUtf8Ascii( normName );
clonedDn.upName = suffix.getName() + "," + upName;
}
}
else
{
- clonedDn.apply( schemaManager );
+ clonedDn.apply( schemaManager, true );
clonedDn.toUpName();
}
@@ -922,7 +922,7 @@ public class Dn implements Iterable<Rdn>
clonedDn.rdns.add( 0, newRdn );
- clonedDn.apply( schemaManager );
+ clonedDn.apply( schemaManager, true );
clonedDn.toUpName();
return clonedDn;
@@ -945,7 +945,7 @@ public class Dn implements Iterable<Rdn>
Dn clonedDn = copy();
clonedDn.rdns.add( 0, newRdn.clone() );
- clonedDn.apply( schemaManager );
+ clonedDn.apply( schemaManager, true );
clonedDn.toUpName();
return clonedDn;
@@ -978,7 +978,7 @@ public class Dn implements Iterable<Rdn>
try
{
- newDn.apply( schemaManager );
+ newDn.apply( schemaManager, true );
}
catch ( LdapInvalidDnException e )
{
@@ -1029,7 +1029,7 @@ public class Dn implements Iterable<Rdn>
{
return true;
}
-
+
if ( name.size() != this.size() )
{
return false;
@@ -1137,7 +1137,7 @@ public class Dn implements Iterable<Rdn>
// ATAVs
Rdn rdnCopy = rdn.clone();
rdn.clear();
-
+
if ( rdnCopy.size() < 2 )
{
Ava newAtav = atavOidToName( rdnCopy.getAva(), schemaManager );
@@ -1156,7 +1156,7 @@ public class Dn implements Iterable<Rdn>
sortedOids.add( oid );
avas.put( oid, newAtav );
}
-
+
// And create the Rdn
for ( String oid : sortedOids )
{
@@ -1167,90 +1167,94 @@ public class Dn implements Iterable<Rdn>
/**
- * Normalizes the Dn using the given the schema manager
+ * Normalizes the Dn using the given the schema manager. If the flag is set to true,
+ * we will replace the inner SchemaManager by the provided one.
*
* @param schemaManager The schemaManagerto use to normalize the Dn
+ * @param force Tells if we should replace an existing SchemaManager by a new one
* @return The normalized Dn
* @throws LdapInvalidDnException If the Dn is invalid.
*/
- public Dn apply( SchemaManager schemaManager ) throws LdapInvalidDnException
+ public Dn apply( SchemaManager schemaManager, boolean force ) throws LdapInvalidDnException
{
- this.schemaManager = schemaManager;
-
- if ( this.schemaManager != null )
+ if ( ( this.schemaManager == null ) || force )
{
- synchronized ( this )
- {
- if ( size() == 0 )
- {
- bytes = null;
- normName = "";
-
- return this;
- }
- StringBuilder sb = new StringBuilder();
- boolean isFirst = true;
+ this.schemaManager = schemaManager;
- for ( Rdn rdn : rdns )
+ if ( this.schemaManager != null )
+ {
+ synchronized ( this )
{
- rdn.apply( schemaManager );
-
- if ( isFirst )
+ if ( size() == 0 )
{
- isFirst = false;
+ bytes = null;
+ normName = "";
+
+ return this;
}
- else
+
+ StringBuilder sb = new StringBuilder();
+ boolean isFirst = true;
+
+ for ( Rdn rdn : rdns )
{
- sb.append( ',' );
- }
+ rdn.apply( schemaManager );
- sb.append( rdn.getNormName() );
- }
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
+ {
+ sb.append( ',' );
+ }
- String newNormName = sb.toString();
+ sb.append( rdn.getNormName() );
+ }
- if ( ( normName == null ) || !normName.equals( newNormName ) )
- {
- bytes = Strings.getBytesUtf8( newNormName );
- normName = newNormName;
- }
+ String newNormName = sb.toString();
- return this;
- }
- }
- else
- {
- if ( rdns.size() == 0 )
- {
- bytes = null;
- normName = "";
+ if ( ( normName == null ) || !normName.equals( newNormName ) )
+ {
+ bytes = Strings.getBytesUtf8Ascii( newNormName );
+ normName = newNormName;
+ }
+ }
}
else
{
- StringBuffer sb = new StringBuffer();
- boolean isFirst = true;
-
- for ( Rdn rdn : rdns )
+ if ( rdns.size() == 0 )
{
- if ( isFirst )
- {
- isFirst = false;
- }
- else
+ bytes = null;
+ normName = "";
+ }
+ else
+ {
+ StringBuffer sb = new StringBuffer();
+ boolean isFirst = true;
+
+ for ( Rdn rdn : rdns )
{
- sb.append( ',' );
- }
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
+ {
+ sb.append( ',' );
+ }
- sb.append( rdn.getNormName() );
- }
+ sb.append( rdn.getNormName() );
+ }
- String newNormName = sb.toString();
+ String newNormName = sb.toString();
- if ( ( normName == null ) || !normName.equals( newNormName ) )
- {
- bytes = Strings.getBytesUtf8( newNormName );
- normName = newNormName;
+ if ( ( normName == null ) || !normName.equals( newNormName ) )
+ {
+ bytes = Strings.getBytesUtf8Ascii( newNormName );
+ normName = newNormName;
+ }
}
}
}
@@ -1260,6 +1264,26 @@ public class Dn implements Iterable<Rdn>
/**
+ * Normalizes the Dn using the given the schema manager, unless the Dn is already normalized
+ *
+ * @param schemaManager The schemaManagerto use to normalize the Dn
+ * @return The normalized Dn
+ * @throws LdapInvalidDnException If the Dn is invalid.
+ */
+ public Dn apply( SchemaManager schemaManager ) throws LdapInvalidDnException
+ {
+ if ( this.schemaManager != null )
+ {
+ return this;
+ }
+ else
+ {
+ return apply( schemaManager, true );
+ }
+ }
+
+
+ /**
* Tells if the Dn is schema aware
*
* @return <code>true</code> if the Dn is schema aware.
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/comparators/UuidComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/comparators/UuidComparator.java?rev=1389183&r1=1389182&r2=1389183&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/comparators/UuidComparator.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/comparators/UuidComparator.java Mon Sep 24 02:13:15 2012
@@ -20,7 +20,8 @@
package org.apache.directory.shared.ldap.model.schema.comparators;
-import org.apache.directory.shared.ldap.model.schema.LdapComparator;
+import java.util.UUID;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,13 +31,16 @@ import org.slf4j.LoggerFactory;
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class UuidComparator extends LdapComparator<String>
+public class UuidComparator extends SerializableComparator<String>
{
/** The serial version UID */
private static final long serialVersionUID = 2L;
/** A logger for this class */
private static final Logger LOG = LoggerFactory.getLogger( UuidComparator.class );
+ private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ public static UuidComparator INSTANCE = new UuidComparator( "1.3.6.1.1.16.4" );
/**
@@ -54,7 +58,37 @@ public class UuidComparator extends Ldap
*/
public int compare( String uuid1, String uuid2 )
{
- LOG.debug( "comparing UUID objects '{}' with '{}'", uuid1, uuid2 );
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "comparing UUID objects '{}' with '{}'", uuid1, uuid2 );
+ }
+
+ // -------------------------------------------------------------------
+ // Handle some basis cases
+ // -------------------------------------------------------------------
+ if ( uuid1 == null )
+ {
+ return ( uuid2 == null ) ? 0 : -1;
+ }
+
+ if ( uuid2 == null )
+ {
+ return 1;
+ }
+
+ return uuid1.compareTo( uuid2 );
+ }
+
+
+ /**
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare( UUID uuid1, UUID uuid2 )
+ {
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "comparing UUID objects '{}' with '{}'", uuid1, uuid2 );
+ }
// -------------------------------------------------------------------
// Handle some basis cases
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/syntaxCheckers/UuidSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/syntaxCheckers/UuidSyntaxChecker.java?rev=1389183&r1=1389182&r2=1389183&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/syntaxCheckers/UuidSyntaxChecker.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/syntaxCheckers/UuidSyntaxChecker.java Mon Sep 24 02:13:15 2012
@@ -20,6 +20,8 @@
package org.apache.directory.shared.ldap.model.schema.syntaxCheckers;
+import java.util.UUID;
+
import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
import org.apache.directory.shared.ldap.model.schema.SyntaxChecker;
import org.apache.directory.shared.util.Strings;
@@ -61,6 +63,11 @@ public class UuidSyntaxChecker extends S
return false;
}
+ if ( value instanceof UUID )
+ {
+ return true;
+ }
+
if ( !( value instanceof String ) )
{
LOG.debug( "Syntax invalid for '{}'", value );
Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/message/LdapResultImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/message/LdapResultImplTest.java?rev=1389183&r1=1389182&r2=1389183&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/message/LdapResultImplTest.java (original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/message/LdapResultImplTest.java Mon Sep 24 02:13:15 2012
@@ -140,6 +140,12 @@ public class LdapResultImplTest
public void setReferral( Referral referral )
{
}
+
+
+ public boolean isDefaultSuccess()
+ {
+ return false;
+ }
};
assertTrue( "r0 equals should see other impl r1 as equal", r0.equals( r1 ) );
Added: directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou=schema/cn=adsconfig/ou=attributetypes/m-oid=1.3.6.1.4.1.18060.0.4.1.2.165.ldif
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou%3Dschema/cn%3Dadsconfig/ou%3Dattributetypes/m-oid%3D1.3.6.1.4.1.18060.0.4.1.2.165.ldif?rev=1389183&view=auto
==============================================================================
--- directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou=schema/cn=adsconfig/ou=attributetypes/m-oid=1.3.6.1.4.1.18060.0.4.1.2.165.ldif (added)
+++ directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou=schema/cn=adsconfig/ou=attributetypes/m-oid=1.3.6.1.4.1.18060.0.4.1.2.165.ldif Mon Sep 24 02:13:15 2012
@@ -0,0 +1,12 @@
+version: 1
+dn: m-oid=1.3.6.1.4.1.18060.0.4.1.2.165,ou=attributeTypes,cn=adsconfig,ou=schema
+m-singlevalue: TRUE
+m-oid: 1.3.6.1.4.1.18060.0.4.1.2.165
+m-description: A flag telling if the index has a reverse table
+objectclass: top
+objectclass: metaTop
+objectclass: metaAttributeType
+m-syntax: 1.3.6.1.4.1.1466.115.121.1.7
+m-name: ads-indexHasReverse
+creatorsname: uid=admin,ou=system
+m-equality: booleanMatch
Modified: directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou=schema/cn=adsconfig/ou=objectclasses/m-oid=1.3.6.1.4.1.18060.0.4.1.3.160.ldif
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou%3Dschema/cn%3Dadsconfig/ou%3Dobjectclasses/m-oid%3D1.3.6.1.4.1.18060.0.4.1.3.160.ldif?rev=1389183&r1=1389182&r2=1389183&view=diff
==============================================================================
--- directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou=schema/cn=adsconfig/ou=objectclasses/m-oid=1.3.6.1.4.1.18060.0.4.1.3.160.ldif (original)
+++ directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou=schema/cn=adsconfig/ou=objectclasses/m-oid=1.3.6.1.4.1.18060.0.4.1.3.160.ldif Mon Sep 24 02:13:15 2012
@@ -1,6 +1,7 @@
version: 1
dn: m-oid=1.3.6.1.4.1.18060.0.4.1.3.160,ou=objectClasses,cn=adsconfig,ou=schema
m-must: ads-indexAttributeId
+m-must: ads-indexHasReverse
m-oid: 1.3.6.1.4.1.18060.0.4.1.3.160
m-supobjectclass: ads-base
m-description: A generic indexed attribute
Modified: directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou=schema/cn=apache/ou=attributetypes/m-oid=1.3.6.1.4.1.18060.0.4.1.2.5.ldif
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou%3Dschema/cn%3Dapache/ou%3Dattributetypes/m-oid%3D1.3.6.1.4.1.18060.0.4.1.2.5.ldif?rev=1389183&r1=1389182&r2=1389183&view=diff
==============================================================================
--- directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou=schema/cn=apache/ou=attributetypes/m-oid=1.3.6.1.4.1.18060.0.4.1.2.5.ldif (original)
+++ directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou=schema/cn=apache/ou=attributetypes/m-oid=1.3.6.1.4.1.18060.0.4.1.2.5.ldif Mon Sep 24 02:13:15 2012
@@ -9,8 +9,8 @@ m-nousermodification: TRUE
objectclass: metaAttributeType
objectclass: metaTop
objectclass: top
-m-syntax: 1.3.6.1.4.1.1466.115.121.1.27
+m-syntax: 1.3.6.1.1.16.1
m-usage: DSA_OPERATION
m-name: apacheOneAlias
creatorsname: uid=admin,ou=system
-m-equality: integerMatch
+m-equality: uuidMatch
Modified: directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou=schema/cn=apache/ou=attributetypes/m-oid=1.3.6.1.4.1.18060.0.4.1.2.6.ldif
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou%3Dschema/cn%3Dapache/ou%3Dattributetypes/m-oid%3D1.3.6.1.4.1.18060.0.4.1.2.6.ldif?rev=1389183&r1=1389182&r2=1389183&view=diff
==============================================================================
--- directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou=schema/cn=apache/ou=attributetypes/m-oid=1.3.6.1.4.1.18060.0.4.1.2.6.ldif (original)
+++ directory/shared/trunk/ldap/schema/data/src/main/resources/schema/ou=schema/cn=apache/ou=attributetypes/m-oid=1.3.6.1.4.1.18060.0.4.1.2.6.ldif Mon Sep 24 02:13:15 2012
@@ -9,8 +9,8 @@ m-nousermodification: TRUE
objectclass: metaAttributeType
objectclass: metaTop
objectclass: top
-m-syntax: 1.3.6.1.4.1.1466.115.121.1.27
+m-syntax: 1.3.6.1.1.16.1
m-usage: DSA_OPERATION
m-name: apacheSubAlias
creatorsname: uid=admin,ou=system
-m-equality: integerMatch
+m-equality: uuidMatch
Modified: directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/shared/ldap/schemaloader/SchemaManagerEnableDisableLoadTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/shared/ldap/schemaloader/SchemaManagerEnableDisableLoadTest.java?rev=1389183&r1=1389182&r2=1389183&view=diff
==============================================================================
--- directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/shared/ldap/schemaloader/SchemaManagerEnableDisableLoadTest.java (original)
+++ directory/shared/trunk/ldap/schema/data/src/test/java/org/apache/directory/shared/ldap/schemaloader/SchemaManagerEnableDisableLoadTest.java Mon Sep 24 02:13:15 2012
@@ -156,14 +156,14 @@ public class SchemaManagerEnableDisableL
assertEquals( 0, disabled.size() );
assertTrue( schemaManager.getErrors().isEmpty() );
- assertEquals( 425, schemaManager.getAttributeTypeRegistry().size() );
+ assertEquals( 426, schemaManager.getAttributeTypeRegistry().size() );
assertEquals( 48, schemaManager.getComparatorRegistry().size() );
assertEquals( 48, schemaManager.getMatchingRuleRegistry().size() );
assertEquals( 48, schemaManager.getNormalizerRegistry().size() );
assertEquals( 120, schemaManager.getObjectClassRegistry().size() );
assertEquals( 68, schemaManager.getSyntaxCheckerRegistry().size() );
assertEquals( 73, schemaManager.getLdapSyntaxRegistry().size() );
- assertEquals( 666, schemaManager.getGlobalOidRegistry().size() );
+ assertEquals( 667, schemaManager.getGlobalOidRegistry().size() );
assertEquals( 12, schemaManager.getRegistries().getLoadedSchemas().size() );
assertNull( schemaManager.getRegistries().getLoadedSchema( "nis" ) );
@@ -201,14 +201,14 @@ public class SchemaManagerEnableDisableL
assertNotNull( schemaManager.lookupAttributeTypeRegistry( "gecos" ) );
assertTrue( schemaManager.getErrors().isEmpty() );
- assertEquals( 452, schemaManager.getAttributeTypeRegistry().size() );
+ assertEquals( 453, schemaManager.getAttributeTypeRegistry().size() );
assertEquals( 49, schemaManager.getComparatorRegistry().size() );
assertEquals( 49, schemaManager.getMatchingRuleRegistry().size() );
assertEquals( 49, schemaManager.getNormalizerRegistry().size() );
assertEquals( 133, schemaManager.getObjectClassRegistry().size() );
assertEquals( 70, schemaManager.getSyntaxCheckerRegistry().size() );
assertEquals( 75, schemaManager.getLdapSyntaxRegistry().size() );
- assertEquals( 709, schemaManager.getGlobalOidRegistry().size() );
+ assertEquals( 710, schemaManager.getGlobalOidRegistry().size() );
assertEquals( 13, schemaManager.getRegistries().getLoadedSchemas().size() );
assertNotNull( schemaManager.getRegistries().getLoadedSchema( "nis" ) );
@@ -241,14 +241,14 @@ public class SchemaManagerEnableDisableL
}
assertTrue( schemaManager.getErrors().isEmpty() );
- assertEquals( 425, schemaManager.getAttributeTypeRegistry().size() );
+ assertEquals( 426, schemaManager.getAttributeTypeRegistry().size() );
assertEquals( 48, schemaManager.getComparatorRegistry().size() );
assertEquals( 48, schemaManager.getMatchingRuleRegistry().size() );
assertEquals( 48, schemaManager.getNormalizerRegistry().size() );
assertEquals( 120, schemaManager.getObjectClassRegistry().size() );
assertEquals( 68, schemaManager.getSyntaxCheckerRegistry().size() );
assertEquals( 73, schemaManager.getLdapSyntaxRegistry().size() );
- assertEquals( 666, schemaManager.getGlobalOidRegistry().size() );
+ assertEquals( 667, schemaManager.getGlobalOidRegistry().size() );
assertEquals( 12, schemaManager.getRegistries().getLoadedSchemas().size() );
assertNull( schemaManager.getRegistries().getLoadedSchema( "nis" ) );
@@ -293,14 +293,14 @@ public class SchemaManagerEnableDisableL
assertNotNull( schemaManager.lookupAttributeTypeRegistry( "gecos" ) );
assertTrue( schemaManager.getErrors().isEmpty() );
- assertEquals( 499, schemaManager.getAttributeTypeRegistry().size() );
+ assertEquals( 500, schemaManager.getAttributeTypeRegistry().size() );
assertEquals( 49, schemaManager.getComparatorRegistry().size() );
assertEquals( 49, schemaManager.getMatchingRuleRegistry().size() );
assertEquals( 49, schemaManager.getNormalizerRegistry().size() );
assertEquals( 144, schemaManager.getObjectClassRegistry().size() );
assertEquals( 70, schemaManager.getSyntaxCheckerRegistry().size() );
assertEquals( 75, schemaManager.getLdapSyntaxRegistry().size() );
- assertEquals( 767, schemaManager.getGlobalOidRegistry().size() );
+ assertEquals( 768, schemaManager.getGlobalOidRegistry().size() );
assertEquals( 14, schemaManager.getRegistries().getLoadedSchemas().size() );
assertNotNull( schemaManager.getRegistries().getLoadedSchema( "samba" ) );
Modified: directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java?rev=1389183&r1=1389182&r2=1389183&view=diff
==============================================================================
--- directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java (original)
+++ directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java Mon Sep 24 02:13:15 2012
@@ -34,6 +34,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
import org.apache.directory.shared.i18n.I18n;
import org.slf4j.Logger;
@@ -250,6 +251,9 @@ public final class Strings
0, 0, 0, 0, 0, 0, 0, 0
};
+ /** A empty byte array */
+ public static final byte[] EMPTY_BYTES = new byte[0];
+
/**
* Private constructor
@@ -733,6 +737,16 @@ public final class Strings
}
}
+ private static final byte[] UTF8 = new byte[]
+ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
+ 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C,
+ 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E,
+ 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40,
+ 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52,
+ 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64,
+ 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
+ 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F };
+
/**
* Return an UTF-8 encoded String
@@ -747,15 +761,30 @@ public final class Strings
return "";
}
+ char[] chars = new char[bytes.length];
+ int pos = 0;
+
try
{
- return new String( bytes, "UTF-8" );
+ for ( byte b : bytes )
+ {
+ chars[pos++] = ( char ) UTF8[b];
+ }
}
- catch ( UnsupportedEncodingException uee )
+ catch ( ArrayIndexOutOfBoundsException aioobe )
{
- // if this happens something is really strange
- throw new RuntimeException( uee );
+ try
+ {
+ return new String( bytes, "UTF-8" );
+ }
+ catch ( UnsupportedEncodingException uee )
+ {
+ // if this happens something is really strange
+ throw new RuntimeException( uee );
+ }
}
+
+ return new String( chars );
}
@@ -1550,7 +1579,7 @@ public final class Strings
{
if ( string == null )
{
- return new byte[0];
+ return EMPTY_BYTES;
}
try
@@ -1566,6 +1595,48 @@ public final class Strings
/**
+ * When the string to convert to bytes is pure ascii, ths is a faster
+ * method than the getBytesUtf8. Otherwis, it's slower.
+ *
+ * @param string The string to convert to byte[]
+ * @return The bytes
+ */
+ public static byte[] getBytesUtf8Ascii( String string )
+ {
+ if ( string == null )
+ {
+ return new byte[0];
+ }
+
+ try
+ {
+ try
+ {
+ char[] chars = string.toCharArray();
+ byte[] bytes = new byte[chars.length];
+ int pos = 0;
+
+ for ( char c : chars )
+ {
+ bytes[pos++] = UTF8[c];
+ }
+
+ return bytes;
+ }
+ catch ( ArrayIndexOutOfBoundsException aioobe )
+ {
+ return string.getBytes( "UTF-8" );
+ }
+ }
+ catch ( UnsupportedEncodingException uee )
+ {
+ // if this happens something is really strange
+ throw new RuntimeException( uee );
+ }
+ }
+
+
+ /**
* Get the default charset
*
* @return The default charset
@@ -2183,4 +2254,16 @@ public final class Strings
{
return getString( data, 0, data.length, charset );
}
+
+
+ /**
+ * Create a new UUID using a long as the least significant bits
+ *
+ * @param value The least significant bits.
+ * @return
+ */
+ public static String getUUID( long value )
+ {
+ return new UUID( 0, value ).toString();
+ }
}