/**
   * Removes the old properties from the provided services and propagate new properties.
   *
   * @param newProps : new properties to propagate
   * @param oldProps : old properties to remove
   */
  private void propagate(Dictionary newProps, Dictionary oldProps) {
    if (m_mustPropagate && m_providedServiceHandler != null) {
      if (oldProps != null) {
        m_providedServiceHandler.removeProperties(oldProps);
      }

      if (newProps != null) {
        // Remove the name, the pid and the managed service pid props
        newProps.remove("name");
        newProps.remove("managed.service.pid");
        newProps.remove(Constants.SERVICE_PID);
        // Propagation of the properties to service registrations :
        m_providedServiceHandler.addProperties(newProps);
      }
    }
  }
示例#2
0
  public void execute(Session session, String line, PrintStream out, PrintStream err) {
    // Parse command line.
    StringTokenizer st = new StringTokenizer(line, " ");

    // Ignore the command name.
    st.nextToken();

    // Check for optional argument.
    String property = null;
    if (st.countTokens() >= 1) {
      property = st.nextToken().trim();
    }

    try {
      if (session.getAttribute(Activator.CURRENT) == null) {
        throw new Exception("No configuration open currently");
      }
      Dictionary dict = (Dictionary) session.getAttribute(Activator.EDITED);
      if (dict == null) {
        Configuration cfg = (Configuration) session.getAttribute(Activator.CURRENT);
        dict = cfg.getProperties();
        session.setAttribute(Activator.EDITED, dict);
      }
      Object oldValue = dict.remove(property);
      if (oldValue == null) {
        throw new Exception("No property named " + property + " in current configuration.");
      }
    } catch (Exception e) {
      out.println("Unset failed. Details:");
      String reason = e.getMessage();
      out.println(reason == null ? "<unknown>: " + e.toString() : reason);
    }
  }
示例#3
0
 protected void doExecute(ConfigurationAdmin admin) throws Exception {
   Dictionary props = getEditedProps();
   if (props == null) {
     System.err.println("No configuration is being edited. Run the edit command first");
   } else {
     props.remove(prop);
   }
 }
  private String getProperty(Dictionary props, String name, String defValue) {
    Object value = props.remove(name);
    if (value == null) {
      value = this.context.getProperty(name);
    }

    return value != null ? String.valueOf(value) : defValue;
  }
示例#5
0
 @SuppressWarnings("unchecked")
 private void updateSystemProperties(Dictionary properties) {
   properties.put(Constants.SERVICE_PID, this.pid);
   if (this.factoryPid == null) {
     properties.remove(ConfigurationAdmin.SERVICE_FACTORYPID);
   } else {
     properties.put(ConfigurationAdmin.SERVICE_FACTORYPID, this.factoryPid);
   }
 }
示例#6
0
    @Override
    public boolean matches(Object object) {
      if ((object == null) || !(object instanceof Dictionary)) {
        return false;
      }

      @SuppressWarnings("unchecked")
      Dictionary<String, Object> properties = (Dictionary<String, Object>) object;

      if (properties.get("service.pid") == null) {
        return false;
      }

      if (!((String) properties.get("service.pid")).startsWith(factoryPid)) {
        return false;
      }

      properties.remove("service.pid");

      return super.matches(properties);
    }
 private String[] getStringArrayProperty(Dictionary props, String name, String[] defValue) {
   Object value = props.remove(name);
   if (value == null) {
     value = this.context.getProperty(name);
   }
   if (value instanceof String) {
     return new String[] {(String) value};
   } else if (value instanceof String[]) {
     return (String[]) value;
   } else if (value instanceof Collection) {
     ArrayList<String> conv = new ArrayList<String>();
     for (Iterator<?> vi = ((Collection<?>) value).iterator(); vi.hasNext(); ) {
       Object object = vi.next();
       if (object != null) {
         conv.add(String.valueOf(object));
       }
     }
     return conv.toArray(new String[conv.size()]);
   } else {
     return defValue;
   }
 }
