Java Code Examples for org.osgi.framework.BundleContext#getProperty()

The following examples show how to use org.osgi.framework.BundleContext#getProperty() . 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: HttpClientConnection.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
HttpClientConnection(final BundleContext bc,
                     final String url,
                     final int mode,
                     final boolean timeouts)
  throws URIException
{
  this.bc = bc;
  uri = new URI(url, false); // assume not escaped URIs
  ProxySelector.configureProxy(bc, client, url);

  final String timeoutString = bc.getProperty(TIMEOUT);
  if (timeoutString != null) {
    try {
      client.getParams().setSoTimeout(Integer.parseInt(timeoutString));
    } catch (NumberFormatException e) {
      throw new RuntimeException("Invalid timeout " + timeoutString);
    }
  }
}
 
Example 2
Source File: ConfigProperties.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
public static String getProperty(Class<?> classParam, final String propertyStr, final String defaultValue) {
    String value = ConfigProperties.OVERRIDES.get(propertyStr);
    if (value != null) {
        return value;
    }

    Bundle bundle = FrameworkUtil.getBundle(classParam);

    if (bundle != null) {
        BundleContext bundleContext = bundle.getBundleContext();
        if (bundleContext != null) {
            value = bundleContext.getProperty(propertyStr);
        }
    }
    if (value == null) {
        value = System.getProperty(propertyStr, defaultValue);
    }

    if (value == null) {
        LOG.debug("ConfigProperties missing a value for {}, default {}", propertyStr, defaultValue);
    }

    return value;
}
 
Example 3
Source File: TelnetConfig.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public TelnetConfig(BundleContext bc) throws ConfigurationException
{
  final String user = bc.getProperty("org.knopflerfish.consoletelnet.user");
  if (null != user && 0 < user.length()) {
    defaultUser = user;
  }

  final String pswd = bc.getProperty("org.knopflerfish.consoletelnet.pwd");
  if (null != pswd && 0 < pswd.length()) {
    defaultPassword = pswd;
  }

  final String bw = bc.getProperty("org.knopflerfish.consoletelnet.busywait");
  if (null != bw) {
    busyWait = bw.trim().equalsIgnoreCase("true");
  }

  final String po = bc.getProperty("org.knopflerfish.consoletelnet.port");
  if (null != po && 0 < po.length()) {
    try {
      port = Integer.parseInt(po);
    } catch (final Exception _e) {
    }
  }

  final String hp = bc.getProperty("org.knopflerfish.consoletelnet.host");
  if (null != hp) {
    host = hp;
  }

  configuration = TelnetConfig.getDefaultConfig();
  updated(configuration);
}
 
Example 4
Source File: FSPackageRegistry.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
/**
 * Deafult constructor for OSGi initialization (homeDir defined via activator)
 * @throws IOException 
 */
@Activate
public FSPackageRegistry(BundleContext context, Config config) throws IOException {
    this(
            context.getProperty(REPOSITORY_HOME) != null ? ( 
                    new File(config.homePath()).isAbsolute() ? new File(config.homePath()) : new File(context.getProperty(REPOSITORY_HOME) + "/" + config.homePath()))  
                  : context.getDataFile(config.homePath()),
            InstallationScope.valueOf(config.scope()),
            new AbstractPackageRegistry.SecurityConfig(config.authIdsForHookExecution(), config.authIdsForRootInstallation()));
    if (!homeDir.exists()) {
        homeDir.mkdirs();
    }
}
 
Example 5
Source File: RDF2GoActivator.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
 */
@Override
public void start(BundleContext context) throws Exception {
	this.bc = context;
	this.defaultFactoryClassName = context.getProperty(DEFAULTMODELFACTORY_CFG);
	this.bc.addServiceListener(this, MODEL_FACTORY_FILTER);
	initalizeListener();
}
 
Example 6
Source File: Config.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Boolean getBoolProperty(BundleContext bc, String p, Boolean def) {
  Boolean ret;
  
  final Object o = bc.getProperty(p);
  if (null != o)
    ret = new Boolean((String)o);
  else
    ret = def;
  
  Activator.logger.info( p + " : " + ret);
  return ret;
  
}
 
