下面列出了怎么用org.xml.sax.Locator的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Define its content model.
*/
void define(short contentModelType, Term contentModel, Locator locator) {
assert this.contentModel==null; // may not be called twice
this.contentModelType = contentModelType;
this.contentModel = contentModel;
this.locator = locator;
contentModel.normalize(normalizedBlocks,false);
for( Block b : normalizedBlocks ) {
if(b.isRepeated || b.elements.size()>1) {
for( Element e : b.elements ) {
owner.getOrCreateElement(e.name).mustBeClass = true;
}
}
}
}
protected CPropertyInfo(String name, boolean collection, XSComponent source,
CCustomizations customizations, Locator locator) {
this.publicName = name;
String n = null;
Model m = Ring.get(Model.class);
if (m != null) {
n = m.getNameConverter().toVariableName(name);
} else {
n = NameConverter.standard.toVariableName(name);
}
if(!JJavaName.isJavaIdentifier(n))
n = '_'+n; // avoid colliding with the reserved names like 'abstract'.
this.privateName = n;
this.isCollection = collection;
this.locator = locator;
if(customizations==null)
this.customizations = CCustomizations.EMPTY;
else
this.customizations = customizations;
this.source = source;
}
public ParsedPattern endGrammar(Location loc, Annotations anno) throws BuildException {
for (Enumeration e = defines.keys();
e.hasMoreElements();) {
String name = (String) e.nextElement();
RefPattern rp = (RefPattern) defines.get(name);
if (rp.getPattern() == null) {
sb.error("reference_to_undefined", name, rp.getRefLocator());
rp.setPattern(sb.pb.makeError());
}
}
Pattern start = startRef.getPattern();
if (start == null) {
sb.error("missing_start_element", (Locator) loc);
start = sb.pb.makeError();
}
return start;
}
@Override
public Object[] adaptArguments(Object[] arguments) {
for (int i = 0; i < arguments.length; i++) {
if (arguments[i] instanceof Locator) {
arguments[i] = null;
}
}
return arguments;
}
/**
* Filter a new document locator event.
*
* @param locator The document locator.
*/
public void setDocumentLocator (Locator locator)
{
this.locator = locator;
if (contentHandler != null) {
contentHandler.setDocumentLocator(locator);
}
}
public SchemaImpl(SchemaSetImpl _parent, Locator loc, String tns) {
if (tns == null)
// the empty string must be used.
throw new IllegalArgumentException();
this.targetNamespace = tns;
this.parent = _parent;
this.locator = loc;
}
/**
* Copy an existing Locator or Locator2 object.
* If the object implements Locator2, values of the
* <em>encoding</em> and <em>version</em>strings are copied,
* otherwise they set to <em>null</em>.
*
* @param locator The existing Locator object.
*/
public Locator2Impl (Locator locator)
{
super (locator);
if (locator instanceof Locator2) {
Locator2 l2 = (Locator2) locator;
version = l2.getXMLVersion ();
encoding = l2.getEncoding ();
}
}
public elementDeclBody(NGCCHandler parent, NGCCEventSource source, NGCCRuntimeEx runtime, int cookie, Locator _locator, boolean _isGlobal) {
super(source, parent, cookie);
$runtime = runtime;
this.locator = _locator;
this.isGlobal = _isGlobal;
$_ngcc_current_state = 48;
}
public attributeDeclBody(NGCCHandler parent, NGCCEventSource source, NGCCRuntimeEx runtime, int cookie, Locator _locator, boolean _isLocal, String _defaultValue, String _fixedValue) {
super(source, parent, cookie);
$runtime = runtime;
this.locator = _locator;
this.isLocal = _isLocal;
this.defaultValue = _defaultValue;
this.fixedValue = _fixedValue;
$_ngcc_current_state = 13;
}
/**
* Compares if two {@link Locator}s point to the exact same position.
*/
public static boolean equals(Locator lhs, Locator rhs) {
return lhs.getLineNumber()==rhs.getLineNumber()
&& lhs.getColumnNumber()==rhs.getColumnNumber()
&& equals(lhs.getSystemId(),rhs.getSystemId())
&& equals(lhs.getPublicId(),rhs.getPublicId());
}
DelayedRef( PatcherManager _manager, Locator _source, SchemaImpl _schema, UName _name ) {
this.schema = _schema.getRoot();
this.manager = _manager;
this.name = _name;
this.source = _source;
if(name==null) throw new InternalError();
manager.addPatcher(this);
}
public modelGroupBody(NGCCHandler parent, NGCCEventSource source, NGCCRuntimeEx runtime, int cookie, Locator _locator, String _compositorName) {
super(source, parent, cookie);
$runtime = runtime;
this.locator = _locator;
this.compositorName = _compositorName;
$_ngcc_current_state = 6;
}
public CEnumLeafInfo(Model model,
QName typeName,
CClassInfoParent container,
String shortName,
CNonElement base,
Collection<CEnumConstant> _members,
XSComponent source,
CCustomizations customizations,
Locator _sourceLocator) {
this.model = model;
this.parent = container;
this.shortName = model.allocator.assignClassName(parent,shortName);
this.base = base;
this.members = _members;
this.source = source;
if(customizations==null)
customizations = CCustomizations.EMPTY;
this.customizations = customizations;
this.sourceLocator = _sourceLocator;
this.typeName = typeName;
for( CEnumConstant mem : members )
mem.setParent(this);
model.add(this);
// TODO: can we take advantage of the fact that enum can be XmlRootElement?
}
/**
* Implements org.xml.sax.ContentHandler.setDocumentLocator()
* Receive an object for locating the origin of SAX document events.
*/
@Override
public void setDocumentLocator(Locator locator) {
_locator = locator;
if (_handler != null) {
_handler.setDocumentLocator(locator);
}
}
/**
* Compares if two {@link Locator}s point to the exact same position.
*/
public static boolean equals(Locator lhs, Locator rhs) {
return lhs.getLineNumber()==rhs.getLineNumber()
&& lhs.getColumnNumber()==rhs.getColumnNumber()
&& equals(lhs.getSystemId(),rhs.getSystemId())
&& equals(lhs.getPublicId(),rhs.getPublicId());
}
private String printLocator(Locator loc) {
if( loc==null ) return "";
int line = loc.getLineNumber();
String sysId = loc.getSystemId();
if(sysId==null) sysId = Messages.format(Messages.MSG_UNKNOWN_FILE);
if( line!=-1 )
return Messages.format( Messages.MSG_LINE_X_OF_Y,
Integer.toString(line), sysId );
else
return sysId;
}
public Attribute(String ns, String localName, String prefix, String value, Locator loc) {
this.ns = ns;
this.localName = localName;
this.prefix = prefix;
this.value = value;
this.loc = loc;
}
public ParsedPattern makeParentRef(String name, Location loc, Annotations anno) throws BuildException {
// TODO: do this check by the caller
if (parent == null) {
sb.error("parent_ref_outside_grammar", (Locator) loc);
return sb.makeErrorPattern();
}
return parent.makeRef(name, loc, anno);
}
/**
* Sets the document locator associated with our parser.
*
* @param locator The new locator
*/
@Override
public void setDocumentLocator(Locator locator) {
if (saxLog.isDebugEnabled()) {
saxLog.debug("setDocumentLocator(" + locator + ")");
}
this.locator = locator;
}
public Definitions(AbstractDocument document, Locator locator) {
super(locator);
_document = document;
_bindings = new ArrayList();
_imports = new ArrayList();
_messages = new ArrayList();
_portTypes = new ArrayList();
_services = new ArrayList();
_importedNamespaces = new HashSet();
_helper = new ExtensibilityHelper();
}
SimpleTypeImpl(
SchemaDocumentImpl _parent,
AnnotationImpl _annon,
Locator _loc,
ForeignAttributesImpl _fa,
String _name,
boolean _anonymous,
Set<XSVariety> finalSet,
Ref.SimpleType _baseType) {
super(_parent, _annon, _loc, _fa, _parent.getTargetNamespace(), _name, _anonymous);
this.baseType = _baseType;
this.finalSet = finalSet;
}
/**
* Adapter implementation method; do not call.
* Adapt a SAX1 document locator event.
*
* @param locator A document locator.
* @see org.xml.sax.ContentHandler#setDocumentLocator
*/
public void setDocumentLocator (Locator locator)
{
this.locator = locator;
if (contentHandler != null) {
contentHandler.setDocumentLocator(locator);
}
}
public Binding(Defining defining, Locator locator, ErrorReceiver receiver) {
super(defining, locator, receiver);
_operations = new ArrayList();
_helper = new ExtensibilityHelper();
}
private void warning(String key, Locator loc) throws SAXException {
warning(new SAXParseException(localizer.message(key), loc));
}
public final void error( Locator loc, String msg, Exception e ) {
error( new SAXParseException2(msg,loc,e) );
}
public void yyevent(SaxEvent saxtoken) throws SAXException {
if (accepted) {
throw new SAXException("yyevent called after parser has accepted");
}
SaxEventType event = saxtoken.eventtype;
String name = saxtoken.name;
int yytoken = 0;
Lexeme element = null;
Lexeme attr = null;
element = elementmap.get(name);
switch (event) {
case STARTELEMENT:
if (element == null) {// undefined
yytoken = UNKNOWN_ELEMENT_;
break;
}
yytoken = element.open;
if (yytoken == OTHERXML_) {
otherxml = true;
textok = true;
} else if (!otherxml && yytoken == VALUE_)
textok = true;
break;
case ATTRIBUTE:
String lcname = name.toLowerCase();
attr = attributemap.get(lcname);
if (attr == null) {
if (lcname.startsWith(SPECIALATTRPREFIX))
yytoken = ATTR_SPECIAL;
else
yytoken = UNKNOWN_ATTR;
} else
yytoken = attr.atoken;
break;
case ENDELEMENT:
if (element == null) {// undefined
yytoken = _UNKNOWN_ELEMENT;
break;
}
yytoken = element.close;
if (yytoken == _OTHERXML) {
otherxml = false;
textok = false;
} else if (!otherxml && yytoken == _VALUE)
textok = false;
break;
case CHARACTERS:
if (!textok)
return; // ignore
yytoken = TEXT;
break;
case ENDDOCUMENT:
yytoken = EOF;
break;
default:
return; // ignore
} // switch
int status = 0;
try {
Locator loc = getLocator();
Dap4BisonParser parser = (Dap4BisonParser) this;
// Bison.Position pos = new Bison.Position(loc);
// Dap4BisonParser.Location yyloc = parser.new Location(pos);
status = parser.push_parse(yytoken, saxtoken);
} catch (Exception e) {
throw new SAXException(e);
}
if (status == YYABORT)
throw new SAXException("YYABORT");
else if (status == YYACCEPT)
accepted = true;
}
protected WildcardImpl( SchemaDocumentImpl owner, AnnotationImpl _annon, Locator _loc, ForeignAttributesImpl _fa, int _mode ) {
super(owner,_annon,_loc,_fa);
this.mode = _mode;
}
private void error(String key, String arg, Locator loc) throws SAXException {
error(new SAXParseException(localizer.message(key, arg), loc));
}
private void warning(String key, String arg1, String arg2, Locator loc)
throws SAXException {
warning(new SAXParseException(localizer.message(key, arg1, arg2), loc));
}
@Override
public void setDocumentLocator(Locator locator) {
}