Ejemplo n.º 1
0
  private boolean isReadOnly(
      final String name, final ClassOrInterfaceTypeDetails governorTypeDetails) {
    List<String> readOnly = new ArrayList<String>();
    ClassOrInterfaceTypeDetails proxy = gwtTypeService.lookupProxyFromEntity(governorTypeDetails);
    if (proxy != null) {
      readOnly.addAll(GwtUtils.getAnnotationValues(proxy, RooJavaType.ROO_GWT_PROXY, "readOnly"));
    }

    return readOnly.contains(name);
  }
 private MethodMetadataBuilder getIdMethod(
     String declaredById, JavaType targetType, MethodMetadata idAccessor) {
   InvocableMemberBodyBuilder invocableMemberBodyBuilder =
       InvocableMemberBodyBuilder.getInstance();
   invocableMemberBodyBuilder.append(
       "return "
           + StringUtils.uncapitalize(targetType.getSimpleTypeName())
           + "."
           + idAccessor.getMethodName()
           + "();");
   MethodMetadataBuilder getIdMethod =
       new MethodMetadataBuilder(
           declaredById,
           Modifier.PUBLIC,
           new JavaSymbolName("getId"),
           GwtUtils.convertPrimitiveType(idAccessor.getReturnType(), true),
           invocableMemberBodyBuilder);
   getIdMethod.addParameter(StringUtils.uncapitalize(targetType.getSimpleTypeName()), targetType);
   return getIdMethod;
 }
  public GwtTemplateDataHolder getMirrorTemplateTypeDetails(
      final ClassOrInterfaceTypeDetails mirroredType,
      final Map<JavaSymbolName, GwtProxyProperty> clientSideTypeMap,
      final String moduleName) {
    final ClassOrInterfaceTypeDetails proxy = gwtTypeService.lookupProxyFromEntity(mirroredType);
    final ClassOrInterfaceTypeDetails request =
        gwtTypeService.lookupRequestFromEntity(mirroredType);
    final JavaPackage topLevelPackage = projectOperations.getTopLevelPackage(moduleName);
    final Map<GwtType, JavaType> mirrorTypeMap =
        GwtUtils.getMirrorTypeMap(mirroredType.getName(), topLevelPackage);
    mirrorTypeMap.put(GwtType.PROXY, proxy.getName());
    mirrorTypeMap.put(GwtType.REQUEST, request.getName());

    final Map<GwtType, ClassOrInterfaceTypeDetails> templateTypeDetailsMap =
        new LinkedHashMap<GwtType, ClassOrInterfaceTypeDetails>();
    final Map<GwtType, String> xmlTemplates = new LinkedHashMap<GwtType, String>();
    for (final GwtType gwtType : GwtType.getMirrorTypes()) {
      if (gwtType.getTemplate() == null) {
        continue;
      }
      TemplateDataDictionary dataDictionary =
          buildMirrorDataDictionary(
              gwtType, mirroredType, proxy, mirrorTypeMap, clientSideTypeMap, moduleName);
      gwtType.dynamicallyResolveFieldsToWatch(clientSideTypeMap);
      gwtType.dynamicallyResolveMethodsToWatch(
          mirroredType.getName(), clientSideTypeMap, topLevelPackage);
      templateTypeDetailsMap.put(
          gwtType,
          getTemplateDetails(
              dataDictionary, gwtType.getTemplate(), mirrorTypeMap.get(gwtType), moduleName));

      if (gwtType.isCreateUiXml()) {
        dataDictionary =
            buildMirrorDataDictionary(
                gwtType, mirroredType, proxy, mirrorTypeMap, clientSideTypeMap, moduleName);
        final String contents =
            getTemplateContents(gwtType.getTemplate() + "UiXml", dataDictionary);
        xmlTemplates.put(gwtType, contents);
      }
    }

    final Map<String, String> xmlMap = new LinkedHashMap<String, String>();
    final List<ClassOrInterfaceTypeDetails> typeDetails =
        new ArrayList<ClassOrInterfaceTypeDetails>();
    for (final GwtProxyProperty proxyProperty : clientSideTypeMap.values()) {
      if (!proxyProperty.isCollection() || proxyProperty.isCollectionOfProxy()) {
        continue;
      }

      TemplateDataDictionary dataDictionary = TemplateDictionary.create();
      dataDictionary.setVariable("packageName", GwtPath.MANAGED_UI.packageName(topLevelPackage));
      dataDictionary.setVariable(
          "scaffoldUiPackage", GwtPath.SCAFFOLD_UI.packageName(topLevelPackage));
      final JavaType collectionTypeImpl =
          getCollectionImplementation(proxyProperty.getPropertyType());
      addImport(dataDictionary, collectionTypeImpl);
      addImport(dataDictionary, proxyProperty.getPropertyType());

      final String collectionType = proxyProperty.getPropertyType().getSimpleTypeName();
      final String boundCollectionType =
          proxyProperty.getPropertyType().getParameters().get(0).getSimpleTypeName();

      dataDictionary.setVariable("collectionType", collectionType);
      dataDictionary.setVariable("collectionTypeImpl", collectionTypeImpl.getSimpleTypeName());
      dataDictionary.setVariable("boundCollectionType", boundCollectionType);

      final JavaType collectionEditorType =
          new JavaType(
              GwtPath.MANAGED_UI.packageName(topLevelPackage)
                  + "."
                  + boundCollectionType
                  + collectionType
                  + "Editor");
      typeDetails.add(
          getTemplateDetails(dataDictionary, "CollectionEditor", collectionEditorType, moduleName));

      dataDictionary = TemplateDictionary.create();
      dataDictionary.setVariable("packageName", GwtPath.MANAGED_UI.packageName(topLevelPackage));
      dataDictionary.setVariable(
          "scaffoldUiPackage", GwtPath.SCAFFOLD_UI.packageName(topLevelPackage));
      dataDictionary.setVariable("collectionType", collectionType);
      dataDictionary.setVariable("collectionTypeImpl", collectionTypeImpl.getSimpleTypeName());
      dataDictionary.setVariable("boundCollectionType", boundCollectionType);
      addImport(dataDictionary, proxyProperty.getPropertyType());

      final String contents = getTemplateContents("CollectionEditor" + "UiXml", dataDictionary);
      final String packagePath =
          projectOperations
              .getPathResolver()
              .getFocusedIdentifier(
                  Path.SRC_MAIN_JAVA, GwtPath.MANAGED_UI.getPackagePath(topLevelPackage));
      xmlMap.put(
          packagePath + "/" + boundCollectionType + collectionType + "Editor.ui.xml", contents);
    }

    return new GwtTemplateDataHolder(templateTypeDetailsMap, xmlTemplates, typeDetails, xmlMap);
  }
  private TemplateDataDictionary buildDictionary(final GwtType type, final String moduleName) {
    final Set<ClassOrInterfaceTypeDetails> proxies =
        typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_GWT_PROXY);
    final TemplateDataDictionary dataDictionary = buildStandardDataDictionary(type, moduleName);
    switch (type) {
      case APP_ENTITY_TYPES_PROCESSOR:
        for (final ClassOrInterfaceTypeDetails proxy : proxies) {
          if (!GwtUtils.scaffoldProxy(proxy)) {
            continue;
          }
          final String proxySimpleName = proxy.getName().getSimpleTypeName();
          final ClassOrInterfaceTypeDetails entity = gwtTypeService.lookupEntityFromProxy(proxy);
          if (entity != null) {
            final String entitySimpleName = entity.getName().getSimpleTypeName();

            dataDictionary.addSection("proxys").setVariable("proxy", proxySimpleName);

            final String entity1 =
                new StringBuilder("\t\tif (")
                    .append(proxySimpleName)
                    .append(".class.equals(clazz)) {\n\t\t\tprocessor.handle")
                    .append(entitySimpleName)
                    .append("((")
                    .append(proxySimpleName)
                    .append(") null);\n\t\t\treturn;\n\t\t}")
                    .toString();
            dataDictionary.addSection("entities1").setVariable("entity", entity1);

            final String entity2 =
                new StringBuilder("\t\tif (proxy instanceof ")
                    .append(proxySimpleName)
                    .append(") {\n\t\t\tprocessor.handle")
                    .append(entitySimpleName)
                    .append("((")
                    .append(proxySimpleName)
                    .append(") proxy);\n\t\t\treturn;\n\t\t}")
                    .toString();
            dataDictionary.addSection("entities2").setVariable("entity", entity2);

            final String entity3 =
                new StringBuilder("\tpublic abstract void handle")
                    .append(entitySimpleName)
                    .append("(")
                    .append(proxySimpleName)
                    .append(" proxy);")
                    .toString();
            dataDictionary.addSection("entities3").setVariable("entity", entity3);
            addImport(dataDictionary, proxy.getName().getFullyQualifiedTypeName());
          }
        }
        break;
      case MASTER_ACTIVITIES:
        for (final ClassOrInterfaceTypeDetails proxy : proxies) {
          if (!GwtUtils.scaffoldProxy(proxy)) {
            continue;
          }
          final String proxySimpleName = proxy.getName().getSimpleTypeName();
          final ClassOrInterfaceTypeDetails entity = gwtTypeService.lookupEntityFromProxy(proxy);
          if (entity != null && !Modifier.isAbstract(entity.getModifier())) {
            final String entitySimpleName = entity.getName().getSimpleTypeName();
            final TemplateDataDictionary section = dataDictionary.addSection("entities");
            section.setVariable("entitySimpleName", entitySimpleName);
            section.setVariable("entityFullPath", proxySimpleName);
            addImport(dataDictionary, entitySimpleName, GwtType.LIST_ACTIVITY, moduleName);
            addImport(dataDictionary, proxy.getName().getFullyQualifiedTypeName());
            addImport(dataDictionary, entitySimpleName, GwtType.LIST_VIEW, moduleName);
            addImport(dataDictionary, entitySimpleName, GwtType.MOBILE_LIST_VIEW, moduleName);
          }
        }
        break;
      case APP_REQUEST_FACTORY:
        for (final ClassOrInterfaceTypeDetails proxy : proxies) {
          if (!GwtUtils.scaffoldProxy(proxy)) {
            continue;
          }
          final ClassOrInterfaceTypeDetails entity = gwtTypeService.lookupEntityFromProxy(proxy);
          if (entity != null && !Modifier.isAbstract(entity.getModifier())) {
            final String entitySimpleName = entity.getName().getSimpleTypeName();
            final ClassOrInterfaceTypeDetails request =
                gwtTypeService.lookupRequestFromProxy(proxy);
            if (request != null) {
              final String requestExpression =
                  new StringBuilder("\t")
                      .append(request.getName().getSimpleTypeName())
                      .append(" ")
                      .append(StringUtils.uncapitalize(entitySimpleName))
                      .append("Request();")
                      .toString();
              dataDictionary.addSection("entities").setVariable("entity", requestExpression);
              addImport(dataDictionary, request.getName().getFullyQualifiedTypeName());
            }
          }
          dataDictionary.setVariable(
              "sharedScaffoldPackage",
              GwtPath.SHARED_SCAFFOLD.packageName(
                  projectOperations.getTopLevelPackage(moduleName)));
        }

        if (projectOperations.isFeatureInstalledInFocusedModule(FeatureNames.GAE)) {
          dataDictionary.showSection("gae");
        }
        break;
      case LIST_PLACE_RENDERER:
        for (final ClassOrInterfaceTypeDetails proxy : proxies) {
          if (!GwtUtils.scaffoldProxy(proxy)) {
            continue;
          }
          final ClassOrInterfaceTypeDetails entity = gwtTypeService.lookupEntityFromProxy(proxy);
          if (entity != null) {
            final String entitySimpleName = entity.getName().getSimpleTypeName();
            final String proxySimpleName = proxy.getName().getSimpleTypeName();
            final TemplateDataDictionary section = dataDictionary.addSection("entities");
            section.setVariable("entitySimpleName", entitySimpleName);
            section.setVariable("entityFullPath", proxySimpleName);
            addImport(dataDictionary, proxy.getName().getFullyQualifiedTypeName());
          }
        }
        break;
      case DETAILS_ACTIVITIES:
        for (final ClassOrInterfaceTypeDetails proxy : proxies) {
          if (!GwtUtils.scaffoldProxy(proxy)) {
            continue;
          }
          final ClassOrInterfaceTypeDetails entity = gwtTypeService.lookupEntityFromProxy(proxy);
          if (entity != null) {
            final String proxySimpleName = proxy.getName().getSimpleTypeName();
            final String entitySimpleName = entity.getName().getSimpleTypeName();
            final String entityExpression =
                new StringBuilder("\t\t\tpublic void handle")
                    .append(entitySimpleName)
                    .append("(")
                    .append(proxySimpleName)
                    .append(" proxy) {\n")
                    .append("\t\t\t\tsetResult(new ")
                    .append(entitySimpleName)
                    .append(
                        "ActivitiesMapper(requests, placeController).getActivity(proxyPlace));\n\t\t\t}")
                    .toString();
            dataDictionary.addSection("entities").setVariable("entity", entityExpression);
            addImport(dataDictionary, proxy.getName().getFullyQualifiedTypeName());
            addImport(
                dataDictionary,
                GwtType.ACTIVITIES_MAPPER
                        .getPath()
                        .packageName(projectOperations.getTopLevelPackage(moduleName))
                    + "."
                    + entitySimpleName
                    + GwtType.ACTIVITIES_MAPPER.getSuffix());
          }
        }
        break;
      case MOBILE_ACTIVITIES:
        // Do nothing
        break;
    }

    return dataDictionary;
  }
