@Override
  public List<String> getFieldListTypeAllPossibleValues(ShellContext shellContext) {
    // Get current value of class
    String currentText = shellContext.getParameters().get("type");

    List<String> allPossibleValues = new ArrayList<String>();

    // Getting all existing entities
    Set<ClassOrInterfaceTypeDetails> entitiesInProject =
        typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_JPA_ENTITY);
    for (ClassOrInterfaceTypeDetails entity : entitiesInProject) {
      String name = replaceTopLevelPackageString(entity, currentText);
      if (!allPossibleValues.contains(name)) {
        allPossibleValues.add(name);
      }
    }

    // Getting all existing dtos
    Set<ClassOrInterfaceTypeDetails> dtosInProject =
        typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_DTO);
    for (ClassOrInterfaceTypeDetails dto : dtosInProject) {
      String name = replaceTopLevelPackageString(dto, currentText);
      if (!allPossibleValues.contains(name)) {
        allPossibleValues.add(name);
      }
    }

    return allPossibleValues;
  }
  /** {@inheritDoc} */
  public void annotateType(final JavaType type, final JavaPackage javaPackage) {
    // TODO check for existing controller

    // Use Roo's Assert type for null checks
    Validate.notNull(type, "Java type required");
    Validate.notNull(javaPackage, "Java package required, web mvc all command package required");

    // Obtain ClassOrInterfaceTypeDetails for this java type
    ClassOrInterfaceTypeDetails entityDetails = typeLocationService.getTypeDetails(type);

    // Test if the annotation already exists on the target type
    if (entityDetails != null
        && MemberFindingUtils.getAnnotationOfType(
                entityDetails.getAnnotations(), new JavaType(RooEnvers.class.getName()))
            == null) {
      ClassOrInterfaceTypeDetailsBuilder classOrInterfaceTypeDetailsBuilder =
          new ClassOrInterfaceTypeDetailsBuilder(entityDetails);

      // Create JavaType instance for the add-ons trigger annotation
      JavaType rooEnvers = new JavaType(RooEnvers.class.getName());

      // Create Annotation metadata
      AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(rooEnvers);

      // Add annotation to target type
      classOrInterfaceTypeDetailsBuilder.addAnnotation(annotationBuilder.build());

      // Save changes to disk
      typeManagementService.createOrUpdateTypeOnDisk(classOrInterfaceTypeDetailsBuilder.build());
    }

    // Get details for existing controller
    JavaType typeController =
        new JavaType(
            javaPackage.getFullyQualifiedPackageName()
                + "."
                + type.getSimpleTypeName()
                + "Controller");
    ClassOrInterfaceTypeDetails typeControllerDetails =
        typeLocationService.getTypeDetails(typeController);

    // Add annotation @RooEnversController to existing controller
    ClassOrInterfaceTypeDetailsBuilder classOrInterfaceTypeDetailsBuilder =
        new ClassOrInterfaceTypeDetailsBuilder(typeControllerDetails);
    JavaType rooEnversController =
        new JavaType("de.eightbitboy.roo.envers.controller.RooEnversController");

    final List<AnnotationAttributeValue<?>> rooEnversControllerAttributes =
        new ArrayList<AnnotationAttributeValue<?>>();
    rooEnversControllerAttributes.add(new ClassAttributeValue(new JavaSymbolName("type"), type));

    AnnotationMetadataBuilder annotationBuilder =
        new AnnotationMetadataBuilder(rooEnversController, rooEnversControllerAttributes);
    classOrInterfaceTypeDetailsBuilder.addAnnotation(annotationBuilder.build());

    typeManagementService.createOrUpdateTypeOnDisk(classOrInterfaceTypeDetailsBuilder.build());
  }
  @Override
  public void restResource(
      final JavaType type, final boolean hide, final String path, final String rel) {

    final ClassOrInterfaceTypeDetails typeDetails = typeLocationService.getTypeDetails(type);
    Validate.notNull(typeDetails, "The repository specified, '" + type + "'doesn't exist");

    final AnnotationMetadataBuilder annotationBuilder =
        new AnnotationMetadataBuilder(REST_RESOURCE);
    if (hide) {
      annotationBuilder.addBooleanAttribute("exported", false);
    }
    if (!StringUtils.isEmpty(path)) {
      annotationBuilder.addStringAttribute("path", path);
    }
    if (!StringUtils.isEmpty(rel)) {
      annotationBuilder.addStringAttribute("rel", rel);
    }

    final ClassOrInterfaceTypeDetailsBuilder cidBuilder =
        new ClassOrInterfaceTypeDetailsBuilder(typeDetails);

    if (MemberFindingUtils.getAnnotationOfType(typeDetails.getAnnotations(), REST_RESOURCE)
        != null) {
      cidBuilder.removeAnnotation(REST_RESOURCE);
    }

    cidBuilder.addAnnotation(annotationBuilder);

    typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
  }
  @Override
  public void systemService(
      final JavaType type,
      JavaSymbolName fieldName,
      final SystemService service,
      final boolean addPermissions) {

    final ClassOrInterfaceTypeDetails typeDetails = typeLocationService.getTypeDetails(type);
    Validate.notNull(typeDetails, "The type specified, '" + type + "' doesn't exist");

    if (fieldName == null) {
      fieldName =
          new JavaSymbolName(
              StringUtils.uncapitalize(service.getServiceType().getSimpleTypeName()));
    }

    final String physicalTypeIdentifier = typeDetails.getDeclaredByMetadataId();

    final List<AnnotationMetadataBuilder> annotations =
        Arrays.asList(new AnnotationMetadataBuilder(ROO_SYSTEM_SERVICE));

    final FieldMetadataBuilder fieldBuilder =
        new FieldMetadataBuilder(
            physicalTypeIdentifier, 0, annotations, fieldName, service.getServiceType());
    typeManagementService.addField(fieldBuilder.build());

    if (addPermissions) {
      final String moduleName = projectOperations.getFocusedModuleName();
      for (Permission permission : service.getPermissions()) {
        androidTypeService.addPermission(moduleName, permission.permissionName());
      }
    }
  }
