001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.ejb.query;
012:
013: import com.versant.core.metadata.FieldMetaData;
014: import com.versant.core.metadata.ClassMetaData;
015:
016: /**
017: * Navigation through a field.
018: */
019: public class NavField extends NavBase {
020:
021: private FieldMetaData fmd; // the field being navigated
022: private boolean outer; // navigate with outer join semantics
023: private boolean fetch; // is this navigation for a fetch?
024:
025: private NavBase parent; // our parent
026: private NavField next; // our next sibling
027:
028: /**
029: * This will append us to our parents list of children.
030: */
031: public NavField(FieldMetaData fmd, NavBase parent, boolean outer,
032: boolean fetch) {
033: this .fmd = fmd;
034: this .outer = outer;
035: this .fetch = fetch;
036: setParent(parent);
037: }
038:
039: /**
040: * Remove us from our current parent (if any) and add us to np.
041: */
042: public void setParent(NavBase np) {
043: if (parent == np) {
044: return;
045: }
046: if (parent != null) {
047: NavField p = null;
048: for (NavField i = parent.children; i != this ; i = i.next)
049: ;
050: if (p == null) {
051: parent.children = next;
052: } else {
053: p.next = next;
054: }
055: next = null;
056: }
057: parent = np;
058: if (parent != null) {
059: if (parent.children == null) {
060: parent.children = this ;
061: } else {
062: NavField i;
063: for (i = parent.children; i.next != null; i = i.next)
064: ;
065: i.next = this ;
066: }
067: }
068: }
069:
070: /**
071: * Get the field being navigated.
072: */
073: public FieldMetaData getFmd() {
074: return fmd;
075: }
076:
077: public NavRoot getRoot() {
078: return parent == null ? null : parent.getRoot();
079: }
080:
081: public NavBase getParent() {
082: return parent;
083: }
084:
085: public NavField getNext() {
086: return next;
087: }
088:
089: public boolean isOuter() {
090: return outer;
091: }
092:
093: public boolean isFetch() {
094: return fetch;
095: }
096:
097: public ClassMetaData getNavClassMetaData() {
098: return fmd.getRefOrValueClassMetaData();
099: }
100:
101: public String toString() {
102: StringBuffer s = new StringBuffer();
103: s.append(fmd.name);
104: childrenToString(s);
105: return s.toString();
106: }
107:
108: }
|