KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > amber > expr > AbstractPathExpr


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free Software Foundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.amber.expr;
30
31 import com.caucho.amber.AmberRuntimeException;
32 import com.caucho.amber.field.AmberField;
33 import com.caucho.amber.query.FromItem;
34 import com.caucho.amber.query.QueryParser;
35 import com.caucho.amber.type.AbstractStatefulType;
36 import com.caucho.amber.type.RelatedType;
37 import com.caucho.util.L10N;
38
39 /**
40  * Represents an amber mapping query expression
41  */

42 abstract public class AbstractPathExpr extends AbstractAmberExpr
43   implements PathExpr {
44   private static final L10N L = new L10N(AbstractPathExpr.class);
45
46   /**
47    * Creates the expr from the path.
48    */

49   public AmberExpr createField(QueryParser parser, String JavaDoc fieldName)
50   {
51     AmberField field = null;
52
53     AbstractStatefulType type = getTargetType();
54
55     do {
56       field = type.getField(fieldName);
57
58       if (type instanceof RelatedType)
59         type = ((RelatedType) type).getParentType();
60     }
61     while ((type != null) && (field == null));
62
63     if (field == null)
64       throw new AmberRuntimeException(L.l("'{0}' is an unknown field of '{1}'.",
65             fieldName, getTargetType().getName()));
66
67     return field.createExpr(parser, this);
68   }
69
70   /**
71    * Creates an array reference.
72    */

73   public AmberExpr createArray(AmberExpr field)
74   {
75     throw new UnsupportedOperationException JavaDoc(getClass().getName());
76   }
77
78   /**
79    * Binds the expression as a select item.
80    */

81   public PathExpr bindSelect(QueryParser parser, String JavaDoc tableName)
82   {
83     return this;
84   }
85
86   /**
87    * Binds the expression as a select item.
88    */

89   public FromItem bindSubPath(QueryParser parser)
90   {
91     return null;
92   }
93
94   /**
95    * Returns the from item
96    */

97   public FromItem getChildFromItem()
98   {
99     throw new UnsupportedOperationException JavaDoc(getClass().getName());
100   }
101 }
102
Popular Tags