[CVS nano] update
Paul Hammant <paul-yCVjj/[email protected]> Mon, 17 Nov 2003 15:01:36 -0600
| Newsgroups | gmane.comp.java.nanocontainer.cvs |
|---|---|
| Message-ID | <[email protected]> |
Commit in nano/integrationkit/src/java/org/picoextras/integrationkit on MAIN ContainerAssembler.java +20 added 1.1 ContainerBuilder.java +35 added 1.1 DefaultLifecycleContainerBuilder.java +63 added 1.1 ObjectReference.java +23 added 1.1 +141 4 added files - TODO: What should I throw? update ---------- nano /integrationkit /src /java /org /picoextras /integrationkit ContainerAssembler.java added at 1.1 diff -N ContainerAssembler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ContainerAssembler.java 17 Nov 2003 21:01:36 -0000 1.1 @@ -0,0 +1,20 @@ +/***************************************************************************** + * Copyright (C) NanoContainer Organization. All rights reserved. * + * ------------------------------------------------------------------------- * + * The software in this package is published under the terms of the BSD * + * style license a copy of which has been included with this distribution in * + * the LICENSE.txt file. * + * * + *****************************************************************************/ +package org.picoextras.integrationkit; + +import org.picocontainer.MutablePicoContainer; + +/** + * @author Joe Walnes <a href="mailto:[email protected]">Joe Walnes</a> + */ +public interface ContainerAssembler { + + void assembleContainer(MutablePicoContainer container, String name); + +} ---------- nano /integrationkit /src /java /org /picoextras /integrationkit ContainerBuilder.java added at 1.1 diff -N ContainerBuilder.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ContainerBuilder.java 17 Nov 2003 21:01:36 -0000 1.1 @@ -0,0 +1,35 @@ +/***************************************************************************** + * Copyright (C) NanoContainer Organization. All rights reserved. * + * ------------------------------------------------------------------------- * + * The software in this package is published under the terms of the BSD * + * style license a copy of which has been included with this distribution in * + * the LICENSE.txt file. * + * * + *****************************************************************************/ +package org.picoextras.integrationkit; + +/** + * @author <a href="mailto:[email protected]">Joe Walnes</a> + */ +public interface ContainerBuilder { + + /** + * Create, assemble, init and start a new PicoContainer and store it + * at a given reference. + * + * @param containerRef Where to store the new container. + * @param parentContainerRef Parent container (may be null) + * @param assembler Strategy for assembling components in container. + * @param assemblyName Argument to be passed to ContainerAssembler. + */ + void buildContainer(ObjectReference containerRef, ObjectReference parentContainerRef, ContainerAssembler assembler, String assemblyName); + + /** + * Locate a container at the given reference so it can stopped, + * destroyed and removed. + * + * @param containerRef Where the container is stored. + */ + void killContainer(ObjectReference containerRef); + +} ---------- nano /integrationkit /src /java /org /picoextras /integrationkit DefaultLifecycleContainerBuilder.java added at 1.1 diff -N DefaultLifecycleContainerBuilder.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ DefaultLifecycleContainerBuilder.java 17 Nov 2003 21:01:36 -0000 1.1 @@ -0,0 +1,63 @@ +/***************************************************************************** + * Copyright (C) NanoContainer Organization. All rights reserved. * + * ------------------------------------------------------------------------- * + * The software in this package is published under the terms of the BSD * + * style license a copy of which has been included with this distribution in * + * the LICENSE.txt file. * + * * + *****************************************************************************/ +package org.picoextras.integrationkit; + +import org.picocontainer.MutablePicoContainer; +import org.picocontainer.extras.DefaultLifecyclePicoContainer; + +import java.util.Iterator; +import java.util.List; +import java.util.LinkedList; + +/** + * @author <a href="mailto:[email protected]">Joe Walnes</a> + */ +public class DefaultLifecycleContainerBuilder implements ContainerBuilder { + + public void buildContainer(ObjectReference containerRef, ObjectReference parentContainerRef, ContainerAssembler assembler, String assemblyName) { + + DefaultLifecyclePicoContainer container = new DefaultLifecyclePicoContainer(); + + if (parentContainerRef != null) { + MutablePicoContainer parent = (MutablePicoContainer) parentContainerRef.get(); + container.addParent(parent); + } + + try { + assembler.assembleContainer(container, assemblyName); + container.start(); + } catch (Exception e) { + throw new RuntimeException(e); // TODO: What should I throw? + } + + // hold on to it + containerRef.set(container); + + } + + public void killContainer(ObjectReference containerRef) { + try { + DefaultLifecyclePicoContainer container = (DefaultLifecyclePicoContainer) containerRef.get(); + container.stop(); + container.dispose(); + List parentsToRemove = new LinkedList(); // eww + for (Iterator iterator = container.getParentContainers().iterator(); iterator.hasNext();) { + parentsToRemove.add(iterator.next()); + } + for (Iterator iterator = parentsToRemove.iterator(); iterator.hasNext();) { + container.removeParent((MutablePicoContainer) iterator.next()); + } + } catch (Exception e) { + throw new RuntimeException("Cannot shutdown container", e); // todo: what should i throw? + } finally { + containerRef.set(null); + } + } + +} ---------- nano /integrationkit /src /java /org /picoextras /integrationkit ObjectReference.java added at 1.1 diff -N ObjectReference.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ObjectReference.java 17 Nov 2003 21:01:36 -0000 1.1 @@ -0,0 +1,23 @@ +/***************************************************************************** + * Copyright (C) NanoContainer Organization. All rights reserved. * + * ------------------------------------------------------------------------- * + * The software in this package is published under the terms of the BSD * + * style license a copy of which has been included with this distribution in * + * the LICENSE.txt file. * + * * + *****************************************************************************/ +package org.picoextras.integrationkit; + +/** + * A way to refer to objects that are stored in awkward places + * (for example HttpSession or ThreadLocal). + * + * This is typically implemented by someone integrating Pico into + * an existing container. + * + * @author <a href="mailto:[email protected]">Joe Walnes</a> + */ +public interface ObjectReference { + Object get(); + void set(Object item); +}