Package br.com.caelum.vraptor.form

Source Code of br.com.caelum.vraptor.form.ObjectContent

package br.com.caelum.vraptor.form;

import ognl.Ognl;
import ognl.OgnlException;
import net.vidageek.mirror.dsl.Mirror;
import br.com.caelum.vraptor.form.annotation.DefaultValue;

public class ObjectContent {

  private String field;
  private Object object;
  private Object content;

  public ObjectContent(Object object, String propertyPath) {
    this.object = object;
    this.field = propertyPath;
    try {
      this.content = Ognl.getValue(propertyPath,object);
    } catch (OgnlException e) {
      throw new RuntimeException(e);
    }
  }
 
  public ObjectContent orDefault() {
    if(content == null) {
      DefaultValue annotation = new Mirror().on(object.getClass()).reflect().annotation(DefaultValue.class).atField(field);
      content = annotation.value();
    }
    return this;
  }

  @Override
  public String toString() {
    return content.toString();
  }
 
  public Object getContent() {
    return content;
  }

}
TOP

Related Classes of br.com.caelum.vraptor.form.ObjectContent

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.