1 28 29 package com.caucho.amber.expr; 30 31 import com.caucho.amber.field.AmberField; 32 import com.caucho.amber.query.FromItem; 33 import com.caucho.amber.query.QueryParseException; 34 import com.caucho.amber.query.QueryParser; 35 import com.caucho.amber.type.RelatedType; 36 import com.caucho.util.L10N; 37 38 41 public class OneToOneSchemaExpr extends SchemaExpr { 42 private static final L10N L = new L10N(OneToOneSchemaExpr.class); 43 44 private DependentEntityOneToOneExpr _expr; 45 private String _name; 46 47 50 public OneToOneSchemaExpr(DependentEntityOneToOneExpr expr, 51 String name) 52 { 53 _expr = expr; 54 _name = name; 55 } 56 57 60 public String getTailName() 61 { 62 return _name; 63 } 64 65 68 public SchemaExpr createField(QueryParser parser, String name) 69 throws QueryParseException 70 { 71 RelatedType type = _expr.getTargetType(); 72 73 AmberField field = type.getField(name); 74 75 if (field == null) 76 throw parser.error(L.l("{0}: '{1}' is an unknown field.", 77 type.getBeanClass().getName(), 78 name)); 79 80 AmberExpr fieldExpr = _expr.createField(parser, name); 81 82 if (fieldExpr instanceof ManyToOneExpr) 83 return new ManyToOneSchemaExpr((ManyToOneExpr) fieldExpr, name); 84 85 if (fieldExpr instanceof DependentEntityOneToOneExpr) 86 return new OneToOneSchemaExpr((DependentEntityOneToOneExpr) fieldExpr, 87 name); 88 89 throw parser.error(L.l("{0}: '{1}' must be a collection or one-to-one relationship.", 90 type.getBeanClass().getName(), 91 name)); 92 } 93 94 97 public FromItem addFromItem(QueryParser parser, String id) 98 throws QueryParseException 99 { 100 _expr = (DependentEntityOneToOneExpr) _expr.bindSelect(parser, id); 101 102 FromItem fromItem = _expr.bindSubPath(parser); 103 104 return fromItem; 105 } 106 } 107 | Popular Tags |