Example 7
Source File: Config.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Boolean getBoolProperty(BundleContext bc, String p, Boolean def) {
  Boolean ret;
  
  final Object o = bc.getProperty(p);
  if (null != o)
    ret = new Boolean((String)o);
  else
    ret = def;
  
  Activator.logger.info( p + " : " + ret);
  return ret;
  
}
 
Example 8
Source File: EventTableModel.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** The default constructor. */
public EventTableModel(BundleContext bc) {
  super();
  final String capacityS = bc.getProperty(CAPACITY_PROP_NAME);
  if (null!=capacityS && capacityS.length()>0) {
    try {
      capacity = Integer.parseInt(capacityS.trim());
    } catch (NumberFormatException nfe){
    }
  }
  if (capacity>0) {
    entries.ensureCapacity(capacity);
  }
}
 
Example 9
Source File: LogTableModel.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public LogTableModel(BundleContext bc) {
  super();

  final String capacityS = bc.getProperty(CAPACITY_PROP_NAME);
  if (null!=capacityS && capacityS.length()>0) {
    try {
      capacity = Integer.parseInt(capacityS.trim());
    } catch (NumberFormatException nfe){
    }
  }
  if (capacity>0) {
    entries.ensureCapacity(capacity);
  }
}
 
Example 10
Source File: Activator.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
SysPropMetatypeProvider(BundleContext bc)
{
  super("System properties");

  final Dictionary<String, Object> defProps = new Hashtable<String, Object>();

  final Properties sysProps = System.getProperties();

  for (final Enumeration<?> e = sysProps.keys(); e.hasMoreElements();) {
    final String key = (String) e.nextElement();
    // Use the local value for the current framework instance; props
    // that have not been exported with some value as system
    // properties will not be visible due to the limitation of
    // BundleContex.getProprty() on OSGi R4.
    final Object val = bc.getProperty(key);
    if (key.startsWith("java.") || key.startsWith("os.")
        || key.startsWith("sun.") || key.startsWith("awt.")
        || key.startsWith("user.")) {
      continue;
    }
    if (null != val) {
      defProps.put(key, val);
    }
  }

  spOCD = new OCD(PID, PID, "Java system properties", defProps);

  addService(PID, spOCD);
}
 
Example 11
Source File: Activator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override void start(final BundleContext context) throws Exception {
        if (System.getProperty("netbeans.home") != null) {
            throw new IllegalStateException("Should not be run from inside regular NetBeans module system");
        }
        String storage = context.getProperty(Constants.FRAMEWORK_STORAGE);
        if (storage != null) {
            System.setProperty("netbeans.user", storage);
        }
        System.setProperty("TopSecurityManager.disable", "true");
        NbBundle.setBranding(System.getProperty("branding.token"));
        OSGiMainLookup.initialize(context);
        queue = new DependencyQueue<String,Bundle>();
        this.context = context;
        framework = ((Framework) context.getBundle(0));
        if (framework.getState() == Bundle.STARTING) {
            LOG.fine("framework still starting");
            final AtomicReference<FrameworkListener> frameworkListener = new AtomicReference<FrameworkListener>();
            frameworkListener.set(new FrameworkListener() {
                public @Override void frameworkEvent(FrameworkEvent event) {
                    if (event.getType() == FrameworkEvent.STARTED) {
//                        System.err.println("framework started");
                        context.removeFrameworkListener(frameworkListener.get());
                        context.addBundleListener(Activator.this);
                        processLoadedBundles();
                    }
                }
            });
            context.addFrameworkListener(frameworkListener.get());
        } else {
            LOG.fine("framework already started");
            context.addBundleListener(this);
            processLoadedBundles();
        }
    }
 
Example 12
Source File: HttpConfig.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static String getPropertyAsString(BundleContext bc,
                                          String name,
                                          String defVal)
{
  final String val = bc.getProperty(name);
  return val == null ? defVal : val;
}
 
Example 13
Source File: HttpConfig.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Integer getPropertyAsInteger(BundleContext bc,
                                            String name,
                                            int defVal)
{
  final String val = bc.getProperty(name);
  return val == null ? new Integer(defVal) : Integer.valueOf(val);
}
 
Example 14
Source File: HttpConfig.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Boolean getPropertyAsBoolean(BundleContext bc,
                                            String name,
                                            boolean defVal)
{
  final String val = bc.getProperty(name);
  return val == null ? defVal : Boolean.valueOf(val);
}
 
