01: package org.apache.ojb.jdo.jdoql;
02:
03: /* Copyright 2003-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import org.apache.ojb.broker.metadata.*;
19:
20: /**
21: * A field access expression. Note that this expression type can only be
22: * present in a query tree after resolving it.
23: *
24: * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
25: */
26: public class FieldAccess extends NameExpression {
27: /** The descriptor for the accessed field, either a field or a reference descriptor */
28: private AttributeDescriptorBase _descriptor;
29:
30: /**
31: * Creates a new field access object.
32: *
33: * @param base The base expression (can be <code>null</code>)
34: * @param name The field's name
35: */
36: public FieldAccess(Expression base, String name) {
37: super (base, name);
38: }
39:
40: /* (non-Javadoc)
41: * @see org.apache.ojb.jdo.jdoql.Acceptor#accept(org.apache.ojb.jdo.jdoql.Visitor)
42: */
43: public void accept(Visitor visitor) {
44: visitor.visit(this );
45: }
46:
47: /**
48: * Sets the descriptor of the field accessed by this field access expression.
49: * Must be either a reference or a field descriptor.
50: *
51: * @param descriptor The descriptor of the field
52: */
53: public void setFieldDescriptor(AttributeDescriptorBase descriptor) {
54: _descriptor = descriptor;
55: }
56:
57: /**
58: * Returns the descriptor of the field accessed by this field access expression.
59: *
60: * @return The descriptor which is either a reference or field descriptor
61: */
62: public AttributeDescriptorBase getFieldDescriptor() {
63: return _descriptor;
64: }
65:
66: /* (non-Javadoc)
67: * @see org.apache.ojb.jdo.jdoql.Expression#getType()
68: */
69: public Class getType() {
70: if (_descriptor instanceof FieldDescriptor) {
71: return ((FieldDescriptor) _descriptor).getPersistentField()
72: .getType();
73: } else {
74: // this also covers collections
75: return ((ObjectReferenceDescriptor) _descriptor)
76: .getItemClass();
77: }
78: }
79: }
|