You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ps...@apache.org on 2004/03/17 12:44:52 UTC

cvs commit: jakarta-commons-sandbox/id/src/java/org/apache/commons/id IdentifierUtils.java IdentifierGeneratorFactory.java

psteitz     2004/03/17 03:44:52

  Modified:    id/src/java/org/apache/commons/id IdentifierUtils.java
                        IdentifierGeneratorFactory.java
  Log:
  Added UUID generator factory methods.
  Contributed by Tim Reilly
  PR #27725
  
  Revision  Changes    Path
  1.4       +67 -6     jakarta-commons-sandbox/id/src/java/org/apache/commons/id/IdentifierUtils.java
  
  Index: IdentifierUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/id/src/java/org/apache/commons/id/IdentifierUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- IdentifierUtils.java	29 Feb 2004 16:06:33 -0000	1.3
  +++ IdentifierUtils.java	17 Mar 2004 11:44:52 -0000	1.4
  @@ -1,12 +1,12 @@
   /*
    * Copyright 2003-2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed 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.
  @@ -17,7 +17,7 @@
   
   /**
    * <p><code>IdentifierUtils</code> provides convenience methods for generating
  - * identifiers using the identifier generators provided by commons-uid.</p>
  + * identifiers using the identifier generators provided by commons-id.</p>
    *
    * <p>This class maintains a static instance of each generator and uses this instance
    * to generate identifiers via its corresponding nextXxx() method.</p>
  @@ -28,7 +28,7 @@
    * methods will throw null pointer exceptions. This will not happen unless a custom
    * configuration is used and the specified factory class fails to load.</p>
    *
  - * @author Commons-Uid team
  + * @author Commons-Id team
    * @version $Id$
    */
   public class IdentifierUtils {
  @@ -113,6 +113,32 @@
       public static final StringIdentifierGenerator STRING_SESSION_IDENTIFIER_GENERATOR =
           createSessionIdGenerator();
   
  +
  +    /**
  +     * <p>Singleton instance of the uuid <code>VersionOneGenerator</code>.</p>
  +     *
  +     * <p>Generates {@link org.apache.commons.id.uuid.UUID} Objects according to the
  +     * <a href="http://www.ietf.org/internet-drafts/draft-mealling-uuid-urn-02.txt">
  +     * IETF Draft UUID specification</a>.
  +     * </p>
  +     *
  +     */
  +    public static final IdentifierGenerator UUID_VERSION_ONE_GENERATOR =
  +        createUUIDVersionOneGenerator();
  +
  +    /**
  +     * <p>Singleton instance of the uuid <code>VersionFourGenerator</code>.</p>
  +     *
  +     * <p>Generates {@link org.apache.commons.id.uuid.UUID} Objects according to the
  +     * <a href="http://www.ietf.org/internet-drafts/draft-mealling-uuid-urn-02.txt">
  +     * IETF Draft UUID specification</a>.
  +     * </p>
  +     *
  +     */
  +    public static final IdentifierGenerator UUID_VERSION_FOUR_GENERATOR =
  +        createUUIDVersionFourGenerator();
  +
  +
       //---------------------------------------------------------------------------------
   
       /**
  @@ -265,4 +291,39 @@
                return null;
            }
       }
  +
  +    /**
  +     * <p>Gets a IdentifierGenerator that produces version one UUID to initialize
  +     * UUID_VERSION_ONE_GENERATOR with.</p>
  +     *
  +     * <p>Returns null if instance creation fails.</p>
  +     *
  +     * @return a new IdentifierGenerator that produces version one UUIDs.
  +     *
  +     */
  +    private static IdentifierGenerator createUUIDVersionOneGenerator() {
  +         try {
  +             return factory.uuidVersionOneGenerator(); // will toss NPE if factory is null
  +         } catch (Exception ex) {
  +             return null;
  +         }
  +    }
  +
  +    /**
  +     * <p>Gets a IdentifierGenerator that produces version four UUID to initialize
  +     * UUID_VERSION_FOUR_GENERATOR with.</p>
  +     *
  +     * <p>Returns null if instance creation fails.</p>
  +     *
  +     * @return a new IdentifierGenerator that produces version four UUIDs.
  +     *
  +     */
  +    private static IdentifierGenerator createUUIDVersionFourGenerator() {
  +         try {
  +             return factory.uuidVersionFourGenerator(); // will toss NPE if factory is null
  +         } catch (Exception ex) {
  +             return null;
  +         }
  +    }
  +
   }
  
  
  
  1.4       +25 -9     jakarta-commons-sandbox/id/src/java/org/apache/commons/id/IdentifierGeneratorFactory.java
  
  Index: IdentifierGeneratorFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/id/src/java/org/apache/commons/id/IdentifierGeneratorFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- IdentifierGeneratorFactory.java	29 Feb 2004 16:06:33 -0000	1.3
  +++ IdentifierGeneratorFactory.java	17 Mar 2004 11:44:52 -0000	1.4
  @@ -1,12 +1,12 @@
   /*
    * Copyright 2003-2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed 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.
  @@ -16,6 +16,8 @@
   
   package org.apache.commons.id;
   
  +import java.lang.reflect.InvocationTargetException;
  +
   import org.apache.commons.discovery.tools.DiscoverClass;
   
   /**
  @@ -136,13 +138,27 @@
       public abstract StringIdentifierGenerator sessionIdGenerator();
   
       /**
  -     * <p>Gets a new {@link StringIdentifierGenerator} that generates a sequence of String objects
  -     * that conform to the <a href="http://www.ietf.org/internet-drafts/draft-mealling-uuid-urn-01.txt">
  +     * <p>Gets a new {@link IndentifierGenerator} that generates version one UUID objects
  +     * that conform to the <a href="http://www.ietf.org/internet-drafts/draft-mealling-uuid-urn-02.txt">
        * IETF Draft UUID specification</a>.</p>
        *
  -     * <p>NOT IMPLEMENTED YET -- throws UnsupportedOperationExcption</p>
        *
  -     * @return a new StringIdentifierGenerator
  +     * @return a new IdentifierGenerator that generates version one UUIDs.
  +     * @throws NoSuchMethodException exception thrown while instantiating the generator.
  +     * @throws InvocationTargetException exception thrown while instantiating the generator.
  +     * @throws IllegalAccessException exception thrown while instantiating the generator.
  +     * @throws InstantiationException exception thrown while instantiating the generator.
  +     */
  +    public abstract IdentifierGenerator uuidVersionOneGenerator() throws NoSuchMethodException, InvocationTargetException,
  +        IllegalAccessException, InstantiationException;
  +
  +    /**
  +     * <p>Gets a new {@link IdentifierGenerator} that generates version four UUID Obejcts that conform to the
  +     * <a href="http://www.ietf.org/internet-drafts/draft-mealling-uuid-urn-02.txt">
  +     * IETF Draft UUID specification</a>.</p>
  +     *
  +     *
  +     * @return a new IdentifierGenerator that generates version four UUIDs.
        */
  -    public abstract StringIdentifierGenerator uuidGenerator();
  +    public abstract IdentifierGenerator uuidVersionFourGenerator();
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org