sk.uniba.euromath.document.schema.impl.export
Class ElementRuleImpl

java.lang.Object
  extended by sk.uniba.euromath.document.schema.impl.export.ElementRuleImpl
All Implemented Interfaces:
IBaseRuleP, IElementRuleP

public class ElementRuleImpl
extends Object
implements IElementRuleP

Implements the ElementRuleP interface.

Author:
Martin Vysny

Constructor Summary
ElementRuleImpl(SchemaImpl schema, Element e)
          Constructs instance of object.
 
Method Summary
 List<? extends Element> areElementsDeletable(Set<? extends Element> elements)
          Checks whether given elements are deletable.
 IAttributeRuleP getAttributeRule(Attr attribute)
          Returns rule for given attribute.
 INameListP<? extends INewElementRuleP> getEnclosingElements(sk.baka.ikslibs.ptr.DOMPoint start, sk.baka.ikslibs.ptr.DOMPoint end)
          Computes and returns an one-sized insertlist of elements, that can enclose given nodeset.
 INameListP<? extends IAttributeRuleP> getInsertableAttributes()
          Returns all attributes that can be created in this element.
 List<? extends IInsertListP> getInsertableElements(sk.baka.ikslibs.ptr.DOMPoint point)
          Computes insertable elements, with their positions between other nodes.
 IValueRule getValueRule()
          Gets text acceptor, that checks valid text values for given element.
 boolean isAnyStringInsertable(sk.baka.ikslibs.ptr.DOMPoint ip)
           Checks, if there can be any string inserted into given point.
 boolean isDeclosable(Element e)
          Checks if given element is declosable - if the contents of given element can replace the element.
 boolean isDeletable(sk.baka.ikslibs.ptr.DOMPoint start, sk.baka.ikslibs.ptr.DOMPoint end)
          Checks if given interval is removable from the document.
 boolean isDeletable(Node node)
          Checks if a simple node is deletable from the element.
 boolean isDeletableAttribute(Attr attribute)
          Checks, whether given attribute is deletable from its element.
 boolean isInsertable(sk.baka.ikslibs.ptr.DOMPoint ip, Node node)
          Checks if given nodes are insertable into given position.
 String toString()
           
 void validate()
           Validates the element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ElementRuleImpl

public ElementRuleImpl(SchemaImpl schema,
                       Element e)
Constructs instance of object.

Parameters:
schema - the schema instance.
e - element, which will this rule represent.
Throws:
DocumentValidityException - if e is invalid against this schema.
Method Detail

getInsertableAttributes

public INameListP<? extends IAttributeRuleP> getInsertableAttributes()
Description copied from interface: IElementRuleP
Returns all attributes that can be created in this element. Result namelist must be used for inserting one attribute only.

Specified by:
getInsertableAttributes in interface IElementRuleP
Returns:
List containing AttributeRule instances - all attribute rules, that can be added to element e.

isDeletableAttribute

public boolean isDeletableAttribute(Attr attribute)
Description copied from interface: IElementRuleP
Checks, whether given attribute is deletable from its element.

Specified by:
isDeletableAttribute in interface IElementRuleP
Parameters:
attribute - attribute to check. It may be foreign attribute also.
Returns:
false if attribute is not deletable.

getInsertableElements

public List<? extends IInsertListP> getInsertableElements(sk.baka.ikslibs.ptr.DOMPoint point)
Description copied from interface: IElementRuleP
Computes insertable elements, with their positions between other nodes. User can choose, which sequence he wishes to create.

Specified by:
getInsertableElements in interface IElementRuleP
Parameters:
point - insertion point, before which we want to insert element. If InsertPoint.FIRST, new element will be created before first node.
Returns:
array of element lists, each list represents one possibility, which elements can be inserted.

getValueRule

public IValueRule getValueRule()
Description copied from interface: IElementRuleP
Gets text acceptor, that checks valid text values for given element. Result applies only to textual content of element, that doesn't contain a child element(s). It applies to whole textual content - it may be multiple Text and CData nodes.

Specified by:
getValueRule in interface IElementRuleP
Returns:
text acceptor. If it was called on element with one or more child elements, returns null.

getAttributeRule

public IAttributeRuleP getAttributeRule(Attr attribute)
Description copied from interface: IElementRuleP
Returns rule for given attribute.

