KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > xml > XMLCollectionElement


1 /* XMLCollectionElement.java
2  *
3  * Authors:
4  * Stefanovic Nenad chupo@iis.ns.ac.yu
5  * Bojanic Sasa sasaboy@neobee.net
6  * Puskas Vladimir vpuskas@eunet.yu
7  * Pilipovic Goran zboniek@uns.ac.yu
8  *
9  */

10
11
12 package org.enhydra.jawe.xml;
13
14 import org.enhydra.jawe.xml.panels.XMLPanel;
15
16 import java.util.*;
17 import org.w3c.dom.*;
18
19 /**
20 * Represents an XML element that belongs to some collection.
21 * Such element always has the 'Id' attribute.
22 */

23 public class XMLCollectionElement extends XMLComplexElement {
24
25    public static final String JavaDoc ID_DELIMITER="_";
26
27    protected XMLAttribute attrId=new XMLAttribute("Id"); //required
28
protected transient XMLCollection myCollection;
29
30    // element by itself doesn't fill the structure - it is up
31
// to extended classes to do it
32
public XMLCollectionElement (XMLCollection myCollection) {
33       super();
34
35       this.myCollection=myCollection;
36       try {
37          attrId.setValue(myCollection.generateID());
38       } catch (Exception JavaDoc ex) {} // this happens when collection is null
39
}
40
41    public String JavaDoc getID() {
42       return attrId.value.toString();
43    }
44
45    public XMLCollection getCollection () {
46       return myCollection;
47    }
48
49    protected void fillStructure () {
50       attrId.setRequired(true);
51
52       complexStructure.add(attrId);
53       attributes.add(attrId);
54    }
55
56    public void fromXML(Node node) {
57       super.fromXML(node);
58       myCollection.updateID(getID());
59    }
60
61    public boolean isIDUniqueAndValid (XMLPanel p) {
62       return true;
63    }
64
65    // I think that clone is not needed here because of constructor
66
// add cloned attributes to attributes list
67
public Object JavaDoc clone () {
68       XMLCollectionElement d=(XMLCollectionElement)super.clone();
69       d.attrId=(XMLAttribute)this.attrId.clone();
70       d.myCollection=this.myCollection;
71       return d;
72    }
73
74 }
75
76 /* End of XMLCollectionElement.java */
77
Popular Tags