directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r776130 - in /directory: apacheds/trunk/schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/ shared/trunk/ldap-constants/src/main/java/org/apache/directory/shared/ldap/constants/ shared/trunk/ldap/src/main/java/org/a...
Date Mon, 18 May 2009 23:09:56 GMT
Author: elecharny
Date: Mon May 18 23:09:56 2009
New Revision: 776130

URL: http://svn.apache.org/viewvc?rev=776130&view=rev
Log:
Added the CSN and UUID SyntaxChecker into the registries. Added a isValid() static method
in the CSN class

Added:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxes/CsnSyntaxChecker.java
Modified:
    directory/apacheds/trunk/schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/ApacheSyntaxProducer.java
    directory/shared/trunk/ldap-constants/src/main/java/org/apache/directory/shared/ldap/constants/SchemaConstants.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/csn/CSN.java

Modified: directory/apacheds/trunk/schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/ApacheSyntaxProducer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/ApacheSyntaxProducer.java?rev=776130&r1=776129&r2=776130&view=diff
==============================================================================
--- directory/apacheds/trunk/schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/ApacheSyntaxProducer.java
(original)
+++ directory/apacheds/trunk/schema-bootstrap/src/main/java/org/apache/directory/server/schema/bootstrap/ApacheSyntaxProducer.java
Mon May 18 23:09:56 2009
@@ -26,10 +26,12 @@
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.schema.AbstractSyntax;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
+import org.apache.directory.shared.ldap.schema.syntaxes.CsnSyntaxChecker;
 import org.apache.directory.shared.ldap.schema.syntaxes.JavaByteSyntaxChecker;
 import org.apache.directory.shared.ldap.schema.syntaxes.JavaIntegerSyntaxChecker;
 import org.apache.directory.shared.ldap.schema.syntaxes.JavaLongSyntaxChecker;
 import org.apache.directory.shared.ldap.schema.syntaxes.JavaShortSyntaxChecker;
+import org.apache.directory.shared.ldap.schema.syntaxes.UuidSyntaxChecker;
 
 
 
