juergen     02/05/17 01:35:41

  Modified:    src/share/org/apache/slide/content NodeProperty.java
  Log:
  Added inner class NamespaceCache.
  (ralf)
  
  Revision  Changes    Path
  1.13      +106 -4    
jakarta-slide/src/share/org/apache/slide/content/NodeProperty.java
  
  Index: NodeProperty.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/content/NodeProperty.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- NodeProperty.java 14 May 2002 11:36:22 -0000      1.12
  +++ NodeProperty.java 17 May 2002 08:35:41 -0000      1.13
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/content/NodeProperty.java,v 1.12 
2002/05/14 11:36:22 pnever Exp $
  - * $Revision: 1.12 $
  - * $Date: 2002/05/14 11:36:22 $
  + * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/content/NodeProperty.java,v 1.13 
2002/05/17 08:35:41 juergen Exp $
  + * $Revision: 1.13 $
  + * $Date: 2002/05/17 08:35:41 $
    *
    * ====================================================================
    *
  @@ -74,11 +74,13 @@
   import org.apache.slide.common.Domain;
   import org.apache.slide.common.ObjectValidationFailedException;
   
  +import org.jdom.Namespace;
  +
   /**
    * Node property class
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
  - * @version $Revision: 1.12 $
  + * @version $Revision: 1.13 $
    */
   public final class NodeProperty implements Serializable, Cloneable {
       
  @@ -555,4 +557,104 @@
               this.id = id;
           }
       }
  +    
  +    /**
  +     * The usage of this class avoids the creation of mutliple Namespace objects
  +     * with the same URI but different prefix. Just use it as a replacement
  +     * for the <code>org.jdom.Namespace</code>.
  +     * It also predefines Namespace objects for the <code>DAV:</code> and
  +     * the <code>http://jakarta.apache.org/slide/</code> namespace
  +     * (with an appropriate prefix).
  +     */
  +    public static class NamespaceCache {
  +        
  +        /**
  +         * String constant for <code>S</code>.
  +         */
  +        public final static String SLIDE_PREFIX = "S";
  +        
  +        /**
  +         * String constant for <code>http://jakarta.apache.org/slide/</code>.
  +         */
  +        public final static String SLIDE_URI = NodeProperty.SLIDE_NAMESPACE;
  +        
  +        /**
  +         * Namespace with {@link #SLIDE_PREFIX SLIDE_PREFIX} and
  +         * {@link #SLIDE_URI SLIDE_URI}.
  +         */
  +        public final static Namespace SLIDE_NAMESPACE = getNamespace(SLIDE_PREFIX, 
SLIDE_URI);;
  +        
  +        /**
  +         * String constant for <code>D</code>.
  +         */
  +        public final static String DEFAULT_PREFIX = "D";
  +        
  +        /**
  +         * String constant for <code>DAV:</code>.
  +         */
  +        public final static String DEFAULT_URI = NodeProperty.DEFAULT_NAMESPACE;
  +        
  +        /**
  +         * Namespace with {@link #DEFAULT_PREFIX DEFAULT_PREFIX} and
  +         * {@link #DEFAULT_URI DEFAULT_URI}.
  +         */
  +        public final static Namespace DEFAULT_NAMESPACE = 
getNamespace(DEFAULT_PREFIX, DEFAULT_URI);;
  +        
  +        /**
  +         * Maps the namespace' URI to the Namespace object.
  +         */
  +        protected static Map namespaceMap;
  +        
  +        
  +        /**
  +         * Returns the Namespace for the given <code>uri</code>.
  +         * If there is already an entry in the cache for this URI,
  +         * this Namespace will be returned.
  +         * Otherwise a new Namespace with the prefix <code>""</code>
  +         * (default namespace) will be created and put into the cache.
  +         *
  +         * @param      uri  the URI for which to return the Namespace.
  +         *
  +         * @return     the Namespace for the given URI.
  +         */
  +        public static Namespace getNamespace(String uri) {
  +            return getNamespace("", uri);
  +        }
  +        
  +        /**
  +         * Returns the Namespace for the given <code>prefix</code> and
  +         * <code>uri</code>.
  +         * If there is already an entry in the cache for this URI,
  +         * this Namespace will be returned.
  +         * Otherwise a new Namespace with the given <code>prefix</code>
  +         * and <code>uri</code> will be created and put into the cache.
  +         *
  +         * @param      prefix  the prefix for which to return the Namespace.
  +         * @param      uri     the URI for which to return the Namespace.
  +         *
  +         * @return     the Namespace for the given URI.
  +         */
  +        public static Namespace getNamespace(String prefix, String uri) {
  +            
  +            Namespace namespace = (Namespace)getNamespaceMap().get(uri);
  +            if (namespace == null) {
  +                namespace = Namespace.getNamespace(prefix, uri);
  +                getNamespaceMap().put(namespace.getURI(), namespace);
  +            }
  +            return namespace;
  +        }
  +        
  +        /**
  +         * Returns the {@link #namespaceMap namespaceMap}.
  +         *
  +         * @return     the {@link #namespaceMap namespaceMap}.
  +         */
  +        protected static Map getNamespaceMap() {
  +            if (namespaceMap == null) {
  +                namespaceMap = new HashMap();
  +            }
  +            return namespaceMap;
  +        }
  +    }
  +    
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to