1 18 package org.objectweb.kilim.description; 19 20 import org.objectweb.kilim.KilimException; 21 22 25 public class Instance extends TemplateElementImpl implements NamedElement { 26 private String localName; 27 private int status; 28 private TemplateDescription template; 29 30 38 public Instance(String aName, int aStatus, TemplateDescription aTemplate, TemplateDescription aContain) throws KilimException { 39 if (aName == null) { 40 throw new KilimException("illegal null name for a named template element in template " + getContainingTemplate().getName()); 41 } 42 checkStatus(aStatus); 43 localName = aName; 44 status = aStatus; 45 template = aTemplate; 46 setContainingTemplate(aContain); 47 } 48 49 52 public void setLocalName(String aName) throws KilimException { 53 String oName = getLocalName(); 54 if (aName == null) { 55 throw new KilimException("null name in setting local name of a component " + oName + " in template " + getContainingTemplate().getName()); 56 } 57 localName = aName; 58 TemplateDescription template = getContainingTemplate(); 59 if (template != null) { 60 template.removeLocalInstance(oName); 61 template.addLocalInstance(this); 62 } 63 } 64 65 68 public String getLocalName() { 69 return localName; 70 } 71 72 75 public int getStatus() { 76 return status; 77 } 78 79 82 public void setStatus(int aStatus) throws KilimException { 83 checkStatus(aStatus); 84 status = aStatus; 85 TemplateDescription template = getContainingTemplate(); 86 if (template != null) { 87 template.removeLocalInstance(getLocalName()); 88 template.addLocalInstance(this); 89 } 90 } 91 92 96 public TemplateDescription getTemplate() { 97 return template; 98 } 99 100 104 public void setTemplate(TemplateDescription aTemplate) { 105 template = aTemplate; 106 } 107 108 111 public String toString() { 112 return "[" + getLocalName() + "]"; 113 } 114 115 private void checkStatus(int aStatus) throws KilimException { 116 if (aStatus < 1 || aStatus > 3) { 117 throw new KilimException("illegal value " + aStatus + " for element " + localName); 118 } 119 } 120 } | Popular Tags |