1 23 24 package com.sun.enterprise.config.serverbeans.validation; 25 26 import java.util.Stack ; 27 import org.xml.sax.Attributes ; 28 import org.xml.sax.Locator ; 29 import org.xml.sax.SAXException ; 30 import org.xml.sax.helpers.DefaultHandler ; 31 import org.xml.sax.helpers.XMLFilterImpl ; 32 43 public class Framer extends DefaultHandler 47 { 48 49 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 50 if (isSystemPropertyElement(localName)){ 51 handleSystemPropertyEvent(atts); 52 } else if (isConfigEvent(localName)) { 53 handleStartConfigEvent(atts); 54 } else if (isServerEvent(localName)) { 55 handleStartServerEvent(atts); 56 } else if (isClusterEvent(localName)) { 57 handleStartClusterEvent(atts); 58 } else if (isServerRefEvent(localName)) { 59 handleStartServerRefEvent(atts); 60 } 61 super.startElement(namespaceURI, localName, qName, atts); 62 } 63 64 public void endElement(String namespaceURI, String localName, String qName) throws SAXException { 65 if (isConfigEvent(localName) || isServerEvent(localName) || isClusterEvent(localName)){ 66 frameStack.pop(); 67 } 68 super.endElement(namespaceURI, localName, qName); 69 } 70 71 72 private boolean isClusterEvent(String n){ 73 return n.equals(CLUSTER); 74 } 75 76 private boolean isConfigEvent(String n){ 77 return n.equals(CONFIG); 78 } 79 private boolean isServerEvent(String n){ 80 return n.equals(SERVER); 81 } 82 private boolean isServerRefEvent(String n){ 83 return n.equals(SERVER_REF); 84 } 85 private boolean isSystemPropertyElement(String n){ 86 return n.equals(SYSTEM_PROPERTY); 87 } 88 89 private void handleStartClusterEvent(Attributes atts){ 90 frameStack.push(getClusterFrame(atts)); 91 } 92 93 private void handleStartConfigEvent(Attributes atts){ 94 frameStack.push(getConfigFrame(atts)); 95 } 96 97 private void handleStartServerEvent(Attributes atts){ 98 frameStack.push(getServerFrame(atts)); 99 } 100 protected void handleStartServerRefEvent(Attributes atts){} 101 102 private void handleSystemPropertyEvent(Attributes atts){ 103 currentFrame().put(atts.getValue(NAMESPACE, NAME), atts.getValue(NAMESPACE, VALUE)); 104 } 105 106 protected Frame getClusterFrame(Attributes atts){ 107 return frameHolder.getClusterFrame(getFrameName(atts)); 108 } 109 110 protected Frame getConfigFrame(Attributes atts){ 111 return frameHolder.getConfigFrame(getFrameName(atts)); 112 } 113 114 protected Frame getServerFrame(Attributes atts){ 115 return frameHolder.getServerFrame(getFrameName(atts)); 116 } 117 118 119 private String getFrameName(Attributes atts){ 120 return atts.getValue(NAMESPACE, NAME); 121 } 122 123 Framer(){ 124 this(new FrameHolder()); 125 } 126 127 Framer(FrameHolder fh){ 128 frameHolder = fh; 129 frameStack.push(fh.getDomainFrame()); 130 } 131 132 133 FrameHolder getFrameHolder(){ 134 return frameHolder; 135 } 136 137 Frame currentFrame(){ 138 return (Frame) frameStack.peek(); 139 } 140 141 142 private Stack frameStack = new Stack (); 143 protected FrameHolder frameHolder = new FrameHolder(); 144 145 public static final String CLUSTER = "cluster"; 146 public static final String CONFIG = "config"; 147 public static final String CONFIG_REF = "config-ref"; 148 public static final String NAME = "name"; 149 public static final String NAMESPACE = ""; 150 public static final String SERVER = "server"; 151 public static final String SERVER_REF = "server-ref"; 152 public static final String SYSTEM_PROPERTY = "system-property"; 153 public static final String VALUE = "value"; 154 155 } 156 | Popular Tags |