Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 91   Methods: 8
NCLOC: 67   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
AttributeImpls.java 100% 100% 100% 100%
 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.instance.impl;
 11   
 
 12   
 import java.util.HashMap;
 13   
 import java.util.Iterator;
 14   
 
 15   
 import org.jbind.xml.base.ILocation;
 16   
 import org.jbind.xml.base.IRef;
 17   
 import org.jbind.xml.base.ISymbolspaces;
 18   
 import org.jbind.xml.base.QName;
 19   
 import org.jbind.xml.base.Ref;
 20   
 import org.jbind.xml.core.base.ITextContentProvider;
 21   
 import org.jbind.xml.core.bridge.IAttributeImpl;
 22   
 import org.jbind.xml.core.bridge.IDefaultAttrCreator;
 23   
 import org.jbind.xml.core.bridge.IElementImpl;
 24   
 
 25   
 public class AttributeImpls {
 26   
 
 27  20113
   private static String key(String aNamespace, String aName) {
 28  20113
     return aNamespace + "::" + aName;
 29   
   }
 30   
 
 31   
   private HashMap myAttributeImpls = new HashMap();
 32   
   private IDefaultAttrCreator myDefaultAttrCreator = null;
 33   
 
 34   
   private IElementImpl myOwnerElement;
 35   
 
 36  2753
   public AttributeImpls(IElementImpl anElementImpl) {
 37  2753
     myOwnerElement = anElementImpl;
 38   
   }
 39   
 
 40  6
   public IAttributeImpl addAttribute(String aNamespace, String aQName, ITextContentProvider aProvider, boolean anIsDefault, ILocation aLocation) {
 41  6
     String name = QName.getLocalPart(aQName);
 42  6
     String k = key(aNamespace, name);
 43  6
     AttributeImpl a = new AttributeImpl(myOwnerElement, aNamespace, name, aProvider, anIsDefault, aLocation);
 44  6
     myAttributeImpls.put(k, a);
 45  6
     return a;
 46   
   }
 47   
 
 48  2196
   public IAttributeImpl addAttribute(String aNamespace, String aQName, String aValue, boolean anIsDefault, ILocation aLocation) {
 49  2196
     String name = QName.getLocalPart(aQName);
 50  2196
     String k = key(aNamespace, name);
 51  2196
     AttributeImpl a = new AttributeImpl(myOwnerElement, aNamespace, name, aValue, anIsDefault, aLocation);
 52  2196
     myAttributeImpls.put(k, a);
 53  2196
     return a;
 54   
   }
 55   
 
 56  17727
   public IAttributeImpl getAttributeImpl(String aNamespace, String aName) {
 57  17727
     String k = key(aNamespace, aName);
 58  17727
     IAttributeImpl res = (IAttributeImpl)myAttributeImpls.get(k);
 59  17727
     if ((res == null) && (myDefaultAttrCreator != null)) {
 60  7875
       Ref ref = new Ref(aNamespace, ISymbolspaces.ATTRIBUTE, aName);
 61  7875
       res = myDefaultAttrCreator.createDefaultAttr(myOwnerElement, ref);
 62   
     }
 63  17727
     return res;
 64   
   }
 65   
 
 66  10
   public void removeAttribute(String aNamespace, String aName) {
 67  10
     String k = key(aNamespace, aName);
 68  10
     myAttributeImpls.remove(k);
 69   
   }
 70   
 
 71  2858
   public Iterator iterImpls() {
 72  2858
     if (null != myDefaultAttrCreator) {
 73  372
       for (Iterator i = myDefaultAttrCreator.iterDefaultAttrRefs();
 74  546
               i.hasNext(); ) {
 75  174
         IRef ref = (IRef)i.next();
 76  174
         String k = key(ref.getNamespace(), ref.getLocalPart());
 77  174
         if (myAttributeImpls.get(k) == null) {
 78  152
           IAttributeImpl a = myDefaultAttrCreator.createDefaultAttr(myOwnerElement, ref);
 79  152
           myAttributeImpls.put(k, a);
 80   
         }
 81   
       }
 82   
     }
 83  2858
     return myAttributeImpls.values().iterator();
 84   
   }
 85   
 
 86  1987
   public void setDefaultAttrCreator(IDefaultAttrCreator aCreator) {
 87  1987
     myDefaultAttrCreator = aCreator;
 88   
   }
 89   
 
 90   
 }
 91