Package org.codehaus.enunciate.config

Examples of org.codehaus.enunciate.config.EnunciateConfiguration


    if (typeName == null) {
      for (AnnotationMirror annotation : declaration.getAnnotationMirrors()) {
        AnnotationTypeDeclaration decl = annotation.getAnnotationType().getDeclaration();
        if (decl != null) {
          String fqn = decl.getQualifiedName();
          EnunciateConfiguration config = ((EnunciateFreemarkerModel) FreemarkerModel.get()).getEnunciateConfig();
          if (config != null && config.getCustomResourceParameterAnnotations().contains(fqn)) {
            parameterName = declaration.getSimpleName();
            typeName = decl.getSimpleName().toLowerCase().replaceAll("param", "");
            break;
          }
        }
View Full Code Here


            || HeaderParam.class.getName().equals(fqn)
            || FormParam.class.getName().equals(fqn)) {
            return true;
          }

          EnunciateConfiguration config = ((EnunciateFreemarkerModel) FreemarkerModel.get()).getEnunciateConfig();
          if (config != null && config.getSystemResourceParameterAnnotations().contains(fqn)) {
            return false;
          }
          if (config != null && config.getCustomResourceParameterAnnotations().contains(fqn)) {
            return true;
          }
        }
      }
    }
View Full Code Here

      if (declaration != null) {
        String fqn = declaration.getQualifiedName();
        if (Context.class.getName().equals(fqn) && candidate.getAnnotation(TypeHint.class) == null) {
          return true;
        }
        EnunciateConfiguration config = ((EnunciateFreemarkerModel) FreemarkerModel.get()).getEnunciateConfig();
        if (config != null && config.getSystemResourceParameterAnnotations().contains(fqn)) {
          return true;
        }
      }
    }
