Exemple #1
0
  public static PetriNet convert(ConfigurableEPC baseEPC) {
    HashMap<EPCFunction, Transition> functionActivityMapping;
    HashMap<EPCConnector, Place> xorconnectorChoiceMapping;

    // HV: Initialize the mappings.
    functionActivityMapping = new HashMap<EPCFunction, Transition>();
    xorconnectorChoiceMapping = new HashMap<EPCConnector, Place>();

    // Check to use the weights if necessary
    // HV: Add both mappings. On completion, these will be filledd.
    PetriNet petrinet =
        EPCToPetriNetConverter.convert(
            baseEPC, new HashMap(), functionActivityMapping, xorconnectorChoiceMapping);

    HashSet visible = new HashSet();

    // HV: The next block is taken care of by the functionActivityMapping
    // below.
    /*
     * Iterator it = petrinet.getTransitions().iterator(); while
     * (it.hasNext()) { Transition t = (Transition) it.next(); if (t.object
     * instanceof EPCFunction) { // if (t.getLogEvent() != null) { // Add
     * transitions with LogEvent (i.e. referring to functions)
     * visible.add(t); } }
     */

    // HV: Prevent the places mapped onto from being reduced.
    visible.addAll(functionActivityMapping.values());
    visible.addAll(xorconnectorChoiceMapping.values());
    Message.add(visible.toString(), Message.DEBUG);

    Iterator it = petrinet.getPlaces().iterator();
    while (it.hasNext()) {
      Place p = (Place) it.next();
      if (p.inDegree() * p.outDegree() == 0) {
        // Add Initial and final places to visible, i.e. places that
        // refer to in and output events
        visible.add(p);
      }
    }

    // Reduce the PetriNet with Murata rules, while keeping the visible ones
    PetriNetReduction pnred = new PetriNetReduction();
    pnred.setNonReducableNodes(visible);

    HashMap pnMap = new HashMap(); // Used to map pre-reduction nodes to
    // post-reduction nodes.
    PetriNet reduced = pnred.reduce(petrinet, pnMap);

    if (reduced != petrinet) {
      // Update both mappings from pre-reduction nodes to post-reduction
      // nodes.
      HashMap<EPCFunction, Transition> newFunctionActivityMapping =
          new HashMap<EPCFunction, Transition>();
      for (EPCFunction function : functionActivityMapping.keySet()) {
        Transition transition = (Transition) functionActivityMapping.get(function);
        if (pnMap.keySet().contains(transition)) {
          newFunctionActivityMapping.put(function, (Transition) pnMap.get(transition));
        }
      }
      functionActivityMapping = newFunctionActivityMapping;
      HashMap<EPCConnector, Place> newXorconnectorChoiceMapping =
          new HashMap<EPCConnector, Place>();
      for (EPCConnector connector : xorconnectorChoiceMapping.keySet()) {
        Place place = (Place) xorconnectorChoiceMapping.get(connector);
        if (pnMap.keySet().contains(place)) {
          newXorconnectorChoiceMapping.put(connector, (Place) pnMap.get(place));
        }
      }
      xorconnectorChoiceMapping = newXorconnectorChoiceMapping;
    }
    reduced.makeClusters();

    // filter the \nunknown:normal
    ArrayList<Transition> alTrans = reduced.getVisibleTasks();
    for (int i = 0; i < alTrans.size(); i++) {
      Transition t = alTrans.get(i);
      String id = t.getIdentifier();
      int idx = id.indexOf("\\nunknown:normal");
      if (idx > 0) {
        id = id.substring(0, idx);
      }
      // �˴������ֵ��ѯ�滻���е�label
      String mappedId = htDict.get(id);
      if (mappedId != null) {
        t.setIdentifier(mappedId);
      } else {
        t.setIdentifier(id);
      }
    }

    return reduced;
  }
 public static void identifyDuplicateJars(
     List<File> jarFileListInDistribution,
     File distributionVersion,
     HashSet<String> distributionDuplicateJarList,
     ArrayList<String> unidentifiedVersionJars) {
   Iterator<File> itJarList = jarFileListInDistribution.iterator();
   ArrayList<String> tempArr = new ArrayList<String>();
   ArrayList<File> pathListForAddedJarToJarVersions = new ArrayList<File>();
   HashMap<String, String> jarVersions = new HashMap<String, String>();
   StringBuilder builder = new StringBuilder();
   Pattern numeric = Pattern.compile("[^0-9_.-]");
   Pattern nonNumeric = Pattern.compile("[a-zA-Z]");
   while (itJarList.hasNext()) {
     File jarFilePath = itJarList.next();
     String jarName = (jarFilePath).getName();
     if (!jarFilePath
         .getAbsolutePath()
         .contains(
             distributionVersion.getName().replaceAll(".zip", "")
                 + File.separator
                 + TEMP_DIRECTORY
                 + File.separator)) {
       for (int letter = jarName.length() - 1; letter >= 0; letter--) {
         char singleChar = jarName.charAt(letter);
         Matcher matcher = numeric.matcher(Character.toString(singleChar));
         // Find all matches
         if (!matcher.find()) {
           // Get the matching string
           builder.append(singleChar);
         } else if (nonNumeric.matcher(Character.toString(singleChar)).find()) {
           if (builder.length() > 1) {
             tempArr.add(builder.toString());
             builder.setLength(0);
           } else {
             builder.setLength(0);
           }
         }
       }
       int max;
       int previousMax = 0;
       String[] version = new String[1];
       for (String element : tempArr) {
         max = element.length();
         if (max > previousMax) {
           previousMax = max;
           version[0] = element;
         }
       }
       tempArr.clear();
       if (version[0] != null) {
         String jar = jarName.split((StringUtils.reverse(version[0])))[0];
         if (jar.length() >= 2) {
           if (jarVersions.containsKey(jar)) {
             if (!jarVersions.get(jar).equals(jarName.split(jar)[1])) {
               // removing patches - plugins duplication
               if (distributionDuplicateJarList.toString().contains(jarName)) {
                 for (String itemDistributionDuplicateJarList : distributionDuplicateJarList) {
                   if (itemDistributionDuplicateJarList.contains(jarName)
                       && (itemDistributionDuplicateJarList.contains("patches")
                           || itemDistributionDuplicateJarList.contains("plugins"))) {
                     if (!(jarFilePath.getAbsolutePath().contains("patches")
                         || jarFilePath.getAbsolutePath().contains("plugins"))) {
                       distributionDuplicateJarList.add(jarFilePath.getAbsolutePath());
                     }
                   }
                 }
               } else {
                 distributionDuplicateJarList.add(jarFilePath.getAbsolutePath());
               }
               for (File pathListForAddedJarToJarVersion : pathListForAddedJarToJarVersions) {
                 String path = pathListForAddedJarToJarVersion.toString();
                 if (path.contains(jar + jarVersions.get(jar))) {
                   distributionDuplicateJarList.add(path);
                   break;
                 }
               }
             }
           } else {
             jarVersions.put(jar, jarName.split(jar)[1]);
             pathListForAddedJarToJarVersions.add(jarFilePath);
           }
         } else {
           log.info("Unable to identify the version " + jar);
           unidentifiedVersionJars.add(jarFilePath.getAbsolutePath());
         }
       } else {
         jarVersions.put(jarName, null);
         pathListForAddedJarToJarVersions.add(jarFilePath);
       }
     }
   }
 }