Package org.springframework.ide.eclipse.core.model.validation

Examples of org.springframework.ide.eclipse.core.model.validation.ValidationProblemAttribute


        BeanDefinition dependsBd = context.getCompleteRegistry().getBeanDefinition(beanName);
        if (dependsBd.isAbstract()
            || (dependsBd.getBeanClassName() == null && dependsBd.getFactoryBeanName() == null)) {
          context.error(bean, "INVALID_DEPENDS_ON_BEAN", "Referenced depends-on bean '" + beanName
              + "' is invalid (abstract or no bean class and no " + "factory bean)",
              new ValidationProblemAttribute("BEAN", beanName),
              new ValidationProblemAttribute("BEAN_NAME", bean.getElementName()));
        }
      }
      catch (NoSuchBeanDefinitionException e) {

        // Skip error "parent name is equal to bean name"
        if (!e.getBeanName().equals(bean.getElementName())) {
          context.warning(bean, "UNDEFINED_DEPENDS_ON_BEAN", "Depends-on bean '" + beanName + "' not found",
              new ValidationProblemAttribute("BEAN", beanName),
              new ValidationProblemAttribute("BEAN_NAME", bean.getElementName()));
        }
      }
    }
  }
View Full Code Here


    if (beanName != null && !SpringCoreUtils.hasPlaceHolder(beanName) && !ignorableBeans.contains(beanName)) {
      try {
        BeanDefinition refBd = context.getCompleteRegistry().getBeanDefinition(beanName);
        if (refBd.isAbstract() || (refBd.getBeanClassName() == null && refBd.getFactoryBeanName() == null)) {
          context.error(element, "INVALID_REFERENCED_BEAN", "Referenced bean '" + beanName + "' is invalid "
              + "(abstract or no bean class and " + "no factory bean)", new ValidationProblemAttribute(
              "BEAN", beanName), new ValidationProblemAttribute("BEAN_NAME", ValidationRuleUtils.getBeanName(element)));
        }
      }
      catch (NoSuchBeanDefinitionException e) {

        // Handle factory bean references
        if (ValidationRuleUtils.isFactoryBeanReference(beanName)) {
          String tempBeanName = beanName.replaceFirst(ValidationRuleUtils.FACTORY_BEAN_REFERENCE_REGEXP, "");
          try {
            BeanDefinition def = context.getCompleteRegistry().getBeanDefinition(tempBeanName);
            String beanClassName = def.getBeanClassName();
            if (beanClassName != null) {
              IType type = JdtUtils.getJavaType(BeansModelUtils.getProject(element).getProject(),
                  beanClassName);
              if (type != null) {
                if (!JdtUtils.doesImplement(context.getRootElementResource(), type, FactoryBean.class
                    .getName())) {
                  context.error(element, "INVALID_FACTORY_BEAN", "Referenced factory bean '"
                      + tempBeanName + "' does not implement the " + "interface 'FactoryBean'",
                      new ValidationProblemAttribute("BEAN", tempBeanName),
                      new ValidationProblemAttribute("BEAN_NAME", ValidationRuleUtils.getBeanName(element)));
                }
              }
              else {
                context.warning(element, "INVALID_REFERENCED_BEAN", "Referenced factory bean '"
                    + tempBeanName + "' implementation class not found",
                    new ValidationProblemAttribute("BEAN", tempBeanName),
                    new ValidationProblemAttribute("BEAN_NAME", ValidationRuleUtils.getBeanName(element)));
              }
            }
          }
          catch (NoSuchBeanDefinitionException be) {
            context.warning(element, "UNDEFINED_FACTORY_BEAN", "Referenced factory bean '" + tempBeanName
                + "' not found", new ValidationProblemAttribute("BEAN", tempBeanName),
                new ValidationProblemAttribute("BEAN_NAME", ValidationRuleUtils.getBeanName(element)));
          }
          catch (BeanDefinitionStoreException be) {
            // ignore unresolvable parent bean exceptions
          }
        }
        else {
          if (element instanceof BeanProperty) {
          context.warning(element, "UNDEFINED_REFERENCED_BEAN", "Referenced bean '" + beanName
              + "' not found", new ValidationProblemAttribute("BEAN", beanName),
              new ValidationProblemAttribute("BEAN_NAME", ValidationRuleUtils.getBeanName(element)));
          } else {
            context.warning(element, "UNDEFINED_REFERENCED_BEAN", "Referenced bean '" + beanName
                + "' not found", new ValidationProblemAttribute("BEAN", beanName),
                new ValidationProblemAttribute("BEAN_NAME", ValidationRuleUtils.getBeanName(element)));
           
          }
        }
      }
      catch (BeanDefinitionStoreException e) {
View Full Code Here

                  AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME,
                  AutowiredAnnotationBeanPostProcessor.class.getName()))) {
            String className = type.getFullyQualifiedName();
            context.error(bean, "NO_CONSTRUCTOR", "No constructor with " + numArguments
                + (numArguments == 1 ? " argument" : " arguments") + " defined in class '" + className
                + "'", new ValidationProblemAttribute("CLASS", className));
          }
        }
       
        // Validate the actual constructors for name, type matches
        else if (numArguments > 0) {
          Set<IMethod> ctors = Introspector.getConstructors(type, numArguments, true);
         
          for (IBeanConstructorArgument argument : bean.getConstructorArguments()) {
            String name = argument.getName();
            if (name != null) {
              boolean found = false;
              for(IMethod ctor: ctors) {
                List<String> parameterNames = Arrays.asList(ctor.getParameterNames());
                if (parameterNames.contains(name)) {
                  found = true;
                }
              }
             
              if (!found) {
                context.warning(argument, "MISSING_CONSTRUCTOR_ARG_NAME", String.format(
                    "Cannot find constructor parameter with name '%s'", name),
                    new ValidationProblemAttribute("CLASS", type.getFullyQualifiedName()),
                    new ValidationProblemAttribute("NUM_CONSTRUCTOR_ARGS", numArguments));
              }
            }
          }
        }
      }
