directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r614513 - /directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/
Date Wed, 23 Jan 2008 12:09:27 GMT
Author: pamarcelot
Date: Wed Jan 23 04:09:24 2008
New Revision: 614513

URL: http://svn.apache.org/viewvc?rev=614513&view=rev
Log:
Added a parser Aliases String (comma separated aliases values).

Added:
    directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/
    directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AbstractAlias.java
    directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AbstractAliasWithError.java
    directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/Alias.java
    directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasWithError.java
    directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasWithPartError.java
    directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasWithStartError.java
    directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasesStringParser.java
    directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasesStringScanner.java
    directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasesStringToken.java
    directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/DefaultAlias.java

Added: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AbstractAlias.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AbstractAlias.java?rev=614513&view=auto
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AbstractAlias.java
(added)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AbstractAlias.java
Wed Jan 23 04:09:24 2008
@@ -0,0 +1,63 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.schemaeditor.model.alias;
+
+
+/**
+ * Abstract class for the {@link Alias} interface.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractAlias implements Alias
+{
+    /** The alias */
+    private String alias;
+
+
+    /**
+     * Creates a new instance of AbstractAlias.
+     *
+     * @param alias
+     *      the alias
+     */
+    public AbstractAlias( String alias )
+    {
+        this.alias = alias;
+    }
+
+
+    /* (non-Javadoc)
+     * @see IAlias#getAlias()
+     */
+    public String getAlias()
+    {
+        return alias;
+    }
+
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    public String toString()
+    {
+        return alias;
+    }
+}

Added: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AbstractAliasWithError.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AbstractAliasWithError.java?rev=614513&view=auto
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AbstractAliasWithError.java
(added)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AbstractAliasWithError.java
Wed Jan 23 04:09:24 2008
@@ -0,0 +1,57 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.schemaeditor.model.alias;
+
+
+/**
+ * Abstract class for the {@link AliasWithError} interface.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractAliasWithError extends AbstractAlias implements AliasWithError
+{
+    /** The error character */
+    private char errorChar;
+
+
+    /**
+     * Creates a new instance of AbstractAliasWithError.
+     *
+     * @param alias
+     *      the alias
+     * @param errorChar
+     *      the error character
+     */
+    public AbstractAliasWithError( String alias, char errorChar )
+    {
+        super( alias );
+        this.errorChar = errorChar;
+    }
+
+
+    /* (non-Javadoc)
+     * @see AliasWithError#getErrorChar()
+     */
+    public char getErrorChar()
+    {
+        return errorChar;
+    }
+}

Added: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/Alias.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/Alias.java?rev=614513&view=auto
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/Alias.java
(added)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/Alias.java
Wed Jan 23 04:09:24 2008
@@ -0,0 +1,38 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.schemaeditor.model.alias;
+
+
+/**
+ * This interface defines an {@link Alias}.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface Alias
+{
+    /**
+     * Gets the alias.
+     *
+     * @return
+     *      the alias
+     */
+    String getAlias();
+}

Added: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasWithError.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasWithError.java?rev=614513&view=auto
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasWithError.java
(added)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasWithError.java
Wed Jan 23 04:09:24 2008
@@ -0,0 +1,38 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.schemaeditor.model.alias;
+
+
+/**
+ * This interface defines an {@link Alias} with error.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface AliasWithError extends Alias
+{
+    /**
+     * Gets the error character.
+     *
+     * @return
+     *      the error character
+     */
+    char getErrorChar();
+}

Added: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasWithPartError.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasWithPartError.java?rev=614513&view=auto
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasWithPartError.java
(added)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasWithPartError.java
Wed Jan 23 04:09:24 2008
@@ -0,0 +1,44 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.schemaeditor.model.alias;
+
+
+/**
+ * This class defines an {@link AliasWithError} with an error on the non first
+ * character of the alias.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AliasWithPartError extends AbstractAliasWithError
+{
+    /**
+     * Creates a new instance of AliasWithPartError.
+     *
+     * @param alias
+     *      the alias
+     * @param errorChar
+     *      the error character
+     */
+    public AliasWithPartError( String alias, char errorChar )
+    {
+        super( alias, errorChar );
+    }
+}

