public Set<String> getTargets() {
   Set<JavonMapping.Service> services = mapping.getServiceMappings();
   Set<String> targets = new HashSet<String>();
   for (JavonMapping.Service service : services) {
     targets.add(service.getType());
   }
   return Collections.unmodifiableSet(targets);
 }
  public boolean generateTarget(ProgressHandle ph, String target) {
    if (mapping.getServiceMapping(target) != null) {
      String msg = NbBundle.getMessage(ClientJavonTemplate.class, "MSG_Client"); // NOI18N
      ph.progress(msg);
      OutputLogger.getInstance().log(msg);
      mapping.setProperty("target", "client");

      JavonMapping.Service service = mapping.getServiceMapping(target);
      FileObject outputDir =
          FileUtil.toFileObject(
              FileUtil.normalizeFile(new File(mapping.getClientMapping().getOutputDirectory())));
      outputDir =
          outputDir.getFileObject(mapping.getClientMapping().getPackageName().replace('.', '/'));

      FileObject outputFile =
          outputDir.getFileObject(mapping.getClientMapping().getClassName(), "java");
      if (outputFile == null) {
        OutputLogger.getInstance()
            .log(
                MessageFormat.format(
                    NbBundle.getMessage(ClientJavonTemplate.class, "MSG_ClientJavonCreation"),
                    mapping.getClientMapping().getClassName())); // NOI18N
        try {
          outputFile = outputDir.createData(mapping.getClientMapping().getClassName(), "java");
        } catch (IOException e) {
          OutputLogger.getInstance()
              .log(
                  LogLevel.ERROR,
                  MessageFormat.format(
                      NbBundle.getMessage(ClientJavonTemplate.class, "MSG_FailClientJavonCreation"),
                      mapping.getClientMapping().getClassName())); // NOI18N
        }
      }
      OutputFileFormatter off = null;
      try {
        off = new OutputFileFormatter(outputFile);
      } catch (DataObjectNotFoundException e) {
        generationFailed(e, outputFile);
        return false;
      } catch (IOException e) {
        generationFailed(e, outputFile);
        return false;
      }

      ScriptEngineManager mgr = new ScriptEngineManager();
      ScriptEngine eng = mgr.getEngineByName("freemarker");
      Bindings bind = eng.getContext().getBindings(ScriptContext.ENGINE_SCOPE);

      FileObject template = FileUtil.getConfigFile("Templates/Client/Client.java");

      OutputLogger.getInstance()
          .log(NbBundle.getMessage(ClientJavonTemplate.class, "MSG_ConfigureBindings")); // NOI18N
      Set<ClassData> returnTypes = service.getReturnTypes();
      Set<ClassData> parameterTypes = service.getParameterTypes();
      bind.put("mapping", mapping);
      bind.put("registry", mapping.getRegistry());
      bind.put("returnTypes", returnTypes);
      bind.put("parameterTypes", parameterTypes);
      bind.put("service", service);
      bind.put("utils", new Utils(mapping.getRegistry()));

      // Compute imports for JavaBeans
      Set<String> imports = new HashSet<String>();
      for (ClassData cd : parameterTypes) {
        while (cd.isArray()) {
          cd = cd.getComponentType();
        }
        if (cd.isPrimitive()) continue;
        if (cd.getPackage().equals("java.lang")) continue;
        if (cd.getFullyQualifiedName().equals("java.util.List")) continue;
        imports.add(cd.getFullyQualifiedName());
      }
      for (ClassData cd : returnTypes) {
        while (cd.isArray()) {
          cd = cd.getComponentType();
        }
        if (cd.isPrimitive()) continue;
        if (cd.getPackage().equals("java.lang")) continue;
        if (cd.getFullyQualifiedName().equals("java.util.List")) continue;
        imports.add(cd.getFullyQualifiedName());
      }
      bind.put("imports", imports);

      OutputLogger.getInstance()
          .log(
              MessageFormat.format(
                  NbBundle.getMessage(ClientBeanGeneratorTemplate.class, "MSG_GenerateJavonClient"),
                  FileUtil.toFile(outputFile))); // NOI18N
      Writer w = null;
      Reader is = null;
      try {
        try {
          w = new StringWriter();
          is = new InputStreamReader(template.getInputStream());

          eng.getContext().setWriter(w);
          eng.getContext()
              .setAttribute(FileObject.class.getName(), template, ScriptContext.ENGINE_SCOPE);
          eng.getContext()
              .setAttribute(
                  ScriptEngine.FILENAME, template.getNameExt(), ScriptContext.ENGINE_SCOPE);

          eng.eval(is);
        } catch (FileNotFoundException e) {
          OutputLogger.getInstance().log(e);
          ErrorManager.getDefault().notify(e);
          return false;
        } catch (ScriptException e) {
          OutputLogger.getInstance().log(e);
          ErrorManager.getDefault().notify(e);
          return false;
        } finally {
          if (w != null) {
            off.write(w.toString());
            // System.err.println( "" + w.toString());
            w.close();
          }
          if (is != null) is.close();
          off.close();
        }
      } catch (IOException e) {
        generationFailed(e, FileUtil.toFile(outputFile));
        return false;
      }

      OutputLogger.getInstance()
          .log(
              MessageFormat.format(
                  NbBundle.getMessage(ClientJavonTemplate.class, "MSG_ClientGenerated"),
                  FileUtil.toFile(outputFile)));
    }
    return true;
  }