예제 #1
0
 public String getCollectionRenderer() {
   JavaType arg = OBJECT;
   if (type.getParameters().size() > 0) {
     arg = type.getParameters().get(0);
   }
   return GwtPath.SCAFFOLD_PLACE.packageName(topLevelPackage)
       + ".CollectionRenderer.of("
       + new GwtProxyProperty(topLevelPackage, ptmd, arg).getRenderer()
       + ")";
 }
예제 #2
0
 private String getSetEditor() {
   String typeName = OBJECT.getFullyQualifiedTypeName();
   if (type.getParameters().size() > 0) {
     typeName = type.getParameters().get(0).getSimpleTypeName();
   }
   if (typeName.endsWith(GwtType.PROXY.getSuffix())) {
     typeName = typeName.substring(0, typeName.length() - GwtType.PROXY.getSuffix().length());
   }
   return typeName
       + (type.getSimpleTypeName().equals("Set")
           ? GwtType.SET_EDITOR.getSuffix()
           : GwtType.LIST_EDITOR.getSuffix());
 }
 private JavaType getCollectionImplementation(final JavaType javaType) {
   if (isSameBaseType(javaType, SET)) {
     return new JavaType(
         HASH_SET.getFullyQualifiedTypeName(),
         javaType.getArray(),
         javaType.getDataType(),
         javaType.getArgName(),
         javaType.getParameters());
   }
   if (isSameBaseType(javaType, LIST)) {
     return new JavaType(
         ARRAY_LIST.getFullyQualifiedTypeName(),
         javaType.getArray(),
         javaType.getDataType(),
         javaType.getArgName(),
         javaType.getParameters());
   }
   return javaType;
 }
예제 #4
0
 public String getSetValuePickerMethod() {
   return "\tpublic void "
       + getSetValuePickerMethodName()
       + "(Collection<"
       + (isCollection()
           ? type.getParameters().get(0).getSimpleTypeName()
           : type.getSimpleTypeName())
       + "> values) {\n"
       + "\t\t"
       + getName()
       + ".setAcceptableValues(values);\n"
       + "\t}\n";
 }
  public Set<JavaType> getPersistentFieldTypes(
      final JavaType thisType, final PersistenceMemberLocator persistenceMemberLocator) {
    final MethodMetadata identifierAccessor =
        persistenceMemberLocator.getIdentifierAccessor(thisType);
    final MethodMetadata versionAccessor = persistenceMemberLocator.getVersionAccessor(thisType);

    final Set<JavaType> fieldTypes = new LinkedHashSet<JavaType>();
    for (final MethodMetadata method : getMethods()) {
      // Not interested in non-accessor methods or persistence identifiers
      // and version fields
      if (!BeanInfoUtils.isAccessorMethod(method)
          || method.hasSameName(identifierAccessor, versionAccessor)) {
        continue;
      }

      // Not interested in fields that are JPA transient fields or
      // immutable fields
      final FieldMetadata field = BeanInfoUtils.getFieldForJavaBeanMethod(this, method);
      if (field == null
          || field.getCustomData().keySet().contains(CustomDataKeys.TRANSIENT_FIELD)
          || !BeanInfoUtils.hasAccessorAndMutator(field, this)) {
        continue;
      }
      final JavaType returnType = method.getReturnType();
      if (returnType.isCommonCollectionType()) {
        for (final JavaType genericType : returnType.getParameters()) {
          fieldTypes.add(genericType);
        }
      } else {
        if (!field.getCustomData().keySet().contains(EMBEDDED_FIELD)) {
          fieldTypes.add(returnType);
        }
      }
    }
    return fieldTypes;
  }
 private void addImport(final TemplateDataDictionary dataDictionary, final JavaType type) {
   dataDictionary.addSection("imports").setVariable("import", type.getFullyQualifiedTypeName());
   for (final JavaType param : type.getParameters()) {
     addImport(dataDictionary, param.getFullyQualifiedTypeName());
   }
 }
예제 #7
0
 public JavaType getValueType() {
   if (isCollection()) {
     return type.getParameters().get(0);
   }
   return type;
 }
예제 #8
0
 public boolean isCollectionOfProxy() {
   return type.getParameters().size() != 0
       && isCollection()
       && new GwtProxyProperty(topLevelPackage, ptmd, type.getParameters().get(0)).isProxy();
 }
예제 #9
0
 String getProxyRendererType() {
   return getProxyRendererType(
       topLevelPackage, isCollectionOfProxy() ? type.getParameters().get(0) : type);
 }