@@ -63,6 +65,7 @@
     {
         AbstractSyntax syntax = null;
         
+        // A Syntax for Java byte, OID = 1.3.6.1.4.1.18060.0.4.1.0.0
         syntax = new AbstractSyntax( SchemaConstants.JAVA_BYTE_SYNTAX, "a syntax for java
byte values", true )
         {
             private static final long serialVersionUID = 1L;
@@ -83,9 +86,39 @@
                 return JAVA_BYTE_SYNTAX_CHECKER;
             }
         };
+        
         syntax.setSchema( "apache" );
         cb.schemaObjectProduced( this, syntax.getOid(), syntax );
 
+        // A Syntax for Java char, OID = 1.3.6.1.4.1.18060.0.4.1.0.1
+        // TODO : Define the JavaCharSyntaxChecker
+        /*
+        syntax = new AbstractSyntax( SchemaConstants.JAVA_CHAR_SYNTAX, "a syntax for java
char values", true )
+        {
+            private static final long serialVersionUID = 1L;
+            private final JavaByteSyntaxChecker JAVA_CHAR_SYNTAX_CHECKER = new JavaCharSyntaxChecker();
+
+            public String getName()
+            {
+                return "JAVA_CHAR";
+            }
+            
+            public String[] getNames()
+            {
+                return new String[] { "JAVA_CHAR" };
+            }
+            
+            public SyntaxChecker getSyntaxChecker() throws NamingException
+            {
+                return JAVA_CHAR_SYNTAX_CHECKER;
+            }
+        };
+
+        syntax.setSchema( "apache" );
+        cb.schemaObjectProduced( this, syntax.getOid(), syntax );
+        */
+        
+        // A Syntax for Java short, OID = 1.3.6.1.4.1.18060.0.4.1.0.2
         syntax = new AbstractSyntax( SchemaConstants.JAVA_SHORT_SYNTAX, "a syntax for java
short values", true )
         {
             private static final long serialVersionUID = 1L;
@@ -106,9 +139,36 @@
                 return JAVA_SHORT_SYNTAX_CHECKER;
             }
         };
+        
         syntax.setSchema( "apache" );
         cb.schemaObjectProduced( this, syntax.getOid(), syntax );
 
+        // A Syntax for Java long, OID = 1.3.6.1.4.1.18060.0.4.1.0.3
+        syntax = new AbstractSyntax( SchemaConstants.JAVA_LONG_SYNTAX, "a syntax for java
long values", true )
+        {
+            private static final long serialVersionUID = 1L;
+            private final JavaLongSyntaxChecker JAVA_LONG_SYNTAX_CHECKER = new JavaLongSyntaxChecker();
+
+            public String getName()
+            {
+                return "JAVA_LONG";
+            }
+            
+            public String[] getNames()
+            {
+                return new String[] { "JAVA_LONG" };
+            }
+            
+            public SyntaxChecker getSyntaxChecker() throws NamingException
+            {
+                return JAVA_LONG_SYNTAX_CHECKER;
+            }
+        };
+        
+        syntax.setSchema( "apache" );
+        cb.schemaObjectProduced( this, syntax.getOid(), syntax );
+
+        // A Syntax for Java int, OID = 1.3.6.1.4.1.18060.0.4.1.0.4
         syntax = new AbstractSyntax( SchemaConstants.JAVA_INT_SYNTAX, "a syntax for java
int values", true )
         {
             private static final long serialVersionUID = 1L;
@@ -129,29 +189,57 @@
                 return JAVA_INT_SYNTAX_CHECKER;
             }
         };
+        
         syntax.setSchema( "apache" );
         cb.schemaObjectProduced( this, syntax.getOid(), syntax );
 
-        syntax = new AbstractSyntax( SchemaConstants.JAVA_LONG_SYNTAX, "a syntax for java
long values", true )
+        // A Syntax for UUID, OID = 1.3.6.1.1.16.1
+        syntax = new AbstractSyntax( SchemaConstants.UUID_SYNTAX, "a syntax for UUID values",
false )
         {
             private static final long serialVersionUID = 1L;
-            private final JavaLongSyntaxChecker JAVA_LONG_SYNTAX_CHECKER = new JavaLongSyntaxChecker();
+            private final UuidSyntaxChecker UUID_SYNTAX_CHECKER = new UuidSyntaxChecker();
 
             public String getName()
             {
-                return "JAVA_LONG";
+                return "UUID";
             }
             
             public String[] getNames()
             {
-                return new String[] { "JAVA_LONG" };
+                return new String[] { "UUID" };
             }
             
             public SyntaxChecker getSyntaxChecker() throws NamingException
             {
-                return JAVA_LONG_SYNTAX_CHECKER;
+                return UUID_SYNTAX_CHECKER;
             }
         };
+        
+        syntax.setSchema( "apache" );
+        cb.schemaObjectProduced( this, syntax.getOid(), syntax );
+
+        // A Syntax for CSN, OID = 1.3.6.1.4.1.4203.666.11.2.1
+        syntax = new AbstractSyntax( SchemaConstants.CSN_SYNTAX, "a syntax for CSN values",
false )
+        {
+            private static final long serialVersionUID = 1L;
+            private final CsnSyntaxChecker CSN_SYNTAX_CHECKER = new CsnSyntaxChecker();
+
+            public String getName()
+            {
+                return "CSN";
+            }
+            
+            public String[] getNames()
+            {
+                return new String[] { "CSN" };
+            }
+            
+            public SyntaxChecker getSyntaxChecker() throws NamingException
+            {
+                return CSN_SYNTAX_CHECKER;
+            }
+        };
+        
         syntax.setSchema( "apache" );
         cb.schemaObjectProduced( this, syntax.getOid(), syntax );
     }

Modified: directory/shared/trunk/ldap-constants/src/main/java/org/apache/directory/shared/ldap/constants/SchemaConstants.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-constants/src/main/java/org/apache/directory/shared/ldap/constants/SchemaConstants.java?rev=776130&r1=776129&r2=776130&view=diff
==============================================================================
--- directory/shared/trunk/ldap-constants/src/main/java/org/apache/directory/shared/ldap/constants/SchemaConstants.java
(original)
+++ directory/shared/trunk/ldap-constants/src/main/java/org/apache/directory/shared/ldap/constants/SchemaConstants.java
Mon May 18 23:09:56 2009
@@ -435,6 +435,7 @@
     String UTC_TIME_SYNTAX = "1.3.6.1.4.1.1466.115.121.1.53";
     String DIRECTORY_STRING_SYNTAX = "1.3.6.1.4.1.1466.115.121.1.15";
     String UUID_SYNTAX = "1.3.6.1.1.16.1";
+    String CSN_SYNTAX = "1.3.6.1.4.1.4203.666.11.2.1";
 
     String JAVA_BYTE_SYNTAX = "1.3.6.1.4.1.18060.0.4.1.0.0";
     String JAVA_CHAR_SYNTAX = "1.3.6.1.4.1.18060.0.4.1.0.1";

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/csn/CSN.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/csn/CSN.java?rev=776130&r1=776129&r2=776130&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/csn/CSN.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/csn/CSN.java
Mon May 18 23:09:56 2009
@@ -173,8 +173,19 @@
             }
         }
         
+        int millis = 0;
+        
         // And add the milliseconds and microseconds now
-        int millis = Integer.valueOf( timestampStr.substring( 15, 21 ) );
+        try
+        {
+            millis = Integer.valueOf( timestampStr.substring( 15, 21 ) );
+        }
+        catch ( NumberFormatException nfe )
+        {
+            String message = "The microseconds part is invalid";
+            LOG.error( message );
+            throw new InvalidCSNException( message );
+        }
         
         tempTimestamp += (millis/1000);
         timestamp = tempTimestamp;
