Search in sources :

Example 26 with Activate

use of org.apache.felix.scr.annotations.Activate in project sling by apache.

the class ScriptSandboxServiceImpl method activate.

/**
     *
     * @param context
     */
@Activate
protected void activate(ComponentContext context) {
    try {
        this.slingBabelSource = "//@sourceURL=" + getClass().getCanonicalName() + "\n load( { name : \"" + getClass().getCanonicalName() + "\", script: \"" + StringEscapeUtils.escapeEcmaScript(new String(IOUtils.toByteArray(context.getBundleContext().getBundle().getEntry(this.SLING_BABEL_SOURCE_CODE).openStream()))) + "\"} )";
    } catch (Exception ex) {
        log.error("failed to load babel source", ex);
    }
    String options = "var config = { " + "    presets: [\"es2015\"], " + "    compact: 'true'," + "    plugins: [[\"transform-react-jsx\", { pragma : \"SlingEsx.createElement\"}]] " + //"    \"plugins\": [\"SlingSandbox, [\"transform-react-jsx\", { \"pragma\" : \"SlingEsx.createElement\"}]] \n" +        
    "    }";
    NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
    this.scriptEngine = factory.getScriptEngine();
    try {
        log.info("trying to load babel into the system");
        this.scriptEngine.eval(options);
        this.babelOptions = this.scriptEngine.get("config");
        scriptEngine.eval(slingBabelSource);
        this.babel = this.scriptEngine.get("SlingBabel");
        log.info("Babel loaded");
    } catch (ScriptException ex) {
        log.error("coudlnt load babel options", ex);
    }
}
Also used : NashornScriptEngineFactory(jdk.nashorn.api.scripting.NashornScriptEngineFactory) ScriptException(javax.script.ScriptException) IOException(java.io.IOException) ScriptException(javax.script.ScriptException) Activate(org.apache.felix.scr.annotations.Activate)

Example 27 with Activate

use of org.apache.felix.scr.annotations.Activate in project sling by apache.

the class MongoDBResourceProviderFactory method activate.

@Activate
protected void activate(final Map<String, Object> props) throws Exception {
    final String[] roots = PropertiesUtil.toStringArray(props.get(ResourceProvider.ROOTS));
    if (roots == null || roots.length == 0) {
        throw new Exception("Roots configuration is missing.");
    }
    if (roots.length > 1) {
        throw new Exception("Only a single root should be configured.");
    }
    if (roots[0] == null || roots[0].trim().length() == 0) {
        throw new Exception("Roots configuration is missing.");
    }
    final String host = PropertiesUtil.toString(props.get(PROP_HOST), DEFAULT_HOST);
    final int port = PropertiesUtil.toInteger(props.get(PROP_PORT), DEFAULT_PORT);
    final String db = PropertiesUtil.toString(props.get(PROP_DB), DEFAULT_DB);
    logger.info("Starting MongoDB resource provider with host={}, port={}, db={}", new Object[] { host, port, db });
    final DBAddress address = new DBAddress(host, port, db);
    final MongoOptions options = new MongoOptions();
    options.connectionsPerHost = PropertiesUtil.toInteger(props.get(PROP_NUM_CONNECTIONS), DEFAULT_NUMCONNECTIONS);
    options.threadsAllowedToBlockForConnectionMultiplier = PropertiesUtil.toInteger(props.get(PROP_THREAD_MULTIPLIER), DEFAULT_THREAD_MULTIPLIER);
    final Mongo m = new Mongo(address, options);
    final DB database = m.getDB(db);
    logger.info("Connected to database {}", database);
    this.context = new MongoDBContext(database, roots[0], PropertiesUtil.toStringArray(props.get(PROP_FILTER_COLLECTIONS)), this.eventAdmin);
}
Also used : Mongo(com.mongodb.Mongo) MongoOptions(com.mongodb.MongoOptions) DBAddress(com.mongodb.DBAddress) LoginException(org.apache.sling.api.resource.LoginException) DB(com.mongodb.DB) Activate(org.apache.felix.scr.annotations.Activate)

