001 /*
002 * JBoss, Home of Professional Open Source.
003 * Copyright 2008, Red Hat Middleware LLC, and individual contributors
004 * as indicated by the @author tags. See the copyright.txt file in the
005 * distribution for a full listing of individual contributors.
006 *
007 * This is free software; you can redistribute it and/or modify it
008 * under the terms of the GNU Lesser General Public License as
009 * published by the Free Software Foundation; either version 2.1 of
010 * the License, or (at your option) any later version.
011 *
012 * This software is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this software; if not, write to the Free
019 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021 */
022 package org.jboss.dna.graph.properties;
023
024 import java.util.Set;
025 import net.jcip.annotations.ThreadSafe;
026
027 /**
028 * Registry of namespaces, which are used to provide isolated and independent domains for {@link Name names}.
029 *
030 * @author Randall Hauch
031 */
032 @ThreadSafe
033 public interface NamespaceRegistry {
034
035 /**
036 * Return the namespace URI that is currently mapped to the empty prefix, or null if there is no current default namespace.
037 *
038 * @return the namespace URI that represents the default namespace, or null if there is no default namespace
039 */
040 String getDefaultNamespaceUri();
041
042 /**
043 * Get the namespace URI for the supplied prefix.
044 *
045 * @param prefix the namespace prefix
046 * @return the namespace URI for the supplied prefix, or null if there is no namespace currently registered to use that prefix
047 * @throws IllegalArgumentException if the prefix is null
048 */
049 String getNamespaceForPrefix( String prefix );
050
051 /**
052 * Return the prefix used for the supplied namespace URI.
053 *
054 * @param namespaceUri the namespace URI
055 * @param generateIfMissing true if the namespace URI has not already been registered and the method should auto-register the
056 * namespace with a generated prefix, or false if the method should never auto-register the namespace
057 * @return the prefix currently being used for the namespace, or <code>null</code> if the namespace has not been registered
058 * and <code>generateIfMissing</code> is <code>false</code>
059 * @throws IllegalArgumentException if the namespace URI is null
060 * @see #isRegisteredNamespaceUri(String)
061 */
062 String getPrefixForNamespaceUri( String namespaceUri,
063 boolean generateIfMissing );
064
065 /**
066 * Return whether there is a registered prefix for the supplied namespace URI.
067 *
068 * @param namespaceUri the namespace URI
069 * @return true if the supplied namespace has been registered with a prefix, or false otherwise
070 * @throws IllegalArgumentException if the namespace URI is null
071 */
072 boolean isRegisteredNamespaceUri( String namespaceUri );
073
074 /**
075 * Register a new namespace using the supplied prefix, returning the namespace URI previously registered under that prefix.
076 *
077 * @param prefix the prefix for the namespace, or null if a namesapce prefix should be generated automatically
078 * @param namespaceUri the namespace URI
079 * @return the namespace URI that was previously registered with the supplied prefix, or null if the prefix was not previously
080 * bound to a namespace URI
081 * @throws IllegalArgumentException if the namespace URI is null
082 */
083 String register( String prefix,
084 String namespaceUri );
085
086 /**
087 * Obtain the set of namespaces that are registered.
088 *
089 * @return the set of
090 */
091 Set<String> getRegisteredNamespaceUris();
092
093 }