1
2
3
4
5
6
7
8 package com.bbn.swede.core.dom;
9
10 import org.eclipse.core.resources.IMarker;
11 import org.eclipse.core.resources.IResource;
12 import org.eclipse.core.resources.WorkspaceJob;
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17
18 /***
19 * Custom text node implementation for unparseable XML errors.
20 * @author jlerner
21 */
22 public class UnparseableNode extends TextNode
23 {
24 /***
25 * A marker on the document indicating the invalid XML.
26 */
27 protected IMarker _marker;
28
29 /***
30 * Creates an Unparseable node.
31 * @param sText The full text of the invalid XML.
32 */
33 public UnparseableNode(String sText)
34 {
35 super(sText);
36 }
37
38 private final String _sUnparseable = "com.bbn.swede.ui.unparseablemarker";
39 /***
40 * Creates a marker resource to indicate the invalid XML of this node.
41 * @param resource The Eclipse resource of the file containing the node.
42 * @return An invalid XML marker attached to <code>resource</code> and the
43 * text range indicated by this node's offset and length.
44 * @throws CoreException if marker creation fails.
45 */
46 public IMarker createMarker(IResource resource) throws CoreException
47 {
48 final IResource fRes = resource;
49 final int fOffset = _iOffset;
50 final int fLength = _iLength;
51 WorkspaceJob job = new WorkspaceJob("Adding invalid XML marker to " + resource.getName())
52 {
53 public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException
54 {
55 IMarker mark = fRes.createMarker(_sUnparseable);
56 mark.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
57 mark.setAttribute(IMarker.MESSAGE, "Invalid XML");
58
59 mark.setAttribute(IMarker.CHAR_START, new Integer(fOffset));
60 mark.setAttribute(IMarker.CHAR_END, new Integer(fOffset + fLength));
61 _marker = mark;
62 return Status.OK_STATUS;
63 }
64 };
65
66 job.setSystem(true);
67
68 job.setRule(resource);
69 job.schedule();
70 return _marker;
71 }
72
73
74
75
76
77 protected int[] allowedChildren()
78 {
79 return null;
80 }
81
82
83
84
85
86 public int getNodeType()
87 {
88 return OASTNode.UNPARSEABLE;
89 }
90
91
92
93
94
95 public String getQName()
96 {
97 return "unparseable";
98 }
99 }