FileDocCategorySizeDatePackage
ElementType.javaAPI DocAndroid 1.5 API7946Wed May 06 22:41:42 BST 2009org.ccil.cowan.tagsoup

ElementType

public class ElementType extends Object
This class represents an element type in the schema. An element type has a name, a content model vector, a member-of vector, a flags vector, default attributes, and a schema to which it belongs.
see
Schema

Fields Summary
private String
theName
private String
theNamespace
private String
theLocalName
private int
theModel
private int
theMemberOf
private int
theFlags
private AttributesImpl
theAtts
private ElementType
theParent
private Schema
theSchema
Constructors Summary
public ElementType(String name, int model, int memberOf, int flags, Schema schema)
Construct an ElementType: but it's better to use Schema.element() instead. The content model, member-of, and flags vectors are specified as ints.

param
name The element type name
param
model ORed-together bits representing the content models allowed in the content of this element type
param
memberOf ORed-together bits representing the content models to which this element type belongs
param
flags ORed-together bits representing the flags associated with this element type
param
schema The schema with which this element type will be associated

		theName = name;
		theModel = model;
		theMemberOf = memberOf;
		theFlags = flags;
		theAtts = new AttributesImpl();
		theSchema = schema;
		theNamespace = namespace(name, false);
		theLocalName = localName(name);
		
Methods Summary
public AttributesImplatts()
Returns the default attributes associated with this element type. Attributes of type CDATA that don't have default values are typically not included. Other attributes without default values have an internal value of null. The return value is an AttributesImpl to allow the caller to mutate the attributes.

return theAtts;
public booleancanContain(org.ccil.cowan.tagsoup.ElementType other)
Returns true if this element type can contain another element type. That is, if any of the models in this element's model vector match any of the models in the other element type's member-of vector.

param
other The other element type

		return (theModel & other.theMemberOf) != 0;
		
public intflags()
Returns the flags associated with this element type.

return
The flags associated with this element type as a vector of bits

 return theFlags; 
public java.lang.StringlocalName(java.lang.String name)
Return a local name from a Qname.

param
name The Qname
return
The local name

		int colon = name.indexOf(':");
		if (colon == -1) {
			return name;
			}
		else {
			return name.substring(colon+1).intern();
			}
		
public java.lang.StringlocalName()
Returns the local name of this element type.

return
The local name of the element type

 return theLocalName; 
public intmemberOf()
Returns the content models to which this element type belongs.

return
The content models to which this element type belongs as a vector of bits

 return theMemberOf; 
public intmodel()
Returns the content models of this element type.

return
The content models of this element type as a vector of bits

 return theModel; 
public java.lang.Stringname()
Returns the name of this element type.

return
The name of the element type

 return theName; 
public java.lang.Stringnamespace(java.lang.String name, boolean attribute)
Return a namespace name from a Qname. The attribute flag tells us whether to return an empty namespace name if there is no prefix, or use the schema default instead.

param
name The Qname
param
attribute True if name is an attribute name
return
The namespace name

		int colon = name.indexOf(':");
		if (colon == -1) {
			return attribute ? "" : theSchema.getURI();
			}
		String prefix = name.substring(0, colon);
		if (prefix.equals("xml")) {
			return "http://www.w3.org/XML/1998/namespace";
			}
		else {
			return ("urn:x-prefix:" + prefix).intern();
			}
		
public java.lang.Stringnamespace()
Returns the namespace name of this element type.

return
The namespace name of the element type

 return theNamespace; 
public static java.lang.Stringnormalize(java.lang.String value)
Normalize an attribute value (ID-style). CDATA-style attribute normalization is already done.

param
value The value to normalize
return
The normalized value

		if (value == null) return value;
		value = value.trim();
		if (value.indexOf("  ") == -1) return value;
		boolean space = false;
		int len = value.length();
		StringBuffer b = new StringBuffer(len);
		for (int i = 0; i < len; i++) {
			char v = value.charAt(i);
			if (v == ' ") {
				if (!space) b.append(v);
				space = true;
				}
			else {
				b.append(v);
				space = false;
				}
			}
		return b.toString();
		
public org.ccil.cowan.tagsoup.ElementTypeparent()
Returns the parent element type of this element type.

return
The parent element type

return theParent;
public Schemaschema()
Returns the schema which this element type is associated with.

return
The schema

return theSchema;
public voidsetAttribute(AttributesImpl atts, java.lang.String name, java.lang.String type, java.lang.String value)
Sets an attribute and its value into an AttributesImpl object. Attempts to set a namespace declaration are ignored.

param
atts The AttributesImpl object
param
name The name (Qname) of the attribute
param
type The type of the attribute
param
value The value of the attribute

		if (name.equals("xmlns") || name.startsWith("xmlns:")) {
			return;
			}
;
		String namespace = namespace(name, true);
		String localName = localName(name);
		int i = atts.getIndex(name);
		if (i == -1) {
			name = name.intern();
			if (type == null) type = "CDATA";
			if (!type.equals("CDATA")) value = normalize(value);
			atts.addAttribute(namespace, localName, name, type, value);
			}
		else {
			if (type == null) type = atts.getType(i);
			if (!type.equals("CDATA")) value=normalize(value);
			atts.setAttribute(i, namespace, localName, name, type, value);
			}
		
public voidsetAttribute(java.lang.String name, java.lang.String type, java.lang.String value)
Sets an attribute and its value into this element type.

param
name The name of the attribute
param
type The type of the attribute
param
value The value of the attribute

		setAttribute(theAtts, name, type, value);
		
public voidsetFlags(int flags)
Sets the flags of this element type.

param
flags associated with this element type The flags as a vector of bits

 theFlags = flags; 
public voidsetMemberOf(int memberOf)
Sets the content models to which this element type belongs.

param
memberOf The content models to which this element type belongs as a vector of bits

 theMemberOf = memberOf; 
public voidsetModel(int model)
Sets the models of this element type.

param
model The content models of this element type as a vector of bits

 theModel = model; 
public voidsetParent(org.ccil.cowan.tagsoup.ElementType parent)
Sets the parent element type of this element type.

param
parent The parent element type

 theParent = parent;