@Override public String convertToPresentation(Date value, ValueContext context) { if (value == null) { return null; } return getFormat(context.getLocale().orElse(null)).format(value); }
@Override public Result<Date> convertToModel(String value, ValueContext context) { if (value == null) { return Result.ok(null); } // Remove leading and trailing white space value = value.trim(); ParsePosition parsePosition = new ParsePosition(0); Date parsedValue = getFormat(context.getLocale().orElse(null)).parse(value, parsePosition); if (parsePosition.getIndex() != value.length()) { return Result.error("Could not convert '" + value); } return Result.ok(parsedValue); }
@SuppressWarnings("unchecked") private <Y> Type<Y> getMetaModelType(ValueContext typeContext) { switch (typeContext.getValueClassification()) { case BASIC: { return new BasicTypeImpl<Y>(typeContext.getBindableType(), Type.PersistenceType.BASIC); } case ENTITY: { final org.hibernate.type.EntityType type = (EntityType) typeContext.getValue().getType(); return (Type<Y>) context.locateEntityType(type.getAssociatedEntityName()); } case EMBEDDABLE: { final Component component = (Component) typeContext.getValue(); final EmbeddableTypeImpl<Y> embeddableType = new EmbeddableTypeImpl<Y>( typeContext.getBindableType(), typeContext.getAttributeMetadata().getOwnerType(), (ComponentType) typeContext.getValue().getType()); context.registerEmbeddedableType(embeddableType); final Iterator<Property> subProperties = component.getPropertyIterator(); while (subProperties.hasNext()) { final Property property = subProperties.next(); final AttributeImplementor<Y, Object> attribute = buildAttribute(embeddableType, property); if (attribute != null) { embeddableType.getBuilder().addAttribute(attribute); } } embeddableType.lock(); return embeddableType; } default: { throw new AssertionFailure("Unknown type : " + typeContext.getValueClassification()); } } }
public final ValueContext value() throws RecognitionException { ValueContext _localctx = new ValueContext(_ctx, getState()); enterRule(_localctx, 8, RULE_value); try { setState(55); switch (_input.LA(1)) { case STRING: _localctx = new StringContext(_localctx); enterOuterAlt(_localctx, 1); { setState(48); match(STRING); } break; case NUMBER: _localctx = new AtomContext(_localctx); enterOuterAlt(_localctx, 2); { setState(49); match(NUMBER); } break; case LCURLY: _localctx = new ObjectValueContext(_localctx); enterOuterAlt(_localctx, 3); { setState(50); object(); } break; case LBRACK: _localctx = new ArrayValueContext(_localctx); enterOuterAlt(_localctx, 4); { setState(51); array(); } break; case T__4: _localctx = new AtomContext(_localctx); enterOuterAlt(_localctx, 5); { setState(52); match(T__4); } break; case T__5: _localctx = new AtomContext(_localctx); enterOuterAlt(_localctx, 6); { setState(53); match(T__5); } break; case T__6: _localctx = new AtomContext(_localctx); enterOuterAlt(_localctx, 7); { setState(54); match(T__6); } break; default: throw new NoViableAltException(this); } } catch (RecognitionException re) { _localctx.exception = re; _errHandler.reportError(this, re); _errHandler.recover(this, re); } finally { exitRule(); } return _localctx; }