01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.metadata.parser;
12:
13: import com.versant.core.metadata.MDStatics;
14:
15: import java.io.Serializable;
16: import java.util.ArrayList;
17:
18: /**
19: * Base class for elements in the tree.
20: */
21: public abstract class JdoElement implements Serializable, MDStatics {
22:
23: public abstract JdoElement getParent();
24:
25: /**
26: * Get nicely formatted context information for an error message or
27: * debugging. This follows the parent chain.
28: */
29: public String getContext() {
30: ArrayList a = new ArrayList();
31: for (JdoElement e = this ; e != null; e = e.getParent())
32: a.add(e);
33: StringBuffer s = new StringBuffer();
34: boolean first = true;
35: for (int i = a.size() - 1; i >= 0; i--) {
36: if (first) {
37: first = false;
38: s.append("--> ");
39: } else
40: s.append('/');
41: s.append(((JdoElement) a.get(i)).getSubContext());
42: }
43: return s.toString();
44: }
45:
46: /**
47: * Get information for this element to be used in building up a
48: * context string.
49: * @see #getContext
50: */
51: public abstract String getSubContext();
52:
53: public JdoExtension[] addExtension(JdoExtension[] exts,
54: JdoExtension e) {
55: JdoExtension[] tmp = new JdoExtension[exts.length + 1];
56: System.arraycopy(exts, 0, tmp, 0, exts.length);
57: tmp[exts.length] = e;
58: return tmp;
59: }
60:
61: public JdoExtension createChild(int key, String value,
62: JdoElement parent) {
63: JdoExtension e = new JdoExtension();
64: e.key = key;
65: e.value = value;
66: e.parent = parent;
67: return e;
68: }
69:
70: }
|