Example 15
Source File: BasicDriverLocator.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
BasicDriverLocator(BundleContext bc)
{
  this.bc = bc;

  // Try to get log service and handle it's life cycle
  log = new LogRef(bc);

  final String jars = bc.getProperty("org.knopflerfish.gosg.jars");
  jarbase = (null == jars || jars.length() == 0) ? "file:" : jars;
}
 
Example 16
Source File: DelayedProbeInvokerFactory.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return Name of the real Pax-Exam {@link ProbeInvokerFactory}
 */
private static String getExamInvoker(final BundleContext context) {
  final String value = context.getProperty(NEXUS_PAX_EXAM_INVOKER_KEY);
  if (value == null || value.trim().length() == 0) {
    return NEXUS_PAX_EXAM_INVOKER_DEFAULT;
  }
  return value;
}
 
Example 17
Source File: DelayedProbeInvokerFactory.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return Timeout to apply when waiting for Nexus to start
 */
private static int getExamTimeout(final BundleContext context) {
  final String value = context.getProperty(NEXUS_PAX_EXAM_TIMEOUT_KEY);
  if (value == null || value.trim().length() == 0) {
    return NEXUS_PAX_EXAM_TIMEOUT_DEFAULT;
  }
  try {
    return Integer.parseInt(value);
  }
  catch (final NumberFormatException e) {
    return NEXUS_PAX_EXAM_TIMEOUT_DEFAULT;
  }
}
 
Example 18
Source File: LauncherActivator.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private static String checkProperty(final BundleContext bundleContext, final String name) {
  String value = bundleContext.getProperty(name);
  if (value == null || value.trim().isEmpty()) {
    throw new IllegalArgumentException("Missing property " + name);
  }
  return value;
}
 
Example 19
Source File: JavaSoundAudioSink.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Activate
protected void activate(BundleContext context) {
    String os = context.getProperty(Constants.FRAMEWORK_OS_NAME);
    if (os != null && os.toLowerCase().startsWith("macos")) {
        isMac = true;
    }
}
 
Example 20
Source File: Activator.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void start(final BundleContext bc) throws Exception {
  this.bc  = bc;
  factory = new FactoryImpl(bc);
  final String commaSeparatedUrls = bc.getProperty(REPOSITORY_XML_URLS);
  if(commaSeparatedUrls != null && !"".equals(commaSeparatedUrls)) {
    final StringTokenizer urls = new StringTokenizer(commaSeparatedUrls, ",");
    while(urls.hasMoreTokens()) {
      final String url = urls.nextToken().trim();

      new Thread(new Runnable() {

        @Override
        public void run() {
          try {
          factory.create(url, null, null);
        } catch (final Exception e) {
       // TODO: Add logging
        }

          
        }}).run(); 
    }

  }

  sr = bc.registerService(XmlBackedRepositoryFactory.class, factory, null);


  final Hashtable<String, String> h = new Hashtable<String, String>();
  h.put(Constants.SERVICE_PID, REPOSITORY_XML_PID);
  msfr = bc.registerService(ManagedServiceFactory.class, new MSF(), h);
 
  if ("true".equals(bc.getProperty("org.knopflerfish.repository.ct.prime"))) {
    tckTracker = new ServiceTracker<String, String>(bc, String.class,
        new ServiceTrackerCustomizer<String, String>() {

          @Override
          public String addingService(ServiceReference<String> reference) {
            if (reference.getProperty("repository-xml") == null) {
              return null;
            }
            final String xml = bc.getService(reference);
            new Thread(new Runnable() {

              @Override
              public void run() {
                Dictionary<String, String> p = new Hashtable<String, String>();
                p.put("repository-populated",
                    "org.osgi.test.cases.repository.junit.RepositoryTest");
                try {
                  factory.createFromString(xml);
                } catch (final Exception e) {
                  // TODO: Add logging
                }
                bc.registerService(Object.class, new Object(), p);

              }
            }).run();
            return xml;
          }

          @Override
          public void modifiedService(ServiceReference<String> r, String s) {
          }

          @Override
          public void removedService(ServiceReference<String> r, String s) {
          }
        });

    tckTracker.open();
  }
  
}