Examples of StaticJavaStub


Examples of org.metawidget.statically.javacode.StaticJavaStub

      // Suppress

      if (TRUE.equals(attributes.get(HIDDEN)))
      {
         return new StaticJavaStub();
      }

      Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, null);
      String name = attributes.get(NAME);

      // String

      if (String.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement("String " + name + " = this.example.get" + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null && !\"\".equals(" + name + "))");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.like(root.<String>get(\"" + name + "\"), '%' + " + name
                           + " + '%'))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // int or short

      if (int.class.equals(clazz) || short.class.equals(clazz) || byte.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement(clazz.getSimpleName() + " " + name + " = this.example.get"
                           + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != 0)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // LOOKUP

      String type = attributes.get(TYPE);

      if (attributes.containsKey(LOOKUP))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name + " = this.example.get"
                  + StringUtils.capitalize(name) + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // FACES_LOOKUP

      if (attributes.containsKey(FACES_LOOKUP))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name + " = this.example.get"
                  + StringUtils.capitalize(name) + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // We tried searching against N_TO_MANY relationships, but had the following problems:
      //
      // 1. Difficult to make JPA Criteria Builder search for 'a Set having all of the following items'. For 'a Set
      // having the following item' can do: predicatesList.add(root.join("customers").in(this.example.getCustomer()));
      // 2. Cumbersome to have a new class for this.example that only has a single Customer, as opposed to a Set
      // 3. Difficult to make JSF's h:selectOne* bind to a Set
      // 4. Difficult to make JSF's h:selectMany* appear as a single item dropdown
      //
      // So we've left it out for now

      return new StaticJavaStub();
   }
View Full Code Here

Examples of org.metawidget.statically.javacode.StaticJavaStub

      // Suppress

      if (TRUE.equals(attributes.get(HIDDEN)))
      {
         return new StaticJavaStub();
      }

      Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, null);
      String name = attributes.get(NAME);

      // String

      if (String.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement("String " + name + " = this.example.get" + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null && !\"\".equals(" + name + "))");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.like(builder.lower(root.<String>get(\"" + name + "\")), '%' + " + name
                           + ".toLowerCase() + '%'))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // int or short
      if (int.class.equals(clazz) || short.class.equals(clazz) || byte.class.equals(clazz) || long.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement(clazz.getSimpleName() + " " + name + " = this.example.get"
                           + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != 0)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      if (Integer.class.equals(clazz) || Short.class.equals(clazz) || Byte.class.equals(clazz)
               || Long.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement(clazz.getSimpleName() + " " + name + " = this.example.get"
                           + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null && "+name+".intValue() != 0)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // LOOKUP

      String type = attributes.get(TYPE);

      if (attributes.containsKey(LOOKUP))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name + " = this.example.get"
                  + StringUtils.capitalize(name) + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // FACES_LOOKUP

      if (attributes.containsKey(FACES_LOOKUP))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name + " = this.example.get"
                  + StringUtils.capitalize(name) + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // We tried searching against N_TO_MANY relationships, but had the following problems:
      //
      // 1. Difficult to make JPA Criteria Builder search for 'a Set having all of the following items'. For 'a Set
      // having the following item' can do: predicatesList.add(root.join("customers").in(this.example.getCustomer()));
      // 2. Cumbersome to have a new class for this.example that only has a single Customer, as opposed to a Set
      // 3. Difficult to make JSF's h:selectOne* bind to a Set
      // 4. Difficult to make JSF's h:selectMany* appear as a single item dropdown
      //
      // So we've left it out for now

      return new StaticJavaStub();
   }
View Full Code Here

Examples of org.metawidget.statically.javacode.StaticJavaStub

      String inverseField = attributes.get(INVERSE_FIELD);

      String capitalizedName = StringUtils.capitalize(name);
      if (oneToOne && ownerField != null && inverseField != null)
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name
                  + " = deletableEntity.get"
                  + capitalizedName + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         String fieldToNullify = name.equals(ownerField) ? inverseField : ownerField;
         JavaStatement removeRelationship = new JavaStatement(name + ".set"
                  + StringUtils.capitalize(fieldToNullify)
                  + "(null)");
         toReturn.getChildren().add(removeRelationship);
         JavaStatement mergeModification = new JavaStatement("this.entityManager.merge(" + name + ")");
         toReturn.getChildren().add(mergeModification);
         return toReturn;
      }
      else if (manyToOne && inverseField != null)
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name
                  + " = deletableEntity.get"
                  + capitalizedName + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         JavaStatement removeInverse = new JavaStatement(name + ".get"
                  + StringUtils.capitalize(inverseField)
                  + "().remove(deletableEntity)");
         toReturn.getChildren().add(removeInverse);
         JavaStatement nullOwner = new JavaStatement("deletableEntity.set" + capitalizedName + "(null)");
         toReturn.getChildren().add(nullOwner);
         JavaStatement mergeModification = new JavaStatement("this.entityManager.merge(" + name + ")");
         toReturn.getChildren().add(mergeModification);
         return toReturn;
      }
      else if (oneToMany && ownerField != null)
      {
         if (type.equals(Collection.class.getName()) || type.equals(Set.class.getName())
                  || type.equals(List.class.getName()))
         {
            String parameterizedType = attributes.get(PARAMETERIZED_TYPE);
            String simpleParameterizedType = ClassUtils.getSimpleName(parameterizedType);

            StaticJavaStub toReturn = new StaticJavaStub();
            JavaStatement iterator = new JavaStatement("Iterator<" + simpleParameterizedType + "> iter"
                     + capitalizedName + " = deletableEntity.get"
                     + capitalizedName + "().iterator()");
            iterator.putImport(Iterator.class.getName());
            iterator.putImport(parameterizedType);
            toReturn.getChildren().add(iterator);

            JavaStatement collectionModifiers = new JavaStatement("for (; iter" + capitalizedName + ".hasNext() ;) ");

            String scopedVariable = "nextIn" + capitalizedName;
            JavaStatement iterable = new JavaStatement(simpleParameterizedType + " " + scopedVariable
                     + " = iter" + capitalizedName + ".next()");
            collectionModifiers.getChildren().add(iterable);

            JavaStatement nullOwner = new JavaStatement(scopedVariable + ".set"
                     + StringUtils.capitalize(ownerField)
                     + "(null)");
            collectionModifiers.getChildren().add(nullOwner);

            JavaStatement removeInverse = new JavaStatement("iter" + capitalizedName + ".remove()");
            collectionModifiers.getChildren().add(removeInverse);

            JavaStatement mergeModification = new JavaStatement("this.entityManager.merge(" + scopedVariable + ")");
            collectionModifiers.getChildren().add(mergeModification);

            toReturn.getChildren().add(collectionModifiers);
            return toReturn;
         }
      }
      else if (manyToMany && ownerField != null && inverseField != null)
      {
         if (type.equals(Collection.class.getName()) || type.equals(Set.class.getName())
                  || type.equals(List.class.getName()))
         {
            String parameterizedType = attributes.get(PARAMETERIZED_TYPE);
            String simpleParameterizedType = ClassUtils.getSimpleName(parameterizedType);

            StaticJavaStub toReturn = new StaticJavaStub();
            JavaStatement iterator = new JavaStatement("Iterator<" + simpleParameterizedType + "> iter"
                     + capitalizedName + " = deletableEntity.get"
                     + capitalizedName + "().iterator()");
            iterator.putImport(Iterator.class.getName());
            iterator.putImport(parameterizedType);
            toReturn.getChildren().add(iterator);

            JavaStatement collectionModifiers = new JavaStatement("for (; iter" + capitalizedName + ".hasNext() ;) ");

            String scopedVariable = "nextIn" + capitalizedName;
            JavaStatement iterable = new JavaStatement(simpleParameterizedType + " " + scopedVariable
                     + " = iter" + capitalizedName + ".next()");
            collectionModifiers.getChildren().add(iterable);

            String collectionToModify = name.equals(ownerField) ? inverseField : ownerField;
            JavaStatement removeOtherMember = new JavaStatement(scopedVariable + ".get"
                     + StringUtils.capitalize(collectionToModify)
                     + "().remove(deletableEntity)");
            collectionModifiers.getChildren().add(removeOtherMember);

            JavaStatement removeInverse = new JavaStatement("iter" + capitalizedName + ".remove()");
            collectionModifiers.getChildren().add(removeInverse);

            JavaStatement mergeModification = new JavaStatement("this.entityManager.merge(" + scopedVariable + ")");
            collectionModifiers.getChildren().add(mergeModification);

            toReturn.getChildren().add(collectionModifiers);
            return toReturn;
         }
      }
      return new StaticJavaStub();
   }
View Full Code Here

Examples of org.metawidget.statically.javacode.StaticJavaStub

      // Suppress

      if (TRUE.equals(attributes.get(HIDDEN)))
      {
         return new StaticJavaStub();
      }

      Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, null);
      String name = attributes.get(NAME);

      // String

      if (String.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement("String " + name + " = this.example.get" + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null && !\"\".equals(" + name + "))");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.like(root.<String>get(\"" + name + "\"), '%' + " + name
                           + " + '%'))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // int or short

      if (int.class.equals(clazz) || short.class.equals(clazz) || byte.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement(clazz.getSimpleName() + " " + name + " = this.example.get"
                           + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != 0)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // LOOKUP

      String type = attributes.get(TYPE);

      if (attributes.containsKey(LOOKUP))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name + " = this.example.get"
                  + StringUtils.capitalize(name) + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // FACES_LOOKUP

      if (attributes.containsKey(FACES_LOOKUP))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name + " = this.example.get"
                  + StringUtils.capitalize(name) + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // We tried searching against N_TO_MANY relationships, but had the following problems:
      //
      // 1. Difficult to make JPA Criteria Builder search for 'a Set having all of the following items'. For 'a Set
      // having the following item' can do: predicatesList.add(root.join("customers").in(this.example.getCustomer()));
      // 2. Cumbersome to have a new class for this.example that only has a single Customer, as opposed to a Set
      // 3. Difficult to make JSF's h:selectOne* bind to a Set
      // 4. Difficult to make JSF's h:selectMany* appear as a single item dropdown
      //
      // So we've left it out for now

      return new StaticJavaStub();
   }
View Full Code Here

Examples of org.metawidget.statically.javacode.StaticJavaStub

      // Suppress

      if (TRUE.equals(attributes.get(HIDDEN)))
      {
         return new StaticJavaStub();
      }

      Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, null);
      String name = attributes.get(NAME);

      // String

      if (String.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement("String " + name + " = this.example.get" + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null && !\"\".equals(" + name + "))");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.like(root.<String>get(\"" + name + "\"), '%' + " + name
                           + " + '%'))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // int or short
      if (int.class.equals(clazz) || short.class.equals(clazz) || byte.class.equals(clazz) || long.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement(clazz.getSimpleName() + " " + name + " = this.example.get"
                           + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != 0)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      if (Integer.class.equals(clazz) || Short.class.equals(clazz) || Byte.class.equals(clazz)
               || Long.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement(clazz.getSimpleName() + " " + name + " = this.example.get"
                           + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null && "+name+".intValue() != 0)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // LOOKUP

      String type = attributes.get(TYPE);

      if (attributes.containsKey(LOOKUP))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name + " = this.example.get"
                  + StringUtils.capitalize(name) + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // FACES_LOOKUP

      if (attributes.containsKey(FACES_LOOKUP))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name + " = this.example.get"
                  + StringUtils.capitalize(name) + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // We tried searching against N_TO_MANY relationships, but had the following problems:
      //
      // 1. Difficult to make JPA Criteria Builder search for 'a Set having all of the following items'. For 'a Set
      // having the following item' can do: predicatesList.add(root.join("customers").in(this.example.getCustomer()));
      // 2. Cumbersome to have a new class for this.example that only has a single Customer, as opposed to a Set
      // 3. Difficult to make JSF's h:selectOne* bind to a Set
      // 4. Difficult to make JSF's h:selectMany* appear as a single item dropdown
      //
      // So we've left it out for now

      return new StaticJavaStub();
   }
View Full Code Here

Examples of org.metawidget.statically.javacode.StaticJavaStub

      // Suppress

      if (TRUE.equals(attributes.get(HIDDEN)))
      {
         return new StaticJavaStub();
      }

      String type = WidgetBuilderUtils.getActualClassOrType(attributes);
      Class<?> clazz = ClassUtils.niceForName(type);
      String name = attributes.get(NAME);

      // String

      if (String.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement("String " + name + " = this.search.get" + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null && !\"\".equals(" + name + "))");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.like(root.<String>get(\"" + name + "\"), '%' + " + name
                           + " + '%'))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // int

      if (int.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement("int " + name + " = this.search.get" + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != 0)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\")," + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // Lookup

      if (attributes.containsKey(FACES_LOOKUP))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name + " = this.search.get"
                  + StringUtils.capitalize(name) + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null && " + name + ".getId() != null)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\")," + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // We tried searching against N_TO_MANY relationships, but had the following problems:
      //
      // 1. Difficult to make JPA Criteria Builder search for 'a Set having all of the following items'. For 'a Set
      // having the following item' can do: predicatesList.add(root.join("customers").in(this.search.getCustomer()));
      // 2. Cumbersome to have a new class for this.search that only has a single Customer, as opposed to a Set
      // 3. Difficult to make JSF's h:selectOne* bind to a Set
      // 4. Difficult to make JSF's h:selectMany* appear as a single item dropdown
      //
      // So we've left it out for now

      return new StaticJavaStub();
   }
View Full Code Here

Examples of org.metawidget.statically.javacode.StaticJavaStub

      // Suppress

      if (TRUE.equals(attributes.get(HIDDEN)))
      {
         return new StaticJavaStub();
      }

      Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, null);
      String name = attributes.get(NAME);

      // String

      if (String.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement("String " + name + " = this.search.get" + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null && !\"\".equals(" + name + "))");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.like(root.<String>get(\"" + name + "\"), '%' + " + name
                           + " + '%'))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // int or short

      if (int.class.equals(clazz) || short.class.equals(clazz) || byte.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement(clazz.getSimpleName() + " " + name + " = this.search.get"
                           + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != 0)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // LOOKUP

      String type = attributes.get(TYPE);

      if (attributes.containsKey(LOOKUP))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name + " = this.search.get"
                  + StringUtils.capitalize(name) + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // FACES_LOOKUP

      if (attributes.containsKey(FACES_LOOKUP))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name + " = this.search.get"
                  + StringUtils.capitalize(name) + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // We tried searching against N_TO_MANY relationships, but had the following problems:
      //
      // 1. Difficult to make JPA Criteria Builder search for 'a Set having all of the following items'. For 'a Set
      // having the following item' can do: predicatesList.add(root.join("customers").in(this.search.getCustomer()));
      // 2. Cumbersome to have a new class for this.search that only has a single Customer, as opposed to a Set
      // 3. Difficult to make JSF's h:selectOne* bind to a Set
      // 4. Difficult to make JSF's h:selectMany* appear as a single item dropdown
      //
      // So we've left it out for now

      return new StaticJavaStub();
   }
View Full Code Here

Examples of org.metawidget.statically.javacode.StaticJavaStub

      // Suppress

      if (TRUE.equals(attributes.get(HIDDEN)) && !Boolean.valueOf(attributes.get(PRIMARY_KEY_NOT_GENERATED)))
      {
         return new StaticJavaStub();
      }

      String type = WidgetBuilderUtils.getActualClassOrType(attributes);
      Class<?> clazz = ClassUtils.niceForName(type);
      String name = attributes.get(NAME);

      // String

      if (String.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement("String " + name + " = this.search.get" + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null && !\"\".equals(" + name + "))");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.like(root.<String>get(\"" + name + "\"), '%' + " + name
                           + " + '%'))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // int or short

      if (int.class.equals(clazz) || short.class.equals(clazz) || byte.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement(clazz.getSimpleName() + " " + name + " = this.search.get" + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != 0)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // LOOKUP

      if (attributes.containsKey(LOOKUP))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name + " = this.search.get"
                  + StringUtils.capitalize(name) + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // FACES_LOOKUP

      if (attributes.containsKey(FACES_LOOKUP))
      {
          String reverseKey = "Id";
          if (attributes.containsKey(REVERSE_PRIMARY_KEY))
              reverseKey = StringUtils.capitalize(attributes.get(REVERSE_PRIMARY_KEY));

          StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name + " = this.search.get"
                  + StringUtils.capitalize(name) + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // We tried searching against N_TO_MANY relationships, but had the following problems:
      //
      // 1. Difficult to make JPA Criteria Builder search for 'a Set having all of the following items'. For 'a Set
      // having the following item' can do: predicatesList.add(root.join("customers").in(this.search.getCustomer()));
      // 2. Cumbersome to have a new class for this.search that only has a single Customer, as opposed to a Set
      // 3. Difficult to make JSF's h:selectOne* bind to a Set
      // 4. Difficult to make JSF's h:selectMany* appear as a single item dropdown
      //
      // So we've left it out for now

      return new StaticJavaStub();
   }
View Full Code Here

Examples of org.metawidget.statically.javacode.StaticJavaStub

      String inverseField = attributes.get(INVERSE_FIELD);

      String capitalizedName = StringUtils.capitalize(name);
      if (oneToOne && ownerField != null && inverseField != null)
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name
                  + " = deletableEntity.get"
                  + capitalizedName + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         String fieldToNullify = name.equals(ownerField) ? inverseField : ownerField;
         JavaStatement removeRelationship = new JavaStatement(name + ".set"
                  + StringUtils.capitalize(fieldToNullify)
                  + "(null)");
         toReturn.getChildren().add(removeRelationship);
         JavaStatement mergeModification = new JavaStatement("this.entityManager.merge(" + name + ")");
         toReturn.getChildren().add(mergeModification);
         return toReturn;
      }
      else if (manyToOne && inverseField != null)
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name
                  + " = deletableEntity.get"
                  + capitalizedName + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         JavaStatement removeInverse = new JavaStatement(name + ".get"
                  + StringUtils.capitalize(inverseField)
                  + "().remove(deletableEntity)");
         toReturn.getChildren().add(removeInverse);
         JavaStatement nullOwner = new JavaStatement("deletableEntity.set" + capitalizedName + "(null)");
         toReturn.getChildren().add(nullOwner);
         JavaStatement mergeModification = new JavaStatement("this.entityManager.merge(" + name + ")");
         toReturn.getChildren().add(mergeModification);
         return toReturn;
      }
      else if (oneToMany && ownerField != null)
      {
         if (type.equals(Collection.class.getName()) || type.equals(Set.class.getName())
                  || type.equals(List.class.getName()))
         {
            String parameterizedType = attributes.get(PARAMETERIZED_TYPE);
            String simpleParameterizedType = ClassUtils.getSimpleName(parameterizedType);

            StaticJavaStub toReturn = new StaticJavaStub();
            JavaStatement iterator = new JavaStatement("Iterator<" + simpleParameterizedType + "> iter"
                     + capitalizedName + " = deletableEntity.get"
                     + capitalizedName + "().iterator()");
            iterator.putImport(Iterator.class.getName());
            iterator.putImport(parameterizedType);
            toReturn.getChildren().add(iterator);

            JavaStatement collectionModifiers = new JavaStatement("for (; iter" + capitalizedName + ".hasNext() ;) ");

            String scopedVariable = "nextIn" + capitalizedName;
            JavaStatement iterable = new JavaStatement(simpleParameterizedType + " " + scopedVariable
                     + " = iter" + capitalizedName + ".next()");
            collectionModifiers.getChildren().add(iterable);

            JavaStatement nullOwner = new JavaStatement(scopedVariable + ".set"
                     + StringUtils.capitalize(ownerField)
                     + "(null)");
            collectionModifiers.getChildren().add(nullOwner);

            JavaStatement removeInverse = new JavaStatement("iter" + capitalizedName + ".remove()");
            collectionModifiers.getChildren().add(removeInverse);

            JavaStatement mergeModification = new JavaStatement("this.entityManager.merge(" + scopedVariable + ")");
            collectionModifiers.getChildren().add(mergeModification);

            toReturn.getChildren().add(collectionModifiers);
            return toReturn;
         }
      }
      else if (manyToMany && ownerField != null && inverseField != null)
      {
         if (type.equals(Collection.class.getName()) || type.equals(Set.class.getName())
                  || type.equals(List.class.getName()))
         {
            String parameterizedType = attributes.get(PARAMETERIZED_TYPE);
            String simpleParameterizedType = ClassUtils.getSimpleName(parameterizedType);

            StaticJavaStub toReturn = new StaticJavaStub();
            JavaStatement iterator = new JavaStatement("Iterator<" + simpleParameterizedType + "> iter"
                     + capitalizedName + " = deletableEntity.get"
                     + capitalizedName + "().iterator()");
            iterator.putImport(Iterator.class.getName());
            iterator.putImport(parameterizedType);
            toReturn.getChildren().add(iterator);

            JavaStatement collectionModifiers = new JavaStatement("for (; iter" + capitalizedName + ".hasNext() ;) ");

            String scopedVariable = "nextIn" + capitalizedName;
            JavaStatement iterable = new JavaStatement(simpleParameterizedType + " " + scopedVariable
                     + " = iter" + capitalizedName + ".next()");
            collectionModifiers.getChildren().add(iterable);

            String collectionToModify = name.equals(ownerField) ? inverseField : ownerField;
            JavaStatement removeOtherMember = new JavaStatement(scopedVariable + ".get"
                     + StringUtils.capitalize(collectionToModify)
                     + "().remove(deletableEntity)");
            collectionModifiers.getChildren().add(removeOtherMember);

            JavaStatement removeInverse = new JavaStatement("iter" + capitalizedName + ".remove()");
            collectionModifiers.getChildren().add(removeInverse);

            JavaStatement mergeModification = new JavaStatement("this.entityManager.merge(" + scopedVariable + ")");
            collectionModifiers.getChildren().add(mergeModification);

            toReturn.getChildren().add(collectionModifiers);
            return toReturn;
         }
      }
      return new StaticJavaStub();
   }
View Full Code Here

Examples of org.metawidget.statically.javacode.StaticJavaStub

      // Suppress

      if (TRUE.equals(attributes.get(HIDDEN)))
      {
         return new StaticJavaStub();
      }

      Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, null);
      String name = attributes.get(NAME);

      // String

      if (String.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement("String " + name + " = this.example.get" + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null && !\"\".equals(" + name + "))");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.like(root.<String>get(\"" + name + "\"), '%' + " + name
                           + " + '%'))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // int or short

      if (int.class.equals(clazz) || short.class.equals(clazz) || byte.class.equals(clazz) || long.class.equals(clazz)
               || Integer.class.equals(clazz) || Short.class.equals(clazz) || Byte.class.equals(clazz)
               || Long.class.equals(clazz))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         toReturn.getChildren().add(
                  new JavaStatement(clazz.getSimpleName() + " " + name + " = this.example.get"
                           + StringUtils.capitalize(name) + "()"));
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != 0)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // LOOKUP

      String type = attributes.get(TYPE);

      if (attributes.containsKey(LOOKUP))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name + " = this.example.get"
                  + StringUtils.capitalize(name) + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // FACES_LOOKUP

      if (attributes.containsKey(FACES_LOOKUP))
      {
         StaticJavaStub toReturn = new StaticJavaStub();
         JavaStatement getValue = new JavaStatement(ClassUtils.getSimpleName(type) + " " + name + " = this.example.get"
                  + StringUtils.capitalize(name) + "()");
         getValue.putImport(type);
         toReturn.getChildren().add(getValue);
         JavaStatement ifNotEmpty = new JavaStatement("if (" + name + " != null)");
         ifNotEmpty.getChildren().add(
                  new JavaStatement("predicatesList.add(builder.equal(root.get(\"" + name + "\"), " + name + "))"));
         toReturn.getChildren().add(ifNotEmpty);
         return toReturn;
      }

      // We tried searching against N_TO_MANY relationships, but had the following problems:
      //
      // 1. Difficult to make JPA Criteria Builder search for 'a Set having all of the following items'. For 'a Set
      // having the following item' can do: predicatesList.add(root.join("customers").in(this.example.getCustomer()));
      // 2. Cumbersome to have a new class for this.example that only has a single Customer, as opposed to a Set
      // 3. Difficult to make JSF's h:selectOne* bind to a Set
      // 4. Difficult to make JSF's h:selectMany* appear as a single item dropdown
      //
      // So we've left it out for now

      return new StaticJavaStub();
   }
View Full Code Here
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.