[jboss-cvs] JBossAS SVN: r64180 - in projects/microcontainer/trunk/kernel/src: main/org/jboss/beans/metadata/plugins/builder and 8 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Jul 22 06:14:45 EDT 2007
Author: alesj
Date: 2007-07-22 06:14:45 -0400 (Sun, 22 Jul 2007)
New Revision: 64180
Added:
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractValueFactoryMetaData.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/ValueFactoryHandler.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/ValueFactoryParametersInterceptor.java
projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryBadNoBean.xml
projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryBadNoMethod.xml
projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithBean.xml
projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithDefault.xml
projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithParameter.xml
projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithParameters.xml
projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithState.xml
projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithWhenRequired.xml
projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testValueFactory.xml
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/LDAPFactory.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/PropHolder.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/Transformer.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/TrimTransformer.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueFactoryTestCase.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueFactoryXMLTestCase.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryTestCase.java
Modified:
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/builder/BeanMetaDataBuilderImpl.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/builder/ParameterMetaDataBuilder.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/builder/BeanMetaDataBuilder.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding20.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBindingHelper.java
projects/microcontainer/trunk/kernel/src/resources/main/schema/bean-deployer_2_0.xsd
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ConfigTestSuite.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/InjectionTestCase.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/XMLTestSuite.java
Log:
ValueFactory impl.
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractValueFactoryMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractValueFactoryMetaData.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/AbstractValueFactoryMetaData.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,363 @@
+/*
+* 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.beans.metadata.plugins;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.jboss.beans.metadata.plugins.builder.MutableParameterizedMetaData;
+import org.jboss.beans.metadata.spi.MetaDataVisitor;
+import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.dependency.plugins.AbstractDependencyItem;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.dependency.spi.dispatch.InvokeDispatchContext;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.config.Configurator;
+import org.jboss.kernel.spi.config.KernelConfigurator;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.reflect.spi.MethodInfo;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * ValueFactory value.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ */
+public class AbstractValueFactoryMetaData extends AbstractValueMetaData implements MutableParameterizedMetaData
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The context
+ */
+ protected transient KernelControllerContext context;
+
+ /**
+ * The property name
+ */
+ protected String method;
+
+ /**
+ * The parameter
+ */
+ protected String parameter;
+
+ /**
+ * The defaultValue
+ */
+ protected String defaultValue;
+
+ /**
+ * The when required state of the dependency or null to use current context state
+ */
+ protected ControllerState whenRequiredState;
+
+ /**
+ * The required state of the dependency or null to look in the registry
+ */
+ protected ControllerState dependentState = ControllerState.INSTALLED;
+
+ /** The parameters */
+ protected List<ParameterMetaData> parameters;
+
+ /**
+ * Create a new dependency value
+ */
+ public AbstractValueFactoryMetaData()
+ {
+ }
+
+ /**
+ * Create a new dependency value
+ *
+ * @param value the value
+ */
+ public AbstractValueFactoryMetaData(Object value)
+ {
+ super(value);
+ }
+
+ /**
+ * Create a new value-factory value
+ *
+ * @param value the value
+ * @param method the method
+ */
+ public AbstractValueFactoryMetaData(Object value, String method)
+ {
+ this(value, method, null);
+ }
+
+ /**
+ * Create a new value-factory value
+ *
+ * @param value the value
+ * @param method the method
+ * @param defaultValue the default
+ */
+ public AbstractValueFactoryMetaData(Object value, String method, String defaultValue)
+ {
+ super(value);
+ this.method = method;
+ this.defaultValue = defaultValue;
+ }
+
+ /**
+ * Get the method
+ *
+ * @return the method
+ */
+ public String getMethod()
+ {
+ return method;
+ }
+
+ /**
+ * Set the property
+ *
+ * @param method the property name
+ */
+ public void setMethod(String method)
+ {
+ this.method = method;
+ }
+
+ /**
+ * Get the parameter.
+ *
+ * @return the parameter
+ */
+ public String getParameter()
+ {
+ return parameter;
+ }
+
+ /**
+ * Set the parameter.
+ *
+ * @param parameter the parameter
+ */
+ public void setParameter(String parameter)
+ {
+ this.parameter = parameter;
+ }
+
+ /**
+ * Set the when required state of the dependency
+ *
+ * @param whenRequiredState the when required state or null if it uses current context state
+ */
+ public void setWhenRequiredState(ControllerState whenRequiredState)
+ {
+ this.whenRequiredState = whenRequiredState;
+ flushJBossObjectCache();
+ }
+
+ /**
+ * Get when required state.
+ *
+ * @return when required state
+ */
+ public ControllerState getWhenRequiredState()
+ {
+ return whenRequiredState;
+ }
+
+ /**
+ * Set the required state of the dependency
+ *
+ * @param dependentState the required state or null if it must be in the registry
+ */
+ public void setDependentState(ControllerState dependentState)
+ {
+ this.dependentState = dependentState;
+ flushJBossObjectCache();
+ }
+
+ /**
+ * Get the dependant state.
+ *
+ * @return the dependant state
+ */
+ public ControllerState getDependentState()
+ {
+ return dependentState;
+ }
+
+ /**
+ * Get the default value.
+ *
+ * @return the default value
+ */
+ public String getDefaultValue()
+ {
+ return defaultValue;
+ }
+
+ /**
+ * Set the default value.
+ *
+ * @param defaultValue default value
+ */
+ public void setDefaultValue(String defaultValue)
+ {
+ this.defaultValue = defaultValue;
+ }
+
+ /**
+ * Get the parameters.
+ *
+ * @return the parameters
+ */
+ public List<ParameterMetaData> getParameters()
+ {
+ return parameters;
+ }
+
+ /**
+ * Set the parameters.
+ *
+ * @param parameters the parameters
+ */
+ public void setParameters(List<ParameterMetaData> parameters)
+ {
+ this.parameters = parameters;
+ }
+
+ public void initialVisit(MetaDataVisitor visitor)
+ {
+ context = visitor.getControllerContext();
+ Object name = context.getName();
+ Object iDependOn = getUnderlyingValue();
+
+ ControllerState whenRequired = whenRequiredState;
+ if (whenRequired == null)
+ {
+ whenRequired = visitor.getContextState();
+ }
+ ControllerState state = dependentState;
+ if (state == null)
+ {
+ state = ControllerState.INSTALLED;
+ }
+
+ DependencyItem item = new AbstractDependencyItem(name, iDependOn, whenRequired, state);
+ visitor.addDependency(item);
+ super.initialVisit(visitor);
+ }
+
+ public Iterator<? extends MetaDataVisitorNode> getChildren()
+ {
+ if (getParameters() != null)
+ return getParameters().iterator();
+ return null;
+ }
+
+ public Object getValue(TypeInfo info, ClassLoader cl) throws Throwable
+ {
+ ControllerState state = dependentState;
+ if (state == null)
+ state = ControllerState.INSTALLED;
+ KernelController controller = (KernelController)context.getController();
+ ControllerContext lookup = controller.getContext(getUnderlyingValue(), state);
+ if (lookup == null)
+ throw new Error("Should not be here - dependency failed - " + this);
+ if (lookup instanceof InvokeDispatchContext == false)
+ throw new IllegalArgumentException("Underlying context is not InvokeDispatchContext: " + context);
+
+ Kernel kernel = controller.getKernel();
+ KernelConfigurator configurator = kernel.getConfigurator();
+ Object result = invoke(configurator, (InvokeDispatchContext)lookup, getMethod(), getParameters());
+ if (result == null)
+ result = defaultValue;
+ return info != null ? info.convertValue(result) : result;
+ }
+
+ protected Object invoke(KernelConfigurator configurator, InvokeDispatchContext context, String name, List<ParameterMetaData> params) throws Throwable
+ {
+ String[] signature;
+ Object[] parameters;
+ if (params == null || params.isEmpty())
+ {
+ signature = new String[0];
+ parameters = new Object[0];
+ }
+ else
+ {
+ int size = params.size();
+ signature = Configurator.getParameterTypes(log.isTraceEnabled(), params);
+ Object target = context.getTarget();
+ // TODO - is this ok for non-POJO targets?
+ if (target != null)
+ {
+ MethodInfo methodInfo = Configurator.findMethodInfo(configurator.getClassInfo(target.getClass()), name, signature);
+ parameters = Configurator.getParameters(log.isTraceEnabled(), context.getClassLoader(), methodInfo.getParameterTypes(), params);
+ // add some more info, if not yet set
+ for(int i = 0; i < size; i++)
+ {
+ if (signature[i] == null)
+ {
+ signature[i] = methodInfo.getParameterTypes()[i].getName();
+ }
+ }
+ }
+ else
+ {
+ parameters = new Object[size];
+ ClassLoader classLoader = context.getClassLoader();
+ for (int i = 0; i < size; i++)
+ {
+ ParameterMetaData pmd = params.get(i);
+ TypeInfo typeInfo = null;
+ if (signature[i] != null)
+ {
+ typeInfo = configurator.getClassInfo(signature[i], classLoader);
+ }
+ // typeInfo might be null, but we can still get value in some cases
+ parameters[i] = pmd.getValue().getValue(typeInfo, classLoader);
+ }
+
+ }
+ }
+ return context.invoke(name, parameters, signature);
+ }
+
+ public void toString(JBossStringBuilder buffer)
+ {
+ super.toString(buffer);
+ if (method != null)
+ buffer.append(" method=").append(method);
+ if (whenRequiredState != null)
+ buffer.append(" whenRequiredState=").append(whenRequiredState.getStateString());
+ if (dependentState != null)
+ buffer.append(" dependentState=").append(dependentState.getStateString());
+ if (defaultValue != null)
+ buffer.append(" default=").append(defaultValue);
+ if (parameters != null && parameters.isEmpty() == false)
+ buffer.append(" parameters=").append(parameters);
+ }
+}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/builder/BeanMetaDataBuilderImpl.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/builder/BeanMetaDataBuilderImpl.java 2007-07-22 01:20:57 UTC (rev 64179)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/builder/BeanMetaDataBuilderImpl.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -108,7 +108,7 @@
return this;
}
- public BeanMetaDataBuilder addConstructorParameter(String type, Object value)
+ protected void checkConstructorBuilder()
{
AbstractConstructorMetaData constructor = (AbstractConstructorMetaData) beanMetaData.getConstructor();
if (constructor == null)
@@ -117,10 +117,22 @@
beanMetaData.setConstructor(constructor);
constructorBuilder = new ParameterMetaDataBuilder<AbstractConstructorMetaData>(constructor);
}
+ }
+
+ public BeanMetaDataBuilder addConstructorParameter(String type, Object value)
+ {
+ checkConstructorBuilder();
constructorBuilder.addParameterMetaData(type, value);
return this;
}
+ public BeanMetaDataBuilder addConstructorParameter(String type, ValueMetaData value)
+ {
+ checkConstructorBuilder();
+ constructorBuilder.addParameterMetaData(type, value);
+ return this;
+ }
+
public BeanMetaDataBuilder addPropertyMetaData(String name, Object value)
{
Set<PropertyMetaData> properties = getProperties();
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/builder/ParameterMetaDataBuilder.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/builder/ParameterMetaDataBuilder.java 2007-07-22 01:20:57 UTC (rev 64179)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/builder/ParameterMetaDataBuilder.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -26,6 +26,7 @@
import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.beans.metadata.spi.ValueMetaData;
/**
* Helper class.
@@ -54,7 +55,7 @@
parameterHolder.setParameters(parameters);
}
- public T addParameterMetaData(String type, Object value)
+ private List<ParameterMetaData> checkParameters()
{
List<ParameterMetaData> parameters = getParameters();
if (parameters == null)
@@ -62,8 +63,21 @@
parameters = new ArrayList<ParameterMetaData>();
setParameters(parameters);
}
+ return parameters;
+ }
+
+ public T addParameterMetaData(String type, Object value)
+ {
+ List<ParameterMetaData> parameters = checkParameters();
parameters.add(new AbstractParameterMetaData(type, value));
return parameterHolder;
}
+ public T addParameterMetaData(String type, ValueMetaData value)
+ {
+ List<ParameterMetaData> parameters = checkParameters();
+ parameters.add(new AbstractParameterMetaData(type, value));
+ return parameterHolder;
+ }
+
}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/builder/BeanMetaDataBuilder.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/builder/BeanMetaDataBuilder.java 2007-07-22 01:20:57 UTC (rev 64179)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/spi/builder/BeanMetaDataBuilder.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -43,6 +43,8 @@
BeanMetaDataBuilder addConstructorParameter(String type, Object value);
+ BeanMetaDataBuilder addConstructorParameter(String type, ValueMetaData value);
+
BeanMetaDataBuilder addPropertyMetaData(String name, Object value);
BeanMetaDataBuilder addPropertyMetaData(String name, String value);
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding20.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding20.java 2007-07-22 01:20:57 UTC (rev 64179)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding20.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -155,12 +155,18 @@
/** The dependency binding */
public static final QName injectionTypeQName = new QName(BEAN_DEPLOYER_NS, "injectionType");
+ /** The value-factory binding */
+ public static final QName valueFactoryTypeQName = new QName(BEAN_DEPLOYER_NS, "valueFactoryType");
+
/** The factory binding */
public static final QName factoryTypeQName = new QName(BEAN_DEPLOYER_NS, "factoryType");
/** The inject element name */
public static final QName injectQName = new QName(BEAN_DEPLOYER_NS, "inject");
+ /** The value-factory element name */
+ public static final QName valueFactoryQName = new QName(BEAN_DEPLOYER_NS, "value-factory");
+
/** The plain value binding */
public static final QName plainValueTypeQName = new QName(BEAN_DEPLOYER_NS, "plainValueType");
@@ -334,6 +340,10 @@
TypeBinding injectionType = schemaBinding.getType(injectionTypeQName);
BeanSchemaBindingHelper.initInjectionHandlers(injectionType);
+ // value-factory binding
+ TypeBinding valueFactoryType = schemaBinding.getType(valueFactoryTypeQName);
+ BeanSchemaBindingHelper.initValueFactoryHandlers(valueFactoryType);
+
// factory binding
TypeBinding factoryType = schemaBinding.getType(factoryTypeQName);
BeanSchemaBindingHelper.initFactoryHandlers(factoryType);
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBindingHelper.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBindingHelper.java 2007-07-22 01:20:57 UTC (rev 64179)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBindingHelper.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -395,6 +395,19 @@
}
/**
+ * Initialize the handlers for the value factory type
+ *
+ * @param valueFactoryType the dependency type
+ */
+ public static void initValueFactoryHandlers(TypeBinding valueFactoryType)
+ {
+ valueFactoryType.setHandler(ValueFactoryHandler.HANDLER);
+
+ // value-factory has parameters
+ valueFactoryType.pushInterceptor(BeanSchemaBinding20.parameterQName, ValueFactoryParametersInterceptor.INTERCEPTOR);
+ }
+
+ /**
* Initialize the handlers for the factory type
*
* @param factoryType the factory type
@@ -496,6 +509,9 @@
// type has injections
typeBinding.pushInterceptor(BeanSchemaBinding20.injectQName, ValueMetaDataElementInterceptor.VALUES);
+ // type has value-factories
+ typeBinding.pushInterceptor(BeanSchemaBinding20.valueFactoryQName, ValueMetaDataElementInterceptor.VALUES);
+
// type can take a collection
typeBinding.pushInterceptor(BeanSchemaBinding20.collectionQName, ValueMetaDataElementInterceptor.VALUES);
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/ValueFactoryHandler.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/ValueFactoryHandler.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/ValueFactoryHandler.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,88 @@
+/*
+* 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.kernel.plugins.deployment.xml;
+
+import java.util.List;
+import java.util.ArrayList;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+
+import org.jboss.beans.metadata.plugins.AbstractValueFactoryMetaData;
+import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultElementHandler;
+import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
+import org.xml.sax.Attributes;
+
+/**
+ * ValueFactoryHandler.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ValueFactoryHandler extends DefaultElementHandler
+{
+ /** The handler */
+ public static final ValueFactoryHandler HANDLER = new ValueFactoryHandler();
+
+ public Object startElement(Object parent, QName name, ElementBinding element)
+ {
+ return new AbstractValueFactoryMetaData();
+ }
+
+ public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
+ {
+ AbstractValueFactoryMetaData valueFactory = (AbstractValueFactoryMetaData) o;
+ for (int i = 0; i < attrs.getLength(); ++i)
+ {
+ String localName = attrs.getLocalName(i);
+ if ("bean".equals(localName))
+ valueFactory.setValue(attrs.getValue(i));
+ else if ("method".equals(localName))
+ valueFactory.setMethod(attrs.getValue(i));
+ else if ("state".equals(localName))
+ valueFactory.setDependentState(new ControllerState(attrs.getValue(i)));
+ else if ("whenRequired".equals(localName))
+ valueFactory.setWhenRequiredState(new ControllerState(attrs.getValue(i)));
+ else if ("parameter".equals(localName))
+ valueFactory.setParameter(attrs.getValue(i));
+ else if ("default".equals(localName))
+ valueFactory.setDefaultValue(attrs.getValue(i));
+ }
+ }
+
+ public Object endElement(Object o, QName qName, ElementBinding element)
+ {
+ AbstractValueFactoryMetaData vf = (AbstractValueFactoryMetaData)o;
+ if (vf.getUnderlyingValue() == null || vf.getMethod() == null)
+ throw new IllegalArgumentException("Bean or method cannot null: " + vf);
+ if (vf.getParameter() != null && vf.getParameters() != null)
+ throw new IllegalArgumentException("Both parameter and parameters cannot be set: " + vf);
+ if (vf.getParameter() != null)
+ {
+ List<ParameterMetaData> parameters = new ArrayList<ParameterMetaData>();
+ parameters.add(new AbstractParameterMetaData(String.class.getName(), vf.getParameter()));
+ vf.setParameters(parameters);
+ }
+ return vf;
+ }
+}
Added: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/ValueFactoryParametersInterceptor.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/ValueFactoryParametersInterceptor.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/ValueFactoryParametersInterceptor.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,56 @@
+/*
+* 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.kernel.plugins.deployment.xml;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.namespace.QName;
+
+import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
+import org.jboss.beans.metadata.plugins.AbstractValueFactoryMetaData;
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultElementInterceptor;
+
+/**
+ * ValueFactoryParametersInterceptor.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ValueFactoryParametersInterceptor extends DefaultElementInterceptor
+{
+ /** The interceptor */
+ public static final ValueFactoryParametersInterceptor INTERCEPTOR = new ValueFactoryParametersInterceptor();
+
+ public void add(Object parent, Object child, QName name)
+ {
+ AbstractValueFactoryMetaData factoryMetaData = (AbstractValueFactoryMetaData) parent;
+ AbstractParameterMetaData parameter = (AbstractParameterMetaData) child;
+ List<ParameterMetaData> parameters = factoryMetaData.getParameters();
+ if (parameters == null)
+ {
+ parameters = new ArrayList<ParameterMetaData>();
+ factoryMetaData.setParameters(parameters);
+ }
+ parameter.setIndex(parameters.size());
+ parameters.add(parameter);
+ }
+}
Modified: projects/microcontainer/trunk/kernel/src/resources/main/schema/bean-deployer_2_0.xsd
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/main/schema/bean-deployer_2_0.xsd 2007-07-22 01:20:57 UTC (rev 64179)
+++ projects/microcontainer/trunk/kernel/src/resources/main/schema/bean-deployer_2_0.xsd 2007-07-22 10:14:45 UTC (rev 64180)
@@ -226,6 +226,7 @@
<xsd:element name="array" type="arrayType"/>
<xsd:element name="map" type="mapType"/>
<xsd:element name="inject" type="injectionType"/>
+ <xsd:element name="value-factory" type="valueFactoryType"/>
<xsd:any namespace="##other" processContents="strict">
<xsd:annotation>
<xsd:documentation>An extension value</xsd:documentation>
@@ -397,6 +398,46 @@
<xsd:attribute name="fromContext" type="contextType" use="optional"/>
</xsd:complexType>
+ <xsd:complexType name="valueFactoryType">
+ <xsd:annotation>
+ <xsd:documentation>
+ <![CDATA[
+ A dependency represents an value injection into the bean.
+ They can be used anywhere a string value can appear.
+
+ e.g. Bean instance - "InjectedIntoMe".setSomeProperty("ValueFactory".getValue("foo.bar.prop", "mydefault"));
+ <bean name="InjectedIntoMe" ...>
+ <property name="someProperty">
+ <value-factory bean="BeanInjected" method="getValue">
+ <parameter>foo.bar.prop</parameter>
+ <parameter>mydefault</parameter>
+ </value-factory>
+ </property>
+ </bean>
+ <bean name="BeanInjected" .../>
+
+ e.g. Bean instance - "InjectedIntoMe".setSomeProperty("ValueFactory".getValue("foo.bar.prop"));
+ <bean name="InjectedIntoMe" ...>
+ <property name="someProperty">
+ <value-factory bean="BeanInjected" method="getValue" parameter="foo.bar.prop" default="mydefault" />
+ </property>
+ </bean>
+ <bean name="BeanInjected" .../>
+
+ ]]>
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:sequence>
+ <xsd:element name="parameter" type="parameterType" minOccurs="0" maxOccurs="unbounded"/>
+ </xsd:sequence>
+ <xsd:attribute name="bean" type="xsd:string"/>
+ <xsd:attribute name="method" type="xsd:string"/>
+ <xsd:attribute name="state" type="controllerStateType" use="optional"/>
+ <xsd:attribute name="whenRequired" type="controllerStateType" use="optional"/>
+ <xsd:attribute name="parameter" type="xsd:string" use="optional"/>
+ <xsd:attribute name="default" type="xsd:string" use="optional"/>
+ </xsd:complexType>
+
<xsd:complexType name="factoryType">
<xsd:annotation>
<xsd:documentation>
@@ -602,6 +643,7 @@
<!--<xsd:element name="bean" type="beanType"/>-->
<xsd:element name="value" type="plainValueType"/>
<xsd:element name="inject" type="injectionType"/>
+ <xsd:element name="value-factory" type="valueFactoryType"/>
<xsd:element name="collection" type="collectionType"/>
<xsd:element name="list" type="listType"/>
<xsd:element name="set" type="setType"/>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryBadNoBean.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryBadNoBean.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryBadNoBean.xml 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<bean xmlns="urn:jboss:bean-deployer:2.0" class="Dummy">
+ <property name="Dummy">
+ <value-factory method="getValue" parameter="qwert"/>
+ </property>
+</bean>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryBadNoMethod.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryBadNoMethod.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryBadNoMethod.xml 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<bean xmlns="urn:jboss:bean-deployer:2.0" class="Dummy">
+ <property name="Dummy">
+ <value-factory bean="Dummy" parameter="qwert"/>
+ </property>
+</bean>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithBean.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithBean.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithBean.xml 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<bean xmlns="urn:jboss:bean-deployer:2.0" class="Dummy">
+ <property name="Dummy">
+ <value-factory bean="Dummy" method="getValue" parameter="qwert"/>
+ </property>
+</bean>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithDefault.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithDefault.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithDefault.xml 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<bean xmlns="urn:jboss:bean-deployer:2.0" class="Dummy">
+ <property name="Dummy">
+ <value-factory bean="Dummy" method="getValue" parameter="foo.bar.key" default="mydefault"/>
+ </property>
+</bean>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithParameter.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithParameter.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithParameter.xml 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<bean xmlns="urn:jboss:bean-deployer:2.0" class="Dummy">
+ <property name="Dummy">
+ <value-factory bean="Dummy" method="getValue" parameter="foo.bar.key"/>
+ </property>
+</bean>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithParameters.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithParameters.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithParameters.xml 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<bean xmlns="urn:jboss:bean-deployer:2.0" class="Dummy">
+ <property name="Dummy">
+ <value-factory bean="Dummy" method="getValue">
+ <parameter>foo.bar.key</parameter>
+ <parameter>mydefault</parameter>
+ </value-factory>
+ </property>
+</bean>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithState.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithState.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithState.xml 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<bean xmlns="urn:jboss:bean-deployer:2.0" class="Dummy">
+ <property name="Dummy">
+ <value-factory bean="Dummy" method="getValue" parameter="qwert" state="Configured"/>
+ </property>
+</bean>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithWhenRequired.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithWhenRequired.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryWithWhenRequired.xml 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<bean xmlns="urn:jboss:bean-deployer:2.0" class="Dummy">
+ <property name="Dummy">
+ <value-factory bean="Dummy" method="getValue" parameter="qwert" whenRequired="Create"/>
+ </property>
+</bean>
Added: projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testValueFactory.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testValueFactory.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testValueFactory.xml 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd"
+ xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="ldap" class="org.jboss.test.kernel.config.support.LDAPFactory">
+ <constructor>
+ <parameter>
+ <map keyClass="java.lang.String" valueClass="java.lang.String">
+ <entry>
+ <key>foo.bar.key</key>
+ <value>QWERT</value>
+ </entry>
+ <entry>
+ <key>xyz.key</key>
+ <value> QWERT </value>
+ </entry>
+ </map>
+ </parameter>
+ </constructor>
+ </bean>
+
+ <bean name="PropHolder" class="org.jboss.test.kernel.config.support.PropHolder">
+ <constructor>
+ <parameter>
+ <value-factory bean="ldap" method="getValue" parameter="foo.bar.key"/>
+ </parameter>
+ </constructor>
+ <property name="value">
+ <value-factory bean="ldap" method="getValue" parameter="foo.bar.key"/>
+ </property>
+ <property name="list">
+ <list elementClass="java.lang.String">
+ <value-factory bean="ldap" method="getValue" parameter="foo.bar.key"/>
+ <value-factory bean="ldap" method="getValue">
+ <parameter>foo.bar.key</parameter>
+ <parameter>qaz</parameter>
+ </value-factory>
+ <value-factory bean="ldap" method="getValue">
+ <parameter>xyz.key</parameter>
+ <parameter>xyz</parameter>
+ <parameter><bean name="t" class="org.jboss.test.kernel.config.support.TrimTransformer"/></parameter>
+ </value-factory>
+ <value-factory bean="ldap" method="getValue" default="QWERT">
+ <parameter>no.such.key</parameter>
+ </value-factory>
+ </list>
+ </property>
+ </bean>
+
+</deployment>
+
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/LDAPFactory.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/LDAPFactory.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/LDAPFactory.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,65 @@
+/*
+* 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.test.kernel.config.support;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class LDAPFactory
+{
+ private Map<String, String> map;
+
+ public LDAPFactory(Map<String, String> map)
+ {
+ if (map == null)
+ throw new IllegalArgumentException("Map is null.");
+ this.map = map;
+ }
+
+ public String getValue(String key)
+ {
+ return getValue(key, null);
+ }
+
+ public String getValue(String key, String def)
+ {
+ return getValue(key, def, null);
+ }
+
+ public String getValue(String key, String def, Transformer<String> transformer)
+ {
+ if (transformer == null)
+ transformer = new Transformer<String>()
+ {
+ public String transform(String value)
+ {
+ return value;
+ }
+ };
+ String value = map.get(key);
+ if (value == null)
+ value = def;
+ return transformer.transform(value);
+ }
+}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/PropHolder.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/PropHolder.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/PropHolder.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,66 @@
+/*
+* 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.test.kernel.config.support;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class PropHolder
+{
+ private String constructor;
+ private String value;
+ private List<String> list;
+
+ public PropHolder(String constructor)
+ {
+ this.constructor = constructor;
+ }
+
+ public String getConstructor()
+ {
+ return constructor;
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public void setValue(String value)
+ {
+ this.value = value;
+ }
+
+ public List<String> getList()
+ {
+ return list;
+ }
+
+ public void setList(List<String> list)
+ {
+ this.list = list;
+ }
+
+
+}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/Transformer.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/Transformer.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/Transformer.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,31 @@
+/*
+* 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.test.kernel.config.support;
+
+/**
+ * @param <T> transformer type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface Transformer<T>
+{
+ T transform(T value);
+}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/TrimTransformer.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/TrimTransformer.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/TrimTransformer.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,33 @@
+/*
+* 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.test.kernel.config.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TrimTransformer implements Transformer<String>
+{
+ public String transform(String value)
+ {
+ return value.trim();
+ }
+}
Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ConfigTestSuite.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ConfigTestSuite.java 2007-07-22 01:20:57 UTC (rev 64179)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ConfigTestSuite.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -69,6 +69,8 @@
suite.addTest(PropertyReplaceXMLTestCase.suite());
suite.addTest(ElementTestCase.suite());
suite.addTest(ElementXMLTestCase.suite());
+ suite.addTest(ValueFactoryTestCase.suite());
+ suite.addTest(ValueFactoryXMLTestCase.suite());
return suite;
}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueFactoryTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueFactoryTestCase.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueFactoryTestCase.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,132 @@
+/*
+* 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.test.kernel.config.test;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Test;
+import org.jboss.beans.metadata.plugins.AbstractListMetaData;
+import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
+import org.jboss.beans.metadata.plugins.AbstractValueFactoryMetaData;
+import org.jboss.beans.metadata.plugins.AbstractMapMetaData;
+import org.jboss.beans.metadata.plugins.StringValueMetaData;
+import org.jboss.beans.metadata.plugins.builder.BeanMetaDataBuilderFactory;
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.Kernel;
+import org.jboss.test.kernel.config.support.PropHolder;
+import org.jboss.test.kernel.config.support.TrimTransformer;
+import org.jboss.test.kernel.config.support.LDAPFactory;
+import org.jboss.test.kernel.config.support.Transformer;
+
+/**
+ * Test org.w3c.dom.Element usage in MC xml.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ValueFactoryTestCase extends AbstractKernelConfigTest
+{
+ public ValueFactoryTestCase(String name)
+ {
+ super(name);
+ }
+
+ public ValueFactoryTestCase(String name, boolean xmltest)
+ {
+ super(name, xmltest);
+ }
+
+ public static Test suite()
+ {
+ return suite(ValueFactoryTestCase.class);
+ }
+
+ public void testValueFactory() throws Throwable
+ {
+ Kernel kernel = bootstrap();
+ KernelController controller = kernel.getController();
+ PropHolder propHolder = instantiateHolder(controller);
+ assertNotNull(propHolder);
+ assertEquals("QWERT", propHolder.getConstructor());
+ assertEquals("QWERT", propHolder.getValue());
+ assertNotNull(propHolder.getList());
+ for (String prop : propHolder.getList())
+ assertEquals("QWERT", prop);
+ }
+
+ protected PropHolder instantiateHolder(KernelController controller) throws Throwable
+ {
+ // ldap
+ BeanMetaDataBuilder ldap = BeanMetaDataBuilderFactory.createBuilder("ldap", LDAPFactory.class.getName());
+ AbstractMapMetaData map = new AbstractMapMetaData();
+ map.setKeyType(String.class.getName());
+ map.setValueType(String.class.getName());
+ map.put(new StringValueMetaData("foo.bar.key"), new StringValueMetaData("QWERT"));
+ map.put(new StringValueMetaData("xyz.key"), new StringValueMetaData(" QWERT "));
+ ldap.addConstructorParameter(Map.class.getName(), map);
+ LDAPFactory lf = (LDAPFactory)instantiate(controller, ldap.getBeanMetaData());
+ assertNotNull(lf);
+
+ // simple one
+ AbstractValueFactoryMetaData vfmd1 = new AbstractValueFactoryMetaData("ldap", "getValue");
+ List<ParameterMetaData> parameters1 = new ArrayList<ParameterMetaData>();
+ vfmd1.setParameters(parameters1);
+ parameters1.add(new AbstractParameterMetaData(String.class.getName(), "foo.bar.key"));
+
+ BeanMetaDataBuilder builder = BeanMetaDataBuilderFactory.createBuilder("PropHolder", PropHolder.class.getName());
+ builder.addConstructorParameter(String.class.getName(), vfmd1);
+ builder.addPropertyMetaData("value", vfmd1);
+
+ AbstractListMetaData listMD = new AbstractListMetaData();
+ listMD.add(vfmd1);
+ // default from 2nd param
+ AbstractValueFactoryMetaData vfmd2 = new AbstractValueFactoryMetaData("ldap", "getValue");
+ List<ParameterMetaData> parameters2 = new ArrayList<ParameterMetaData>();
+ vfmd2.setParameters(parameters2);
+ parameters2.add(new AbstractParameterMetaData(String.class.getName(), "foo.bar.key"));
+ parameters2.add(new AbstractParameterMetaData(String.class.getName(), "qaz"));
+ listMD.add(vfmd2);
+ // with transformer
+ AbstractValueFactoryMetaData vfmd3 = new AbstractValueFactoryMetaData("ldap", "getValue");
+ List<ParameterMetaData> parameters3 = new ArrayList<ParameterMetaData>();
+ vfmd3.setParameters(parameters3);
+ parameters3.add(new AbstractParameterMetaData(String.class.getName(), "xyz.key"));
+ parameters3.add(new AbstractParameterMetaData(String.class.getName(), "xyz"));
+ // instantiate transformer
+ BeanMetaDataBuilder tranformer = BeanMetaDataBuilderFactory.createBuilder("t", TrimTransformer.class.getName());
+ assertNotNull(instantiate(controller, tranformer.getBeanMetaData()));
+ parameters3.add(new AbstractParameterMetaData(Transformer.class.getName(), tranformer.getBeanMetaData()));
+ listMD.add(vfmd3);
+ // null, use default
+ AbstractValueFactoryMetaData vfmd4 = new AbstractValueFactoryMetaData("ldap", "getValue", "QWERT");
+ List<ParameterMetaData> parameters4 = new ArrayList<ParameterMetaData>();
+ vfmd4.setParameters(parameters4);
+ parameters4.add(new AbstractParameterMetaData(String.class.getName(), "no.such.key"));
+ listMD.add(vfmd4);
+ builder.addPropertyMetaData("list", listMD);
+ return (PropHolder)instantiate(controller, builder.getBeanMetaData());
+ }
+
+}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueFactoryXMLTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueFactoryXMLTestCase.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueFactoryXMLTestCase.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,57 @@
+/*
+* 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.test.kernel.config.test;
+
+import junit.framework.Test;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.test.kernel.config.support.PropHolder;
+import org.jboss.test.kernel.config.support.XMLUtil;
+
+/**
+ * Test org.w3c.dom.Element usage in MC xml.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ValueFactoryXMLTestCase extends ValueFactoryTestCase
+{
+ public ValueFactoryXMLTestCase(String name)
+ {
+ super(name);
+ }
+
+ public ValueFactoryXMLTestCase(String name, boolean xmltest)
+ {
+ super(name, xmltest);
+ }
+
+ public static Test suite()
+ {
+ return suite(ValueFactoryXMLTestCase.class);
+ }
+
+ protected PropHolder instantiateHolder(KernelController controller) throws Throwable
+ {
+ XMLUtil util = bootstrapXML(true);
+ return (PropHolder) util.getBean("PropHolder");
+ }
+
+}
Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/InjectionTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/InjectionTestCase.java 2007-07-22 01:20:57 UTC (rev 64179)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/InjectionTestCase.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -50,7 +50,7 @@
PropertyMetaData property = (PropertyMetaData) properties.iterator().next();
assertNotNull(property);
ValueMetaData value = property.getValue();
- assertNotNull(property);
+ assertNotNull(value);
assertTrue(value instanceof AbstractInjectionValueMetaData);
return (AbstractInjectionValueMetaData) value;
}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryTestCase.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/ValueFactoryTestCase.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -0,0 +1,163 @@
+/*
+* 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.test.kernel.deployment.xml.test;
+
+import java.util.Set;
+import java.util.List;
+
+import junit.framework.Test;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractValueFactoryMetaData;
+import org.jboss.beans.metadata.spi.PropertyMetaData;
+import org.jboss.beans.metadata.spi.ValueMetaData;
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * ValueFactoryTestCase.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ValueFactoryTestCase extends AbstractXMLTest
+{
+ protected AbstractValueFactoryMetaData getValueFactory(String name) throws Exception
+ {
+ AbstractBeanMetaData bean = unmarshalBean(name);
+ Set properties = bean.getProperties();
+ assertNotNull(properties);
+ assertEquals(1, properties.size());
+ PropertyMetaData property = (PropertyMetaData) properties.iterator().next();
+ assertNotNull(property);
+ ValueMetaData value = property.getValue();
+ assertNotNull(value);
+ assertTrue(value instanceof AbstractValueFactoryMetaData);
+ return (AbstractValueFactoryMetaData) value;
+ }
+
+ public void testValueFactoryWithBean() throws Exception
+ {
+ AbstractValueFactoryMetaData dependency = getValueFactory("ValueFactoryWithBean.xml");
+ assertEquals("Dummy", dependency.getValue());
+ assertEquals("getValue", dependency.getMethod());
+ assertEquals(ControllerState.INSTALLED, dependency.getDependentState());
+ }
+
+ public void testValueFactoryWithParameter() throws Exception
+ {
+ AbstractValueFactoryMetaData dependency = getValueFactory("ValueFactoryWithParameter.xml");
+ assertEquals("Dummy", dependency.getValue());
+ assertEquals("getValue", dependency.getMethod());
+ List<ParameterMetaData> parameters = dependency.getParameters();
+ assertNotNull(parameters);
+ assertFalse(parameters.isEmpty());
+ assertTrue(parameters.size() == 1);
+ ParameterMetaData pmd = parameters.get(0);
+ assertNotNull(pmd);
+ ValueMetaData value = pmd.getValue();
+ assertNotNull(value);
+ assertEquals("foo.bar.key", value.getUnderlyingValue());
+ assertEquals(ControllerState.INSTALLED, dependency.getDependentState());
+ }
+
+ public void testValueFactoryWithParameters() throws Exception
+ {
+ AbstractValueFactoryMetaData dependency = getValueFactory("ValueFactoryWithParameters.xml");
+ assertEquals("Dummy", dependency.getValue());
+ assertEquals("getValue", dependency.getMethod());
+ List<ParameterMetaData> parameters = dependency.getParameters();
+ assertNotNull(parameters);
+ assertFalse(parameters.isEmpty());
+ assertTrue(parameters.size() == 2);
+ ParameterMetaData pmd1 = parameters.get(0);
+ assertNotNull(pmd1);
+ ValueMetaData value1 = pmd1.getValue();
+ assertNotNull(value1);
+ assertEquals("foo.bar.key", value1.getUnderlyingValue());
+ ParameterMetaData pmd2 = parameters.get(1);
+ assertNotNull(pmd2);
+ ValueMetaData value2 = pmd2.getValue();
+ assertNotNull(value2);
+ assertEquals("mydefault", value2.getUnderlyingValue());
+ assertEquals(ControllerState.INSTALLED, dependency.getDependentState());
+ }
+
+ public void testValueFactoryWithDefault() throws Exception
+ {
+ AbstractValueFactoryMetaData dependency = getValueFactory("ValueFactoryWithDefault.xml");
+ assertEquals("Dummy", dependency.getValue());
+ assertEquals("getValue", dependency.getMethod());
+ assertEquals("mydefault", dependency.getDefaultValue());
+ assertEquals(ControllerState.INSTALLED, dependency.getDependentState());
+ }
+
+ public void testValueFactoryWithState() throws Exception
+ {
+ AbstractValueFactoryMetaData dependency = getValueFactory("ValueFactoryWithState.xml");
+ assertEquals("Dummy", dependency.getValue());
+ assertEquals("getValue", dependency.getMethod());
+ assertEquals(ControllerState.CONFIGURED, dependency.getDependentState());
+ }
+
+ public void testValueFactoryWithWhenRequired() throws Exception
+ {
+ AbstractValueFactoryMetaData dependency = getValueFactory("ValueFactoryWithWhenRequired.xml");
+ assertEquals("Dummy", dependency.getValue());
+ assertEquals("getValue", dependency.getMethod());
+ assertEquals(ControllerState.CREATE, dependency.getWhenRequiredState());
+ }
+
+ public void testValueFactoryBadNoBean() throws Exception
+ {
+ try
+ {
+ AbstractValueFactoryMetaData dependency = getValueFactory("ValueFactoryBadNoBean.xml");
+ assertNull(dependency.getValue());
+ }
+ catch (Exception expected)
+ {
+ checkJBossXBException(IllegalArgumentException.class, expected);
+ }
+ }
+
+ public void testValueFactoryBadNoMethod() throws Exception
+ {
+ try
+ {
+ AbstractValueFactoryMetaData dependency = getValueFactory("ValueFactoryBadNoMethod.xml");
+ assertNull(dependency.getValue());
+ }
+ catch (Exception expected)
+ {
+ checkJBossXBException(IllegalArgumentException.class, expected);
+ }
+ }
+
+ public static Test suite()
+ {
+ return suite(ValueFactoryTestCase.class);
+ }
+
+ public ValueFactoryTestCase(String name)
+ {
+ super(name);
+ }
+}
Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/XMLTestSuite.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/XMLTestSuite.java 2007-07-22 01:20:57 UTC (rev 64179)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/XMLTestSuite.java 2007-07-22 10:14:45 UTC (rev 64180)
@@ -68,6 +68,7 @@
suite.addTest(PolicyTestCase.suite());
suite.addTest(AliasTestCase.suite());
suite.addTest(CallbackTestCase.suite());
+ suite.addTest(ValueFactoryTestCase.suite());
return suite;
}
More information about the jboss-cvs-commits
mailing list