[jboss-cvs] JBossAS SVN: r81974 - in projects/demos/microcontainer/trunk/ioc/src/main: resources/META-INF and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Dec 2 12:29:46 EST 2008


Author: alesj
Date: 2008-12-02 12:29:46 -0500 (Tue, 02 Dec 2008)
New Revision: 81974

Added:
   projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/access/ConstantsProvider.java
   projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/access/IConstants.java
Modified:
   projects/demos/microcontainer/trunk/ioc/src/main/resources/META-INF/access-mode-beans.xml
Log:
Constants provider.

Copied: projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/access/ConstantsProvider.java (from rev 81961, projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/access/XConstUser.java)
===================================================================
--- projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/access/ConstantsProvider.java	                        (rev 0)
+++ projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/access/ConstantsProvider.java	2008-12-02 17:29:46 UTC (rev 81974)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.access;
+
+import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.kernel.spi.config.KernelConfigurator;
+import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.FieldInfo;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ConstantsProvider
+{
+   private KernelConfigurator configurator;
+   private String className;
+   private ClassInfo classInfo;
+
+   public ConstantsProvider(String className)
+   {
+      this.className = className;
+   }
+
+   @Inject(bean = KernelConstants.KERNEL_CONFIGURATOR_NAME)
+   public void setConfigurator(KernelConfigurator configurator)
+   {
+      this.configurator = configurator;
+   }
+
+   public void create() throws Throwable
+   {
+      if (configurator == null)
+         throw new IllegalArgumentException("Null configurator");
+
+      if (className != null)
+         classInfo = configurator.getClassInfo(className, getClass().getClassLoader());
+   }
+
+   public Object getConstant(String constantName) throws Throwable
+   {
+      return getConstant(classInfo, constantName);
+   }
+
+   public Object getConstant(String className, String constantName) throws Throwable
+   {
+      ClassInfo classInfo = configurator.getClassInfo(className, getClass().getClassLoader());
+      return getConstant(classInfo, constantName);
+   }
+
+   protected Object getConstant(ClassInfo classInfo, String constantName) throws Throwable
+   {
+      FieldInfo field = classInfo.getDeclaredField(constantName);
+      return field.get(null);
+   }
+}
\ No newline at end of file


Property changes on: projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/access/ConstantsProvider.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Copied: projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/access/IConstants.java (from rev 81960, projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/access/XConstants.java)
===================================================================
--- projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/access/IConstants.java	                        (rev 0)
+++ projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/access/IConstants.java	2008-12-02 17:29:46 UTC (rev 81974)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.access;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface IConstants
+{
+   public static final int X_INT_VALUE = 42;
+
+   void setFoo(int foo);
+}
\ No newline at end of file


Property changes on: projects/demos/microcontainer/trunk/ioc/src/main/java/org/jboss/demos/ioc/access/IConstants.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: projects/demos/microcontainer/trunk/ioc/src/main/resources/META-INF/access-mode-beans.xml
===================================================================
--- projects/demos/microcontainer/trunk/ioc/src/main/resources/META-INF/access-mode-beans.xml	2008-12-02 17:01:25 UTC (rev 81973)
+++ projects/demos/microcontainer/trunk/ioc/src/main/resources/META-INF/access-mode-beans.xml	2008-12-02 17:29:46 UTC (rev 81974)
@@ -6,8 +6,18 @@
 
   <bean name="XConstants" class="org.jboss.demos.ioc.access.XConstants" access-mode="FIELDS"/>
 
-  <bean name="XConstUser" class="org.jboss.demos.ioc.access.XConstUser">
+  <bean name="XConstUser1" class="org.jboss.demos.ioc.access.XConstUser">
     <property name="x"><inject bean="XConstants" property="X_INT_VALUE"/></property>
   </bean>
 
+  <bean name="ConstantsProvider" class="org.jboss.demos.ioc.access.ConstantsProvider">
+    <constructor>
+      <parameter>org.jboss.demos.ioc.access.IConstants</parameter>
+    </constructor>
+  </bean>
+
+  <bean name="XConstUser2" class="org.jboss.demos.ioc.access.XConstUser">
+    <property name="x"><value-factory bean="ConstantsProvider" method="getConstant" parameter="X_INT_VALUE"/></property>
+  </bean>
+
 </deployment>




More information about the jboss-cvs-commits mailing list