1 17 package org.apache.ws.jaxme.xs.xml.impl; 18 19 import org.apache.ws.jaxme.xs.parser.XSContext; 20 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException; 21 import org.apache.ws.jaxme.xs.xml.*; 22 import org.apache.ws.jaxme.xs.xml.XsObject; 23 import org.xml.sax.Locator ; 24 import org.xml.sax.SAXException ; 25 import org.xml.sax.helpers.LocatorImpl ; 26 import org.xml.sax.helpers.NamespaceSupport ; 27 28 29 33 public class XsObjectImpl implements XsObject { 34 private final XsObject parent; 35 private boolean isValidated; 36 private final Locator locator; 37 38 protected XsObjectImpl(XsObject pParent) { 39 if (pParent == null) { 40 if (!(this instanceof XsESchema)) { 41 throw new IllegalStateException ("Only the schema may have a null parent."); 42 } 43 } else { 44 if (this instanceof XsESchema) { 45 throw new IllegalStateException ("The schema must have a null parent."); 46 } 47 } 48 parent = pParent; 49 XSContext context = getContext(); 50 if (context != null) { 51 Locator loc = context.getLocator(); 52 locator = loc == null ? null : new LocatorImpl (getContext().getLocator()); 53 } else { 54 locator = null; 55 } 56 } 57 58 public XsESchema getXsESchema() { 59 if (parent == null) { 60 return (XsESchema) this; 61 } else { 62 return parent.getXsESchema(); 63 } 64 } 65 66 public boolean isTopLevelObject() { return parent == null || parent instanceof XsESchema; } 67 public XsObject getParentObject() { return parent; } 68 69 public XsObjectFactory getObjectFactory() { return getContext().getXsObjectFactory(); } 70 public Locator getLocator() { return locator; } 71 protected NamespaceSupport getNamespaceSupport() { return getContext().getNamespaceSupport(); } 72 protected XsQName asXsQName(String pName) throws SAXException { 73 return asXsQName(getXsESchema(), getLocator(), getNamespaceSupport(), pName); 74 } 75 protected static XsQName asXsQName(XsESchema pSchema, Locator pLocator, NamespaceSupport pNss, String pName) throws SAXException { 76 String [] parts = pNss.processName(pName, new String [3], false); 77 if (parts == null) { 78 throw new LocSAXException("Undeclared namespace prefix: " + pName, pLocator); 79 } 80 if (pSchema instanceof XsESchemaImpl 81 && pSchema.getTargetNamespace() == null 82 && (parts[0] == null || "".equals(parts[0]))) { 83 return ((XsESchemaImpl) pSchema).newXsQName(parts[1], XsQName.prefixOf(pName)); 85 } else { 86 return new XsQName(parts[0], parts[1], XsQName.prefixOf(pName)); 87 } 88 } 89 public XSContext getContext() { return getXsESchema().getContext(); } 90 91 protected final boolean isValidated() { 92 return isValidated; 93 } 94 95 public void validate() throws SAXException { 96 isValidated = true; 97 } 98 } 99 | Popular Tags |