Пример #1
0
  @Override
  public void updateResource(
      final String archiveName, final Map<String, byte[]> replacedResources) {
    final ModuleIdentifier moduleId = getModuleIdentifier(archiveName);
    final ModuleClassLoader loader = loadersByModuleIdentifier.get(moduleId);
    if (loader == null) {
      return;
    }

    final DeploymentUnit deploymentUnit =
        (DeploymentUnit)
            CurrentServiceRegistry.getServiceRegistry()
                .getRequiredService(Services.deploymentUnitName(archiveName))
                .getValue();
    final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);

    for (final Map.Entry<String, byte[]> entry : replacedResources.entrySet()) {
      final VirtualFile file = root.getRoot().getChild(entry.getKey());
      try {
        final FileOutputStream stream = new FileOutputStream(file.getPhysicalFile(), false);
        try {
          stream.write(entry.getValue());
        } finally {
          stream.close();
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
  @Override
  public <T> T getBusinessObject(SessionContext ctx, Class<T> businessInterface)
      throws IllegalStateException {
    if (businessInterface == null) {
      throw new IllegalStateException("Business interface type cannot be null");
    }

    final Serializable sessionId =
        ((SessionBeanComponentInstance.SessionBeanComponentInstanceContext) ctx).getId();

    if (viewServices.containsKey(businessInterface.getName())) {
      final ServiceController<?> serviceController =
          CurrentServiceRegistry.getServiceRegistry()
              .getRequiredService(viewServices.get(businessInterface.getName()));
      final ComponentView view = (ComponentView) serviceController.getValue();
      final ComponentViewInstance instance;
      if (sessionId != null) {
        instance =
            view.createInstance(
                Collections.<Object, Object>singletonMap(
                    StatefulSessionComponent.SESSION_ATTACH_KEY, sessionId));
      } else {
        instance = view.createInstance();
      }
      return (T) instance.createProxy();
    } else {
      throw new IllegalStateException(
          "View of type " + businessInterface + " not found on bean " + this);
    }
  }
Пример #3
0
  @Override
  public Set<String> getUpdatedResources(
      final String deploymentName, final Map<String, Long> updatedResources) {
    final ModuleIdentifier moduleId = getModuleIdentifier(deploymentName);
    final ModuleClassLoader loader = loadersByModuleIdentifier.get(moduleId);
    if (loader == null) {
      return Collections.emptySet();
    }

    final DeploymentUnit deploymentUnit =
        (DeploymentUnit)
            CurrentServiceRegistry.getServiceRegistry()
                .getRequiredService(Services.deploymentUnitName(deploymentName))
                .getValue();
    final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);

    final Set<String> resources = new HashSet<String>();
    for (final Map.Entry<String, Long> entry : updatedResources.entrySet()) {
      final VirtualFile file = root.getRoot().getChild(entry.getKey());
      if (file.exists()) {
        long last = file.getLastModified();
        if (entry.getValue() > last) {
          resources.add(entry.getKey());
        }
      }
    }
    return resources;
  }