View Javadoc

1   /*
2    * Copyright 1999-2006 Faculty of Mathematics, Physics
3    * and Informatics, Comenius University, Bratislava. This file is protected by
4    * the Mozilla Public License version 1.1 (the License); you may not use this
5    * file except in compliance with the License. You may obtain a copy of the
6    * License at http://euromath2.sourceforge.net/license.html Unless required by
7    * applicable law or agreed to in writing, software distributed under the
8    * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9    * OF ANY KIND, either express or implied. See the License for the specific
10   * language governing permissions and limitations under the License.
11   */
12  package sk.uniba.euromath.document.schema.plug;
13  import java.util.List;
14  import java.util.Set;
15  import org.w3c.dom.Attr;
16  import org.w3c.dom.Element;
17  import org.w3c.dom.Node;
18  import sk.baka.ikslibs.ptr.DOMPoint;
19  /***
20   * Represents rule for one element, already present in the document. You can
21   * assume that element is not modified while this instance is used.
22   * @author Martin Vysny
23   */
24  public interface IElementRuleP extends IBaseRuleP {
25  	/***
26  	 * Returns all attributes that can be created in this element. Result
27  	 * namelist must be used for inserting one attribute only.
28  	 * @return List containing <code>AttributeRule</code> instances - all
29  	 * attribute rules, that can be added to element <code>e</code>.
30  	 */
31  	public INameListP< ? extends IAttributeRuleP> getInsertableAttributes();
32  	/***
33  	 * Checks, whether given attribute is deletable from its element.
34  	 * @param attribute attribute to check. It may be foreign attribute also.
35  	 * @return false if attribute is not deletable.
36  	 */
37  	public boolean isDeletableAttribute(Attr attribute);
38  	/***
39  	 * Computes insertable elements, with their positions between other nodes.
40  	 * User can choose, which sequence he wishes to create.
41  	 * @param point insertion point, before which we want to insert element. If
42  	 * <code>InsertPoint.FIRST</code>, new element will be created before
43  	 * first node.
44  	 * @return array of element lists, each list represents one possibility,
45  	 * which elements can be inserted.
46  	 */
47  	public List< ? extends IInsertListP> getInsertableElements(DOMPoint point);
48  	/***
49  	 * Gets text acceptor, that checks valid text values for given element.
50  	 * Result applies only to textual content of element, that doesn't contain a
51  	 * child element(s). It applies to whole textual content - it may be
52  	 * multiple Text and CData nodes.
53  	 * @return text acceptor. If it was called on element with one or more child
54  	 * elements, returns <code>null</code>.
55  	 */
56  	public IValueRule getValueRule();
57  	/***
58  	 * <p>
59  	 * Checks, if there can be any string inserted into given point. Must be
60  	 * used only for element, that contains some elements - if true, then any
61  	 * string can be inserted at selected position, if false, then no string can
62  	 * be inserted at all.
63  	 * </p>
64  	 * <p>
65  	 * When element doesn't contain no child element, then
66  	 * <code>getValueRule</code> should be used: it returns more useful rule.
67  	 * </p>
68  	 * @param ip insert point, where we want to insert some text. ip.pos must be
69  	 * equal to zero.
70  	 * @return true, if there can be inserted any string, false otherwise.
71  	 */
72  	public boolean isAnyStringInsertable(DOMPoint ip);
73  	/***
74  	 * Returns rule for given attribute.
75  	 * @param attribute attribute, which rule must be returned. It must be a
76  	 * local attribute.
77  	 * @return rule, validating given attribute.
78  	 */
79  	public IAttributeRuleP getAttributeRule(Attr attribute);
80  	/***
81  	 * Checks whether given elements are deletable. These elements must be
82  	 * children of context element. If all these elements can be safely deleted
83  	 * then function returns non-null reference to a list of elements, that must
84  	 * be deleted aswell. If <code>null</code> is returned then given elements
85  	 * are not deletable.
86  	 * @param elements set of elements that are to be deleted.
87  	 * @return list of elements that must be deleted aswell. The list may be
88  	 * empty. None of the elements contained in result list are contained in the
89  	 * <code>elements</code> aswell. If <code>null</code> is returned then
90  	 * given elements cannot be deleted.
91  	 * @throws IllegalArgumentException if given elements are not children of
92  	 * the context element.
93  	 */
94  	public List< ? extends Element> areElementsDeletable(
95  			Set< ? extends Element> elements);
96  	/***
97  	 * Computes and returns an one-sized insertlist of elements, that can
98  	 * enclose given nodeset.
99  	 * @param start the start of the nodeset. It must point before the
100 	 * <code>end</code> insertpoint.
101 	 * @param end the end of the nodeset.
102 	 * @return insertlist with one item. The item denotes an element, that can
103 	 * replace given content and contain this content as its children. If
104 	 * <code>null</code> is returned then no such element is suitable.
105 	 */
106 	public INameListP< ? extends INewElementRuleP> getEnclosingElements(
107 			DOMPoint start, DOMPoint end);
108 	/***
109 	 * Checks if given element is declosable - if the contents of given element
110 	 * can replace the element.
111 	 * @param e the element to declose
112 	 * @return <code>true</code> if e is declosable, <code>false</code>
113 	 * otherwise.
114 	 */
115 	public boolean isDeclosable(Element e);
116 	/***
117 	 * Checks if a simple node is deletable from the element.
118 	 * @param node the node to query. Only the text/cdata/element/entity node
119 	 * that is child of context element can be queried.
120 	 * @return <code>true</code> if the node is deletable, false otherwise.
121 	 */
122 	public boolean isDeletable(Node node);
123 	/***
124 	 * Checks if given nodes are insertable into given position.
125 	 * @param ip the point where the sequence shall be inserted
126 	 * @param node the node to insert. Entities, Entity references and document
127 	 * fragments are automatically expanded - replaced by their children. The
128 	 * node may be or contain any type of node, including entity references,
129 	 * comments etc.
130 	 * @return <code>true</code> if these nodes are insertable,
131 	 * <code>false</code> otherwise.
132 	 */
133 	public boolean isInsertable(DOMPoint ip, Node node);
134 	/***
135 	 * Checks if given interval is removable from the document.
136 	 * @param start the start of the interval
137 	 * @param end the end of the interval
138 	 * @return <code>true</code> if these nodes are removable,
139 	 * <code>false</code> otherwise.
140 	 */
141 	public boolean isDeletable(DOMPoint start, DOMPoint end);
142 	/***
143 	 * <p>
144 	 * Validates the element. It must be full validation, no elements nor texts
145 	 * must not be skipped. If this element is not valid, exception must be
146 	 * thrown.
147 	 * </p>
148 	 * <p>
149 	 * When element from another namespace uri is encountered in the process of
150 	 * validation, just call <code>ValidationContextP.validate()</code> to
151 	 * validate this unknown element.
152 	 * </p>
153 	 * <p>
154 	 * The only exception to this rule is <code>emp:id</code> attribute, which
155 	 * the schema must ignore.
156 	 * </p>
157 	 * @throws SchemaException if something goes wrong in the process of
158 	 * validation. The <code>Schema</code> instance must provide as much
159 	 * information as possible about error. It should display path to errorneous
160 	 * element with <code>getPathToRoot()</code> method of
161 	 * <code>EuromathSchemaProvider</code> class.
162 	 */
163 	public void validate() throws SchemaException;
164 }