Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 57099 invoked from network); 5 Nov 2007 16:54:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Nov 2007 16:54:39 -0000 Received: (qmail 17838 invoked by uid 500); 5 Nov 2007 16:54:27 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 17789 invoked by uid 500); 5 Nov 2007 16:54:27 -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 17777 invoked by uid 99); 5 Nov 2007 16:54:27 -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 08:54:27 -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 16:55:00 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 70ACD1A9864; Mon, 5 Nov 2007 08:53:36 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r592082 [16/20] - in /directory/sandbox/felixk/studio-ldapbrowser-core: ./ META-INF/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/studio/ s... Date: Mon, 05 Nov 2007 16:52:07 -0000 To: commits@directory.apache.org From: felixk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071105165336.70ACD1A9864@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/AttributeTypeDescription.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/AttributeTypeDescription.java?rev=592082&view=auto ============================================================================== --- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/AttributeTypeDescription.java (added) +++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/AttributeTypeDescription.java Mon Nov 5 08:51:43 2007 @@ -0,0 +1,541 @@ +/* + * 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.ldapbrowser.core.model.schema; + + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin; + + +public class AttributeTypeDescription extends SchemaPart2 +{ + + private static final long serialVersionUID = 8023296692770420698L; + + public static final String ATTRIBUTE_USAGE_USER_APPLICATIONS = "userApplications"; + + public static final String ATTRIBUTE_USAGE_DISTRIBUTED_OPERATION = "distributedOperation"; + + public static final String ATTRIBUTE_USAGE_DIRECTORY_OPERATION = "directoryOperation"; + + public static final String ATTRIBUTE_USAGE_DSA_OPERATION = "dSAOperation"; + + private String superiorAttributeTypeDescriptionName; + + private String equalityMatchingRuleDescriptionOID; + + private String orderingMatchingRuleDescriptionOID; + + private String substringMatchingRuleDescriptionOID; + + private String syntaxDescriptionNumericOIDPlusLength; + + private boolean isSingleValued; + + private boolean isCollective; + + private boolean isNoUserModification; + + private String usage; + + + public AttributeTypeDescription() + { + super(); + this.superiorAttributeTypeDescriptionName = null; + this.equalityMatchingRuleDescriptionOID = null; + this.orderingMatchingRuleDescriptionOID = null; + this.substringMatchingRuleDescriptionOID = null; + this.syntaxDescriptionNumericOIDPlusLength = null; + this.isSingleValued = false; + this.isCollective = false; + this.isNoUserModification = false; + this.usage = ATTRIBUTE_USAGE_USER_APPLICATIONS; + } + + + public int compareTo( Object o ) + { + if ( o instanceof AttributeTypeDescription ) + { + return this.toString().compareTo( o.toString() ); + } + else + { + throw new ClassCastException( "Object of type " + this.getClass().getName() + " required." ); + } + } + + + /** + * + * @return the equality matching rule OID, may be null + */ + public String getEqualityMatchingRuleDescriptionOID() + { + return equalityMatchingRuleDescriptionOID; + } + + + public void setEqualityMatchingRuleDescriptionOID( String equalityMatchingRuleDescriptionOID ) + { + this.equalityMatchingRuleDescriptionOID = equalityMatchingRuleDescriptionOID; + } + + + /** + * + * @return the equality matching rule description OID of this or the + * superior attribute type description, may be null + */ + public String getEqualityMatchingRuleDescriptionOIDTransitive() + { + if ( this.equalityMatchingRuleDescriptionOID != null ) + { + return this.equalityMatchingRuleDescriptionOID; + } + else if ( this.getExistingSuperiorAttributeTypeDescription() != null ) + { + return this.getExistingSuperiorAttributeTypeDescription().getEqualityMatchingRuleDescriptionOIDTransitive(); + } + else + { + return null; + } + } + + + /** + * + * @return the ordering matching rule OID, may be null + */ + public String getOrderingMatchingRuleDescriptionOID() + { + return orderingMatchingRuleDescriptionOID; + } + + + public void setOrderingMatchingRuleDescriptionOID( String orderingMatchingRuleDescriptionOID ) + { + this.orderingMatchingRuleDescriptionOID = orderingMatchingRuleDescriptionOID; + } + + + /** + * + * @return the ordering matching rule description OID of this or the + * superior attribute type description, may be null + */ + public String getOrderingMatchingRuleDescriptionOIDTransitive() + { + if ( this.orderingMatchingRuleDescriptionOID != null ) + { + return this.orderingMatchingRuleDescriptionOID; + } + else if ( this.getExistingSuperiorAttributeTypeDescription() != null ) + { + return this.getExistingSuperiorAttributeTypeDescription().getOrderingMatchingRuleDescriptionOIDTransitive(); + } + else + { + return null; + } + } + + + /** + * + * @return the substring matching rule OID, may be null + */ + public String getSubstringMatchingRuleDescriptionOID() + { + return substringMatchingRuleDescriptionOID; + } + + + public void setSubstringMatchingRuleDescriptionOID( String substringMatchingRuleDescriptionOID ) + { + this.substringMatchingRuleDescriptionOID = substringMatchingRuleDescriptionOID; + } + + + /** + * + * @return the substring matching rule description OID of this or the + * superior attribute type description, may be null + */ + public String getSubstringMatchingRuleDescriptionOIDTransitive() + { + if ( this.substringMatchingRuleDescriptionOID != null ) + { + return this.substringMatchingRuleDescriptionOID; + } + else if ( this.getExistingSuperiorAttributeTypeDescription() != null ) + { + return this.getExistingSuperiorAttributeTypeDescription() + .getSubstringMatchingRuleDescriptionOIDTransitive(); + } + else + { + return null; + } + } + + + /** + * + * @return the name of the superior (parent) attribute type description + * or null + */ + public String getSuperiorAttributeTypeDescriptionName() + { + return superiorAttributeTypeDescriptionName; + } + + + public void setSuperiorAttributeTypeDescriptionName( String superiorAttributeTypeDescriptionName ) + { + this.superiorAttributeTypeDescriptionName = superiorAttributeTypeDescriptionName; + } + + + /** + * + * @return the syntax description OID, may be null + */ + public String getSyntaxDescriptionNumericOIDPlusLength() + { + return syntaxDescriptionNumericOIDPlusLength; + } + + + public void setSyntaxDescriptionNumericOIDPlusLength( String syntaxDescriptionNumericOIDPlusLength ) + { + this.syntaxDescriptionNumericOIDPlusLength = syntaxDescriptionNumericOIDPlusLength; + } + + + /** + * + * @return the syntax description OID of this or the superior attribute + * type description, may be null + */ + public String getSyntaxDescriptionNumericOIDTransitive() + { + if ( this.syntaxDescriptionNumericOIDPlusLength != null ) + { + if ( this.syntaxDescriptionNumericOIDPlusLength.endsWith( "}" ) + && this.syntaxDescriptionNumericOIDPlusLength.indexOf( "{" ) != -1 ) + { + String syntaxOid = this.syntaxDescriptionNumericOIDPlusLength.substring( 0, + this.syntaxDescriptionNumericOIDPlusLength.indexOf( "{" ) ); + return syntaxOid; + } + else + { + return this.syntaxDescriptionNumericOIDPlusLength; + } + } + else if ( this.getExistingSuperiorAttributeTypeDescription() != null ) + { + return this.getExistingSuperiorAttributeTypeDescription().getSyntaxDescriptionNumericOIDTransitive(); + } + else + { + return null; + } + } + + + /** + * + * @return the syntax length of this or the superior attribute type + * description, may be null + */ + public String getSyntaxDescriptionLengthTransitive() + { + if ( this.syntaxDescriptionNumericOIDPlusLength != null + && this.syntaxDescriptionNumericOIDPlusLength.endsWith( "}" ) + && this.syntaxDescriptionNumericOIDPlusLength.indexOf( "{" ) != -1 ) + { + String length = this.syntaxDescriptionNumericOIDPlusLength.substring( + this.syntaxDescriptionNumericOIDPlusLength.indexOf( "{" ) + 1, + this.syntaxDescriptionNumericOIDPlusLength.indexOf( "}" ) ); + return length; + } + else if ( this.getExistingSuperiorAttributeTypeDescription() != null ) + { + return this.getExistingSuperiorAttributeTypeDescription().getSyntaxDescriptionLengthTransitive(); + } + else + { + return null; + } + } + + + /** + * + * @return the usage, on of ATTRIBUTE_USAGE_... + */ + public String getUsage() + { + return usage; + } + + + public void setUsage( String usage ) + { + if ( usage == null ) + { + this.usage = ATTRIBUTE_USAGE_USER_APPLICATIONS; + } + else + { + this.usage = usage; + } + } + + + /** + * + * @return the single-valued flag + */ + public boolean isSingleValued() + { + return isSingleValued; + } + + + public void setSingleValued( boolean isSingleValued ) + { + this.isSingleValued = isSingleValued; + } + + + /** + * + * @return the collective flag + */ + public boolean isCollective() + { + return isCollective; + } + + + public void setCollective( boolean isCollective ) + { + this.isCollective = isCollective; + } + + + /** + * + * @return the no-user-modification flag + */ + public boolean isNoUserModification() + { + return isNoUserModification; + } + + + public void setNoUserModification( boolean isNoUserModification ) + { + this.isNoUserModification = isNoUserModification; + } + + + /** + * Convenience method to !isBinary(). + * + * @return true if this attribute type or its syntax is defined as + * string + */ + public boolean isString() + { + return !isBinary(); + } + + + /** + * Checks the pre-defined and user-defined binary attribute types. If + * this attribute name or OID is defned as binary true is returned. Then + * the syntax is checked, see LdadSyntaxDescription#isBinary(). + * + * @return true if this attribute type or its syntax is defined as + * binary + */ + public boolean isBinary() + { + // check user-defined binary attributes + Set binaryAttributeOidsAndNames = BrowserCorePlugin.getDefault().getCorePreferences() + .getBinaryAttributeOidsAndNames(); + if ( binaryAttributeOidsAndNames.contains( this.numericOID ) ) + { + return true; + } + for ( int i = 0; i < names.length; i++ ) + { + if ( binaryAttributeOidsAndNames.contains( names[i] ) ) + { + return true; + } + } + + // check syntax (includes user-defined binary syntaxes) + return this.getSyntaxDescription().isBinary(); + } + + + /** + * + * @return the syntax description of this or the superior attribute type + * descripiton, may be the default or a dummy, never null + */ + public LdapSyntaxDescription getSyntaxDescription() + { + + String syntaxOid = this.getSyntaxDescriptionNumericOIDTransitive(); + if ( syntaxOid != null ) + { + return this.getSchema().getLdapSyntaxDescription( syntaxOid ); + } + else + { + return LdapSyntaxDescription.DUMMY; + } + } + + + private AttributeTypeDescription getExistingSuperiorAttributeTypeDescription() + { + if ( this.superiorAttributeTypeDescriptionName != null + && this.schema.hasAttributeTypeDescription( this.superiorAttributeTypeDescriptionName ) ) + { + return this.getSchema().getAttributeTypeDescription( this.superiorAttributeTypeDescriptionName ); + } + else + { + return null; + } + } + + + /** + * + * @return all attribute type description using this attribute type + * description as superior + */ + public AttributeTypeDescription[] getDerivedAttributeTypeDescriptions() + { + Set derivedATDSet = new HashSet(); + for ( Iterator it = this.getSchema().getAtdMapByName().values().iterator(); it.hasNext(); ) + { + AttributeTypeDescription atd = ( AttributeTypeDescription ) it.next(); + String supName = atd.getSuperiorAttributeTypeDescriptionName(); + if ( supName != null && this.getLowerCaseIdentifierSet().contains( supName.toLowerCase() ) ) + { + derivedATDSet.add( atd ); + } + } + AttributeTypeDescription[] derivedAtds = ( AttributeTypeDescription[] ) derivedATDSet + .toArray( new AttributeTypeDescription[0] ); + Arrays.sort( derivedAtds ); + return derivedAtds; + } + + + /** + * + * @return all object class description using this attribute type + * description as must attribute + */ + public ObjectClassDescription[] getUsedAsMust() + { + Set usedAsMustSet = new HashSet(); + for ( Iterator it = this.getSchema().getOcdMapByName().values().iterator(); it.hasNext(); ) + { + ObjectClassDescription ocd = ( ObjectClassDescription ) it.next(); + Set mustSet = toLowerCaseSet( ocd.getMustAttributeTypeDescriptionNamesTransitive() ); + if ( mustSet.removeAll( this.getLowerCaseIdentifierSet() ) ) + { + usedAsMustSet.add( ocd ); + } + } + ObjectClassDescription[] ocds = ( ObjectClassDescription[] ) usedAsMustSet + .toArray( new ObjectClassDescription[0] ); + Arrays.sort( ocds ); + return ocds; + } + + + /** + * + * @return all object class description using this attribute type + * description as may attribute + */ + public ObjectClassDescription[] getUsedAsMay() + { + Set usedAsMaySet = new HashSet(); + for ( Iterator it = this.getSchema().getOcdMapByName().values().iterator(); it.hasNext(); ) + { + ObjectClassDescription ocd = ( ObjectClassDescription ) it.next(); + Set maySet = toLowerCaseSet( ocd.getMayAttributeTypeDescriptionNamesTransitive() ); + if ( maySet.removeAll( this.getLowerCaseIdentifierSet() ) ) + { + usedAsMaySet.add( ocd ); + } + } + ObjectClassDescription[] ocds = ( ObjectClassDescription[] ) usedAsMaySet + .toArray( new ObjectClassDescription[0] ); + Arrays.sort( ocds ); + return ocds; + } + + + /** + * + * @return all matching rule description names this attribute type + * description applies to according to the schemas matching rule + * use descriptions + */ + public String[] getOtherMatchingRuleDescriptionNames() + { + Set otherMatchingRuleSet = new HashSet(); + for ( Iterator it = this.getSchema().getMrudMapByName().values().iterator(); it.hasNext(); ) + { + MatchingRuleUseDescription mrud = ( MatchingRuleUseDescription ) it.next(); + Set atdSet = toLowerCaseSet( mrud.getAppliesAttributeTypeDescriptionOIDs() ); + if ( atdSet.removeAll( this.getLowerCaseIdentifierSet() ) ) + { + otherMatchingRuleSet.addAll( Arrays.asList( mrud.getNames() ) ); + } + } + String[] mrds = ( String[] ) otherMatchingRuleSet.toArray( new String[0] ); + Arrays.sort( mrds ); + return mrds; + } + +} Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/AttributeTypeDescription.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/AttributeValueProviderRelation.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/AttributeValueProviderRelation.java?rev=592082&view=auto ============================================================================== --- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/AttributeValueProviderRelation.java (added) +++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/AttributeValueProviderRelation.java Mon Nov 5 08:51:43 2007 @@ -0,0 +1,67 @@ +/* + * 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.ldapbrowser.core.model.schema; + + +public class AttributeValueProviderRelation +{ + + private String attributeNumericOidOrType; + + private String valueProviderClassname; + + + public AttributeValueProviderRelation() + { + } + + + public AttributeValueProviderRelation( String attributeNumericOidOrName, String valueProviderClassname ) + { + this.attributeNumericOidOrType = attributeNumericOidOrName; + this.valueProviderClassname = valueProviderClassname; + } + + + public String getAttributeNumericOidOrType() + { + return attributeNumericOidOrType; + } + + + public void setAttributeNumericOidOrType( String attributeNumericOidOrType ) + { + this.attributeNumericOidOrType = attributeNumericOidOrType; + } + + + public String getValueProviderClassname() + { + return valueProviderClassname; + } + + + public void setValueProviderClassname( String valueProviderClassname ) + { + this.valueProviderClassname = valueProviderClassname; + } + +} Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/AttributeValueProviderRelation.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinaryAttribute.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinaryAttribute.java?rev=592082&view=auto ============================================================================== --- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinaryAttribute.java (added) +++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinaryAttribute.java Mon Nov 5 08:51:43 2007 @@ -0,0 +1,52 @@ +/* + * 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.ldapbrowser.core.model.schema; + + +public class BinaryAttribute +{ + + private String attributeNumericOidOrName; + + + public BinaryAttribute() + { + } + + + public BinaryAttribute( String attributeNumericOidOrName ) + { + this.attributeNumericOidOrName = attributeNumericOidOrName; + } + + + public String getAttributeNumericOidOrName() + { + return attributeNumericOidOrName; + } + + + public void setAttributeNumericOidOrName( String attributeNumericOidOrName ) + { + this.attributeNumericOidOrName = attributeNumericOidOrName; + } + +} Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinaryAttribute.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinarySyntax.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinarySyntax.java?rev=592082&view=auto ============================================================================== --- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinarySyntax.java (added) +++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinarySyntax.java Mon Nov 5 08:51:43 2007 @@ -0,0 +1,52 @@ +/* + * 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.ldapbrowser.core.model.schema; + + +public class BinarySyntax +{ + + private String syntaxNumericOid; + + + public BinarySyntax() + { + } + + + public BinarySyntax( String syntaxNumericOid ) + { + this.syntaxNumericOid = syntaxNumericOid; + } + + + public String getSyntaxNumericOid() + { + return syntaxNumericOid; + } + + + public void setSyntaxNumericOid( String syntaxNumericOid ) + { + this.syntaxNumericOid = syntaxNumericOid; + } + +} Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/BinarySyntax.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/LdapSyntaxDescription.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/LdapSyntaxDescription.java?rev=592082&view=auto ============================================================================== --- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/LdapSyntaxDescription.java (added) +++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/LdapSyntaxDescription.java Mon Nov 5 08:51:43 2007 @@ -0,0 +1,193 @@ +/* + * 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.ldapbrowser.core.model.schema; + + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin; + + +/* + * Value being represented H-R OBJECT IDENTIFIER + * ================================================================= ACI Item N + * 1.3.6.1.4.1.1466.115.121.1.1 Access Point Y 1.3.6.1.4.1.1466.115.121.1.2 + * Attribute Type Description Y 1.3.6.1.4.1.1466.115.121.1.3 Audio N + * 1.3.6.1.4.1.1466.115.121.1.4 Binary N 1.3.6.1.4.1.1466.115.121.1.5 Bit String + * Y 1.3.6.1.4.1.1466.115.121.1.6 Boolean Y 1.3.6.1.4.1.1466.115.121.1.7 + * Certificate N 1.3.6.1.4.1.1466.115.121.1.8 Certificate List N + * 1.3.6.1.4.1.1466.115.121.1.9 Certificate Pair N 1.3.6.1.4.1.1466.115.121.1.10 + * Country String Y 1.3.6.1.4.1.1466.115.121.1.11 DN Y + * 1.3.6.1.4.1.1466.115.121.1.12 Data Quality Syntax Y + * 1.3.6.1.4.1.1466.115.121.1.13 Delivery Method Y 1.3.6.1.4.1.1466.115.121.1.14 + * Directory String Y 1.3.6.1.4.1.1466.115.121.1.15 DIT Content Rule Description + * Y 1.3.6.1.4.1.1466.115.121.1.16 DIT Structure Rule Description Y + * 1.3.6.1.4.1.1466.115.121.1.17 DL Submit Permission Y + * 1.3.6.1.4.1.1466.115.121.1.18 DSA Quality Syntax Y + * 1.3.6.1.4.1.1466.115.121.1.19 DSE Type Y 1.3.6.1.4.1.1466.115.121.1.20 + * Enhanced Guide Y 1.3.6.1.4.1.1466.115.121.1.21 Facsimile Telephone Number Y + * 1.3.6.1.4.1.1466.115.121.1.22 Fax N 1.3.6.1.4.1.1466.115.121.1.23 Generalized + * Time Y 1.3.6.1.4.1.1466.115.121.1.24 Guide Y 1.3.6.1.4.1.1466.115.121.1.25 + * IA5 String Y 1.3.6.1.4.1.1466.115.121.1.26 INTEGER Y + * 1.3.6.1.4.1.1466.115.121.1.27 JPEG N 1.3.6.1.4.1.1466.115.121.1.28 LDAP + * Syntax Description Y 1.3.6.1.4.1.1466.115.121.1.54 LDAP Schema Definition Y + * 1.3.6.1.4.1.1466.115.121.1.56 LDAP Schema Description Y + * 1.3.6.1.4.1.1466.115.121.1.57 Master And Shadow Access Points Y + * 1.3.6.1.4.1.1466.115.121.1.29 Matching Rule Description Y + * 1.3.6.1.4.1.1466.115.121.1.30 Matching Rule Use Description Y + * 1.3.6.1.4.1.1466.115.121.1.31 Mail Preference Y 1.3.6.1.4.1.1466.115.121.1.32 + * MHS OR Address Y 1.3.6.1.4.1.1466.115.121.1.33 Modify Rights Y + * 1.3.6.1.4.1.1466.115.121.1.55 Name And Optional UID Y + * 1.3.6.1.4.1.1466.115.121.1.34 Name Form Description Y + * 1.3.6.1.4.1.1466.115.121.1.35 Numeric String Y 1.3.6.1.4.1.1466.115.121.1.36 + * Object Class Description Y 1.3.6.1.4.1.1466.115.121.1.37 Octet String Y + * 1.3.6.1.4.1.1466.115.121.1.40 OID Y 1.3.6.1.4.1.1466.115.121.1.38 Other + * Mailbox Y 1.3.6.1.4.1.1466.115.121.1.39 Postal Address Y + * 1.3.6.1.4.1.1466.115.121.1.41 Protocol Information Y + * 1.3.6.1.4.1.1466.115.121.1.42 Presentation Address Y + * 1.3.6.1.4.1.1466.115.121.1.43 Printable String Y + * 1.3.6.1.4.1.1466.115.121.1.44 Substring Assertion Y + * 1.3.6.1.4.1.1466.115.121.1.58 Subtree Specification Y + * 1.3.6.1.4.1.1466.115.121.1.45 Supplier Information Y + * 1.3.6.1.4.1.1466.115.121.1.46 Supplier Or Consumer Y + * 1.3.6.1.4.1.1466.115.121.1.47 Supplier And Consumer Y + * 1.3.6.1.4.1.1466.115.121.1.48 Supported Algorithm N + * 1.3.6.1.4.1.1466.115.121.1.49 Telephone Number Y + * 1.3.6.1.4.1.1466.115.121.1.50 Teletex Terminal Identifier Y + * 1.3.6.1.4.1.1466.115.121.1.51 Telex Number Y 1.3.6.1.4.1.1466.115.121.1.52 + * UTC Time Y 1.3.6.1.4.1.1466.115.121.1.53 + */ + +public class LdapSyntaxDescription extends SchemaPart +{ + + private static final long serialVersionUID = 2740623603305997234L; + + public static final String DN_OID = "1.3.6.1.4.1.1466.115.121.1.12"; + + public static final LdapSyntaxDescription DUMMY; + static + { + DUMMY = new LdapSyntaxDescription(); + DUMMY.setSchema( Schema.DEFAULT_SCHEMA ); + DUMMY.setNumericOID( "" ); + DUMMY.setDesc( "" ); + } + + + public LdapSyntaxDescription() + { + super(); + } + + + public int compareTo( Object o ) + { + if ( o instanceof LdapSyntaxDescription ) + { + return this.toString().compareTo( o.toString() ); + } + else + { + throw new ClassCastException( "Object of type " + this.getClass().getName() + " required." ); + } + } + + + /** + * + * @return the string representation of this syntax description, either + * desc or numericOID + */ + public String toString() + { + if ( this.desc != null && this.desc.length() > 0 ) + { + return this.desc; + } + else if ( numericOID != null ) + { + return this.numericOID; + } + else + { + return ""; + } + } + + + /** + * Convenience method to !isBinary(). + * + * @return true if the syntax is defined as string + */ + public boolean isString() + { + return !isBinary(); + } + + + /** + * Checks the pre-defined and user-defined binary syntax oids. If this + * syntax OID is defned as binary true is returned, false otherwise. + * + * @return true if the syntax is defined as binary + */ + public boolean isBinary() + { + // check user-defined binary syntaxes + Set binarySyntaxOids = BrowserCorePlugin.getDefault().getCorePreferences().getBinarySyntaxOids(); + if ( binarySyntaxOids.contains( this.numericOID ) ) + { + return true; + } + + // default: not binary + return false; + } + + + /** + * + * @return all attribute type description using this syntax description + */ + public AttributeTypeDescription[] getUsedFromAttributeTypeDescription() + { + Set usedFromSet = new HashSet(); + for ( Iterator it = this.getSchema().getAtdMapByName().values().iterator(); it.hasNext(); ) + { + AttributeTypeDescription atd = ( AttributeTypeDescription ) it.next(); + if ( atd.getSyntaxDescriptionNumericOIDTransitive() != null && this.numericOID != null + && atd.getSyntaxDescriptionNumericOIDTransitive().toLowerCase().equals( this.numericOID.toLowerCase() ) ) + { + usedFromSet.add( atd ); + } + } + AttributeTypeDescription[] atds = ( AttributeTypeDescription[] ) usedFromSet + .toArray( new AttributeTypeDescription[0] ); + Arrays.sort( atds ); + return atds; + } + +} Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/LdapSyntaxDescription.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/MatchingRuleDescription.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/MatchingRuleDescription.java?rev=592082&view=auto ============================================================================== --- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/MatchingRuleDescription.java (added) +++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/MatchingRuleDescription.java Mon Nov 5 08:51:43 2007 @@ -0,0 +1,110 @@ +/* + * 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.ldapbrowser.core.model.schema; + + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + + +public class MatchingRuleDescription extends SchemaPart2 +{ + + private static final long serialVersionUID = -8497098446034593329L; + + private String syntaxDescriptionNumericOID; + + + public MatchingRuleDescription() + { + super(); + this.syntaxDescriptionNumericOID = null; + } + + + public int compareTo( Object o ) + { + if ( o instanceof MatchingRuleDescription ) + { + return this.toString().compareTo( o.toString() ); + } + else + { + throw new ClassCastException( "Object of type " + this.getClass().getName() + " required." ); + } + } + + + /** + * + * @return the syntax description OID, may be null + */ + public String getSyntaxDescriptionNumericOID() + { + return syntaxDescriptionNumericOID; + } + + + public void setSyntaxDescriptionNumericOID( String syntaxDescriptionNumericOID ) + { + this.syntaxDescriptionNumericOID = syntaxDescriptionNumericOID; + } + + + /** + * + * @return all attribute type descriptions using this matching rule for + * equality, substring or ordering matching + */ + public AttributeTypeDescription[] getUsedFromAttributeTypeDescriptions() + { + Set usedFromSet = new HashSet(); + for ( Iterator it = this.getSchema().getAtdMapByName().values().iterator(); it.hasNext(); ) + { + AttributeTypeDescription atd = ( AttributeTypeDescription ) it.next(); + if ( atd.getEqualityMatchingRuleDescriptionOIDTransitive() != null + && this.getLowerCaseIdentifierSet().contains( + atd.getEqualityMatchingRuleDescriptionOIDTransitive().toLowerCase() ) ) + { + usedFromSet.add( atd ); + } + if ( atd.getSubstringMatchingRuleDescriptionOIDTransitive() != null + && this.getLowerCaseIdentifierSet().contains( + atd.getSubstringMatchingRuleDescriptionOIDTransitive().toLowerCase() ) ) + { + usedFromSet.add( atd ); + } + if ( atd.getOrderingMatchingRuleDescriptionOIDTransitive() != null + && this.getLowerCaseIdentifierSet().contains( + atd.getOrderingMatchingRuleDescriptionOIDTransitive().toLowerCase() ) ) + { + usedFromSet.add( atd ); + } + } + AttributeTypeDescription[] atds = ( AttributeTypeDescription[] ) usedFromSet + .toArray( new AttributeTypeDescription[0] ); + Arrays.sort( atds ); + return atds; + } + +} Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/MatchingRuleDescription.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/MatchingRuleUseDescription.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/MatchingRuleUseDescription.java?rev=592082&view=auto ============================================================================== --- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/MatchingRuleUseDescription.java (added) +++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/MatchingRuleUseDescription.java Mon Nov 5 08:51:43 2007 @@ -0,0 +1,99 @@ +/* + * 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.ldapbrowser.core.model.schema; + + +public class MatchingRuleUseDescription extends SchemaPart2 +{ + + private static final long serialVersionUID = 2768563387519504369L; + + private String[] appliesAttributeTypeDescriptionOIDs; + + + public MatchingRuleUseDescription() + { + super(); + this.appliesAttributeTypeDescriptionOIDs = new String[0]; + } + + + public int compareTo( Object o ) + { + if ( o instanceof MatchingRuleUseDescription ) + { + return this.toString().compareTo( o.toString() ); + } + else + { + throw new ClassCastException( "Object of type " + this.getClass().getName() + " required." ); + } + } + + + /** + * + * @return the names, may be an empty array + */ + public String[] getNames() + { + return names; + } + + + public void setNames( String[] names ) + { + this.names = names; + } + + + /** + * + * @return the obsolete flag + */ + public boolean isObsolete() + { + return isObsolete; + } + + + public void setObsolete( boolean isObsolete ) + { + this.isObsolete = isObsolete; + } + + + /** + * + * @return the applied attribute type description oids + */ + public String[] getAppliesAttributeTypeDescriptionOIDs() + { + return appliesAttributeTypeDescriptionOIDs; + } + + + public void setAppliesAttributeTypeDescriptionOIDs( String[] appliesAttributeTypeDescriptionOIDs ) + { + this.appliesAttributeTypeDescriptionOIDs = appliesAttributeTypeDescriptionOIDs; + } + +} Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/MatchingRuleUseDescription.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/ObjectClassDescription.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/ObjectClassDescription.java?rev=592082&view=auto ============================================================================== --- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/ObjectClassDescription.java (added) +++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/ObjectClassDescription.java Mon Nov 5 08:51:43 2007 @@ -0,0 +1,345 @@ +/* + * 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.ldapbrowser.core.model.schema; + + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + + +public class ObjectClassDescription extends SchemaPart2 +{ + + private static final long serialVersionUID = 2324990817612632432L; + + public static final String EXTENSIBLEOBJECT_OBJECTCLASSNAME = "extensibleObject"; + + public static final String OBSOLETE = "Obsolete"; + + public static final String ABSTRACT = "Abstract"; + + public static final String STRUCTURAL = "Structural"; + + public static final String AUXILIARY = "Auxiliary"; + + public static final String OC_ALIAS = "alias"; + + public static final String OC_REFERRAL = "referral"; + + public static final String OC_SUBENTRY = "subentry"; + + public static final String OC_COUNTRY = "country"; + + public static final String OC_LOCALITY = "locality"; + + public static final String OC_DCOBJECT = "dcObject"; + + public static final String OC_DOMAIN = "domain"; + + public static final String OC_GROUPOFNAMES = "groupOfNames"; + + public static final String OC_GROUPOFUNIQUENAMES = "groupOfUniqueNames"; + + public static final String OC_POSIXGROUP = "posixGroup"; + + public static final String OC_PERSON = "person"; + + public static final String OC_ORGANIZATIONALPERSON = "organizationalPerson"; + + public static final String OC_INETORGPERSON = "inetOrgPerson"; + + public static final String OC_RESIDENTIALPERSON = "residentialPerson"; + + public static final String OC_PILOTPERSON = "pilotPerson"; + + public static final String OC_NEWPILOTPERSON = "newPilotPerson"; + + public static final String OC_ACCOUNT = "account"; + + public static final String OC_ORGANIZATIONALROLE = "organizationalRole"; + + public static final String OC_ORGANIZATION = "organization"; + + public static final String OC_ORGANIZATIONALUNIT = "organizationalUnit"; + + public static final String OC_PILOTORGANIZATION = "pilotOrganization"; + + public static final String OC_DMD = "dmd"; + + public static final String OC_APPLICATIONPROCESS = "applicationProcess"; + + public static final String OC_APPLICATIONENTITY = "applicationEntity"; + + public static final String OC_ = "organizationalUnit"; + + private boolean isAbstract; + + private boolean isStructural; + + private boolean isAuxiliary; + + private String[] superiorObjectClassDescriptionNames; + + private String[] mustAttributeTypeDescriptionNames; + + private String[] mayAttributeTypeDescriptionNames; + + + public ObjectClassDescription() + { + super(); + this.isAbstract = false; + this.isStructural = true; + this.isAuxiliary = false; + this.superiorObjectClassDescriptionNames = new String[0]; + this.mustAttributeTypeDescriptionNames = new String[0]; + this.mayAttributeTypeDescriptionNames = new String[0]; + } + + + public int compareTo( Object o ) + { + if ( o instanceof ObjectClassDescription ) + { + return this.toString().compareTo( o.toString() ); + } + else + { + throw new ClassCastException( "Object of type " + this.getClass().getName() + " required." ); + } + } + + + /** + * + * @return the abstract flag + */ + public boolean isAbstract() + { + return isAbstract; + } + + + public void setAbstract( boolean isAbstract ) + { + this.isAbstract = isAbstract; + this.isAuxiliary = this.isAuxiliary && !this.isAbstract; + this.isStructural = this.isStructural && !this.isAbstract; + } + + + /** + * + * @return the auxiliary flag + */ + public boolean isAuxiliary() + { + return isAuxiliary; + } + + + public void setAuxiliary( boolean isAuxiliary ) + { + this.isAuxiliary = isAuxiliary; + this.isAbstract = this.isAbstract && !this.isAuxiliary; + this.isStructural = this.isStructural && !this.isAuxiliary; + } + + + /** + * + * @return the structural flag + */ + public boolean isStructural() + { + return isStructural; + } + + + public void setStructural( boolean isStructural ) + { + this.isStructural = isStructural; + this.isAbstract = this.isAbstract && !this.isStructural; + this.isAuxiliary = this.isAuxiliary && !this.isStructural; + } + + + /** + * + * @return the may attribute names, may be an empty array + */ + public String[] getMayAttributeTypeDescriptionNames() + { + return mayAttributeTypeDescriptionNames; + } + + + public void setMayAttributeTypeDescriptionNames( String[] mayAttributeTypeDescriptionNames ) + { + this.mayAttributeTypeDescriptionNames = mayAttributeTypeDescriptionNames; + } + + + /** + * + * @return the may attribute names of this and all superior object class + * definitions + */ + public String[] getMayAttributeTypeDescriptionNamesTransitive() + { + Set maySet = new HashSet(); + for ( int i = 0; i < this.mayAttributeTypeDescriptionNames.length; i++ ) + { + maySet.add( this.mayAttributeTypeDescriptionNames[i] ); + } + ObjectClassDescription[] supOCDs = this.getExistingSuperObjectClassDescription(); + if ( supOCDs != null && supOCDs.length > 0 ) + { + for ( int i = 0; i < supOCDs.length; i++ ) + { + maySet.addAll( Arrays.asList( supOCDs[i].getMayAttributeTypeDescriptionNamesTransitive() ) ); + } + } + String[] mays = ( String[] ) maySet.toArray( new String[maySet.size()] ); + Arrays.sort( mays ); + return mays; + } + + + /** + * + * @return the must attribute names, may be an empty array + */ + public String[] getMustAttributeTypeDescriptionNames() + { + return mustAttributeTypeDescriptionNames; + } + + + public void setMustAttributeTypeDescriptionNames( String[] mustAttributeTypeDescriptionNames ) + { + this.mustAttributeTypeDescriptionNames = mustAttributeTypeDescriptionNames; + } + + + /** + * + * @return the must attribute names of this and all superior object + * class definitions + */ + public String[] getMustAttributeTypeDescriptionNamesTransitive() + { + Set maySet = new HashSet(); + for ( int i = 0; i < this.mustAttributeTypeDescriptionNames.length; i++ ) + { + maySet.add( this.mustAttributeTypeDescriptionNames[i] ); + } + ObjectClassDescription[] supOCDs = this.getExistingSuperObjectClassDescription(); + if ( supOCDs != null && supOCDs.length > 0 ) + { + for ( int i = 0; i < supOCDs.length; i++ ) + { + maySet.addAll( Arrays.asList( supOCDs[i].getMustAttributeTypeDescriptionNamesTransitive() ) ); + } + } + String[] musts = ( String[] ) maySet.toArray( new String[maySet.size()] ); + Arrays.sort( musts ); + return musts; + } + + + /** + * + * @return the names of the superior (parent) object class names, may be + * an empty array + */ + public String[] getSuperiorObjectClassDescriptionNames() + { + return superiorObjectClassDescriptionNames; + } + + + public void setSuperiorObjectClassDescriptionNames( String[] superiorObjectClassDescriptionNames ) + { + this.superiorObjectClassDescriptionNames = superiorObjectClassDescriptionNames; + } + + + /** + * + * @return all superior (parent) object class descriptions, may be an empty array + */ + public ObjectClassDescription[] getSuperiorObjectClassDescriptions() + { + String[] names = getSuperiorObjectClassDescriptionNames(); + ObjectClassDescription[] superiorOcds = new ObjectClassDescription[names.length]; + for ( int i = 0; i < superiorOcds.length; i++ ) + { + superiorOcds[i] = getSchema().getObjectClassDescription( names[i] ); + } + return superiorOcds; + } + + /** + * + * @return all object class description using this object class + * definition as superior + */ + public ObjectClassDescription[] getSubObjectClassDescriptions() + { + Set subOCDSet = new HashSet(); + for ( Iterator it = this.getSchema().getOcdMapByName().values().iterator(); it.hasNext(); ) + { + ObjectClassDescription ocd = ( ObjectClassDescription ) it.next(); + Set supNameSet = toLowerCaseSet( ocd.getSuperiorObjectClassDescriptionNames() ); + if ( supNameSet.removeAll( this.getLowerCaseIdentifierSet() ) ) + { + subOCDSet.add( ocd ); + } + } + ObjectClassDescription[] subOcds = ( ObjectClassDescription[] ) subOCDSet + .toArray( new ObjectClassDescription[0] ); + Arrays.sort( subOcds ); + return subOcds; + } + + + private ObjectClassDescription[] getExistingSuperObjectClassDescription() + { + List supList = new ArrayList(); + for ( int i = 0; i < this.superiorObjectClassDescriptionNames.length; i++ ) + { + if ( this.schema.hasObjectClassDescription( this.superiorObjectClassDescriptionNames[i] ) ) + { + supList.add( this.schema.getObjectClassDescription( this.superiorObjectClassDescriptionNames[i] ) ); + } + } + ObjectClassDescription[] supOcds = ( ObjectClassDescription[] ) supList + .toArray( new ObjectClassDescription[supList.size()] ); + Arrays.sort( supOcds ); + return supOcds; + } + +} Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/ObjectClassDescription.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/Schema.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/Schema.java?rev=592082&view=auto ============================================================================== --- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/Schema.java (added) +++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/Schema.java Mon Nov 5 08:51:43 2007 @@ -0,0 +1,902 @@ +/* + * 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.ldapbrowser.core.model.schema; + + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.Serializable; +import java.io.StringReader; +import java.io.Writer; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.directory.shared.ldap.name.LdapDN; +import org.apache.directory.studio.ldapbrowser.core.model.AttributeDescription; +import org.apache.directory.studio.ldapbrowser.core.model.IAttribute; +import org.apache.directory.studio.ldapbrowser.core.model.ldif.LdifEnumeration; +import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContainer; +import org.apache.directory.studio.ldapbrowser.core.model.ldif.container.LdifContentRecord; +import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifAttrValLine; +import org.apache.directory.studio.ldapbrowser.core.model.ldif.parser.LdifParser; +import org.apache.directory.studio.ldapbrowser.core.model.schema.parser.SchemaLexer; +import org.apache.directory.studio.ldapbrowser.core.model.schema.parser.SchemaParser; + + +public class Schema implements Serializable +{ + + private static final long serialVersionUID = 2439355717760227167L; + + public static final String SCHEMA_FILTER = "(objectClass=subschema)"; + + public static final String SCHEMA_ATTRIBUTE_OBJECTCLASSES = "objectClasses"; + + public static final String SCHEMA_ATTRIBUTE_ATTRIBUTETYPES = "attributeTypes"; + + public static final String SCHEMA_ATTRIBUTE_LDAPSYNTAXES = "ldapSyntaxes"; + + public static final String SCHEMA_ATTRIBUTE_MATCHINGRULES = "matchingRules"; + + public static final String SCHEMA_ATTRIBUTE_MATCHINGRULEUSE = "matchingRuleUse"; + + public static final Schema DEFAULT_SCHEMA; + static + { + Schema defaultSchema = null; + + try + { + URL url = Schema.class.getClassLoader().getResource( + "default_schema.ldif" ); + InputStream is = url.openStream(); + Reader reader = new InputStreamReader( is ); + + defaultSchema = new Schema(); + defaultSchema.defaultSchema = true; + defaultSchema.loadFromLdif( reader ); + } + catch ( Exception e ) + { + e.printStackTrace(); + } + + DEFAULT_SCHEMA = defaultSchema; + } + + private boolean defaultSchema = false; + + + public boolean isDefault() + { + return this.defaultSchema; + } + + private LdifContentRecord schemaRecord; + + private LdapDN dn; + + private String[] objectClasses; + + private String createTimestamp; + + private String modifyTimestamp; + + private Map ocdMapByName; + + private Map atdMapByName; + + private Map lsdMapByNumericOID; + + private Map mrdMapByName; + + private Map mrdMapByNumericOID; + + private Map mrudMapByName; + + private Map mrudMapByNumericOID; + + + public Schema() + { + this.schemaRecord = null; + this.dn = null; + this.objectClasses = new String[0]; + this.createTimestamp = null; + this.modifyTimestamp = null; + this.ocdMapByName = new HashMap(); + this.atdMapByName = new HashMap(); + this.lsdMapByNumericOID = new HashMap(); + this.mrdMapByName = new HashMap(); + this.mrdMapByNumericOID = new HashMap(); + this.mrudMapByName = new HashMap(); + this.mrudMapByNumericOID = new HashMap(); + } + + + /** + * Loads all schema elements from the given reader. The input must be in + * LDIF format. + * + * @param reader + */ + public void loadFromLdif( Reader reader ) + { + try + { + LdifParser parser = new LdifParser(); + LdifEnumeration enumeration = parser.parse( reader ); + if ( enumeration.hasNext( null ) ) + { + LdifContainer container = enumeration.next( null ); + if ( container instanceof LdifContentRecord ) + { + LdifContentRecord schemaRecord = ( LdifContentRecord ) container; + this.parseSchemaRecord( schemaRecord ); + } + } + } + catch ( Exception e ) + { + System.out.println( "Schema#loadFromLdif: " + e.toString() ); + } + } + + + public void loadFromRecord( LdifContentRecord schemaRecord ) + { + try + { + this.parseSchemaRecord( schemaRecord ); + } + catch ( Exception e ) + { + System.out.println( "Schema#loadFromRecord: " + e.toString() ); + } + } + + + /** + * Saves the schema in LDIF format to the given writer. + * + * @param writer + */ + public void saveToLdif( Writer writer ) + { + try + { + writer.write( this.getSchemaRecord().toFormattedString() ); + } + catch ( Exception e ) + { + System.out.println( "Schema#saveToLdif: " + e.toString() ); + } + } + + + private void parseSchemaRecord( LdifContentRecord schemaRecord ) throws Exception + { + + this.setSchemaRecord( schemaRecord ); + this.setDn( new LdapDN( schemaRecord.getDnLine().getValueAsString() ) ); + + LdifAttrValLine[] lines = schemaRecord.getAttrVals(); + for ( int i = 0; i < lines.length; i++ ) + { + LdifAttrValLine line = lines[i]; + String attributeName = line.getUnfoldedAttributeDescription(); + String value = line.getValueAsString(); + + SchemaLexer lexer = new SchemaLexer( new StringReader( value ) ); + SchemaParser parser = new SchemaParser( lexer ); + + try + { + if ( attributeName.equalsIgnoreCase( Schema.SCHEMA_ATTRIBUTE_OBJECTCLASSES ) ) + { + ObjectClassDescription ocd = parser.objectClassDescription(); + ocd.setSchema( this ); + ocd.setLine( line ); + this.addObjectClassDescription( ocd ); + } + else if ( attributeName.equalsIgnoreCase( Schema.SCHEMA_ATTRIBUTE_ATTRIBUTETYPES ) ) + { + AttributeTypeDescription atd = parser.attributeTypeDescription(); + atd.setSchema( this ); + atd.setLine( line ); + this.addAttributeTypeDescription( atd ); + } + else if ( attributeName.equalsIgnoreCase( Schema.SCHEMA_ATTRIBUTE_LDAPSYNTAXES ) ) + { + LdapSyntaxDescription lsd = parser.syntaxDescription(); + lsd.setSchema( this ); + lsd.setLine( line ); + this.addLdapSyntaxDescription( lsd ); + } + else if ( attributeName.equalsIgnoreCase( Schema.SCHEMA_ATTRIBUTE_MATCHINGRULES ) ) + { + MatchingRuleDescription mrd = parser.matchingRuleDescription(); + mrd.setSchema( this ); + mrd.setLine( line ); + this.addMatchingRuleDescription( mrd ); + } + else if ( attributeName.equalsIgnoreCase( Schema.SCHEMA_ATTRIBUTE_MATCHINGRULEUSE ) ) + { + MatchingRuleUseDescription mrud = parser.matchingRuleUseDescription(); + mrud.setSchema( this ); + mrud.setLine( line ); + this.addMatchingRuleUseDescription( mrud ); + } + else if ( attributeName.equalsIgnoreCase( IAttribute.OPERATIONAL_ATTRIBUTE_CREATE_TIMESTAMP ) ) + { + this.setCreateTimestamp( value ); + } + else if ( attributeName.equalsIgnoreCase( IAttribute.OPERATIONAL_ATTRIBUTE_MODIFY_TIMESTAMP ) ) + { + this.setModifyTimestamp( value ); + } + } + catch ( Exception e ) + { + System.out.println( e.getMessage() + ": " + attributeName + " - " + value ); + e.printStackTrace(); + } + } + + // set extensibleObject may attributes + ObjectClassDescription extensibleObjectOcd = this + .getObjectClassDescription( ObjectClassDescription.EXTENSIBLEOBJECT_OBJECTCLASSNAME ); + AttributeTypeDescription[] userAtds = SchemaUtils.getUserAttributeDescriptions( this ); + String[] attributeTypeDescriptionNames = SchemaUtils.getAttributeTypeDescriptionNames( userAtds ); + extensibleObjectOcd.setMayAttributeTypeDescriptionNames( attributeTypeDescriptionNames ); + } + + + /** + * + * @return the schema record when the schema was created using the + * loadFromLdif() method, null otherwise + */ + public LdifContentRecord getSchemaRecord() + { + return schemaRecord; + } + + + public void setSchemaRecord( LdifContentRecord schemaRecord ) + { + this.schemaRecord = schemaRecord; + } + + + /** + * + * @return the dn of the schema record, may be null + */ + public LdapDN getDn() + { + return dn; + } + + + public void setDn( LdapDN dn ) + { + this.dn = dn; + } + + + /** + * + * @return the create timestamp of the schema record, may be null + */ + public String getCreateTimestamp() + { + return createTimestamp; + } + + + public void setCreateTimestamp( String createTimestamp ) + { + this.createTimestamp = createTimestamp; + } + + + /** + * + * @return the modify timestamp of the schema record, may be null + */ + public String getModifyTimestamp() + { + return modifyTimestamp; + } + + + public void setModifyTimestamp( String modifyTimestamp ) + { + this.modifyTimestamp = modifyTimestamp; + } + + + /** + * + * @return the object classes of the schema record, may be an empty + * array. + */ + public String[] getObjectClasses() + { + return objectClasses; + } + + + public void setObjectClasses( String[] objectClasses ) + { + this.objectClasses = objectClasses; + } + + + /** + * + * @return a Map of name to attribute type description + */ + Map getAtdMapByName() + { + return atdMapByName; + } + + + void setAtdMapByName( Map atdMapByName ) + { + this.atdMapByName = atdMapByName; + } + + + public void addAttributeTypeDescription( AttributeTypeDescription atd ) + { + if ( atd.getNames() != null && atd.getNames().length > 0 ) + { + for ( int i = 0; i < atd.getNames().length; i++ ) + { + this.atdMapByName.put( atd.getNames()[i].toLowerCase(), atd ); + } + } + if ( atd.getNumericOID() != null ) + { + this.atdMapByName.put( atd.getNumericOID().toLowerCase(), atd ); + } + } + + + /** + * + * @return an array of all attribute type description names + */ + public String[] getAttributeTypeDescriptionNames() + { + Set set = new HashSet(); + for ( Iterator it = this.atdMapByName.values().iterator(); it.hasNext(); ) + { + AttributeTypeDescription atd = ( AttributeTypeDescription ) it.next(); + for ( int i = 0; i < atd.getNames().length; i++ ) + { + set.add( atd.getNames()[i] ); + } + } + return ( String[] ) set.toArray( new String[set.size()] ); + } + + + public AttributeTypeDescription[] getAttributeTypeDescriptions() + { + Set set = new HashSet(); + for ( Iterator it = this.atdMapByName.values().iterator(); it.hasNext(); ) + { + AttributeTypeDescription atd = ( AttributeTypeDescription ) it.next(); + set.add( atd ); + } + return ( AttributeTypeDescription[] ) set.toArray( new AttributeTypeDescription[set.size()] ); + } + + + /** + * + * @return a Map of oid to syntax description + */ + public Map getLsdMapByNumericOID() + { + return lsdMapByNumericOID; + } + + + public void setLsdMapByNumericOID( Map lsdMapByNumericOID ) + { + this.lsdMapByNumericOID = lsdMapByNumericOID; + } + + + public void addLdapSyntaxDescription( LdapSyntaxDescription lsd ) + { + if ( lsd.getNumericOID() != null ) + { + this.lsdMapByNumericOID.put( lsd.getNumericOID().toLowerCase(), lsd ); + } + } + + + /** + * + * @return an array of all syntax description oids + */ + public String[] getLdapSyntaxDescriptionOids() + { + Set set = new HashSet(); + for ( Iterator it = this.lsdMapByNumericOID.values().iterator(); it.hasNext(); ) + { + LdapSyntaxDescription lsd = ( LdapSyntaxDescription ) it.next(); + set.add( lsd.getNumericOID() ); + } + return ( String[] ) set.toArray( new String[set.size()] ); + } + + + public LdapSyntaxDescription[] getLdapSyntaxDescriptions() + { + Set set = new HashSet(); + for ( Iterator it = this.lsdMapByNumericOID.values().iterator(); it.hasNext(); ) + { + LdapSyntaxDescription lsd = ( LdapSyntaxDescription ) it.next(); + set.add( lsd ); + } + return ( LdapSyntaxDescription[] ) set.toArray( new LdapSyntaxDescription[set.size()] ); + } + + + /** + * + * @return a Map of name to matching rule description + */ + public Map getMrdMapByName() + { + return mrdMapByName; + } + + + public void setMrdMapByName( Map mrdMapByName ) + { + this.mrdMapByName = mrdMapByName; + } + + + /** + * + * @return an array of all matching rule description names + */ + public String[] getMatchingRuleDescriptionNames() + { + Set set = new HashSet(); + for ( Iterator it = this.mrdMapByName.values().iterator(); it.hasNext(); ) + { + MatchingRuleDescription mrd = ( MatchingRuleDescription ) it.next(); + for ( int i = 0; i < mrd.getNames().length; i++ ) + { + set.add( mrd.getNames()[i] ); + } + } + return ( String[] ) set.toArray( new String[set.size()] ); + } + + + public MatchingRuleDescription[] getMatchingRuleDescriptions() + { + Set set = new HashSet(); + for ( Iterator it = this.mrdMapByName.values().iterator(); it.hasNext(); ) + { + MatchingRuleDescription mrd = ( MatchingRuleDescription ) it.next(); + set.add( mrd ); + } + return ( MatchingRuleDescription[] ) set.toArray( new MatchingRuleDescription[set.size()] ); + } + + public void addMatchingRuleDescription( MatchingRuleDescription mrd ) + { + if ( mrd.getNames() != null && mrd.getNames().length > 0 ) + { + for ( int i = 0; i < mrd.getNames().length; i++ ) + { + this.mrdMapByName.put( mrd.getNames()[i].toLowerCase(), mrd ); + } + } + if ( mrd.getNumericOID() != null ) + { + this.mrdMapByNumericOID.put( mrd.getNumericOID().toLowerCase(), mrd ); + } + } + + + /** + * + * @return a Map of oid to matching rule description + */ + public Map getMrdMapByNumericOID() + { + return mrdMapByNumericOID; + } + + + public void setMrdMapByNumericOID( Map mrdMapByNumericOID ) + { + this.mrdMapByNumericOID = mrdMapByNumericOID; + } + + + /** + * + * @return a Map of name to matching rule use description + */ + public Map getMrudMapByName() + { + return mrudMapByName; + } + + + public void setMrudMapByName( Map mrudMapByName ) + { + this.mrudMapByName = mrudMapByName; + } + + + public void addMatchingRuleUseDescription( MatchingRuleUseDescription mrud ) + { + if ( mrud.getNames() != null && mrud.getNames().length > 0 ) + { + for ( int i = 0; i < mrud.getNames().length; i++ ) + { + this.mrudMapByName.put( mrud.getNames()[i].toLowerCase(), mrud ); + } + } + if ( mrud.getNumericOID() != null ) + { + this.mrudMapByNumericOID.put( mrud.getNumericOID().toLowerCase(), mrud ); + } + } + + + /** + * + * @return a Map of oid to matching rule use description + */ + public Map getMrudMapByNumericOID() + { + return mrudMapByNumericOID; + } + + + public void setMrduMapByNumericOID( Map mrudMapByNumericOID ) + { + this.mrudMapByNumericOID = mrudMapByNumericOID; + } + + + /** + * + * @return a Map of name to object class description + */ + Map getOcdMapByName() + { + return ocdMapByName; + } + + + void setOcdMapByName( Map ocdMapByName ) + { + this.ocdMapByName = ocdMapByName; + } + + + public void addObjectClassDescription( ObjectClassDescription ocd ) + { + if ( ocd.getNames() != null && ocd.getNames().length > 0 ) + { + for ( int i = 0; i < ocd.getNames().length; i++ ) + { + this.ocdMapByName.put( ocd.getNames()[i].toLowerCase(), ocd ); + } + } + if ( ocd.getNumericOID() != null ) + { + this.ocdMapByName.put( ocd.getNumericOID().toLowerCase(), ocd ); + } + } + + + /** + * + * @return an array of all object class names + */ + public String[] getObjectClassDescriptionNames() + { + Set set = new HashSet(); + for ( Iterator it = this.ocdMapByName.values().iterator(); it.hasNext(); ) + { + ObjectClassDescription ocd = ( ObjectClassDescription ) it.next(); + for ( int i = 0; i < ocd.getNames().length; i++ ) + { + set.add( ocd.getNames()[i] ); + } + } + return ( String[] ) set.toArray( new String[set.size()] ); + } + + + public ObjectClassDescription[] getObjectClassDescriptions() + { + Set set = new HashSet(); + for ( Iterator it = this.ocdMapByName.values().iterator(); it.hasNext(); ) + { + ObjectClassDescription ocd = ( ObjectClassDescription ) it.next(); + set.add( ocd ); + } + return ( ObjectClassDescription[] ) set.toArray( new ObjectClassDescription[set.size()] ); + } + + + /** + * + * @param name + * @return true if a object class description with the given name + * exists. + */ + public boolean hasObjectClassDescription( String name ) + { + return this.ocdMapByName.containsKey( name.toLowerCase() ); + } + + + /** + * Returns the object class description of the given name. If no such + * object exists the default or a dummy object class description is + * returned. + * + * @param name + * the object class name + * @return the object class description, the default or a dummy + */ + public ObjectClassDescription getObjectClassDescription( String name ) + { + if ( this.ocdMapByName.containsKey( name.toLowerCase() ) ) + { + return ( ObjectClassDescription ) this.ocdMapByName.get( name.toLowerCase() ); + } + else if ( !this.isDefault() ) + { + return DEFAULT_SCHEMA.getObjectClassDescription( name ); + } + else + { + // DUMMY + ObjectClassDescription ocd = new ObjectClassDescription(); + ocd.setSchema( this ); + ocd.setNumericOID( name ); + ocd.setNames( new String[] + { name } ); + return ocd; + } + } + + + /** + * + * @param name + * @return true if a attribute type description with the given name + * exists. + */ + public boolean hasAttributeTypeDescription( String name ) + { + return this.atdMapByName.containsKey( name.toLowerCase() ); + } + + + /** + * Returns the attribute type description of the given name. If no such + * object exists the default or a dummy attribute type description is + * returned. + * + * @param description + * the attribute description + * @return the attribute type description, or the default or a dummy + */ + public AttributeTypeDescription getAttributeTypeDescription( String description ) + { + AttributeDescription ad = new AttributeDescription( description ); + String attributeType = ad.getParsedAttributeType(); + + if ( this.atdMapByName.containsKey( attributeType.toLowerCase() ) ) + { + return ( AttributeTypeDescription ) this.atdMapByName.get( attributeType.toLowerCase() ); + } + else if ( !this.isDefault() ) + { + return DEFAULT_SCHEMA.getAttributeTypeDescription( attributeType ); + } + else + { + // DUMMY + AttributeTypeDescription atd = new AttributeTypeDescription(); + atd.setSchema( this ); + atd.setNumericOID( attributeType ); + atd.setNames( new String[] + { attributeType } ); + atd.setNoUserModification( true ); + atd.setUsage( "" ); + return atd; + } + } + + + /** + * + * @param name + * @return true if a syntax description with the given name exists. + */ + public boolean hasLdapSyntaxDescription( String numericOID ) + { + return this.lsdMapByNumericOID.containsKey( numericOID.toLowerCase() ); + } + + + /** + * Returns the syntax description of the given name. If no such object + * exists the default or a dummy syntax description is returned. + * + * @param name + * the attribute name + * @return the attribute type description, or the default or a dummy + */ + public LdapSyntaxDescription getLdapSyntaxDescription( String numericOID ) + { + if ( this.lsdMapByNumericOID.containsKey( numericOID.toLowerCase() ) ) + { + return ( LdapSyntaxDescription ) this.lsdMapByNumericOID.get( numericOID.toLowerCase() ); + } + else if ( !this.isDefault() ) + { + return DEFAULT_SCHEMA.getLdapSyntaxDescription( numericOID ); + } + else + { + // DUMMY + LdapSyntaxDescription lsd = new LdapSyntaxDescription(); + lsd.setSchema( this ); + lsd.setNumericOID( numericOID ); + return lsd; + } + } + + + /** + * + * @param name + * @return true if a matching rule description with the given name or + * oid exists. + */ + public boolean hasMatchingRuleDescription( String nameOrOID ) + { + return this.mrdMapByName.containsKey( nameOrOID.toLowerCase() ) + || this.mrdMapByNumericOID.containsKey( nameOrOID.toLowerCase() ); + } + + + /** + * Returns the matching rule description of the given name or oid. If no + * such object exists the default or a dummy matching rule description + * is returned. + * + * @param name + * the matching rule + * @return the matching rule description, or the default or a dummy + */ + public MatchingRuleDescription getMatchingRuleDescription( String nameOrOID ) + { + if ( this.mrdMapByName.containsKey( nameOrOID.toLowerCase() ) ) + { + return ( MatchingRuleDescription ) this.mrdMapByName.get( nameOrOID.toLowerCase() ); + } + else if ( this.mrdMapByNumericOID.containsKey( nameOrOID.toLowerCase() ) ) + { + return ( MatchingRuleDescription ) this.mrdMapByNumericOID.get( nameOrOID.toLowerCase() ); + } + else if ( !this.isDefault() ) + { + return DEFAULT_SCHEMA.getMatchingRuleDescription( nameOrOID ); + } + else + { + // DUMMY + MatchingRuleDescription mrd = new MatchingRuleDescription(); + mrd.setSchema( this ); + mrd.setNumericOID( nameOrOID ); + return mrd; + } + } + + + /** + * + * @param name + * @return true if a matching rule use description with the given name + * or oid exists. + */ + public boolean hasMatchingRuleUseDescription( String nameOrOID ) + { + return this.mrudMapByName.containsKey( nameOrOID.toLowerCase() ) + || this.mrudMapByNumericOID.containsKey( nameOrOID.toLowerCase() ); + } + + + /** + * Returns the matching rule description of the given name or oid. If no + * such object exists the default or a dummy matching rule description + * is returned. + * + * @param name + * the matching rule + * @return the matching rule description, or the default or a dummy + */ + public MatchingRuleUseDescription getMatchingRuleUseDescription( String nameOrOID ) + { + if ( this.mrudMapByName.containsKey( nameOrOID.toLowerCase() ) ) + { + return ( MatchingRuleUseDescription ) this.mrudMapByName.get( nameOrOID.toLowerCase() ); + } + else if ( this.mrudMapByNumericOID.containsKey( nameOrOID.toLowerCase() ) ) + { + return ( MatchingRuleUseDescription ) this.mrudMapByNumericOID.get( nameOrOID.toLowerCase() ); + } + else if ( !this.isDefault() ) + { + return DEFAULT_SCHEMA.getMatchingRuleUseDescription( nameOrOID ); + } + else + { + // DUMMY + MatchingRuleUseDescription mrud = new MatchingRuleUseDescription(); + mrud.setSchema( this ); + mrud.setNumericOID( nameOrOID ); + return mrud; + } + } + + + static String[] addValue( String[] array, String value ) + { + List list = new ArrayList( Arrays.asList( array ) ); + list.add( value ); + return ( String[] ) list.toArray( new String[list.size()] ); + } + +} Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/Schema.java ------------------------------------------------------------------------------ svn:eol-style = native Added: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/SchemaPart.java URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/SchemaPart.java?rev=592082&view=auto ============================================================================== --- directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/SchemaPart.java (added) +++ directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/SchemaPart.java Mon Nov 5 08:51:43 2007 @@ -0,0 +1,137 @@ +/* + * 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.ldapbrowser.core.model.schema; + + +import java.io.Serializable; + +import org.apache.directory.studio.ldapbrowser.core.model.ldif.lines.LdifAttrValLine; + + +public abstract class SchemaPart implements Comparable, Serializable +{ + + protected LdifAttrValLine line; + + protected Schema schema; + + protected String numericOID; + + protected String desc; + + + protected SchemaPart() + { + this.schema = null; + this.numericOID = null; + this.desc = null; + } + + + /** + * + * @return the schema + */ + public Schema getSchema() + { + return schema; + } + + + public void setSchema( Schema schema ) + { + this.schema = schema; + } + + + /** + * + * @return the numeric OID + */ + public String getNumericOID() + { + return numericOID; + } + + + public void setNumericOID( String numericOID ) + { + this.numericOID = numericOID; + } + + + /** + * + * @return true if this syntax description is part of the default schema + */ + public boolean isDefault() + { + return this.schema.isDefault(); + } + + + /** + * + * @return the desc, may be null + */ + public String getDesc() + { + return desc; + } + + + public void setDesc( String desc ) + { + this.desc = desc; + } + + + public LdifAttrValLine getLine() + { + return line; + } + + + public void setLine( LdifAttrValLine line ) + { + this.line = line; + } + + + public boolean equals( Object obj ) + { + if ( obj instanceof SchemaPart ) + { + return this.getClass() == obj.getClass() && this.toString().equals( obj.toString() ); + } + else + { + return false; + } + } + + + public int hashCode() + { + return toString().hashCode(); + } + +} Propchange: directory/sandbox/felixk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/model/schema/SchemaPart.java ------------------------------------------------------------------------------ svn:eol-style = native