dbertoni    00/11/27 11:46:33

  Modified:    c/src/XPath QName.cpp QName.hpp
  Added:       c/src/XPath QNameByReference.cpp QNameByReference.hpp
                        QNameByValue.cpp QNameByValue.hpp
  Log:
  Made QName an abstract class, and provided two different implementations.
  
  Revision  Changes    Path
  1.13      +1 -145    xml-xalan/c/src/XPath/QName.cpp
  
  Index: QName.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/QName.cpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- QName.cpp 2000/11/02 01:45:58     1.12
  +++ QName.cpp 2000/11/27 19:46:21     1.13
  @@ -61,7 +61,6 @@
   
   #include <PlatformSupport/DOMStringHelper.hpp>
   #include <PlatformSupport/STLHelper.hpp>
  -#include <PlatformSupport/XSLException.hpp>
   #include <PlatformSupport/XalanUnicode.hpp>
   
   
  @@ -70,161 +69,18 @@
   
   
   
  -#include "ElementPrefixResolverProxy.hpp"
  -#include "PrefixResolver.hpp"
  -#include "XPathSupport.hpp"
  -
  -
  -
   const XalanDOMString QName::s_emptyString;
   
   
  -
  -QName::QName() :
  -     m_namespace(),
  -     m_localpart()
  -{
  -}
  -
  -
  -
  -QName::QName(
  -                     const XalanDOMString&   theNamespace,
  -                     const XalanDOMString&   theLocalPart) :
  -     m_namespace(theNamespace),
  -     m_localpart(theLocalPart)
  -{
  -}
  -
  -
  -
  -QName::QName(
  -                     const XalanDOMString&           qname,
  -                     const NamespacesStackType&      namespaces) :
  -     m_namespace(),
  -     m_localpart()
  -{
  -     initialize(c_wstr(qname), namespaces);
  -}
  -
  -
  -
  -QName::QName(
  -                     const XalanDOMChar*                     qname,
  -                     const NamespacesStackType&      namespaces) :
  -     m_namespace(),
  -     m_localpart()
  -{
  -     assert(qname != 0);
  -
  -     initialize(qname, namespaces);
  -}
  -
  -
   
  -QName::QName(
  -                     const XalanDOMString&   qname,
  -                     const XalanElement*             namespaceContext,
  -                     const XPathEnvSupport&  envSupport,
  -                     const XPathSupport&     support) :
  -     m_namespace(),
  -     m_localpart()
  +QName::QName()
   {
  -     ElementPrefixResolverProxy      theProxy(namespaceContext, envSupport, 
support);
  -
  -     resolvePrefix(qname, theProxy);
  -}
  -
  -
  -
  -QName::QName(
  -                     const XalanDOMString&   qname,
  -                     const PrefixResolver&   theResolver) :
  -     m_namespace(),
  -     m_localpart()
  -{
  -     resolvePrefix(qname, theResolver);
   }
   
   
   
   QName::~QName()
   {
  -}
  -
  -
  -
  -bool
  -QName::equals(const QName&   theRHS) const
  -{
  -     return ::equals(m_localpart, theRHS.m_localpart) &&
  -                ::equals(m_namespace, theRHS.m_namespace);
  -}
  -
  -
  -
  -void
  -QName::initialize(
  -                     const XalanDOMChar*                     qname,
  -                     const NamespacesStackType&      namespaces)
  -{
  -     const unsigned int      indexOfNSSep = indexOf(qname, 
XalanUnicode::charColon);
  -
  -     if(indexOfNSSep < length(qname))
  -     {
  -             const XalanDOMString            prefix = substring(qname, 0, 
indexOfNSSep);
  -             if(::equals(prefix, DOMServices::s_XMLNamespace))
  -                     return;
  -             m_namespace = getNamespaceForPrefix(namespaces, prefix);
  -             if(0 == length(m_namespace))
  -             {
  -                     throw XSLException(TranscodeFromLocalCodePage("Prefix 
must resolve to a namespace: ") + prefix);
  -             }
  -             m_localpart =  substring(qname, indexOfNSSep + 1);
  -     }
  -     else
  -             m_localpart = qname;
  -}
  -
  -
  -
  -void
  -QName::resolvePrefix(
  -                     const XalanDOMString&   qname,
  -                     const PrefixResolver&   theResolver)
  -{
  -     const unsigned int      indexOfNSSep = indexOf(qname, 
XalanUnicode::charColon);
  -     const unsigned int      theLength = length(qname);
  -
  -     if(indexOfNSSep < theLength)
  -     {
  -             const XalanDOMString    prefix = substring(qname, 0, 
indexOfNSSep);
  -
  -             if(::equals(prefix, DOMServices::s_XMLString))
  -             {
  -                     m_namespace = DOMServices::s_XMLNamespaceURI;
  -             }
  -             // The default namespace is not resolved.
  -             else if(::equals(prefix, DOMServices::s_XMLNamespace))
  -             {
  -                     return;
  -             }
  -             else
  -             {
  -                     m_namespace = theResolver.getNamespaceForPrefix(prefix);
  -             }  
  -
  -             if(0 == length(m_namespace))
  -             {
  -                     throw XSLException(TranscodeFromLocalCodePage("Prefix 
must resolve to a namespace: ") + prefix);
  -             }
  -     }
  -     else
  -     {
  -             // $$$ ToDo: error or warning...
  -     }
  -
  -     m_localpart = indexOfNSSep == theLength ? qname : substring(qname, 
indexOfNSSep + 1);
   }
   
   
  
  
  
  1.11      +37 -96    xml-xalan/c/src/XPath/QName.hpp
  
  Index: QName.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/QName.hpp,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- QName.hpp 2000/11/02 01:45:59     1.10
  +++ QName.hpp 2000/11/27 19:46:23     1.11
  @@ -118,64 +118,7 @@
        explicit
        QName();
   
  -     /**
  -      * Construct a QName, with the supplied namespace and local part.
  -      *
  -      * @param theNamespace namespace string
  -      * @param theLocalPart local part string
  -      */
  -     QName(
  -                     const XalanDOMString&   theNamespace,
  -                     const XalanDOMString&   theLocalPart);
  -
  -     /**
  -      * Construct a QName from a string, resolving the prefix using the given
  -      * namespace vector stack. The default namespace is not resolved.
  -      *
  -      * @param qname      QName string
  -      * @param namespaces namespace vector stack to use
  -      */
  -     QName(
  -                     const XalanDOMString&           qname,
  -                     const NamespacesStackType&      namespaces);
  -
  -     /**
  -      * Construct a QName from a string, resolving the prefix using the given
  -      * namespace vector stack. The default namespace is not resolved.
  -      *
  -      * @param qname      QName string
  -      * @param namespaces namespace vector stack to use
  -      */
  -     QName(
  -                     const XalanDOMChar*                     qname,
  -                     const NamespacesStackType&      namespaces);
  -
  -     /**
  -      * Construct a QName from a string, resolving the prefix using the given
  -      * namespace context. The default namespace is not resolved.
  -      *
  -      * @param qname            QName string
  -      * @param namespaceContext context object for namespace resolution
  -      * @param envSupport       XPath environment support class instance
  -      * @param support          XPath support class instance
  -      */
  -     QName(
  -                     const XalanDOMString&   qname,
  -                     const XalanElement*             namespaceContext,
  -                     const XPathEnvSupport&  envSupport,
  -                     const XPathSupport&             support);
  -
  -     /**
  -      * Construct a QName from a string, resolving the prefix using the given
  -      * prefix resolver. The default namespace is not resolved.
  -      *
  -      * @param qname            QName string
  -      * @param theResolver prefix resolver to use
  -      */
  -     QName(
  -                     const XalanDOMString&           qname,
  -                     const PrefixResolver&   theResolver);
  -
  +     virtual
        ~QName();
   
        /**
  @@ -183,31 +126,26 @@
         * 
         * @return local part string
         */
  -     const XalanDOMString&
  -     getLocalPart() const
  -     {
  -             return m_localpart;
  -     }
  +     virtual const XalanDOMString&
  +     getLocalPart() const = 0;
   
        /**
         * Retrieve the namespace of qualified name.
         * 
         * @return namespace string
         */
  -     const XalanDOMString&
  -     getNamespace() const
  -     {
  -             return m_namespace;
  -     }
  +     virtual const XalanDOMString&
  +     getNamespace() const = 0;
   
        /**
         * Whether the qualified name is empty.
         * 
         * @return true if namespace and local part are both empty
         */
  -     bool isEmpty() const
  +     bool
  +     isEmpty() const
        {
  -             return (::isEmpty(m_namespace) && ::isEmpty(m_localpart));
  +             return ::isEmpty(getNamespace()) && ::isEmpty(getLocalPart());
        }
   
        /**
  @@ -218,19 +156,12 @@
         * @return true if namespace and local part are both empty
         */
        bool
  -     equals(const QName&             theRHS) const;
  -
  -     /**
  -      * Override equals and agree that we're equal if the passed object is a
  -      * string and it matches the name of the arg.
  -      * 
  -      * @param theRHS namespace to compare
  -      * @return true if namespace and local part are both empty
  -      */
  -     bool
  -     operator==(const QName&         theRHS) const
  +     equals(const QName&             theRHS) const
        {
  -             return equals(theRHS);
  +             // Note that we do not use our member variables here.  See
  +             // class QNameReference for details...
  +             return ::equals(getLocalPart(), theRHS.getLocalPart()) &&
  +                        ::equals(getNamespace(), theRHS.getNamespace());
        }
   
        /**
  @@ -287,24 +218,30 @@
                        const XalanDOMString&           uri,
                        bool                                            reverse 
= true);
   
  -private:
  +protected:
   
  -     void
  -     initialize(
  -                     const XalanDOMChar*                     qname,
  -                     const NamespacesStackType&      namespaces);
  +     static const XalanDOMString             s_emptyString;
  +};
   
  -     void
  -     resolvePrefix(
  -                     const XalanDOMString&   qname,
  -                     const PrefixResolver&   theResolver);
   
  -     XalanDOMString  m_namespace;
   
  -     XalanDOMString  m_localpart;
  +inline bool
  +operator==(
  +                     const QName&    theLHS,
  +                     const QName&    theRHS)
  +{
  +     return theLHS.equals(theRHS);
  +}
   
  -     static const XalanDOMString             s_emptyString;
  -};
  +
  +
  +inline bool
  +operator!=(
  +                     const QName&    theLHS,
  +                     const QName&    theRHS)
  +{
  +     return !(theLHS == theRHS);
  +}
   
   
   
  @@ -314,13 +251,17 @@
                        const QName&    theRHS)
   {
        if (theLHS.getNamespace() < theRHS.getNamespace())
  +     {
                return true;
  -     else if (equals( theLHS.getNamespace(), theRHS.getNamespace()))
  +     }
  +     else if (equals(theLHS.getNamespace(), theRHS.getNamespace()))
        {
                return theLHS.getLocalPart() < theRHS.getLocalPart();
        }
        else
  +     {
                return false;
  +     }
   }
   
   
  
  
  
  1.1                  xml-xalan/c/src/XPath/QNameByReference.cpp
  
  Index: QNameByReference.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  // Class header file...
  #include "QNameByReference.hpp"
  
  
  
  QNameByReference::QNameByReference() :
        QName(),
        m_namespace(s_emptyString),
        m_localpart(s_emptyString)
  {
  }
  
  
  
  QNameByReference::QNameByReference(
                        const XalanDOMString&   theNamespace,
                        const XalanDOMString&   theLocalPart) :
        QName(),
        m_namespace(theNamespace),
        m_localpart(theLocalPart)
  {
  }
  
  
  
  QNameByReference::~QNameByReference()
  {
  }
  
  
  
  const XalanDOMString&
  QNameByReference::getLocalPart() const
  {
        return m_localpart;
  }
  
  
  
  const XalanDOMString&
  QNameByReference::getNamespace() const
  {
        return m_namespace;
  }
  
  
  
  1.1                  xml-xalan/c/src/XPath/QNameByReference.hpp
  
  Index: QNameByReference.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  #if !defined(QNAMEBYREFERENCE_HEADER_GUARD_1357924680)
  #define QNAMEBYREFERENCE_HEADER_GUARD_1357924680
  
  
  
  // Base header file.  Must be first.
  #include <XPath/XPathDefinitions.hpp>
  
  
  
  // Base class header file...
  #include <XPath/QName.hpp>
  
  
  
  class XALAN_XPATH_EXPORT QNameByReference : public QName
  {
  public:
  
        /**
         * Construct an empty QNameByReference.
         */
        explicit
        QNameByReference();
  
        /**
         * Construct a QNameByReference, with the supplied namespace and local 
part.
         * The instance keeps only a _reference_ to the string, to avoid making 
a
         * copy.
         * @param theNamespace namespace string
         * @param theLocalPart local part string
         */
        QNameByReference(
                        const XalanDOMString&   theNamespace,
                        const XalanDOMString&   theLocalPart);
  
        virtual
        ~QNameByReference();
  
        /**
         * Retrieve the local part of qualified name.
         * 
         * @return local part string
         */
        virtual const XalanDOMString&
        getLocalPart() const;
  
        /**
         * Retrieve the namespace of qualified name.
         * 
         * @return namespace string
         */
        virtual const XalanDOMString&
        getNamespace() const;
  
  private:
  
        const XalanDOMString&   m_namespace;
  
        const XalanDOMString&   m_localpart;
  };
  
  
  
  #endif        // QNAMEBYREFERENCE_HEADER_GUARD_1357924680
  
  
  
  1.1                  xml-xalan/c/src/XPath/QNameByValue.cpp
  
  Index: QNameByValue.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  // Class header file...
  #include "QNameByValue.hpp"
  
  
  
  #include <PlatformSupport/XSLException.hpp>
  
  
  
  #include <DOMSupport/DOMServices.hpp>
  
  
  
  #include "ElementPrefixResolverProxy.hpp"
  #include "PrefixResolver.hpp"
  #include "XPathSupport.hpp"
  
  
  
  QNameByValue::QNameByValue() :
        QName(),
        m_namespace(),
        m_localpart()
  {
  }
  
  
  
  QNameByValue::QNameByValue(const QNameByValue&        theSource) :
        QName(),
        m_namespace(theSource.m_namespace),
        m_localpart(theSource.m_localpart)
  {
  }
  
  
  
  QNameByValue::QNameByValue(const QName&               theSource) :
        QName(),
        m_namespace(theSource.getNamespace()),
        m_localpart(theSource.getLocalPart())
  {
  }
  
  
  
  QNameByValue::QNameByValue(
                        const XalanDOMString&   theNamespace,
                        const XalanDOMString&   theLocalPart) :
        QName(),
        m_namespace(theNamespace),
        m_localpart(theLocalPart)
  {
  }
  
  
  
  QNameByValue::QNameByValue(
                        const XalanDOMString&           qname,
                        const NamespacesStackType&      namespaces) :
        m_namespace(),
        m_localpart()
  {
        initialize(c_wstr(qname), namespaces);
  }
  
  
  
  QNameByValue::QNameByValue(
                        const XalanDOMChar*                     qname,
                        const NamespacesStackType&      namespaces) :
        m_namespace(),
        m_localpart()
  {
        assert(qname != 0);
  
        initialize(qname, namespaces);
  }
  
  
  
  QNameByValue::QNameByValue(
                        const XalanDOMString&   qname,
                        const XalanElement*             namespaceContext,
                        const XPathEnvSupport&  envSupport,
                        const XPathSupport&     support) :
        m_namespace(),
        m_localpart()
  {
        ElementPrefixResolverProxy      theProxy(namespaceContext, envSupport, 
support);
  
        resolvePrefix(qname, theProxy);
  }
  
  
  
  QNameByValue::QNameByValue(
                        const XalanDOMString&   qname,
                        const PrefixResolver&   theResolver) :
        m_namespace(),
        m_localpart()
  {
        resolvePrefix(qname, theResolver);
  }
  
  
  
  QNameByValue::~QNameByValue()
  {
  }
  
  
  
  const XalanDOMString&
  QNameByValue::getLocalPart() const
  {
        return m_localpart;
  }
  
  
  
  const XalanDOMString&
  QNameByValue::getNamespace() const
  {
        return m_namespace;
  }
  
  
  
  void
  QNameByValue::initialize(
                        const XalanDOMChar*                     qname,
                        const NamespacesStackType&      namespaces)
  {
        const unsigned int      indexOfNSSep = indexOf(qname, 
XalanUnicode::charColon);
  
        if(indexOfNSSep < length(qname))
        {
                const XalanDOMString            prefix = substring(qname, 0, 
indexOfNSSep);
  
                if(::equals(prefix, DOMServices::s_XMLNamespace))
                        return;
  
                m_namespace = getNamespaceForPrefix(namespaces, prefix);
  
                if(0 == length(m_namespace))
                {
                        throw XSLException(TranscodeFromLocalCodePage("Prefix 
must resolve to a namespace: ") + prefix);
                }
  
                m_localpart =  substring(qname, indexOfNSSep + 1);
        }
        else
        {
                m_localpart = qname;
        }
  }
  
  
  
  void
  QNameByValue::resolvePrefix(
                        const XalanDOMString&   qname,
                        const PrefixResolver&   theResolver)
  {
        const unsigned int      indexOfNSSep = indexOf(qname, 
XalanUnicode::charColon);
        const unsigned int      theLength = length(qname);
  
        if(indexOfNSSep < theLength)
        {
                const XalanDOMString    prefix = substring(qname, 0, 
indexOfNSSep);
  
                if(::equals(prefix, DOMServices::s_XMLString))
                {
                        m_namespace = DOMServices::s_XMLNamespaceURI;
                }
                // The default namespace is not resolved.
                else if(::equals(prefix, DOMServices::s_XMLNamespace))
                {
                        return;
                }
                else
                {
                        m_namespace = theResolver.getNamespaceForPrefix(prefix);
                }  
  
                if(0 == length(m_namespace))
                {
                        throw XSLException(TranscodeFromLocalCodePage("Prefix 
must resolve to a namespace: ") + prefix);
                }
        }
        else
        {
                // $$$ ToDo: error or warning...
        }
  
        m_localpart = indexOfNSSep == theLength ? qname : substring(qname, 
indexOfNSSep + 1);
  }
  
  
  
  1.1                  xml-xalan/c/src/XPath/QNameByValue.hpp
  
  Index: QNameByValue.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.ibm.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  #if !defined(QNAMEBYVALUE_HEADER_GUARD_1357924680)
  #define QNAMEBYVALUE_HEADER_GUARD_1357924680
  
  
  
  // Base header file.  Must be first.
  #include <XPath/XPathDefinitions.hpp>
  
  
  
  // Base class header file...
  #include <XPath/QName.hpp>
  
  
  
  class XALAN_XPATH_EXPORT QNameByValue : public QName
  {
  public:
  
        /**
         * Construct an empty QNameByValue.
         */
        explicit
        QNameByValue();
  
        /**
         * Copy constructor.
         *
         * @param theSource The source of the copy.
         */
        QNameByValue(const QNameByValue&        theSource);
  
        /**
         * Construct an instance from another QName.
         *
         * @param theSource The source of the copy.
         */
        QNameByValue(const QName&       theSource);
  
        /**
         * Construct a QNameByValue, with the supplied namespace and local part.
         *
         * @param theNamespace namespace string
         * @param theLocalPart local part string
         */
        QNameByValue(
                        const XalanDOMString&   theNamespace,
                        const XalanDOMString&   theLocalPart);
  
        /**
         * Construct a QNameByValue from a string, resolving the prefix using 
the given
         * namespace vector stack. The default namespace is not resolved.
         *
         * @param qname      QName string
         * @param namespaces namespace vector stack to use
         */
        QNameByValue(
                        const XalanDOMString&           qname,
                        const NamespacesStackType&      namespaces);
  
        /**
         * Construct a QNameByValue from a string, resolving the prefix using 
the given
         * namespace vector stack. The default namespace is not resolved.
         *
         * @param qname      QName string
         * @param namespaces namespace vector stack to use
         */
        QNameByValue(
                        const XalanDOMChar*                     qname,
                        const NamespacesStackType&      namespaces);
  
        /**
         * Construct a QNameByValue from a string, resolving the prefix using 
the given
         * namespace context. The default namespace is not resolved.
         *
         * @param qname            QName string
         * @param namespaceContext context object for namespace resolution
         * @param envSupport       XPath environment support class instance
         * @param support          XPath support class instance
         */
        QNameByValue(
                        const XalanDOMString&   qname,
                        const XalanElement*             namespaceContext,
                        const XPathEnvSupport&  envSupport,
                        const XPathSupport&             support);
  
        /**
         * Construct a QNameByValue from a string, resolving the prefix using 
the given
         * prefix resolver. The default namespace is not resolved.
         *
         * @param qname            QName string
         * @param theResolver prefix resolver to use
         */
        QNameByValue(
                        const XalanDOMString&   qname,
                        const PrefixResolver&   theResolver);
  
        virtual
        ~QNameByValue();
  
        /**
         * Retrieve the local part of qualified name.
         * 
         * @return local part string
         */
        virtual const XalanDOMString&
        getLocalPart() const;
  
        /**
         * Retrieve the namespace of qualified name.
         * 
         * @return namespace string
         */
        virtual const XalanDOMString&
        getNamespace() const;
  
  private:
  
        void
        initialize(
                        const XalanDOMChar*                     qname,
                        const NamespacesStackType&      namespaces);
  
        void
        resolvePrefix(
                        const XalanDOMString&   qname,
                        const PrefixResolver&   theResolver);
  
        XalanDOMString  m_namespace;
  
        XalanDOMString  m_localpart;
  };
  
  
  
  #endif        // QNAMEBYVALUE_HEADER_GUARD_1357924680
  
  
  

Reply via email to