KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > metadata > parser > JdoElement


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.metadata.parser;
13
14 import com.versant.core.metadata.MDStatics;
15
16 import java.io.Serializable JavaDoc;
17 import java.util.ArrayList JavaDoc;
18
19 /**
20  * Base class for elements in the tree.
21  */

22 public abstract class JdoElement implements Serializable JavaDoc, MDStatics {
23
24     public abstract JdoElement getParent();
25
26     /**
27      * Get nicely formatted context information for an error message or
28      * debugging. This follows the parent chain.
29      */

30     public String JavaDoc getContext() {
31         ArrayList JavaDoc a = new ArrayList JavaDoc();
32         for (JdoElement e = this; e != null; e = e.getParent()) a.add(e);
33         StringBuffer JavaDoc s = new StringBuffer JavaDoc();
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 s.append('/');
40             s.append(((JdoElement)a.get(i)).getSubContext());
41         }
42         return s.toString();
43     }
44
45     /**
46      * Get information for this element to be used in building up a
47      * context string.
48      * @see #getContext
49      */

50     public abstract String JavaDoc getSubContext();
51
52     public JdoExtension[] addExtension(JdoExtension[] exts, JdoExtension e) {
53         JdoExtension[] tmp = new JdoExtension[exts.length + 1];
54         System.arraycopy(exts, 0, tmp, 0, exts.length);
55         tmp[exts.length] = e;
56         return tmp;
57     }
58
59     public JdoExtension createChild(int key, String JavaDoc value, JdoElement parent) {
60         JdoExtension e = new JdoExtension();
61         e.key = key;
62         e.value = value;
63         e.parent = parent;
64         return e;
65     }
66
67 }
68
69
Popular Tags