Added: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasWithStartError.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasWithStartError.java?rev=614513&view=auto
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasWithStartError.java
(added)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasWithStartError.java
Wed Jan 23 04:09:24 2008
@@ -0,0 +1,44 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.schemaeditor.model.alias;
+
+
+/**
+ * This class defines an {@link AliasWithError} with an error on the first
+ * character of the alias.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AliasWithStartError extends AbstractAliasWithError
+{
+    /**
+     * Creates a new instance of AliasWithStartError.
+     *
+     * @param alias
+     *      the alias
+     * @param errorChar
+     *      the error character
+     */
+    public AliasWithStartError( String alias, char errorChar )
+    {
+        super( alias, errorChar );
+    }
+}

Added: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasesStringParser.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasesStringParser.java?rev=614513&view=auto
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasesStringParser.java
(added)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasesStringParser.java
Wed Jan 23 04:09:24 2008
@@ -0,0 +1,129 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.schemaeditor.model.alias;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * The AliasesParser implements a parser for Aliases {@link String}.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AliasesStringParser
+{
+    /** The scanner */
+    private AliasesStringScanner scanner;
+
+    /** The parsed aliases */
+    private List<Alias> aliases;
+
+
+    /**
+     * Creates a new instance of LdapFilterParser.
+     */
+    public AliasesStringParser()
+    {
+        this.scanner = new AliasesStringScanner();
+        this.aliases = new ArrayList<Alias>();
+    }
+
+
+    /**
+     * Gets the parsed aliases.
+     * 
+     * @return the parsed aliases
+     */
+    public List<Alias> getAliases()
+    {
+        return aliases;
+    }
+
+
+    /**
+     * Parses the given aliases String.
+     * 
+     * @param str the aliases String
+     */
+    public void parse( String str )
+    {
+        // reset state
+        scanner.reset( str );
+
+        // handle error tokens before filter
+        AliasesStringToken token = scanner.nextToken();
+
+        // loop till aliases end or EOF
+        do
+        {
+            switch ( token.getType() )
+            {
+                case AliasesStringToken.ALIAS:
+                {
+                    aliases.add( new DefaultAlias( token.getValue() ) );
+                    break;
+                }
+                case AliasesStringToken.ERROR_ALIAS_START:
+                {
+                    String previousTokenValue = token.getValue();
+
+                    token = scanner.nextToken();
+                    if ( token.getType() == AliasesStringToken.ERROR_ALIAS_SUBSTRING )
+                    {
+                        aliases.add( new AliasWithStartError( previousTokenValue + token.getValue(),
previousTokenValue
+                            .charAt( 0 ) ) );
+                        break;
+                    }
+                    else
+                    {
+                        continue;
+                    }
+                }
+                case AliasesStringToken.ERROR_ALIAS_PART:
+                {
+                    String previousTokenValue = token.getValue();
+
+                    token = scanner.nextToken();
+                    if ( token.getType() == AliasesStringToken.ERROR_ALIAS_SUBSTRING )
+                    {
+                        aliases.add( new AliasWithPartError( previousTokenValue + token.getValue(),
previousTokenValue
+                            .charAt( previousTokenValue.length() - 1 ) ) );
+                        break;
+                    }
+                    else
+                    {
+                        continue;
+                    }
+                }
+                default:
+                {
+                    break;
+                }
+            }
+
+            // next token
+            token = scanner.nextToken();
+        }
+        while ( token.getType() != AliasesStringToken.EOF );
+    }
+}