@@ -259,6 +270,128 @@
 
 
     /**
+     * Check if the given String is a valid CSN.
+     * 
+     * @param value The String to check
+     * @return <code>true</code> if the String is a valid CSN
+     */
+    public static boolean isValid( String value )
+    {
+        if ( StringTools.isEmpty( value ) )
+        {
+            return false;
+        }
+        
+        if ( value.length() != 40 )
+        {
+            return false;
+        }
+    
+        // Get the Timestamp
+        int sepTS = value.indexOf( '#' );
+        
+        if ( sepTS < 0 )
+        {
+            return false;
+        }
+        
+        String timestampStr = value.substring( 0, sepTS ).trim();
+        
+        if ( timestampStr.length() != 22 )
+        {
+            return false;
+        }
+        
+        // Let's transform the Timestamp by removing the mulliseconds and microseconds
+        String realTimestamp = timestampStr.substring( 0, 14 );
+        
+        synchronized ( sdf )
+        {
+            try
+            {
+                sdf.parse( realTimestamp ).getTime();
+            }
+            catch ( ParseException pe )
+            {
+                return false;
+            }
+        }
+        
+        // And add the milliseconds and microseconds now
+        try
+        {
+            Integer.valueOf( timestampStr.substring( 15, 21 ) );
+        }
+        catch ( NumberFormatException nfe )
+        {
+            return false;
+        }
+    
+        // Get the changeCount. It should be an hex number prefixed with '0x'
+        int sepCC = value.indexOf( '#', sepTS + 1 );
+        
+        if ( sepCC < 0 )
+        {
+            return false;
+        }
+    
+        String changeCountStr = value.substring( sepTS + 1, sepCC ).trim();
+        
+        try
+        {
+            Integer.parseInt( changeCountStr, 16 ); 
+        }
+        catch ( NumberFormatException nfe )
+        {
+            return false;
+        }
+        
+        // Get the replicaIDfalse
+        int sepRI = value.indexOf( '#', sepCC + 1 );
+        
+        if ( sepRI < 0 )
+        {
+            return false;
+        }
+    
+        String replicaIdStr = value.substring( sepCC + 1, sepRI ).trim();
+        
+        if ( StringTools.isEmpty( replicaIdStr ) )
+        {
+            return false;
+        }
+        
+        try
+        {
+            Integer.parseInt( replicaIdStr, 16 ); 
+        }
+        catch ( NumberFormatException nfe )
+        {
+            return false;
+        }
+        
+        // Get the modification number
+        if ( sepCC == value.length() )
+        {
+            return false;
+        }
+        
+        String operationNumberStr = value.substring( sepRI + 1 ).trim();
+        
+        try
+        {
+            Integer.parseInt( operationNumberStr, 16 ); 
+        }
+        catch ( NumberFormatException nfe )
+        {
+            return false;
+        }
+        
+        return true;
+    }
+
+
+    /**
      * Creates a new instance of SimpleCSN from the serialized data
      *
      * @param value The byte array which contains the serialized CSN

Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxes/CsnSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxes/CsnSyntaxChecker.java?rev=776130&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxes/CsnSyntaxChecker.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntaxes/CsnSyntaxChecker.java
Mon May 18 23:09:56 2009
@@ -0,0 +1,95 @@
+/*
+ *  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, eCopyOfUuidSyntaxCheckerither express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.schema.syntaxes;
+
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.csn.CSN;
+import org.apache.directory.shared.ldap.csn.InvalidCSNException;
+import org.apache.directory.shared.ldap.schema.AbstractSyntaxChecker;
+import org.apache.directory.shared.ldap.schema.SyntaxChecker;
+
+
+/**
+ * An CSN syntax checker.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 736240 $
+ */
+public class CsnSyntaxChecker extends AbstractSyntaxChecker
+{
+    /** the Apache assigned internal OID for this syntax checker */
+    public static final SyntaxChecker INSTANCE = new CsnSyntaxChecker();
+
+
+    /**
+     * Creates a new instance of CsnSyntaxChecker.
+     */
+    public CsnSyntaxChecker()
+    {
+        super( SchemaConstants.CSN_SYNTAX );
+    }
+
+
+    /**
+     * 
+     * Creates a new instance of CsnSyntaxChecker.
+     * 
+     * @param oid the oid to associate with this new SyntaxChecker
+     *
+     */
+    protected CsnSyntaxChecker( String oid )
+    {
+        super( oid );
+    }
+
+    
+    /**
+     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#isValidSyntax(Object)
+     * 
+     * The value is stored as a String internally.
+     * 
+     * @param value the value of some attribute with the syntax
+     * @return true if the value is in the valid syntax, false otherwise
+     */
+    public boolean isValidSyntax( Object value )
+    {
+        if ( value == null )
+        {
+            return false;
+        }
+        
+        if ( ! ( value instanceof String ) )
+        {
+            return false;
+        }
+        
+        String csnStr = (String)value;
+        
+        // It must be a valid CSN : try to create a new one.
+        try
+        {
+            return CSN.isValid( csnStr );
+        }
+        catch ( InvalidCSNException icsne )
+        {
+            return false;
+        }
+    }
+}



Mime
View raw message