Beispiel #1
0
  /**
   * DOC smallet Comment method "createRoutine".
   *
   * @param url
   * @throws PersistenceException
   */
  private void createRoutine(URL url, IPath path, String label, List<LibraryInfo> neededJars)
      throws PersistenceException {
    if (url == null) {
      throw new IllegalArgumentException();
    }
    InputStream stream = null;
    try {
      Property property = PropertiesFactory.eINSTANCE.createProperty();
      property.setId(getNextId());
      property.setLabel(label);

      ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
      stream = url.openStream();
      byte[] innerContent = new byte[stream.available()];
      stream.read(innerContent);
      stream.close();
      byteArray.setInnerContent(innerContent);

      // String basePath = System.getProperty("user.dir") + File.separator + "plugins";

      RoutineItem routineItem = PropertiesFactory.eINSTANCE.createRoutineItem();
      routineItem.setProperty(property);
      routineItem.setContent(byteArray);
      routineItem.setBuiltIn(true);
      if (neededJars != null) {
        for (LibraryInfo jar : neededJars) {
          IMPORTType type = ComponentFactory.eINSTANCE.createIMPORTType();
          type.setMESSAGE("");
          type.setNAME(label);
          type.setREQUIRED(true);
          type.setMODULE(jar.getLibName());
          type.setBundleID(jar.getBundleId());
          routineItem.getImports().add(type);
        }
      }

      if (!routineItem.getProperty().getLabel().equals(coreSerivce.getTemplateString())) {
        create(getRepositoryContext().getProject(), routineItem, path, true);
      }
    } catch (IOException ioe) {
      if (stream != null) {
        try {
          stream.close();
        } catch (IOException e) {
          throw new PersistenceException(ioe);
        }
      }
      throw new PersistenceException(ioe);
    }
  }
Beispiel #2
0
  @Override
  public List<ModuleNeeded> getModulesNeededForJobs() throws PersistenceException {
    List<ModuleNeeded> importNeedsList = new ArrayList<ModuleNeeded>();
    IProxyRepositoryFactory repositoryFactory =
        CoreRuntimePlugin.getInstance().getRepositoryService().getProxyRepositoryFactory();
    ERepositoryObjectType jobType = ERepositoryObjectType.PROCESS;
    if (jobType != null) {
      List<IRepositoryViewObject> jobs = repositoryFactory.getAll(jobType, true);
      for (IRepositoryViewObject cur : jobs) {
        if (!cur.isDeleted()) {
          ProcessItem item = (ProcessItem) cur.getProperty().getItem();
          if (item == null || item.getProcess() == null) {
            continue;
          }
          List<NodeType> nodes = item.getProcess().getNode();
          for (NodeType node : nodes) {
            List<ElementParameterType> elementParameter = node.getElementParameter();
            for (ElementParameterType elementParam : elementParameter) {
              if (elementParam.getField() != null
                  && elementParam.getField().equals(EParameterFieldType.MODULE_LIST.getName())) {
                String uniquename = coreSerivce.getParameterUNIQUENAME(node);
                ModuleNeeded toAdd =
                    new ModuleNeeded(
                        Messages.getString("AbstractEMFRepositoryFactory.job")
                            + item.getProperty().getLabel(), // $NON-NLS-1$
                        elementParam.getValue(),
                        Messages.getString("AbstractEMFRepositoryFactory.requiredComponent")
                            + uniquename
                            + ".",
                        true); //$NON-NLS-1$ //$NON-NLS-2$
                importNeedsList.add(toAdd);
              }
            }
          }
        }
      }
    }

    return importNeedsList;
  }
Beispiel #3
0
  protected void createSystemRoutines() throws PersistenceException {
    ERepositoryObjectType routinesType = ERepositoryObjectType.ROUTINES;
    if (routinesType == null) {
      return; // don't load, nothing to do
    }
    ILibrariesService service = null;
    if (!GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
      return;
    }

    service =
        (ILibrariesService) GlobalServiceRegister.getDefault().getService(ILibrariesService.class);

    Project project = getRepositoryContext().getProject();
    FolderHelper folderHelper = getFolderHelper(project.getEmfProject());

    List<URL> routines = service.getSystemRoutines();
    Path path = new Path(RepositoryConstants.SYSTEM_DIRECTORY);
    // will automatically set the children folders
    IPath systemRoutinePath = new Path(ERepositoryObjectType.getFolderName(routinesType));
    systemRoutinePath = systemRoutinePath.append(RepositoryConstants.SYSTEM_DIRECTORY);
    FolderItem folderItem = folderHelper.getFolder(systemRoutinePath);
    if (folderItem == null) {
      folderItem = folderHelper.createFolder(systemRoutinePath.toString());
    }
    IPath systemRoutineApiPath = new Path(ERepositoryObjectType.getFolderName(routinesType));
    systemRoutineApiPath =
        systemRoutinePath.append(RepositoryConstants.SYSTEM_DIRECTORY).append("api");
    FolderItem folderItemApi = folderHelper.getFolder(systemRoutineApiPath);
    if (folderItemApi == null) {
      folderItemApi = folderHelper.createFolder(systemRoutineApiPath.toString());
    }

    List<IRepositoryViewObject> repositoryObjects = getAll(project, routinesType, false, false);
    Map<String, List<LibraryInfo>> routineAndJars = coreSerivce.getRoutineAndJars();
    for (URL url : routines) {
      String[] fragments = url.toString().split("/"); // $NON-NLS-1$
      String label = fragments[fragments.length - 1];
      String[] tmp = label.split("\\."); // $NON-NLS-1$
      String routineLabel = tmp[0];

      if (routineLabel.equals(coreSerivce.getTemplateString())) {
        continue;
      }

      RoutineItem existingItem = null;
      for (IRepositoryViewObject object : repositoryObjects) {
        if (object.getLabel().equals(routineLabel)
            && object.getProperty().getItem() instanceof RoutineItem) {
          existingItem = (RoutineItem) object.getProperty().getItem();
          break;
        }
      }
      if (existingItem == null) {
        createRoutine(
            url,
            path,
            routineLabel,
            routineAndJars != null ? routineAndJars.get(routineLabel) : null);
      } else {
        updateRoutine(url, existingItem);
        existingItem.setParent(folderItem);
      }
    }
  }