Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 92003 invoked from network); 5 Nov 2007 14:33:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Nov 2007 14:33:43 -0000 Received: (qmail 42243 invoked by uid 500); 5 Nov 2007 14:33:31 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 42203 invoked by uid 500); 5 Nov 2007 14:33:31 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 42192 invoked by uid 99); 5 Nov 2007 14:33:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Nov 2007 06:33:31 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Nov 2007 14:33:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 760861A984E; Mon, 5 Nov 2007 06:33:03 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r592014 [5/6] - in /directory/sandbox/felixk: studio-apacheds-configuration-feature/ studio-apacheds-configuration-feature/META-INF/ studio-apacheds-configuration-help/ studio-apacheds-configuration-help/META-INF/ studio-apacheds-configurat... Date: Mon, 05 Nov 2007 14:32:32 -0000 To: commits@directory.apache.org From: felixk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071105143303.760861A984E@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ExtendedOperation.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ExtendedOperation.java?rev=592014&view=auto ============================================================================== --- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ExtendedOperation.java (added) +++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ExtendedOperation.java Mon Nov 5 06:32:20 2007 @@ -0,0 +1,78 @@ +/* + * 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.studio.apacheds.configuration.model; + + +/** + * This class represents an Extended Operation. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class ExtendedOperation +{ + /** The class of the partition */ + private String classType; + + + /** + * Creates a new instance of Partition. + * + * @param classType + * the classType of the partition + */ + public ExtendedOperation( String classType ) + { + this.classType = classType; + } + + + /** + * Gets the class type of the partition. + * + * @return + * the class type of the partition + */ + public String getClassType() + { + return this.classType; + } + + + /** + * Sets the class type of the partition. + * + * @param classType + * the new class type to set + */ + public void setClassType( String classType ) + { + this.classType = classType; + } + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() + { + return classType; + } +} Propchange: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ExtendedOperation.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/IndexedAttribute.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/IndexedAttribute.java?rev=592014&view=auto ============================================================================== --- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/IndexedAttribute.java (added) +++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/IndexedAttribute.java Mon Nov 5 06:32:20 2007 @@ -0,0 +1,108 @@ +/* + * 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.studio.apacheds.configuration.model; + + +/** + * This class represents an Indexed Attribute. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class IndexedAttribute +{ + /** The attribute id */ + private String attributeId; + + /** The cache size */ + private int cacheSize; + + + /** + * Creates a new instance of IndexedAttribute. + * + * @param attributeId + * the attribute id + * @param cacheSize + * the cache size + */ + public IndexedAttribute( String attributeId, int cacheSize ) + { + this.attributeId = attributeId; + this.cacheSize = cacheSize; + } + + + /** + * Gets the attribute id. + * + * @return + * the attribute id + */ + public String getAttributeId() + { + return attributeId; + } + + + /** + * Sets the attribute id. + * + * @param attributeId + * the new attribute id + */ + public void setAttributeId( String attributeId ) + { + this.attributeId = attributeId; + } + + + /** + * Gets the cache size. + * + * @return + * the cache size + */ + public int getCacheSize() + { + return cacheSize; + } + + + /** + * Gets the cache size. + * + * @param cacheSize + * the new cache size + */ + public void setCacheSize( int cacheSize ) + { + this.cacheSize = cacheSize; + } + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() + { + return attributeId + " [" + cacheSize + "]"; + } +} Propchange: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/IndexedAttribute.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/Interceptor.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/Interceptor.java?rev=592014&view=auto ============================================================================== --- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/Interceptor.java (added) +++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/Interceptor.java Mon Nov 5 06:32:20 2007 @@ -0,0 +1,105 @@ +/* + * 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.studio.apacheds.configuration.model; + + +/** + * This class represents an Interceptor. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class Interceptor +{ + /** The name of the interceptor */ + private String name; + + /** The class of the class of the interceptor */ + private String classType; + + + /** + * Creates a new instance of Interceptor. + * + * @param name + * the name of the interceptor + */ + public Interceptor( String name ) + { + this.name = name; + } + + + /** + * Gets the name of the interceptor. + * + * @return + * the name of the interceptor + */ + public String getName() + { + return this.name; + } + + + /** + * Sets the name of the interceptor. + * + * @param name + * the new name to set + */ + public void setName( String name ) + { + this.name = name; + } + + + /** + * Gets the class type of the interceptor. + * + * @return + * the class type of the interceptor + */ + public String getClassType() + { + return classType; + } + + + /** + * Sets the class type of the interceptor. + * + * @param classType + * the new class type to set + */ + public void setClassType( String classType ) + { + this.classType = classType; + } + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() + { + return name; + } +} Propchange: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/Interceptor.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/Partition.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/Partition.java?rev=592014&view=auto ============================================================================== --- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/Partition.java (added) +++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/Partition.java Mon Nov 5 06:32:20 2007 @@ -0,0 +1,314 @@ +/* + * 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.studio.apacheds.configuration.model; + + +import java.util.ArrayList; +import java.util.List; + +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttributes; + + +/** + * This class represents a Partition. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class Partition +{ + /** The name of the partition */ + private String name; + + /** The cache size of the partition */ + private int cacheSize; + + /** The suffix of the partition */ + private String suffix; + + /** The Enable Optimizer flag */ + private boolean enableOptimizer; + + /** The Synchronization On Write flag */ + private boolean synchronizationOnWrite; + + /** The Context Entry */ + private Attributes contextEntry; + + /** The indexed attributes */ + private List indexedAttributes; + + /** The System Partition flag */ + private boolean systemPartition = false; + + + /** + * Creates a new instance of Partition. + */ + public Partition() + { + indexedAttributes = new ArrayList(); + contextEntry = new BasicAttributes( true ); + } + + + /** + * Creates a new instance of Partition. + * + * @param name + * the name of the partition + */ + public Partition( String name ) + { + indexedAttributes = new ArrayList(); + contextEntry = new BasicAttributes( true ); + this.name = name; + } + + + /** + * Gets the name of the partition. + * + * @return + * the name of the partition + */ + public String getName() + { + return this.name; + } + + + /** + * Sets the name of the partition. + * + * @param name + * the new name to set + */ + public void setName( String name ) + { + this.name = name; + } + + + /** + * Gets the cache size. + * + * @return + * the cache size + */ + public int getCacheSize() + { + return cacheSize; + } + + + /** + * Sets the cache size. + * + * @param cacheSize + * the new cache size + */ + public void setCacheSize( int cacheSize ) + { + this.cacheSize = cacheSize; + } + + + /** + * Gets the Context Entry. + * + * @return + * the Content Entry + */ + public Attributes getContextEntry() + { + return contextEntry; + } + + + /** + * Sets the Context Entry + * + * @param contextEntry + * the new Context Entry + */ + public void setContextEntry( Attributes contextEntry ) + { + this.contextEntry = contextEntry; + } + + + /** + * Gets the Enable Optimizer flag. + * + * @return + * the Enable Optimizer flag + */ + public boolean isEnableOptimizer() + { + return enableOptimizer; + } + + + /** + * Sets the Enable Optimizer flag. + * + * @param enableOptimizer + * the new value for the Enable Optimizer flag + */ + public void setEnableOptimizer( boolean enableOptimizer ) + { + this.enableOptimizer = enableOptimizer; + } + + + /** + * Get the Indexed Attributes List. + * + * @return + * the Indexed Attributes List + */ + public List getIndexedAttributes() + { + return indexedAttributes; + } + + + /** + * Set the Indexed Attributes List. + * + * @param indexedAttributes + * the new Indexed Attributes List + */ + public void setIndexedAttributes( List indexedAttributes ) + { + this.indexedAttributes = indexedAttributes; + } + + + /** + * Adds an Indexed Attribute. + * + * @param indexedAttribute + * the Indexed Attribute to add + * @return + * true (as per the general contract of the Collection.add method). + */ + public boolean addIndexedAttribute( IndexedAttribute indexedAttribute ) + { + return indexedAttributes.add( indexedAttribute ); + } + + + /** + * Removes a Indexed Attribute. + * + * @param indexedAttribute + * the Indexed Attribute to remove + * @return + * true if this list contained the specified element. + */ + public boolean removeIndexedAttribute( IndexedAttribute indexedAttribute ) + { + return indexedAttributes.remove( indexedAttribute ); + } + + + /** + * Gets the suffix. + * + * @return + * the suffix + */ + public String getSuffix() + { + return suffix; + } + + + /** + * Sets the suffix. + * + * @param suffix + * the new suffix + */ + public void setSuffix( String suffix ) + { + this.suffix = suffix; + } + + + /** + * Gets the Synchronization On Write flag. + * + * @return + * the Synchronization On Write flag + */ + public boolean isSynchronizationOnWrite() + { + return synchronizationOnWrite; + } + + + /** + * Sets the Synchronization On Write flag. + * + * @param synchronizationOnWrite + * the Synchronization On Write flag + */ + public void setSynchronizationOnWrite( boolean synchronizationOnWrite ) + { + this.synchronizationOnWrite = synchronizationOnWrite; + } + + + /** + * Returns the System Partition flag. + * + * @return + * true if the partition is the System Partition + */ + public boolean isSystemPartition() + { + return systemPartition; + } + + + /** + * Sets the System Partition flag. + * + * @param systemPartition + * the System Partition flag + */ + public void setSystemPartition( boolean systemPartition ) + { + this.systemPartition = systemPartition; + } + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() + { + return name; + } +} Propchange: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/Partition.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfiguration.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfiguration.java?rev=592014&view=auto ============================================================================== --- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfiguration.java (added) +++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfiguration.java Mon Nov 5 06:32:20 2007 @@ -0,0 +1,680 @@ +/* + * 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.studio.apacheds.configuration.model; + + +import java.util.ArrayList; +import java.util.List; + + +/** + * This class represents a Server Configuration. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class ServerConfiguration +{ + /** The path of the Server Configuration file */ + private String path; + + /** The port */ + private int port; + + /** The principal */ + private String principal; + + /** The password */ + private String password; + + /** The flag for Allow Anonymous Access */ + private boolean allowAnonymousAccess; + + /** The Max Time Limit */ + private int maxTimeLimit; + + /** the Max Size Limit */ + private int maxSizeLimit; + + /** The Synchonization Period */ + private long synchronizationPeriod; + + /** The Maximum number of Threads */ + private int maxThreads; + + /** The flag for Enable Access Control */ + private boolean enableAccessControl; + + /** The flag for Enable Kerberos */ + private boolean enableKerberos; + + /** The flag for Enable NTP */ + private boolean enableNTP; + + /** The flag for Enable Change Password */ + private boolean enableChangePassword; + + /** The flag for Denormalize Operational Attributes */ + private boolean denormalizeOpAttr; + + /** The Binary Attributes */ + private List binaryAttributes; + + /** The Partitions */ + private List partitions; + + /** The Interceptors */ + private List interceptors; + + /** The Extended Operations */ + private List extendedOperations; + + + /** + * Creates a new instance of ServerConfiguration. + */ + public ServerConfiguration() + { + partitions = new ArrayList(); + interceptors = new ArrayList(); + extendedOperations = new ArrayList(); + binaryAttributes = new ArrayList(); + } + + + /** + * Gets the Allow Anonymous flag. + * + * @return + * true if the server configuration allows Anonymous Access + */ + public boolean isAllowAnonymousAccess() + { + return allowAnonymousAccess; + } + + + /** + * Sets the Allow Anonymous flag. + * + * @param allowAnonymousAccess + * the new value + */ + public void setAllowAnonymousAccess( boolean allowAnonymousAccess ) + { + this.allowAnonymousAccess = allowAnonymousAccess; + } + + + /** + * Gets the Enable Access Control flag. + * + * @return + * true if Access Control is enabled + */ + public boolean isEnableAccessControl() + { + return enableAccessControl; + } + + + /** + * Sets the Enable Access Control flag. + * + * @param enableAccessControl + * the new value + */ + public void setEnableAccessControl( boolean enableAccessControl ) + { + this.enableAccessControl = enableAccessControl; + } + + + /** + * Gets the Enable Change Password flag. + * + * @return + * true if Change Password is enabled + */ + public boolean isEnableChangePassword() + { + return enableChangePassword; + } + + + /** + * Sets the Enable Change Password flag. + * + * @param enableChangePassword + * the new value + */ + public void setEnableChangePassword( boolean enableChangePassword ) + { + this.enableChangePassword = enableChangePassword; + } + + + /** + * Gets the Enable Kerberos flag. + * + * @return + * true if Kerberos is enabled + */ + public boolean isEnableKerberos() + { + return enableKerberos; + } + + + /** + * Sets the Enable Kerberos flag. + * + * @param enableKerberos + * the new value + */ + public void setEnableKerberos( boolean enableKerberos ) + { + this.enableKerberos = enableKerberos; + } + + + /** + * Gets the Enable NTP flag. + * + * @return + * true if NTP is enabled + */ + public boolean isEnableNTP() + { + return enableNTP; + } + + + /** + * Sets the Enable NTP flag. + * + * @param enableNTP + * the new value + */ + public void setEnableNTP( boolean enableNTP ) + { + this.enableNTP = enableNTP; + } + + + /** + * Gets the Extended Operations List. + * + * @return + * the Extended Operations List + */ + public List getExtendedOperations() + { + return extendedOperations; + } + + + /** + * Sets the Extended Operations List. + * + * @param extendedOperations + * the new value + */ + public void setExtendedOperations( List extendedOperations ) + { + this.extendedOperations = extendedOperations; + } + + + /** + * Adds ab Extended Operation. + * + * @param extendedOperation + * the Extended Operation to add + * @return + * true (as per the general contract of the Collection.add method). + */ + public boolean addExtendedOperation( ExtendedOperation extendedOperation ) + { + return extendedOperations.add( extendedOperation ); + } + + + /** + * Removes an Extended Operation. + * + * @param extendedOperation + * the Extended Operation to remove + * @return + * true if this list contained the specified element. + */ + public boolean removeExtendedOperation( ExtendedOperation extendedOperation ) + { + return extendedOperations.remove( extendedOperation ); + } + + + /** + * Removes all ExtendedOperations. + */ + public void clearExtendedOperations() + { + extendedOperations.clear(); + } + + + /** + * Gets the Interceptors List. + * + * @return + * the Interceptors List + */ + public List getInterceptors() + { + return interceptors; + } + + + /** + * Sets the Interceptors List. + * + * @param interceptors + * the new value + */ + public void setInterceptors( List interceptors ) + { + this.interceptors = interceptors; + } + + + /** + * Adds an Interceptor. + * + * @param interceptor + * the Interceptor to add + * @return + * true (as per the general contract of the Collection.add method). + */ + public boolean addInterceptor( Interceptor interceptor ) + { + return interceptors.add( interceptor ); + } + + + /** + * Removes an Interceptor. + * + * @param interceptor + * the Interceptor to remove + * @return + * true if this list contained the specified element. + */ + public boolean removeInterceptor( Interceptor interceptor ) + { + return interceptors.remove( interceptor ); + } + + + /** + * Removes all interceptors. + */ + public void clearInterceptors() + { + interceptors.clear(); + } + + + /** + * Gets the Maximum Size Limit. + * + * @return + * the Maximum Size Limit + */ + public int getMaxSizeLimit() + { + return maxSizeLimit; + } + + + /** + * Sets the Maximum Size Limit. + * + * @param maxSizeLimit + * the new value + */ + public void setMaxSizeLimit( int maxSizeLimit ) + { + this.maxSizeLimit = maxSizeLimit; + } + + + /** + * Gets the Maximum number of Threads. + * + * @return + * the Maximum number of Threads + */ + public int getMaxThreads() + { + return maxThreads; + } + + + /** + * Sets the Maximum number of Threads + * + * @param maxThreads + * the new value + */ + public void setMaxThreads( int maxThreads ) + { + this.maxThreads = maxThreads; + } + + + /** + * Gets the Maximum Time Limit. + * + * @return + * the Maximum Time Limit + */ + public int getMaxTimeLimit() + { + return maxTimeLimit; + } + + + /** + * Sets the Maximum Time Limit. + * + * @param maxTimeLimit + * the new value + */ + public void setMaxTimeLimit( int maxTimeLimit ) + { + this.maxTimeLimit = maxTimeLimit; + } + + + /** + * Gets the Partitions List. + * + * @return + * the Partitions List + */ + public List getPartitions() + { + return partitions; + } + + + /** + * Sets the Partitions List. + * + * @param partitions + * the new value + */ + public void setPartitions( List partitions ) + { + this.partitions = partitions; + } + + + /** + * Adds a Partition. + * + * @param partition + * the Partition to add + * @return + * true (as per the general contract of the Collection.add method). + */ + public boolean addPartition( Partition partition ) + { + return partitions.add( partition ); + } + + + /** + * Removes a Partition. + * + * @param partition + * the partition to remove + * @return + * true if this list contained the specified element. + */ + public boolean removePartition( Partition partition ) + { + return partitions.remove( partition ); + } + + + /** + * Removes all partitions. + */ + public void clearPartitions() + { + partitions.clear(); + } + + + /** + * Gets the password. + * + * @return + * the password + */ + public String getPassword() + { + return password; + } + + + /** + * Sets the password. + * + * @param password + * the new password + */ + public void setPassword( String password ) + { + this.password = password; + } + + + /** + * Gets the Path of the file corresponding to the ServerConfiguration. + * + * @return + * the Path of the corresponding file + */ + public String getPath() + { + return path; + } + + + /** + * Sets the Path of the file corresponding to the ServerConfiguration. + * + * @param path + * the new value + */ + public void setPath( String path ) + { + this.path = path; + } + + + /** + * Gets the Port. + * + * @return + * the Port + */ + public int getPort() + { + return port; + } + + + /** + * Sets the Port + * + * @param port + * the new value + */ + public void setPort( int port ) + { + this.port = port; + } + + + /** + * Gets the Principal + * + * @return + * the Principal + */ + public String getPrincipal() + { + return principal; + } + + + /** + * Sets the Principal + * + * @param principal + * the new value + */ + public void setPrincipal( String principal ) + { + this.principal = principal; + } + + + /** + * Gets the Synchronization Period. + * + * @return + * the Synchronization Period + */ + public long getSynchronizationPeriod() + { + return synchronizationPeriod; + } + + + /** + * Sets the Synchonization Period. + * + * @param synchronizationPeriod + * the new value + */ + public void setSynchronizationPeriod( long synchronizationPeriod ) + { + this.synchronizationPeriod = synchronizationPeriod; + } + + + /** + * Gets the Denormalize Operational Attributes flag. + * + * @return + * the Denormalize Operational Attributes flag + */ + public boolean isDenormalizeOpAttr() + { + return denormalizeOpAttr; + } + + + /** + * Sets the Denormalize Operational Attributes flag. + * + * @param denormalizeOpAttr + * the new Denormalize Operational Attributes flag + */ + public void setDenormalizeOpAttr( boolean denormalizeOpAttr ) + { + this.denormalizeOpAttr = denormalizeOpAttr; + } + + + /** + * Gets the Binary Attributes List. + * + * @return + * the Binary Attributes List + */ + public List getBinaryAttributes() + { + return binaryAttributes; + } + + + /** + * Sets the Binary Attributes List. + * + * @param binaryAttributes + * the new value + */ + public void setBinaryAttributes( List binaryAttributes ) + { + this.binaryAttributes = binaryAttributes; + } + + + /** + * Adds a Binary Attribute. + * + * @param binaryAttribute + * the Partition to add + * @return + * true (as per the general contract of the Collection.add method). + */ + public boolean addBinaryAttribute( String binaryAttribute ) + { + return binaryAttributes.add( binaryAttribute ); + } + + + /** + * Removes a Binary Attribute. + * + * @param binaryAttribute + * the Binary Attribute to remove + * @return + * true if this list contained the specified element. + */ + public boolean removeBinaryAttribute( String binaryAttribute ) + { + return binaryAttributes.remove( binaryAttribute ); + } + + + /** + * Removes all Binary Attributes. + */ + public void clearBinaryAttributes() + { + binaryAttributes.clear(); + } +} Propchange: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfiguration.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationParser.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationParser.java?rev=592014&view=auto ============================================================================== --- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationParser.java (added) +++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationParser.java Mon Nov 5 06:32:20 2007 @@ -0,0 +1,862 @@ +/* + * 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.studio.apacheds.configuration.model; + + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.naming.NamingException; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttributes; + +import org.apache.directory.shared.ldap.ldif.LdifReader; +import org.apache.directory.shared.ldap.message.AttributesImpl; +import org.apache.directory.shared.ldap.util.StringTools; +import org.dom4j.Attribute; +import org.dom4j.Document; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; + + +/** + * This class represents the Server Configuration Parser. It can be used to parse a 'server.xml' file + * and get Server Configuration Object from it. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class ServerConfigurationParser +{ + /** + * Parses a 'server.xml' file located at the given path and returns + * the corresponding ServerConfiguration Object. + * + * @param path + * the path of the file to parse + * @return + * the corresponding ServerConfiguration Object + * @throws ServerConfigurationParserException + * if an error occurrs when reading the Server Configuration file + */ + public ServerConfiguration parse( String path ) throws ServerConfigurationParserException + { + try + { + SAXReader reader = new SAXReader(); + Document document = reader.read( path ); + + ServerConfiguration serverConfiguration = new ServerConfiguration(); + serverConfiguration.setPath( path ); + + parse( document, serverConfiguration ); + + return serverConfiguration; + } + catch ( Exception e ) + { + if ( e instanceof ServerConfigurationParserException ) + { + throw ( ServerConfigurationParserException ) e; + } + else + { + ServerConfigurationParserException exception = new ServerConfigurationParserException( e.getMessage(), + e.getCause() ); + exception.setStackTrace( e.getStackTrace() ); + throw exception; + } + } + } + + + /** + * Parses a 'server.xml' file located at the given path and returns + * the corresponding ServerConfiguration Object. + * + * @param inputStream + * the Input Stream of the file to parse + * @return + * the corresponding ServerConfiguration Object + * @throws ServerConfigurationParserException + * if an error occurrs when reading the Server Configuration file + */ + public ServerConfiguration parse( InputStream inputStream ) throws ServerConfigurationParserException + { + try + { + SAXReader reader = new SAXReader(); + Document document = reader.read( inputStream ); + + ServerConfiguration serverConfiguration = new ServerConfiguration(); + + parse( document, serverConfiguration ); + + return serverConfiguration; + } + catch ( Exception e ) + { + if ( e instanceof ServerConfigurationParserException ) + { + throw ( ServerConfigurationParserException ) e; + } + else + { + ServerConfigurationParserException exception = new ServerConfigurationParserException( e.getMessage(), + e.getCause() ); + exception.setStackTrace( e.getStackTrace() ); + throw exception; + } + } + } + + + /** + * Parses the Document. + * + * @param document + * the Document + * @param serverConfiguration + * the Server Configuration + * @throws NumberFormatException + * @throws BooleanFormatException + * @throws ServerConfigurationParserException + */ + private void parse( Document document, ServerConfiguration serverConfiguration ) throws NumberFormatException, + BooleanFormatException, ServerConfigurationParserException + { + // Reading the 'Environment' Bean + readEnvironmentBean( document, serverConfiguration ); + + // Reading the 'Configuration' Bean + readConfigurationBean( document, serverConfiguration ); + } + + + /** + * Reads the "Environment" Bean and store its values in the given ServerConfiguration. + * + * @param document + * the document to use + * @param serverConfiguration + * the Server Configuration + */ + private void readEnvironmentBean( Document document, ServerConfiguration serverConfiguration ) + { + Element environmentBean = getBeanElementById( document, "environment" ); + + // Principal + String principal = readEnvironmentBeanProperty( "java.naming.security.principal", environmentBean ); + if ( principal != null ) + { + serverConfiguration.setPrincipal( principal ); + } + + // Password + String password = readEnvironmentBeanProperty( "java.naming.security.credentials", environmentBean ); + if ( password != null ) + { + serverConfiguration.setPassword( password ); + } + + // Binary Attributes + String binaryAttributes = readEnvironmentBeanProperty( "java.naming.ldap.attributes.binary", environmentBean ); + if ( binaryAttributes != null ) + { + String[] attributes = binaryAttributes.split( " " ); + + for( String attribute : attributes) + { + serverConfiguration.addBinaryAttribute( attribute ); + } + } + } + + + /** + * Reads the given property in the 'Environment' Bean and returns it. + * + * @param property + * the property + * @param element + * the Environment Bean Element + * @return + * the value of the property, or null if the property has not been found + */ + private String readEnvironmentBeanProperty( String property, Element element ) + { + Element propertyElement = element.element( "property" ); + if ( propertyElement != null ) + { + Element propsElement = propertyElement.element( "props" ); + if ( propsElement != null ) + { + for ( Iterator i = propsElement.elementIterator( "prop" ); i.hasNext(); ) + { + Element propElement = ( Element ) i.next(); + Attribute keyAttribute = propElement.attribute( "key" ); + if ( keyAttribute != null && ( keyAttribute.getValue().equals( property ) ) ) + { + return propElement.getText(); + } + } + } + } + + return null; + } + + + /** + * Reads the "Configuration" Bean and store its values in the given ServerConfiguration. + * + * @param document + * the document to use + * @param serverConfiguration + * the Server Configuration + * @throws NumberFormatException + * @throws BooleanFormatException + * @throws ServerConfigurationParserException + */ + private void readConfigurationBean( Document document, ServerConfiguration serverConfiguration ) + throws NumberFormatException, BooleanFormatException, ServerConfigurationParserException + { + Element configurationBean = getBeanElementById( document, "configuration" ); + + // LdapPort + String ldapPort = readBeanProperty( "ldapPort", configurationBean ); + if ( ldapPort != null ) + { + serverConfiguration.setPort( Integer.parseInt( ldapPort ) ); + } + + // SynchPeriodMillis + String synchPeriodMillis = readBeanProperty( "synchPeriodMillis", configurationBean ); + if ( synchPeriodMillis != null ) + { + serverConfiguration.setSynchronizationPeriod( Long.parseLong( synchPeriodMillis ) ); + } + + // MaxTimeLimit + String maxTimeLimit = readBeanProperty( "maxTimeLimit", configurationBean ); + if ( maxTimeLimit != null ) + { + serverConfiguration.setMaxTimeLimit( Integer.parseInt( maxTimeLimit ) ); + } + + // MaxSizeLimit + String maxSizeLimit = readBeanProperty( "maxSizeLimit", configurationBean ); + if ( maxSizeLimit != null ) + { + serverConfiguration.setMaxSizeLimit( Integer.parseInt( maxSizeLimit ) ); + } + + // MaxThreads + String maxThreads = readBeanProperty( "maxThreads", configurationBean ); + if ( maxThreads != null ) + { + serverConfiguration.setMaxThreads( Integer.parseInt( maxThreads ) ); + } + + // AllowAnonymousAccess + String allowAnonymousAccess = readBeanProperty( "allowAnonymousAccess", configurationBean ); + if ( allowAnonymousAccess != null ) + { + serverConfiguration.setAllowAnonymousAccess( parseBoolean( allowAnonymousAccess ) ); + } + + // AccessControlEnabled + String accessControlEnabled = readBeanProperty( "accessControlEnabled", configurationBean ); + if ( accessControlEnabled != null ) + { + serverConfiguration.setEnableAccessControl( parseBoolean( accessControlEnabled ) ); + } + + // EnableNtp + String enableNtp = readBeanProperty( "enableNtp", configurationBean ); + if ( enableNtp != null ) + { + serverConfiguration.setEnableNTP( parseBoolean( enableNtp ) ); + } + + // EnableKerberos + String enableKerberos = readBeanProperty( "enableKerberos", configurationBean ); + if ( enableKerberos != null ) + { + serverConfiguration.setEnableKerberos( parseBoolean( enableKerberos ) ); + } + + // EnableChangePassword + String enableChangePassword = readBeanProperty( "enableChangePassword", configurationBean ); + if ( enableChangePassword != null ) + { + serverConfiguration.setEnableChangePassword( parseBoolean( enableChangePassword ) ); + } + + // EnableChangePassword + String denormalizeOpAttrsEnabled = readBeanProperty( "denormalizeOpAttrsEnabled", configurationBean ); + if ( denormalizeOpAttrsEnabled != null ) + { + serverConfiguration.setDenormalizeOpAttr( parseBoolean( denormalizeOpAttrsEnabled ) ); + } + + // SystemPartition + String systemPartitionConfiguration = readBeanProperty( "systemPartitionConfiguration", configurationBean ); + if ( systemPartitionConfiguration != null ) + { + Partition systemPartition = readPartition( document, systemPartitionConfiguration, true ); + if ( systemPartition != null ) + { + serverConfiguration.addPartition( systemPartition ); + } + } + else + { + throw new ServerConfigurationParserException( + "The Server Configuration does not contain a 'systemPartitionConfiguration' property." ); + } + + // Other Partitions + readOtherPartitions( configurationBean, serverConfiguration ); + + // Interceptors + readInterceptors( configurationBean, serverConfiguration ); + + // ExtendedOperations + readExtendedOperations( configurationBean, serverConfiguration ); + } + + + /** + * Reads and adds Partitions (other than the SystemPartition) to the Server Configuration. + * + * @param configurationBean + * the Configuration Bean Element + * @param serverConfiguration + * the Server Configuration + * @throws BooleanFormatException + * @throws NumberFormatException + */ + private void readOtherPartitions( Element configurationBean, ServerConfiguration serverConfiguration ) + throws NumberFormatException, BooleanFormatException + { + Element propertyElement = getBeanPropertyElement( "partitionConfigurations", configurationBean ); + if ( propertyElement != null ) + { + Element setElement = propertyElement.element( "set" ); + if ( setElement != null ) + { + for ( Iterator i = setElement.elementIterator( "ref" ); i.hasNext(); ) + { + Element element = ( Element ) i.next(); + Attribute beanAttribute = element.attribute( "bean" ); + if ( beanAttribute != null ) + { + Partition partition = readPartition( configurationBean.getDocument(), beanAttribute.getValue(), + false ); + if ( partition != null ) + { + serverConfiguration.addPartition( partition ); + } + } + } + } + } + } + + + /** + * Reads the partition associated with the given Bean ID and return it. + * + * @param document + * the document + * @param id + * the Bean ID of the partition + * @param isSystemPartition + * true if this partition is the System Partition + * @return + * the partition associated with the given Bean ID + * @throws BooleanFormatException + */ + private Partition readPartition( Document document, String id, boolean isSystemPartition ) + throws BooleanFormatException, NumberFormatException + { + Element partitionBean = getBeanElementById( document, id ); + if ( partitionBean != null ) + { + Partition partition = new Partition(); + partition.setSystemPartition( isSystemPartition ); + + // Name + String name = readBeanProperty( "name", partitionBean ); + if ( name != null ) + { + partition.setName( name ); + } + + // CacheSize + String cacheSize = readBeanProperty( "cacheSize", partitionBean ); + if ( cacheSize != null ) + { + partition.setCacheSize( Integer.parseInt( cacheSize ) ); + } + + // Suffix + String suffix = readBeanProperty( "suffix", partitionBean ); + if ( suffix != null ) + { + partition.setSuffix( suffix ); + } + + // OptimizerEnabled + String optimizerEnabled = readBeanProperty( "optimizerEnabled", partitionBean ); + if ( optimizerEnabled != null ) + { + partition.setEnableOptimizer( parseBoolean( optimizerEnabled ) ); + } + + // SynchOnWrite + String synchOnWrite = readBeanProperty( "synchOnWrite", partitionBean ); + if ( synchOnWrite != null ) + { + partition.setSynchronizationOnWrite( parseBoolean( synchOnWrite ) ); + } + + // IndexedAttributes + partition.setIndexedAttributes( readPartitionIndexedAttributes( partitionBean ) ); + + // ContextEntry + partition.setContextEntry( readPartitionContextEntry( partitionBean ) ); + + return partition; + } + + return null; + } + + + /** + * Reads the Indexed Attributes of the given Partition Bean Element + * + * @param partitionBean + * the Partition Bean Element + * @return + * the Indexed Attributes + */ + private List readPartitionIndexedAttributes( Element partitionBean ) throws NumberFormatException + { + List indexedAttributes = new ArrayList(); + + Element propertyElement = getBeanPropertyElement( "indexedAttributes", partitionBean ); + if ( propertyElement != null ) + { + Element setElement = propertyElement.element( "set" ); + if ( setElement != null ) + { + for ( Iterator i = setElement.elementIterator( "bean" ); i.hasNext(); ) + { + Element beanElement = ( Element ) i.next(); + IndexedAttribute ia = readIndexedAttribute( beanElement ); + if ( ia != null ) + { + indexedAttributes.add( ia ); + } + } + } + } + + return indexedAttributes; + } + + + /** + * Reads an Indexed Attribute. + * + * @param beanElement + * the Bean Element of the Indexed Attribute + * @return + * the corresponding Indexed Attribute or null if it could not be parsed + * @throws NumberFormatException + */ + private IndexedAttribute readIndexedAttribute( Element beanElement ) throws NumberFormatException + { + Attribute classAttribute = beanElement.attribute( "class" ); + if ( classAttribute != null + && classAttribute.getValue().equals( + "org.apache.directory.server.core.partition.impl.btree.MutableIndexConfiguration" ) ) + { + String attributeId = readBeanProperty( "attributeId", beanElement ); + String cacheSize = readBeanProperty( "cacheSize", beanElement ); + if ( ( attributeId != null ) && ( cacheSize != null ) ) + { + return new IndexedAttribute( attributeId, Integer.parseInt( cacheSize ) ); + } + + } + + return null; + } + + + /** + * Reads the Context Entry of the given Partition Bean Element + * + * @param partitionBean + * the Partition Bean Element + * @return + * the Context Entry + */ + private Attributes readPartitionContextEntry( Element partitionBean ) + { + Element propertyElement = getBeanPropertyElement( "contextEntry", partitionBean ); + if ( propertyElement != null ) + { + Element valueElement = propertyElement.element( "value" ); + if ( valueElement != null ) + { + return readContextEntry( valueElement.getText() ); + } + } + + return new BasicAttributes( true ); + } + + + /** + * Read an entry (without DN) + * + * @param text + * The ldif format text + * @return An Attributes. + */ + private Attributes readContextEntry( String text ) + { + StringReader strIn = new StringReader( text ); + BufferedReader in = new BufferedReader( strIn ); + + String line = null; + Attributes attributes = new AttributesImpl( true ); + + try + { + while ( ( line = ( ( BufferedReader ) in ).readLine() ) != null ) + { + if ( line.length() == 0 ) + { + continue; + } + + String addedLine = line.trim(); + + if ( StringTools.isEmpty( addedLine ) ) + { + continue; + } + + javax.naming.directory.Attribute attribute = LdifReader.parseAttributeValue( addedLine ); + javax.naming.directory.Attribute oldAttribute = attributes.get( attribute.getID() ); + + if ( oldAttribute != null ) + { + try + { + oldAttribute.add( attribute.get() ); + attributes.put( oldAttribute ); + } + catch ( NamingException ne ) + { + // Do nothing + } + } + else + { + attributes.put( attribute ); + } + } + } + catch ( IOException ioe ) + { + // Do nothing : we can't reach this point ! + } + + return attributes; + } + + + /** + * Reads and adds the Interceptors to the Server Configuration. + * + * @param configurationBean + * the Configuration Bean Element + * @param serverConfiguration + * the Server Configuration + */ + private void readInterceptors( Element configurationBean, ServerConfiguration serverConfiguration ) + { + Element propertyElement = getBeanPropertyElement( "interceptorConfigurations", configurationBean ); + if ( propertyElement != null ) + { + Element listElement = propertyElement.element( "list" ); + if ( listElement != null ) + { + for ( Iterator i = listElement.elementIterator( "bean" ); i.hasNext(); ) + { + Interceptor interceptor = readInterceptor( ( Element ) i.next() ); + if ( interceptor != null ) + { + serverConfiguration.addInterceptor( interceptor ); + } + } + } + } + } + + + /** + * Reads an Interceptor. + * + * @param element + * the Interceptor Element + * @return + * the Interceptor or null if it could not be parsed + */ + private Interceptor readInterceptor( Element element ) + { + Attribute classAttribute = element.attribute( "class" ); + if ( classAttribute != null + && classAttribute.getValue().equals( + "org.apache.directory.server.core.configuration.MutableInterceptorConfiguration" ) ) + { + String name = readBeanProperty( "name", element ); + + for ( Iterator i = element.elementIterator( "property" ); i.hasNext(); ) + { + Element propertyElement = ( Element ) i.next(); + Attribute nameAttribute = propertyElement.attribute( "name" ); + if ( nameAttribute != null && ( nameAttribute.getValue().equals( "interceptor" ) ) ) + { + Element beanElement = propertyElement.element( "bean" ); + if ( beanElement != null ) + { + Attribute beanClassAttribute = beanElement.attribute( "class" ); + if ( beanClassAttribute != null ) + { + Interceptor interceptor = new Interceptor( name ); + interceptor.setClassType( beanClassAttribute.getValue() ); + return interceptor; + } + } + } + } + } + + return null; + } + + + /** + * Reads and adds the ExtendedOperations to the Server Configuration. + * + * @param configurationBean + * the Configuration Bean Element + * @param serverConfiguration + * the Server Configuration + */ + private void readExtendedOperations( Element configurationBean, ServerConfiguration serverConfiguration ) + { + Element propertyElement = getBeanPropertyElement( "extendedOperationHandlers", configurationBean ); + if ( propertyElement != null ) + { + Element listElement = propertyElement.element( "list" ); + if ( listElement != null ) + { + for ( Iterator i = listElement.elementIterator( "bean" ); i.hasNext(); ) + { + ExtendedOperation extendedOperation = readExtendedOperation( ( Element ) i.next() ); + if ( extendedOperation != null ) + { + serverConfiguration.addExtendedOperation( extendedOperation ); + } + } + } + } + } + + + /** + * Reads an Extended Operation. + * + * @param element + * the Extended Operation Element + * @return + * the Extended Operation or null if it could not be parsed + */ + private ExtendedOperation readExtendedOperation( Element element ) + { + Attribute classAttribute = element.attribute( "class" ); + if ( classAttribute != null ) + { + return new ExtendedOperation( classAttribute.getValue() ); + } + + return null; + } + + + /** + * Gets the Bean element corresponding to the given ID. + * + * @param document + * the document to use + * @param id + * the id + * @return + * the Bean element corresponding to the given ID or null if the bean was not found + */ + private Element getBeanElementById( Document document, String id ) + { + for ( Iterator i = document.getRootElement().elementIterator( "bean" ); i.hasNext(); ) + { + Element element = ( Element ) i.next(); + Attribute idAttribute = element.attribute( "id" ); + if ( idAttribute != null && ( idAttribute.getValue().equals( id ) ) ) + { + return element; + } + } + + return null; + } + + + /** + * Reads the given property in the Bean and returns its value. + * + * @param property + * the property + * @param element + * the Bean Element + * @return + * the value of the property, or null if the property has not been found + */ + private String readBeanProperty( String property, Element element ) + { + Element propertyElement = getBeanPropertyElement( property, element ); + if ( propertyElement != null ) + { + Attribute valueAttribute = propertyElement.attribute( "value" ); + if ( valueAttribute != null ) + { + return valueAttribute.getValue(); + } + + Attribute refAttribute = propertyElement.attribute( "ref" ); + if ( refAttribute != null ) + { + return refAttribute.getValue(); + } + } + + return null; + } + + + /** + * Gets the given property Element in the the bean + * + * @param property + * the propery + * @param element + * the bean Element + * @return + * the associated property, or null if the property has not been found + */ + private Element getBeanPropertyElement( String property, Element element ) + { + for ( Iterator i = element.elementIterator( "property" ); i.hasNext(); ) + { + Element propertyElement = ( Element ) i.next(); + Attribute nameAttribute = propertyElement.attribute( "name" ); + if ( nameAttribute != null && ( nameAttribute.getValue().equals( property ) ) ) + { + return propertyElement; + } + } + + return null; + } + + + /** + * Parses the string argument as a boolean. + * + * @param s + * a String containing the boolean representation to be parsed + * @return + * the boolean value represented by the argument. + * @throws BooleanFormatException + * if the string does not contain a parsable boolean. + */ + private boolean parseBoolean( String s ) throws BooleanFormatException + { + if ( "true".equals( s ) ) + { + return true; + } + else if ( "false".equals( s ) ) + { + return false; + } + else + { + throw new BooleanFormatException( "The String '" + s + "' could not be parsed as a boolean." ); + } + } + + /** + * Thrown to indicate that the application has attempted to convert a string to a boolean, + * but that the string does not have the appropriate format. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ + private class BooleanFormatException extends Exception + { + /** The Serial Version UID */ + private static final long serialVersionUID = -6426955193802317452L; + + + /** + * Creates a new instance of BooleanFormatException. + * + * @param message + * @param cause + */ + public BooleanFormatException( String message ) + { + super( message ); + } + } +} Propchange: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationParser.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationParserException.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationParserException.java?rev=592014&view=auto ============================================================================== --- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationParserException.java (added) +++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationParserException.java Mon Nov 5 06:32:20 2007 @@ -0,0 +1,64 @@ +/* + * 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.studio.apacheds.configuration.model; + + +/** + * This class represents the Server Configuration Parser Exception, that can be thrown + * when an error is detected when reading the Server Configuration file. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class ServerConfigurationParserException extends Exception +{ + /** The Serial Version UID */ + private static final long serialVersionUID = 7274953743060751973L; + + + /** + * Creates a new instance of ServerConfigurationParserException. + * + * @param message + * the detail message (which is saved for later retrieval by the + * getMessage() method). + */ + public ServerConfigurationParserException( String message ) + { + super( message ); + } + + + /** + * Creates a new instance of ServerConfigurationParserException. + * + * @param message + * the detail message (which is saved for later retrieval by the + * getMessage() method). + * @param cause + * the cause (which is saved for later retrieval by the getCause() + * method). (A null value is permitted, and indicates that the cause + * is nonexistent or unknown.) + */ + public ServerConfigurationParserException( String message, Throwable cause ) + { + super( message, cause ); + } +} Propchange: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationParserException.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationWriter.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationWriter.java?rev=592014&view=auto ============================================================================== --- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationWriter.java (added) +++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationWriter.java Mon Nov 5 06:32:20 2007 @@ -0,0 +1,480 @@ +/* + * 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.studio.apacheds.configuration.model; + + +import java.io.BufferedWriter; +import java.io.FileWriter; + +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.Attributes; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamSource; + +import org.apache.directory.studio.apacheds.configuration.Activator; +import org.dom4j.Document; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; +import org.dom4j.io.DocumentResult; +import org.dom4j.io.DocumentSource; + + +/** + * This class represents the Server Configuration Writer. It can be used to save a 'server.xml' file from. + * + * @author Apache Directory Project + * @version $Rev$, $Date$ + */ +public class ServerConfigurationWriter +{ + /** + * Writes the Server Configuration to disk. + * + * @param serverConfiguration + * the Server Configuration + * @throws ServerConfigurationWriterException + * if an error occurrs when writing the Server Configuration file + */ + public void write( ServerConfiguration serverConfiguration ) throws ServerConfigurationWriterException + { + try + { + BufferedWriter outFile = new BufferedWriter( new FileWriter( serverConfiguration.getPath() ) ); + + Document document = DocumentHelper.createDocument(); + Element root = document.addElement( "beans" ); + + // Environment Bean + createEnvironmentBean( root, serverConfiguration ); + + // Configuration Bean + createConfigurationBean( root, serverConfiguration ); + + // System Partition Configuration Bean + createSystemPartitionConfigurationBean( root, serverConfiguration ); + + // User Partitions Beans + createUserPartitionsConfigurationsBean( root, serverConfiguration ); + + // CustomEditors Bean + createCustomEditorsBean( root ); + + Document stylizedDocuement = styleDocument( document ); + stylizedDocuement.addDocType( "beans", "-//SPRING//DTD BEAN//EN", + "http://www.springframework.org/dtd/spring-beans.dtd" ); + outFile.write( stylizedDocuement.asXML() ); + outFile.close(); + } + catch ( Exception e ) + { + ServerConfigurationWriterException exception = new ServerConfigurationWriterException( e.getMessage(), e + .getCause() ); + exception.setStackTrace( e.getStackTrace() ); + throw exception; + } + } + + + /** + * Creates the Environment Bean + * + * @param root + * the root Element + * @param serverConfiguration + * the Server Configuration + */ + private void createEnvironmentBean( Element root, ServerConfiguration serverConfiguration ) + { + Element environmentBean = root.addElement( "bean" ); + environmentBean.addAttribute( "id", "environment" ); + environmentBean.addAttribute( "class", "org.springframework.beans.factory.config.PropertiesFactoryBean" ); + + Element propertyElement = environmentBean.addElement( "property" ); + propertyElement.addAttribute( "name", "properties" ); + Element propsElement = propertyElement.addElement( "props" ); + + // Key 'java.naming.security.authentication' + Element propElement = propsElement.addElement( "prop" ); + propElement.addAttribute( "key", "java.naming.security.authentication" ); + propElement.setText( "simple" ); + + // Key 'java.naming.security.principal' + propElement = propsElement.addElement( "prop" ); + propElement.addAttribute( "key", "java.naming.security.principal" ); + propElement.setText( serverConfiguration.getPrincipal() ); + + // Key 'java.naming.security.credentials' + propElement = propsElement.addElement( "prop" ); + propElement.addAttribute( "key", "java.naming.security.credentials" ); + propElement.setText( serverConfiguration.getPassword() ); + + // Key 'java.naming.ldap.attributes.binary' + if ( !serverConfiguration.getBinaryAttributes().isEmpty() ) + { + propElement = propsElement.addElement( "prop" ); + propElement.addAttribute( "key", "java.naming.ldap.attributes.binary" ); + StringBuffer sb = new StringBuffer(); + for ( String attribute : serverConfiguration.getBinaryAttributes() ) + { + sb.append( attribute ); + sb.append( " " ); + } + String attributes = sb.toString(); + propElement.setText( attributes.substring( 0, attributes.length() - 1 ) ); + } + + } + + + /** + * Creates the Configuration Bean. + * + * @param root + * the root Element + * @param serverConfiguration + * the Server Configuration + */ + private void createConfigurationBean( Element root, ServerConfiguration serverConfiguration ) + { + Element configurationBean = root.addElement( "bean" ); + configurationBean.addAttribute( "id", "configuration" ); + configurationBean.addAttribute( "class", + "org.apache.directory.server.configuration.MutableServerStartupConfiguration" ); + + // Working directory + Element propertyElement = configurationBean.addElement( "property" ); + propertyElement.addAttribute( "name", "workingDirectory" ); + propertyElement.addAttribute( "value", "example.com" ); // Ask Alex about this value. + + // SynchPeriodMillis + propertyElement = configurationBean.addElement( "property" ); + propertyElement.addAttribute( "name", "synchPeriodMillis" ); + propertyElement.addAttribute( "value", "" + serverConfiguration.getSynchronizationPeriod() ); + + // MaxTimeLimit + propertyElement = configurationBean.addElement( "property" ); + propertyElement.addAttribute( "name", "maxTimeLimit" ); + propertyElement.addAttribute( "value", "" + serverConfiguration.getMaxTimeLimit() ); + + // MaxSizeLimit + propertyElement = configurationBean.addElement( "property" ); + propertyElement.addAttribute( "name", "maxSizeLimit" ); + propertyElement.addAttribute( "value", "" + serverConfiguration.getMaxSizeLimit() ); + + // MaxThreads + propertyElement = configurationBean.addElement( "property" ); + propertyElement.addAttribute( "name", "maxThreads" ); + propertyElement.addAttribute( "value", "" + serverConfiguration.getMaxThreads() ); + + // AllowAnonymousAccess + propertyElement = configurationBean.addElement( "property" ); + propertyElement.addAttribute( "name", "allowAnonymousAccess" ); + propertyElement.addAttribute( "value", "" + serverConfiguration.isAllowAnonymousAccess() ); + + // AccessControlEnabled + propertyElement = configurationBean.addElement( "property" ); + propertyElement.addAttribute( "name", "accessControlEnabled" ); + propertyElement.addAttribute( "value", "" + serverConfiguration.isEnableAccessControl() ); + + // Enable NTP + propertyElement = configurationBean.addElement( "property" ); + propertyElement.addAttribute( "name", "enableNtp" ); + propertyElement.addAttribute( "value", "" + serverConfiguration.isEnableNTP() ); + + // EnableKerberos + propertyElement = configurationBean.addElement( "property" ); + propertyElement.addAttribute( "name", "enableKerberos" ); + propertyElement.addAttribute( "value", "" + serverConfiguration.isEnableKerberos() ); + + // EnableChangePassword + propertyElement = configurationBean.addElement( "property" ); + propertyElement.addAttribute( "name", "enableChangePassword" ); + propertyElement.addAttribute( "value", "" + serverConfiguration.isEnableChangePassword() ); + + // DenormalizeOpAttrsEnabled + propertyElement = configurationBean.addElement( "property" ); + propertyElement.addAttribute( "name", "denormalizeOpAttrsEnabled" ); + propertyElement.addAttribute( "value", "" + serverConfiguration.isDenormalizeOpAttr() ); + + // LdapPort + propertyElement = configurationBean.addElement( "property" ); + propertyElement.addAttribute( "name", "ldapPort" ); + propertyElement.addAttribute( "value", "" + serverConfiguration.getPort() ); + + // SystemPartitionConfiguration + propertyElement = configurationBean.addElement( "property" ); + propertyElement.addAttribute( "name", "systemPartitionConfiguration" ); + propertyElement.addAttribute( "ref", "systemPartitionConfiguration" ); + + // PartitionConfigurations + propertyElement = configurationBean.addElement( "property" ); + propertyElement.addAttribute( "name", "partitionConfigurations" ); + if ( serverConfiguration.getPartitions().size() > 1 ) + { + Element setElement = propertyElement.addElement( "set" ); + int partitionCounter = 1; + for ( Partition partition : serverConfiguration.getPartitions() ) + { + if ( !partition.isSystemPartition() ) + { + setElement.addElement( "ref" ).addAttribute( "bean", "partition-" + partitionCounter ); + partitionCounter++; + } + } + } + + // ExtendedOperationHandlers + propertyElement = configurationBean.addElement( "property" ); + propertyElement.addAttribute( "name", "extendedOperationHandlers" ); + if ( serverConfiguration.getExtendedOperations().size() > 1 ) + { + Element listElement = propertyElement.addElement( "list" ); + for ( ExtendedOperation extendedOperation : serverConfiguration.getExtendedOperations() ) + { + listElement.addElement( "bean" ).addAttribute( "class", extendedOperation.getClassType() ); + } + } + + // InterceptorConfigurations + propertyElement = configurationBean.addElement( "property" ); + propertyElement.addAttribute( "name", "interceptorConfigurations" ); + if ( serverConfiguration.getInterceptors().size() > 1 ) + { + Element listElement = propertyElement.addElement( "list" ); + for ( Interceptor interceptor : serverConfiguration.getInterceptors() ) + { + Element interceptorBeanElement = listElement.addElement( "bean" ); + interceptorBeanElement.addAttribute( "class", + "org.apache.directory.server.core.configuration.MutableInterceptorConfiguration" ); + + Element interceptorPropertyElement = interceptorBeanElement.addElement( "property" ); + interceptorPropertyElement.addAttribute( "name", "name" ); + interceptorPropertyElement.addAttribute( "value", interceptor.getName() ); + + interceptorPropertyElement = interceptorBeanElement.addElement( "property" ); + interceptorPropertyElement.addAttribute( "name", "interceptor" ); + interceptorPropertyElement.addElement( "bean" ).addAttribute( "class", + ( interceptor.getClassType() == null ? "" : interceptor.getClassType() ) ); + } + } + + } + + + /** + * Creates the SystemPartitionConfiguration Bean. + * + * @param root + * the root Element + * @param serverConfiguration + * the Server Configuration + */ + private void createSystemPartitionConfigurationBean( Element root, ServerConfiguration serverConfiguration ) + { + Partition systemPartition = null; + for ( Partition partition : serverConfiguration.getPartitions() ) + { + if ( partition.isSystemPartition() ) + { + systemPartition = partition; + break; + } + } + + if ( systemPartition != null ) + { + createPartitionConfigurationBean( root, systemPartition, "systemPartitionConfiguration" ); + } + } + + + /** + * Creates the UserPartitionConfigurations Bean. + * + * @param root + * the root Element + * @param serverConfiguration + * the Server Configuration + */ + private void createUserPartitionsConfigurationsBean( Element root, ServerConfiguration serverConfiguration ) + { + int counter = 1; + for ( Partition partition : serverConfiguration.getPartitions() ) + { + if ( !partition.isSystemPartition() ) + { + createPartitionConfigurationBean( root, partition, "partition-" + counter ); + counter++; + } + } + } + + + /** + * Creates a Partition Configuration Bean. + * + * @param root + * the root Element + * @param partition + * the Partition + * @param name + * the name to use + */ + private void createPartitionConfigurationBean( Element root, Partition partition, String name ) + { + Element partitionBean = root.addElement( "bean" ); + partitionBean.addAttribute( "id", name ); + partitionBean.addAttribute( "class", + "org.apache.directory.server.core.partition.impl.btree.MutableBTreePartitionConfiguration" ); + + // Name + Element propertyElement = partitionBean.addElement( "property" ); + propertyElement.addAttribute( "name", "name" ); + propertyElement.addAttribute( "value", partition.getName() ); + + // CacheSize + propertyElement = partitionBean.addElement( "property" ); + propertyElement.addAttribute( "name", "cacheSize" ); + propertyElement.addAttribute( "value", "" + partition.getCacheSize() ); + + // Suffix + propertyElement = partitionBean.addElement( "property" ); + propertyElement.addAttribute( "name", "suffix" ); + propertyElement.addAttribute( "value", partition.getSuffix() ); + + // OptimizerEnabled + propertyElement = partitionBean.addElement( "property" ); + propertyElement.addAttribute( "name", "optimizerEnabled" ); + propertyElement.addAttribute( "value", "" + partition.isEnableOptimizer() ); + + // SynchOnWrite + propertyElement = partitionBean.addElement( "property" ); + propertyElement.addAttribute( "name", "synchOnWrite" ); + propertyElement.addAttribute( "value", "" + partition.isSynchronizationOnWrite() ); + + // Indexed Attributes + propertyElement = partitionBean.addElement( "property" ); + propertyElement.addAttribute( "name", "indexedAttributes" ); + if ( partition.getIndexedAttributes().size() > 1 ) + { + Element setElement = propertyElement.addElement( "set" ); + for ( IndexedAttribute indexedAttribute : partition.getIndexedAttributes() ) + { + Element beanElement = setElement.addElement( "bean" ); + beanElement.addAttribute( "class", + "org.apache.directory.server.core.partition.impl.btree.MutableIndexConfiguration" ); + + // AttributeID + Element beanPropertyElement = beanElement.addElement( "property" ); + beanPropertyElement.addAttribute( "name", "attributeId" ); + beanPropertyElement.addAttribute( "value", indexedAttribute.getAttributeId() ); + + // CacheSize + beanPropertyElement = beanElement.addElement( "property" ); + beanPropertyElement.addAttribute( "name", "cacheSize" ); + beanPropertyElement.addAttribute( "value", "" + indexedAttribute.getCacheSize() ); + } + } + + // ContextEntry + propertyElement = partitionBean.addElement( "property" ); + propertyElement.addAttribute( "name", "contextEntry" ); + if ( partition.getContextEntry() != null ) + { + Element valueElement = propertyElement.addElement( "value" ); + + Attributes contextEntry = partition.getContextEntry(); + StringBuffer sb = new StringBuffer(); + NamingEnumeration ne = contextEntry.getAll(); + while ( ne.hasMoreElements() ) + { + Attribute attribute = ( Attribute ) ne.nextElement(); + try + { + NamingEnumeration values = attribute.getAll(); + while ( values.hasMoreElements() ) + { + sb.append( attribute.getID() + ": " + values.nextElement() + "\n" ); + } + } + catch ( NamingException e ) + { + } + } + + valueElement.setText( sb.toString() ); + } + } + + + /** + * Creates the Custom Editors Bean. + * + * @param root + * the root Element + */ + private void createCustomEditorsBean( Element root ) + { + Element customEditorsBean = root.addElement( "bean" ); + customEditorsBean.addAttribute( "class", "org.springframework.beans.factory.config.CustomEditorConfigurer" ); + Element propertyElement = customEditorsBean.addElement( "property" ); + propertyElement.addAttribute( "name", "customEditors" ); + Element mapElement = propertyElement.addElement( "map" ); + Element entryElement = mapElement.addElement( "entry" ); + entryElement.addAttribute( "key", "javax.naming.directory.Attributes" ); + Element entryBeanElement = entryElement.addElement( "bean" ); + entryBeanElement.addAttribute( "class", + "org.apache.directory.server.core.configuration.AttributesPropertyEditor" ); + } + + + /** + * XML Pretty Printer XSLT Tranformation + * + * @param document + * the Dom4j Document + * @return + * the stylized Document + * @throws TransformerException + */ + private Document styleDocument( Document document ) throws TransformerException + { + // load the transformer using JAXP + TransformerFactory factory = TransformerFactory.newInstance(); + Transformer transformer = null; + + transformer = factory + .newTransformer( new StreamSource( Activator.class.getResourceAsStream( "template.xslt" ) ) ); + + // now lets style the given document + DocumentSource source = new DocumentSource( document ); + DocumentResult result = new DocumentResult(); + + transformer.transform( source, result ); + + // return the transformed document + Document transformedDoc = result.getDocument(); + return transformedDoc; + } +} Propchange: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/model/ServerConfigurationWriter.java ------------------------------------------------------------------------------ svn:eol-style = native