1 19 package org.netbeans.modules.xml.axi; 20 21 import java.io.IOException ; 22 import org.netbeans.modules.xml.axi.impl.AXIModelImpl; 23 import org.netbeans.modules.xml.axi.visitor.AXIVisitor; 24 import org.netbeans.modules.xml.axi.Compositor.CompositorType; 25 import org.netbeans.modules.xml.schema.model.All; 26 import org.netbeans.modules.xml.schema.model.Choice; 27 import org.netbeans.modules.xml.schema.model.SchemaComponent; 28 import org.netbeans.modules.xml.schema.model.Sequence; 29 30 36 public class Compositor extends AXIComponent { 37 38 42 public static enum CompositorType { 43 SEQUENCE, CHOICE, ALL; 44 45 public String getName() { 46 return toString(); 47 } 48 49 public String toString() { 50 String retValue = super.toString(); 51 return retValue.substring(0,1) + retValue.substring(1).toLowerCase(); 52 } 53 } 54 55 58 Compositor(AXIModel model, CompositorType type) { 59 super(model); 60 this.type = type; 61 } 62 63 66 Compositor(AXIModel model, SchemaComponent schemaComponent) { 67 super(model, schemaComponent); 68 if(schemaComponent instanceof Sequence) 69 type = CompositorType.SEQUENCE; 70 if(schemaComponent instanceof Choice) 71 type = CompositorType.CHOICE; 72 if(schemaComponent instanceof All) 73 type = CompositorType.ALL; 74 } 75 76 79 public Compositor(AXIModel model, AXIComponent sharedComponent) { 80 super(model, sharedComponent); 81 } 82 83 84 public void accept(AXIVisitor visitor) { 85 visitor.visit(this); 86 } 87 88 91 public CompositorType getType() { 92 return type; 93 } 94 95 98 public void setType(CompositorType value) { 99 getModel().startTransaction(); 100 try{ 101 firePropertyChangeEvent(Compositor.PROP_TYPE, getType(), value); 102 }finally{ 103 getModel().endTransaction(); 104 try { 105 ((AXIModelImpl)getModel()).setForceSync(true); 106 getModel().sync(); 107 } catch(IOException iox) { 108 } finally { 109 if(getModel() != null) 110 ((AXIModelImpl)getModel()).setForceSync(false); 111 } 112 } 113 } 114 115 void setCompositorType(Compositor.CompositorType newType) { 116 this.type = newType; 117 } 118 119 122 public String getMinOccurs() { 123 return minOccurs; 124 } 125 126 public void setMinOccurs(String value) { 127 String oldValue = getMinOccurs(); 128 if( (oldValue == null && value == null) || 129 (oldValue != null && oldValue.equals(value)) ) { 130 return; 131 } 132 this.minOccurs = value; 133 firePropertyChangeEvent(PROP_MINOCCURS, oldValue, value); 134 } 135 136 139 public String getMaxOccurs() { 140 return maxOccurs; 141 } 142 143 public void setMaxOccurs(String value) { 144 String oldValue = getMaxOccurs(); 145 if( (oldValue == null && value == null) || 146 (oldValue != null && oldValue.equals(value)) ) { 147 return; 148 } 149 this.maxOccurs = value; 150 firePropertyChangeEvent(PROP_MAXOCCURS, oldValue, value); 151 } 152 153 156 public void addCompositor(Compositor compositor) { 157 appendChild(Compositor.PROP_COMPOSITOR, compositor); 158 } 159 160 163 public void removeCompositor(Compositor compositor) { 164 removeChild(Compositor.PROP_COMPOSITOR, compositor); 165 } 166 167 170 public void addElement(Element element) { 171 appendChild(Element.PROP_ELEMENT, element); 172 } 173 174 177 public void removeElement(Element element) { 178 removeChild(Element.PROP_ELEMENT, element); 179 } 180 181 186 public boolean allowsFullMultiplicity() { 187 return !(getParent() instanceof Compositor && 188 ((Compositor)getParent()).getType() == CompositorType.ALL); 189 } 190 191 public String toString() { 192 if(type == null) 193 return null; 194 195 return type.toString(); 196 } 197 198 private CompositorType type; 199 private String minOccurs; 200 private String maxOccurs; 201 202 public static final String PROP_COMPOSITOR = "compositor"; public static final String PROP_MINOCCURS = "minOccurs"; public static final String PROP_MAXOCCURS = "maxOccurs"; public static final String PROP_TYPE = "type"; } 207 | Popular Tags |