Author: norman
Date: Sun Jan 31 19:57:38 2010
New Revision: 905110
URL: http://svn.apache.org/viewvc?rev=905110&view=rev
Log:
Start to add some osgi related code (JAMES-835)
Added:
james/server/trunk/osgi-deployment/src/
james/server/trunk/osgi-deployment/src/main/
james/server/trunk/osgi-deployment/src/main/java/
james/server/trunk/osgi-deployment/src/main/java/org/
james/server/trunk/osgi-deployment/src/main/java/org/apache/
james/server/trunk/osgi-deployment/src/main/java/org/apache/james/
james/server/trunk/osgi-deployment/src/main/java/org/apache/james/container/
james/server/trunk/osgi-deployment/src/main/java/org/apache/james/container/spring/
james/server/trunk/osgi-deployment/src/main/java/org/apache/james/container/spring/osgi/
james/server/trunk/osgi-deployment/src/main/java/org/apache/james/container/spring/osgi/JamesOsgiApplicationContextCreator.java
james/server/trunk/osgi-deployment/src/main/java/org/apache/james/container/spring/osgi/JamesOsgiBundleXmlApplicationContext.java
Added:
james/server/trunk/osgi-deployment/src/main/java/org/apache/james/container/spring/osgi/JamesOsgiApplicationContextCreator.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/osgi-deployment/src/main/java/org/apache/james/container/spring/osgi/JamesOsgiApplicationContextCreator.java?rev=905110&view=auto
==============================================================================
---
james/server/trunk/osgi-deployment/src/main/java/org/apache/james/container/spring/osgi/JamesOsgiApplicationContextCreator.java
(added)
+++
james/server/trunk/osgi-deployment/src/main/java/org/apache/james/container/spring/osgi/JamesOsgiApplicationContextCreator.java
Sun Jan 31 19:57:38 2010
@@ -0,0 +1,52 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+package org.apache.james.container.spring.osgi;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import
org.springframework.osgi.context.DelegatedExecutionOsgiBundleApplicationContext;
+import org.springframework.osgi.extender.OsgiApplicationContextCreator;
+import
org.springframework.osgi.extender.support.ApplicationContextConfiguration;
+import org.springframework.osgi.extender.support.scanning.ConfigurationScanner;
+import
org.springframework.osgi.extender.support.scanning.DefaultConfigurationScanner;
+
+public class JamesOsgiApplicationContextCreator implements
OsgiApplicationContextCreator{
+ private ConfigurationScanner configurationScanner = new
DefaultConfigurationScanner();
+
+ /*
+ * (non-Javadoc)
+ * @see
org.springframework.osgi.extender.OsgiApplicationContextCreator#createApplicationContext(org.osgi.framework.BundleContext)
+ */
+ public DelegatedExecutionOsgiBundleApplicationContext
createApplicationContext(BundleContext context) throws Exception {
+ Bundle bundle = context.getBundle();
+ ApplicationContextConfiguration config = new
ApplicationContextConfiguration(bundle, configurationScanner);
+
+ if (!config.isSpringPoweredBundle()) {
+ return null;
+ }
+
+ DelegatedExecutionOsgiBundleApplicationContext sdoac = new
JamesOsgiBundleXmlApplicationContext(config.getConfigurationLocations());
+ sdoac.setBundleContext(context);
+ sdoac.setPublishContextAsService(config.isPublishContextAsService());
+
+ return sdoac;
+
+ }
+
+}
Added:
james/server/trunk/osgi-deployment/src/main/java/org/apache/james/container/spring/osgi/JamesOsgiBundleXmlApplicationContext.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/osgi-deployment/src/main/java/org/apache/james/container/spring/osgi/JamesOsgiBundleXmlApplicationContext.java?rev=905110&view=auto
==============================================================================
---
james/server/trunk/osgi-deployment/src/main/java/org/apache/james/container/spring/osgi/JamesOsgiBundleXmlApplicationContext.java
(added)
+++
james/server/trunk/osgi-deployment/src/main/java/org/apache/james/container/spring/osgi/JamesOsgiBundleXmlApplicationContext.java
Sun Jan 31 19:57:38 2010
@@ -0,0 +1,66 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+package org.apache.james.container.spring.osgi;
+
+import java.io.File;
+
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.core.io.Resource;
+import
org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
+
+public class JamesOsgiBundleXmlApplicationContext extends
OsgiBundleXmlApplicationContext{
+
+
+ private static final String FILE_PROTOCOL = "file://";
+ private static final String FILE_PROTOCOL_ABSOLUTE = "file:///";
+
+ private static final String FILE_PROTOCOL_AND_CONF = "file://conf/";
+ private static final String FILE_PROTOCOL_AND_VAR = "file://var/";
+
+ public JamesOsgiBundleXmlApplicationContext(String[]
configurationLocations) {
+ super(configurationLocations);
+ }
+
+ @Override
+ public Resource getResource(String fileURL) {
+ Resource r = null;
+ if (fileURL.startsWith("classpath:")) {
+ String resourceName = fileURL.substring("classpath:".length());
+ r = new ClassPathResource(resourceName);
+ } else if (fileURL.startsWith(FILE_PROTOCOL)) {
+ File file = null;
+ if (fileURL.startsWith(FILE_PROTOCOL_AND_CONF)) {
+ file = new File("../conf/" +
fileURL.substring(FILE_PROTOCOL_AND_CONF.length()));
+ } else if (fileURL.startsWith(FILE_PROTOCOL_AND_VAR)) {
+ file = new File("../var/" +
fileURL.substring(FILE_PROTOCOL_AND_VAR.length()));
+ } else if (fileURL.startsWith(FILE_PROTOCOL_ABSOLUTE)) {
+ file = new File("/" +
fileURL.substring(FILE_PROTOCOL_ABSOLUTE.length()));
+ } else {
+ // move to the root folder of the spring deployment
+ file = new File("../" +
fileURL.substring(FILE_PROTOCOL.length()));
+ }
+ r = new FileSystemResource(file);
+ } else {
+ r = super.getResource(fileURL);
+ }
+ return r;
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]