KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > dtd > schema > Element


1 /*******************************************************************************
2  * Copyright (c) 2002, 2005 Object Factory Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Object Factory Inc. - Initial implementation
10  * IBM Corporation - fix for Bug 40951
11  *******************************************************************************/

12 package org.eclipse.ant.internal.ui.dtd.schema;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.ant.internal.ui.dtd.IAttribute;
18 import org.eclipse.ant.internal.ui.dtd.IDfm;
19 import org.eclipse.ant.internal.ui.dtd.IElement;
20 import org.eclipse.ant.internal.ui.dtd.IModel;
21 import org.eclipse.ant.internal.ui.dtd.ParseError;
22
23 public class Element extends Atom implements IElement {
24     private boolean fUndefined = true;
25     private boolean fText;
26     private IModel fModel;
27     private Map JavaDoc fMap = new HashMap JavaDoc(4);
28     private Dfm fElementDfm;
29
30     /**
31      * Constructor
32      * @param name QName of element.
33      */

34     public Element(String JavaDoc name) {
35         super(ELEMENT, name);
36     }
37
38     /**
39      * Set undefined property.
40      * @param undefined False if defined; otherwise true (default).
41      */

42     public void setUndefined(boolean undefined) {
43         fUndefined = undefined;
44     }
45     
46     /**
47      * Set text property.
48      * @param text True if text only; otherwise false (default).
49      */

50     public void setText(boolean text) {
51         fText = text;
52     }
53     
54     /**
55      * Set model property.
56      * @param model Dfm describing content model.
57      */

58     public void setContentModel(IModel model) {
59         fModel = model;
60     }
61     
62     /**
63      * Add an attribute to the attribute map.
64      * @param attribute Attribute to add.
65      */

66     public void addAttribute(IAttribute attribute) {
67         fMap.put(attribute.getName(), attribute);
68     }
69     
70     /**
71      * @see org.eclipse.ant.internal.ui.dtd.IElement#getAttributes()
72      */

73     public Map JavaDoc getAttributes() {
74         return fMap;
75     }
76
77     
78     /* (non-Javadoc)
79      * @see org.eclipse.ant.internal.ui.dtd.IElement#isMixed()
80      */

81     public IModel getContentModel() {
82         return fModel;
83     }
84
85     /**
86      * @see org.eclipse.ant.internal.ui.dtd.IElement#isText()
87      */

88     public boolean isText() {
89         return fText;
90     }
91
92     /**
93      * @see org.eclipse.ant.internal.ui.dtd.IElement#isUndefined()
94      */

95     public boolean isUndefined() {
96         return fUndefined;
97     }
98
99     /**
100      * @see org.eclipse.ant.internal.ui.dtd.IElement#getDfm()
101      */

102     public IDfm getDfm() {
103         Dfm dfm = fElementDfm;
104         if (dfm == null) {
105             dfm = parseElementDfm();
106             fElementDfm = dfm;
107         }
108         return dfm;
109     }
110     
111     private Dfm parseElementDfm() {
112         Dfm dfm;
113         if (fAny) {
114             dfm = Dfm.dfm(true);
115             dfm.any = true;
116         }
117         else if (fEmpty || fText) {
118             dfm = Dfm.dfm(true);
119             dfm.empty = true;
120         }
121         else {
122             dfm = parseModel(fModel);
123         }
124         return dfm;
125     }
126     
127     private Dfm parseModel(IModel model) {
128         Dfm dfm;
129         Nfm nfm = model.toNfm();
130         if (nfm != null) {
131             try {
132                 dfm = fNfmParser.parse(nfm);
133             } catch (ParseError e) {
134                 //??? this would be the place to log the error
135
dfm = Dfm.dfm(false);
136             }
137         }
138         else {
139             dfm = Dfm.dfm(false);
140         }
141         return dfm;
142     }
143     
144     private static final NfmParser fNfmParser = new NfmParser();
145     private boolean fAny;
146     private boolean fEmpty;
147
148     /**
149      * @see org.eclipse.ant.internal.ui.dtd.IElement#isAny()
150      */

151     public boolean isAny() {
152         return fAny;
153     }
154
155     /**
156      * @see org.eclipse.ant.internal.ui.dtd.IElement#isEmpty()
157      */

158     public boolean isEmpty() {
159         return fEmpty;
160     }
161
162     /**
163      * Sets the any.
164      * @param any The any to set
165      */

166     public void setAny(boolean any) {
167         fAny = any;
168     }
169
170     /**
171      * Sets the empty.
172      * @param empty The empty to set
173      */

174     public void setEmpty(boolean empty) {
175         fEmpty = empty;
176     }
177
178 }
179
180
Popular Tags