1 18 19 package org.objectweb.kilim.model; 20 21 import java.util.Iterator ; 22 import java.util.Stack ; 23 24 import org.objectweb.kilim.KilimException; 25 import org.objectweb.kilim.description.KILIM; 26 import org.objectweb.kilim.description.NamedElement; 27 import org.objectweb.kilim.description.Property; 28 import org.objectweb.kilim.description.TemplateDescription; 29 import org.objectweb.kilim.description.TemplateElementImpl; 30 31 34 35 public class RtComponentProperty extends RtComponentInterface implements ComponentProperty { 36 private static Object UNSET = new Object (); 37 private boolean used; 38 private Object value; 39 40 41 46 public RtComponentProperty(TemplateElementImpl aElement, Component aComponent) { 47 super(aElement, aComponent); 48 value = ((Property) getElementDescription()).getValue(); 49 } 50 51 54 public String getLocalName() { 55 NamedElement elem = (NamedElement) getElementDescription(); 56 return elem.getLocalName(); 57 } 58 59 64 public void setValue(Object aValue) throws KilimException { 65 bindValue(aValue); 66 } 67 68 71 public boolean isEventSource() { 72 return false; 73 } 74 75 78 public Object getEventSourceValue() throws KilimException { 79 return null; 80 } 81 82 85 public void setEventSourceValue(Object aSource) throws KilimException { } 86 87 90 public void bindProvider(RuntimeSource aSource, boolean jReplace) throws KilimException { 91 TemplateDescription tmp0 = getContainingComponent().getTemplate(); 92 String lName = getLocalName(); 93 String tmpList = tmp0.getName(); 94 while ((tmp0 = tmp0.getSuperTemplate()) != null) { 95 Iterator iter = tmp0.getBindings(lName, true); 96 if (iter != KILIM.EMPTY_ITERATOR) { 97 tmpList = tmpList + ", " + tmp0.getName(); 98 } 99 } 100 throw new KilimException("attempt to bind a property " + getQualifiedName() + " (binding definition in templates : " + tmpList + ")"); 101 } 102 103 106 public void unbindProvider(RuntimeSource aSource) throws KilimException { 107 throw new KilimException("attempt to unbind a provider " + aSource + " from a property " + getQualifiedName()); 108 } 109 110 113 protected Object specificGetValue() throws KilimException { 114 Object resultValue = null; 115 if (mappingContext != null) { 116 mappingContext.getCallStack().push(this); 117 } 118 if (value == UNSET) { 119 throw new KilimException("attempt to get the value of an unset property " + getQualifiedName()); 120 } 121 122 mapper.enterContext(mappingContext); 123 resultValue = mapper.getPropertyValue(value, mappingContext); 124 if (mappingContext != null) { 125 mappingContext.getCallStack().pop(); 126 } 127 mapper.leaveContext(mappingContext); 128 used = true; 129 return resultValue; 130 } 131 132 135 protected void specificUnbindValue() throws KilimException { 136 value = UNSET; 137 } 138 139 142 protected void specificBindValue(Object aValue) throws KilimException { 143 value = aValue; 144 } 145 146 149 public boolean isSingleValuePort() { 150 return false; 151 } 152 153 156 public boolean isCollectionPort() { 157 return false; 158 } 159 160 163 public boolean isProvider() { 164 return false; 165 } 166 167 170 public boolean isProperty() { 171 return true; 172 } 173 174 177 public boolean hasValue() { 178 return value != UNSET; 179 } 180 181 184 public boolean checkValue(Stack exclude) throws KilimException { 185 return true; 186 } 187 } 188 | Popular Tags |