Added: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasesStringScanner.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasesStringScanner.java?rev=614513&view=auto
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasesStringScanner.java
(added)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasesStringScanner.java
Wed Jan 23 04:09:24 2008
@@ -0,0 +1,260 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.schemaeditor.model.alias;
+
+
+public class AliasesStringScanner
+{
+    private static final char CHAR_COMMA = ',';
+    private static final char CHAR_EOF = '\u0000';
+
+    /** The aliases to scan */
+    private String aliases;
+
+    /** The current position */
+    private int pos;
+
+    /** The last token type. */
+    private int lastTokenType;
+
+
+    /**
+     * Creates a new instance of LdapFilterScanner.
+     */
+    public AliasesStringScanner()
+    {
+        super();
+        aliases = "";
+    }
+
+
+    /**
+     * Resets this scanner.
+     * 
+     * @param aliases the new aliases to scan
+     */
+    public void reset( String aliases )
+    {
+        this.aliases = aliases;
+        pos = -1;
+        lastTokenType = AliasesStringToken.START;
+    }
+
+
+    /**
+     * Gets the character at the current position.
+     * 
+     * @return the character at the current position
+     */
+    private char currentChar()
+    {
+        return 0 <= pos && pos < aliases.length() ? aliases.charAt( pos ) :
CHAR_EOF;
+    }
+
+
+    /**
+     * Increments the position counter and gets
+     * the character at that positon.
+     * 
+     * @return the character at the next position
+     */
+    private char nextChar()
+    {
+        pos++;
+        return currentChar();
+    }
+
+
+    /**
+     * Decrements the position counter and gets
+     * the character at that positon.
+     * 
+     * @return the character at the previous position
+     */
+    private char prevChar()
+    {
+        pos--;
+        return currentChar();
+    }
+
+
+    /**
+     * Gets the next token.
+     * 
+     * @return the next token
+     */
+    public AliasesStringToken nextToken()
+    {
+        char c;
+
+        // check for EOF
+        c = nextChar();
+        if ( c == CHAR_EOF )
+        {
+            lastTokenType = AliasesStringToken.EOF;
+            return new AliasesStringToken( lastTokenType, "", pos );
+        }
+        prevChar();
+
+        // check the substring if there was an error
+        c = nextChar();
+        if ( lastTokenType == AliasesStringToken.ERROR_ALIAS_PART
+            || lastTokenType == AliasesStringToken.ERROR_ALIAS_START )
+        {
+            StringBuffer sb = new StringBuffer();
+            while ( c != CHAR_COMMA && c != CHAR_EOF )
+            {
+                sb.append( c );
+                c = nextChar();
+            }
+
+            lastTokenType = AliasesStringToken.ERROR_ALIAS_SUBSTRING;
+            return new AliasesStringToken( lastTokenType, sb.toString(), pos - sb.length()
+ 1 );
+        }
+        prevChar();
+
+        // check for ignorable whitespaces
+        c = nextChar();
+        if ( Character.isWhitespace( c ) )
+        {
+            StringBuffer sb = new StringBuffer();
+            while ( Character.isWhitespace( c ) )
+            {
+                sb.append( c );
+                c = nextChar();
+            }
+            prevChar();
+
+            lastTokenType = AliasesStringToken.WHITESPACE;
+            return new AliasesStringToken( lastTokenType, sb.toString(), pos - sb.length()
+ 1 );
+        }
+        prevChar();
+
+        // check special characters
+        c = nextChar();
+        if ( c == CHAR_COMMA )
+        {
+            lastTokenType = AliasesStringToken.COMMA;
+            return new AliasesStringToken( lastTokenType, ",", pos );
+        }
+        prevChar();
+
+        // check Alias
+        c = nextChar();
+        if ( isAliasSafeCharStart( c ) )
+        {
+            StringBuffer sb = new StringBuffer();
+            boolean hasError = false;
+
+            sb.append( c );
+
+            c = nextChar();
+            while ( c != CHAR_COMMA && c != CHAR_EOF )
+            {
+                sb.append( c );
+
+                if ( !isAliasSafeCharPart( c ) )
+                {
+                    hasError = true;
+                    break;
+                }
+
+                c = nextChar();
+            }
+            prevChar();
+
+            if ( hasError )
+            {
+                lastTokenType = AliasesStringToken.ERROR_ALIAS_PART;
+                return new AliasesStringToken( lastTokenType, sb.toString(), pos - sb.length()
+ 1 );
+            }
+            else
+            {
+                lastTokenType = AliasesStringToken.ALIAS;
+                return new AliasesStringToken( lastTokenType, sb.toString(), pos - sb.length()
+ 1 );
+            }
+        }
+        else
+        {
+            lastTokenType = AliasesStringToken.ERROR_ALIAS_START;
+            return new AliasesStringToken( lastTokenType, c + "", pos );
+        }
+    }
+
+
+    /**
+     * Determines if the specified character is
+     * permissible as the first character in an attribute type or object class
+     * alias.
+     * <p>
+     * A character may start an attribute type or object class alias if and
+     * only if one of the following conditions is true:
+     * <ul>
+     * <li> it is a letter between 'a' to 'z' and between 'A' to 'Z'
+     * </ul>
+     *
+     * <p><b>Note:</b> This method cannot handle <a
+     * href="#supplementary"> supplementary characters</a>. To support
+     * all Unicode characters, including supplementary characters, use
+     * the {@link #isJavaIdentifierStart(int)} method.
+     *
+     * @param   c the character to be tested.
+     * @return  <code>true</code> if the character may start an attribute type
+     * or object class alias.; <code>false</code> otherwise.
+     */
+    private boolean isAliasSafeCharStart( char c )
+    {
+        return ( c == 'a' || c == 'b' || c == 'c' || c == 'd' || c == 'e' || c == 'f' ||
c == 'g' || c == 'h'
+            || c == 'i' || c == 'j' || c == 'k' || c == 'l' || c == 'm' || c == 'n' || c
== 'o' || c == 'p' || c == 'q'
+            || c == 'r' || c == 's' || c == 't' || c == 'u' || c == 'v' || c == 'w' || c
== 'x' || c == 'y' || c == 'z'
+            || c == 'A' || c == 'B' || c == 'C' || c == 'D' || c == 'E' || c == 'F' || c
== 'G' || c == 'H' || c == 'I'
+            || c == 'J' || c == 'K' || c == 'L' || c == 'M' || c == 'N' || c == 'O' || c
== 'P' || c == 'Q' || c == 'R'
+            || c == 'S' || c == 'T' || c == 'U' || c == 'V' || c == 'W' || c == 'X' || c
== 'Y' || c == 'Z' );
+    }
+
+
+    /**
+     * Determines if the specified character may be part of an attribute type or
+     * object class alias as other than the first character.
+     * <p>
+     * A character may be part of an attribute type or object class alias if any 
+     * of the following are true:
+     * <ul>
+     * <li>  it is a letter between 'a' to 'z' and between 'A' to 'Z'
+     * <li>  it is a digit
+     * <li>  it is a hyphen ('-')
+     * <li>  it is a semi-colon (';')
+     * </ul>
+     *
+     * @param   c      the character to be tested.
+     * @return <code>true</code> if the character may be part of an attribute

+     * type or object class alias; <code>false</code> otherwise.
+     */
+    private boolean isAliasSafeCharPart( char c )
+    {
+        return ( c == 'a' || c == 'b' || c == 'c' || c == 'd' || c == 'e' || c == 'f' ||
c == 'g' || c == 'h'
+            || c == 'i' || c == 'j' || c == 'k' || c == 'l' || c == 'm' || c == 'n' || c
== 'o' || c == 'p' || c == 'q'
+            || c == 'r' || c == 's' || c == 't' || c == 'u' || c == 'v' || c == 'w' || c
== 'x' || c == 'y' || c == 'z'
+            || c == 'A' || c == 'B' || c == 'C' || c == 'D' || c == 'E' || c == 'F' || c
== 'G' || c == 'H' || c == 'I'
+            || c == 'J' || c == 'K' || c == 'L' || c == 'M' || c == 'N' || c == 'O' || c
== 'P' || c == 'Q' || c == 'R'
+            || c == 'S' || c == 'T' || c == 'U' || c == 'V' || c == 'W' || c == 'X' || c
== 'Y' || c == 'Z' || c == '0'
+            || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c
== '7' || c == '8' || c == '9' || c == '-' );
+    }
+}

