Java Code Examples for org.osgi.service.cm.Configuration#getFactoryPid()

The following examples show how to use org.osgi.service.cm.Configuration#getFactoryPid() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CMDataWriter.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void writeConfigurations(final Configuration[] cs,
                                       final PrintWriter w)
{
  writeLines(PRE, w);
  for (final Configuration cfg : cs) {
    if (cfg.getFactoryPid() != null) {
      w.println("<factoryconfiguration factorypid=\"" + cfg.getFactoryPid()
                + "\" mode=\"update\">");
      writeProperties(cfg.getProperties(), w);
      w.println("</factoryconfiguration>");
    } else {
      w.println("<configuration pid=\"" + cfg.getPid() + "\" mode=\"new\">");
      writeProperties(cfg.getProperties(), w);
      w.println("</configuration>");
    }
  }
  writeLines(POST, w);
}
 
Example 2
Source File: CMCommands.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void printConfiguration(PrintWriter out,
                                Session session,
                                final Configuration cfg,
                                boolean printTypes)
    throws Exception
{
  final String pid = cfg.getPid();
  final int listIndex = getIndexOfPidInLastList(session, pid);
  out.print('[');
  out.print(listIndex > -1 ? String.valueOf(listIndex) : "-" );
  out.print("] ");
  out.println(pid);

  final String factoryPid = cfg.getFactoryPid();
  if (factoryPid != null) {
    out.print(" factory PID: ");
    out.println(factoryPid);
  }

  out.print(" location: ");
  final String location = cfg.getBundleLocation();
  out.println(location != null ? location : "-");

  out.print(" change count: ");
  out.println(cfg.getChangeCount());

  final Dictionary<String, Object> d = cfg.getProperties();
  out.println(" properties:");
  if (d == null) {
    out.println("  -");
  } else {
    printDictionary(out, d, printTypes);
  }
}
 
Example 3
Source File: ConfigurationBackupServiceImpl.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
private void storeConfigurations ( final ZipOutputStream zos, final List<Configuration> cfgs ) throws Exception
{
    zos.putNextEntry ( new ZipEntry ( CFG_FILE_NAME ) );

    final XmlHelper xml = new XmlHelper ();

    final Document doc = xml.create ();
    final Element root = doc.createElement ( "configuration" );
    doc.appendChild ( root );
    root.setAttribute ( "version", BACKUP_VERSION );

    for ( final Configuration cfg : cfgs )
    {
        final Element entry = XmlHelper.addElement ( root, "entry" );

        if ( cfg.getFactoryPid () != null )
        {
            entry.setAttribute ( "factoryPid", cfg.getFactoryPid () );
        }
        else if ( cfg.getPid () != null )
        {
            entry.setAttribute ( "pid", cfg.getPid () );
        }

        for ( final String key : Collections.list ( cfg.getProperties ().keys () ) )
        {
            final Object value = cfg.getProperties ().get ( key );
            final Element prop = XmlHelper.addElement ( entry, "property" );
            prop.setAttribute ( "key", key );
            if ( value != null )
            {
                prop.setAttribute ( "type", value.getClass ().getName () );
                prop.setTextContent ( value.toString () );
            }
        }
    }

    xml.write ( doc, zos );
    zos.closeEntry ();
}
 
Example 4
Source File: TargetPanel.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Load all targeted factory configuration instances and update user interface
 * to show them.
 *
 * @param selectedPid
 *          If this PID is available then select it, otherwise select the last
 *          PID. If {@link #nextFactoryPidToSelect} is non-null then select
 *          that configuration instance and set the field to {@code null}.
 */
private void updateSelectionFactoryPID(String selectedPid)
{
  synchronized (pid2Cfg) {
    pid2Cfg.clear();
    if (selectedPid == null) {
      selectedPid = "";
    }

    for (int i = 0; i < MAX_SIZE; i++) {
      try {
        final Configuration[] configs =
          CMDisplayer.getCA().listConfigurations("(service.factoryPid="
                                                     + targetedPids[i] + ")");
        if (configs != null) {
          for (final Configuration cfg : configs) {
            pid2Cfg.put(cfg.getPid(), cfg);
          }
        }
      } catch (final Exception e) {
        Activator.log
            .error("Faile to load factory configuration instances for fpid '"
                   + targetedPids[i] + "': " + e.getMessage(), e);
      }
    }

    final SortedSet<String> instancePIDs =
      new TreeSet<String>(pid2Cfg.keySet());
    instancePIDs.add(FACTORY_PID_DEFAULTS);

    final DefaultComboBoxModel model =
      new DefaultComboBoxModel(instancePIDs.toArray());
    if (nextFactoryPidToSelect != null) {
      if (instancePIDs.contains(nextFactoryPidToSelect)) {
        selectedPid = nextFactoryPidToSelect;
      }
      nextFactoryPidToSelect = null;
    } else if (!instancePIDs.contains(selectedPid)) {
      // New selection needed, use last PID.
      selectedPid = (String) model.getElementAt(model.getSize() - 1);
    }
    model.setSelectedItem(selectedPid);
    fbox.setModel(model);
    final Configuration selectedCfg = pid2Cfg.get(selectedPid);

    // Update the targeted PID selectors to match the target selectors in the
    // factory PID of the selected instance.
    final String fpid =
      selectedCfg != null ? selectedCfg.getFactoryPid() : targetedPids[0];
    String tpid = null;
    for (int i = 0; i < MAX_SIZE && null != (tpid = targetedPids[i]); i++) {
      rbs[i].setToolTipText(TARGET_LEVEL_FACOTRY_PID_TOOLTIPS[i] + tpid
                            + "</code></p></html>");

      if (fpid.equals(targetedPids[i])) {
        rbs[i].setSelected(true);
        selectedTargetLevel = i;
        if (selectedCfg != null) {
          icons[i].setIcon(openDocumentIcon);
          icons[i].setToolTipText("exists");
        } else {
          icons[i].setIcon(newDocumentIcon);
          icons[i].setToolTipText("to be created");
        }
      } else {
        icons[i].setIcon(newDocumentIcon);
        icons[i].setToolTipText("to be created");
      }
    }
  }
}