Example 28 with Activate

use of org.apache.felix.scr.annotations.Activate in project sling by apache.

the class MDCInsertingFilter method activate.

@Activate
private void activate(BundleContext context, Map<String, Object> config) {
    Properties p = new Properties();
    p.setProperty("filter.scope", "REQUEST");
    //The MDC Filter might be running in a non Sling container. Hence to avoid
    //direct dependency on Sling we use a ServiceFactory
    filterReg = context.registerService(Filter.class.getName(), new ServiceFactory() {

        private Object instance;

        public synchronized Object getService(Bundle bundle, ServiceRegistration serviceRegistration) {
            if (instance == null) {
                instance = new SlingMDCFilter();
            }
            return instance;
        }

        public void ungetService(Bundle bundle, ServiceRegistration serviceRegistration, Object o) {
        }
    }, p);
    modified(config);
}
Also used : ServiceFactory(org.osgi.framework.ServiceFactory) Bundle(org.osgi.framework.Bundle) Properties(java.util.Properties) ServiceRegistration(org.osgi.framework.ServiceRegistration) Activate(org.apache.felix.scr.annotations.Activate)

Example 29 with Activate

use of org.apache.felix.scr.annotations.Activate in project sling by apache.

the class JNDIDataSourceFactory method activate.

@Activate
protected void activate(BundleContext bundleContext, Map<String, ?> config) throws Exception {
    String name = DataSourceFactory.getDataSourceName(config);
    String jndiName = PropertiesUtil.toString(config.get(PROP_DS_JNDI_NAME), null);
    checkArgument(name != null, "DataSource name must be specified via [%s] property", PROP_DATASOURCE_NAME);
    checkArgument(jndiName != null, "DataSource JNDI name must be specified via [%s] property", PROP_DS_JNDI_NAME);
    DataSource dataSource = lookupDataSource(jndiName, config);
    String svcPropName = DataSourceFactory.getSvcPropName(config);
    Dictionary<String, Object> svcProps = new Hashtable<String, Object>();
    svcProps.put(svcPropName, name);
    svcProps.put(Constants.SERVICE_VENDOR, "Apache Software Foundation");
    svcProps.put(Constants.SERVICE_DESCRIPTION, "DataSource service looked up from " + jndiName);
    dsRegistration = bundleContext.registerService(javax.sql.DataSource.class, dataSource, svcProps);
    log.info("Registered DataSource [{}] looked up from JNDI at [{}]", name, jndiName);
}
Also used : Hashtable(java.util.Hashtable) DataSource(javax.sql.DataSource) Activate(org.apache.felix.scr.annotations.Activate)

Example 30 with Activate

use of org.apache.felix.scr.annotations.Activate in project fabric8 by jboss-fuse.

the class ContainerConnect method activate.

@Activate
void activate(BundleContext bundleContext) {
    this.agentFactory = new KarafAgentFactory();
    this.agentFactory.setBundleContext(bundleContext);
    activateComponent();
}
Also used : KarafAgentFactory(org.apache.karaf.shell.ssh.KarafAgentFactory) Activate(org.apache.felix.scr.annotations.Activate)

Aggregations

Activate (org.apache.felix.scr.annotations.Activate)153 ConfigurationException (org.osgi.service.cm.ConfigurationException)31 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 BundleContext (org.osgi.framework.BundleContext)19 File (java.io.File)15 OsgiWhiteboard (org.apache.jackrabbit.oak.osgi.OsgiWhiteboard)12 URL (java.net.URL)11 Hashtable (java.util.Hashtable)11 ServiceReference (org.osgi.framework.ServiceReference)11 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)9 HashSet (java.util.HashSet)8 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 Map (java.util.Map)6 Session (javax.jcr.Session)5 StandardMBean (javax.management.StandardMBean)5 Whiteboard (org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard)5 Filter (org.osgi.framework.Filter)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4