Added: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasesStringToken.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasesStringToken.java?rev=614513&view=auto
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasesStringToken.java
(added)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/AliasesStringToken.java
Wed Jan 23 04:09:24 2008
@@ -0,0 +1,143 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.schemaeditor.model.alias;
+
+
+public class AliasesStringToken implements Comparable<AliasesStringToken>
+{
+    /** The token identifier for the start */
+    public static final int START = Integer.MIN_VALUE;
+
+    /** The token identifier for end of file */
+    public static final int EOF = -1;
+
+    /** The token identifier for a whitespace */
+    public static final int WHITESPACE = 0;
+
+    /** The token identifier for a comma ',' */
+    public static final int COMMA = 1;
+
+    /** The token identifier for an alias */
+    public static final int ALIAS = 2;
+
+    /** The token identifier for an error at the start of an alias */
+    public static final int ERROR_ALIAS_START = 3;
+
+    /** The token identifier for an error in a part (not the first character) of an alias
*/
+    public static final int ERROR_ALIAS_PART = 4;
+
+    /** The token identifier for the substring following an error in an alias */
+    public static final int ERROR_ALIAS_SUBSTRING = 5;
+
+    /** The offset. */
+    private int offset;
+
+    /** The type. */
+    private int type;
+
+    /** The value. */
+    private String value;
+
+
+    /**
+     * Creates a new instance of LdapFilterToken.
+     * 
+     * @param type the type
+     * @param value the value
+     * @param offset the offset
+     */
+    public AliasesStringToken( 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 filter
+     * 
+     * @return the start positon of the token
+     */
+    public int getOffset()
+    {
+        return offset;
+    }
+
+
+    /**
+     * Returns the length of the token in the original filter
+     * 
+     * @return the length of the token
+     */
+    public int getLength()
+    {
+        return value.length();
+    }
+
+
+    /**
+     * Gets the token type.
+     * 
+     * @return the token type
+     */
+    public int getType()
+    {
+        return type;
+    }
+
+
+    /**
+     * Gets the value of the token in the original filter.
+     * 
+     * @return the value of the token
+     */
+    public String getValue()
+    {
+        return value;
+    }
+
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    public String toString()
+    {
+        return "(" + offset + ") " + "(" + type + ") " + value;
+    }
+
+
+    /**
+     * @see java.lang.Comparable#compareTo(java.lang.Object)
+     */
+    public int compareTo( AliasesStringToken o )
+    {
+        if ( o instanceof AliasesStringToken )
+        {
+            AliasesStringToken token = ( AliasesStringToken ) o;
+            return this.offset - token.offset;
+        }
+        else
+        {
+            throw new ClassCastException( "Not instanceof AliasesToken: " + o.getClass().getName()
);
+        }
+    }
+
+}

Added: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/DefaultAlias.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/DefaultAlias.java?rev=614513&view=auto
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/DefaultAlias.java
(added)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/alias/DefaultAlias.java
Wed Jan 23 04:09:24 2008
@@ -0,0 +1,41 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.schemaeditor.model.alias;
+
+
+/**
+ * This class defines an {@link Alias}.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DefaultAlias extends AbstractAlias
+{
+    /**
+     * Creates a new instance of DefaultAlias.
+     *
+     * @param alias
+     *      the alias
+     */
+    public DefaultAlias( String alias )
+    {
+        super( alias );
+    }
+}



Mime
View raw message