You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2010/12/13 18:37:39 UTC
svn commit: r1045252 -
/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ReadOnlyConfigurationPartition.java
Author: pamarcelot
Date: Mon Dec 13 17:37:38 2010
New Revision: 1045252
URL: http://svn.apache.org/viewvc?rev=1045252&view=rev
Log:
Added a read-only configuration partition which is initialized from a input stream (needed for use in Studio).
Added:
directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ReadOnlyConfigurationPartition.java
Added: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ReadOnlyConfigurationPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ReadOnlyConfigurationPartition.java?rev=1045252&view=auto
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ReadOnlyConfigurationPartition.java (added)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ReadOnlyConfigurationPartition.java Mon Dec 13 17:37:38 2010
@@ -0,0 +1,218 @@
+/*
+ * 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.config;
+
+
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.UUID;
+
+import javax.naming.InvalidNameException;
+
+import org.apache.directory.server.core.interceptor.context.AddOperationContext;
+import org.apache.directory.server.core.interceptor.context.BindOperationContext;
+import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
+import org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext;
+import org.apache.directory.server.core.interceptor.context.MoveOperationContext;
+import org.apache.directory.server.core.interceptor.context.RenameOperationContext;
+import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
+import org.apache.directory.server.core.partition.ldif.AbstractLdifPartition;
+import org.apache.directory.server.xdbm.impl.avl.AvlStore;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.ldif.LdifEntry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
+import org.apache.directory.shared.ldap.name.DN;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+
+
+/**
+ * This class implements the Server Configuration Editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ReadOnlyConfigurationPartition extends AbstractLdifPartition
+{
+ /** The input stream */
+ private InputStream inputStream;
+
+
+ public ReadOnlyConfigurationPartition( InputStream inputStream, SchemaManager schemaManager )
+ {
+ this.inputStream = inputStream;
+ setSchemaManager( schemaManager );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void doInit() throws InvalidNameException, Exception
+ {
+ // Initializing the wrapped partition
+ setWrappedPartition( new AvlPartition() );
+ setId( "config" );
+ setSuffix( new DN( "ou=config" ) );
+ wrappedPartition.setSchemaManager( schemaManager );
+ wrappedPartition.initialize();
+
+ // Getting the search engine
+ searchEngine = wrappedPartition.getSearchEngine();
+
+ // Load LDIF entries
+ loadLdifEntries();
+ }
+
+
+ /**
+ * Loads the LDIF entries from the input stream.
+ *
+ * @throws Exception
+ */
+ private void loadLdifEntries() throws Exception
+ {
+ if ( inputStream != null )
+ {
+ // Initializing the reader and the entry iterator
+ LdifReader reader = new LdifReader( inputStream );
+ Iterator<LdifEntry> itr = reader.iterator();
+
+ // Exiting if there's no entry
+ if ( !itr.hasNext() )
+ {
+ return;
+ }
+
+ // Getting the wrapped partition store
+ AvlStore<Entry> store = wrappedPartition.getStore();
+
+ // Getting the context entry
+ LdifEntry ldifEntry = itr.next();
+ contextEntry = new DefaultEntry( schemaManager, ldifEntry.getEntry() );
+
+ // Checking the context entry
+ if ( suffix.equals( contextEntry.getDn() ) )
+ {
+ addMandatoryOpAt( contextEntry );
+ store.add( contextEntry );
+ }
+ else
+ {
+ throw new LdapException( "The given LDIF file doesn't contain the context entry" );
+ }
+
+ // Iterating on all entries
+ while ( itr.hasNext() )
+ {
+ Entry entry = new DefaultEntry( schemaManager, itr.next().getEntry() );
+ addMandatoryOpAt( entry );
+ store.add( entry );
+ }
+
+ // Closing the reader
+ reader.close();
+ }
+ }
+
+
+ /**
+ * Adds the CSN and UUID attributes to the entry if they are not present.
+ */
+ private void addMandatoryOpAt( Entry entry ) throws LdapException
+ {
+ // entryCSN
+ if ( entry.get( SchemaConstants.ENTRY_CSN_AT ) == null )
+ {
+ entry.add( SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString() );
+ }
+
+ // entryUUID
+ if ( entry.get( SchemaConstants.ENTRY_UUID_AT ) == null )
+ {
+ String uuid = UUID.randomUUID().toString();
+ entry.add( SchemaConstants.ENTRY_UUID_AT, uuid );
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void bind( BindOperationContext bindContext ) throws LdapException
+ {
+ wrappedPartition.bind( bindContext );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void add( AddOperationContext arg0 ) throws LdapException
+ {
+ // Not implemented (Read-Only)
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void delete( Long arg0 ) throws LdapException
+ {
+ // Not implemented (Read-Only)
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void modify( ModifyOperationContext arg0 ) throws LdapException
+ {
+ // Not implemented (Read-Only)
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void move( MoveOperationContext arg0 ) throws LdapException
+ {
+ // Not implemented (Read-Only)
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void moveAndRename( MoveAndRenameOperationContext arg0 ) throws LdapException
+ {
+ // Not implemented (Read-Only)
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void rename( RenameOperationContext arg0 ) throws LdapException
+ {
+ // Not implemented (Read-Only)
+ }
+}