Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 105   Methods: 9
NCLOC: 63   Classes: 1
This license of Clover is provided to support the development of JBind only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
QName.java 60% 93,8% 100% 88,2%
 1   
 /*
 2   
  * JBind
 3   
  *
 4   
  * Copyright (c) by Stefan Wachter. All rights reserved.
 5   
  *
 6   
  * Usage, modification, and redistribution is subject to license terms that are
 7   
  * available at 'http://www.jbind.org'. The JBind license is like the
 8   
  * 'Apache Software License V 1.1'.
 9   
  */
 10   
 package org.jbind.xml.base;
 11   
 
 12   
 import java.util.Map;
 13   
 
 14   
 /**
 15   
  * Represents a qualified name.
 16   
  */
 17   
 public class QName implements IQName {
 18   
 
 19   
   /**
 20   
    * Gets the local part of a QName.
 21   
    *
 22   
    * @param aQName <i>(required)</i>.
 23   
    * @return <i>(required)</i>.
 24   
    */
 25  4955
   public static final String getLocalPart(String aQName) {
 26  4955
     int idx = aQName.lastIndexOf(':');
 27  4955
     return (idx > 0) ? aQName.substring(idx + 1) : aQName;
 28   
   }
 29   
 
 30   
   /**
 31   
    * Creates a QName.
 32   
    *
 33   
    * @param aQName <i>(optional)</i>.
 34   
    * @param aPrefixToNamespaceMapping <i>(required)</i>.
 35   
    * @return <i>(optional)</i>. If the provided QName does not satisfied the
 36   
    * syntactic constraints of QNames or the namespace could not be determined
 37   
    * then <code>null</code> is returned.
 38   
    */
 39  2037
   public static final QName create(String aQName, Map aPrefixToNamespaceMapping) {
 40  2037
     QName res = null;
 41  2037
     if (StringUtil.isValidQName(aQName)) {
 42  2037
       int idx = aQName.indexOf(':');
 43  2037
       String prefix = null;
 44  2037
       String localName;
 45  2037
       if (idx >= 0) {
 46  1345
         prefix = aQName.substring(0, idx);
 47  1345
         localName = aQName.substring(idx + 1);
 48   
       } else {
 49  692
         prefix = "";
 50  692
         localName = aQName;
 51   
       }
 52  2037
       String namespace = (String)aPrefixToNamespaceMapping.get(prefix);
 53  2037
       if (namespace == null) {
 54  0
         return null;
 55   
       }
 56  2037
       res = new QName(prefix, localName, namespace);
 57   
     }
 58  2037
     return res;
 59   
   }
 60   
 
 61   
   private String myPrefix = null;
 62   
 
 63   
   private String myLocalPart = null;
 64   
 
 65   
   protected String myNamespace = null;
 66   
 
 67  57950
   public String getPrefix() {
 68  57950
     return myPrefix;
 69   
   }
 70   
 
 71  41350
   public String getLocalPart() {
 72  41350
     return myLocalPart;
 73   
   }
 74   
 
 75  55810
   public String getNamespace() {
 76  55810
     return myNamespace;
 77   
   }
 78   
 
 79  25551
   protected QName(String aPrefix, String aLocalName, String aNamespace) {
 80  25551
     myPrefix = aPrefix;
 81  25551
     myLocalPart = aLocalName;
 82  25551
     myNamespace = aNamespace;
 83   
   }
 84   
 
 85  4793
   public String toString() {
 86  4793
     if (null == myPrefix) {
 87  0
       return "?:" + myLocalPart;
 88   
     }
 89  4793
     return ("".equals(myPrefix) ? "" : myPrefix + ":") + myLocalPart;
 90   
   }
 91   
 
 92  1
   public final boolean equals(Object anObject) {
 93  1
     boolean res = anObject instanceof IQName;
 94  1
     if (res) {
 95  1
       IQName qn = (IQName)anObject;
 96  1
       res = myNamespace.equals(qn.getNamespace()) && myLocalPart.equals(qn.getLocalPart());
 97   
     }
 98  1
     return res;
 99   
   }
 100   
 
 101  9349
   public final int hashCode() {
 102  9349
     return myNamespace.hashCode() + myLocalPart.hashCode();
 103   
   }
 104   
 }
 105