1 12 package org.eclipse.ant.internal.ui.dtd.schema; 13 14 import java.util.HashMap ; 15 import java.util.Map ; 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 fMap = new HashMap (4); 28 private Dfm fElementDfm; 29 30 34 public Element(String name) { 35 super(ELEMENT, name); 36 } 37 38 42 public void setUndefined(boolean undefined) { 43 fUndefined = undefined; 44 } 45 46 50 public void setText(boolean text) { 51 fText = text; 52 } 53 54 58 public void setContentModel(IModel model) { 59 fModel = model; 60 } 61 62 66 public void addAttribute(IAttribute attribute) { 67 fMap.put(attribute.getName(), attribute); 68 } 69 70 73 public Map getAttributes() { 74 return fMap; 75 } 76 77 78 81 public IModel getContentModel() { 82 return fModel; 83 } 84 85 88 public boolean isText() { 89 return fText; 90 } 91 92 95 public boolean isUndefined() { 96 return fUndefined; 97 } 98 99 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 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 151 public boolean isAny() { 152 return fAny; 153 } 154 155 158 public boolean isEmpty() { 159 return fEmpty; 160 } 161 162 166 public void setAny(boolean any) { 167 fAny = any; 168 } 169 170 174 public void setEmpty(boolean empty) { 175 fEmpty = empty; 176 } 177 178 } 179 180 | Popular Tags |