use of org.apache.aries.blueprint.container.BlueprintContainerImpl in project aries by apache.
the class BlueprintContextListener method contextDestroyed.
public void contextDestroyed(ServletContextEvent event) {
ServletContext servletContext = event.getServletContext();
Object container = servletContext.getAttribute(CONTAINER_ATTRIBUTE);
if (container instanceof BlueprintContainerImpl) {
BlueprintContainerImpl blueprint = (BlueprintContainerImpl) container;
blueprint.destroy();
}
}
use of org.apache.aries.blueprint.container.BlueprintContainerImpl in project aries by apache.
the class BlueprintContextListener method contextInitialized.
public void contextInitialized(ServletContextEvent event) {
ServletContext servletContext = event.getServletContext();
String location = servletContext.getInitParameter(CONTEXT_LOCATION);
if (location == null) {
location = DEFAULT_CONTEXT_LOCATION;
}
List<URL> resourcePaths = new ArrayList<URL>();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
Enumeration<URL> resources = classLoader.getResources(location);
while (resources.hasMoreElements()) {
resourcePaths.add(resources.nextElement());
}
servletContext.log("Loading Blueprint contexts " + resourcePaths);
Map<String, String> properties = new HashMap<String, String>();
String propLocations = servletContext.getInitParameter(PROPERTIES);
if (propLocations != null) {
for (String propLoc : propLocations.split(",")) {
Enumeration<URL> propUrl = classLoader.getResources(propLoc);
while (propUrl.hasMoreElements()) {
URL url = propUrl.nextElement();
InputStream is = url.openStream();
try {
Properties props = new Properties();
props.load(is);
Enumeration names = props.propertyNames();
while (names.hasMoreElements()) {
String key = names.nextElement().toString();
properties.put(key, props.getProperty(key));
}
} finally {
is.close();
}
}
}
}
NamespaceHandlerSet nsHandlerSet = getNamespaceHandlerSet(servletContext, classLoader);
BlueprintContainerImpl container = new BlueprintContainerImpl(classLoader, resourcePaths, properties, nsHandlerSet, true);
servletContext.setAttribute(CONTAINER_ATTRIBUTE, container);
} catch (Exception e) {
servletContext.log("Failed to startup blueprint container. " + e, e);
}
}
use of org.apache.aries.blueprint.container.BlueprintContainerImpl in project aries by apache.
the class BlueprintContainerTest method testPlaceholders.
@Test
public void testPlaceholders() throws Exception {
URL url1 = getClass().getClassLoader().getResource("test.xml");
URL url2 = getClass().getClassLoader().getResource("test2.xml");
BlueprintContainerImpl container = new BlueprintContainerImpl(getClass().getClassLoader(), Arrays.asList(url1, url2));
Foo foo = (Foo) container.getComponentInstance("foo");
System.out.println(foo);
assertNotNull(foo);
assertEquals(5, foo.getA());
assertEquals(1, foo.getB());
container.destroy();
}
use of org.apache.aries.blueprint.container.BlueprintContainerImpl in project aries by apache.
the class BlueprintContainerTest method testSimple.
@Test
public void testSimple() throws Exception {
URL url = getClass().getClassLoader().getResource("test.xml");
BlueprintContainerImpl container = new BlueprintContainerImpl(getClass().getClassLoader(), Arrays.asList(url));
Foo foo = (Foo) container.getComponentInstance("foo");
System.out.println(foo);
assertNotNull(foo);
assertEquals(5, foo.getA());
assertEquals(1, foo.getB());
container.destroy();
}
use of org.apache.aries.blueprint.container.BlueprintContainerImpl in project aries by apache.
the class BlueprintContainerTest method main.
public static void main(String[] args) throws Exception {
URL url = BlueprintContainerTest.class.getClassLoader().getResource("test.xml");
BlueprintContainerImpl container = new BlueprintContainerImpl(BlueprintContainerTest.class.getClassLoader(), Arrays.asList(url));
System.out.println(container.getComponentInstance("foo"));
container.destroy();
}
Aggregations