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.EmbeddableType; 36 import com.caucho.util.L10N; 37 38 41 public class EmbeddedSchemaExpr extends SchemaExpr { 42 private static final L10N L = new L10N(EmbeddedSchemaExpr.class); 43 44 private EmbeddedExpr _expr; 45 private String _name; 46 47 50 public EmbeddedSchemaExpr(EmbeddedExpr 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 EmbeddedExpr getExpr() 69 { 70 return _expr; 71 } 72 73 76 public SchemaExpr createField(QueryParser parser, String name) 77 throws QueryParseException 78 { 79 EmbeddableType type = _expr.getTargetType(); 80 81 AmberField field = type.getField(name); 82 83 if (field == null) 84 throw parser.error(L.l("{0}: '{1}' is an unknown field.", 85 type.getBeanClass().getName(), 86 name)); 87 88 AmberExpr fieldExpr = _expr.createField(parser, name); 89 90 if (fieldExpr instanceof EmbeddedExpr) 91 return new EmbeddedSchemaExpr((EmbeddedExpr) fieldExpr, name); 92 93 throw parser.error(L.l("{0}: '{1}' must be a collection or one-to-one relationship.", 94 type.getBeanClass().getName(), 95 name)); 96 } 97 98 101 public FromItem addFromItem(QueryParser parser, String id) 102 throws QueryParseException 103 { 104 _expr = (EmbeddedExpr) _expr.bindSelect(parser, id); 105 106 FromItem fromItem = _expr.bindSubPath(parser); 107 108 return fromItem; 109 } 110 111 public String toString() 112 { 113 return "EmbeddedSchemaExpr[" + _name + "]"; 114 } 115 } 116 | Popular Tags |