Exemple #1
0
  /* package */ @SuppressWarnings({"unchecked"})
  void register() {
    ServiceLocator locator = getServiceLocator();

    ActiveDescriptor<?> myselfReified = locator.reifyDescriptor(this);

    DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
    DynamicConfiguration dc = dcs.createDynamicConfiguration();

    //        habitat.add(this);
    HK2Loader loader = this.model.classLoaderHolder;

    Set<Type> ctrs = new HashSet<Type>();
    ctrs.add(myselfReified.getImplementationClass());

    if (ConfigBean.class.isAssignableFrom(this.getClass())) {
      ctrs.add(ConfigBean.class);
    }

    DomDescriptor<Dom> domDesc =
        new DomDescriptor<Dom>(
            this, ctrs, Singleton.class, getImplementation(), new HashSet<Annotation>());
    domDesc.setLoader(loader);
    domDescriptor = dc.addActiveDescriptor(domDesc, false);

    String key = getKey();
    for (String contract : model.contracts) {
      ActiveDescriptor<Dom> alias = new AliasDescriptor<Dom>(locator, domDescriptor, contract, key);
      dc.addActiveDescriptor(alias, false);
    }
    if (key != null) {
      ActiveDescriptor<Dom> alias =
          new AliasDescriptor<Dom>(locator, domDescriptor, model.targetTypeName, key);
      dc.addActiveDescriptor(alias, false);
    }

    dc.commit();

    serviceHandle = getHabitat().getServiceHandle(domDescriptor);
  }
  @Override
  public void configure(DynamicConfiguration config) {
    config.addActiveDescriptor(ServerDataCommand.class);
    config.addActiveDescriptor(ClientDataCommand.class);
    config.addActiveDescriptor(ClientHealthCommand.class);
    config.addActiveDescriptor(ServerHealthCommand.class);
    config.addActiveDescriptor(ListCommandCommand.class);

    config.addActiveDescriptor(TractorElephantShoe.class);
    config.addActiveDescriptor(UnknownToy.class);
    config.addActiveDescriptor(JustShoe.class);
    config.addActiveDescriptor(ToyService.class);
  }
 /* (non-Javadoc)
  * @see org.glassfish.hk2.tests.locator.utilities.TestModule#configure(org.glassfish.hk2.api.DynamicConfiguration)
  */
 @Override
 public void configure(DynamicConfiguration config) {
   config.addActiveDescriptor(SimpleSingleton.class);
 }