atavs = rdn.iterator(); atavs.hasNext(); /**/)
+ {
+ Ava atav = atavs.next();
+ String type = schemaManager.lookupAttributeTypeRegistry( rdn.getNormType() ).getName();
+ buf.append( type ).append( '=' ).append( atav.getNormValue() );
+
+ if ( atavs.hasNext() )
+ {
+ buf.append( '+' );
+ }
+ }
+
+ newDn = newDn.add( new Rdn( buf.toString() ) );
+ }
+
+ return newDn;
+ }
+
+
+ private boolean filterDenormalized( Entry entry ) throws Exception
+ {
+ denormalizeEntryOpAttrs( entry );
+ return true;
+ }
+}
\ No newline at end of file
Propchange: directory/apacheds/trunk/interceptors/referral/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Oct 14 22:36:08 2011
@@ -0,0 +1,10 @@
+.project
+.classpath
+.settings
+eclipse-classes
+*.log
+*.iml
+*.ipr
+dependency-reduced-pom.xml
+META-INF
+
Added: directory/apacheds/trunk/interceptors/referral/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/referral/pom.xml?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/referral/pom.xml (added)
+++ directory/apacheds/trunk/interceptors/referral/pom.xml Fri Oct 14 22:36:08 2011
@@ -0,0 +1,183 @@
+
+
+
+
+
+ 4.0.0
+
+ org.apache.directory.server
+ apacheds-interceptors
+ 2.0.0-M4-SNAPSHOT
+
+
+ apacheds-interceptors-referral
+ ApacheDS Referral Interceptor
+ jar
+
+
+ Referral interceptor
+
+
+
+
+ org.apache.directory.junit
+ junit-addons
+ test
+
+
+
+ ${project.groupId}
+ apacheds-i18n
+
+
+
+ ${project.groupId}
+ apacheds-core-api
+
+
+
+ ${project.groupId}
+ apacheds-core-api
+ tests
+ test
+
+
+
+ ${project.groupId}
+ apacheds-core-shared
+
+
+
+ commons-collections
+ commons-collections
+
+
+
+ commons-lang
+ commons-lang
+
+
+
+ org.apache.directory.shared
+ shared-ldap-client-api
+
+
+
+ org.apache.directory.shared
+ shared-i18n
+
+
+
+ org.apache.directory.shared
+ shared-ldap-codec-standalone
+ provided
+
+
+
+ org.apache.directory.shared
+ shared-ldap-codec-core
+
+
+
+ org.apache.directory.shared
+ shared-ldap-extras-aci
+
+
+
+ org.apache.directory.shared
+ shared-ldap-extras-trigger
+
+
+
+ org.apache.directory.shared
+ shared-ldap-extras-util
+
+
+
+ org.apache.directory.shared
+ shared-ldap-model
+
+
+
+ org.apache.directory.shared
+ shared-ldap-schema-data
+
+
+
+ org.apache.directory.shared
+ shared-util
+
+
+
+ bouncycastle
+ bcprov-jdk15
+
+
+
+ net.sf.ehcache
+ ehcache-core
+
+
+
+ org.apache.directory.shared
+ shared-ldap-extras-codec
+ provided
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ ${basedir}/target/server-work
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+
+
+ attach-sources
+ verify
+
+ jar
+
+
+
+
+
+
+
+
+ src/main/resources
+ true
+
+ **/*.gif
+
+
+
+
+
+
Added: directory/apacheds/trunk/interceptors/referral/src/main/java/org/apache/directory/server/core/referral/ReferralInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/referral/src/main/java/org/apache/directory/server/core/referral/ReferralInterceptor.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/referral/src/main/java/org/apache/directory/server/core/referral/ReferralInterceptor.java (added)
+++ directory/apacheds/trunk/interceptors/referral/src/main/java/org/apache/directory/server/core/referral/ReferralInterceptor.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,408 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.server.core.referral;
+
+
+import javax.naming.Context;
+
+import org.apache.directory.server.core.shared.ReferralManagerImpl;
+import org.apache.directory.server.core.api.DirectoryService;
+import org.apache.directory.server.core.api.ReferralManager;
+import org.apache.directory.server.core.api.entry.ClonedServerEntry;
+import org.apache.directory.server.core.api.interceptor.BaseInterceptor;
+import org.apache.directory.server.core.api.interceptor.NextInterceptor;
+import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.DeleteOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.MoveAndRenameOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.MoveOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
+import org.apache.directory.server.core.api.partition.PartitionNexus;
+import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.StringValue;
+import org.apache.directory.shared.ldap.model.entry.Value;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.exception.LdapURLEncodingException;
+import org.apache.directory.shared.ldap.model.message.SearchScope;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.url.LdapUrl;
+import org.apache.directory.shared.util.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * An service which is responsible referral handling behavoirs. It manages
+ * referral handling behavoir when the {@link Context#REFERRAL} is implicitly
+ * or explicitly set to "ignore", when set to "throw" and when set to "follow".
+ *
+ * @author Apache Directory Project
+ */
+public class ReferralInterceptor extends BaseInterceptor
+{
+ private static final Logger LOG = LoggerFactory.getLogger( ReferralInterceptor.class );
+
+ private PartitionNexus nexus;
+
+ /** The referralManager */
+ private ReferralManager referralManager;
+
+ /** A normalized form for the SubschemaSubentry Dn */
+ private Dn subschemaSubentryDn;
+
+ static private void checkRefAttributeValue( Value> value ) throws LdapException, LdapURLEncodingException
+ {
+ StringValue ref = (StringValue) value;
+
+ String refVal = ref.getString();
+
+ LdapUrl ldapUrl = new LdapUrl( refVal );
+
+ // We have a LDAP URL, we have to check that :
+ // - we don't have scope specifier
+ // - we don't have filters
+ // - we don't have attribute description list
+ // - we don't have extensions
+ // - the Dn is not empty
+
+ if ( ldapUrl.getScope() != SearchScope.OBJECT )
+ {
+ // This is the default value if we don't have any scope
+ // Let's assume that it's incorrect if we get something
+ // else in the LdapURL
+ String message = I18n.err( I18n.ERR_36 );
+ LOG.error( message );
+ throw new LdapException( message );
+ }
+
+ if ( !Strings.isEmpty(ldapUrl.getFilter()) )
+ {
+ String message = I18n.err( I18n.ERR_37 );
+ LOG.error( message );
+ throw new LdapException( message );
+ }
+
+ if ( ( ldapUrl.getAttributes() != null ) && ( ldapUrl.getAttributes().size() != 0 ) )
+ {
+ String message = I18n.err( I18n.ERR_38 );
+ LOG.error( message );
+ throw new LdapException( message );
+ }
+
+ if ( ( ldapUrl.getExtensions() != null ) && ( ldapUrl.getExtensions().size() != 0 ) )
+ {
+ String message = I18n.err( I18n.ERR_39 );
+ LOG.error( message );
+ throw new LdapException( message );
+ }
+
+ if ( ( ldapUrl.getExtensions() != null ) && ( ldapUrl.getExtensions().size() != 0 ) )
+ {
+ String message = I18n.err( I18n.ERR_40 );
+ LOG.error( message );
+ throw new LdapException( message );
+ }
+
+ Dn dn = ldapUrl.getDn();
+
+ if ( ( dn == null ) || dn.isEmpty() )
+ {
+ String message = I18n.err( I18n.ERR_41 );
+ LOG.error( message );
+ throw new LdapException( message );
+ }
+ }
+
+
+ // This will suppress PMD.EmptyCatchBlock warnings in this method
+ @SuppressWarnings("PMD.EmptyCatchBlock")
+ static private boolean isReferral( Entry entry ) throws LdapException
+ {
+ // Check that the entry is not null, otherwise return FALSE.
+ // This is typically to cover the case where the entry has not
+ // been added into the context because it does not exists.
+ if ( entry == null )
+ {
+ return false;
+ }
+
+ Attribute oc = entry.get( OBJECT_CLASS_AT );
+
+ if ( oc == null )
+ {
+ LOG.warn( "could not find objectClass attribute in entry: " + entry );
+ return false;
+ }
+
+ if ( !oc.contains( SchemaConstants.REFERRAL_OC ) )
+ {
+ return false;
+ }
+ else
+ {
+ // We have a referral ObjectClass, let's check that the ref is
+ // valid, accordingly to the RFC
+
+ // Get the 'ref' attributeType
+ Attribute refAttr = entry.get( SchemaConstants.REF_AT );
+
+ if ( refAttr == null )
+ {
+ // very unlikely, as we have already checked the entry in SchemaInterceptor
+ String message = I18n.err( I18n.ERR_42 );
+ LOG.error( message );
+ throw new LdapException( message );
+ }
+
+ for ( Value> value : refAttr )
+ {
+ try
+ {
+ checkRefAttributeValue( value );
+ }
+ catch ( LdapURLEncodingException luee )
+ {
+ // Either the URL is invalid, or it's not a LDAP URL.
+ // we will just ignore this LdapURL.
+ }
+ }
+
+ return true;
+ }
+ }
+
+
+ public void init( DirectoryService directoryService ) throws LdapException
+ {
+ super.init( directoryService );
+
+ nexus = directoryService.getPartitionNexus();
+
+ // Initialize the referralManager
+ referralManager = new ReferralManagerImpl( directoryService );
+ directoryService.setReferralManager( referralManager );
+
+ Value> subschemaSubentry = nexus.getRootDSE( null ).get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
+ subschemaSubentryDn = directoryService.getDnFactory().create( subschemaSubentry.getString() );
+ }
+
+
+ /**
+ * Add an entry into the server. We have 3 cases :
+ * (1) The entry does not have any parent referral and is not a referral itself
+ * (2) The entry does not have any parent referral and is a referral itself
+ * (3) The entry has a parent referral
+ *
+ * Case (1) is easy : we inject the entry into the server and we are done.
+ * Case (2) is the same as case (1), but we have to update the referral manager.
+ * Case (3) is handled by the LdapProcotol handler, as we have to return a
+ * LdapResult containing a list of this entry's parent's referrals URL, if the
+ * ManageDSAIT control is not present, or the parent's entry if the control
+ * is present.
+ *
+ * Of course, if the entry already exists, nothing will be done, as we will get an
+ * entryAlreadyExists error.
+ *
+ */
+ public void add( NextInterceptor next, AddOperationContext addContext ) throws LdapException
+ {
+ Entry entry = addContext.getEntry();
+
+ // Check if the entry is a referral itself
+ boolean isReferral = isReferral( entry );
+
+ // We add the entry into the server
+ next.add( addContext );
+
+ // If the addition is successful, we update the referralManager
+ if ( isReferral )
+ {
+ // We have to add it to the referralManager
+ referralManager.lockWrite();
+
+ referralManager.addReferral( entry );
+
+ referralManager.unlock();
+ }
+ }
+
+
+ /**
+ * Delete an entry in the server. We have 4 cases :
+ * (1) the entry is not a referral and does not have a parent referral
+ * (2) the entry is not a referral but has a parent referral
+ * (3) the entry is a referral
+ *
+ * Case (1) is handled by removing the entry from the server
+ * In case (2), we return an exception build using the parent referral
+ * For case(3), we remove the entry from the server and remove the referral
+ * from the referral manager.
+ *
+ * If the entry does not exist in the server, we will get a NoSuchObject error
+ */
+ public void delete( NextInterceptor next, DeleteOperationContext deleteContext ) throws LdapException
+ {
+ // First delete the entry into the server
+ next.delete( deleteContext );
+
+ Entry entry = deleteContext.getEntry();
+
+ // Check if the entry exists and is a referral itself
+ // If so, we have to update the referralManager
+ if ( ( entry != null ) && isReferral( entry ) )
+ {
+ // We have to remove it from the referralManager
+ referralManager.lockWrite();
+
+ referralManager.removeReferral( entry );
+
+ referralManager.unlock();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ **/
+ public void move( NextInterceptor next, MoveOperationContext moveContext ) throws LdapException
+ {
+ Dn newDn = moveContext.getNewDn();
+
+ // Check if the entry is a referral itself
+ boolean isReferral = isReferral( moveContext.getOriginalEntry() );
+
+ next.move( moveContext );
+
+ if ( isReferral )
+ {
+ // Update the referralManager
+ referralManager.lockWrite();
+
+ referralManager.addReferral( moveContext.getModifiedEntry() );
+ referralManager.removeReferral( moveContext.getOriginalEntry() );
+
+ referralManager.unlock();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ **/
+ public void moveAndRename( NextInterceptor next, MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException
+ {
+ // Check if the entry is a referral itself
+ boolean isReferral = isReferral( moveAndRenameContext.getOriginalEntry() );
+
+ next.moveAndRename( moveAndRenameContext );
+
+ if ( isReferral )
+ {
+ // Update the referralManager
+ Entry newEntry = moveAndRenameContext.getModifiedEntry();
+
+ referralManager.lockWrite();
+
+ referralManager.addReferral( newEntry );
+ referralManager.removeReferral( moveAndRenameContext.getOriginalEntry() );
+
+ referralManager.unlock();
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ **/
+ public void rename( NextInterceptor next, RenameOperationContext renameContext ) throws LdapException
+ {
+ // Check if the entry is a referral itself
+ boolean isReferral = isReferral( renameContext.getOriginalEntry() );
+
+ next.rename( renameContext );
+
+ if ( isReferral )
+ {
+ // Update the referralManager
+ LookupOperationContext lookupContext = new LookupOperationContext( renameContext.getSession(), renameContext
+ .getNewDn() );
+ lookupContext.setAttrsId( SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+
+ Entry newEntry = nexus.lookup( lookupContext );
+
+ referralManager.lockWrite();
+
+ referralManager.addReferral( newEntry );
+ referralManager.removeReferral( ((ClonedServerEntry)renameContext.getEntry()).getOriginalEntry() );
+
+ referralManager.unlock();
+ }
+ }
+
+
+ /**
+ * Modify an entry in the server.
+ */
+ public void modify( NextInterceptor next, ModifyOperationContext modifyContext ) throws LdapException
+ {
+ Dn dn = modifyContext.getDn();
+
+ // handle a normal modify without following referrals
+ next.modify( modifyContext );
+
+ // Check if we are trying to modify the schema or the rootDSE,
+ // if so, we don't modify the referralManager
+ if ( dn.isEmpty() || dn.equals( subschemaSubentryDn ) )
+ {
+ // Do nothing
+ return;
+ }
+
+ // Update the referralManager. We have to read the entry again
+ // as it has been modified, before updating the ReferralManager
+ // TODO: this can be spare, as we already have the altered entry
+ // into the opContext, but for an unknow reason, this will fail
+ // on eferral tests...
+ LookupOperationContext lookupContext = new LookupOperationContext( modifyContext.getSession(), dn );
+ lookupContext.setAttrsId( SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+
+ Entry newEntry = nexus.lookup( lookupContext );
+
+ // Update the referralManager.
+ // Check that we have the entry, just in case
+ // TODO : entries should be locked until the operation is done on it.
+ if ( newEntry != null )
+ {
+ referralManager.lockWrite();
+
+ if ( referralManager.isReferral( newEntry.getDn() ) )
+ {
+ referralManager.removeReferral( modifyContext.getEntry() );
+ referralManager.addReferral( newEntry );
+ }
+
+ referralManager.unlock();
+ }
+ }
+}
Propchange: directory/apacheds/trunk/interceptors/schema/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Oct 14 22:36:08 2011
@@ -0,0 +1,11 @@
+.project
+.classpath
+.settings
+eclipse-classes
+*.log
+*.iml
+*.ipr
+dependency-reduced-pom.xml
+META-INF
+
+
Added: directory/apacheds/trunk/interceptors/schema/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/schema/pom.xml?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/schema/pom.xml (added)
+++ directory/apacheds/trunk/interceptors/schema/pom.xml Fri Oct 14 22:36:08 2011
@@ -0,0 +1,198 @@
+
+
+
+
+
+ 4.0.0
+
+ org.apache.directory.server
+ apacheds-interceptors
+ 2.0.0-M4-SNAPSHOT
+
+
+ apacheds-interceptors-schema
+ ApacheDS Schema Interceptor
+ jar
+
+
+ Schema interceptor
+
+
+
+
+ org.apache.directory.junit
+ junit-addons
+ test
+
+
+
+ ${project.groupId}
+ apacheds-i18n
+
+
+
+ ${project.groupId}
+ apacheds-core-api
+
+
+
+ ${project.groupId}
+ apacheds-core-api
+ tests
+ test
+
+
+
+ ${project.groupId}
+ apacheds-core-shared
+
+
+
+ ${project.groupId}
+ apacheds-interceptors-authn
+
+
+
+ ${project.groupId}
+ apacheds-interceptors-exception
+
+
+
+ ${project.groupId}
+ apacheds-interceptors-normalization
+
+
+
+ commons-collections
+ commons-collections
+
+
+
+ commons-lang
+ commons-lang
+
+
+
+ org.apache.directory.shared
+ shared-ldap-client-api
+
+
+
+ org.apache.directory.shared
+ shared-i18n
+
+
+
+ org.apache.directory.shared
+ shared-ldap-codec-standalone
+ provided
+
+
+
+ org.apache.directory.shared
+ shared-ldap-codec-core
+
+
+
+ org.apache.directory.shared
+ shared-ldap-extras-aci
+
+
+
+ org.apache.directory.shared
+ shared-ldap-extras-trigger
+
+
+
+ org.apache.directory.shared
+ shared-ldap-extras-util
+
+
+
+ org.apache.directory.shared
+ shared-ldap-model
+
+
+
+ org.apache.directory.shared
+ shared-ldap-schema-data
+
+
+
+ org.apache.directory.shared
+ shared-util
+
+
+
+ bouncycastle
+ bcprov-jdk15
+
+
+
+ net.sf.ehcache
+ ehcache-core
+
+
+
+ org.apache.directory.shared
+ shared-ldap-extras-codec
+ provided
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ ${basedir}/target/server-work
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+
+
+ attach-sources
+ verify
+
+ jar
+
+
+
+
+
+
+
+
+ src/main/resources
+ true
+
+ **/*.gif
+
+
+
+
+
+
Added: directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/AttributesFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/AttributesFactory.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/AttributesFactory.java (added)
+++ directory/apacheds/trunk/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/AttributesFactory.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,420 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.server.core.schema;
+
+
+import java.util.List;
+
+import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.shared.ldap.model.constants.MetaSchemaConstants;
+import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.model.entry.DefaultAttribute;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.apache.directory.shared.ldap.model.schema.DITContentRule;
+import org.apache.directory.shared.ldap.model.schema.DITStructureRule;
+import org.apache.directory.shared.ldap.model.schema.LdapComparator;
+import org.apache.directory.shared.ldap.model.schema.LdapSyntax;
+import org.apache.directory.shared.ldap.model.schema.MatchingRule;
+import org.apache.directory.shared.ldap.model.schema.MatchingRuleUse;
+import org.apache.directory.shared.ldap.model.schema.NameForm;
+import org.apache.directory.shared.ldap.model.schema.Normalizer;
+import org.apache.directory.shared.ldap.model.schema.ObjectClass;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.model.schema.SchemaObject;
+import org.apache.directory.shared.ldap.model.schema.SyntaxChecker;
+import org.apache.directory.shared.ldap.model.schema.registries.Schema;
+import org.apache.directory.shared.util.DateUtils;
+
+
+/**
+ * A factory that generates an entry using the meta schema for schema
+ * elements.
+ *
+ * @author Apache Directory Project
+ */
+public class AttributesFactory
+{
+ public Entry getAttributes( SchemaObject obj, Schema schema, SchemaManager schemaManager ) throws LdapException
+ {
+ if ( obj instanceof LdapSyntax )
+ {
+ return getAttributes( ( LdapSyntax ) obj, schema, schemaManager );
+ }
+ else if ( obj instanceof MatchingRule )
+ {
+ return getAttributes( ( MatchingRule ) obj, schema, schemaManager );
+ }
+ else if ( obj instanceof AttributeType )
+ {
+ return getAttributes( ( AttributeType ) obj, schema, schemaManager );
+ }
+ else if ( obj instanceof ObjectClass )
+ {
+ return getAttributes( ( ObjectClass ) obj, schema, schemaManager );
+ }
+ else if ( obj instanceof MatchingRuleUse )
+ {
+ return getAttributes( ( MatchingRuleUse ) obj, schema, schemaManager );
+ }
+ else if ( obj instanceof DITStructureRule )
+ {
+ return getAttributes( ( DITStructureRule ) obj, schema, schemaManager );
+ }
+ else if ( obj instanceof DITContentRule )
+ {
+ return getAttributes( ( DITContentRule ) obj, schema, schemaManager );
+ }
+ else if ( obj instanceof NameForm )
+ {
+ return getAttributes( ( NameForm ) obj, schema, schemaManager );
+ }
+
+ throw new IllegalArgumentException( I18n.err( I18n.ERR_698, obj.getClass() ) );
+ }
+
+
+ public Entry getAttributes( Schema schema, SchemaManager schemaManager ) throws LdapException
+ {
+ Entry entry = new DefaultEntry( schemaManager );
+
+ entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_SCHEMA_OC );
+ entry.put( SchemaConstants.CN_AT, schema.getSchemaName() );
+ entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+ entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+
+ if ( schema.isDisabled() )
+ {
+ entry.put( MetaSchemaConstants.M_DISABLED_AT, "TRUE" );
+ }
+
+ String[] dependencies = schema.getDependencies();
+
+ if ( dependencies != null && dependencies.length > 0 )
+ {
+ Attribute attr = new DefaultAttribute( schemaManager.getAttributeType( MetaSchemaConstants.M_DEPENDENCIES_AT ) );
+
+ for ( String dependency:dependencies )
+ {
+ attr.add( dependency );
+ }
+
+ entry.put( attr );
+ }
+
+ return entry;
+ }
+
+
+ public Entry getAttributes( SyntaxChecker syntaxChecker, Schema schema, SchemaManager schemaManager )
+ {
+ Entry entry = new DefaultEntry( schemaManager );
+
+ entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_SYNTAX_CHECKER_OC );
+ entry.put( MetaSchemaConstants.M_OID_AT, syntaxChecker.getOid() );
+ entry.put( MetaSchemaConstants.M_FQCN_AT, syntaxChecker.getClass().getName() );
+ entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+ entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+
+ return entry;
+ }
+
+
+ public Entry getAttributes( LdapSyntax syntax, Schema schema, SchemaManager schemaManager ) throws LdapException
+ {
+ Entry entry = new DefaultEntry( schemaManager );
+
+ entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_SYNTAX_OC );
+ entry.put( MetaSchemaConstants.X_HUMAN_READABLE_AT, getBoolean( syntax.isHumanReadable() ) );
+ entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+ entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ injectCommon( syntax, entry, schemaManager );
+
+ return entry;
+ }
+
+
+ public Entry getAttributes( String oid, Normalizer normalizer, Schema schema, SchemaManager schemaManager )
+ {
+ Entry entry = new DefaultEntry( schemaManager );
+
+ entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_NORMALIZER_OC );
+ entry.put( MetaSchemaConstants.M_OID_AT, oid );
+ entry.put( MetaSchemaConstants.M_FQCN_AT, normalizer.getClass().getName() );
+ entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+ entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ return entry;
+ }
+
+
+ public Entry getAttributes( String oid, LdapComparator super Object> comparator, Schema schema, SchemaManager schemaManager )
+ {
+ Entry entry = new DefaultEntry( schemaManager );
+
+ entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_COMPARATOR_OC );
+ entry.put( MetaSchemaConstants.M_OID_AT, oid );
+ entry.put( MetaSchemaConstants.M_FQCN_AT, comparator.getClass().getName() );
+ entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+ entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ return entry;
+ }
+
+
+ /**
+ *
+ * @param matchingRule
+ * @return Attributes
+ * @throws LdapException
+ */
+ public Entry getAttributes( MatchingRule matchingRule, Schema schema, SchemaManager schemaManager ) throws LdapException
+ {
+ Entry entry = new DefaultEntry( schemaManager );
+
+ entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_MATCHING_RULE_OC );
+ entry.put( MetaSchemaConstants.M_SYNTAX_AT, matchingRule.getSyntaxOid() );
+ entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+ entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ injectCommon( matchingRule, entry, schemaManager );
+ return entry;
+ }
+
+
+ public Entry getAttributes( MatchingRuleUse matchingRuleUse, Schema schema, SchemaManager schemaManager )
+ {
+ Entry entry = new DefaultEntry( schemaManager );
+
+ entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "" );
+ entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+ entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ return entry;
+ }
+
+
+ public Entry getAttributes( DITStructureRule dITStructureRule, Schema schema, SchemaManager schemaManager )
+ {
+ Entry entry = new DefaultEntry( schemaManager );
+
+ entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "" );
+ entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+ entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ return entry;
+ }
+
+
+ public Entry getAttributes( DITContentRule dITContentRule, Schema schema, SchemaManager schemaManager )
+ {
+ Entry entry = new DefaultEntry( schemaManager );
+
+ entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "" );
+ entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+ entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ return entry;
+ }
+
+
+ public Entry getAttributes( NameForm nameForm, Schema schema, SchemaManager schemaManager )
+ {
+ Entry entry = new DefaultEntry( schemaManager );
+
+ entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "" );
+ entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+ entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+ return entry;
+ }
+
+
+ /**
+ *
+ * objectclass ( 1.3.6.1.4.1.18060.0.4.0.3.3
+ * NAME 'metaAttributeType'
+ * DESC 'meta definition of the AttributeType object'
+ * SUP metaTop
+ * STRUCTURAL
+ * MUST ( m-name $ m-syntax )
+ * MAY ( m-supAttributeType $ m-obsolete $ m-equality $ m-ordering $
+ * m-substr $ m-singleValue $ m-collective $ m-noUserModification $
+ * m-usage $ m-extensionAttributeType )
+ * )
+ *
+ *
+ * @param attributeType
+ * @return Attributes
+ * @throws LdapException
+ */
+ public Entry getAttributes( AttributeType attributeType, Schema schema, SchemaManager schemaManager ) throws LdapException
+ {
+ Entry entry = new DefaultEntry( schemaManager );
+
+ entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC );
+ entry.put( MetaSchemaConstants.M_SYNTAX_AT, attributeType.getSyntaxOid() );
+ entry.put( MetaSchemaConstants.M_COLLECTIVE_AT, getBoolean( attributeType.isCollective() ) );
+ entry.put( MetaSchemaConstants.M_NO_USER_MODIFICATION_AT, getBoolean( ! attributeType.isUserModifiable() ) );
+ entry.put( MetaSchemaConstants.M_SINGLE_VALUE_AT, getBoolean( attributeType.isSingleValued() ) );
+ entry.put( MetaSchemaConstants.M_USAGE_AT, attributeType.getUsage().toString() );
+ entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+ entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+
+ injectCommon( attributeType, entry, schemaManager );
+
+ String superiorOid = attributeType.getSuperiorOid();
+
+ if ( superiorOid != null )
+ {
+ entry.put( MetaSchemaConstants.M_SUP_ATTRIBUTE_TYPE_AT, superiorOid );
+ }
+
+ if ( attributeType.getEqualityOid() != null )
+ {
+ entry.put( MetaSchemaConstants.M_EQUALITY_AT, attributeType.getEqualityOid() );
+ }
+
+ if ( attributeType.getSubstringOid() != null )
+ {
+ entry.put( MetaSchemaConstants.M_SUBSTR_AT, attributeType.getSubstringOid() );
+ }
+
+ if ( attributeType.getOrderingOid() != null )
+ {
+ entry.put( MetaSchemaConstants.M_ORDERING_AT, attributeType.getOrderingOid() );
+ }
+
+ return entry;
+ }
+
+
+ /**
+ * Creates the attributes of an entry representing an objectClass.
+ *
+ *
+ * objectclass ( 1.3.6.1.4.1.18060.0.4.0.3.2
+ * NAME 'metaObjectClass'
+ * DESC 'meta definition of the objectclass object'
+ * SUP metaTop
+ * STRUCTURAL
+ * MUST m-oid
+ * MAY ( m-name $ m-obsolete $ m-supObjectClass $ m-typeObjectClass $ m-must $
+ * m-may $ m-extensionObjectClass )
+ * )
+ *
+ *
+ * @param objectClass the objectClass to produce a meta schema entry for
+ * @return the attributes of the metaSchema entry representing the objectClass
+ * @throws LdapException if there are any problems
+ */
+ public Entry getAttributes( ObjectClass objectClass, Schema schema, SchemaManager schemaManager ) throws LdapException
+ {
+ Entry entry = new DefaultEntry( schemaManager );
+
+ entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_OBJECT_CLASS_OC );
+ entry.put( MetaSchemaConstants.M_TYPE_OBJECT_CLASS_AT, objectClass.getType().toString() );
+ entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
+ entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
+
+ injectCommon( objectClass, entry, schemaManager );
+
+ // handle the superior objectClasses
+ if ( objectClass.getSuperiorOids() != null && objectClass.getSuperiorOids().size() != 0 )
+ {
+ Attribute attr = new DefaultAttribute( schemaManager.getAttributeType( MetaSchemaConstants.M_SUP_OBJECT_CLASS_AT ) );
+
+ for ( String superior:objectClass.getSuperiorOids() )
+ {
+ attr.add( superior );
+ }
+
+ entry.put( attr );
+ }
+
+ // add the must list
+ if ( objectClass.getMustAttributeTypeOids() != null && objectClass.getMustAttributeTypeOids().size() != 0 )
+ {
+ Attribute attr = new DefaultAttribute( schemaManager.getAttributeType( MetaSchemaConstants.M_MUST_AT ) );
+
+ for ( String mustOid :objectClass.getMustAttributeTypeOids() )
+ {
+ attr.add( mustOid );
+ }
+
+ entry.put( attr );
+ }
+
+ // add the may list
+ if ( objectClass.getMayAttributeTypeOids() != null && objectClass.getMayAttributeTypeOids().size() != 0 )
+ {
+ Attribute attr = new DefaultAttribute( schemaManager.getAttributeType( MetaSchemaConstants.M_MAY_AT ) );
+
+ for ( String mayOid :objectClass.getMayAttributeTypeOids() )
+ {
+ attr.add( mayOid );
+ }
+
+ entry.put( attr );
+ }
+
+ return entry;
+ }
+
+
+ private final void injectCommon( SchemaObject object, Entry entry, SchemaManager schemaManager ) throws LdapException
+ {
+ injectNames( object.getNames(), entry, schemaManager );
+ entry.put( MetaSchemaConstants.M_OBSOLETE_AT, getBoolean( object.isObsolete() ) );
+ entry.put( MetaSchemaConstants.M_OID_AT, object.getOid() );
+
+ if ( object.getDescription() != null )
+ {
+ entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, object.getDescription() );
+ }
+ }
+
+
+ private final void injectNames( List names, Entry entry, SchemaManager schemaManager ) throws LdapException
+ {
+ if ( ( names == null ) || ( names.size() == 0 ) )
+ {
+ return;
+ }
+
+ Attribute attr = new DefaultAttribute( schemaManager.getAttributeType( MetaSchemaConstants.M_NAME_AT ) );
+
+ for ( String name:names )
+ {
+ attr.add( name );
+ }
+
+ entry.put( attr );
+ }
+
+
+ private final String getBoolean( boolean value )
+ {
+ if ( value )
+ {
+ return "TRUE";
+ }
+ else
+ {
+ return "FALSE";
+ }
+ }
+}