1 19 20 package org.netbeans.modules.xml.axi.impl; 21 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.Collections ; 25 import java.util.HashMap ; 26 import java.util.List ; 27 import org.netbeans.modules.xml.axi.AXIComponent; 28 import org.netbeans.modules.xml.axi.impl.SchemaUpdate.UpdateUnit.Type; 29 30 34 public class SchemaUpdate { 35 36 37 public SchemaUpdate() { 38 } 39 40 public Collection <UpdateUnit> getUpdateUnits() { 41 return Collections.unmodifiableList(units); 42 } 43 44 public void addUpdateUnit(UpdateUnit uu) { 45 units.add(uu); 46 } 47 48 public UpdateUnit createUpdateUnit(Type type, 49 AXIComponent source, Object oldValue, Object newValue, String propertyName) { 50 AXIComponent key = null; 51 if(type == UpdateUnit.Type.CHILD_MODIFIED) 52 key = source; 53 else if(type == UpdateUnit.Type.CHILD_ADDED) 54 key = (AXIComponent) newValue; 55 else if(type == UpdateUnit.Type.CHILD_DELETED) 56 key = (AXIComponent) oldValue; 57 58 if(key instanceof AXIComponentProxy) { 59 key = key.getOriginal(); 60 } 61 if(key != null) { 62 List <AXIComponent> items = uniqueMap.get(key); 63 if(items == null) { 64 items = new ArrayList (); 65 uniqueMap.put(key, items); 66 } 67 items.add(key); 68 return new UpdateUnit(String.valueOf(count++), type, source, oldValue, newValue, 69 propertyName); 70 } 71 return null; 72 } 73 74 public static class UpdateUnit { 75 76 public static enum Type {CHILD_ADDED, CHILD_DELETED, CHILD_MODIFIED}; 77 78 private String id; 79 80 private Type type; 81 82 private AXIComponent source; 83 84 private Object oldValue; 85 86 private Object newValue; 87 88 private String propertyName; 89 90 public UpdateUnit(String id, Type type, 91 AXIComponent source, Object oldValue, Object newValue, 92 String propertyName) { 93 this.id = id; 94 this.type = type; 95 this.source = source; 96 this.oldValue = oldValue; 97 this.newValue = newValue; 98 this.propertyName = propertyName; 99 } 100 101 public String getId() { 102 return id; 103 } 104 105 public AXIComponent getSource() { 106 return source; 107 } 108 109 public Type getType() { 110 return type; 111 } 112 113 public Object getOldValue() { 114 return oldValue; 115 } 116 117 public Object getNewValue() { 118 return newValue; 119 } 120 121 public String getPropertyName() { 122 return propertyName; 123 } 124 } 125 126 private List <UpdateUnit> units = new ArrayList <UpdateUnit>(); 127 128 private HashMap <AXIComponent, List <AXIComponent>> uniqueMap = 129 new HashMap <AXIComponent, List <AXIComponent>>(); 130 131 private int count = 0; 132 } 133 | Popular Tags |