+ private void firstInit() {
+ log.info("## FIRST INIT ##");
+ String nodeInit = getFrameworkProp(NODE_INIT);
+ if (nodeInit == null)
+ nodeInit = "../../init";
+ File initDir;
+ if (nodeInit.startsWith("."))
+ initDir = KernelUtils.getExecutionDir(nodeInit);
+ else
+ initDir = new File(nodeInit);
+ // TODO also uncompress archives
+ if (initDir.exists())
+ try {
+ FileUtils.copyDirectory(initDir, getOsgiInstanceDir(),
+ new FileFilter() {
+
+ @Override
+ public boolean accept(File pathname) {
+ if (pathname.getName().equals(".svn")
+ || pathname.getName().equals(".git"))
+ return false;
+ return true;
+ }
+ });
+ log.info("CMS initialized from " + initDir.getCanonicalPath());
+ } catch (IOException e) {
+ throw new CmsException("Cannot initialize from " + initDir, e);
+ }
+ }
+
+ /** Can be null */
+ private ConfigurationAdmin findConfigurationAdmin() {
+ configurationAdmin = bc.getServiceReference(ConfigurationAdmin.class);
+ if (configurationAdmin == null) {
+ return null;
+ }
+ return bc.getService(configurationAdmin);
+ }
+
+ private void initTransactionManager() {
+ bitronix.tm.Configuration tmConf = TransactionManagerServices
+ .getConfiguration();
+ tmConf.setServerId(getFrameworkProp(FRAMEWORK_UUID));
+
+ // File tmBaseDir = new File(getFrameworkProp(TRANSACTIONS_HOME,
+ // getOsgiInstancePath(DIR_TRANSACTIONS)));
+ File tmBaseDir = bc.getDataFile(DIR_TRANSACTIONS);
+ File tmDir1 = new File(tmBaseDir, "btm1");
+ tmDir1.mkdirs();
+ tmConf.setLogPart1Filename(new File(tmDir1, tmDir1.getName() + ".tlog")
+ .getAbsolutePath());
+ File tmDir2 = new File(tmBaseDir, "btm2");
+ tmDir2.mkdirs();
+ tmConf.setLogPart2Filename(new File(tmDir2, tmDir2.getName() + ".tlog")
+ .getAbsolutePath());
+ transactionManager = getTransactionManager();
+ transactionSynchronizationRegistry = getTransactionSynchronizationRegistry();
+ }
+
+ private void initWebServer(ConfigurationAdmin conf) {
+ String httpPort = getFrameworkProp("org.osgi.service.http.port");
+ String httpsPort = getFrameworkProp("org.osgi.service.http.port.secure");
+ try {
+ if (httpPort != null || httpsPort != null) {
+ Hashtable<String, Object> jettyProps = new Hashtable<String, Object>();
+ if (httpPort != null) {
+ jettyProps.put(JettyConstants.HTTP_PORT, httpPort);
+ jettyProps.put(JettyConstants.HTTP_ENABLED, true);
+ }
+ if (httpsPort != null) {
+ jettyProps.put(JettyConstants.HTTPS_PORT, httpsPort);
+ jettyProps.put(JettyConstants.HTTPS_ENABLED, true);
+ jettyProps.put(JettyConstants.SSL_KEYSTORETYPE, "PKCS12");
+ jettyProps.put(JettyConstants.SSL_KEYSTORE, nodeSecurity
+ .getHttpServerKeyStore().getCanonicalPath());
+ jettyProps.put(JettyConstants.SSL_PASSWORD, "changeit");
+ jettyProps.put(JettyConstants.SSL_WANTCLIENTAUTH, true);
+ }
+ if (conf != null) {
+ // TODO make filter more generic
+ String filter = "(" + JettyConstants.HTTP_PORT + "="
+ + httpPort + ")";
+ if (conf.listConfigurations(filter) != null)
+ return;
+ Configuration jettyConf = conf.createFactoryConfiguration(
+ JETTY_FACTORY_PID, null);
+ jettyConf.update(jettyProps);
+ } else {
+ JettyConfigurator.startServer("default", jettyProps);
+ }
+ }
+ } catch (Exception e) {
+ throw new CmsException("Cannot initialize web server on "
+ + httpPortsMsg(httpPort, httpsPort), e);
+ }
+ }
+
+ private void publish() {
+ // Listen to service publication (also ours)
+ bc.addServiceListener(Kernel.this);
+
+ // Logging
+ loggerReg = bc.registerService(ArgeoLogger.class, logger, null);
+ // Transaction
+ tmReg = bc.registerService(TransactionManager.class,
+ transactionManager, null);
+ utReg = bc.registerService(UserTransaction.class, transactionManager,
+ null);
+ tsrReg = bc.registerService(TransactionSynchronizationRegistry.class,
+ transactionSynchronizationRegistry, null);
+ // User admin
+ userAdminReg = bc.registerService(UserAdmin.class, userAdmin,
+ userAdmin.currentState());
+ // JCR
+ Hashtable<String, String> regProps = new Hashtable<String, String>();
+ regProps.put(JCR_REPOSITORY_ALIAS, ALIAS_NODE);
+ repositoryReg = bc.registerService(Repository.class, repository,
+ regProps);
+ repositoryFactoryReg = bc.registerService(RepositoryFactory.class,
+ repositoryFactory, null);
+ }
+