Specified by:
getAttributeRule in interface IElementRuleP
Parameters:
attribute - attribute, which rule must be returned. It must be a local attribute.
Returns:
rule, validating given attribute.

isAnyStringInsertable

public boolean isAnyStringInsertable(sk.baka.ikslibs.ptr.DOMPoint ip)
Description copied from interface: IElementRuleP

Checks, if there can be any string inserted into given point. Must be used only for element, that contains some elements - if true, then any string can be inserted at selected position, if false, then no string can be inserted at all.

When element doesn't contain no child element, then getValueRule should be used: it returns more useful rule.

Specified by:
isAnyStringInsertable in interface IElementRuleP
Parameters:
ip - insert point, where we want to insert some text. ip.pos must be equal to zero.
Returns:
true, if there can be inserted any string, false otherwise.

toString

public String toString()
Overrides:
toString in class Object

areElementsDeletable

public List<? extends Element> areElementsDeletable(Set<? extends Element> elements)
Description copied from interface: IElementRuleP
Checks whether given elements are deletable. These elements must be children of context element. If all these elements can be safely deleted then function returns non-null reference to a list of elements, that must be deleted aswell. If null is returned then given elements are not deletable.

Specified by:
areElementsDeletable in interface IElementRuleP
Parameters:
elements - set of elements that are to be deleted.
Returns:
list of elements that must be deleted aswell. The list may be empty. None of the elements contained in result list are contained in the elements aswell. If null is returned then given elements cannot be deleted.

getEnclosingElements

public INameListP<? extends INewElementRuleP> getEnclosingElements(sk.baka.ikslibs.ptr.DOMPoint start,
                                                                   sk.baka.ikslibs.ptr.DOMPoint end)
Description copied from interface: IElementRuleP
Computes and returns an one-sized insertlist of elements, that can enclose given nodeset.

Specified by:
getEnclosingElements in interface IElementRuleP
Parameters:
start - the start of the nodeset. It must point before the end insertpoint.
end - the end of the nodeset.
Returns:
insertlist with one item. The item denotes an element, that can replace given content and contain this content as its children. If null is returned then no such element is suitable.

isDeclosable

public boolean isDeclosable(Element e)
Description copied from interface: IElementRuleP
Checks if given element is declosable - if the contents of given element can replace the element.

Specified by:
isDeclosable in interface IElementRuleP
Parameters:
e - the element to declose
Returns:
true if e is declosable, false otherwise.

isDeletable

public boolean isDeletable(Node node)
Checks if a simple node is deletable from the element.

Specified by:
isDeletable in interface IElementRuleP
Parameters:
node - the node to query. Only the text/cdata/element/entity node that is child of context element can be queried.
Returns:
true if the node is deletable, false otherwise.

isInsertable

public boolean isInsertable(sk.baka.ikslibs.ptr.DOMPoint ip,
                            Node node)
Description copied from interface: IElementRuleP
Checks if given nodes are insertable into given position.

Specified by:
isInsertable in interface IElementRuleP
Parameters:
ip - the point where the sequence shall be inserted
node - the node to insert. Entities, Entity references and document fragments are automatically expanded - replaced by their children. The node may be or contain any type of node, including entity references, comments etc.
Returns:
true if these nodes are insertable, false otherwise.

isDeletable

public boolean isDeletable(sk.baka.ikslibs.ptr.DOMPoint start,
                           sk.baka.ikslibs.ptr.DOMPoint end)
Description copied from interface: IElementRuleP
Checks if given interval is removable from the document.

Specified by:
isDeletable in interface IElementRuleP
Parameters:
start - the start of the interval
end - the end of the interval
Returns:
true if these nodes are removable, false otherwise.

validate

public void validate()
              throws SchemaException
Description copied from interface: IElementRuleP

Validates the 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 ValidationContextP.validate() to validate this unknown element.

The only exception to this rule is emp:id attribute, which the schema must ignore.

Specified by:
validate in interface IElementRuleP
Throws:
SchemaException - if something goes wrong in the process of validation. The Schema instance must provide as much information as possible about error. It should display path to errorneous element with getPathToRoot() method of EuromathSchemaProvider class.


Copyright © 2003-2006 null. All Rights Reserved.