1 18 19 package org.objectweb.kilim.model; 20 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import org.objectweb.kilim.InternalException; 25 import org.objectweb.kilim.KilimException; 26 import org.objectweb.kilim.description.TemplateElementImpl; 27 28 34 35 public abstract class RtComponentElement implements ComponentElement, RuntimeElement { 36 protected static long nbComponent = 0; 37 protected static long nbElement = 0; 38 39 public static long getNbComponent() { 40 return nbComponent; 41 } 42 43 public static long getNbElement() { 44 return nbElement; 45 } 46 private ContainerElement container; 47 private TemplateElementImpl element; 48 49 54 protected RtComponentElement(TemplateElementImpl aElement, ContainerElement aContainer) { 55 element = aElement; 56 container = aContainer; 57 nbElement++; 58 } 59 60 63 public ContainerElement getContainingElement() { 64 return container; 65 } 66 67 70 public Component getContainingComponent() { 71 ContainerElement cont = getContainingElement(); 72 while (cont != null && !cont.isComponent()) { 73 cont = cont.getContainingElement(); 74 } 75 return (Component) cont; 76 } 77 78 81 public TemplateElementImpl getElementDescription() { 82 return element; 83 } 84 85 88 public Iterator getTemplateDefHierarchy() { 89 return element.getTemplateDefHierarchy(); 90 } 91 92 95 public String getQualifiedName() { 96 if (container == null) { 97 return getLocalName(); 98 } 99 100 String contName = container.getQualifiedName(); 101 102 if ("".equals(contName)) { 103 return getLocalName(); 104 } 105 106 return contName + "/" + getLocalName(); 107 } 108 109 112 public RuntimeElement getTarget() throws KilimException { 113 return this; 114 } 115 116 protected boolean containsElement(List aList, String aName) throws InternalException { 118 int lSize = aList.size(); 119 if (lSize == 0) { 120 return false; 121 } 122 123 for (int i = 0; i < lSize; i++) { 124 ComponentElement el = (ComponentElement) aList.get(i); 125 if (aName.equals(el.getLocalName())) { 126 return true; 127 } 128 } 129 return false; 130 } 131 132 protected Object removeElement(List aList, String aName) throws InternalException { 133 int lSize = aList.size(); 134 if (lSize == 0) { 135 return null; 136 } 137 138 for (int i = 0; i < lSize; i++) { 139 ComponentElement el = (ComponentElement) aList.get(i); 140 if (aName.equals(el.getLocalName())) { 141 return aList.remove(i); 142 } 143 } 144 return null; 145 } 146 147 protected Object getElement(List aList, String aName) throws InternalException { 148 int lSize = aList.size(); 149 if (lSize == 0) { 150 return null; 151 } 152 153 for (int i = 0; i < lSize; i++) { 154 ComponentElement el = (ComponentElement) aList.get(i); 155 if (aName.equals(el.getLocalName())) { 156 return el; 157 } 158 } 159 return null; 160 } 161 } | Popular Tags |