[jboss-cvs] JBossAS SVN: r80048 - in projects/demos/microcontainer/trunk/ioc/src/main: java/org/jboss/demos/ioc/ondemand and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Oct 24 08:35:20 EDT 2008
Author: alesj
Date: 2008-10-24 08:35:19 -0400 (Fri, 24 Oct 2008)
New Revision: 80048
Added:
projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/ondemand/
projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/ondemand/OptionalService.java
projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/ondemand/OptionalServiceCaller.java
projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/ondemand/OptionalServiceUser.java
projects/demos/microcontainer/trunk/ioc/src/main/resources/META-INF/ondemand-beans.xml
Log:
Add on-demand example.
Added: projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/ondemand/OptionalService.java
===================================================================
--- projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/ondemand/OptionalService.java (rev 0)
+++ projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/ondemand/OptionalService.java 2008-10-24 12:35:19 UTC (rev 80048)
@@ -0,0 +1,29 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.demos.ioc.ondemand;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class OptionalService
+{
+}
Added: projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/ondemand/OptionalServiceCaller.java
===================================================================
--- projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/ondemand/OptionalServiceCaller.java (rev 0)
+++ projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/ondemand/OptionalServiceCaller.java 2008-10-24 12:35:19 UTC (rev 80048)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.demos.ioc.ondemand;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class OptionalServiceCaller
+{
+ private OptionalService service;
+
+ public OptionalServiceCaller(OptionalService service)
+ {
+ this.service = service;
+ }
+
+ public OptionalService getService()
+ {
+ return service;
+ }
+}
\ No newline at end of file
Added: projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/ondemand/OptionalServiceUser.java
===================================================================
--- projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/ondemand/OptionalServiceUser.java (rev 0)
+++ projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/ondemand/OptionalServiceUser.java 2008-10-24 12:35:19 UTC (rev 80048)
@@ -0,0 +1,74 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.demos.ioc.ondemand;
+
+import org.jboss.beans.metadata.api.annotations.Constructor;
+import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.plugins.AbstractDependencyItem;
+import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
+import org.jboss.kernel.spi.dependency.KernelController;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class OptionalServiceUser
+{
+ private KernelController controller;
+
+ @Constructor
+ public OptionalServiceUser(@Inject(bean = KernelConstants.KERNEL_CONTROLLER_NAME) KernelController controller)
+ {
+ this.controller = controller;
+ }
+
+ public void create() throws Throwable
+ {
+ ControllerContext os = controller.getInstalledContext("OptionalService");
+ if (os != null && os.getState().equals(ControllerState.INSTALLED))
+ throw new IllegalArgumentException("Optional service should NOT be installed.");
+
+ // add dependency, so that we wait till OSCaller is instantiated - hence invoking OptionalService
+ ControllerContext thisContext = controller.getContext("OptionalServiceUser", null);
+ DependencyInfo di = thisContext.getDependencyInfo();
+ di.addIDependOn(new AbstractDependencyItem(thisContext.getName(), "OSCaller", ControllerState.START, ControllerState.INSTANTIATED));
+
+ BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("OSCaller", OptionalServiceCaller.class.getName());
+ builder.addConstructorParameter(OptionalService.class.getName(), builder.createInject("OptionalService"));
+ controller.install(builder.getBeanMetaData());
+ }
+
+ public void start()
+ {
+ ControllerContext os = controller.getInstalledContext("OptionalService");
+ if (os == null || os.getState().equals(ControllerState.INSTALLED) == false)
+ throw new IllegalArgumentException("Optional service should BE installed.");
+ }
+
+ public void destroy()
+ {
+ controller.uninstall("OSCaller");
+ }
+}
\ No newline at end of file
Copied: projects/demos/microcontainer/trunk/ioc/src/main/resources/META-INF/ondemand-beans.xml (from rev 79973, projects/demos/microcontainer/trunk/ioc/src/main/resources/META-INF/builder-util-beans.xml)
===================================================================
--- projects/demos/microcontainer/trunk/ioc/src/main/resources/META-INF/ondemand-beans.xml (rev 0)
+++ projects/demos/microcontainer/trunk/ioc/src/main/resources/META-INF/ondemand-beans.xml 2008-10-24 12:35:19 UTC (rev 80048)
@@ -0,0 +1,7 @@
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="OptionalService" class="org.jboss.demos.ioc.ondemand.OptionalService" mode="On Demand"/>
+
+ <bean name="OptionalServiceUser" class="org.jboss.demos.ioc.ondemand.OptionalServiceUser"/>
+
+</deployment>
More information about the jboss-cvs-commits
mailing list