Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 49134 invoked from network); 28 Jan 2011 14:57:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 28 Jan 2011 14:57:46 -0000 Received: (qmail 47355 invoked by uid 500); 28 Jan 2011 14:57:46 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 47303 invoked by uid 500); 28 Jan 2011 14:57:45 -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 47296 invoked by uid 99); 28 Jan 2011 14:57:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Jan 2011 14:57:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Jan 2011 14:57:41 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id BA9C023889D5; Fri, 28 Jan 2011 14:57:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1064712 - in /directory/studio/trunk/plugins/schemaeditor: ./ src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/ Date: Fri, 28 Jan 2011 14:57:19 -0000 To: commits@directory.apache.org From: pamarcelot@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110128145719.BA9C023889D5@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: pamarcelot Date: Fri Jan 28 14:57:19 2011 New Revision: 1064712 URL: http://svn.apache.org/viewvc?rev=1064712&view=rev Log: Added a template for a dedicated SchemaLoader. Added a utility class for converting schema elements to entries for the SchemaLoader (AttributeType is implemented, other objects need to be added). Added: directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/ directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoader.java directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoaderUtils.java Modified: directory/studio/trunk/plugins/schemaeditor/pom.xml Modified: directory/studio/trunk/plugins/schemaeditor/pom.xml URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/schemaeditor/pom.xml?rev=1064712&r1=1064711&r2=1064712&view=diff ============================================================================== --- directory/studio/trunk/plugins/schemaeditor/pom.xml (original) +++ directory/studio/trunk/plugins/schemaeditor/pom.xml Fri Jan 28 14:57:19 2011 @@ -117,7 +117,9 @@ org.apache.commons.io;bundle-version="${org.apache.commons.io.version}", org.apache.directory.shared.asn1.api;bundle-version="${org.apache.directory.shared.validversion}", org.apache.directory.shared.ldap;bundle-version="${org.apache.directory.shared.validversion}", + org.apache.directory.shared.ldap.schema;bundle-version="${org.apache.directory.shared.validversion}", org.apache.directory.shared.ldap.schema.converter;bundle-version="${org.apache.directory.shared.validversion}", + org.apache.directory.shared.util;bundle-version="${org.apache.directory.shared.validversion}", org.apache.directory.studio.common.core, org.apache.directory.studio.common.ui, org.apache.directory.studio.connection.core, @@ -166,10 +168,20 @@ org.apache.directory.shared + shared-ldap-schema + provided + + + org.apache.directory.shared shared-ldap-schema-converter provided + org.apache.directory.shared + shared-util + provided + + org.apache.directory.studio org.apache.commons.io provided Added: directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoader.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoader.java?rev=1064712&view=auto ============================================================================== --- directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoader.java (added) +++ directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoader.java Fri Jan 28 14:57:19 2011 @@ -0,0 +1,178 @@ +/* + * 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.schemaeditor.model.schemamanager; + + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +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.registries.AbstractSchemaLoader; +import org.apache.directory.shared.ldap.model.schema.registries.Schema; + + +/** + * Loads schema data from schema files (OpenLDAP and XML formats). + * + * @author Apache Directory Project + */ +public class SchemaEditorSchemaLoader extends AbstractSchemaLoader +{ + /** + * Creates a new instance of SchemaEditorSchemaLoader. + * + * @throws Exception + */ + public SchemaEditorSchemaLoader() + { + initializeSchemas(); + } + + + /** + * Initialize schemas. + */ + private void initializeSchemas() + { + } + + + /** + * {@inheritDoc} + */ + public List loadComparators( Schema... schemas ) throws LdapException, IOException + { + List comparatorList = new ArrayList(); + + return comparatorList; + } + + + /** + * {@inheritDoc} + */ + public List loadSyntaxCheckers( Schema... schemas ) throws LdapException, IOException + { + List syntaxCheckerList = new ArrayList(); + + return syntaxCheckerList; + } + + + /** + * {@inheritDoc} + */ + public List loadNormalizers( Schema... schemas ) throws LdapException, IOException + { + List normalizerList = new ArrayList(); + + return normalizerList; + } + + + /** + * {@inheritDoc} + */ + public List loadMatchingRules( Schema... schemas ) throws LdapException, IOException + { + List matchingRuleList = new ArrayList(); + + return matchingRuleList; + } + + + /** + * {@inheritDoc} + */ + public List loadSyntaxes( Schema... schemas ) throws LdapException, IOException + { + List syntaxList = new ArrayList(); + + return syntaxList; + } + + + /** + * {@inheritDoc} + */ + public List loadAttributeTypes( Schema... schemas ) throws LdapException, IOException + { + List attributeTypeList = new ArrayList(); + + return attributeTypeList; + } + + + /** + * {@inheritDoc} + */ + public List loadMatchingRuleUses( Schema... schemas ) throws LdapException, IOException + { + List matchingRuleUseList = new ArrayList(); + + return matchingRuleUseList; + } + + + /** + * {@inheritDoc} + */ + public List loadNameForms( Schema... schemas ) throws LdapException, IOException + { + List nameFormList = new ArrayList(); + + return nameFormList; + } + + + /** + * {@inheritDoc} + */ + public List loadDitContentRules( Schema... schemas ) throws LdapException, IOException + { + List ditContentRuleList = new ArrayList(); + + return ditContentRuleList; + } + + + /** + * {@inheritDoc} + */ + public List loadDitStructureRules( Schema... schemas ) throws LdapException, IOException + { + List ditStructureRuleList = new ArrayList(); + + return ditStructureRuleList; + } + + + /** + * {@inheritDoc} + */ + public List loadObjectClasses( Schema... schemas ) throws LdapException, IOException + { + List objectClassList = new ArrayList(); + + return objectClassList; + } +} Added: directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoaderUtils.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoaderUtils.java?rev=1064712&view=auto ============================================================================== --- directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoaderUtils.java (added) +++ directory/studio/trunk/plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/schemamanager/SchemaEditorSchemaLoaderUtils.java Fri Jan 28 14:57:19 2011 @@ -0,0 +1,455 @@ +/* + * 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.schemaeditor.model.schemamanager; + + +import java.util.List; + +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.DefaultEntryAttribute; +import org.apache.directory.shared.ldap.model.entry.Entry; +import org.apache.directory.shared.ldap.model.entry.EntryAttribute; +import org.apache.directory.shared.ldap.model.exception.LdapException; +import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException; +import org.apache.directory.shared.ldap.model.name.Dn; +import org.apache.directory.shared.ldap.model.name.Rdn; +import org.apache.directory.shared.ldap.model.schema.AttributeType; +import org.apache.directory.shared.ldap.model.schema.SchemaObject; +import org.apache.directory.shared.ldap.model.schema.UsageEnum; +import org.apache.directory.shared.util.Strings; + + +/** + * This class is a helper class for the {@link SchemaEditorSchemaLoader} class. + * + * @author Apache Directory Project + */ +public class SchemaEditorSchemaLoaderUtils +{ + private static final String M_COLLECTIVE = "m-collective"; + private static final String M_DESCRIPTION = "m-description"; + private static final String M_EQUALITY = "m-equality"; + private static final String M_LENGTH = "m-length"; + private static final String M_NAME = "m-name"; + private static final String M_NO_USER_MODIFICATION = "m-noUserModification"; + private static final String M_OBSOLETE = "m-obsolete"; + private static final String M_OID = "m-oid"; + private static final String M_ORDERING = "m-ordering"; + private static final String M_SINGLE_VALUE = "m-singleValue"; + private static final String M_SUBSTR = "m-substr"; + private static final String M_SUP_ATTRIBUTE_TYPE = "m-supAttributeType"; + private static final String M_SYNTAX = "m-syntax"; + private static final String M_USAGE = "m-usage"; + private static final String TRUE = "TRUE"; + + + /** + * Converts the given attribute type to an equivalent entry representation. + * + * @param attributeType + * the attribute type + * @return + * the attribute type converted to an equivalent entry representation + * @throws LdapException + */ + public Entry toEntry( AttributeType attributeType ) throws LdapException + { + // Creating a blank entry + Entry entry = new DefaultEntry(); + + // Setting calculated DN + entry.setDn( getDn( attributeType, SchemaConstants.ATTRIBUTES_TYPE_PATH ) ); + + // Values common to all schema objects + addSchemaObjectValues( attributeType, SchemaConstants.META_ATTRIBUTE_TYPE_OC, entry ); + + // Superior value + addSuperiorValue( attributeType, entry ); + + // Equality matching rule value + addEqualityValue( attributeType, entry ); + + // Ordering matching rule value + addOrderingValue( attributeType, entry ); + + // Substrings matching rule value + addSubstrValue( attributeType, entry ); + + // Syntax value + addSyntaxValue( attributeType, entry ); + + // Single value value + addSingleValueValue( attributeType, entry ); + + // Collective value + addCollectiveValue( attributeType, entry ); + + // No user modification value + addNoUserModificationValue( attributeType, entry ); + + // Usage value + addUsageValue( attributeType, entry ); + + return entry; + } + + + /** + * Returns the DN for the given schema object in the given object path. + * + * @param schemaObject + * the schema object + * @param objectPath + * the object path + * @return + * the DN for the given schema object in the given object path + * @throws LdapInvalidDnException + */ + private Dn getDn( SchemaObject schemaObject, String objectPath ) throws LdapInvalidDnException + { + return Dn.EMPTY_DN + .add( new Rdn( M_OID, schemaObject.getOid() ) ) + .add( new Rdn( objectPath ) ) + .add( new Rdn( SchemaConstants.CN_AT, schemaObject.getSchemaName() ) ) + .add( new Rdn( SchemaConstants.OU_SCHEMA ) ); + } + + + /** + * Adds the values common to all {@link SchemaObject}(s) to the entry. + * + * @param schemaObject + * the schema object + * @param objectClassValue + * the value for the objectClass attribute + * @param entry + * the entry + * @throws LdapException + */ + private void addSchemaObjectValues( SchemaObject schemaObject, String objectClassValue, Entry entry ) + throws LdapException + { + // ObjectClass + addObjectClassValue( schemaObject, objectClassValue, entry ); + + // OID + addOidValue( schemaObject, entry ); + + // Names + addNamesValue( schemaObject, entry ); + + // Description + addDescriptionValue( schemaObject, entry ); + + // Obsolete (only if true) + addObsoleteValue( schemaObject, entry ); + } + + + /** + * Adds the objectClass value to the entry. + * + * @param schemaObject + * the schema object + * @param objectClassValue + * the value for the objectClass attribute + * @param entry + * the entry + * @throws LdapException + */ + private void addObjectClassValue( SchemaObject schemaObject, String objectClassValue, Entry entry ) + throws LdapException + { + EntryAttribute objectClassAttribute = new DefaultEntryAttribute( SchemaConstants.OBJECT_CLASS_AT ); + entry.add( objectClassAttribute ); + objectClassAttribute.add( SchemaConstants.TOP_OC ); + objectClassAttribute.add( SchemaConstants.META_TOP_OC ); + objectClassAttribute.add( objectClassValue ); + } + + + /** + * Adds the OID value to the entry. + * + * @param schemaObject + * the schema object + * @param entry + * the entry + * @throws LdapException + */ + private void addOidValue( SchemaObject schemaObject, Entry entry ) throws LdapException + { + String oid = schemaObject.getOid(); + if ( !Strings.isEmpty( oid ) ) + { + EntryAttribute attribute = new DefaultEntryAttribute( M_OID, oid ); + entry.add( attribute ); + } + } + + + /** + * Adds the names value to the entry. + * + * @param schemaObject + * the schema object + * @param entry + * the entry + * @throws LdapException + */ + private void addNamesValue( SchemaObject schemaObject, Entry entry ) throws LdapException + { + List names = schemaObject.getNames(); + if ( ( names != null ) && ( names.size() > 0 ) ) + { + EntryAttribute attribute = new DefaultEntryAttribute( M_NAME ); + entry.add( attribute ); + + for ( String name : names ) + { + attribute.add( name ); + } + } + } + + + /** + * Adds the description value to the entry. + * + * @param schemaObject + * the schema object + * @param entry + * the entry + * @throws LdapException + */ + private void addDescriptionValue( SchemaObject schemaObject, Entry entry ) throws LdapException + { + String description = schemaObject.getDescription(); + if ( !Strings.isEmpty( description ) ) + { + EntryAttribute attribute = new DefaultEntryAttribute( M_DESCRIPTION, description ); + entry.add( attribute ); + } + } + + + /** + * Adds the obsolete value to the entry. + * + * @param schemaObject + * the schema object + * @param entry + * the entry + * @throws LdapException + */ + private void addObsoleteValue( SchemaObject schemaObject, Entry entry ) throws LdapException + { + if ( schemaObject.isObsolete() ) + { + EntryAttribute attribute = new DefaultEntryAttribute( M_OBSOLETE, TRUE ); + entry.add( attribute ); + } + } + + + /** + * Adds the superior value. + * + * @param attributeType + * the attribute type + * @param entry + * the entry + * @throws LdapException + */ + private void addSuperiorValue( AttributeType attributeType, Entry entry ) throws LdapException + { + String superior = attributeType.getSuperiorName(); + if ( !Strings.isEmpty( superior ) ) + { + EntryAttribute attribute = new DefaultEntryAttribute( M_SUP_ATTRIBUTE_TYPE, superior ); + entry.add( attribute ); + } + } + + + /** + * Adds the equality matching rule value. + * + * @param attributeType + * the attribute type + * @param entry + * the entry + * @throws LdapException + */ + private void addEqualityValue( AttributeType attributeType, Entry entry ) throws LdapException + { + String equality = attributeType.getEqualityName(); + if ( !Strings.isEmpty( equality ) ) + { + EntryAttribute attribute = new DefaultEntryAttribute( M_EQUALITY, equality ); + entry.add( attribute ); + } + } + + + /** + * Adds the ordering matching rule value. + * + * @param attributeType + * the attribute type + * @param entry + * the entry + * @throws LdapException + */ + private void addOrderingValue( AttributeType attributeType, Entry entry ) throws LdapException + { + String ordering = attributeType.getOrderingName(); + if ( !Strings.isEmpty( ordering ) ) + { + EntryAttribute attribute = new DefaultEntryAttribute( M_ORDERING, ordering ); + entry.add( attribute ); + } + } + + + /** + * Adds the substring matching rule value. + * + * @param attributeType + * the attribute type + * @param entry + * the entry + * @throws LdapException + */ + private void addSubstrValue( AttributeType attributeType, Entry entry ) throws LdapException + { + String substr = attributeType.getSubstringName(); + if ( !Strings.isEmpty( substr ) ) + { + EntryAttribute attribute = new DefaultEntryAttribute( M_SUBSTR, substr ); + entry.add( attribute ); + } + } + + + /** + * Adds the syntax value. + * + * @param attributeType + * the attribute type + * @param entry + * the entry + * @throws LdapException + */ + private void addSyntaxValue( AttributeType attributeType, Entry entry ) throws LdapException + { + String syntax = attributeType.getSyntaxName(); + if ( !Strings.isEmpty( syntax ) ) + { + EntryAttribute attribute = new DefaultEntryAttribute( M_SYNTAX, syntax ); + entry.add( attribute ); + + long syntaxLength = attributeType.getSyntaxLength(); + if ( syntaxLength != -1 ) + { + attribute = new DefaultEntryAttribute( M_LENGTH, "" + syntaxLength ); + entry.add( attribute ); + } + } + } + + + /** + * Adds the single value value. + * + * @param attributeType + * the attribute type + * @param entry + * the entry + * @throws LdapException + */ + private void addSingleValueValue( AttributeType attributeType, Entry entry ) throws LdapException + { + if ( attributeType.isSingleValued() ) + { + EntryAttribute attribute = new DefaultEntryAttribute( M_SINGLE_VALUE, TRUE ); + entry.add( attribute ); + } + } + + + /** + * Adds the collective value. + * + * @param attributeType + * the attribute type + * @param entry + * the entry + * @throws LdapException + */ + private void addCollectiveValue( AttributeType attributeType, Entry entry ) throws LdapException + { + if ( attributeType.isCollective() ) + { + EntryAttribute attribute = new DefaultEntryAttribute( M_COLLECTIVE, TRUE ); + entry.add( attribute ); + } + } + + + /** + * Adds the no user modification value. + * + * @param attributeType + * the attribute type + * @param entry + * the entry + * @throws LdapException + */ + private void addNoUserModificationValue( AttributeType attributeType, Entry entry ) throws LdapException + { + if ( !attributeType.isUserModifiable() ) + { + EntryAttribute attribute = new DefaultEntryAttribute( M_NO_USER_MODIFICATION, TRUE ); + entry.add( attribute ); + } + } + + + /** + * Adds the usage value. + * + * @param attributeType + * the attribute type + * @param entry + * the entry + * @throws LdapException + */ + private void addUsageValue( AttributeType attributeType, Entry entry ) throws LdapException + { + UsageEnum usage = attributeType.getUsage(); + if ( usage != UsageEnum.USER_APPLICATIONS ) + { + EntryAttribute attribute = new DefaultEntryAttribute( M_USAGE, usage.render() ); + entry.add( attribute ); + } + } +}