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.ejb.query;
12:
13: import com.versant.core.metadata.ClassMetaData;
14: import com.versant.core.common.CmdBitSet;
15:
16: /**
17: * Base class for Nav and NavRoot holding the children list and associated
18: * methods.
19: */
20: public abstract class NavBase {
21:
22: /**
23: * Fields navigated from us.
24: */
25: protected NavField children;
26:
27: /**
28: * Store specific info attached to us.
29: */
30: public Object storeObject;
31:
32: public NavBase() {
33: }
34:
35: /**
36: * Field the child with name and matching outer and fetch or null if none.
37: */
38: public NavField findChild(String name, boolean outer, boolean fetch) {
39: NavField i;
40: for (i = children; i != null; i = i.getNext()) {
41: if (i.getFmd().name.equals(name) && i.isOuter() == outer
42: && i.isFetch() == fetch) {
43: return i;
44: }
45: }
46: return null;
47: }
48:
49: /**
50: * Get our root.
51: */
52: public abstract NavRoot getRoot();
53:
54: /**
55: * Get the meta data used to resolve navigation from us in paths.
56: */
57: public abstract ClassMetaData getNavClassMetaData();
58:
59: /**
60: * Convert our children into a nice String.
61: */
62: protected void childrenToString(StringBuffer s) {
63: if (children != null) {
64: if (children.getNext() == null) {
65: s.append(" -> ");
66: s.append(children);
67: } else {
68: for (NavField f = children; f != null; f = f.getNext()) {
69: s.append(" [ -> ");
70: s.append(children);
71: s.append("] ");
72: }
73: }
74: }
75: }
76:
77: /**
78: * Add all classes referenced by this node and its children recursivley
79: * to bits. This is used to figure out class dependencies for flushing
80: * and eviction.
81: */
82: public void addInvolvedClasses(CmdBitSet bits) {
83: bits.addPlus(getNavClassMetaData());
84: for (NavField i = children; i != null; i = i.getNext()) {
85: i.addInvolvedClasses(bits);
86: }
87: }
88:
89: public NavField getChildren() {
90: return children;
91: }
92:
93: }
|