@Override
  public void deploy(DeploymentUnit unit) throws DeploymentException {
    TorqueBoxMetaData externalMetaData =
        unit.getAttachment(TorqueBoxMetaData.EXTERNAL, TorqueBoxMetaData.class);
    if (log.isTraceEnabled()) {
      log.trace("External: " + externalMetaData);
    }

    if (externalMetaData == null) {
      return;
    }

    TorqueBoxMetaData metaData = unit.getAttachment(TorqueBoxMetaData.class);
    if (log.isTraceEnabled()) {
      log.trace("Internal: " + metaData);
    }

    if (metaData == null) {
      unit.addAttachment(TorqueBoxMetaData.class, externalMetaData);
      return;
    }
    try {
      TorqueBoxMetaData mergedMetaData = externalMetaData.overlayOnto(metaData);
      if (log.isTraceEnabled()) {
        log.trace("Merged: " + mergedMetaData);
      }
      unit.addAttachment(TorqueBoxMetaData.class, mergedMetaData);
    } catch (ClassCastException e) {
      throw new DeploymentException(
          "Incompatible structures in external and internal deployment descriptors", e);
    }
  }
  public void deploy(DeploymentUnit unit) throws DeploymentException {
    Set<? extends RubyEndpointMetaData> allMetaData =
        unit.getAllMetaData(RubyEndpointMetaData.class);

    if (allMetaData.size() == 0) {
      return;
    }

    log.debug("deploying for: " + unit);

    BeanMetaData busMetaData =
        unit.getAttachment(BeanMetaData.class + "$cxf.bus", BeanMetaData.class);

    RubyDynamicClassLoader classLoader = unit.getAttachment(RubyDynamicClassLoader.class);

    for (RubyEndpointMetaData endpointMetaData : allMetaData) {
      String beanName = getBeanName(unit, endpointMetaData.getName());
      BeanMetaDataBuilder builder =
          BeanMetaDataBuilder.createBuilder(beanName, RubyTypeSpace.class.getName());

      builder.addPropertyMetaData("rubyPath", "jboss/databinding/" + endpointMetaData.getName());
      builder.addPropertyMetaData("wsdlLocation", endpointMetaData.getWsdlLocation());
      builder.addPropertyMetaData("rubyDynamicClassLoader", classLoader);

      ValueMetaData busInjection = builder.createInject(busMetaData.getName());
      builder.addPropertyMetaData("bus", busInjection);

      BeanMetaData beanMetaData = builder.getBeanMetaData();
      unit.addAttachment(
          BeanMetaData.class.getName() + "$databinding." + endpointMetaData.getName(),
          beanMetaData,
          BeanMetaData.class);
    }
  }
  @Override
  protected void internalDeploy(DeploymentUnit unit) throws DeploymentException {
    if (!isJavaEEModule(unit)) return;

    // appName is either the name of the JavaEE application or null for a stand-alone JavaEE module
    String appName = informer.getApplicationName(unit);
    String moduleName = informer.getModuleName(unit);

    // create JavaEEModule bean
    String name = "jboss.naming:";
    if (appName != null) name += "application=" + appName + ",";
    name += "module=" + moduleName;
    BeanMetaDataBuilder builder =
        BeanMetaDataBuilderFactory.createBuilder(name, MCJavaEEModule.class.getName())
            //         .addAnnotation(annotation(DeploymentScope.class, moduleName))
            .addConstructorParameter(String.class.getName(), moduleName)
        //         .addAlias("java:module")
        ;
    if (appName != null) {
      //         builder.addAnnotation(annotation(ApplicationScope.class, appName));
      //         AbstractInjectionValueMetaData javaApp = new
      // AbstractInjectionValueMetaData("java:app");
      //         javaApp.setSearch(new ParentsLookupStrategy());
      AbstractInjectionValueMetaData javaApp =
          new AbstractInjectionValueMetaData("jboss.naming:application=" + appName);
      builder.addConstructorParameter(JavaEEApplication.class.getName(), javaApp);
    } else builder.addConstructorParameter(JavaEEApplication.class.getName(), (Object) null);
    builder.addPropertyMetaData("nameSpaces", builder.createInject("NameSpaces"));

    unit.addAttachment(BeanMetaData.class + "." + name, builder.getBeanMetaData());
  }
 protected static void addTestComponent(DeploymentUnit unit, TestComponentMetaData test) {
   DeploymentUnit component = unit.addComponent(test.name);
   component.addAttachment(TestComponentMetaData.class, test);
 }
  /**
   * Creates a {@link NoInterfaceViewJNDIBinderFacade} MC bean for the no-interface view represented
   * by the <code>sessionBeanMetaData</code>. The {@link NoInterfaceViewJNDIBinderFacade} is created
   * only if the bean is eligible for a no-interface view as defined by the EJB3.1 spec
   *
   * <p>The {@link NoInterfaceViewJNDIBinderFacade}, thus created, will be dependent on the {@link
   * ControllerState#DESCRIBED} state of the container (endpoint) MC bean. This way, we ensure that
   * this {@link NoInterfaceViewJNDIBinderFacade} will be deployed only after the corresponding
   * container MC bean moves to {@link ControllerState#DESCRIBED} state.
   *
   * @param unit Deployment unit
   * @param sessionBeanMetaData Session bean metadata
   * @throws DeploymentException If any exceptions are encountered during processing of the
   *     deployment unit
   */
  private void deploy(DeploymentUnit unit, JBossSessionBean31MetaData sessionBeanMetaData)
      throws DeploymentException {
    try {
      if (!sessionBeanMetaData.isNoInterfaceBean()) {
        if (logger.isTraceEnabled()) {
          logger.trace(
              "Bean class "
                  + sessionBeanMetaData.getEjbClass()
                  + " is not eligible for no-interface view");
        }
        return;
      }
      Class<?> beanClass =
          Class.forName(sessionBeanMetaData.getEjbClass(), false, unit.getClassLoader());

      String containerMCBeanName = sessionBeanMetaData.getContainerName();
      if (logger.isTraceEnabled()) {
        logger.trace(
            "Container name for bean "
                + sessionBeanMetaData.getEjbName()
                + " in unit "
                + unit
                + " is "
                + containerMCBeanName);
      }
      if (containerMCBeanName == null) {
        // The container name is set in the metadata only after the creation of the container
        // However, this deployer does not have an dependency on the creation of a container,
        // so getting the container name from the bean metadata won't work. Need to do a
        // different/better way
        // String containerMCBeanName = sessionBeanMetaData.getContainerName();
        containerMCBeanName = getContainerName(unit, sessionBeanMetaData);
      }

      // Create the NoInterfaceViewJNDIBinder (MC bean) and add a dependency on the DESCRIBED
      // state of the container (endpoint) MC bean
      NoInterfaceViewJNDIBinderFacade noInterfaceViewJNDIBinderFacade =
          new NoInterfaceViewJNDIBinderFacade(new InitialContext(), beanClass, sessionBeanMetaData);
      String noInterfaceViewMCBeanName = unit.getName() + "$" + sessionBeanMetaData.getEjbName();
      BeanMetaDataBuilder builder =
          BeanMetaDataBuilder.createBuilder(
              noInterfaceViewMCBeanName, noInterfaceViewJNDIBinderFacade.getClass().getName());
      builder.setConstructorValue(noInterfaceViewJNDIBinderFacade);

      // add dependency
      AbstractInjectionValueMetaData injectMetaData =
          new AbstractInjectionValueMetaData(containerMCBeanName);
      // EJBTHREE-2166 - Depending on DESCRIBED state and then pushing to INSTALLED
      // through MC API, won't work. So for now, just depend on INSTALLED state.
      // injectMetaData.setDependentState(ControllerState.DESCRIBED);
      injectMetaData.setDependentState(ControllerState.INSTALLED);
      injectMetaData.setFromContext(FromContext.CONTEXT);

      // Too bad we have to know the field name. Need to do more research on MC to see if we can
      // add property metadata based on type instead of field name.
      builder.addPropertyMetaData("endpointContext", injectMetaData);

      // Add this as an attachment
      unit.addAttachment(
          BeanMetaData.class + ":" + noInterfaceViewMCBeanName, builder.getBeanMetaData());

      logger.debug(
          "No-interface JNDI binder for container "
              + containerMCBeanName
              + " has been created and added to the deployment unit "
              + unit);

    } catch (Throwable t) {
      DeploymentException.rethrowAsDeploymentException(
          "Could not create no-interface view for "
              + sessionBeanMetaData.getEjbClass()
              + " in unit "
              + unit.getName(),
          t);
    }
  }