示例#5
0
  public void injectEmailTemplate(
      final JavaType targetType, final JavaSymbolName fieldName, final boolean async) {
    Assert.notNull(targetType, "Java type required");
    Assert.notNull(fieldName, "Field name required");

    final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    annotations.add(new AnnotationMetadataBuilder(AUTOWIRED));

    // Obtain the physical type and its mutable class details
    final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(targetType);
    ClassOrInterfaceTypeDetails existing = typeLocationService.findClassOrInterface(targetType);
    if (existing == null) {
      log.warning(
          "Aborting: Unable to find metadata for target type '"
              + targetType.getFullyQualifiedTypeName()
              + "'");
      return;
    }
    final ClassOrInterfaceTypeDetailsBuilder classOrInterfaceTypeDetailsBuilder =
        new ClassOrInterfaceTypeDetailsBuilder(existing);

    // Add the MailSender field
    final FieldMetadataBuilder mailSenderFieldBuilder =
        new FieldMetadataBuilder(
            declaredByMetadataId, PRIVATE_TRANSIENT, annotations, fieldName, MAIL_SENDER);
    classOrInterfaceTypeDetailsBuilder.addField(mailSenderFieldBuilder.build());

    // Add the "sendMessage" method
    classOrInterfaceTypeDetailsBuilder.addMethod(
        getSendMethod(fieldName, async, declaredByMetadataId, classOrInterfaceTypeDetailsBuilder));
    typeManagementService.createOrUpdateTypeOnDisk(classOrInterfaceTypeDetailsBuilder.build());
  }
 private PhysicalTypeMetadata getPhysicalTypeMetadata(final JavaType javaType) {
   final String declaredByMetadataId = typeLocationService.getPhysicalTypeIdentifier(javaType);
   if (StringUtils.isBlank(declaredByMetadataId)) {
     return null;
   }
   return (PhysicalTypeMetadata) metadataService.get(declaredByMetadataId);
 }
  private ClassOrInterfaceTypeDetails getGovernor(String metadataIdentificationString) {
    JavaType governorTypeName = GwtLocatorMetadata.getJavaType(metadataIdentificationString);
    Path governorTypePath = GwtLocatorMetadata.getPath(metadataIdentificationString);

    String physicalTypeId =
        PhysicalTypeIdentifier.createIdentifier(governorTypeName, governorTypePath);
    return typeLocationService.getTypeForIdentifier(physicalTypeId);
  }
 @Override
 public boolean isFieldManagementAvailable() {
   Set<ClassOrInterfaceTypeDetails> dtoClasses =
       typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_DTO);
   if (!dtoClasses.isEmpty()) {
     return true;
   }
   return false;
 }
  @Override
  public boolean isValid(JavaType javaType) {
    ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(javaType);
    if (cid.getAnnotation(RooJavaType.ROO_DTO) != null) {
      return true;
    }

    return false;
  }
 /**
  * Returns details of the given Java type's members
  *
  * @param type the type for which to get the members (required)
  * @return <code>null</code> if the member details are unavailable
  */
 protected MemberDetails getMemberDetails(final JavaType type) {
   String physicalTypeIdentifier = typeLocationService.getPhysicalTypeIdentifier(type);
   if (physicalTypeIdentifier == null) {
     return null;
   }
   // We need to lookup the metadata we depend on
   final PhysicalTypeMetadata physicalTypeMetadata =
       (PhysicalTypeMetadata) metadataService.get(physicalTypeIdentifier);
   return getMemberDetails(physicalTypeMetadata);
 }
  private Set<ClassOrInterfaceTypeDetails> getManagedIdentifiers() {
    final Set<ClassOrInterfaceTypeDetails> managedIdentifierTypes =
        new LinkedHashSet<ClassOrInterfaceTypeDetails>();

    final Set<ClassOrInterfaceTypeDetails> identifierTypes =
        typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(ROO_IDENTIFIER);
    for (final ClassOrInterfaceTypeDetails managedIdentifierType : identifierTypes) {
      final AnnotationMetadata identifierAnnotation =
          managedIdentifierType.getTypeAnnotation(ROO_IDENTIFIER);
      final AnnotationAttributeValue<?> attrValue = identifierAnnotation.getAttribute(DB_MANAGED);
      if (attrValue != null && (Boolean) attrValue.getValue()) {
        managedIdentifierTypes.add(managedIdentifierType);
      }
    }
    return managedIdentifierTypes;
  }
  @Override
  public void resourceString(
      final JavaType type, final String name, final JavaSymbolName fieldName, final String value) {

    final ClassOrInterfaceTypeDetails typeDetails = typeLocationService.getTypeDetails(type);
    Validate.notNull(typeDetails, "The type specified, '" + type + "' doesn't exist");

    final DocumentBuilder builder = newDocumentBuilder();
    final String valuesPath =
        pathResolver.getFocusedIdentifier(Path.ROOT, VALUES_PATH + SEP + STRINGS + XML_EXTENSION);

    InputStream inputStream = null;
    Document document = null;
    try {
      inputStream = fileManager.getInputStream(valuesPath);
      document = builder.parse(inputStream);
    } catch (final Exception e) {
      LOGGER.severe("Error reading resource XML: " + e.getMessage());
    } finally {
      IOUtils.closeQuietly(inputStream);
    }

    if (document != null) {
      final Element root = document.getDocumentElement();

      final Element stringElem = XmlUtils.createTextElement(document, "string", value);
      final String id = StringUtils.isEmpty(name) ? fieldName.getSymbolName() : name;
      stringElem.setAttribute("name", id);
      root.appendChild(stringElem);

      fileManager.createOrUpdateTextFileIfRequired(
          valuesPath, XmlUtils.nodeToString(document), true);
    }

    final String physicalTypeIdentifier = typeDetails.getDeclaredByMetadataId();

    final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    final AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(ROO_STRING);
    if (!StringUtils.isEmpty(name)) {
      annotationBuilder.addStringAttribute("value", name);
    }
    annotations.add(annotationBuilder);

    final FieldMetadataBuilder fieldBuilder =
        new FieldMetadataBuilder(physicalTypeIdentifier, 0, annotations, fieldName, STRING);
    typeManagementService.addField(fieldBuilder.build());
  }
  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;
  }
  private void reverseEngineer(final Database database) {
    final Set<ClassOrInterfaceTypeDetails> managedEntities =
        typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(ROO_DB_MANAGED);
    // Determine whether to create "active record" CRUD methods
    database.setActiveRecord(isActiveRecord(database, managedEntities));

    // Lookup the relevant destination package if not explicitly given
    final JavaPackage destinationPackage = getDestinationPackage(database, managedEntities);

    // Set the destination package in the database
    database.setDestinationPackage(destinationPackage);

    // Get tables from database
    final Set<Table> tables = new LinkedHashSet<Table>(database.getTables());

    // Manage existing entities with @RooDbManaged annotation
    for (final ClassOrInterfaceTypeDetails managedEntity : managedEntities) {
      // Remove table from set as each managed entity is processed.
      // The tables that remain in the set will be used for creation of
      // new entities later
      final Table table = updateOrDeleteManagedEntity(managedEntity, database);
      if (table != null) {
        tables.remove(table);
      }
    }

    // Create new entities from tables
    final List<ClassOrInterfaceTypeDetails> newEntities =
        new ArrayList<ClassOrInterfaceTypeDetails>();
    for (final Table table : tables) {
      // Don't create types from join tables in many-to-many associations
      if (!table.isJoinTable()) {
        JavaPackage schemaPackage = destinationPackage;
        if (database.hasMultipleSchemas()) {
          schemaPackage =
              new JavaPackage(
                  destinationPackage.getFullyQualifiedPackageName()
                      + "."
                      + DbreTypeUtils.suggestPackageName(table.getSchema().getName()));
        }
        final JavaType javaType =
            DbreTypeUtils.suggestTypeNameForNewTable(table.getName(), schemaPackage);
        final boolean activeRecord = database.isActiveRecord() && !database.isRepository();
        if (typeLocationService.getTypeDetails(javaType) == null) {
          table.setIncludeNonPortableAttributes(database.isIncludeNonPortableAttributes());
          table.setDisableVersionFields(database.isDisableVersionFields());
          table.setDisableGeneratedIdentifiers(database.isDisableGeneratedIdentifiers());
          newEntities.add(createNewManagedEntityFromTable(javaType, table, activeRecord));
        }
      }
    }

    // Create repositories if required
    if (database.isRepository()) {
      for (final ClassOrInterfaceTypeDetails entity : newEntities) {
        final JavaType type = entity.getType();
        repositoryJpaOperations.setupRepository(
            new JavaType(type.getFullyQualifiedTypeName() + "Repository"), type);
      }
    }

    // Create services if required
    if (database.isService()) {
      for (final ClassOrInterfaceTypeDetails entity : newEntities) {
        final JavaType type = entity.getType();
        final String typeName = type.getFullyQualifiedTypeName();
        serviceOperations.setupService(
            new JavaType(typeName + "Service"),
            new JavaType(typeName + "ServiceImpl"),
            type,
            false,
            "",
            false,
            false);
      }
    }

    // Create integration tests if required
    if (database.isTestAutomatically()) {
      for (final ClassOrInterfaceTypeDetails entity : newEntities) {
        integrationTestOperations.newIntegrationTest(entity.getType());
      }
    }

    // Notify
    final List<ClassOrInterfaceTypeDetails> allEntities =
        new ArrayList<ClassOrInterfaceTypeDetails>();
    allEntities.addAll(newEntities);
    allEntities.addAll(managedEntities);
    notify(allEntities);
  }
  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);
  }
  @Override
  public void view(
      final JavaType type,
      final String viewName,
      final String identifier,
      final JavaSymbolName fieldName,
      final Dimension height,
      final Dimension width) {

    final ClassOrInterfaceTypeDetails typeDetails = typeLocationService.getTypeDetails(type);
    Validate.notNull(typeDetails, "The type specified, '" + type + "'doesn't exist");

    final JavaType viewType =
        new JavaType(viewName.contains(".") ? viewName : WIDGET_PACKAGE + "." + viewName);

    final String layout =
        RequestFactoryUtils.getStringAnnotationValue(typeDetails, ROO_ACTIVITY, "value", "");
    if (!StringUtils.isEmpty(layout)) {
      final DocumentBuilder builder = newDocumentBuilder();
      final String layoutPath =
          pathResolver.getFocusedIdentifier(Path.ROOT, LAYOUT_PATH + SEP + layout + XML_EXTENSION);

      InputStream inputStream = null;
      Document document = null;
      try {
        inputStream = fileManager.getInputStream(layoutPath);
        document = builder.parse(inputStream);
      } catch (final Exception e) {
        LOGGER.severe("Error reading layout XML: " + e.getMessage());
      } finally {
        IOUtils.closeQuietly(inputStream);
      }

      if (document != null) {
        final Element root = document.getDocumentElement();

        final Element viewElem = document.createElement(viewType.getSimpleTypeName());
        final String id = StringUtils.isEmpty(identifier) ? fieldName.getSymbolName() : identifier;
        viewElem.setAttribute("android:id", ID_PREFIX + id);
        viewElem.setAttribute("android:layout_height", height.value());
        viewElem.setAttribute("android:layout_width", width.value());
        root.appendChild(viewElem);

        fileManager.createOrUpdateTextFileIfRequired(
            layoutPath, XmlUtils.nodeToString(document), true);
      }
    }

    final String physicalTypeIdentifier = typeDetails.getDeclaredByMetadataId();

    final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    final AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(ROO_VIEW);
    if (!StringUtils.isEmpty(identifier)) {
      annotationBuilder.addStringAttribute("value", identifier);
    }
    annotations.add(annotationBuilder);

    final FieldMetadataBuilder fieldBuilder =
        new FieldMetadataBuilder(physicalTypeIdentifier, 0, annotations, fieldName, viewType);
    typeManagementService.addField(fieldBuilder.build());
  }
 @Override
 public boolean isViewAvailable() {
   return projectOperations.isFocusedProjectAvailable()
       && typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(ROO_ACTIVITY).size() > 0;
 }