[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: SAX2 Namespace Support

  • From: Toby Speight <Toby.Speight@s...>
  • To: "XML developers' list" <xml-dev@i...>
  • Date: 13 Jan 2000 10:56:50 +0000

Re: SAX2 Namespace Support
David> David Megginson <URL:mailto:david@m...>

0> In article <m3r9fwtuv8.fsf@l...>, David wrote:

David> In principle (the principle of least surprise), it's very bad
David> behaviour for two objects to be == in C++ or equals() in Java
David> if any of their publicly-accessible fields differ.  Think of
David> sets, for example.

You could follow the example of java.lang.String and define equals() to
compare all public data (as usual), and define an additional method
equalsIgnorePrefix() which doesn't.  The problem with this is that
hashCode() has to be consistent with equals(), but sometimes you want
to use a hashCode() based on equalsIgnorePrefix().  I've solved this in
the past (for a case-insensitive String class) by making a wrapper that
defines equals() in terms of equalsIgnoreCase(), and a corresponding
hashCode().  I'm not sure I like this for SAX2 though, as we should be
making the common case - ignoring the prefix - the simplest.

public class QName {
  public String getPrefix();
  public String getUri();
  public String getLocal();

  public int hashCode(); // based on prefix, URI, local
  public boolean hashCodeIgnorePrefix(Object o); // based on URI, local

  public boolean equals(Object o); // based on prefix, URI, local
  public boolean equalsIgnorePrefix(Object o); // based on URI, local
}


public class QNameIgnorePrefix {
  private QName name;
  public QNameIgnorePrefix(QName name) { this.name = name; }

  public String getUri() { return name.getUri(); }
  public String getLocal() { return name.getLocal(); }

  public int hashCode() { return name.hashCodeIgnorePrefix(); }
  public boolean equals(Object o); { return name.equalsIgnorePrefix(o); }
}

-- 


xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@i...
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ or CD-ROM/ISBN 981-02-3594-1
Please note: New list subscriptions now closed in preparation for transfer to OASIS.



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.