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:
15: /**
16: * For identification_variable_declaration.
17: */
18: public class IdentificationVarNode extends Node {
19:
20: private String abstractSchemaName;
21: private String identifier;
22: private JoinNode joinList;
23:
24: private NavRoot navRoot;
25:
26: public IdentificationVarNode(String schemaName, String identifier,
27: JoinNode joinList) {
28: this .abstractSchemaName = schemaName;
29: this .identifier = identifier;
30: this .joinList = joinList;
31: }
32:
33: public String getAbstractSchemaName() {
34: return abstractSchemaName;
35: }
36:
37: public String getIdentifier() {
38: return identifier;
39: }
40:
41: public JoinNode getJoinList() {
42: return joinList;
43: }
44:
45: public Object arrive(NodeVisitor v, Object msg) {
46: return v.arriveIdentificationVarNode(this , msg);
47: }
48:
49: public String toStringImp() {
50: StringBuffer s = new StringBuffer();
51: s.append(abstractSchemaName);
52: if (navRoot != null) {
53: s.append('%');
54: s.append(navRoot.getNavClassMetaData().qname);
55: }
56: s.append(" AS ");
57: s.append(identifier);
58: for (Node e = joinList; e != null; e = e.getNext()) {
59: s.append(' ');
60: s.append(e);
61: }
62: return s.toString();
63: }
64:
65: public void resolve(ResolveContext rc) {
66: checkIdVarDoesNotExist(rc);
67: ClassMetaData cmd = rc.getModelMetaData().getClassMetaByASN(
68: abstractSchemaName);
69: if (cmd == null) {
70: throw rc.createUserException(
71: "Unknown abstract schema name: "
72: + abstractSchemaName, this );
73: }
74: navRoot = new NavRoot(this , cmd);
75: rc.addIdVar(identifier, navRoot);
76: resolve(joinList, rc);
77: }
78:
79: private void checkIdVarDoesNotExist(ResolveContext rc) {
80: NavBase dup = rc.getIdVar(identifier);
81: if (dup != null) {
82: throw rc.createUserException(
83: "Duplicate identification variable: " + identifier,
84: this );
85: }
86: }
87:
88: public NavRoot getNavRoot() {
89: return navRoot;
90: }
91:
92: }
|