示例#8
0
  DynamicBindings(BundleContext bundleContext, PersistenceManager persistenceManager)
      throws IOException {
    this.persistenceManager = persistenceManager;

    if (persistenceManager.exists(BINDINGS_FILE_NAME)) {
      this.bindings = persistenceManager.load(BINDINGS_FILE_NAME);

      // get locations of installed bundles to validate the bindings
      final HashSet locations = new HashSet();
      final Bundle[] bundles = bundleContext.getBundles();
      for (int i = 0; i < bundles.length; i++) {
        locations.add(bundles[i].getLocation());
      }

      // collect pids whose location is not installed any more
      ArrayList removedKeys = new ArrayList();
      for (Enumeration ke = bindings.keys(); ke.hasMoreElements(); ) {
        final String pid = (String) ke.nextElement();
        final String location = (String) bindings.get(pid);
        if (!locations.contains(location)) {
          removedKeys.add(pid);
        }
      }

      // if some bindings had to be removed, store the mapping again
      if (removedKeys.size() > 0) {
        // remove invalid mappings
        for (Iterator rki = removedKeys.iterator(); rki.hasNext(); ) {
          bindings.remove(rki.next());
        }

        // store the modified map
        persistenceManager.store(BINDINGS_FILE_NAME, bindings);
      }
    } else {
      this.bindings = new Hashtable();
    }
  }
  @Override
  public void setConfiguration(String configuration) {
    try {
      Properties props = new Properties();
      props.load(new StringReader(configuration));

      String strategy = getStrategy();
      BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
      ServiceReference<ConfigurationAdmin> sr =
          bundleContext.getServiceReference(ConfigurationAdmin.class);
      ConfigurationAdmin ca = bundleContext.getService(sr);
      if (ca != null) {
        Configuration config = ca.getConfiguration(Activator.INSIGHT_CAMEL_PID);
        Dictionary<String, Object> dic = config.getProperties();
        if (dic == null) {
          dic = new Hashtable<String, Object>();
        }
        Set<String> s = new HashSet<String>();
        for (Enumeration<String> keyEnum = dic.keys(); keyEnum.hasMoreElements(); ) {
          String key = keyEnum.nextElement();
          if (key.startsWith(strategy + ".")) {
            s.add(key);
          }
        }
        for (String key : s) {
          dic.remove(key);
        }
        for (String key : props.stringPropertyNames()) {
          dic.put(strategy + "." + key, props.getProperty(key));
        }
        config.update(dic);
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
 public String remove(Object key) {
   return headers.remove(key);
 }
  @SuppressWarnings("unchecked")
  @Override
  public void updateSettings(SettingsCommand command) {
    // group all updates by provider+instance, to reduce the number of CA updates
    // when multiple settings are changed
    if (command.getProviderKey() == null) {
      Map<String, SettingsCommand> groups = new LinkedHashMap<String, SettingsCommand>(8);
      Map<String, SettingsCommand> indexedGroups = null;
      for (SettingValueBean bean : command.getValues()) {
        String groupKey =
            bean.getProviderKey() + (bean.getInstanceKey() == null ? "" : bean.getInstanceKey());
        final boolean indexed = INDEXED_PROP_PATTERN.matcher(bean.getKey()).find();
        SettingsCommand cmd = null;
        if (indexed) {
          // indexed property, add in indexed groups
          if (indexedGroups == null) {
            indexedGroups = new LinkedHashMap<String, SettingsCommand>(8);
          }
          cmd = indexedGroups.get(groupKey);
        } else {
          cmd = groups.get(groupKey);
        }

        if (cmd == null) {
          cmd = new SettingsCommand();
          cmd.setProviderKey(bean.getProviderKey());
          cmd.setInstanceKey(bean.getInstanceKey());
          if (indexed) {
            indexedGroups.put(groupKey, cmd);
          } else {
            groups.put(groupKey, cmd);
          }
        }
        cmd.getValues().add(bean);
      }
      for (SettingsCommand cmd : groups.values()) {
        updateSettings(cmd);
      }
      if (indexedGroups != null) {
        for (SettingsCommand cmd : indexedGroups.values()) {
          updateSettings(cmd);
        }
      }
      return;
    }

    try {
      Configuration conf = getConfiguration(command.getProviderKey(), command.getInstanceKey());
      Dictionary<String, Object> props = conf.getProperties();
      if (props == null) {
        props = new Hashtable<String, Object>();
      }
      for (SettingValueBean bean : command.getValues()) {
        String settingKey = command.getProviderKey();
        String instanceKey = command.getInstanceKey();
        if (instanceKey != null) {
          settingKey = getFactoryInstanceSettingKey(settingKey, instanceKey);
        }
        if (bean.isRemove()) {
          props.remove(bean.getKey());
        } else {
          props.put(bean.getKey(), bean.getValue());
        }

        if (!bean.isTransient()) {
          if (bean.isRemove()) {
            settingDao.deleteSetting(settingKey, bean.getKey());
          } else {
            settingDao.storeSetting(settingKey, bean.getKey(), bean.getValue());
          }
        }
      }
      if (conf != null && props != null) {
        if (command.getInstanceKey() != null) {
          props.put(OSGI_PROPERTY_KEY_FACTORY_INSTANCE_KEY, command.getInstanceKey());
        }
        conf.update(props);
      }

    } catch (IOException e) {
      throw new RuntimeException(e);
    } catch (InvalidSyntaxException e) {
      throw new RuntimeException(e);
    }
  }
 public void removeAttribute(String attributeName) {
   Dictionary<String, Object> attributes = proxyContext.getContextAttributes(httpContext);
   attributes.remove(attributeName);
 }
示例#13
0
  public static int[] getShortestPath(double budget, int[] sequence) {

    Dictionary<Integer, String> places1 = new Hashtable<Integer, String>();
    places1.put(0, "MBS");
    places1.put(1, "GBTB");
    places1.put(2, "SF");
    places1.put(3, "TP");
    places1.put(4, "BTRT");
    places1.put(5, "SGR");
    places1.put(6, "VC");
    places1.put(7, "RWS");
    places1.put(8, "JBP");
    places1.put(9, "ZOO");

    Dictionary<Integer, String> places2 = new Hashtable<Integer, String>();
    places2.put(0, "MBS");
    places2.put(1, "GBTB");
    places2.put(2, "SF");
    places2.put(3, "TP");
    places2.put(4, "BTRT");
    places2.put(5, "SGR");
    places2.put(6, "VC");
    places2.put(7, "RWS");
    places2.put(8, "JBP");
    places2.put(9, "ZOO");

    HashMap<Integer, Double[][]> hm = new HashMap<Integer, Double[][]>();
    // HARDCODED SHORTEST PATH ---- MBS >> GBTB >> SF >> TP >> BTRT >> SGR >> VC >> RWS >> JBP >>
    // ZOO
    hm.put(
        0,
        new Double[][] {
          {0.0, 0.0},
          {0.00001, 0.7},
          {0.83, 17.0},
          {0.77, 11.0},
          {0.88, 19.0},
          {0.9, 18.0},
          {1.18, 26.0},
          {4.03, 35.0},
          {2.55, 58.0},
          {1.96, 84.0}
        }); // 0 MBS
    hm.put(
        1,
        new Double[][] {
          {0.0001, 7.0},
          {0.0, 0.0},
          {0.79, 13.0},
          {0.79, 14.0},
          {0.79, 19.0},
          {1.01, 21.0},
          {1.20, 21.0},
          {1.20, 33.0},
          {1.38, 59.0},
          {2.18, 56.0}
        }); // 1 GBTB
    hm.put(
        2,
        new Double[][] {
          {0.83, 17.0},
          {0.79, 10.0},
          {0.0, 0.0},
          {0.79, 8.0},
          {0.98, 24.0},
          {0.90, 17.0},
          {1.26, 31.0},
          {4.03, 38.0},
          {1.38, 59.0},
          {1.89, 85.0}
        }); // 2 SF
    hm.put(
        3,
        new Double[][] {
          {0.79, 12.0},
          {0.79, 16.0},
          {0.79, 10.0},
          {0.0, 0.0},
          {0.79, 10.0},
          {0.79, 13.0},
          {1.12, 19.0},
          {1.12, 30.0},
          {1.27, 66.0},
          {0.21, 50.0}
        }); // 3 TP
    hm.put(
        4,
        new Double[][] {
          {0.88, 18.0},
          {5.60, 4.0},
          {0.98, 23.0},
          {4.90, 3.0},
          {0.0, 0.0},
          {4.60, 3.0},
          {0.98, 19.0},
          {3.98, 28.0},
          {17.10, 15.0},
          {1.91, 83.0}
        }); // 4 BTRT
    hm.put(
        5,
        new Double[][] {
          {0.79, 19.0},
          {0.90, 20.0},
          {0.90, 17.0},
          {0.79, 13.0},
          {0.79, 12.0},
          {0.0, 0.0},
          {1.12, 21.0},
          {1.12, 36.0},
          {1.38, 58.0},
          {2.14, 48.0}
        }); // 5 SGR
    hm.put(
        6,
        new Double[][] {
          {1.18, 24.0},
          {1.12, 24.0},
          {1.26, 29.0},
          {0.79, 13.0},
          {0.98, 18.0},
          {1.01, 23.0},
          {0.0, 0.0},
          {2.0, 10.0},
          {1.9, 81.0},
          {1.99, 85.0}
        }); // 6 VC
    hm.put(
        7,
        new Double[][] {
          {1.18, 33.0},
          {1.12, 36.0},
          {1.26, 38.0},
          {1.12, 30.0},
          {0.98, 27.0},
          {1.01, 36.0},
          {3.0, 10.0},
          {0.0, 0.0},
          {1.7, 92.0},
          {1.99, 99.0}
        }); // 7 RWS
    hm.put(
        8,
        new Double[][] {
          {1.38, 63.0},
          {1.46, 64.0},
          {1.45, 65.0},
          {1.46, 59.0},
          {1.38, 59.0},
          {1.46, 60.0},
          {1.90, 73.0},
          {1.88, 79.0},
          {0.0, 0.0},
          {1.92, 68.0}
        }); // 8 JBP
    hm.put(
        9,
        new Double[][] {
          {1.88, 86.0},
          {1.42, 66.0},
          {1.96, 87.0},
          {1.27, 48.0},
          {1.91, 84.0},
          {1.27, 56.0},
          {2.11, 86.0},
          {4.99, 96.0},
          {1.88, 66.0},
          {0.0, 0.0}
        }); // 9 ZOO

    int j = 1;
    int k = 0;
    int tempKey = 0;
    int[] placesIWent = new int[11];
    placesIWent[10] = 0;

    int r = 1;
    double min = hm.get(k)[r][1]; // init min to be GBTB

    for (int i = 0; i <= 9; i++) { // to get 10 places in shortest path sequence
      hm.get(k)[0][1] = 100.0;
      min = hm.get(k)[0][1];
      j = k; // the index of the row need to be removed

      for (int u = 0; u <= 9; u++) { // find the shortest path between between 2 points.

        // System.out.println("U loop, Key before conditions :"+u);
        for (int m = 0; m < placesIWent.length; m++)
          // System.out.println(placesIWent[m]);

          if (places1.get(u) == null) {

            // System.out.println("Ignored :"+u);

          } else {

            // System.out.println("min :"+min+"  next value: "+hm.get(j)[u][1]);

            if (min >= hm.get(j)[u][1]
                && hm.get(j)[u][1] != 0
                && hm.get(j)[u][0] != 0) { // if the current min is larger than the next value
              // System.out.println("Next Value is smaller than min!");
              min = hm.get(j)[u][1]; // set current time to be next min
              // System.out.println("new min: "+min);
              tempKey = j; // var for index that gonna be removed
              k = u;
              // System.out.println("value k is " + k);
            }
            // else
            // System.out.println("something is wrong");
          }
      }

      // System.out.println("End Loop\n\n\n"+"Temp is " + tempKey);
      placesIWent[i] = j; // array that contains the places which have been reached.
      hm.remove(tempKey); // remove place visited
      places1.remove(tempKey);

      // System.out.println("key removed " + tempKey);
      // System.out.println("Going to " + places1.get(k));

      // System.out.println(hm.keySet().toString());

    }
    String seqPlaces = "";
    String seqPlaces1 = "";
    for (int w = 0; w < placesIWent.length; w++) {
      if (w == placesIWent.length - 1) seqPlaces += places2.get(placesIWent[w]);
      else seqPlaces += places2.get(placesIWent[w]) + " >>> ";
      seqPlaces1 += "  " + placesIWent[w] + "     ";
    }
    System.out.println(seqPlaces1);
    System.out.println(seqPlaces);

    return placesIWent;
  }