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 2010/01/06 19:27:19 UTC
svn commit: r896599 [3/30] - in /directory/apacheds/trunk: ./ avl-partition/
avl-partition/src/ avl-partition/src/main/ avl-partition/src/main/java/
avl-partition/src/main/java/org/ avl-partition/src/main/java/org/apache/
avl-partition/src/main/java/or...
Modified: directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java (original)
+++ directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java Wed Jan 6 18:26:43 2010
@@ -32,6 +32,7 @@
import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.LdapComparator;
import org.apache.directory.shared.ldap.schema.MatchingRule;
import org.apache.directory.shared.ldap.schema.Normalizer;
import org.apache.directory.shared.ldap.schema.comparators.ByteArrayComparator;
@@ -53,7 +54,7 @@
{
/** Used for serialization */
private static final long serialVersionUID = 2L;
-
+
/** logger for reporting errors that might not be handled properly upstream */
private static final Logger LOG = LoggerFactory.getLogger( ServerBinaryValue.class );
@@ -73,38 +74,31 @@
*/
protected String logAssert( String message )
{
- LOG.error( message );
+ LOG.error( message );
return message;
}
-
+
/**
* Check the attributeType member. It should not be null,
* and it should contains a syntax.
*/
protected String checkAttributeType( AttributeType attributeType )
{
- try
+ if ( attributeType == null )
{
- if ( attributeType == null )
- {
- return "The AttributeType parameter should not be null";
- }
-
- if ( attributeType.getSyntax() == null )
- {
- return "There is no Syntax associated with this attributeType";
- }
-
- return null;
+ return "The AttributeType parameter should not be null";
}
- catch ( NamingException ne )
+
+ if ( attributeType.getSyntax() == null )
{
- return "This AttributeType is incorrect";
+ return "There is no Syntax associated with this attributeType";
}
+
+ return null;
}
-
+
// -----------------------------------------------------------------------
// Constructors
// -----------------------------------------------------------------------
@@ -116,27 +110,20 @@
public ServerBinaryValue( AttributeType attributeType )
{
super();
-
+
if ( attributeType == null )
{
throw new IllegalArgumentException( "The AttributeType parameter should not be null" );
}
- try
+ if ( attributeType.getSyntax() == null )
{
- if ( attributeType.getSyntax() == null )
- {
- throw new IllegalArgumentException( "There is no Syntax associated with this attributeType" );
- }
-
- if ( attributeType.getSyntax().isHumanReadable() )
- {
- LOG.warn( "Treating a value of a human readible attribute {} as binary: ", attributeType.getName() );
- }
+ throw new IllegalArgumentException( "There is no Syntax associated with this attributeType" );
}
- catch( NamingException e )
+
+ if ( attributeType.getSyntax().isHumanReadable() )
{
- LOG.error( "Failed to resolve syntax for attributeType {}", attributeType, e );
+ LOG.warn( "Treating a value of a human readible attribute {} as binary: ", attributeType.getName() );
}
this.attributeType = attributeType;
@@ -164,7 +151,7 @@
* @param wrapped the value to wrap which can be null
* @param normalizedValue the normalized value
*/
- /** No protection */
+ /** No protection */
ServerBinaryValue( AttributeType attributeType, byte[] wrapped, byte[] normalizedValue, boolean same, boolean valid )
{
super( wrapped );
@@ -172,7 +159,7 @@
this.attributeType = attributeType;
this.normalizedValue = normalizedValue;
this.valid = valid;
- this.same = same;
+ this.same = same;
//this.oid = attributeType.getOid();
}
@@ -187,11 +174,11 @@
// Bypass the normalization if it has already been done.
return;
}
-
+
if ( wrapped != null )
{
Normalizer normalizer = getNormalizer();
-
+
if ( normalizer == null )
{
normalizedValue = wrapped;
@@ -213,9 +200,9 @@
}
}
-
+
/**
- * Gets the normalized (cannonical) representation for the wrapped string.
+ * Gets the normalized (canonical) representation for the wrapped string.
* If the wrapped String is null, null is returned, otherwise the normalized
* form is returned. If no the normalizedValue is null, then this method
* will attempt to generate it from the wrapped value: repeated calls to
@@ -259,7 +246,7 @@
*
* @return gets the normalized value
*/
- public byte[] getNormalizedValue()
+ public byte[] getNormalizedValue()
{
if ( isNull() )
{
@@ -315,7 +302,7 @@
if ( normalizedValue != null )
{
- byte[] copy = new byte[ normalizedValue.length ];
+ byte[] copy = new byte[normalizedValue.length];
System.arraycopy( normalizedValue, 0, copy, 0, normalizedValue.length );
return copy;
}
@@ -342,20 +329,11 @@
return valid;
}
- try
- {
- valid = attributeType.getSyntax().getSyntaxChecker().isValidSyntax( getReference() );
- }
- catch ( NamingException ne )
- {
- String message = "Cannot check the syntax : " + ne.getMessage();
- LOG.error( message );
- valid = false;
- }
-
+ valid = attributeType.getSyntax().getSyntaxChecker().isValidSyntax( getReference() );
+
return valid;
}
-
+
/**
*
@@ -378,7 +356,7 @@
}
else
{
- if ( ( value == null ) || value.isNull() )
+ if ( ( value == null ) || value.isNull() )
{
return 1;
}
@@ -390,29 +368,30 @@
try
{
- Comparator<? super Value<byte[]>> comparator = getComparator();
-
+ Comparator<? super byte[]> comparator = getLdapComparator();
+
if ( comparator != null )
{
- return getComparator().compare( getNormalizedValueReference(), binaryValue.getNormalizedValueReference() );
+ return comparator
+ .compare( getNormalizedValueReference(), binaryValue.getNormalizedValueReference() );
}
else
{
- return ByteArrayComparator.INSTANCE.compare( getNormalizedValueReference(),
- binaryValue.getNormalizedValueReference() );
+ return new ByteArrayComparator( null ).compare( getNormalizedValueReference(), binaryValue
+ .getNormalizedValueReference() );
}
}
catch ( NamingException e )
{
- String msg = "Failed to compare normalized values for " + Arrays.toString( getReference() )
- + " and " + value;
+ String msg = "Failed to compare normalized values for " + Arrays.toString( getReference() ) + " and "
+ + value;
LOG.error( msg, e );
throw new IllegalStateException( msg, e );
}
}
- String message = "I don't really know how to compare anything other " +
- "than ServerBinaryValues at this point in time.";
+ String message = "I don't really know how to compare anything other "
+ + "than ServerBinaryValues at this point in time.";
LOG.error( message );
throw new NotImplementedException( message );
}
@@ -485,18 +464,18 @@
return true;
}
- if ( ! ( obj instanceof ServerBinaryValue ) )
+ if ( !( obj instanceof ServerBinaryValue ) )
{
return false;
}
ServerBinaryValue other = ( ServerBinaryValue ) obj;
-
+
if ( !attributeType.equals( other.attributeType ) )
{
return false;
}
-
+
if ( isNull() )
{
return other.isNull();
@@ -512,7 +491,7 @@
{
try
{
- Comparator<byte[]> comparator = getComparator();
+ LdapComparator<? super byte[]> comparator = getLdapComparator();
// Compare normalized values
if ( comparator == null )
@@ -555,7 +534,7 @@
if ( mr == null )
{
- mr = attributeType.getSubstr();
+ mr = attributeType.getSubstring();
}
return mr;
@@ -589,7 +568,7 @@
* @return a comparator associated with the attributeType or null if one cannot be found
* @throws NamingException if resolution of schema entities fail
*/
- private Comparator getComparator() throws NamingException
+ private LdapComparator<? super Object> getLdapComparator() throws NamingException
{
MatchingRule mr = getMatchingRule();
@@ -598,23 +577,23 @@
return null;
}
- return mr.getComparator();
+ return mr.getLdapComparator();
}
-
-
+
+
/**
* @return a copy of the current value
*/
public ServerBinaryValue clone()
{
- ServerBinaryValue clone = (ServerBinaryValue)super.clone();
-
+ ServerBinaryValue clone = ( ServerBinaryValue ) super.clone();
+
if ( normalizedValue != null )
{
- clone.normalizedValue = new byte[ normalizedValue.length ];
+ clone.normalizedValue = new byte[normalizedValue.length];
System.arraycopy( normalizedValue, 0, clone.normalizedValue, 0, normalizedValue.length );
}
-
+
return clone;
}
@@ -624,13 +603,13 @@
*
* We can't use this method for a ServerBinaryValue, as we have to feed the value
* with an AttributeType object
- */
+ */
public void writeExternal( ObjectOutput out ) throws IOException
{
throw new IllegalStateException( "Cannot use standard serialization for a ServerStringValue" );
}
-
-
+
+
/**
* We will write the value and the normalized value, only
* if the normalized value is different.
@@ -655,18 +634,18 @@
{
// write a the wrapped length
out.writeInt( wrapped.length );
-
+
// Write the data if not empty
if ( wrapped.length > 0 )
{
// The data
out.write( wrapped );
-
+
// Normalize the data
try
{
normalize();
-
+
if ( !normalized )
{
// We may not have a normalizer. Just get out
@@ -677,7 +656,7 @@
{
// Write a flag indicating that the data has been normalized
out.writeBoolean( true );
-
+
if ( Arrays.equals( getReference(), normalizedValue ) )
{
// Write the 'same = true' flag
@@ -687,10 +666,10 @@
{
// Write the 'same = false' flag
out.writeBoolean( false );
-
+
// Write the normalized value length
- out.write( normalizedValue.length );
-
+ out.writeInt( normalizedValue.length );
+
if ( normalizedValue.length > 0 )
{
// Write the normalized value if not empty
@@ -715,7 +694,7 @@
}
}
-
+
/**
* @see Externalizable#readExternal(ObjectInput)
*
@@ -726,7 +705,7 @@
{
throw new IllegalStateException( "Cannot use standard serialization for a ServerStringValue" );
}
-
+
/**
*
@@ -740,7 +719,7 @@
{
// The UP value length
int wrappedLength = in.readInt();
-
+
if ( wrappedLength == -1 )
{
// If the value is null, the length will be set to -1
@@ -749,35 +728,35 @@
}
else if ( wrappedLength == 0 )
{
- wrapped = StringTools.EMPTY_BYTES;
- same = true;
- normalized = true;
- normalizedValue = wrapped;
+ wrapped = StringTools.EMPTY_BYTES;
+ same = true;
+ normalized = true;
+ normalizedValue = wrapped;
}
else
{
wrapped = new byte[wrappedLength];
-
+
// Read the data
in.readFully( wrapped );
-
+
// Check if we have a normalized value
normalized = in.readBoolean();
-
+
if ( normalized )
{
// Read the 'same' flag
same = in.readBoolean();
-
+
if ( !same )
{
// Read the normalizedvalue length
int normalizedLength = in.readInt();
-
+
if ( normalizedLength > 0 )
{
normalizedValue = new byte[normalizedLength];
-
+
// Read the normalized value
in.read( normalizedValue, 0, normalizedLength );
}
@@ -794,4 +773,4 @@
}
}
}
-}
+}
Modified: directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntrySerializer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntrySerializer.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntrySerializer.java (original)
+++ directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntrySerializer.java Wed Jan 6 18:26:43 2010
@@ -25,12 +25,12 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import org.apache.directory.server.schema.registries.Registries;
+import jdbm.helper.Serializer;
+
+import org.apache.directory.shared.ldap.schema.SchemaManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import jdbm.helper.Serializer;
-
/**
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
@@ -48,18 +48,18 @@
*/
private static final boolean IS_DEBUG = LOG.isDebugEnabled();
- /** The registries reference */
- private transient Registries registries;
+ /** The schemaManager reference */
+ private transient SchemaManager schemaManager;
/**
* Creates a new instance of ServerEntrySerializer.
*
- * @param registries The reference to the global registries
+ * @param schemaManager The reference to the global schemaManager
*/
- public ServerEntrySerializer( Registries registries )
+ public ServerEntrySerializer( SchemaManager schemaManager )
{
- this.registries = registries;
+ this.schemaManager = schemaManager;
}
@@ -144,7 +144,7 @@
{
ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( bytes ) );
- DefaultServerEntry serverEntry = new DefaultServerEntry( registries );
+ DefaultServerEntry serverEntry = new DefaultServerEntry( schemaManager );
try
{
Modified: directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java (original)
+++ directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java Wed Jan 6 18:26:43 2010
@@ -35,15 +35,15 @@
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchResult;
-import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
-import org.apache.directory.server.schema.registries.Registries;
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.entry.Modification;
import org.apache.directory.shared.ldap.entry.ModificationOperation;
import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeIdentifierException;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
import org.apache.directory.shared.ldap.schema.SchemaUtils;
import org.apache.directory.shared.ldap.util.EmptyEnumeration;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -195,14 +195,14 @@
*
* @throws InvalidAttributeIdentifierException If we get an invalid attribute
*/
- public static ServerEntry toServerEntry( Attributes attributes, LdapDN dn, Registries registries )
+ public static ServerEntry toServerEntry( Attributes attributes, LdapDN dn, SchemaManager schemaManager )
throws InvalidAttributeIdentifierException
{
if ( attributes instanceof BasicAttributes )
{
try
{
- ServerEntry entry = new DefaultServerEntry( registries, dn );
+ ServerEntry entry = new DefaultServerEntry( schemaManager, dn );
for ( NamingEnumeration<? extends Attribute> attrs = attributes.getAll(); attrs.hasMoreElements(); )
{
@@ -212,7 +212,7 @@
String id = SchemaUtils.stripOptions( attributeId );
Set<String> options = SchemaUtils.getOptions( attributeId );
// TODO : handle options.
- AttributeType attributeType = registries.getAttributeTypeRegistry().lookup( id );
+ AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
ServerAttribute serverAttribute = ServerEntryUtils.toServerAttribute( attr, attributeType );
if ( serverAttribute != null )
@@ -244,12 +244,12 @@
* @return the resultant entry after the modification has taken place
* @throws NamingException if there are problems accessing attributes
*/
- public static ServerEntry getTargetEntry( Modification mod, ServerEntry entry, Registries registries ) throws NamingException
+ public static ServerEntry getTargetEntry( Modification mod, ServerEntry entry, SchemaManager schemaManager ) throws NamingException
{
ServerEntry targetEntry = ( ServerEntry ) entry.clone();
ModificationOperation modOp = mod.getOperation();
String id = mod.getAttribute().getId();
- AttributeType attributeType = registries.getAttributeTypeRegistry().lookup( id );
+ AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
switch ( modOp )
{
@@ -397,7 +397,7 @@
* @throws NamingException
*/
public static List<Modification> convertToServerModification( List<ModificationItem> modificationItems,
- AttributeTypeRegistry atRegistry ) throws NamingException
+ SchemaManager schemaManager ) throws NamingException
{
if ( modificationItems != null )
{
@@ -405,7 +405,7 @@
for ( ModificationItem modificationItem: modificationItems )
{
- AttributeType attributeType = atRegistry.lookup( modificationItem.getAttribute().getID() );
+ AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( modificationItem.getAttribute().getID() );
modifications.add( toServerModification( modificationItem, attributeType ) );
}
@@ -442,7 +442,7 @@
public static List<Modification> toServerModification( Modification[] modifications,
- AttributeTypeRegistry atRegistry ) throws NamingException
+ SchemaManager schemaManager ) throws NamingException
{
if ( modifications != null )
{
@@ -459,25 +459,21 @@
// DIRSERVER-646 Fix: Replacing an unknown attribute with no values
// (deletion) causes an error
// -------------------------------------------------------------------
-
- // TODO - after removing JNDI we need to make the server handle
- // this in the codec
-
- if ( ! atRegistry.hasAttributeType( id )
+ if ( ! schemaManager.getAttributeTypeRegistry().contains( id )
&& modification.getAttribute().size() == 0
&& modification.getOperation() == ModificationOperation.REPLACE_ATTRIBUTE )
{
- continue;
+ // The attributeType does not exist in the schema.
+ // It's an error
+ String message = "The AttributeType '" + id + "' does not exist in the schema";
+ throw new LdapInvalidAttributeIdentifierException( message );
+ }
+ else
+ {
+ // TODO : handle options
+ AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
+ modificationsList.add( toServerModification( modification, attributeType ) );
}
-
- // -------------------------------------------------------------------
- // END DIRSERVER-646 Fix
- // -------------------------------------------------------------------
-
-
- // TODO : handle options
- AttributeType attributeType = atRegistry.lookup( id );
- modificationsList.add( toServerModification( modification, attributeType ) );
}
return modificationsList;
@@ -490,7 +486,7 @@
public static List<Modification> toServerModification( ModificationItem[] modifications,
- AttributeTypeRegistry atRegistry ) throws NamingException
+ SchemaManager schemaManager ) throws NamingException
{
if ( modifications != null )
{
@@ -510,7 +506,7 @@
// TODO - after removing JNDI we need to make the server handle
// this in the codec
- if ( ! atRegistry.hasAttributeType( id )
+ if ( ! schemaManager.getAttributeTypeRegistry().contains( id )
&& modification.getAttribute().size() == 0
&& modification.getModificationOp() == DirContext.REPLACE_ATTRIBUTE )
{
@@ -523,7 +519,7 @@
// TODO : handle options
- AttributeType attributeType = atRegistry.lookup( id );
+ AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
modificationsList.add( toServerModification( (ModificationItem)modification, attributeType ) );
}
@@ -616,7 +612,7 @@
ServerSearchResult rec = result.next();
SearchResult searchResult = new SearchResult(
- rec.getDn().getUpName(),
+ rec.getDn().getName(),
rec.getObject(),
toBasicAttributes( rec.getServerEntry() ),
rec.isRelative() );
@@ -644,7 +640,7 @@
ServerSearchResult rec = result.next();
SearchResult searchResult = new SearchResult(
- rec.getDn().getUpName(),
+ rec.getDn().getName(),
rec.getObject(),
toBasicAttributes( rec.getServerEntry() ),
rec.isRelative() );
Modified: directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerModification.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerModification.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerModification.java (original)
+++ directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerModification.java Wed Jan 6 18:26:43 2010
@@ -24,15 +24,13 @@
import java.io.ObjectOutput;
import javax.naming.NamingException;
-//import javax.naming.directory.DirContext;
-import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
-import org.apache.directory.server.schema.registries.Registries;
import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.entry.Modification;
import org.apache.directory.shared.ldap.entry.ModificationOperation;
import org.apache.directory.shared.ldap.entry.client.ClientModification;
import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -81,7 +79,7 @@
}
- public ServerModification( Registries registries, Modification modification )
+ public ServerModification( SchemaManager schemaManager, Modification modification )
{
operation = modification.getOperation();
@@ -97,7 +95,7 @@
}
else
{
- at = registries.getAttributeTypeRegistry().lookup( modAttribute.getId() );
+ at = schemaManager.lookupAttributeTypeRegistry( modAttribute.getId() );
}
attribute = new DefaultServerAttribute( at, modAttribute );
@@ -278,7 +276,7 @@
* @throws ClassNotFoundException if we weren't able to construct a Modification instance
* @throws NamingException If we didn't found the AttributeType in the registries
*/
- public void deserialize( ObjectInput in, AttributeTypeRegistry atRegistry ) throws IOException, ClassNotFoundException, NamingException
+ public void deserialize( ObjectInput in, SchemaManager schemaManager ) throws IOException, ClassNotFoundException, NamingException
{
// Read the operation
int op = in.readInt();
@@ -289,7 +287,7 @@
String oid = in.readUTF();
// Lookup for tha associated AttributeType
- AttributeType attributeType = atRegistry.lookup( oid );
+ AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( oid );
attribute = new DefaultServerAttribute( attributeType );
Modified: directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerSearchResult.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerSearchResult.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerSearchResult.java (original)
+++ directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerSearchResult.java Wed Jan 6 18:26:43 2010
@@ -131,7 +131,7 @@
*/
public String toString()
{
- String name = (dn == null ? "null" : ( dn == LdapDN.EMPTY_LDAPDN ? "\"\"" : dn.getUpName() ) );
+ String name = (dn == null ? "null" : ( dn == LdapDN.EMPTY_LDAPDN ? "\"\"" : dn.getName() ) );
return "ServerSearchResult : " + name + "\n" + serverEntry;
}
}
Modified: directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java (original)
+++ directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java Wed Jan 6 18:26:43 2010
@@ -23,7 +23,6 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import java.util.Comparator;
import javax.naming.NamingException;
@@ -31,6 +30,7 @@
import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.LdapComparator;
import org.apache.directory.shared.ldap.schema.MatchingRule;
import org.apache.directory.shared.ldap.schema.Normalizer;
import org.slf4j.Logger;
@@ -77,24 +77,17 @@
*/
protected String checkAttributeType( AttributeType attributeType )
{
- try
+ if ( attributeType == null )
{
- if ( attributeType == null )
- {
- return "The AttributeType parameter should not be null";
- }
-
- if ( attributeType.getSyntax() == null )
- {
- return "There is no Syntax associated with this attributeType";
- }
-
- return null;
+ return "The AttributeType parameter should not be null";
}
- catch ( NamingException ne )
+
+ if ( attributeType.getSyntax() == null )
{
- return "This AttributeType is incorrect";
+ return "There is no Syntax associated with this attributeType";
}
+
+ return null;
}
@@ -115,22 +108,15 @@
throw new IllegalArgumentException( "The AttributeType parameter should not be null" );
}
- try
+ if ( attributeType.getSyntax() == null )
{
- if ( attributeType.getSyntax() == null )
- {
- throw new IllegalArgumentException( "There is no Syntax associated with this attributeType" );
- }
-
- if ( ! attributeType.getSyntax().isHumanReadable() )
- {
- LOG.warn( "Treating a value of a binary attribute {} as a String: " +
- "\nthis could cause data corruption!", attributeType.getName() );
- }
+ throw new IllegalArgumentException( "There is no Syntax associated with this attributeType" );
}
- catch( NamingException e )
+
+ if ( ! attributeType.getSyntax().isHumanReadable() )
{
- LOG.error( "Failed to resolve syntax for attributeType {}", attributeType, e );
+ LOG.warn( "Treating a value of a binary attribute {} as a String: " +
+ "\nthis could cause data corruption!", attributeType.getName() );
}
this.attributeType = attributeType;
@@ -269,16 +255,7 @@
return valid;
}
- try
- {
- valid = attributeType.getSyntax().getSyntaxChecker().isValidSyntax( get() );
- }
- catch ( NamingException ne )
- {
- String message = "Cannot check the syntax : " + ne.getMessage();
- LOG.error( message );
- valid = false;
- }
+ valid = attributeType.getSyntax().getSyntaxChecker().isValidSyntax( get() );
return valid;
}
@@ -336,7 +313,7 @@
try
{
//noinspection unchecked
- return getComparator().compare( getNormalizedValue(), stringValue.getNormalizedValue() );
+ return getLdapComparator().compare( getNormalizedValue(), stringValue.getNormalizedValue() );
}
catch ( NamingException e )
{
@@ -436,7 +413,7 @@
{
try
{
- Comparator<String> comparator = getComparator();
+ LdapComparator<? super Object> comparator = getLdapComparator();
// Compare normalized values
if ( comparator == null )
@@ -445,7 +422,15 @@
}
else
{
- return comparator.compare( getNormalizedValue(), other.getNormalizedValue() ) == 0;
+ if ( isNormalized() )
+ {
+ return comparator.compare( getNormalizedValue(), other.getNormalizedValue() ) == 0;
+ }
+ else
+ {
+ Normalizer normalizer = attributeType.getEquality().getNormalizer();
+ return comparator.compare( normalizer.normalize( get() ), normalizer.normalize( other.get() ) ) == 0;
+ }
}
}
catch ( NamingException ne )
@@ -481,7 +466,7 @@
if ( mr == null )
{
- mr = attributeType.getSubstr();
+ mr = attributeType.getSubstring();
}
return mr;
@@ -549,7 +534,7 @@
* @return a comparator associated with the attributeType or null if one cannot be found
* @throws NamingException if resolution of schema entities fail
*/
- private Comparator getComparator() throws NamingException
+ private LdapComparator<? super Object> getLdapComparator() throws NamingException
{
MatchingRule mr = getMatchingRule();
@@ -558,7 +543,7 @@
return null;
}
- return mr.getComparator();
+ return mr.getLdapComparator();
}
Modified: directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/TestServerEntryUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/TestServerEntryUtils.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/TestServerEntryUtils.java (original)
+++ directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/TestServerEntryUtils.java Wed Jan 6 18:26:43 2010
@@ -19,21 +19,16 @@
*/
package org.apache.directory.server.core.entry;
-import java.util.Comparator;
-
import javax.naming.NamingException;
-import javax.naming.directory.InvalidAttributeValueException;
import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
-import org.apache.directory.shared.ldap.schema.AbstractAttributeType;
-import org.apache.directory.shared.ldap.schema.AbstractMatchingRule;
-import org.apache.directory.shared.ldap.schema.AbstractSyntax;
import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.LdapComparator;
+import org.apache.directory.shared.ldap.schema.LdapSyntax;
import org.apache.directory.shared.ldap.schema.MatchingRule;
import org.apache.directory.shared.ldap.schema.Normalizer;
-import org.apache.directory.shared.ldap.schema.Syntax;
import org.apache.directory.shared.ldap.schema.SyntaxChecker;
import org.apache.directory.shared.ldap.schema.comparators.ByteArrayComparator;
import org.apache.directory.shared.ldap.schema.normalizers.DeepTrimToLowerNormalizer;
@@ -50,165 +45,66 @@
/**
* A local Syntax class for tests
*/
- static class AT extends AbstractAttributeType
+ static class AT extends AttributeType
{
private static final long serialVersionUID = 0L;
- AttributeType superior;
- Syntax syntax;
- MatchingRule equality;
- MatchingRule ordering;
- MatchingRule substr;
protected AT( String oid )
{
super( oid );
}
-
- public AttributeType getSuperior() throws NamingException
- {
- return superior;
- }
-
-
- public Syntax getSyntax() throws NamingException
- {
- return syntax;
- }
-
-
- public MatchingRule getEquality() throws NamingException
- {
- return equality;
- }
-
-
- public MatchingRule getOrdering() throws NamingException
- {
- return ordering;
- }
-
-
- public MatchingRule getSubstr() throws NamingException
- {
- return substr;
- }
-
-
- public void setSuperior( AttributeType superior )
- {
- this.superior = superior;
- }
-
-
- public void setSyntax( Syntax syntax )
- {
- this.syntax = syntax;
- }
-
-
- public void setEquality( MatchingRule equality )
- {
- this.equality = equality;
- }
-
-
- public void setOrdering( MatchingRule ordering )
- {
- this.ordering = ordering;
- }
-
-
- public void setSubstr( MatchingRule substr )
- {
- this.substr = substr;
- }
}
+ public static MatchingRule matchingRuleFactory( String oid )
+ {
+ MatchingRule matchingRule = new MatchingRule( oid );
+
+ return matchingRule;
+ }
/**
* A local MatchingRule class for tests
*/
- static class MR extends AbstractMatchingRule
+ static class MR extends MatchingRule
{
private static final long serialVersionUID = 0L;
- Syntax syntax;
- Comparator comparator;
- Normalizer normalizer;
protected MR( String oid )
{
super( oid );
}
-
- public Syntax getSyntax() throws NamingException
- {
- return syntax;
- }
-
- public Comparator getComparator() throws NamingException
- {
- return comparator;
- }
-
-
- public Normalizer getNormalizer() throws NamingException
- {
- return normalizer;
- }
-
-
- public void setSyntax( Syntax syntax )
- {
- this.syntax = syntax;
- }
-
-
- public void setComparator( Comparator<?> comparator )
- {
- this.comparator = comparator;
- }
-
-
- public void setNormalizer( Normalizer normalizer )
- {
- this.normalizer = normalizer;
- }
}
/**
* A local Syntax class used for the tests
*/
- static class S extends AbstractSyntax
+ public static LdapSyntax syntaxFactory( String oid, boolean humanReadable )
+ {
+ LdapSyntax ldapSyntax = new LdapSyntax( oid );
+
+ ldapSyntax.setHumanReadable( humanReadable );
+
+ return ldapSyntax;
+ }
+ static class S extends LdapSyntax
{
private static final long serialVersionUID = 0L;
- SyntaxChecker checker;
public S( String oid, boolean humanReadible )
{
- super( oid, humanReadible );
- }
-
- public void setSyntaxChecker( SyntaxChecker checker )
- {
- this.checker = checker;
- }
-
- public SyntaxChecker getSyntaxChecker() throws NamingException
- {
- return checker;
+ super( oid, "", humanReadible );
}
}
/* no protection*/ static AttributeType getCaseIgnoringAttributeNoNumbersType()
{
- S s = new S( "1.1.1.1", true );
+ AttributeType attributeType = new AttributeType( "1.1.3.1" );
+ LdapSyntax syntax = new LdapSyntax( "1.1.1.1", "", true );
- s.setSyntaxChecker( new SyntaxChecker()
+ syntax.setSyntaxChecker( new SyntaxChecker( "1.1.2.1" )
{
- public String getSyntaxOid()
- {
- return "1.1.1.1";
- }
+ private static final long serialVersionUID = 0L;
+
public boolean isValidSyntax( Object value )
{
if ( !( value instanceof String ) )
@@ -227,20 +123,16 @@
}
return true;
}
-
- public void assertSyntax( Object value ) throws NamingException
- {
- if ( ! isValidSyntax( value ) )
- {
- throw new InvalidAttributeValueException();
- }
- }
} );
+
+ MatchingRule matchingRule = new MatchingRule( "1.1.2.1" );
+ matchingRule.setSyntax( syntax );
+
- final MR mr = new MR( "1.1.2.1" );
- mr.syntax = s;
- mr.comparator = new Comparator<String>()
+ matchingRule.setLdapComparator( new LdapComparator<String>( matchingRule.getOid() )
{
+ private static final long serialVersionUID = 0L;
+
public int compare( String o1, String o2 )
{
return ( o1 == null ?
@@ -265,12 +157,11 @@
throw new IllegalArgumentException( "Not a valid value" );
}
- };
+ } );
- mr.normalizer = new Normalizer()
+ Normalizer normalizer = new Normalizer( "1.1.1" )
{
- // The serial UID
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 0L;
public Value<?> normalize( Value<?> value ) throws NamingException
{
@@ -289,98 +180,77 @@
}
};
- AT at = new AT( "1.1.3.1" );
- at.setEquality( mr );
- at.setSyntax( s );
- return at;
+ matchingRule.setNormalizer( normalizer );
+
+ attributeType.setEquality( matchingRule );
+ attributeType.setSyntax( syntax );
+
+ return attributeType;
}
/* no protection*/ static AttributeType getIA5StringAttributeType()
{
- AT at = new AT( "1.1" );
-
- S s = new S( "1.1.1", true );
+ AttributeType attributeType = new AttributeType( "1.1" );
+ attributeType.addName( "1.1" );
+ LdapSyntax syntax = new LdapSyntax( "1.1.1", "", true );
- s.setSyntaxChecker( new SyntaxChecker()
+ syntax.setSyntaxChecker( new SyntaxChecker( "1.1.2" )
{
- public String getSyntaxOid()
- {
- return "1.1.1";
- }
+ private static final long serialVersionUID = 0L;
+
public boolean isValidSyntax( Object value )
{
return ((String)value == null) || (((String)value).length() < 7) ;
}
-
- public void assertSyntax( Object value ) throws NamingException
- {
- if ( ! isValidSyntax( value ) )
- {
- throw new InvalidAttributeValueException();
- }
- }
} );
+
+ MatchingRule matchingRule = new MatchingRule( "1.1.2" );
+ matchingRule.setSyntax( syntax );
+
- final MR mr = new MR( "1.1.2" );
- mr.syntax = s;
- mr.comparator = new Comparator<String>()
+ matchingRule.setLdapComparator( new LdapComparator<String>( matchingRule.getOid() )
{
+ private static final long serialVersionUID = 0L;
+
public int compare( String o1, String o2 )
{
return ( ( o1 == null ) ?
( o2 == null ? 0 : -1 ) :
( o2 == null ? 1 : o1.compareTo( o2 ) ) );
}
- };
+ } );
+
+ matchingRule.setNormalizer( new DeepTrimToLowerNormalizer( matchingRule.getOid() ) );
- mr.normalizer = new DeepTrimToLowerNormalizer();
+ attributeType.setEquality( matchingRule );
+ attributeType.setSyntax( syntax );
- at.setEquality( mr );
- at.setSyntax( s );
- return at;
+ return attributeType;
}
/* No protection */ static AttributeType getBytesAttributeType()
{
- AT at = new AT( "1.2" );
+ AttributeType attributeType = new AttributeType( "1.2" );
+ LdapSyntax syntax = new LdapSyntax( "1.2.1", "", true );
- S s = new S( "1.2.1", true );
-
- s.setSyntaxChecker( new SyntaxChecker()
+ syntax.setSyntaxChecker( new SyntaxChecker( "1.2.1" )
{
- public String getSyntaxOid()
- {
- return "1.2.1";
- }
+ private static final long serialVersionUID = 0L;
+
public boolean isValidSyntax( Object value )
{
return ( value == null ) || ( ((byte[])value).length < 5 );
}
-
- public void assertSyntax( Object value ) throws NamingException
- {
- if ( ! isValidSyntax( value ) )
- {
- throw new InvalidAttributeValueException();
- }
- }
} );
- final MR mr = new MR( "1.2.2" );
- mr.syntax = s;
- mr.comparator = new Comparator<byte[]>()
- {
- public int compare( byte[] o1, byte[] o2 )
- {
- return ( ( o1 == null ) ?
- ( o2 == null ? 0 : -1 ) :
- ( o2 == null ? 1 : ByteArrayComparator.INSTANCE.compare( o1, o2 ) ) );
- }
- };
+ MatchingRule matchingRule = new MatchingRule( "1.2.2" );
+ matchingRule.setSyntax( syntax );
+
+ matchingRule.setLdapComparator( new ByteArrayComparator( "1.2.2" ) );
- mr.normalizer = new Normalizer()
+ matchingRule.setNormalizer( new Normalizer( "1.1.1" )
{
// The serial UID
private static final long serialVersionUID = 1L;
@@ -411,10 +281,11 @@
{
throw new IllegalStateException( "expected byte[] to normalize" );
}
- };
+ } );
- at.setEquality( mr );
- at.setSyntax( s );
- return at;
+ attributeType.setEquality( matchingRule );
+ attributeType.setSyntax( syntax );
+
+ return attributeType;
}
}
Modified: directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java (original)
+++ directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java Wed Jan 6 18:26:43 2010
@@ -19,16 +19,17 @@
package org.apache.directory.server.core.entry;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -42,18 +43,7 @@
import javax.naming.NamingException;
import javax.naming.directory.InvalidAttributeValueException;
-import org.apache.directory.server.schema.bootstrap.ApacheSchema;
-import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
-import org.apache.directory.server.schema.bootstrap.BootstrapSchemaLoader;
-import org.apache.directory.server.schema.bootstrap.CoreSchema;
-import org.apache.directory.server.schema.bootstrap.CosineSchema;
-import org.apache.directory.server.schema.bootstrap.InetorgpersonSchema;
-import org.apache.directory.server.schema.bootstrap.Schema;
-import org.apache.directory.server.schema.bootstrap.SystemSchema;
-import org.apache.directory.server.schema.registries.DefaultOidRegistry;
-import org.apache.directory.server.schema.registries.DefaultRegistries;
-import org.apache.directory.server.schema.registries.OidRegistry;
-import org.apache.directory.server.schema.registries.Registries;
+import org.apache.commons.io.FileUtils;
import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.entry.client.ClientAttribute;
@@ -61,8 +51,13 @@
import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
import org.apache.directory.shared.ldap.util.StringTools;
-
import org.junit.BeforeClass;
import org.junit.Test;
@@ -75,9 +70,7 @@
*/
public class DefaultServerAttributeTest
{
- private static BootstrapSchemaLoader loader;
- private static Registries registries;
- private static OidRegistry oidRegistry;
+ private static LdifSchemaLoader loader;
private static AttributeType atCN;
private static AttributeType atSN;
@@ -105,30 +98,46 @@
private static final ClientBinaryValue BIN_VALUE3 = new ClientBinaryValue( BYTES3 );
private static final ClientBinaryValue BIN_VALUE4 = new ClientBinaryValue( BYTES4 );
+
/**
* Initialize the registries once for the whole test suite
*/
@BeforeClass
public static void setup() throws Exception
{
- loader = new BootstrapSchemaLoader();
- oidRegistry = new DefaultOidRegistry();
- registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
-
- // load essential bootstrap schemas
- Set<Schema> bootstrapSchemas = new HashSet<Schema>();
- bootstrapSchemas.add( new ApachemetaSchema() );
- bootstrapSchemas.add( new ApacheSchema() );
- bootstrapSchemas.add( new CoreSchema() );
- bootstrapSchemas.add( new SystemSchema() );
- bootstrapSchemas.add( new InetorgpersonSchema() );
- bootstrapSchemas.add( new CosineSchema() );
- loader.loadWithDependencies( bootstrapSchemas, registries );
-
- atCN = registries.getAttributeTypeRegistry().lookup( "cn" );
- atC = registries.getAttributeTypeRegistry().lookup( "c" );
- atSN = registries.getAttributeTypeRegistry().lookup( "sn" );
- atPwd = registries.getAttributeTypeRegistry().lookup( "userpassword" );
+ String workingDirectory = System.getProperty( "workingDirectory" );
+
+ if ( workingDirectory == null )
+ {
+ String path = DefaultServerAttributeTest.class.getResource( "" ).getPath();
+ int targetPos = path.indexOf( "target" );
+ workingDirectory = path.substring( 0, targetPos + 6 );
+ }
+
+ // Cleanup the target directory
+ File schemaRepository = new File( workingDirectory, "schema" );
+ FileUtils.deleteDirectory( schemaRepository );
+
+ SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
+ extractor.extractOrCopy( true );
+ loader = new LdifSchemaLoader( schemaRepository );
+ SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+ schemaManager.loadAllEnabled();
+
+ List<Throwable> errors = schemaManager.getErrors();
+
+ if ( errors.size() != 0 )
+ {
+ // We have inconsistencies : log them and exit.
+ throw new RuntimeException( "Inconsistent schemas : " +
+ ExceptionUtils.printErrors( errors ) );
+ }
+
+ atCN = schemaManager.lookupAttributeTypeRegistry( "cn" );
+ atC = schemaManager.lookupAttributeTypeRegistry( "c" );
+ atSN = schemaManager.lookupAttributeTypeRegistry( "sn" );
+ atPwd = schemaManager.lookupAttributeTypeRegistry( "userpassword" );
}
/**
@@ -573,8 +582,8 @@
{
ServerAttribute attr = new DefaultServerAttribute( atCN );
- // No value, this should be valid
- assertTrue( attr.isValid() );
+ // No value, this should not be valid
+ assertFalse( attr.isValid() );
attr.add( "test", "test2", "A123\\;" );
assertTrue( attr.isValid() );
@@ -2097,7 +2106,7 @@
assertEquals( "cn", dsaSer.getUpId() );
assertEquals( 0, dsaSer.size() );
assertTrue( dsaSer.isHR() );
- assertTrue( dsaSer.isValid() );
+ assertFalse( dsaSer.isValid() );
}
Re: svn commit: r896599 [3/30] - in /directory/apacheds/trunk: ./
avl-partition/ avl-partition/src/ avl-partition/src/main/ avl-partition/src/main/java/
avl-partition/src/main/java/org/ avl-partition/src/main/java/org/apache/
avl-partition/src/main/java/or...
Posted by Emmanuel Lecharny <el...@gmail.com>.
Felix Knecht a écrit :
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> This doesn't seems to be JDK1.5 compliant (at least for me):
>
I confirm. I will fix that.
--
Regards,
Cordialement,
Emmanuel Lécharny
www.nextury.com
Re: svn commit: r896599 [3/30] - in /directory/apacheds/trunk: ./
avl-partition/ avl-partition/src/ avl-partition/src/main/ avl-partition/src/main/java/
avl-partition/src/main/java/org/ avl-partition/src/main/java/org/apache/
avl-partition/src/main/java/or...
Posted by Felix Knecht <fe...@apache.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
This doesn't seems to be JDK1.5 compliant (at least for me):
[INFO] Compilation failure
/home/felix/svn/apache/directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java:[376,24]
compare(capture of ? super byte[],capture of ? super byte[]) in
java.util.Comparator<capture of ? super byte[]> cannot be applied to
(byte[],byte[])
/home/felix/svn/apache/directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java:[503,37]
compare(capture of ? super byte[],capture of ? super byte[]) in
java.util.Comparator<capture of ? super byte[]> cannot be applied to
(byte[],byte[])
~/svn/apache/directory/apacheds/trunk $ java -version
java version "1.5.0_22"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03)
Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_22-b03, mixed mode)
Regards
Felix
On 06.01.2010 19:27, elecharny@apache.org wrote:
> Modified: directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
> URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java?rev=896599&r1=896598&r2=896599&view=diff
> ==============================================================================
> --- directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java (original)
> +++ directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java Wed Jan 6 18:26:43 2010
> @@ -32,6 +32,7 @@
> import org.apache.directory.shared.ldap.entry.Value;
> import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
> import org.apache.directory.shared.ldap.schema.AttributeType;
> +import org.apache.directory.shared.ldap.schema.LdapComparator;
> import org.apache.directory.shared.ldap.schema.MatchingRule;
> import org.apache.directory.shared.ldap.schema.Normalizer;
> import org.apache.directory.shared.ldap.schema.comparators.ByteArrayComparator;
> @@ -53,7 +54,7 @@
> {
> /** Used for serialization */
> private static final long serialVersionUID = 2L;
> -
> +
> /** logger for reporting errors that might not be handled properly upstream */
> private static final Logger LOG = LoggerFactory.getLogger( ServerBinaryValue.class );
>
> @@ -73,38 +74,31 @@
> */
> protected String logAssert( String message )
> {
> - LOG.error( message );
> + LOG.error( message );
> return message;
> }
>
> -
> +
> /**
> * Check the attributeType member. It should not be null,
> * and it should contains a syntax.
> */
> protected String checkAttributeType( AttributeType attributeType )
> {
> - try
> + if ( attributeType == null )
> {
> - if ( attributeType == null )
> - {
> - return "The AttributeType parameter should not be null";
> - }
> -
> - if ( attributeType.getSyntax() == null )
> - {
> - return "There is no Syntax associated with this attributeType";
> - }
> -
> - return null;
> + return "The AttributeType parameter should not be null";
> }
> - catch ( NamingException ne )
> +
> + if ( attributeType.getSyntax() == null )
> {
> - return "This AttributeType is incorrect";
> + return "There is no Syntax associated with this attributeType";
> }
> +
> + return null;
> }
>
> -
> +
> // -----------------------------------------------------------------------
> // Constructors
> // -----------------------------------------------------------------------
> @@ -116,27 +110,20 @@
> public ServerBinaryValue( AttributeType attributeType )
> {
> super();
> -
> +
> if ( attributeType == null )
> {
> throw new IllegalArgumentException( "The AttributeType parameter should not be null" );
> }
>
> - try
> + if ( attributeType.getSyntax() == null )
> {
> - if ( attributeType.getSyntax() == null )
> - {
> - throw new IllegalArgumentException( "There is no Syntax associated with this attributeType" );
> - }
> -
> - if ( attributeType.getSyntax().isHumanReadable() )
> - {
> - LOG.warn( "Treating a value of a human readible attribute {} as binary: ", attributeType.getName() );
> - }
> + throw new IllegalArgumentException( "There is no Syntax associated with this attributeType" );
> }
> - catch( NamingException e )
> +
> + if ( attributeType.getSyntax().isHumanReadable() )
> {
> - LOG.error( "Failed to resolve syntax for attributeType {}", attributeType, e );
> + LOG.warn( "Treating a value of a human readible attribute {} as binary: ", attributeType.getName() );
> }
>
> this.attributeType = attributeType;
> @@ -164,7 +151,7 @@
> * @param wrapped the value to wrap which can be null
> * @param normalizedValue the normalized value
> */
> - /** No protection */
> + /** No protection */
> ServerBinaryValue( AttributeType attributeType, byte[] wrapped, byte[] normalizedValue, boolean same, boolean valid )
> {
> super( wrapped );
> @@ -172,7 +159,7 @@
> this.attributeType = attributeType;
> this.normalizedValue = normalizedValue;
> this.valid = valid;
> - this.same = same;
> + this.same = same;
> //this.oid = attributeType.getOid();
> }
>
> @@ -187,11 +174,11 @@
> // Bypass the normalization if it has already been done.
> return;
> }
> -
> +
> if ( wrapped != null )
> {
> Normalizer normalizer = getNormalizer();
> -
> +
> if ( normalizer == null )
> {
> normalizedValue = wrapped;
> @@ -213,9 +200,9 @@
> }
> }
>
> -
> +
> /**
> - * Gets the normalized (cannonical) representation for the wrapped string.
> + * Gets the normalized (canonical) representation for the wrapped string.
> * If the wrapped String is null, null is returned, otherwise the normalized
> * form is returned. If no the normalizedValue is null, then this method
> * will attempt to generate it from the wrapped value: repeated calls to
> @@ -259,7 +246,7 @@
> *
> * @return gets the normalized value
> */
> - public byte[] getNormalizedValue()
> + public byte[] getNormalizedValue()
> {
> if ( isNull() )
> {
> @@ -315,7 +302,7 @@
>
> if ( normalizedValue != null )
> {
> - byte[] copy = new byte[ normalizedValue.length ];
> + byte[] copy = new byte[normalizedValue.length];
> System.arraycopy( normalizedValue, 0, copy, 0, normalizedValue.length );
> return copy;
> }
> @@ -342,20 +329,11 @@
> return valid;
> }
>
> - try
> - {
> - valid = attributeType.getSyntax().getSyntaxChecker().isValidSyntax( getReference() );
> - }
> - catch ( NamingException ne )
> - {
> - String message = "Cannot check the syntax : " + ne.getMessage();
> - LOG.error( message );
> - valid = false;
> - }
> -
> + valid = attributeType.getSyntax().getSyntaxChecker().isValidSyntax( getReference() );
> +
> return valid;
> }
> -
> +
>
> /**
> *
> @@ -378,7 +356,7 @@
> }
> else
> {
> - if ( ( value == null ) || value.isNull() )
> + if ( ( value == null ) || value.isNull() )
> {
> return 1;
> }
> @@ -390,29 +368,30 @@
>
> try
> {
> - Comparator<? super Value<byte[]>> comparator = getComparator();
> -
> + Comparator<? super byte[]> comparator = getLdapComparator();
> +
> if ( comparator != null )
> {
> - return getComparator().compare( getNormalizedValueReference(), binaryValue.getNormalizedValueReference() );
> + return comparator
> + .compare( getNormalizedValueReference(), binaryValue.getNormalizedValueReference() );
> }
> else
> {
> - return ByteArrayComparator.INSTANCE.compare( getNormalizedValueReference(),
> - binaryValue.getNormalizedValueReference() );
> + return new ByteArrayComparator( null ).compare( getNormalizedValueReference(), binaryValue
> + .getNormalizedValueReference() );
> }
> }
> catch ( NamingException e )
> {
> - String msg = "Failed to compare normalized values for " + Arrays.toString( getReference() )
> - + " and " + value;
> + String msg = "Failed to compare normalized values for " + Arrays.toString( getReference() ) + " and "
> + + value;
> LOG.error( msg, e );
> throw new IllegalStateException( msg, e );
> }
> }
>
> - String message = "I don't really know how to compare anything other " +
> - "than ServerBinaryValues at this point in time.";
> + String message = "I don't really know how to compare anything other "
> + + "than ServerBinaryValues at this point in time.";
> LOG.error( message );
> throw new NotImplementedException( message );
> }
> @@ -485,18 +464,18 @@
> return true;
> }
>
> - if ( ! ( obj instanceof ServerBinaryValue ) )
> + if ( !( obj instanceof ServerBinaryValue ) )
> {
> return false;
> }
>
> ServerBinaryValue other = ( ServerBinaryValue ) obj;
> -
> +
> if ( !attributeType.equals( other.attributeType ) )
> {
> return false;
> }
> -
> +
> if ( isNull() )
> {
> return other.isNull();
> @@ -512,7 +491,7 @@
> {
> try
> {
> - Comparator<byte[]> comparator = getComparator();
> + LdapComparator<? super byte[]> comparator = getLdapComparator();
>
> // Compare normalized values
> if ( comparator == null )
> @@ -555,7 +534,7 @@
>
> if ( mr == null )
> {
> - mr = attributeType.getSubstr();
> + mr = attributeType.getSubstring();
> }
>
> return mr;
> @@ -589,7 +568,7 @@
> * @return a comparator associated with the attributeType or null if one cannot be found
> * @throws NamingException if resolution of schema entities fail
> */
> - private Comparator getComparator() throws NamingException
> + private LdapComparator<? super Object> getLdapComparator() throws NamingException
> {
> MatchingRule mr = getMatchingRule();
>
> @@ -598,23 +577,23 @@
> return null;
> }
>
> - return mr.getComparator();
> + return mr.getLdapComparator();
> }
> -
> -
> +
> +
> /**
> * @return a copy of the current value
> */
> public ServerBinaryValue clone()
> {
> - ServerBinaryValue clone = (ServerBinaryValue)super.clone();
> -
> + ServerBinaryValue clone = ( ServerBinaryValue ) super.clone();
> +
> if ( normalizedValue != null )
> {
> - clone.normalizedValue = new byte[ normalizedValue.length ];
> + clone.normalizedValue = new byte[normalizedValue.length];
> System.arraycopy( normalizedValue, 0, clone.normalizedValue, 0, normalizedValue.length );
> }
> -
> +
> return clone;
> }
>
> @@ -624,13 +603,13 @@
> *
> * We can't use this method for a ServerBinaryValue, as we have to feed the value
> * with an AttributeType object
> - */
> + */
> public void writeExternal( ObjectOutput out ) throws IOException
> {
> throw new IllegalStateException( "Cannot use standard serialization for a ServerStringValue" );
> }
> -
> -
> +
> +
> /**
> * We will write the value and the normalized value, only
> * if the normalized value is different.
> @@ -655,18 +634,18 @@
> {
> // write a the wrapped length
> out.writeInt( wrapped.length );
> -
> +
> // Write the data if not empty
> if ( wrapped.length > 0 )
> {
> // The data
> out.write( wrapped );
> -
> +
> // Normalize the data
> try
> {
> normalize();
> -
> +
> if ( !normalized )
> {
> // We may not have a normalizer. Just get out
> @@ -677,7 +656,7 @@
> {
> // Write a flag indicating that the data has been normalized
> out.writeBoolean( true );
> -
> +
> if ( Arrays.equals( getReference(), normalizedValue ) )
> {
> // Write the 'same = true' flag
> @@ -687,10 +666,10 @@
> {
> // Write the 'same = false' flag
> out.writeBoolean( false );
> -
> +
> // Write the normalized value length
> - out.write( normalizedValue.length );
> -
> + out.writeInt( normalizedValue.length );
> +
> if ( normalizedValue.length > 0 )
> {
> // Write the normalized value if not empty
> @@ -715,7 +694,7 @@
> }
> }
>
> -
> +
> /**
> * @see Externalizable#readExternal(ObjectInput)
> *
> @@ -726,7 +705,7 @@
> {
> throw new IllegalStateException( "Cannot use standard serialization for a ServerStringValue" );
> }
> -
> +
>
> /**
> *
> @@ -740,7 +719,7 @@
> {
> // The UP value length
> int wrappedLength = in.readInt();
> -
> +
> if ( wrappedLength == -1 )
> {
> // If the value is null, the length will be set to -1
> @@ -749,35 +728,35 @@
> }
> else if ( wrappedLength == 0 )
> {
> - wrapped = StringTools.EMPTY_BYTES;
> - same = true;
> - normalized = true;
> - normalizedValue = wrapped;
> + wrapped = StringTools.EMPTY_BYTES;
> + same = true;
> + normalized = true;
> + normalizedValue = wrapped;
> }
> else
> {
> wrapped = new byte[wrappedLength];
> -
> +
> // Read the data
> in.readFully( wrapped );
> -
> +
> // Check if we have a normalized value
> normalized = in.readBoolean();
> -
> +
> if ( normalized )
> {
> // Read the 'same' flag
> same = in.readBoolean();
> -
> +
> if ( !same )
> {
> // Read the normalizedvalue length
> int normalizedLength = in.readInt();
> -
> +
> if ( normalizedLength > 0 )
> {
> normalizedValue = new byte[normalizedLength];
> -
> +
> // Read the normalized value
> in.read( normalizedValue, 0, normalizedLength );
> }
> @@ -794,4 +773,4 @@
> }
> }
> }
> -}
> +}
>
> Modified: directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntrySerializer.java
> URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntrySerializer.java?rev=896599&r1=896598&r2=896599&view=diff
> ==============================================================================
> --- directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntrySerializer.java (original)
> +++ directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntrySerializer.java Wed Jan 6 18:26:43 2010
> @@ -25,12 +25,12 @@
> import java.io.ObjectInputStream;
> import java.io.ObjectOutputStream;
>
> -import org.apache.directory.server.schema.registries.Registries;
> +import jdbm.helper.Serializer;
> +
> +import org.apache.directory.shared.ldap.schema.SchemaManager;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> -import jdbm.helper.Serializer;
> -
>
> /**
> * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
> @@ -48,18 +48,18 @@
> */
> private static final boolean IS_DEBUG = LOG.isDebugEnabled();
>
> - /** The registries reference */
> - private transient Registries registries;
> + /** The schemaManager reference */
> + private transient SchemaManager schemaManager;
>
>
> /**
> * Creates a new instance of ServerEntrySerializer.
> *
> - * @param registries The reference to the global registries
> + * @param schemaManager The reference to the global schemaManager
> */
> - public ServerEntrySerializer( Registries registries )
> + public ServerEntrySerializer( SchemaManager schemaManager )
> {
> - this.registries = registries;
> + this.schemaManager = schemaManager;
> }
>
>
> @@ -144,7 +144,7 @@
> {
> ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( bytes ) );
>
> - DefaultServerEntry serverEntry = new DefaultServerEntry( registries );
> + DefaultServerEntry serverEntry = new DefaultServerEntry( schemaManager );
>
> try
> {
>
> Modified: directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java
> URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java?rev=896599&r1=896598&r2=896599&view=diff
> ==============================================================================
> --- directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java (original)
> +++ directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerEntryUtils.java Wed Jan 6 18:26:43 2010
> @@ -35,15 +35,15 @@
> import javax.naming.directory.ModificationItem;
> import javax.naming.directory.SearchResult;
>
> -import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
> -import org.apache.directory.server.schema.registries.Registries;
> import org.apache.directory.shared.ldap.constants.SchemaConstants;
> import org.apache.directory.shared.ldap.entry.EntryAttribute;
> import org.apache.directory.shared.ldap.entry.Modification;
> import org.apache.directory.shared.ldap.entry.ModificationOperation;
> import org.apache.directory.shared.ldap.entry.Value;
> +import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeIdentifierException;
> import org.apache.directory.shared.ldap.name.LdapDN;
> import org.apache.directory.shared.ldap.schema.AttributeType;
> +import org.apache.directory.shared.ldap.schema.SchemaManager;
> import org.apache.directory.shared.ldap.schema.SchemaUtils;
> import org.apache.directory.shared.ldap.util.EmptyEnumeration;
> import org.apache.directory.shared.ldap.util.StringTools;
> @@ -195,14 +195,14 @@
> *
> * @throws InvalidAttributeIdentifierException If we get an invalid attribute
> */
> - public static ServerEntry toServerEntry( Attributes attributes, LdapDN dn, Registries registries )
> + public static ServerEntry toServerEntry( Attributes attributes, LdapDN dn, SchemaManager schemaManager )
> throws InvalidAttributeIdentifierException
> {
> if ( attributes instanceof BasicAttributes )
> {
> try
> {
> - ServerEntry entry = new DefaultServerEntry( registries, dn );
> + ServerEntry entry = new DefaultServerEntry( schemaManager, dn );
>
> for ( NamingEnumeration<? extends Attribute> attrs = attributes.getAll(); attrs.hasMoreElements(); )
> {
> @@ -212,7 +212,7 @@
> String id = SchemaUtils.stripOptions( attributeId );
> Set<String> options = SchemaUtils.getOptions( attributeId );
> // TODO : handle options.
> - AttributeType attributeType = registries.getAttributeTypeRegistry().lookup( id );
> + AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
> ServerAttribute serverAttribute = ServerEntryUtils.toServerAttribute( attr, attributeType );
>
> if ( serverAttribute != null )
> @@ -244,12 +244,12 @@
> * @return the resultant entry after the modification has taken place
> * @throws NamingException if there are problems accessing attributes
> */
> - public static ServerEntry getTargetEntry( Modification mod, ServerEntry entry, Registries registries ) throws NamingException
> + public static ServerEntry getTargetEntry( Modification mod, ServerEntry entry, SchemaManager schemaManager ) throws NamingException
> {
> ServerEntry targetEntry = ( ServerEntry ) entry.clone();
> ModificationOperation modOp = mod.getOperation();
> String id = mod.getAttribute().getId();
> - AttributeType attributeType = registries.getAttributeTypeRegistry().lookup( id );
> + AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
>
> switch ( modOp )
> {
> @@ -397,7 +397,7 @@
> * @throws NamingException
> */
> public static List<Modification> convertToServerModification( List<ModificationItem> modificationItems,
> - AttributeTypeRegistry atRegistry ) throws NamingException
> + SchemaManager schemaManager ) throws NamingException
> {
> if ( modificationItems != null )
> {
> @@ -405,7 +405,7 @@
>
> for ( ModificationItem modificationItem: modificationItems )
> {
> - AttributeType attributeType = atRegistry.lookup( modificationItem.getAttribute().getID() );
> + AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( modificationItem.getAttribute().getID() );
> modifications.add( toServerModification( modificationItem, attributeType ) );
> }
>
> @@ -442,7 +442,7 @@
>
>
> public static List<Modification> toServerModification( Modification[] modifications,
> - AttributeTypeRegistry atRegistry ) throws NamingException
> + SchemaManager schemaManager ) throws NamingException
> {
> if ( modifications != null )
> {
> @@ -459,25 +459,21 @@
> // DIRSERVER-646 Fix: Replacing an unknown attribute with no values
> // (deletion) causes an error
> // -------------------------------------------------------------------
> -
> - // TODO - after removing JNDI we need to make the server handle
> - // this in the codec
> -
> - if ( ! atRegistry.hasAttributeType( id )
> + if ( ! schemaManager.getAttributeTypeRegistry().contains( id )
> && modification.getAttribute().size() == 0
> && modification.getOperation() == ModificationOperation.REPLACE_ATTRIBUTE )
> {
> - continue;
> + // The attributeType does not exist in the schema.
> + // It's an error
> + String message = "The AttributeType '" + id + "' does not exist in the schema";
> + throw new LdapInvalidAttributeIdentifierException( message );
> + }
> + else
> + {
> + // TODO : handle options
> + AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
> + modificationsList.add( toServerModification( modification, attributeType ) );
> }
> -
> - // -------------------------------------------------------------------
> - // END DIRSERVER-646 Fix
> - // -------------------------------------------------------------------
> -
> -
> - // TODO : handle options
> - AttributeType attributeType = atRegistry.lookup( id );
> - modificationsList.add( toServerModification( modification, attributeType ) );
> }
>
> return modificationsList;
> @@ -490,7 +486,7 @@
>
>
> public static List<Modification> toServerModification( ModificationItem[] modifications,
> - AttributeTypeRegistry atRegistry ) throws NamingException
> + SchemaManager schemaManager ) throws NamingException
> {
> if ( modifications != null )
> {
> @@ -510,7 +506,7 @@
> // TODO - after removing JNDI we need to make the server handle
> // this in the codec
>
> - if ( ! atRegistry.hasAttributeType( id )
> + if ( ! schemaManager.getAttributeTypeRegistry().contains( id )
> && modification.getAttribute().size() == 0
> && modification.getModificationOp() == DirContext.REPLACE_ATTRIBUTE )
> {
> @@ -523,7 +519,7 @@
>
>
> // TODO : handle options
> - AttributeType attributeType = atRegistry.lookup( id );
> + AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
> modificationsList.add( toServerModification( (ModificationItem)modification, attributeType ) );
> }
>
> @@ -616,7 +612,7 @@
> ServerSearchResult rec = result.next();
>
> SearchResult searchResult = new SearchResult(
> - rec.getDn().getUpName(),
> + rec.getDn().getName(),
> rec.getObject(),
> toBasicAttributes( rec.getServerEntry() ),
> rec.isRelative() );
> @@ -644,7 +640,7 @@
> ServerSearchResult rec = result.next();
>
> SearchResult searchResult = new SearchResult(
> - rec.getDn().getUpName(),
> + rec.getDn().getName(),
> rec.getObject(),
> toBasicAttributes( rec.getServerEntry() ),
> rec.isRelative() );
>
> Modified: directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerModification.java
> URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerModification.java?rev=896599&r1=896598&r2=896599&view=diff
> ==============================================================================
> --- directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerModification.java (original)
> +++ directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerModification.java Wed Jan 6 18:26:43 2010
> @@ -24,15 +24,13 @@
> import java.io.ObjectOutput;
>
> import javax.naming.NamingException;
> -//import javax.naming.directory.DirContext;
>
> -import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
> -import org.apache.directory.server.schema.registries.Registries;
> import org.apache.directory.shared.ldap.entry.EntryAttribute;
> import org.apache.directory.shared.ldap.entry.Modification;
> import org.apache.directory.shared.ldap.entry.ModificationOperation;
> import org.apache.directory.shared.ldap.entry.client.ClientModification;
> import org.apache.directory.shared.ldap.schema.AttributeType;
> +import org.apache.directory.shared.ldap.schema.SchemaManager;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> @@ -81,7 +79,7 @@
> }
>
>
> - public ServerModification( Registries registries, Modification modification )
> + public ServerModification( SchemaManager schemaManager, Modification modification )
> {
> operation = modification.getOperation();
>
> @@ -97,7 +95,7 @@
> }
> else
> {
> - at = registries.getAttributeTypeRegistry().lookup( modAttribute.getId() );
> + at = schemaManager.lookupAttributeTypeRegistry( modAttribute.getId() );
> }
>
> attribute = new DefaultServerAttribute( at, modAttribute );
> @@ -278,7 +276,7 @@
> * @throws ClassNotFoundException if we weren't able to construct a Modification instance
> * @throws NamingException If we didn't found the AttributeType in the registries
> */
> - public void deserialize( ObjectInput in, AttributeTypeRegistry atRegistry ) throws IOException, ClassNotFoundException, NamingException
> + public void deserialize( ObjectInput in, SchemaManager schemaManager ) throws IOException, ClassNotFoundException, NamingException
> {
> // Read the operation
> int op = in.readInt();
> @@ -289,7 +287,7 @@
> String oid = in.readUTF();
>
> // Lookup for tha associated AttributeType
> - AttributeType attributeType = atRegistry.lookup( oid );
> + AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( oid );
>
> attribute = new DefaultServerAttribute( attributeType );
>
>
> Modified: directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerSearchResult.java
> URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerSearchResult.java?rev=896599&r1=896598&r2=896599&view=diff
> ==============================================================================
> --- directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerSearchResult.java (original)
> +++ directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerSearchResult.java Wed Jan 6 18:26:43 2010
> @@ -131,7 +131,7 @@
> */
> public String toString()
> {
> - String name = (dn == null ? "null" : ( dn == LdapDN.EMPTY_LDAPDN ? "\"\"" : dn.getUpName() ) );
> + String name = (dn == null ? "null" : ( dn == LdapDN.EMPTY_LDAPDN ? "\"\"" : dn.getName() ) );
> return "ServerSearchResult : " + name + "\n" + serverEntry;
> }
> }
>
> Modified: directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java
> URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java?rev=896599&r1=896598&r2=896599&view=diff
> ==============================================================================
> --- directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java (original)
> +++ directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerStringValue.java Wed Jan 6 18:26:43 2010
> @@ -23,7 +23,6 @@
> import java.io.IOException;
> import java.io.ObjectInput;
> import java.io.ObjectOutput;
> -import java.util.Comparator;
>
> import javax.naming.NamingException;
>
> @@ -31,6 +30,7 @@
> import org.apache.directory.shared.ldap.entry.Value;
> import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
> import org.apache.directory.shared.ldap.schema.AttributeType;
> +import org.apache.directory.shared.ldap.schema.LdapComparator;
> import org.apache.directory.shared.ldap.schema.MatchingRule;
> import org.apache.directory.shared.ldap.schema.Normalizer;
> import org.slf4j.Logger;
> @@ -77,24 +77,17 @@
> */
> protected String checkAttributeType( AttributeType attributeType )
> {
> - try
> + if ( attributeType == null )
> {
> - if ( attributeType == null )
> - {
> - return "The AttributeType parameter should not be null";
> - }
> -
> - if ( attributeType.getSyntax() == null )
> - {
> - return "There is no Syntax associated with this attributeType";
> - }
> -
> - return null;
> + return "The AttributeType parameter should not be null";
> }
> - catch ( NamingException ne )
> +
> + if ( attributeType.getSyntax() == null )
> {
> - return "This AttributeType is incorrect";
> + return "There is no Syntax associated with this attributeType";
> }
> +
> + return null;
> }
>
>
> @@ -115,22 +108,15 @@
> throw new IllegalArgumentException( "The AttributeType parameter should not be null" );
> }
>
> - try
> + if ( attributeType.getSyntax() == null )
> {
> - if ( attributeType.getSyntax() == null )
> - {
> - throw new IllegalArgumentException( "There is no Syntax associated with this attributeType" );
> - }
> -
> - if ( ! attributeType.getSyntax().isHumanReadable() )
> - {
> - LOG.warn( "Treating a value of a binary attribute {} as a String: " +
> - "\nthis could cause data corruption!", attributeType.getName() );
> - }
> + throw new IllegalArgumentException( "There is no Syntax associated with this attributeType" );
> }
> - catch( NamingException e )
> +
> + if ( ! attributeType.getSyntax().isHumanReadable() )
> {
> - LOG.error( "Failed to resolve syntax for attributeType {}", attributeType, e );
> + LOG.warn( "Treating a value of a binary attribute {} as a String: " +
> + "\nthis could cause data corruption!", attributeType.getName() );
> }
>
> this.attributeType = attributeType;
> @@ -269,16 +255,7 @@
> return valid;
> }
>
> - try
> - {
> - valid = attributeType.getSyntax().getSyntaxChecker().isValidSyntax( get() );
> - }
> - catch ( NamingException ne )
> - {
> - String message = "Cannot check the syntax : " + ne.getMessage();
> - LOG.error( message );
> - valid = false;
> - }
> + valid = attributeType.getSyntax().getSyntaxChecker().isValidSyntax( get() );
>
> return valid;
> }
> @@ -336,7 +313,7 @@
> try
> {
> //noinspection unchecked
> - return getComparator().compare( getNormalizedValue(), stringValue.getNormalizedValue() );
> + return getLdapComparator().compare( getNormalizedValue(), stringValue.getNormalizedValue() );
> }
> catch ( NamingException e )
> {
> @@ -436,7 +413,7 @@
> {
> try
> {
> - Comparator<String> comparator = getComparator();
> + LdapComparator<? super Object> comparator = getLdapComparator();
>
> // Compare normalized values
> if ( comparator == null )
> @@ -445,7 +422,15 @@
> }
> else
> {
> - return comparator.compare( getNormalizedValue(), other.getNormalizedValue() ) == 0;
> + if ( isNormalized() )
> + {
> + return comparator.compare( getNormalizedValue(), other.getNormalizedValue() ) == 0;
> + }
> + else
> + {
> + Normalizer normalizer = attributeType.getEquality().getNormalizer();
> + return comparator.compare( normalizer.normalize( get() ), normalizer.normalize( other.get() ) ) == 0;
> + }
> }
> }
> catch ( NamingException ne )
> @@ -481,7 +466,7 @@
>
> if ( mr == null )
> {
> - mr = attributeType.getSubstr();
> + mr = attributeType.getSubstring();
> }
>
> return mr;
> @@ -549,7 +534,7 @@
> * @return a comparator associated with the attributeType or null if one cannot be found
> * @throws NamingException if resolution of schema entities fail
> */
> - private Comparator getComparator() throws NamingException
> + private LdapComparator<? super Object> getLdapComparator() throws NamingException
> {
> MatchingRule mr = getMatchingRule();
>
> @@ -558,7 +543,7 @@
> return null;
> }
>
> - return mr.getComparator();
> + return mr.getLdapComparator();
> }
>
>
>
> Modified: directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/TestServerEntryUtils.java
> URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/TestServerEntryUtils.java?rev=896599&r1=896598&r2=896599&view=diff
> ==============================================================================
> --- directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/TestServerEntryUtils.java (original)
> +++ directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/TestServerEntryUtils.java Wed Jan 6 18:26:43 2010
> @@ -19,21 +19,16 @@
> */
> package org.apache.directory.server.core.entry;
>
> -import java.util.Comparator;
> -
> import javax.naming.NamingException;
> -import javax.naming.directory.InvalidAttributeValueException;
>
> import org.apache.directory.shared.ldap.entry.Value;
> import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
> import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
> -import org.apache.directory.shared.ldap.schema.AbstractAttributeType;
> -import org.apache.directory.shared.ldap.schema.AbstractMatchingRule;
> -import org.apache.directory.shared.ldap.schema.AbstractSyntax;
> import org.apache.directory.shared.ldap.schema.AttributeType;
> +import org.apache.directory.shared.ldap.schema.LdapComparator;
> +import org.apache.directory.shared.ldap.schema.LdapSyntax;
> import org.apache.directory.shared.ldap.schema.MatchingRule;
> import org.apache.directory.shared.ldap.schema.Normalizer;
> -import org.apache.directory.shared.ldap.schema.Syntax;
> import org.apache.directory.shared.ldap.schema.SyntaxChecker;
> import org.apache.directory.shared.ldap.schema.comparators.ByteArrayComparator;
> import org.apache.directory.shared.ldap.schema.normalizers.DeepTrimToLowerNormalizer;
> @@ -50,165 +45,66 @@
> /**
> * A local Syntax class for tests
> */
> - static class AT extends AbstractAttributeType
> + static class AT extends AttributeType
> {
> private static final long serialVersionUID = 0L;
> - AttributeType superior;
> - Syntax syntax;
> - MatchingRule equality;
> - MatchingRule ordering;
> - MatchingRule substr;
>
> protected AT( String oid )
> {
> super( oid );
> }
> -
> - public AttributeType getSuperior() throws NamingException
> - {
> - return superior;
> - }
> -
> -
> - public Syntax getSyntax() throws NamingException
> - {
> - return syntax;
> - }
> -
> -
> - public MatchingRule getEquality() throws NamingException
> - {
> - return equality;
> - }
> -
> -
> - public MatchingRule getOrdering() throws NamingException
> - {
> - return ordering;
> - }
> -
> -
> - public MatchingRule getSubstr() throws NamingException
> - {
> - return substr;
> - }
> -
> -
> - public void setSuperior( AttributeType superior )
> - {
> - this.superior = superior;
> - }
> -
> -
> - public void setSyntax( Syntax syntax )
> - {
> - this.syntax = syntax;
> - }
> -
> -
> - public void setEquality( MatchingRule equality )
> - {
> - this.equality = equality;
> - }
> -
> -
> - public void setOrdering( MatchingRule ordering )
> - {
> - this.ordering = ordering;
> - }
> -
> -
> - public void setSubstr( MatchingRule substr )
> - {
> - this.substr = substr;
> - }
> }
>
> + public static MatchingRule matchingRuleFactory( String oid )
> + {
> + MatchingRule matchingRule = new MatchingRule( oid );
> +
> + return matchingRule;
> + }
> /**
> * A local MatchingRule class for tests
> */
> - static class MR extends AbstractMatchingRule
> + static class MR extends MatchingRule
> {
> private static final long serialVersionUID = 0L;
> - Syntax syntax;
> - Comparator comparator;
> - Normalizer normalizer;
>
> protected MR( String oid )
> {
> super( oid );
> }
> -
> - public Syntax getSyntax() throws NamingException
> - {
> - return syntax;
> - }
> -
> - public Comparator getComparator() throws NamingException
> - {
> - return comparator;
> - }
> -
> -
> - public Normalizer getNormalizer() throws NamingException
> - {
> - return normalizer;
> - }
> -
> -
> - public void setSyntax( Syntax syntax )
> - {
> - this.syntax = syntax;
> - }
> -
> -
> - public void setComparator( Comparator<?> comparator )
> - {
> - this.comparator = comparator;
> - }
> -
> -
> - public void setNormalizer( Normalizer normalizer )
> - {
> - this.normalizer = normalizer;
> - }
> }
>
>
> /**
> * A local Syntax class used for the tests
> */
> - static class S extends AbstractSyntax
> + public static LdapSyntax syntaxFactory( String oid, boolean humanReadable )
> + {
> + LdapSyntax ldapSyntax = new LdapSyntax( oid );
> +
> + ldapSyntax.setHumanReadable( humanReadable );
> +
> + return ldapSyntax;
> + }
> + static class S extends LdapSyntax
> {
> private static final long serialVersionUID = 0L;
> - SyntaxChecker checker;
>
> public S( String oid, boolean humanReadible )
> {
> - super( oid, humanReadible );
> - }
> -
> - public void setSyntaxChecker( SyntaxChecker checker )
> - {
> - this.checker = checker;
> - }
> -
> - public SyntaxChecker getSyntaxChecker() throws NamingException
> - {
> - return checker;
> + super( oid, "", humanReadible );
> }
> }
>
> /* no protection*/ static AttributeType getCaseIgnoringAttributeNoNumbersType()
> {
> - S s = new S( "1.1.1.1", true );
> + AttributeType attributeType = new AttributeType( "1.1.3.1" );
> + LdapSyntax syntax = new LdapSyntax( "1.1.1.1", "", true );
>
> - s.setSyntaxChecker( new SyntaxChecker()
> + syntax.setSyntaxChecker( new SyntaxChecker( "1.1.2.1" )
> {
> - public String getSyntaxOid()
> - {
> - return "1.1.1.1";
> - }
> + private static final long serialVersionUID = 0L;
> +
> public boolean isValidSyntax( Object value )
> {
> if ( !( value instanceof String ) )
> @@ -227,20 +123,16 @@
> }
> return true;
> }
> -
> - public void assertSyntax( Object value ) throws NamingException
> - {
> - if ( ! isValidSyntax( value ) )
> - {
> - throw new InvalidAttributeValueException();
> - }
> - }
> } );
> +
> + MatchingRule matchingRule = new MatchingRule( "1.1.2.1" );
> + matchingRule.setSyntax( syntax );
> +
>
> - final MR mr = new MR( "1.1.2.1" );
> - mr.syntax = s;
> - mr.comparator = new Comparator<String>()
> + matchingRule.setLdapComparator( new LdapComparator<String>( matchingRule.getOid() )
> {
> + private static final long serialVersionUID = 0L;
> +
> public int compare( String o1, String o2 )
> {
> return ( o1 == null ?
> @@ -265,12 +157,11 @@
>
> throw new IllegalArgumentException( "Not a valid value" );
> }
> - };
> + } );
>
> - mr.normalizer = new Normalizer()
> + Normalizer normalizer = new Normalizer( "1.1.1" )
> {
> - // The serial UID
> - private static final long serialVersionUID = 1L;
> + private static final long serialVersionUID = 0L;
>
> public Value<?> normalize( Value<?> value ) throws NamingException
> {
> @@ -289,98 +180,77 @@
> }
> };
>
> - AT at = new AT( "1.1.3.1" );
> - at.setEquality( mr );
> - at.setSyntax( s );
> - return at;
> + matchingRule.setNormalizer( normalizer );
> +
> + attributeType.setEquality( matchingRule );
> + attributeType.setSyntax( syntax );
> +
> + return attributeType;
> }
>
>
> /* no protection*/ static AttributeType getIA5StringAttributeType()
> {
> - AT at = new AT( "1.1" );
> -
> - S s = new S( "1.1.1", true );
> + AttributeType attributeType = new AttributeType( "1.1" );
> + attributeType.addName( "1.1" );
> + LdapSyntax syntax = new LdapSyntax( "1.1.1", "", true );
>
> - s.setSyntaxChecker( new SyntaxChecker()
> + syntax.setSyntaxChecker( new SyntaxChecker( "1.1.2" )
> {
> - public String getSyntaxOid()
> - {
> - return "1.1.1";
> - }
> + private static final long serialVersionUID = 0L;
> +
> public boolean isValidSyntax( Object value )
> {
> return ((String)value == null) || (((String)value).length() < 7) ;
> }
> -
> - public void assertSyntax( Object value ) throws NamingException
> - {
> - if ( ! isValidSyntax( value ) )
> - {
> - throw new InvalidAttributeValueException();
> - }
> - }
> } );
> +
> + MatchingRule matchingRule = new MatchingRule( "1.1.2" );
> + matchingRule.setSyntax( syntax );
> +
>
> - final MR mr = new MR( "1.1.2" );
> - mr.syntax = s;
> - mr.comparator = new Comparator<String>()
> + matchingRule.setLdapComparator( new LdapComparator<String>( matchingRule.getOid() )
> {
> + private static final long serialVersionUID = 0L;
> +
> public int compare( String o1, String o2 )
> {
> return ( ( o1 == null ) ?
> ( o2 == null ? 0 : -1 ) :
> ( o2 == null ? 1 : o1.compareTo( o2 ) ) );
> }
> - };
> + } );
> +
> + matchingRule.setNormalizer( new DeepTrimToLowerNormalizer( matchingRule.getOid() ) );
>
> - mr.normalizer = new DeepTrimToLowerNormalizer();
> + attributeType.setEquality( matchingRule );
> + attributeType.setSyntax( syntax );
>
> - at.setEquality( mr );
> - at.setSyntax( s );
> - return at;
> + return attributeType;
> }
>
>
> /* No protection */ static AttributeType getBytesAttributeType()
> {
> - AT at = new AT( "1.2" );
> + AttributeType attributeType = new AttributeType( "1.2" );
> + LdapSyntax syntax = new LdapSyntax( "1.2.1", "", true );
>
> - S s = new S( "1.2.1", true );
> -
> - s.setSyntaxChecker( new SyntaxChecker()
> + syntax.setSyntaxChecker( new SyntaxChecker( "1.2.1" )
> {
> - public String getSyntaxOid()
> - {
> - return "1.2.1";
> - }
> + private static final long serialVersionUID = 0L;
> +
> public boolean isValidSyntax( Object value )
> {
> return ( value == null ) || ( ((byte[])value).length < 5 );
> }
> -
> - public void assertSyntax( Object value ) throws NamingException
> - {
> - if ( ! isValidSyntax( value ) )
> - {
> - throw new InvalidAttributeValueException();
> - }
> - }
> } );
>
> - final MR mr = new MR( "1.2.2" );
> - mr.syntax = s;
> - mr.comparator = new Comparator<byte[]>()
> - {
> - public int compare( byte[] o1, byte[] o2 )
> - {
> - return ( ( o1 == null ) ?
> - ( o2 == null ? 0 : -1 ) :
> - ( o2 == null ? 1 : ByteArrayComparator.INSTANCE.compare( o1, o2 ) ) );
> - }
> - };
> + MatchingRule matchingRule = new MatchingRule( "1.2.2" );
> + matchingRule.setSyntax( syntax );
> +
> + matchingRule.setLdapComparator( new ByteArrayComparator( "1.2.2" ) );
>
> - mr.normalizer = new Normalizer()
> + matchingRule.setNormalizer( new Normalizer( "1.1.1" )
> {
> // The serial UID
> private static final long serialVersionUID = 1L;
> @@ -411,10 +281,11 @@
> {
> throw new IllegalStateException( "expected byte[] to normalize" );
> }
> - };
> + } );
>
> - at.setEquality( mr );
> - at.setSyntax( s );
> - return at;
> + attributeType.setEquality( matchingRule );
> + attributeType.setSyntax( syntax );
> +
> + return attributeType;
> }
> }
>
> Modified: directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java
> URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java?rev=896599&r1=896598&r2=896599&view=diff
> ==============================================================================
> --- directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java (original)
> +++ directory/apacheds/trunk/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java Wed Jan 6 18:26:43 2010
> @@ -19,16 +19,17 @@
> package org.apache.directory.server.core.entry;
>
>
> -import static org.junit.Assert.assertNotSame;
> -import static org.junit.Assert.assertTrue;
> -import static org.junit.Assert.assertFalse;
> import static org.junit.Assert.assertEquals;
> -import static org.junit.Assert.assertNull;
> +import static org.junit.Assert.assertFalse;
> import static org.junit.Assert.assertNotNull;
> +import static org.junit.Assert.assertNotSame;
> +import static org.junit.Assert.assertNull;
> +import static org.junit.Assert.assertTrue;
> import static org.junit.Assert.fail;
>
> import java.io.ByteArrayInputStream;
> import java.io.ByteArrayOutputStream;
> +import java.io.File;
> import java.io.IOException;
> import java.io.ObjectInputStream;
> import java.io.ObjectOutputStream;
> @@ -42,18 +43,7 @@
> import javax.naming.NamingException;
> import javax.naming.directory.InvalidAttributeValueException;
>
> -import org.apache.directory.server.schema.bootstrap.ApacheSchema;
> -import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
> -import org.apache.directory.server.schema.bootstrap.BootstrapSchemaLoader;
> -import org.apache.directory.server.schema.bootstrap.CoreSchema;
> -import org.apache.directory.server.schema.bootstrap.CosineSchema;
> -import org.apache.directory.server.schema.bootstrap.InetorgpersonSchema;
> -import org.apache.directory.server.schema.bootstrap.Schema;
> -import org.apache.directory.server.schema.bootstrap.SystemSchema;
> -import org.apache.directory.server.schema.registries.DefaultOidRegistry;
> -import org.apache.directory.server.schema.registries.DefaultRegistries;
> -import org.apache.directory.server.schema.registries.OidRegistry;
> -import org.apache.directory.server.schema.registries.Registries;
> +import org.apache.commons.io.FileUtils;
> import org.apache.directory.shared.ldap.entry.EntryAttribute;
> import org.apache.directory.shared.ldap.entry.Value;
> import org.apache.directory.shared.ldap.entry.client.ClientAttribute;
> @@ -61,8 +51,13 @@
> import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
> import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
> import org.apache.directory.shared.ldap.schema.AttributeType;
> +import org.apache.directory.shared.ldap.schema.SchemaManager;
> +import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
> +import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
> +import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
> +import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
> +import org.apache.directory.shared.ldap.util.ExceptionUtils;
> import org.apache.directory.shared.ldap.util.StringTools;
> -
> import org.junit.BeforeClass;
> import org.junit.Test;
>
> @@ -75,9 +70,7 @@
> */
> public class DefaultServerAttributeTest
> {
> - private static BootstrapSchemaLoader loader;
> - private static Registries registries;
> - private static OidRegistry oidRegistry;
> + private static LdifSchemaLoader loader;
>
> private static AttributeType atCN;
> private static AttributeType atSN;
> @@ -105,30 +98,46 @@
> private static final ClientBinaryValue BIN_VALUE3 = new ClientBinaryValue( BYTES3 );
> private static final ClientBinaryValue BIN_VALUE4 = new ClientBinaryValue( BYTES4 );
>
> +
> /**
> * Initialize the registries once for the whole test suite
> */
> @BeforeClass
> public static void setup() throws Exception
> {
> - loader = new BootstrapSchemaLoader();
> - oidRegistry = new DefaultOidRegistry();
> - registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
> -
> - // load essential bootstrap schemas
> - Set<Schema> bootstrapSchemas = new HashSet<Schema>();
> - bootstrapSchemas.add( new ApachemetaSchema() );
> - bootstrapSchemas.add( new ApacheSchema() );
> - bootstrapSchemas.add( new CoreSchema() );
> - bootstrapSchemas.add( new SystemSchema() );
> - bootstrapSchemas.add( new InetorgpersonSchema() );
> - bootstrapSchemas.add( new CosineSchema() );
> - loader.loadWithDependencies( bootstrapSchemas, registries );
> -
> - atCN = registries.getAttributeTypeRegistry().lookup( "cn" );
> - atC = registries.getAttributeTypeRegistry().lookup( "c" );
> - atSN = registries.getAttributeTypeRegistry().lookup( "sn" );
> - atPwd = registries.getAttributeTypeRegistry().lookup( "userpassword" );
> + String workingDirectory = System.getProperty( "workingDirectory" );
> +
> + if ( workingDirectory == null )
> + {
> + String path = DefaultServerAttributeTest.class.getResource( "" ).getPath();
> + int targetPos = path.indexOf( "target" );
> + workingDirectory = path.substring( 0, targetPos + 6 );
> + }
> +
> + // Cleanup the target directory
> + File schemaRepository = new File( workingDirectory, "schema" );
> + FileUtils.deleteDirectory( schemaRepository );
> +
> + SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
> + extractor.extractOrCopy( true );
> + loader = new LdifSchemaLoader( schemaRepository );
> + SchemaManager schemaManager = new DefaultSchemaManager( loader );
> +
> + schemaManager.loadAllEnabled();
> +
> + List<Throwable> errors = schemaManager.getErrors();
> +
> + if ( errors.size() != 0 )
> + {
> + // We have inconsistencies : log them and exit.
> + throw new RuntimeException( "Inconsistent schemas : " +
> + ExceptionUtils.printErrors( errors ) );
> + }
> +
> + atCN = schemaManager.lookupAttributeTypeRegistry( "cn" );
> + atC = schemaManager.lookupAttributeTypeRegistry( "c" );
> + atSN = schemaManager.lookupAttributeTypeRegistry( "sn" );
> + atPwd = schemaManager.lookupAttributeTypeRegistry( "userpassword" );
> }
>
> /**
> @@ -573,8 +582,8 @@
> {
> ServerAttribute attr = new DefaultServerAttribute( atCN );
>
> - // No value, this should be valid
> - assertTrue( attr.isValid() );
> + // No value, this should not be valid
> + assertFalse( attr.isValid() );
>
> attr.add( "test", "test2", "A123\\;" );
> assertTrue( attr.isValid() );
> @@ -2097,7 +2106,7 @@
> assertEquals( "cn", dsaSer.getUpId() );
> assertEquals( 0, dsaSer.size() );
> assertTrue( dsaSer.isHR() );
> - assertTrue( dsaSer.isValid() );
> + assertFalse( dsaSer.isValid() );
> }
>
>
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAktYLhgACgkQ2lZVCB08qHEVdACggfSPAGWoIoypmj5WmjF13Ddd
tmYAoKJSgsBFp1Rsa7u0DeaAVcyu6ACf
=Ax6y
-----END PGP SIGNATURE-----