You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2006/12/18 18:32:09 UTC
svn commit: r488355 [4/10] - in /directory/sandbox/pamarcelot/ldapstudio:
ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/
ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/filter/
ldapstudio-browse...
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/parser/LdifScanner.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/parser/LdifScanner.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/parser/LdifScanner.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/parser/LdifScanner.java Mon Dec 18 09:32:03 2006
@@ -0,0 +1,1100 @@
+/*
+ * 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.ldapstudio.browser.core.model.ldif.parser;
+
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.Reader;
+
+
+// RFC 2849
+//
+// ldif-file = ldif-content / ldif-changes
+// ldif-content = version-spec 1*(1*SEP ldif-attrval-record)
+// ldif-changes = version-spec 1*(1*SEP ldif-change-record)
+// ldif-attrval-record = dn-spec SEP 1*attrval-spec
+// ldif-change-record = dn-spec SEP *control changerecord
+// version-spec = "version:" FILL version-number
+// version-number = 1*DIGIT
+// ; version-number MUST be "1" for the
+// ; LDIF format described in this document.
+// dn-spec = "dn:" (FILL distinguishedName /
+// ":" FILL base64-distinguishedName)
+// distinguishedName = SAFE-STRING
+// ; a distinguished name, as defined in [3]
+// base64-distinguishedName = BASE64-UTF8-STRING
+// ; a distinguishedName which has been base64
+// ; encoded (see note 10, below)
+// rdn = SAFE-STRING
+// ; a relative distinguished name, defined as
+// ; <name-component> in [3]
+// base64-rdn = BASE64-UTF8-STRING
+// ; an rdn which has been base64 encoded (see
+// ; note 10, below)
+// control = "control:" FILL ldap-oid ; controlType
+// 0*1(1*SPACE ("true" / "false")) ; criticality
+// 0*1(value-spec) ; controlValue
+// SEP
+// ; (See note 9, below)
+// ldap-oid = 1*DIGIT 0*1("." 1*DIGIT)
+// ; An LDAPOID, as defined in [4]
+// attrval-spec = AttributeDescription value-spec SEP
+// value-spec = ":" ( FILL 0*1(SAFE-STRING) /
+// ":" FILL (BASE64-STRING) /
+// "<" FILL url)
+// ; See notes 7 and 8, below
+// url = <a Uniform Resource Locator,
+// as defined in [6]>
+// ; (See Note 6, below)
+// AttributeDescription = AttributeType [";" options]
+// ; Definition taken from [4]
+// AttributeType = ldap-oid / (ALPHA *(attr-type-chars))
+// options = option / (option ";" options)
+// option = 1*opt-char
+// attr-type-chars = ALPHA / DIGIT / "-"
+// opt-char = attr-type-chars
+// changerecord = "changetype:" FILL
+// (change-add / change-delete /
+// change-modify / change-moddn)
+// change-add = "add" SEP 1*attrval-spec
+// change-delete = "delete" SEP
+// change-moddn = ("modrdn" / "moddn") SEP
+// "newrdn:" ( FILL rdn /
+// ":" FILL base64-rdn) SEP
+// "deleteoldrdn:" FILL ("0" / "1") SEP
+// 0*1("newsuperior:"
+// ( FILL distinguishedName /
+// ":" FILL base64-distinguishedName) SEP)
+// change-modify = "modify" SEP *mod-spec
+// mod-spec = ("add:" / "delete:" / "replace:")
+// FILL AttributeDescription SEP
+// *attrval-spec
+// "-" SEP
+// SPACE = %x20
+// ; ASCII SP, space
+// FILL = *SPACE
+// SEP = (CR LF / LF)
+// CR = %x0D
+// ; ASCII CR, carriage return
+// LF = %x0A
+// ; ASCII LF, line feed
+// ALPHA = %x41-5A / %x61-7A
+// ; A-Z / a-z
+// DIGIT = %x30-39
+// ; 0-9
+// UTF8-1 = %x80-BF
+// UTF8-2 = %xC0-DF UTF8-1
+// UTF8-3 = %xE0-EF 2UTF8-1
+// UTF8-4 = %xF0-F7 3UTF8-1
+// UTF8-5 = %xF8-FB 4UTF8-1
+// UTF8-6 = %xFC-FD 5UTF8-1
+// SAFE-CHAR = %x01-09 / %x0B-0C / %x0E-7F
+// ; any value <= 127 decimal except NUL, LF,
+// ; and CR
+// SAFE-INIT-CHAR = %x01-09 / %x0B-0C / %x0E-1F /
+// %x21-39 / %x3B / %x3D-7F
+// ; any value <= 127 except NUL, LF, CR,
+// ; SPACE, colon (":", ASCII 58 decimal)
+// ; and less-than ("<" , ASCII 60 decimal)
+// SAFE-STRING = [SAFE-INIT-CHAR *SAFE-CHAR]
+// UTF8-CHAR = SAFE-CHAR / UTF8-2 / UTF8-3 /
+// UTF8-4 / UTF8-5 / UTF8-6
+// UTF8-STRING = *UTF8-CHAR
+// BASE64-UTF8-STRING = BASE64-STRING
+// ; MUST be the base64 encoding of a
+// ; UTF8-STRING
+// BASE64-CHAR = %x2B / %x2F / %x30-39 / %x3D / %x41-5A /
+// %x61-7A
+// ; +, /, 0-9, =, A-Z, and a-z
+// ; as specified in [5]
+// BASE64-STRING = [*(BASE64-CHAR)]
+
+public class LdifScanner
+{
+
+ private Reader ldifReader;
+
+ private char[] buffer = new char[256];
+
+ private StringBuffer ldifBuffer;
+
+ private int ldifBufferOffset;
+
+ private int pos;
+
+
+ public LdifScanner()
+ {
+ super();
+ }
+
+
+ public void setLdif( Reader ldifReader )
+ {
+ // this.ldif = ldif;
+ this.ldifReader = ldifReader;
+ this.pos = -1;
+
+ this.ldifBuffer = new StringBuffer();
+ this.ldifBufferOffset = 0;
+ }
+
+
+ char currentChar() throws EOFException
+ {
+
+ // check and fill buffer
+ try
+ {
+ int num = 0;
+ while ( ldifBufferOffset + ldifBuffer.length() <= pos && num > -1 )
+ {
+ num = this.ldifReader.read( buffer );
+ if ( num > -1 )
+ {
+ ldifBuffer.append( buffer, 0, num );
+ }
+ }
+ }
+ catch ( IOException e )
+ {
+ }
+
+ if ( 0 <= pos && pos < ldifBufferOffset + ldifBuffer.length() )
+ {
+ try
+ {
+ return ldifBuffer.charAt( pos - ldifBufferOffset );
+ }
+ catch ( RuntimeException e )
+ {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+ else
+ {
+ throw new EOFException();
+ }
+
+ // return 0<=pos&&pos<ldif.length() ? ldif.charAt(pos) : '\u0000';
+ }
+
+
+ void addFolding( StringBuffer sb )
+ {
+
+ int oldPos = pos;
+
+ try
+ {
+ pos++;
+ char c = currentChar();
+ if ( c == '\n' || c == '\r' )
+ {
+ StringBuffer temp = new StringBuffer( 3 );
+ temp.append( c );
+ if ( c == '\r' )
+ {
+ pos++;
+ c = currentChar();
+ if ( c == '\n' )
+ {
+ temp.append( c );
+ }
+ else
+ {
+ pos--;
+ }
+ }
+ else if ( c == '\n' )
+ {
+ pos++;
+ c = currentChar();
+ if ( c == '\r' )
+ {
+ temp.append( c );
+ }
+ else
+ {
+ pos--;
+ }
+ }
+
+ pos++;
+ c = currentChar();
+ if ( c == ' ' )
+ {
+ // space after newline, continue
+ temp.append( c );
+ sb.append( temp );
+ }
+ else
+ {
+ for ( int i = 0; i < temp.length(); i++ )
+ {
+ pos--;
+ }
+ pos--;
+ }
+ }
+ else
+ {
+ pos--;
+ }
+ }
+ catch ( EOFException e )
+ {
+ // reset position
+ pos = oldPos;
+ }
+
+ }
+
+
+ /**
+ * Reads the next character from input stram if available. If read was
+ * possible the character is appended to the given StringBuffer and
+ * returned. Otherwise throws a EOFException. Additionally this method
+ * checks folding sequence SEP + SPACE. If any folding sequence was
+ * found the sequence is appended to the given StringBuffer. So it is
+ * possible the StringBuffer doesn't end with the read character after
+ * calling this method but with a folding sequence
+ *
+ * @param sb
+ * @return the next character if available
+ * @throws EOFException
+ */
+ public char read( StringBuffer sb ) throws EOFException
+ {
+ try
+ {
+
+ // check EOF
+ // if(pos > -1) {
+ // currentChar();
+ // }
+
+ // get next char
+ pos++;
+ char c = currentChar();
+ sb.append( c );
+
+ // folding
+ addFolding( sb );
+
+ return c;
+ }
+ catch ( EOFException e )
+ {
+ pos--;
+ throw e;
+ }
+ }
+
+
+ void removeFolding( StringBuffer sb )
+ {
+
+ int oldPos = pos;
+
+ try
+ {
+ char c = currentChar();
+ pos--;
+ if ( c == ' ' )
+ {
+ StringBuffer temp = new StringBuffer();
+ temp.insert( 0, c );
+ c = currentChar();
+ pos--;
+
+ if ( c == '\n' || c == '\r' )
+ {
+ if ( c == '\r' )
+ {
+ temp.insert( 0, c );
+ c = currentChar();
+ pos--;
+ if ( c == '\n' )
+ {
+ temp.insert( 0, c );
+ }
+ else
+ {
+ pos++;
+ }
+ }
+ else if ( c == '\n' )
+ {
+ temp.insert( 0, c );
+ c = currentChar();
+ pos--;
+ if ( c == '\r' )
+ {
+ temp.insert( 0, c );
+ }
+ else
+ {
+ pos++;
+ }
+ }
+
+ sb.delete( sb.length() - temp.length(), sb.length() );
+ }
+ else
+ {
+ pos++;
+ pos++;
+ }
+ }
+ else
+ {
+ pos++;
+ }
+ }
+ catch ( EOFException e )
+ {
+ // reset position
+ pos = oldPos;
+ }
+ }
+
+
+ /**
+ * Inverses the previous read().
+ *
+ * @param sb
+ * @return the previous character if available
+ * @throws EOFException
+ */
+ public void unread( StringBuffer sb )
+ {
+ removeFolding( sb );
+
+ if ( pos > -1 )
+ {
+ pos--;
+
+ if ( sb.length() > 0 )
+ {
+ sb.deleteCharAt( sb.length() - 1 );
+ }
+ }
+ }
+
+
+ private String getFullLine( String start )
+ {
+ String s1 = this.getWord( start );
+ if ( s1 != null )
+ {
+ String s2 = getContent();
+ return s2 != null ? s1 + s2 : s1;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ private String getContent()
+ {
+
+ StringBuffer sb = new StringBuffer( 256 );
+
+ try
+ {
+ char c = '\u0000';
+ while ( c != '\n' && c != '\r' )
+ {
+ c = read( sb );
+ }
+ unread( sb );
+
+ }
+ catch ( EOFException e )
+ {
+ }
+
+ return sb.length() > 0 ? sb.toString() : null;
+ }
+
+
+ // private String getStartAndFill(String start) {
+ // String s = this.getWord(start);
+ // if(s != null) {
+ // StringBuffer sb = new StringBuffer(s);
+ //
+ // try {
+ // char c = '\u0000';
+ // while (c==' ') {
+ // c = read(sb);
+ // }
+ // unread(sb);
+ // } catch (EOFException e) {
+ // }
+ //
+ // return sb.toString();
+ // }
+ // else {
+ // return null;
+ // }
+ // }
+
+ private String getWord( String word )
+ {
+ StringBuffer sb = new StringBuffer();
+
+ // read
+ try
+ {
+ boolean matches = true;
+ for ( int i = 0; i < word.length(); i++ )
+ {
+
+ char c = read( sb );
+ if ( c != word.charAt( i ) )
+ {
+ matches = false;
+ unread( sb );
+ break;
+ }
+ }
+
+ if ( matches )
+ {
+ return sb.toString();
+ }
+ }
+ catch ( EOFException e )
+ {
+ }
+
+ // unread
+ while ( sb.length() > 0 )
+ {
+ unread( sb );
+ }
+ // prevChar(sb);
+ return null;
+ }
+
+
+ private String getWordTillColon( String word )
+ {
+
+ String wordWithColon = word + ":";
+ String line = getWord( wordWithColon );
+ if ( line != null )
+ {
+ StringBuffer sb = new StringBuffer( line );
+ unread( sb );
+ return sb.toString();
+ }
+
+ // allow eof and sep
+ line = getWord( word );
+ if ( line != null )
+ {
+ StringBuffer sb = new StringBuffer( line );
+ try
+ {
+ char c = read( sb );
+ unread( sb );
+ if ( c == '\r' || c == '\n' )
+ {
+ return sb.toString();
+ }
+ else
+ {
+ while ( sb.length() > 0 )
+ {
+ unread( sb );
+ }
+ return null;
+ }
+ }
+ catch ( EOFException e )
+ {
+ return sb.toString();
+ }
+ }
+
+ return null;
+ }
+
+
+ private void flushBuffer()
+ {
+
+ // System.out.println("flushBuffer():
+ // before("+this.pos+","+this.ldifBufferOffset+")");
+
+ if ( this.ldifBufferOffset < this.pos && this.ldifBuffer.length() > 0 )
+ {
+ int delta = Math.min( pos - this.ldifBufferOffset, this.ldifBuffer.length() );
+ delta--;
+ this.ldifBuffer.delete( 0, delta );
+ this.ldifBufferOffset += delta;
+ }
+
+ // System.out.println("flushBuffer():
+ // after("+this.pos+","+this.ldifBufferOffset+")");
+ }
+
+
+ public LdifToken matchCleanupLine()
+ {
+ this.flushBuffer();
+
+ String line = getContent();
+ LdifToken sep = matchSep();
+
+ if ( line != null || sep != null )
+ {
+ if ( line == null )
+ line = "";
+
+ if ( sep != null )
+ line += sep.getValue();
+
+ return new LdifToken( LdifToken.UNKNOWN, line, pos - line.length() + 1 );
+ }
+
+ return null;
+ }
+
+
+ public LdifToken matchOther()
+ {
+ this.flushBuffer();
+
+ String line = getContent();
+ if ( line != null )
+ {
+ LdifToken sep = matchSep();
+ if ( sep != null )
+ line += sep.getValue();
+ return new LdifToken( LdifToken.UNKNOWN, line, pos - line.length() + 1 );
+ }
+
+ return null;
+ }
+
+
+ public LdifToken matchEOF()
+ {
+ this.flushBuffer();
+
+ StringBuffer sb = new StringBuffer( 1 );
+ try
+ {
+ read( sb );
+ unread( sb );
+ return null;
+ }
+ catch ( EOFException e )
+ {
+ return new LdifToken( LdifToken.EOF, "", pos + 1 );
+ }
+
+ }
+
+
+ public LdifToken matchSep()
+ {
+ this.flushBuffer();
+
+ try
+ {
+ StringBuffer sb = new StringBuffer();
+ char c = read( sb );
+ if ( c == '\n' || c == '\r' )
+ {
+
+ // check for two-char-linebreak
+ try
+ {
+ if ( c == '\r' )
+ {
+ c = read( sb );
+ if ( c != '\n' )
+ {
+ unread( sb );
+ }
+ }
+ else if ( c == '\n' )
+ {
+ c = read( sb );
+ if ( c != '\r' )
+ {
+ unread( sb );
+ }
+ }
+ }
+ catch ( EOFException e )
+ {
+ }
+
+ return new LdifToken( LdifToken.SEP, sb.toString(), pos - sb.length() + 1 );
+ }
+ else
+ {
+ unread( sb );
+ }
+ }
+ catch ( EOFException e )
+ {
+ }
+
+ return null;
+ }
+
+
+ public LdifToken matchComment()
+ {
+ this.flushBuffer();
+
+ String line = getFullLine( "#" );
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.COMMENT, line, pos - line.length() + 1 );
+ }
+
+ return null;
+ }
+
+
+ public LdifToken matchVersionSpec()
+ {
+ this.flushBuffer();
+
+ String line = getWordTillColon( "version" );
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.VERSION_SPEC, line, pos - line.length() + 1 );
+ }
+
+ return null;
+ }
+
+
+ public LdifToken matchDnSpec()
+ {
+ this.flushBuffer();
+
+ String line = getWordTillColon( "dn" );
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.DN_SPEC, line, pos - line.length() + 1 );
+ }
+
+ return null;
+ }
+
+
+ public LdifToken matchControlSpec()
+ {
+ this.flushBuffer();
+
+ String line = getWordTillColon( "control" );
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.CONTROL_SPEC, line, pos - line.length() + 1 );
+ }
+
+ return null;
+ }
+
+
+ public LdifToken matchChangeTypeSpec()
+ {
+ this.flushBuffer();
+
+ String line = getWordTillColon( "changetype" );
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.CHANGETYPE_SPEC, line, pos - line.length() + 1 );
+ }
+
+ return null;
+ }
+
+
+ public LdifToken matchChangeType()
+ {
+ this.flushBuffer();
+
+ String line = getWord( "add" );
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.CHANGETYPE_ADD, line, pos - line.length() + 1 );
+ }
+ line = getWord( "modify" );
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.CHANGETYPE_MODIFY, line, pos - line.length() + 1 );
+ }
+ line = getWord( "delete" );
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.CHANGETYPE_DELETE, line, pos - line.length() + 1 );
+ }
+ line = getWord( "moddn" );
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.CHANGETYPE_MODDN, line, pos - line.length() + 1 );
+ }
+ line = getWord( "modrdn" );
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.CHANGETYPE_MODDN, line, pos - line.length() + 1 );
+ }
+
+ return null;
+ }
+
+
+ public LdifToken matchCriticality()
+ {
+ this.flushBuffer();
+
+ StringBuffer sb = new StringBuffer();
+
+ String s = getWord( " " );
+ while ( s != null )
+ {
+ sb.append( s );
+ s = getWord( " " );
+ }
+
+ String t = getWord( "true" );
+ if ( t != null )
+ {
+ sb.append( t );
+ return new LdifToken( LdifToken.CONTROL_CRITICALITY_TRUE, sb.toString(), pos - sb.length() + 1 );
+ }
+ String f = getWord( "false" );
+ if ( f != null )
+ {
+ sb.append( f );
+ return new LdifToken( LdifToken.CONTROL_CRITICALITY_FALSE, sb.toString(), pos - sb.length() + 1 );
+ }
+
+ while ( sb.length() > 0 )
+ {
+ unread( sb );
+ }
+
+ // for(int i=0; i<sb.length(); i++) {
+ // unread(sb);
+ // }
+
+ return null;
+ }
+
+
+ public LdifToken matchNumber()
+ {
+ this.flushBuffer();
+
+ try
+ {
+ StringBuffer sb = new StringBuffer();
+ char c = read( sb );
+ if ( '0' <= c && c <= '9' )
+ {
+
+ try
+ {
+ while ( '0' <= c && c <= '9' )
+ {
+ c = read( sb );
+ }
+ unread( sb );
+ }
+ catch ( EOFException e )
+ {
+ }
+
+ return new LdifToken( LdifToken.NUMBER, sb.toString(), pos - sb.length() + 1 );
+ }
+ else
+ {
+ unread( sb );
+ }
+ }
+ catch ( EOFException e )
+ {
+ }
+
+ return null;
+ }
+
+
+ public LdifToken matchOid()
+ {
+ this.flushBuffer();
+
+ try
+ {
+ StringBuffer sb = new StringBuffer();
+ char c = read( sb );
+ if ( '0' <= c && c <= '9' )
+ {
+
+ try
+ {
+ while ( '0' <= c && c <= '9' || c == '.' )
+ {
+ c = read( sb );
+ }
+ unread( sb );
+ }
+ catch ( EOFException e )
+ {
+ }
+
+ return new LdifToken( LdifToken.OID, sb.toString(), pos - sb.length() + 1 );
+ }
+ else
+ {
+ unread( sb );
+ }
+ }
+ catch ( EOFException e )
+ {
+ }
+
+ return null;
+ }
+
+
+ public LdifToken matchAttributeDescription()
+ {
+ this.flushBuffer();
+
+ try
+ {
+ StringBuffer sb = new StringBuffer();
+ char c = read( sb );
+ if ( 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || '0' <= c && c <= '9' )
+ {
+
+ try
+ {
+ while ( 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || '0' <= c && c <= '9' || c == '.'
+ || c == ';' || c == '-' )
+ {
+ c = read( sb );
+ }
+ unread( sb );
+ }
+ catch ( EOFException e )
+ {
+ }
+
+ return new LdifToken( LdifToken.ATTRIBUTE, sb.toString(), pos - sb.length() + 1 );
+ }
+ else
+ {
+ unread( sb );
+ }
+ }
+ catch ( EOFException e )
+ {
+ }
+
+ // // a-z,A-Z,0-9,.,-,;
+ // StringBuffer sb = new StringBuffer();
+ // char c = nextChar(sb);
+ // if('a'<=c&&c<='z' || 'A'<=c&&c<='Z' || '0'<=c&&c<='9') {
+ // while('a'<=c&&c<='z' || 'A'<=c&&c<='Z' || '0'<=c&&c<='9' || c=='.' ||
+ // c==';' || c=='-') {
+ // sb.append(c);
+ // c = nextChar(sb);
+ // }
+ // unread(sb);
+ //
+ // return new LdifToken(LdifToken.ATTRIBUTE, sb.toString(),
+ // pos-sb.length()+1);
+ // }
+ // else {
+ // unread(sb);
+ // }
+
+ return null;
+ }
+
+
+ public LdifToken matchModTypeSpec()
+ {
+ this.flushBuffer();
+
+ String line = getWord( "add" );
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.MODTYPE_ADD_SPEC, line, pos - line.length() + 1 );
+ }
+ line = getWord( "replace" );
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.MODTYPE_REPLACE_SPEC, line, pos - line.length() + 1 );
+ }
+ line = getWord( "delete" );
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.MODTYPE_DELETE_SPEC, line, pos - line.length() + 1 );
+ }
+
+ return null;
+ }
+
+
+ public LdifToken matchModSep()
+ {
+ this.flushBuffer();
+
+ String line = getWord( "-" );
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.MODTYPE_SEP, line, pos - line.length() + 1 );
+ }
+
+ return null;
+ }
+
+
+ public LdifToken matchValueType()
+ {
+ this.flushBuffer();
+
+ try
+ {
+ StringBuffer sb = new StringBuffer();
+ char c = read( sb );
+ if ( c == ':' )
+ {
+
+ int tokenType = LdifToken.VALUE_TYPE_SAFE;
+ try
+ {
+ c = read( sb );
+ if ( c == ':' )
+ {
+ tokenType = LdifToken.VALUE_TYPE_BASE64;
+ }
+ else if ( c == '<' )
+ {
+ tokenType = LdifToken.VALUE_TYPE_URL;
+ }
+ else
+ {
+ tokenType = LdifToken.VALUE_TYPE_SAFE;
+ unread( sb );
+ }
+
+ c = read( sb );
+ while ( c == ' ' )
+ {
+ c = read( sb );
+ }
+ unread( sb );
+
+ }
+ catch ( EOFException e )
+ {
+ }
+
+ return new LdifToken( tokenType, sb.toString(), pos - sb.length() + 1 );
+ }
+ else
+ {
+ unread( sb );
+ }
+ }
+ catch ( EOFException e )
+ {
+ }
+
+ return null;
+ }
+
+
+ public LdifToken matchValue()
+ {
+ this.flushBuffer();
+
+ String line = getContent();
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.VALUE, line, pos - line.length() + 1 );
+ }
+
+ return null;
+ }
+
+
+ public LdifToken matchNewrdnSpec()
+ {
+ this.flushBuffer();
+
+ String line = getWordTillColon( "newrdn" );
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.MODDN_NEWRDN_SPEC, line, pos - line.length() + 1 );
+ }
+
+ return null;
+ }
+
+
+ public LdifToken matchDeleteoldrdnSpec()
+ {
+ this.flushBuffer();
+
+ String line = getWordTillColon( "deleteoldrdn" );
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.MODDN_DELOLDRDN_SPEC, line, pos - line.length() + 1 );
+ }
+
+ return null;
+ }
+
+
+ public LdifToken matchNewsuperiorSpec()
+ {
+ this.flushBuffer();
+
+ String line = getWordTillColon( "newsuperior" );
+ if ( line != null )
+ {
+ return new LdifToken( LdifToken.MODDN_NEWSUPERIOR_SPEC, line, pos - line.length() + 1 );
+ }
+
+ return null;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/parser/LdifToken.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/parser/LdifToken.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/parser/LdifToken.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/ldif/parser/LdifToken.java Mon Dec 18 09:32:03 2006
@@ -0,0 +1,160 @@
+/*
+ * 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.ldapstudio.browser.core.model.ldif.parser;
+
+
+public class LdifToken implements Comparable
+{
+
+ public static final int NEW = Integer.MIN_VALUE;
+
+ public static final int ERROR = -2;
+
+ public static final int EOF = -1;
+
+ public static final int UNKNOWN = 0;
+
+ public static final int COMMENT = 1;
+
+ public static final int SEP = 2;
+
+ public static final int VERSION_SPEC = 4;
+
+ public static final int NUMBER = 5;
+
+ public static final int OID = 6;
+
+ public static final int DN_SPEC = 11;
+
+ public static final int DN = 12;
+
+ public static final int ATTRIBUTE = 21;
+
+ public static final int VALUE_TYPE_SAFE = 22;
+
+ public static final int VALUE_TYPE_BASE64 = 23;
+
+ public static final int VALUE_TYPE_URL = 24;
+
+ public static final int VALUE = 27;
+
+ public static final int CHANGETYPE_SPEC = 30;
+
+ public static final int CHANGETYPE_ADD = 31;
+
+ public static final int CHANGETYPE_DELETE = 32;
+
+ public static final int CHANGETYPE_MODIFY = 33;
+
+ public static final int CHANGETYPE_MODDN = 34;
+
+ public static final int MODTYPE_ADD_SPEC = 41;
+
+ public static final int MODTYPE_DELETE_SPEC = 42;
+
+ public static final int MODTYPE_REPLACE_SPEC = 43;
+
+ public static final int MODTYPE_SEP = 45; //
+
+ public static final int CONTROL_SPEC = 51; // control:FILL
+
+ public static final int CONTROL_LDAPOID = 52; //
+
+ public static final int CONTROL_CRITICALITY_TRUE = 53; // FILLtrue
+
+ public static final int CONTROL_CRITICALITY_FALSE = 54; // FILLfalse
+
+ public static final int MODDN_NEWRDN_SPEC = 61;
+
+ public static final int MODDN_DELOLDRDN_SPEC = 63;
+
+ public static final int MODDN_NEWSUPERIOR_SPEC = 65;
+
+ private int offset;
+
+ private int type;
+
+ private String value;
+
+
+ public LdifToken( int type, String value, int offset )
+ {
+ this.type = type;
+ this.value = value;
+ this.offset = offset;
+ }
+
+
+ /**
+ * Returns the start position of the token in the original ldif
+ *
+ * @return the start positon of the token
+ */
+ public int getOffset()
+ {
+ return this.offset;
+ }
+
+
+ /**
+ * Returns the length of the token in the original ldif
+ *
+ * @return the length of the token
+ */
+ public int getLength()
+ {
+ return this.value.length();
+ }
+
+
+ public int getType()
+ {
+ return this.type;
+ }
+
+
+ public String getValue()
+ {
+ return this.value;
+ }
+
+
+ public String toString()
+ {
+ return "(type=" + this.type + ") " + "(offset=" + this.offset + ") " + "(length=" + this.getLength() + ") '"
+ + this.value + "'";
+ }
+
+
+ public int compareTo( Object o )
+ {
+ if ( o instanceof LdifToken )
+ {
+ LdifToken token = ( LdifToken ) o;
+ return this.offset - token.offset;
+ }
+ else
+ {
+ throw new ClassCastException( "Not instanceof LdifToken: " + o.getClass().getName() );
+ }
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/AttributeTypeDescription.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/AttributeTypeDescription.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/AttributeTypeDescription.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/AttributeTypeDescription.java Mon Dec 18 09:32:03 2006
@@ -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.ldapstudio.browser.core.model.schema;
+
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.directory.ldapstudio.browser.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;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/AttributeValueProviderRelation.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/AttributeValueProviderRelation.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/AttributeValueProviderRelation.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/AttributeValueProviderRelation.java Mon Dec 18 09:32:03 2006
@@ -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.ldapstudio.browser.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;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/BinaryAttribute.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/BinaryAttribute.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/BinaryAttribute.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/BinaryAttribute.java Mon Dec 18 09:32:03 2006
@@ -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.ldapstudio.browser.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;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/BinarySyntax.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/BinarySyntax.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/BinarySyntax.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/BinarySyntax.java Mon Dec 18 09:32:03 2006
@@ -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.ldapstudio.browser.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;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/LdapSyntaxDescription.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/LdapSyntaxDescription.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/LdapSyntaxDescription.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/LdapSyntaxDescription.java Mon Dec 18 09:32:03 2006
@@ -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.ldapstudio.browser.core.model.schema;
+
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.directory.ldapstudio.browser.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;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/MatchingRuleDescription.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/MatchingRuleDescription.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/MatchingRuleDescription.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/MatchingRuleDescription.java Mon Dec 18 09:32:03 2006
@@ -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.ldapstudio.browser.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;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/MatchingRuleUseDescription.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/MatchingRuleUseDescription.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/MatchingRuleUseDescription.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/MatchingRuleUseDescription.java Mon Dec 18 09:32:03 2006
@@ -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.ldapstudio.browser.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;
+ }
+
+}
Added: directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/ObjectClassDescription.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/ObjectClassDescription.java?view=auto&rev=488355
==============================================================================
--- directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/ObjectClassDescription.java (added)
+++ directory/sandbox/pamarcelot/ldapstudio/ldapstudio-browser-core/src/org/apache/directory/ldapstudio/browser/core/model/schema/ObjectClassDescription.java Mon Dec 18 09:32:03 2006
@@ -0,0 +1,330 @@
+/*
+ * 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.ldapstudio.browser.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 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;
+ }
+
+}