1 17 package org.eclipse.emf.ecore.xmi.impl; 18 19 import java.util.List ; 20 import java.util.Map ; 21 22 import org.xml.sax.Attributes ; 23 import org.xml.sax.Locator ; 24 25 import org.eclipse.emf.ecore.EAttribute; 26 import org.eclipse.emf.ecore.EObject; 27 import org.eclipse.emf.ecore.EStructuralFeature; 28 import org.eclipse.emf.ecore.InternalEObject; 29 import org.eclipse.emf.ecore.xmi.XMLHelper; 30 import org.eclipse.emf.ecore.xmi.XMLResource; 31 import org.eclipse.emf.ecore.xmi.XMLResource.XMLInfo; 32 33 34 38 public class SAXXMLHandler extends XMLHandler 39 { 40 protected Locator locator; 41 protected Attributes attribs; 42 43 46 public SAXXMLHandler(XMLResource xmiResource, XMLHelper helper, Map options) 47 { 48 super(xmiResource, helper, options); 49 } 50 51 protected Object setAttributes(Object attributes) 52 { 53 Object oldAttribs = attribs; 54 this.attribs = (Attributes )attributes; 55 return oldAttribs; 56 } 57 58 public void setLocator(Object locator) 59 { 60 this.locator = (Locator ) locator; 61 } 62 63 protected int getLineNumber() 64 { 65 if (locator != null) 66 { 67 return locator.getLineNumber(); 68 } 69 else 70 { 71 return super.getLineNumber(); 72 } 73 } 74 75 protected int getColumnNumber() 76 { 77 if (locator != null) 78 { 79 return locator.getColumnNumber(); 80 } 81 else 82 { 83 return super.getColumnNumber(); 84 } 85 } 86 87 90 protected boolean isNull() 91 { 92 return attribs.getValue(NIL_ATTRIB) != null; 93 } 94 95 96 99 protected void handleNamespaceAttribs() 100 { 101 for (int i = 0, size = attribs.getLength(); i < size; ++i) 102 { 103 String attrib = attribs.getQName(i); 104 if (attrib.startsWith(XMLResource.XML_NS)) 105 { 106 handleXMLNSAttribute(attrib, attribs.getValue(i)); 107 } 108 else if (SCHEMA_LOCATION_ATTRIB.equals(attrib)) 109 { 110 handleXSISchemaLocation(attribs.getValue(i)); 111 } 112 else if (NO_NAMESPACE_SCHEMA_LOCATION_ATTRIB.equals(attrib)) 113 { 114 handleXSINoNamespaceSchemaLocation(attribs.getValue(i)); 115 } 116 } 117 } 118 119 protected String getXSIType() 120 { 121 return attribs.getValue(TYPE_ATTRIB); 122 } 123 124 127 protected void handleObjectAttribs(EObject obj) 128 { 129 if (attribs != null) 130 { 131 InternalEObject internalEObject = (InternalEObject)obj; 132 for (int i = 0, size = attribs.getLength(); i < size; ++i) 133 { 134 String name = attribs.getQName(i); 135 if (name.equals(idAttribute)) 136 { 137 xmlResource.setID(internalEObject, attribs.getValue(i)); 138 } 139 else if (name.equals(hrefAttribute) && (!recordUnknownFeature || types.peek() != UNKNOWN_FEATURE_TYPE)) 140 { 141 handleProxy(internalEObject, attribs.getValue(i)); 142 } 143 else if (!name.startsWith(XMLResource.XML_NS) && !notFeatures.contains(name)) 144 { 145 setAttribValue(obj, name, attribs.getValue(i)); 146 } 147 } 148 } 149 } 150 151 protected void processObject(EObject object) 152 { 153 if (object != null) 154 { 155 EStructuralFeature valueFeature = getContentFeature(object); 156 157 if (valueFeature != null) 158 { 159 text = new StringBuffer (); 160 objects.push(object); 161 types.push(valueFeature); 162 return; 163 } 164 } 165 166 super.processObject(object); 167 } 168 169 protected EStructuralFeature getContentFeature(EObject object) 170 { 171 if (xmlMap != null) 172 { 173 List eAttributes = object.eClass().getEAllAttributes(); 174 if (eAttributes.size() >= 1) 175 { 176 EAttribute eAttribute = (EAttribute) eAttributes.get(0); 177 XMLInfo info = xmlMap.getInfo(eAttribute); 178 if (info != null && info.getXMLRepresentation() == XMLInfo.CONTENT) 179 { 180 return eAttribute; 181 } 182 } 183 } 184 185 return null; 186 } 187 } | Popular Tags |