1 package org.xmldb.xupdate.lexus.commands; 2 3 55 56 import org.w3c.dom.Node ; 57 58 import java.util.Hashtable ; 59 60 68 public class CommandConstants extends Object { 69 70 71 public static final int ROOT_ELEMENT = 0; 72 73 public static final int COMMAND_COUNT = 7; 74 75 public static final int COMMAND_REMOVE = 1; 76 77 public static final int COMMAND_RENAME = 2; 78 79 public static final int COMMAND_UPDATE = 3; 80 81 public static final int COMMAND_VARIABLE = 4; 82 83 public static final int COMMAND_APPEND = 5; 84 85 public static final int COMMAND_INSERT_BEFORE = 6; 86 87 public static final int COMMAND_INSERT_AFTER = 7; 88 89 protected static final int FIRST_INSTRUCTION = 100; 90 91 public static final int INSTRUCTION_ELEMENT = 101; 92 93 public static final int INSTRUCTION_ATTRIBUTE = 102; 94 95 public static final int INSTRUCTION_COMMENT = 103; 96 97 public static final int INSTRUCTION_TEXT = 104; 98 99 public static final int INSTRUCTION_CDATA = 105; 100 101 public static final int INSTRUCTION_PROCESSING_INSTRUCTION = 106; 102 103 public static final int INSTRUCTION_VALUE_OF = 107; 104 105 protected static final int LAST_INSTRUCTION = 200; 106 107 public static final int ATTRIBUTES = 200; 108 109 public static final int CHARACTERS = 300; 110 111 112 private Hashtable ids = null; 113 114 private CommandObject[] command = null; 115 116 public static TempTree tempTree = null; 117 118 121 public CommandConstants() { 122 tempTree = new TempTree(); 123 initTable(); 124 } 125 126 127 133 public int idForString(String localName) { 134 Integer result = (Integer ) ids.get(localName); 135 if (result == null) { 136 return 0; 137 } 138 return result.intValue(); 139 } 140 141 142 149 public CommandObject commandForID(int id) { 150 switch (id) { 151 case COMMAND_REMOVE: 152 return command[0]; 153 case COMMAND_RENAME: 154 return command[1]; 155 case COMMAND_UPDATE: 156 return command[2]; 157 case COMMAND_VARIABLE: 158 return command[3]; 159 case COMMAND_APPEND: 160 return command[4]; 161 case COMMAND_INSERT_BEFORE: 162 return command[5]; 163 case COMMAND_INSERT_AFTER: 164 return command[6]; 165 } 166 return null; 167 } 168 169 170 176 public void setContextNode(Node node) throws Exception { 177 if (node == null) { 178 throw new IllegalArgumentException ("context node must not be null !"); 179 } 180 181 command = new CommandObject[COMMAND_COUNT]; 182 command[0] = new RemoveCommand(node); 183 command[1] = new RenameCommand(node); 184 command[2] = new UpdateCommand(node); 185 command[3] = new VariableCommand(node); 186 command[4] = new AppendCommand(node); 187 command[5] = new InsertBeforeCommand(node); 188 command[6] = new InsertAfterCommand(node); 189 } 190 191 192 195 public boolean isInsertOperation(int id) { 196 return id == COMMAND_INSERT_BEFORE 197 || id == COMMAND_INSERT_AFTER 198 || id == COMMAND_APPEND; 199 } 200 201 202 205 public boolean isInstruction(int id) { 206 return FIRST_INSTRUCTION < id && id < LAST_INSTRUCTION; 207 } 208 209 210 214 protected void initTable() { 215 ids = new Hashtable (); 216 ids.put("modifications", new Integer (ROOT_ELEMENT)); 218 ids.put("remove", new Integer (COMMAND_REMOVE)); 220 ids.put("rename", new Integer (COMMAND_RENAME)); 221 ids.put("update", new Integer (COMMAND_UPDATE)); 222 ids.put("variable", new Integer (COMMAND_VARIABLE)); 223 ids.put("append", new Integer (COMMAND_APPEND)); 224 ids.put("insert-before", new Integer (COMMAND_INSERT_BEFORE)); 225 ids.put("insert-after", new Integer (COMMAND_INSERT_AFTER)); 226 ids.put("element", new Integer (INSTRUCTION_ELEMENT)); 228 ids.put("attribute", new Integer (INSTRUCTION_ATTRIBUTE)); 229 ids.put("comment", new Integer (INSTRUCTION_COMMENT)); 230 ids.put("text", new Integer (INSTRUCTION_TEXT)); 231 ids.put("cdata", new Integer (INSTRUCTION_CDATA)); 232 ids.put("value-of", new Integer (INSTRUCTION_VALUE_OF)); 233 ids.put("processing-instruction", 234 new Integer (INSTRUCTION_PROCESSING_INSTRUCTION)); 235 236 } 237 } 238 239 | Popular Tags |