1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package sk.uniba.euromath.document.schema;
18 import org.w3c.dom.Attr;
19 import org.w3c.dom.Element;
20 import sk.uniba.euromath.document.DomCore;
21 import sk.uniba.euromath.document.schema.plug.SchemaException;
22 /***
23 * Document's content modifier helper. For chosen operation returns all
24 * possibilities, that will result in valid document. Not intended to be
25 * subclassed nor instantiated by clients.
26 * @author Martin Vysny
27 */
28 public class DocumentSchema {
29 private final SchemaReferences refs;
30 /***
31 * Constructor. Not intended to be used by clients.
32 * @param doc the document instance.
33 */
34 public DocumentSchema(DomCore doc) {
35 super();
36 refs = new SchemaReferences(doc);
37 }
38 /***
39 * Returns rule for given element. It can be further queried for various
40 * info.
41 * @param element the context element, for which rule will be created.
42 * @return instance of element rule
43 */
44 public ElementRule getElementRule(Element element) {
45 return new ElementRule(refs, element);
46 }
47 /***
48 * Checks, whether given attribute is deletable from its element. It is OK
49 * to use this function. However, for subsequent queries to attribute's
50 * element please use <code>ElementRule</code> instance, it's more
51 * effective.
52 * @param attribute attribute to check.
53 * @return false if attribute is not deletable.
54 */
55 public boolean isDeletableAttribute(Attr attribute) {
56 return new ElementRule(refs, attribute.getOwnerElement())
57 .isDeletableAttribute(attribute);
58 }
59 /***
60 * Gets attribute rule for given attribute. It can be used to validate
61 * textual value of attribute. It is OK to use this function. However, for
62 * subsequent queries to attribute's element please use
63 * <code>ElementRule</code> instance, it's more effective.
64 * @param attribute return rule for this attribute.
65 * @return rule for this attribute.
66 */
67 public AttributeRule getAttributeRule(Attr attribute) {
68 return new ElementRule(refs, attribute.getOwnerElement())
69 .getAttributeRule(attribute);
70 }
71 /***
72 * Validates this document.
73 * @throws SchemaException if something goes wrong in the process of
74 * validation.
75 */
76 public void validate() throws SchemaException {
77 Validator.getInstance().validate(
78 refs.doc.getDocument().getDocumentElement(), refs);
79 }
80 /***
81 * Returns object containing references to loaded schema objects.
82 * @return schema references object
83 */
84 public SchemaReferences getRefs() {
85 return refs;
86 }
87 }