Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

aboutsummaryrefslogtreecommitdiffstats
blob: 61b2bd5a82866c057868d44d0974770a1655ed62 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
* Copyright (c) 2002 IBM Corporation and others.
* All rights reserved.   This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
* 
* Contributors:
*   IBM - Initial API and implementation
*   Jens Lukowski/Innoopract - initial renaming/restructuring
* 
*/
package org.eclipse.wst.xml.core.internal.contentmodel.modelquery;

import java.util.List;

import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.extension.*;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;


/**
 * This class provides an interface for performing higher level queries based on
 * a xml model (DOM) and one or more associated content models (CMDocument).
 *
 * The queries provided can be organized into three groups:
 *
 * 1) DOM Node to CMNode mapping
 *      Given a grammatically valid DOM Node the corresponding CMNode can be determined.
 *      (i.e. Element -> CMElementDeclaration, Attr -> CMAttributeDeclaration, CharacterData -> CMDataType)
 *
 * 2) DOM editing tests ("Can I do this?")
 *      Questions such as canInsert, canRemove, canReplace can assist in the editing of a DOM.
 *
 *      The validityChecking argument determines the strictness of the validity testing that occurs.
 *
 *      - VALIDITY_NONE    : The current content of the Element is ignored.
 *                           Only the content model is considered.
 *                           This is most useful for codeassist related queries.
 *
 *      - VALIDITY_STRICT  : The current content of the Element is considered.
 *                           Returns true only if the operation preserves content validity.
 *                           This is useful when DOM editing needs to be constrained to maintain validity.
 *
 *      - VALIDITY_PARTIAL : Some optimized compromise between the two options above.
 *
 * 3) DOM editing actions ("What can I do here?")
 *      These methods return ModelQueryActions that are relevant at some specified DOM Node.
 *      The actions indicate what kinds of DOM Node can be inserted where (at what index).
 */
public interface ModelQuery
{
  public static final int VALIDITY_NONE = 0;
  public static final int VALIDITY_PARTIAL = 1;
  public static final int VALIDITY_STRICT = 2;

  public static final int INCLUDE_ALL = 0xFF;
  public static final int INCLUDE_ATTRIBUTES = 0x01;
  public static final int INCLUDE_CHILD_NODES = 0x02;
  public static final int INCLUDE_SEQUENCE_GROUPS = 0x04;
  public static final int INCLUDE_TEXT_NODES = 0x08;
  public static final int INCLUDE_ENCLOSING_REPLACE_ACTIONS = 0x10;

  public static final int EDIT_MODE_UNCONSTRAINED = 0;
  public static final int EDIT_MODE_CONSTRAINED_LENIENT= 1;
  public static final int EDIT_MODE_CONSTRAINED_STRICT = 2;


  void setEditMode(int editMode);

  int  getEditMode();

  /**
   * Returns the CMDocument that corresponds to the DOM Node.
   * or null if no CMDocument is appropriate for the DOM Node.
   */
  CMDocument getCorrespondingCMDocument(Node node);

  /**
   * Returns the corresponding CMNode for the DOM Node
   * or null if no CMNode is appropriate for the DOM Node.
   */
  CMNode getCMNode(Node node);

  /**
   * Returns the corresponding CMAttribute for the DOM Node
   * or null if no CMNode is appropriate for the DOM Node.
   */
  CMAttributeDeclaration getCMAttributeDeclaration(Attr attr);

  /**
   * Returns the corresponding CMAttribute for the DOM Node
   * or null if no CMNode is appropriate for the DOM Node.
   */
  CMElementDeclaration getCMElementDeclaration(Element element);

  /**
   * Returns true if the content of the element is valid
   */
  boolean isContentValid(Element element);

  /**
   * Returns the CMNode of the parent element's content model
   * that corresponds to the node
   */
  CMNode getOrigin(Node node);

  /**
   * Returns an array of CMNodes of the parent element's content model
   * that corresponds to the node
   */
  CMNode[] getOriginArray(Element element);

  /**
   * Returns a list of all CMNode 'meta data' that may be potentially added to the element.
   */
  List getAvailableContent(Element element, CMElementDeclaration ed, int includeOptions);

  /**
   * Can a DOM Node corresponding to the CMNode 'meta data' be added to the parent
   */
  boolean canInsert(Element parent, CMNode cmNode, int index, int validityChecking);

  /**
   * Can multiple DOM Nodes corresponding to the list of CMNode 'meta data' be added to the parent
   */
  boolean canInsert(Element parent, List cmNodeList, int index, int validityChecking);

  /**
   * Can the DOM Node be removed
   */
  boolean canRemove(Node node, int validityChecking);

  /**
   * Can the list of DOM Nodes be removed
   */
  boolean canRemove(List nodeList, int validityChecking);

  /**
   * Can the children within the indicated indices be replaced with a DOM Node corresponding to the CMNode 'meta data'
   */
  boolean canReplace(Element parent, int startIndex, int endIndex, CMNode cmNode, int validityChecking);

  /**
   * Can the children within the indicated indices be replaced with multiple DOM Nodes corresponding to the list of CMNode 'meta data'
   */
  boolean canReplace(Element parent, int startIndex, int endIndex, List cmNodeList, int validityChecking);

  /**
   *
   */
  void getInsertActions(Element parent, CMElementDeclaration ed, int index, int includeOptions, int validityChecking, List actionList);

  /**
   *
   */
  void getInsertActions(Document parent, CMDocument cmDocument, int index, int includeOptions, int validityChecking, List actionList);

  /**
   * Return a list of replace actions that can be performed on the parent's content
   */
  void getReplaceActions(Element parent, CMElementDeclaration ed, int includeOptions, int validityChecking, List actionList);

  /**
   * Return a list of replace actions that can be performed on the selected children of that parent 
   */
  void getReplaceActions(Element parent, CMElementDeclaration ed, List selectedChildren, int includeOptions, int validityChecking, List actionList);

                        
  /** 
   *  @deprecated - use getPossibleDataTypeValues()
   */
  List getDataTypeValues(Element element, CMNode cmNode);

  /**
   * This methods return an array of possible values corresponding to the datatype of the CMNode (either an CMAttributeDeclaration or a CMElementDeclaration)
   */
  String[] getPossibleDataTypeValues(Element element, CMNode cmNode);

  /**
   * This method may return null if a CMDocumentManager is not used by the ModelQuery
   */
  CMDocumentManager getCMDocumentManager();                                       

  /**
   * This method may return null the ModelQuery doesn't support the use of extensions
   */
  ModelQueryExtensionManager getExtensionManager();   
}

Back to the top