Ejemplo n.º 5
0
 public static boolean scaffoldProxy(final ClassOrInterfaceTypeDetails proxy) {
   return GwtUtils.getBooleanAnnotationValue(proxy, RooJavaType.ROO_GWT_PROXY, "scaffold", false);
 }
  public MetadataItem get(String metadataIdentificationString) {
    ProjectMetadata projectMetadata = projectOperations.getProjectMetadata();
    if (projectMetadata == null) {
      return null;
    }

    ClassOrInterfaceTypeDetails proxy = getGovernor(metadataIdentificationString);
    if (proxy == null) {
      return null;
    }

    AnnotationMetadata proxyAnnotation =
        GwtUtils.getFirstAnnotation(proxy, GwtUtils.PROXY_ANNOTATIONS);
    if (proxyAnnotation == null) {
      return null;
    }

    String locatorType = GwtUtils.getStringValue(proxyAnnotation.getAttribute("locator"));
    if (!StringUtils.hasText(locatorType)) {
      return null;
    }

    ClassOrInterfaceTypeDetails entity = gwtTypeService.lookupEntityFromProxy(proxy);
    if (entity == null) {
      return null;
    }

    MethodMetadata idAccessor = persistenceMemberLocator.getIdentifierAccessor(entity.getName());
    MethodMetadata versionAccessor = persistenceMemberLocator.getVersionAccessor(entity.getName());
    if (idAccessor == null || versionAccessor == null) {
      return null;
    }

    final JavaType idType = GwtUtils.convertPrimitiveType(idAccessor.getReturnType(), true);
    String locatorIdentifier = PhysicalTypeIdentifier.createIdentifier(new JavaType(locatorType));
    ClassOrInterfaceTypeDetailsBuilder locatorBuilder =
        new ClassOrInterfaceTypeDetailsBuilder(locatorIdentifier);
    AnnotationMetadataBuilder annotationMetadataBuilder =
        new AnnotationMetadataBuilder(RooJavaType.ROO_GWT_LOCATOR);
    annotationMetadataBuilder.addStringAttribute(
        "value", entity.getName().getFullyQualifiedTypeName());
    locatorBuilder.addAnnotation(annotationMetadataBuilder);
    annotationMetadataBuilder = new AnnotationMetadataBuilder(SpringJavaType.COMPONENT);
    locatorBuilder.addAnnotation(annotationMetadataBuilder);
    locatorBuilder.setName(new JavaType(locatorType));
    locatorBuilder.setModifier(Modifier.PUBLIC);
    locatorBuilder.setPhysicalTypeCategory(PhysicalTypeCategory.CLASS);
    locatorBuilder.addExtendsTypes(
        new JavaType(
            GwtUtils.LOCATOR.getFullyQualifiedTypeName(),
            0,
            DataType.TYPE,
            null,
            Arrays.asList(entity.getName(), idType)));
    locatorBuilder.addMethod(getCreateMethod(locatorIdentifier, entity.getName()));
    locatorBuilder.addMethod(
        getFindMethod(locatorBuilder, locatorIdentifier, entity.getName(), idType));
    locatorBuilder.addMethod(getDomainTypeMethod(locatorIdentifier, entity.getName()));
    locatorBuilder.addMethod(getIdMethod(locatorIdentifier, entity.getName(), idAccessor));
    locatorBuilder.addMethod(getIdTypeMethod(locatorIdentifier, entity.getName(), idType));
    locatorBuilder.addMethod(
        getVersionMethod(locatorIdentifier, entity.getName(), versionAccessor));

    typeManagementService.createOrUpdateTypeOnDisk(locatorBuilder.build());
    return null;
  }
  public void notify(String upstreamDependency, String downstreamDependency) {
    ProjectMetadata projectMetadata = projectOperations.getProjectMetadata();
    if (projectMetadata == null) {
      return;
    }

    if (MetadataIdentificationUtils.isIdentifyingClass(downstreamDependency)) {
      Assert.isTrue(
          MetadataIdentificationUtils.getMetadataClass(upstreamDependency)
              .equals(
                  MetadataIdentificationUtils.getMetadataClass(
                      PhysicalTypeIdentifier.getMetadataIdentiferType())),
          "Expected class-level notifications only for PhysicalTypeIdentifier (not '"
              + upstreamDependency
              + "')");

      ClassOrInterfaceTypeDetails cid =
          typeLocationService.getTypeForIdentifier(upstreamDependency);
      boolean processed = false;
      if (MemberFindingUtils.getAnnotationOfType(cid.getAnnotations(), RooJavaType.ROO_GWT_REQUEST)
          != null) {
        ClassOrInterfaceTypeDetails proxy = gwtTypeService.lookupProxyFromRequest(cid);
        if (proxy != null) {
          JavaType typeName = PhysicalTypeIdentifier.getJavaType(proxy.getDeclaredByMetadataId());
          Path typePath = PhysicalTypeIdentifier.getPath(proxy.getDeclaredByMetadataId());
          downstreamDependency = GwtLocatorMetadata.createIdentifier(typeName, typePath);
          processed = true;
        }
      }
      if (!processed
          && MemberFindingUtils.getAnnotationOfType(cid.getAnnotations(), RooJavaType.ROO_GWT_PROXY)
              == null) {
        boolean found = false;
        for (ClassOrInterfaceTypeDetails classOrInterfaceTypeDetails :
            typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(
                RooJavaType.ROO_GWT_PROXY)) {
          AnnotationMetadata annotationMetadata =
              GwtUtils.getFirstAnnotation(
                  classOrInterfaceTypeDetails, GwtUtils.ROO_PROXY_REQUEST_ANNOTATIONS);
          if (annotationMetadata != null) {
            AnnotationAttributeValue<?> attributeValue = annotationMetadata.getAttribute("value");
            if (attributeValue != null) {
              String mirrorName = GwtUtils.getStringValue(attributeValue);
              if (mirrorName != null
                  && cid.getName().getFullyQualifiedTypeName().equals(attributeValue.getValue())) {
                found = true;
                JavaType typeName =
                    PhysicalTypeIdentifier.getJavaType(
                        classOrInterfaceTypeDetails.getDeclaredByMetadataId());
                Path typePath =
                    PhysicalTypeIdentifier.getPath(
                        classOrInterfaceTypeDetails.getDeclaredByMetadataId());
                downstreamDependency = GwtLocatorMetadata.createIdentifier(typeName, typePath);
                break;
              }
            }
          }
        }
        if (!found) {
          return;
        }
      } else if (!processed) {
        // A physical Java type has changed, and determine what the corresponding local metadata
        // identification string would have been
        JavaType typeName = PhysicalTypeIdentifier.getJavaType(upstreamDependency);
        Path typePath = PhysicalTypeIdentifier.getPath(upstreamDependency);
        downstreamDependency = GwtLocatorMetadata.createIdentifier(typeName, typePath);
      }

      // We only need to proceed if the downstream dependency relationship is not already registered
      // (if it's already registered, the event will be delivered directly later on)
      if (metadataDependencyRegistry
          .getDownstream(upstreamDependency)
          .contains(downstreamDependency)) {
        return;
      }
    }

    // We should now have an instance-specific "downstream dependency" that can be processed by this
    // class
    Assert.isTrue(
        MetadataIdentificationUtils.getMetadataClass(downstreamDependency)
            .equals(MetadataIdentificationUtils.getMetadataClass(getProvidesType())),
        "Unexpected downstream notification for '"
            + downstreamDependency
            + "' to this provider (which uses '"
            + getProvidesType()
            + "'");

    metadataService.get(downstreamDependency, true);
  }