View Full Code Here

        PropertyTokenHolder tokens = getPropertyNameTokens(nestedPropertyName);
        String getterName = "get" + StringUtils.capitalize(tokens.actualName);
        IMethod getter = Introspector.findMethod(type, getterName, 0, Public.YES, Static.NO);
        if (getter == null) {
          context.error(property, "NO_GETTER", "No getter found for nested property '" + nestedPropertyName
              + "' in class '" + className + "'", new ValidationProblemAttribute("CLASS", className),
              new ValidationProblemAttribute("PROPERTY", nestedPropertyName),
              new ValidationProblemAttribute("BEAN_NAME", ValidationRuleUtils.getBeanName(property)));
        }
        else {

          // Check getter's return type
          if (tokens.keys != null) {
            // TODO Check getter's return type for index or map
            // type
          }
        }
      }
      else {

        // Now check for mapped property
        int mappedIndex = propertyName.indexOf(PropertyAccessor.PROPERTY_KEY_PREFIX_CHAR);
        if (mappedIndex != -1) {
          propertyName = propertyName.substring(0, mappedIndex);
        }

        // Finally check property
        if (!Introspector.isValidPropertyName(propertyName)) {
          context.error(property, "INVALID_PROPERTY_NAME", "Invalid property name '" + propertyName
              + "' - not JavaBean compliant", new ValidationProblemAttribute("CLASS", className),
              new ValidationProblemAttribute("PROPERTY", propertyName),
              new ValidationProblemAttribute("BEAN_NAME", ValidationRuleUtils.getBeanName(property)));
        }
        else if (!Introspector.hasWritableProperty(type, propertyName)) {
          context.error(property, "NO_SETTER", "No setter found for property '" + propertyName
              + "' in class '" + className + "'", new ValidationProblemAttribute("CLASS", className),
              new ValidationProblemAttribute("PROPERTY", propertyName),
              new ValidationProblemAttribute("BEAN_NAME", ValidationRuleUtils.getBeanName(property)));
        }

        // TODO If mapped property then check type of setter's argument
      }
    }
