1 18 19 package org.objectweb.kilim.description; 20 21 import java.util.Iterator ; 22 import java.util.ArrayList ; 23 24 import org.objectweb.kilim.KilimException; 25 26 30 public class ArraySource extends InlinedElement { 31 private ArrayList arrayElements; 32 private String typeName; 33 34 43 public ArraySource(String aTypeName, TemplateDescription aTemplate) throws KilimException { 44 super(true, false, aTemplate); 45 checkTypeName(aTypeName); 46 typeName = aTypeName; 47 } 48 49 53 private void checkTypeName(String aTypeName) throws KilimException { 54 String name = aTypeName; 55 56 while (name.endsWith("[]")) { 57 name = name.substring(0, name.length() - 2); 58 } 59 if (name.indexOf("[") != -1 || name.indexOf("]") != -1) { 60 throw new KilimException("syntax error in type declaration " + aTypeName + " of an array in template " + getContainingTemplate().getName()); 61 } 62 } 63 64 67 public int getKind() { 68 return KILIM.ARRAY; 69 } 70 71 75 public int getCurrentSize() { 76 if (arrayElements == null) { 77 return 0; 78 } 79 return arrayElements.size(); 80 } 81 82 88 public void addElement(BasicElement value) throws KilimException { 89 if (value == null) { 90 throw new KilimException("attempt to add a null value in an array in template " + getContainingTemplate().getName()); 91 } 92 93 if (!value.providesValue()) { 94 throw new KilimException("attempt to add a non provider to an array in template " + getContainingTemplate().getName()); 95 } 96 if (arrayElements == null) { 97 arrayElements = new ArrayList (); 98 } 99 arrayElements.add(value); 100 } 101 102 108 public BasicElement getElement(int aIndex) throws KilimException { 109 if (aIndex < 0) { 110 throw new KilimException("attempt to use an illegal index : " + aIndex + " in getting Element of an array in template " + getContainingTemplate().getName()); 111 } 112 return (BasicElement) arrayElements.get(aIndex); 113 } 114 115 119 public Iterator getElements() { 120 if (arrayElements == null) { 121 return KILIM.EMPTY_ITERATOR; 122 } 123 return arrayElements.listIterator(); 124 } 125 126 129 public String getTypeName() { 130 return typeName; 131 } 132 } | Popular Tags |