Package com.sun.mirror.apt

Examples of com.sun.mirror.apt.Messager


     * todo: should this always run all tests whenever called for any supported annotation?
     */
    @Override
    public void check(Declaration _decl) {

        Messager messager = _env.getMessager();

        try {

            // check if we've already handled this declaration
            if (handledDecls.contains(_decl)) {
                return;
            }

            // check if we're interested in declaration
            if (! (_decl instanceof TypeDeclaration)) {
                return;
            }
            WebService wsAnnotation = _decl.getAnnotation(WebService.class);
            if (null == wsAnnotation) {
                messager.printError(_decl.getPosition(), "@WebService annotation missing; unable to process: " + ((TypeDeclaration) _decl).getQualifiedName());
            }

            // store declaration so we don't handle it multiple times
            handledDecls.add((TypeDeclaration) _decl);
       
            // service implementation bean
            if (_decl instanceof ClassDeclaration) {
                ClassDeclaration classDecl = (ClassDeclaration) _decl;
                messager.printNotice("processing service implementation bean: " + classDecl.getQualifiedName());
               
                BeehiveWsTypeMetadata om = null;
                String endpointInterface = wsAnnotation.endpointInterface().trim();
               
                // start from endpoint interface
                if (null != endpointInterface && 0 < endpointInterface.length()) {

                    // get object model for service endpoint interface
                    om = getEndpointInterfaceObjectModel(endpointInterface);
                   
                    // merge abstract and concrete object models
                    om.merge(new MirrorTypeInfo(classDecl, _env));
                }
               
                // create object model from scratch
                else {
                    om = new Jsr181TypeMetadataImpl(new MirrorTypeInfo(classDecl, _env));
                }

                // check if we have an object model
                if (null == om) {
                    return;
                }

                // persist object model
                oms.store(om);
            }
           
            // service endpoint interface
            else if (_decl instanceof InterfaceDeclaration) {
                InterfaceDeclaration interfaceDecl = (InterfaceDeclaration) _decl;
               
                messager.printNotice("processing service endpoint interface: " + interfaceDecl.getQualifiedName());
               
                // create object model
                BeehiveWsTypeMetadata om = new Jsr181TypeMetadataImpl(new MirrorTypeInfo(interfaceDecl, _env));
                if (null == om) {
                    return;
                }

                // store the object model
                oms.store(om);
            }

            // @WebService annotation on unknown/unsupported type definition
            else {
                messager.printError(_decl.getPosition(), "found unsupported type of TypeDeclaration:" + _decl.getSimpleName());
            }
        }

        // if an exception or error ocurred log it and return
        catch (Throwable t) {
            messager.printError(_decl.getPosition(), t.getMessage());
        }
    }
View Full Code Here


   * @param model The model to validate.
   * @throws ModelValidationException If any validation errors are encountered.
   */
  protected void validate(EnunciateFreemarkerModel model) throws ModelValidationException {
    debug("Validating the model...");
    Messager messager = getMessager();
    ValidatorChain validator = new ValidatorChain();
    EnunciateConfiguration config = this.enunciate.getConfig();
    Set<String> disabledRules = new TreeSet<String>(config.getDisabledRules());
    if (this.enunciate.isModuleEnabled("rest")) {
      //if the REST module is enabled, disable the validation rule that
      //fails if the module is not enabled.
      disabledRules.add("disabled.rest.module");
    }

    Validator coreValidator = config.getValidator();
    if (coreValidator instanceof ConfigurableRules) {
      ((ConfigurableRules) coreValidator).disableRules(disabledRules);
    }
    validator.addValidator("core", coreValidator);
    debug("Default validator added to the chain.");
    for (DeploymentModule module : config.getEnabledModules()) {
      Validator moduleValidator = module.getValidator();
      if (moduleValidator != null) {
        if (moduleValidator instanceof ConfigurableRules) {
          ((ConfigurableRules)moduleValidator).disableRules(disabledRules);
        }
        validator.addValidator(module.getName(), moduleValidator);
        debug("Validator for module %s added to the chain.", module.getName());
      }
    }

    if (!config.isAllowEmptyNamespace()) {
      validator.addValidator("emptyns", new EmptyNamespaceValidator());
    }

    ValidationResult validationResult = validate(model, validator);

    if (validationResult.hasWarnings()) {
      warn("Validation result has warnings.");
      for (ValidationMessage warning : validationResult.getWarnings()) {
        if (!disabledRules.contains("all.warnings") && !disabledRules.contains(String.valueOf(warning.getLabel()) + ".warnings")) {
          StringBuilder text = new StringBuilder();
          if (warning.getLabel() != null) {
            text.append('[').append(warning.getLabel()).append("] ");
          }
          text.append(warning.getText());

          if (warning.getPosition() != null) {
            messager.printWarning(warning.getPosition(), text.toString());
          }
          else {
            messager.printWarning(text.toString());
          }
        }
      }
    }

    if (validationResult.hasErrors()) {
      warn("Validation result has errors.");
      for (ValidationMessage error : validationResult.getErrors()) {
        StringBuilder text = new StringBuilder();
        if (error.getLabel() != null) {
          text.append('[').append(error.getLabel()).append("] ");
        }
        text.append(error.getText());

        if (error.getPosition() != null) {
          messager.printError(error.getPosition(), text.toString());
        }
        else {
          messager.printError(text.toString());
        }
      }

      throw new ModelValidationException();
    }
View Full Code Here

  //Inherited.
  @Override
  protected void process(TemplateException e) {
    if (!(e instanceof ModelValidationException)) {
      Messager messager = getMessager();
      StringWriter stackTrace = new StringWriter();
      e.printStackTrace(new PrintWriter(stackTrace));
      messager.printError(stackTrace.toString());
    }

    this.ee = new EnunciateException(e);
  }
View Full Code Here

  public void testValidate() throws Exception {
    final EndpointInterface ei = new EndpointInterface(getDeclaration("org.codehaus.enunciate.samples.services.NamespacedWebService"));
    final ComplexTypeDefinition beanOne = new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.BeanOne"));
    final ComplexTypeDefinition beanTwo = new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.BeanTwo"));
    final ComplexTypeDefinition beanThree = new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.BeanThree"));
    final Messager messager = EasyMock.createNiceMock(Messager.class);
    RootElementDeclaration beanThreeElement = new RootElementDeclaration((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.BeanThree"), beanThree);

    EnunciateConfiguration config = new EnunciateConfiguration();
    final MockValidator validator = new MockValidator();
    config.setValidator(validator);
View Full Code Here

TOP

Related Classes of com.sun.mirror.apt.Messager

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.