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);
}
}
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);
}
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);
}
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);
}
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();
}
Aggregations