KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > jdo > jdoql > FieldAccess


1 package org.apache.ojb.jdo.jdoql;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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 {
28     /** The descriptor for the accessed field, either a field or a reference descriptor */
29     private AttributeDescriptorBase _descriptor;
30
31     /**
32      * Creates a new field access object.
33      *
34      * @param base The base expression (can be <code>null</code>)
35      * @param name The field's name
36      */

37     public FieldAccess(Expression base, String JavaDoc name)
38     {
39         super(base, name);
40     }
41
42     /* (non-Javadoc)
43      * @see org.apache.ojb.jdo.jdoql.Acceptor#accept(org.apache.ojb.jdo.jdoql.Visitor)
44      */

45     public void accept(Visitor visitor)
46     {
47         visitor.visit(this);
48     }
49
50     /**
51      * Sets the descriptor of the field accessed by this field access expression.
52      * Must be either a reference or a field descriptor.
53      *
54      * @param descriptor The descriptor of the field
55      */

56     public void setFieldDescriptor(AttributeDescriptorBase descriptor)
57     {
58         _descriptor = descriptor;
59     }
60
61     /**
62      * Returns the descriptor of the field accessed by this field access expression.
63      *
64      * @return The descriptor which is either a reference or field descriptor
65      */

66     public AttributeDescriptorBase getFieldDescriptor()
67     {
68         return _descriptor;
69     }
70
71     /* (non-Javadoc)
72      * @see org.apache.ojb.jdo.jdoql.Expression#getType()
73      */

74     public Class JavaDoc getType()
75     {
76         if (_descriptor instanceof FieldDescriptor)
77         {
78             return ((FieldDescriptor)_descriptor).getPersistentField().getType();
79         }
80         else
81         {
82             // this also covers collections
83
return ((ObjectReferenceDescriptor)_descriptor).getItemClass();
84         }
85     }
86 }
87
Popular Tags