Patch from Stefan Sigurdsson
[phpeclipse.git] / net.sourceforge.phpeclipse.xml.core / src / net / sourceforge / phpeclipse / xml / core / internal / model / XMLElement.java
1 /*
2  * Copyright (c) 2004 Christopher Lenz and others
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     Christopher Lenz - initial API
10  * 
11  * $Id: XMLElement.java,v 1.1 2004-09-02 18:26:55 jsurfer Exp $
12  */
13
14 package net.sourceforge.phpeclipse.xml.core.internal.model;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import net.sourceforge.phpeclipse.core.model.SourceReference;
20 import net.sourceforge.phpeclipse.xml.core.model.IXMLElement;
21
22 import org.eclipse.jface.text.IDocument;
23
24 /**
25  * 
26  */
27 public class XMLElement extends SourceReference implements IXMLElement {
28
29         // Instance Variables ------------------------------------------------------
30
31         private List children;
32
33         private String localName;
34         private String namespaceURI;
35         private String prefix;
36
37         private IXMLElement parent;
38
39         // Constructors ------------------------------------------------------------
40
41         public XMLElement(IDocument document) {
42                 super(document);
43         }
44
45         public XMLElement(IDocument document, int offset) {
46                 super(document, offset);
47         }
48
49         public XMLElement(IDocument document, int offset, int length) {
50                 super(document, offset, length);
51         }
52
53         // IXMLElement Implementation -------------------------------------------------
54
55         /* 
56          * @see IXMLElement#getChildren()
57          */
58         public IXMLElement[] getChildren() {
59                 if (children != null) {
60                         return (IXMLElement[]) children.toArray(
61                                         new IXMLElement[children.size()]);
62                 }
63                 return new IXMLElement[0];
64         }
65
66         /* 
67          * @see IXMLElement#getLocalName()
68          */
69         public String getLocalName() {
70                 return localName;
71         }
72
73         /* 
74          * @see IXMLElement#getNamespaceURI()
75          */
76         public String getNamespaceURI() {
77                 return namespaceURI;
78         }
79
80         /* 
81          * @see IXMLElement#getPrefix()
82          */
83         public String getPrefix() {
84                 return prefix;
85         }
86
87         /* 
88          * @see IXMLElement#getParent()
89          */
90         public IXMLElement getParent() {
91                 return parent;
92         }
93
94         // Public Methods ----------------------------------------------------------
95
96         public void addChild(IXMLElement child) {
97                 if (children == null) {
98                         children = new ArrayList();
99                 }
100                 children.add(child);
101         }
102
103         public void setLocalName(String localName) {
104                 this.localName = localName;
105         }
106
107         public void setNamespaceURI(String namespaceURI) {
108                 this.namespaceURI = namespaceURI;
109         }
110
111         public void setPrefix(String prefix) {
112                 this.prefix = prefix;
113         }
114
115         public void setParent(IXMLElement parent) {
116                 this.parent = parent;
117         }
118
119 }