sk.baka.xml.schematic.pluginterface
Interface ISchema

All Known Implementing Classes:
SchemaImpl

public interface ISchema

Schema returns various information regarding allowed document structure. It is created for every namespace, and each Schema returns elements from its namespace only. Because class can be used by multiple documents simultaneously, each method must be thread-safe.

Because of the identification system, in-memory Document is slightly modified. Schema instance must be aware that:

It is strictly forbidden to modify given document in any way!

Document can be changed between any two calls without further notification to Schema. Thus, Schema must be 'stateless' - it must not change its internal variables due to document contents. In other hand, it is guaranteed that when any Schema function is being executed, the document stays unmodified.

The schema should be checked for all schema mismatches in the loading time. The document is valid when some schema method is called and it must be valid when the suggested modifications are made. Hence the document is always valid and the only method that is allowed to throw an exception is the validate() method. However the method may throw an exception to signalise wrong parameters, invalid document etc (these exceptions signalise that there is something wrong with plugins or EuroMath itself).

Author:
Martin Vysny

Method Summary
 IElementRuleP getElementRule(Element element)
          Returns rule representing given existing element.
 INameListP<IAttributeRuleP> getExportedAttributes()
           Computes all attributes defined in this schema, regardless of element, which they are bound to.
 String getNamespaceUri()
          Returns URI for which the Schema works.
 INameListP<INewElementRuleP> getRootElements()
          Returns list of possible local names of the root elements.
 Iterator<String> getWarnings()
          Returns warnings that occured during schema loading.
 void validate(Element element)
           Validates given root element.
 

Method Detail

getNamespaceUri

String getNamespaceUri()
Returns URI for which the Schema works. Schema may accept elements/attributes from other namespaces, however it should not attempt to define their content.

Returns:
URI to which the Schema is bound.

getRootElements

INameListP<INewElementRuleP> getRootElements()
Returns list of possible local names of the root elements. Namespace URI is fixed and can be returned with getNamespaceUri() - root element automatically belongs to the bounded URI. Schema instance should compute this set only once and return immutable copy on each call.

Returns:
set of strings representing local names of the root elements.

getExportedAttributes

INameListP<IAttributeRuleP> getExportedAttributes()

Computes all attributes defined in this schema, regardless of element, which they are bound to. Returned array must NOT be modifed in any way. These attributes are called exported - they can be inserted into other namespaces.

This list serves for purpose of adding attributes of this namespace to elements from another namespace. Thus, if there are 2 or more attributes defined with same QName in schema, they cannot be returned here. That would raise ambiguity, because attributes are denoted only by QName, and we would have to select from more rules.

Local attributes have empty URI instead of its own namespace URI, so empty URI must be replaced by its namespace URI.

Result should be computed when object is created.

Returns:
all attributes of this schema.

getWarnings

Iterator<String> getWarnings()
Returns warnings that occured during schema loading. Items of iterator must NOT be modified nor deleted.

Returns:
iterator representing warnings, or null if there were no warnings.

validate

void validate(Element element)
              throws SchemaException

Validates given root element. It must be full validation, no elements nor texts must not be skipped. If this element is not valid, exception must be thrown.

When element from another namespace uri is encountered in the process of validation, just call SchemaPool.validate(Element) to validate this unknown element.

Parameters:
element - element to be validated, always one of possible root elements from this namespace.
Throws:
SchemaException - if something goes wrong in the process of validation. The ISchema instance must provide as much information as possible about error. It should display path to errorneous element with DOMUtils.getPathToRoot(org.w3c.dom.Node) method for example.

getElementRule

IElementRuleP getElementRule(Element element)
Returns rule representing given existing element. If the document is not valid then the rule returned is correct if and only if the rule can be identified from the name of the element - the element is said to be context-free.

Parameters:
element - the element. It must stay unchanged while returned instance is used.
Returns:
rule, used to modify contents of given element.


Copyright © 2006 Martin Vysny - baka. All Rights Reserved.