KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > axi > impl > SchemaUpdate


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.axi.impl;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.List JavaDoc;
27 import org.netbeans.modules.xml.axi.AXIComponent;
28 import org.netbeans.modules.xml.axi.impl.SchemaUpdate.UpdateUnit.Type;
29
30 /**
31  *
32  * @author Ayub Khan
33  */

34 public class SchemaUpdate {
35     
36     /** Creates a new instance of SchemaUpdate */
37     public SchemaUpdate() {
38     }
39     
40     public Collection JavaDoc<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 JavaDoc oldValue, Object JavaDoc newValue, String JavaDoc 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 JavaDoc<AXIComponent> items = uniqueMap.get(key);
63             if(items == null) {
64                 items = new ArrayList JavaDoc();
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 JavaDoc id;
79         
80         private Type type;
81         
82         private AXIComponent source;
83         
84         private Object JavaDoc oldValue;
85         
86         private Object JavaDoc newValue;
87         
88         private String JavaDoc propertyName;
89         
90         public UpdateUnit(String JavaDoc id, Type type,
91                 AXIComponent source, Object JavaDoc oldValue, Object JavaDoc newValue,
92                 String JavaDoc 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 JavaDoc 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 JavaDoc getOldValue() {
114             return oldValue;
115         }
116         
117         public Object JavaDoc getNewValue() {
118             return newValue;
119         }
120         
121         public String JavaDoc getPropertyName() {
122             return propertyName;
123         }
124     }
125     
126     private List JavaDoc<UpdateUnit> units = new ArrayList JavaDoc<UpdateUnit>();
127     
128     private HashMap JavaDoc<AXIComponent, List JavaDoc<AXIComponent>> uniqueMap =
129             new HashMap JavaDoc<AXIComponent, List JavaDoc<AXIComponent>>();
130     
131     private int count = 0;
132 }
133
Popular Tags