View Full Code Here

        try {
          new PartTree(methodName, domainClass);
        } catch (PropertyReferenceException e) {
          element.setElementSourceLocation(new JavaModelSourceLocation(
              method));
          ValidationProblemAttribute start = new ValidationProblemAttribute(
              IMarker.CHAR_START, method.getNameRange()
                  .getOffset());
          ValidationProblemAttribute end = new ValidationProblemAttribute(
              IMarker.CHAR_END, method.getSourceRange()
                  .getOffset()
                  + method.getSourceRange().getLength());
          context.error(element, "INVALID_DERIVED_QUERY",
              "Invalid derived query! " + e.getMessage(),
View Full Code Here

              String propertySimpleType = propertyReturnType.getSimpleName();
              String paramSimpleType = Signature.getSignatureSimpleName(paramTypeSignature);
              if (propertySimpleType != null && !(propertySimpleType.equals(paramSimpleType))) {
                element.setElementSourceLocation(new JavaModelSourceLocation(params[0]));
                ISourceRange paramSourceRange = params[0].getSourceRange();
                ValidationProblemAttribute start = new ValidationProblemAttribute(
                    IMarker.CHAR_START,  paramSourceRange.getOffset());
                ValidationProblemAttribute end = new ValidationProblemAttribute(
                    IMarker.CHAR_END, paramSourceRange.getOffset() + paramSourceRange.getLength());
                ValidationProblemAttribute problemId = new ValidationProblemAttribute(IMarker.PROBLEM, PROBLEM_ID);
                ValidationProblemAttribute propertyType = new ValidationProblemAttribute(PROPERTY_TYPE_ATTR, propertyReturnType.getSimpleName());
                ValidationProblemAttribute propertyTypePackage = new ValidationProblemAttribute(PROPERTY_TYPE_PACKAGE_ATTR, propertyReturnType.getPackage().getName());
                context.warning(element, "SpringDataProbleMarker",
                    "Parameter type (" + paramSimpleType + ") does not match domain class property definition (" + propertySimpleType + ").",
                    new ValidationProblemAttribute[] {start, end, problemId, propertyType, propertyTypePackage});
              }
            }
View Full Code Here

    else {
      Map<String, IBean> matchingBeans = findAutowireCandidates(beanName, type, descriptor);
      if (matchingBeans.isEmpty()) {
        if (descriptor.isRequired()) {
          problemReporter.error("Unsatisfied 'required' dependency of type [" + type
              + "]. Expected at least 1 matching bean", descriptor, new ValidationProblemAttribute(AUTOWIRE_PROBLEM_TYPE, REQUIRED_NO_MATCH));
          throw new AutowireResolutionException();
        }
        return;
      }
      if (matchingBeans.size() > 1) {
        String primaryBeanName = determinePrimaryCandidate(matchingBeans, descriptor);
        if (primaryBeanName == null) {
          Set<String> matchingBeanNames = matchingBeans.keySet();
          ValidationProblemAttribute[] attributes = new ValidationProblemAttribute[matchingBeanNames.size() + 2];
          attributes[0] = new ValidationProblemAttribute(AUTOWIRE_PROBLEM_TYPE, TOO_MANY_MATCHING_BEANS);
          attributes[1] = new ValidationProblemAttribute(BEAN_TYPE, type.getName());
          int counter = 2;
          for(String matchingBeanName: matchingBeanNames) {
            attributes[counter] = new ValidationProblemAttribute(MATCHING_BEAN_NAME + counter, matchingBeanName);
            counter++;
          }
          problemReporter.error("Expected single matching bean but found " + matchingBeans.size() + ": "
              + matchingBeanNames, descriptor, attributes);
          throw new AutowireResolutionException();
View Full Code Here

        if (source != null && source.getUnderlyingResource() != null) {
          ValidationProblemAttribute[] newAttributes = new ValidationProblemAttribute[attributes.length + 1];
          for(int i=0; i<attributes.length; i++) {
            newAttributes[i] = attributes[i];
          }
          newAttributes[attributes.length] = new ValidationProblemAttribute("JAVA_HANDLE", source.getHandleIdentifier());
         
          // By convention autowire problems will only get reported as warnings (for now?)
          problems.add(new ValidationProblem(IMarker.SEVERITY_WARNING, message, source
              .getUnderlyingResource(), JdtUtils.getLineNumber(source),
              newAttributes));
View Full Code Here

      }

      // add the error message
      if (missingProperties.size() > 0) {
        String msg = buildExceptionMessage(missingProperties, bean.getElementName());
        context.error(bean, "REQUIRED_PROPERTY_MISSING", msg, new ValidationProblemAttribute("CLASS", type
            .getFullyQualifiedName()), new ValidationProblemAttribute("BEAN_NAME", bean.getElementName()),
            new ValidationProblemAttribute("MISSING_PROPERTIES",
            missingProperties));
      }
    }
    catch (JavaModelException e) {
      BeansCorePlugin.log(e);
View Full Code Here

                + " factory method '"
                + methodName
                + "' "
                + (argCount != -1 ? "with " + argCount + " arguments " : "")
                + "not found in factory bean class '" + className + "'",
                new ValidationProblemAttribute("CLASS", className), new ValidationProblemAttribute(
                    "METHOD", methodName),
                    new ValidationProblemAttribute("BEAN_NAME", bean.getElementName()));
          }
          else if (methodType == MethodType.INIT) {
            context.error(bean, "UNDEFINED_INIT_METHOD", "Init-method '" + methodName
                + "' not found in bean class '" + className + "'", new ValidationProblemAttribute(
                "CLASS", className), new ValidationProblemAttribute("METHOD", methodName),
                new ValidationProblemAttribute("BEAN_NAME", bean.getElementName()));
          }
          else if (methodType == MethodType.DESTROY) {
            context.error(bean, "UNDEFINED_DESTROY_METHOD", "Destroy-method '" + methodName
                + "' not found in bean class '" + className + "'", new ValidationProblemAttribute(
                "CLASS", className), new ValidationProblemAttribute("METHOD", methodName),
                new ValidationProblemAttribute("BEAN_NAME", bean.getElementName()));
          }
        }

        // TODO CD check this back in after adding configurable rule
        // properties
View Full Code Here

TOP

Related Classes of org.springframework.ide.eclipse.core.model.validation.ValidationProblemAttribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.