1 19 20 package org.netbeans.modules.dbschema.jdbcimpl; 21 22 import java.util.*; 23 24 import org.netbeans.modules.dbschema.*; 25 26 29 public class DBElementsCollection implements DBElementProperties { 30 31 32 DBElementImpl owner; 33 34 DBElement[] _elms; 35 36 37 private Object [] _template; 38 39 protected static transient HashSet instances = new HashSet(); 42 43 public DBElementsCollection () { 44 this(null, null); 45 } 46 47 50 public DBElementsCollection (DBElementImpl owner, Object [] template) { 51 this.owner = owner; 52 _template = template; 53 } 54 55 public DBElement[] getElements () { 56 if (_elms != null) 57 return _elms; 58 else 59 return (DBElement[]) Arrays.asList(_template).toArray(new DBElement[_template.length]); 60 61 } 62 63 public void changeElements(DBElement[] elements, int action) { 64 changeElements(Arrays.asList(elements), action); 65 } 66 67 public void changeElements(List elems, int action) { 68 boolean changed = false; 69 DBElement[] oldElements = getElements(); 70 int oldLength = (oldElements == null) ? 0 : oldElements.length; 71 int newLength = (elems == null) ? 0 : elems.size(); 72 List list = null; 73 74 switch (action) { 75 case DBElement.Impl.ADD: 76 if (newLength > 0) { 77 list = ((oldLength == 0) ? new ArrayList() : new ArrayList(Arrays.asList(oldElements))); 78 list.addAll(elems); 79 changed = true; 80 } 81 break; 82 case DBElement.Impl.REMOVE: 83 break; 84 case DBElement.Impl.SET: 85 list = elems; 86 changed = true; 87 break; 88 } 89 if (changed) 90 _elms = (DBElement[]) list.toArray(_template); 92 } 93 94 99 public DBElement find(DBIdentifier id) { 100 DBElement[] me = (DBElement[]) getElements(); 101 102 if (me == null) 103 return null; 104 105 for (int i = 0; i < me.length; i++) 106 if (id.compareTo(me[i].getName(), false)) 107 return me[i]; 108 109 return null; 110 } 111 112 114 118 public DBElementImpl getOwner () { 119 return owner; 120 } 121 122 127 public void setOwner (DBElementImpl owner) { 128 this.owner = owner; 129 } 130 131 136 public void setElements (DBElement[] elements) 137 { 138 _elms = elements; 139 } 140 141 145 public Object [] getTemplate () { return _template; } 146 147 153 public void setTemplate (Object [] template) { _template = template; } 154 } 155 | Popular Tags |