View Full Code Here

      files[i] = file.getAbsolutePath();
    }

    try {
      Enunciate proxy = new AntLoggingEnunciate(files);
      EnunciateConfiguration config;

      if (classpath != null) {
        proxy.setRuntimeClasspath(classpath.toString());

        //set up the classloader for the Enunciate invocation.
        AntClassLoader loader = new AntClassLoader(Enunciate.class.getClassLoader(), getProject(), this.classpath, true);
        proxy.setBuildClasspath(loader.getClasspath());
        Thread.currentThread().setContextClassLoader(loader);
        ArrayList<DeploymentModule> modules = new ArrayList<DeploymentModule>();
        Iterator<DeploymentModule> discoveredModules = ServiceLoader.load(DeploymentModule.class, loader).iterator();
        getProject().log("Loading modules from the specified classpath....");
        while (discoveredModules.hasNext()) {
          DeploymentModule discoveredModule = (DeploymentModule) discoveredModules.next();
          getProject().log("Discovered module " + discoveredModule.getName());
          modules.add(discoveredModule);
        }
        //make sure a basic app module is there.
        modules.add(new BasicAppModule());
        config = new EnunciateConfiguration(modules);
      }
      else {
        config = new EnunciateConfiguration();
      }

      proxy.setConfig(config);

      if (this.configFile != null) {
        getProject().log("Loading config " + this.configFile);
        ExpandProperties reader = new ExpandProperties(new FileReader(this.configFile));
        reader.setProject(getProject());
        config.load(reader);
        proxy.setConfigFile(this.configFile);
      }

      if (this.generateDir != null) {
        proxy.setGenerateDir(this.generateDir);
View Full Code Here

   * Reads the enunciate configuration from the specified file, if any.
   *
   * @return The configuration, or null if none is specified.
   */
  protected EnunciateConfiguration loadConfig() throws IOException {
    EnunciateConfiguration config = new EnunciateConfiguration();
    File configFile = getConfigFile();
    if (configFile == null) {
      info("No config file specified, using defaults....");
    }
    else if (!configFile.exists()) {
      warn("Config file %s doesn't exist, using defaults....", configFile);
    }
    else {
      try {
        config.load(configFile);
      }
      catch (SAXException e) {
        throw new IOException("Error parsing enunciate configuration file " + configFile + ": " + e.getMessage());
      }
    }
View Full Code Here

  /**
   * Package-private constructor for testing purposes.
   */
  EnunciateAnnotationProcessor() throws EnunciateException {
    this(new Enunciate(new String[0], new EnunciateConfiguration()));
  }
View Full Code Here

  public void process() {
    this.processed = true;
    try {
      EnunciateFreemarkerModel model = getRootModel();

      EnunciateConfiguration config = this.enunciate.getConfig();
      for (DeploymentModule module : config.getAllModules()) {
        if (module instanceof EnunciateModelAware) {
          ((EnunciateModelAware) module).initModel(model);
        }
      }

      for (DeploymentModule module : config.getEnabledModules()) {
        debug("Invoking %s step for module %s", Enunciate.Target.GENERATE, module.getName());

        if (module instanceof FacetAware) {
          enunciate.setupFacetFilter((FacetAware) module);
        }
View Full Code Here

   *
   * @return The root model.
   */
  @Override
  protected EnunciateFreemarkerModel getRootModel() throws TemplateModelException {
    EnunciateConfiguration config = this.enunciate.getConfig();
    EnunciateFreemarkerModel model = (EnunciateFreemarkerModel) super.getRootModel();
    model.setEnunciateConfig(config);

    //build up the list of all classes to which we are going to apply enunciate.
    TypeDeclaration[] additionalApiDefinitions = loadAdditionalApiDefinitions();
    AnnotationProcessorEnvironment env = Context.getCurrentEnvironment();
    Collection<TypeDeclaration> typeDeclarations = new ArrayList<TypeDeclaration>(env.getTypeDeclarations());
    typeDeclarations.addAll(Arrays.asList(additionalApiDefinitions));

    //trim the classes that are not "include"d.
    trimNotIncludedClasses(typeDeclarations);

    //remove any explicitly-excluded classes
    removeExcludedClasses(typeDeclarations);

    //override any namespace prefix mappings as specified in the config.
    for (String ns : config.getNamespacesToPrefixes().keySet()) {
      String prefix = config.getNamespacesToPrefixes().get(ns);
      model.getNamespacesToPrefixes().put(ns, prefix);
      debug("Assigning namespace prefix %s to namespace %s as specified in the config.", prefix, ns);
    }

    //override any content type ids as specified in the config.
    for (String ct : config.getContentTypesToIds().keySet()) {
      String id = config.getContentTypesToIds().get(ct);
      model.getContentTypesToIds().put(ct, id);
      debug("Assigning id '%s' to content type '%s' as specified in the config.", id, ct);
    }

    if (config.getGeneratedCodeLicenseFile() != null) {
      File licenseFile = this.enunciate.resolvePath(config.getGeneratedCodeLicenseFile());
      try {
        model.put("generatedCodeLicense", this.enunciate.readFile(licenseFile));
      }
      catch (IOException e) {
        warn("Unable to read code license file %s: %s.", licenseFile.getAbsolutePath(), e.getMessage());
      }
    }

    String baseURL = config.getDeploymentProtocol() + "://" + config.getDeploymentHost();
    if (config.getDeploymentContext() != null) {
      baseURL += config.getDeploymentContext();
    }
    else if ((config.getLabel() != null) && (!"".equals(config.getLabel()))) {
      //we don't have a default context set, so we'll just guess that it's the project label.
      baseURL += ("/" + config.getLabel());
    }
    model.setBaseDeploymentAddress(baseURL);

    List<EnunciateTypeDeclarationListener> typeDeclarationListeners = new ArrayList<EnunciateTypeDeclarationListener>();
    for (DeploymentModule module : config.getAllModules()) {
      if (module instanceof EnunciateTypeDeclarationListener) {
        typeDeclarationListeners.add((EnunciateTypeDeclarationListener) module);
      }
    }

    debug("Reading classes to enunciate...");
    final List<EndpointInterface> eis = new ArrayList<EndpointInterface>();
    for (TypeDeclaration declaration : typeDeclarations) {
      final boolean isEndpointInterface = isEndpointInterface(declaration);
      final boolean isJAXRSRootResource = isJAXRSRootResource(declaration);
      final boolean isJAXRSSupport = isJAXRSSupport(declaration);
      if (isEndpointInterface || isJAXRSRootResource || isJAXRSSupport) {
        if (isEndpointInterface) {
          EndpointInterface endpointInterface = new EndpointInterface(declaration, additionalApiDefinitions);
          debug("%s to be considered as an endpoint interface.", declaration.getQualifiedName());
          for (EndpointImplementation implementation : endpointInterface.getEndpointImplementations()) {
            debug("%s is the implementation of endpoint interface %s.", implementation.getQualifiedName(), endpointInterface.getQualifiedName());
          }
          eis.add(endpointInterface);
        }

        if (isJAXRSRootResource) {
          RootResource rootResource = new RootResource(declaration);
          debug("%s to be considered as a JAX-RS root resource.", declaration.getQualifiedName());
          model.add(rootResource);
        }

        if (isJAXRSSupport) {
          if (declaration.getAnnotation(Provider.class) != null) {
            debug("%s to be considered as a JAX-RS provider.", declaration.getQualifiedName());
            model.addJAXRSProvider(declaration);
          }
          else {
            debug("%s to be considered a JAX-RS support class.", declaration.getQualifiedName());
          }
        }
      }
      else if (isRegistry(declaration)) {
        debug("%s to be considered as an XML registry.", declaration.getQualifiedName());
        Registry registry = new Registry((ClassDeclaration) declaration);
        model.add(registry);
      }
      else if (isJAXRSApplication(declaration)) {
        debug("%s is identified as a JAX-RS Application class.", declaration.getQualifiedName());
        ApplicationPath applicationPath = declaration.getAnnotation(ApplicationPath.class);
        if (applicationPath != null) {
          try {
            URI uri = URI.create(applicationPath.value());
            String path = uri.getPath();
            if (config.getDeploymentContext() != null && path.startsWith(config.getDeploymentContext())) {
              path = path.substring(config.getDeploymentContext().length());
            }
            config.setDefaultRestSubcontextConditionally(path);
          }
          catch (Exception e) {
            warn("Invalid URI: %s (%s)", applicationPath.value(), e.getMessage());
          }
        }
View Full Code Here

   * Remove any classes that are explicitly exluded from this (presumably modifiable) collection.
   *
   * @param typeDeclarations the declarations.
   */
  protected void removeExcludedClasses(Collection<TypeDeclaration> typeDeclarations) {
    EnunciateConfiguration config = this.enunciate.getConfig();
    AntPatternMatcher matcher = new AntPatternMatcher();
    matcher.setPathSeparator(".");
    if (!config.getApiExcludePatterns().isEmpty()) {
      Iterator<TypeDeclaration> typeDeclarationIt = typeDeclarations.iterator();
      while (typeDeclarationIt.hasNext()) {
        TypeDeclaration typeDeclaration = typeDeclarationIt.next();
        boolean exclude = false;
        if (config.getApiExcludePatterns().contains(typeDeclaration.getQualifiedName())) {
          exclude = true;
          debug("%s was explicitly excluded.", typeDeclaration.getQualifiedName());
        }
        else {
          for (String excludePattern : config.getApiExcludePatterns()) {
            if (matcher.match(excludePattern, typeDeclaration.getQualifiedName())) {
              exclude = true;
              debug("%s matches exclude pattern %s.", typeDeclaration.getQualifiedName(), excludePattern);
              break;
            }
View Full Code Here

   * Trim any classes that are not explicitly included from this (presumably modifiable) collection.
   *
   * @param typeDeclarations The declarations.
   */
  protected void trimNotIncludedClasses(Collection<TypeDeclaration> typeDeclarations) {
    EnunciateConfiguration config = this.enunciate.getConfig();
    AntPatternMatcher matcher = new AntPatternMatcher();
    matcher.setPathSeparator(".");
    if (!config.getApiIncludePatterns().isEmpty()) {
      Iterator<TypeDeclaration> typeDeclarationIt = typeDeclarations.iterator();
      while (typeDeclarationIt.hasNext()) {
        TypeDeclaration typeDeclaration = typeDeclarationIt.next();
        boolean include = false;
        if (config.getApiIncludePatterns().contains(typeDeclaration.getQualifiedName())) {
          include = true;
          debug("%s was explicitly included.", typeDeclaration.getQualifiedName());
        }
        else {
          for (String includePattern : config.getApiIncludePatterns()) {
            if (matcher.match(includePattern, typeDeclaration.getQualifiedName())) {
              include = true;
              debug("%s matches include pattern %s.", typeDeclaration.getQualifiedName(), includePattern);
              break;
            }
View Full Code Here

TOP

Related Classes of org.codehaus.enunciate.config.EnunciateConfiguration

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.