Package br.net.woodstock.rockframework.reflection

Examples of br.net.woodstock.rockframework.reflection.BeanDescriptor


  public void cleanEntity(final AbstractPreDatabaseOperationEvent event) {
    Object src = event.getEntity();
    EventSource eventSource = event.getSession();
    if (src instanceof Entity) {
      try {
        BeanDescriptor beanDescriptor = new BeanDescriptorBuilder(src.getClass()).getBeanDescriptor();
        for (PropertyDescriptor propertyDescriptor : beanDescriptor.getProperties()) {
          Class propertyType = propertyDescriptor.getType();
          Object propertyValue = propertyDescriptor.getValue(src);
          if (Entity.class.isAssignableFrom(propertyType)) {
            Entity entity = (Entity) propertyValue;
            if (EntityUtils.isNotEmptyId(entity)) {
View Full Code Here


  @SuppressWarnings("rawtypes")
  public void refreshEntity(final Object src, final EventSource eventSource) {
    if (src instanceof Entity) {
      try {
        BeanDescriptor beanDescriptor = new BeanDescriptorBuilder(src.getClass()).getBeanDescriptor();
        for (PropertyDescriptor propertyDescriptor : beanDescriptor.getProperties()) {
          Class propertyType = propertyDescriptor.getType();
          Object propertyValue = propertyDescriptor.getValue(src);
          if (Entity.class.isAssignableFrom(propertyType)) {
            Entity entity = (Entity) propertyValue;
            if (EntityUtils.isNotEmptyId(entity)) {
View Full Code Here

  public Collection<ValidationResult> validate(final Object entity) {
    if (entity == null) {
      throw new ValidationException(this.getMessage(AbstractEntityValidator.MESSAGE_INVALID_OBJECT));
    }

    BeanDescriptor beanDescriptor = new BeanDescriptorBuilder(entity.getClass()).getBeanDescriptor();
    Collection<ValidationResult> collection = new ArrayList<ValidationResult>();
    for (PropertyDescriptor propertyDescriptor : beanDescriptor.getProperties()) {
      ValidationResult result = null;
      boolean checkIdOnly = false;
      boolean checkColumn = false;
      boolean checkJoinColumn = false;
View Full Code Here

    String name = propertyDescriptor.getName();
    return new ValidationResult(false, name, DomainMessage.getInstance().getMessage(AbstractEntityValidator.MESSAGE_VALIDATION_OK));
  }

  private Object getId(final Object o) {
    BeanDescriptor beanDescriptor = new BeanDescriptorBuilder(o.getClass()).getBeanDescriptor();
    for (PropertyDescriptor propertyDescriptor : beanDescriptor.getProperties()) {
      if (propertyDescriptor.isAnnotationPresent(Id.class)) {
        return propertyDescriptor.getValue(o);
      }
    }
    return null;
View Full Code Here

  public static QueryContext createQueryContext(final Entity entity, final Map<String, Object> options) {
    Assert.notNull(entity, "entity");

    try {
      Class<?> clazz = entity.getClass();
      BeanDescriptor beanDescriptor = new BeanDescriptorBuilder(clazz).getBeanDescriptor();
      String entityName = QueryContextHelper.getEntityName(beanDescriptor);
      QueryContext context = new QueryContext(entityName, entityName, QueryContextHelper.ROOT_ALIAS, null);
      Queue<Entity> parsed = new LinkedList<Entity>();

      parsed.add(entity);

      for (PropertyDescriptor propertyDescriptor : beanDescriptor.getProperties()) {
        if (!propertyDescriptor.isReadable()) {
          continue;
        }
        String name = propertyDescriptor.getName();
        String alias = name;
View Full Code Here

    parsed.add(value);

    if (QueryContextHelper.hasNotNullAttribute(value)) {
      Class<?> clazz = value.getClass();
      QueryContext child = new QueryContext(realName, name, alias, context);
      BeanDescriptor beanDescriptor = new BeanDescriptorBuilder(clazz).getBeanDescriptor();
      child.setJoinNeeded(true);
      for (PropertyDescriptor propertyDescriptor : beanDescriptor.getProperties()) {
        if (!propertyDescriptor.isReadable()) {
          continue;
        }
        String childName = propertyDescriptor.getName();
        String childAlias = propertyDescriptor.getName();
View Full Code Here

            continue;
          }
          parsed.add((Entity) o);

          Class<?> clazz = o.getClass();
          BeanDescriptor beanDescriptor = new BeanDescriptorBuilder(clazz).getBeanDescriptor();
          for (PropertyDescriptor propertyDescriptor : beanDescriptor.getProperties()) {
            if (!propertyDescriptor.isReadable()) {
              continue;
            }
            String childName = propertyDescriptor.getName();
            String childAlias = propertyDescriptor.getName() + QueryContextHelper.ALIAS_SEPARADOR + index;
View Full Code Here

  private static boolean hasNotNullAttribute(final Entity e) {
    if (e == null) {
      return false;
    }

    BeanDescriptor beanDescriptor = new BeanDescriptorBuilder(e.getClass()).getBeanDescriptor();
    for (PropertyDescriptor property : beanDescriptor.getProperties()) {
      if (!property.isReadable()) {
        continue;
      }
      Object tmp = property.getValue(e);
      if ((tmp != null) && (QueryContextHelper.isValidType(property.getType()))) {
View Full Code Here

  public Collection<String> getErrors() {
    Collection<String> collection = new ArrayList<String>();
    ClassFinder classFinder = new ClassFinderImpl(this.baseName, new AssignableClassFilter(Entity.class));
    for (Class<?> clazz : classFinder.getClasses()) {
      BeanDescriptor beanDescriptor = new BeanDescriptorBuilder(clazz).getBeanDescriptor();
      for (PropertyDescriptor propertyDescriptor : beanDescriptor.getProperties()) {
        if (propertyDescriptor.isAnnotationPresent(ManyToMany.class)) {
          ManyToMany manyToMany = propertyDescriptor.getAnnotation(ManyToMany.class);
          CascadeType[] cascades = manyToMany.cascade();
          FetchType fetchType = manyToMany.fetch();

          this.checkCascade(collection, manyToMany, beanDescriptor, propertyDescriptor, cascades);
          this.checkFetch(collection, manyToMany, beanDescriptor, propertyDescriptor, fetchType);

          if (!propertyDescriptor.isAnnotationPresent(JoinTable.class)) {
            collection.add("Missing @JoinTable on " + beanDescriptor.getType().getCanonicalName() + "." + propertyDescriptor.getName());
          }
        }
        if (propertyDescriptor.isAnnotationPresent(ManyToOne.class)) {
          ManyToOne manyToOne = propertyDescriptor.getAnnotation(ManyToOne.class);
          CascadeType[] cascades = manyToOne.cascade();
          FetchType fetchType = manyToOne.fetch();

          this.checkCascade(collection, manyToOne, beanDescriptor, propertyDescriptor, cascades);
          this.checkFetch(collection, manyToOne, beanDescriptor, propertyDescriptor, fetchType);

          if (!propertyDescriptor.isAnnotationPresent(JoinColumn.class)) {
            collection.add("Missing @JoinColumn on " + beanDescriptor.getType().getCanonicalName() + "." + propertyDescriptor.getName());
          } else {
            JoinColumn joinColumn = propertyDescriptor.getAnnotation(JoinColumn.class);
            if (manyToOne.optional() != joinColumn.nullable()) {
              collection.add("Conflict in @ManyToOne(optional) and @JoinColumn(nullable) on " + beanDescriptor.getType().getCanonicalName() + "." + propertyDescriptor.getName());
            }
          }
        }
        if (propertyDescriptor.isAnnotationPresent(OneToMany.class)) {
          OneToMany oneToMany = propertyDescriptor.getAnnotation(OneToMany.class);
          CascadeType[] cascades = oneToMany.cascade();
          FetchType fetchType = oneToMany.fetch();
          String mappedBy = oneToMany.mappedBy();

          this.checkCascade(collection, oneToMany, beanDescriptor, propertyDescriptor, cascades);
          this.checkFetch(collection, oneToMany, beanDescriptor, propertyDescriptor, fetchType);
          this.checkMappedBy(collection, oneToMany, beanDescriptor, propertyDescriptor, mappedBy);
        }
        if (propertyDescriptor.isAnnotationPresent(OneToOne.class)) {
          OneToOne oneToOne = propertyDescriptor.getAnnotation(OneToOne.class);
          CascadeType[] cascades = oneToOne.cascade();
          FetchType fetchType = oneToOne.fetch();
          String mappedBy = oneToOne.mappedBy();

          this.checkCascade(collection, oneToOne, beanDescriptor, propertyDescriptor, cascades);
          this.checkFetch(collection, oneToOne, beanDescriptor, propertyDescriptor, fetchType);

          if (ConditionUtils.isEmpty(mappedBy)) {
            if (!propertyDescriptor.isAnnotationPresent(JoinColumn.class)) {
              collection.add("Missing @OneToOne(mappedBy) or @JoinColumn on " + beanDescriptor.getType().getCanonicalName() + "." + propertyDescriptor.getName());
            } else {
              JoinColumn joinColumn = propertyDescriptor.getAnnotation(JoinColumn.class);
              if (oneToOne.optional() != joinColumn.nullable()) {
                collection.add("Conflict in @OneToOne(optional) and @JoinColumn(nullable) on " + beanDescriptor.getType().getCanonicalName() + "." + propertyDescriptor.getName());
              }
            }
          }
        }
      }
View Full Code Here

    super();
    this.clazz = clazz;
  }

  public BeanDescriptor getBeanDescriptor() {
    BeanDescriptor beanDescriptor = new MethodBeanDescriptor(this.clazz);
    return beanDescriptor;
  }
View Full Code Here

TOP

Related Classes of br.net.woodstock.rockframework.reflection.BeanDescriptor

Copyright © 2018 www.massapicom. 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.