1 17 package org.eclipse.emf.ecore.xmi.impl; 18 19 import java.util.Map ; 20 21 import org.xml.sax.Attributes ; 22 import org.xml.sax.Locator ; 23 24 import org.eclipse.emf.ecore.EObject; 25 import org.eclipse.emf.ecore.InternalEObject; 26 import org.eclipse.emf.ecore.xmi.XMLHelper; 27 import org.eclipse.emf.ecore.xmi.XMLResource; 28 29 30 33 public class SAXXMIHandler extends XMIHandler 34 { 35 protected Locator locator; 36 protected Attributes attribs; 37 38 41 public SAXXMIHandler(XMLResource xmiResource, XMLHelper helper, Map options) 42 { 43 super(xmiResource, helper, options); 44 } 45 46 protected Object setAttributes(Object attributes) 47 { 48 Object oldAttribs = attribs; 49 this.attribs = (Attributes )attributes; 50 return oldAttribs; 51 } 52 53 public void setLocator(Object locator) 54 { 55 this.locator = (Locator ) locator; 56 } 57 58 protected int getLineNumber() 59 { 60 if (locator != null) 61 { 62 return locator.getLineNumber(); 63 } 64 else 65 { 66 return super.getLineNumber(); 67 } 68 } 69 70 protected int getColumnNumber() 71 { 72 if (locator != null) 73 { 74 return locator.getColumnNumber(); 75 } 76 else 77 { 78 return super.getColumnNumber(); 79 } 80 } 81 82 85 protected boolean isNull() 86 { 87 return attribs.getValue(NIL_ATTRIB) != null; 88 } 89 90 91 94 protected void handleNamespaceAttribs() 95 { 96 for (int i = 0, size = attribs.getLength(); i < size; ++i) 97 { 98 String attrib = attribs.getQName(i); 99 if (attrib.startsWith(XMLResource.XML_NS)) 100 { 101 handleXMLNSAttribute(attrib, attribs.getValue(i)); 102 } 103 else if (SCHEMA_LOCATION_ATTRIB.equals(attrib)) 104 { 105 handleXSISchemaLocation(attribs.getValue(i)); 106 } 107 else if (NO_NAMESPACE_SCHEMA_LOCATION_ATTRIB.equals(attrib)) 108 { 109 handleXSINoNamespaceSchemaLocation(attribs.getValue(i)); 110 } 111 } 112 } 113 114 protected String getXSIType() 115 { 116 String xsiType = attribs.getValue(TYPE_ATTRIB); 117 118 if (xsiType == null) 119 { 120 xsiType = attribs.getValue(XMI_TYPE_ATTRIB); 121 } 122 123 return xsiType; 124 } 125 126 129 protected void handleObjectAttribs(EObject obj) 130 { 131 if (attribs != null) 132 { 133 InternalEObject internalEObject = (InternalEObject)obj; 134 for (int i = 0, size = attribs.getLength(); i < size; ++i) 135 { 136 String name = attribs.getQName(i); 137 if (name.equals(ID_ATTRIB)) 138 { 139 xmlResource.setID(internalEObject, attribs.getValue(i)); 140 } 141 else if (name.equals(hrefAttribute) && (!recordUnknownFeature || types.peek() != UNKNOWN_FEATURE_TYPE)) 142 { 143 handleProxy(internalEObject, attribs.getValue(i)); 144 } 145 else if (!name.startsWith(XMLResource.XML_NS) && !notFeatures.contains(name)) 146 { 147 setAttribValue(obj, name, attribs.getValue(i)); 148 } 149 } 150 } 151 } 152 } | Popular Tags |