/**
   * Creates new Web Service deployment.
   *
   * @param unit deployment unit
   * @return archive deployment
   */
  private ArchiveDeployment newDeployment(final DeploymentUnit unit) {
    ROOT_LOGGER.creatingUnifiedWebservicesDeploymentModel(unit);
    final ResourceRoot deploymentRoot = unit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    final VirtualFile root = deploymentRoot != null ? deploymentRoot.getRoot() : null;
    final ClassLoader classLoader;
    final Module module = unit.getAttachment(Attachments.MODULE);
    if (module == null) {
      classLoader = unit.getAttachment(CLASSLOADER_KEY);
      if (classLoader == null) {
        throw MESSAGES.classLoaderResolutionFailed(unit);
      }
    } else {
      classLoader = module.getClassLoader();
    }
    final ArchiveDeployment dep = this.newDeployment(unit.getName(), classLoader);

    if (unit.getParent() != null) {
      final String parentDeploymentName = unit.getParent().getName();
      final Module parentModule = unit.getParent().getAttachment(Attachments.MODULE);
      if (parentModule == null) {
        throw MESSAGES.classLoaderResolutionFailed(deploymentRoot);
      }
      final ClassLoader parentClassLoader = parentModule.getClassLoader();

      ROOT_LOGGER.creatingUnifiedWebservicesDeploymentModel(unit.getParent());
      final ArchiveDeployment parentDep =
          this.newDeployment(parentDeploymentName, parentClassLoader);
      dep.setParent(parentDep);
    }

    if (root != null) {
      dep.setRootFile(new VirtualFileAdaptor(root));
    } else {
      dep.setRootFile(new ResourceLoaderAdapter(classLoader));
    }
    dep.setRuntimeClassLoader(classLoader);
    dep.setType(deploymentType);

    return dep;
  }