예제 #10
0
  private MethodMetadataBuilder getFinderFormMethod(final FinderMetadataDetails finder) {
    Validate.notNull(finder, "Method metadata required for finder");
    final JavaSymbolName finderFormMethodName =
        new JavaSymbolName(
            finder.getFinderMethodMetadata().getMethodName().getSymbolName() + "Form");

    final List<JavaType> methodParameterTypes = new ArrayList<JavaType>();
    final List<JavaSymbolName> methodParameterNames = new ArrayList<JavaSymbolName>();
    final List<JavaType> finderParameterTypes =
        AnnotatedJavaType.convertFromAnnotatedJavaTypes(
            finder.getFinderMethodMetadata().getParameterTypes());

    final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();

    boolean needModel = false;
    for (final JavaType finderParameterType : finderParameterTypes) {
      JavaTypeMetadataDetails typeMd = specialDomainTypes.get(finderParameterType);
      JavaTypePersistenceMetadataDetails javaTypePersistenceMetadataHolder = null;
      if (finderParameterType.isCommonCollectionType()) {
        typeMd = specialDomainTypes.get(finderParameterType.getParameters().get(0));
        if (typeMd != null && typeMd.isApplicationType()) {
          javaTypePersistenceMetadataHolder = typeMd.getPersistenceDetails();
        }
      } else if (typeMd != null && typeMd.isEnumType()) {
        bodyBuilder.appendFormalLine(
            "uiModel.addAttribute(\""
                + typeMd.getPlural().toLowerCase()
                + "\", java.util.Arrays.asList("
                + getShortName(finderParameterType)
                + ".class.getEnumConstants()));");
      } else if (typeMd != null && typeMd.isApplicationType()) {
        javaTypePersistenceMetadataHolder = typeMd.getPersistenceDetails();
      }
      if (typeMd != null
          && javaTypePersistenceMetadataHolder != null
          && javaTypePersistenceMetadataHolder.getFindAllMethod() != null) {
        bodyBuilder.appendFormalLine(
            "uiModel.addAttribute(\""
                + typeMd.getPlural().toLowerCase()
                + "\", "
                + javaTypePersistenceMetadataHolder.getFindAllMethod().getMethodCall()
                + ");");
      }
      needModel = true;
    }
    if (finderParameterTypes.contains(DATE) || finderParameterTypes.contains(CALENDAR)) {
      bodyBuilder.appendFormalLine("addDateTimeFormatPatterns(uiModel);");
    }
    bodyBuilder.appendFormalLine(
        "return \""
            + controllerPath
            + "/"
            + finder.getFinderMethodMetadata().getMethodName().getSymbolName()
            + "\";");

    if (needModel) {
      methodParameterTypes.add(MODEL);
      methodParameterNames.add(new JavaSymbolName("uiModel"));
    }

    if (governorHasMethod(finderFormMethodName, methodParameterTypes)) {
      return null;
    }

    final List<AnnotationAttributeValue<?>> requestMappingAttributes =
        new ArrayList<AnnotationAttributeValue<?>>();
    final List<StringAttributeValue> arrayValues = new ArrayList<StringAttributeValue>();
    arrayValues.add(
        new StringAttributeValue(
            new JavaSymbolName("value"),
            "find="
                + finder
                    .getFinderMethodMetadata()
                    .getMethodName()
                    .getSymbolName()
                    .replaceFirst("find" + javaTypeMetadataHolder.getPlural(), "")));
    arrayValues.add(new StringAttributeValue(new JavaSymbolName("value"), "form"));
    requestMappingAttributes.add(
        new ArrayAttributeValue<StringAttributeValue>(new JavaSymbolName("params"), arrayValues));
    requestMappingAttributes.add(
        new EnumAttributeValue(
            new JavaSymbolName("method"),
            new EnumDetails(REQUEST_METHOD, new JavaSymbolName("GET"))));
    final AnnotationMetadataBuilder requestMapping =
        new AnnotationMetadataBuilder(REQUEST_MAPPING, requestMappingAttributes);
    final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    annotations.add(requestMapping);

    final MethodMetadataBuilder methodBuilder =
        new MethodMetadataBuilder(
            getId(),
            Modifier.PUBLIC,
            finderFormMethodName,
            JavaType.STRING,
            AnnotatedJavaType.convertFromJavaTypes(methodParameterTypes),
            methodParameterNames,
            bodyBuilder);
    methodBuilder.setAnnotations(annotations);
    return methodBuilder;
  }